35 #include "table/strings.h" 40 static void ShowRoadDepotPicker(
Window *parent);
43 static bool _one_way_button_clicked;
51 RF_START_HALFROAD_Y = 0x01,
52 RF_END_HALFROAD_Y = 0x02,
55 RF_START_HALFROAD_X = 0x08,
56 RF_END_HALFROAD_X = 0x10,
67 void CcPlaySound_SPLAT_OTHER(
const CommandCost &result,
TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
133 STR_ERROR_CAN_T_BUILD_ROAD_HERE,
134 STR_ERROR_CAN_T_REMOVE_ROAD_FROM,
135 STR_ERROR_CAN_T_BUILD_ROAD_DEPOT,
136 { STR_ERROR_CAN_T_BUILD_BUS_STATION, STR_ERROR_CAN_T_BUILD_TRUCK_STATION },
137 { STR_ERROR_CAN_T_REMOVE_BUS_STATION, STR_ERROR_CAN_T_REMOVE_TRUCK_STATION },
138 { STR_STATION_BUILD_BUS_ORIENTATION, STR_STATION_BUILD_TRUCK_ORIENTATION },
139 { STR_STATION_BUILD_BUS_ORIENTATION_TOOLTIP, STR_STATION_BUILD_TRUCK_ORIENTATION_TOOLTIP },
141 SPR_CURSOR_ROAD_NESW,
142 SPR_CURSOR_ROAD_NWSE,
146 STR_ERROR_CAN_T_BUILD_TRAMWAY_HERE,
147 STR_ERROR_CAN_T_REMOVE_TRAMWAY_FROM,
148 STR_ERROR_CAN_T_BUILD_TRAM_DEPOT,
149 { STR_ERROR_CAN_T_BUILD_PASSENGER_TRAM_STATION, STR_ERROR_CAN_T_BUILD_CARGO_TRAM_STATION },
150 { STR_ERROR_CAN_T_REMOVE_PASSENGER_TRAM_STATION, STR_ERROR_CAN_T_REMOVE_CARGO_TRAM_STATION },
151 { STR_STATION_BUILD_PASSENGER_TRAM_ORIENTATION, STR_STATION_BUILD_CARGO_TRAM_ORIENTATION },
152 { STR_STATION_BUILD_PASSENGER_TRAM_ORIENTATION_TOOLTIP, STR_STATION_BUILD_CARGO_TRAM_ORIENTATION_TOOLTIP },
154 SPR_CURSOR_TRAMWAY_NESW,
155 SPR_CURSOR_TRAMWAY_NWSE,
178 if (result.
Failed())
return;
203 if (result.
Failed())
return;
208 TileArea roadstop_area(tile,
GB(p1, 0, 8),
GB(p1, 8, 8));
228 uint8 ddir = _road_station_picker_orientation;
229 SB(p2, 16, 16, INVALID_STATION);
251 if (_road_station_picker_orientation <
DIAGDIR_END) {
269 if (_road_station_picker_orientation <
DIAGDIR_END) {
278 typedef void OnButtonClick(
Window *w);
318 this->InitNested(window_number);
319 this->SetWidgetsDisabledState(
true,
324 this->OnInvalidateData();
342 if (!gui_scope)
return;
345 this->SetWidgetsDisabledState(!can_build,
367 switch (clicked_widget) {
381 this->SetWidgetDisabledState(
WID_ROT_REMOVE, !this->IsWidgetLowered(clicked_widget));
387 this->SetWidgetsDisabledState(!this->IsWidgetLowered(clicked_widget),
396 this->SetWidgetsDisabledState(
true,
400 this->SetWidgetsLoweredState(
false,
411 _one_way_button_clicked =
false;
415 this->last_started_action = widget;
420 this->last_started_action = widget;
425 this->last_started_action = widget;
430 this->last_started_action = widget;
436 ShowRoadDepotPicker(
this);
437 this->last_started_action = widget;
445 this->last_started_action = widget;
453 this->last_started_action = widget;
461 SetSelectionRed(
false);
466 this->last_started_action = widget;
471 this->last_started_action = widget;
482 default: NOT_REACHED();
498 switch (this->last_started_action) {
500 _place_road_flag = RF_DIR_X;
501 if (_tile_fract_coords.x >= 8) _place_road_flag |= RF_START_HALFROAD_X;
506 _place_road_flag = RF_DIR_Y;
507 if (_tile_fract_coords.y >= 8) _place_road_flag |= RF_START_HALFROAD_Y;
512 _place_road_flag = RF_NONE;
513 if (_tile_fract_coords.x >= 8) _place_road_flag |= RF_START_HALFROAD_X;
514 if (_tile_fract_coords.y >= 8) _place_road_flag |= RF_START_HALFROAD_Y;
523 DoCommandP(tile, _cur_roadtype << 2 | _road_depot_orientation, 0,
544 default: NOT_REACHED();
550 this->RaiseButtons();
551 this->SetWidgetsDisabledState(
true,
571 switch (select_proc) {
573 _place_road_flag &= ~RF_END_HALFROAD_X;
574 if (pt.x & 8) _place_road_flag |= RF_END_HALFROAD_X;
578 _place_road_flag &= ~RF_END_HALFROAD_Y;
579 if (pt.y & 8) _place_road_flag |= RF_END_HALFROAD_Y;
583 _place_road_flag &= ~(RF_END_HALFROAD_Y | RF_END_HALFROAD_X);
584 if (pt.y & 8) _place_road_flag |= RF_END_HALFROAD_Y;
585 if (pt.x & 8) _place_road_flag |= RF_END_HALFROAD_X;
590 ( (_tile_fract_coords.x < _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) < 16) ||
591 (_tile_fract_coords.x > _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) > 16) ))) {
593 _place_road_flag &= ~RF_DIR_Y;
596 _place_road_flag |= RF_DIR_Y;
611 switch (select_proc) {
612 default: NOT_REACHED();
629 _place_road_flag = (
RoadFlags)((_place_road_flag & RF_DIR_Y) ? (_place_road_flag & 0x07) : (_place_road_flag >> 3));
631 DoCommandP(start_tile, end_tile, _place_road_flag | (_cur_roadtype << 3) | (_one_way_button_clicked << 5),
687 switch (_game_mode) {
689 extern RoadType _last_built_roadtype;
706 static Hotkey roadtoolbar_hotkeys[] = {
723 static const NWidgetPart _nested_build_road_widgets[] = {
760 _nested_build_road_widgets,
lengthof(_nested_build_road_widgets),
761 &BuildRoadToolbarWindow::hotkeys
764 static const NWidgetPart _nested_build_tramway_widgets[] = {
800 _nested_build_tramway_widgets,
lengthof(_nested_build_tramway_widgets),
801 &BuildRoadToolbarWindow::hotkeys
814 _cur_roadtype = roadtype;
817 return AllocateWindowDescFront<BuildRoadToolbarWindow>(roadtype ==
ROADTYPE_ROAD ? &_build_road_desc : &_build_tramway_desc,
TRANSPORT_ROAD);
820 static const NWidgetPart _nested_build_road_scen_widgets[] = {
848 WDP_AUTO,
"toolbar_road_scen", 0, 0,
851 _nested_build_road_scen_widgets,
lengthof(_nested_build_road_scen_widgets),
852 &BuildRoadToolbarWindow::hotkeys
862 return AllocateWindowDescFront<BuildRoadToolbarWindow>(&_build_road_scen_desc,
TRANSPORT_ROAD);
868 this->CreateNestedTree();
872 this->GetWidget<NWidgetCore>(
WID_BROD_CAPTION)->widget_data = STR_BUILD_DEPOT_TRAM_ORIENTATION_CAPTION;
914 static const NWidgetPart _nested_build_road_depot_widgets[] = {
948 _nested_build_road_depot_widgets,
lengthof(_nested_build_road_depot_widgets)
951 static void ShowRoadDepotPicker(
Window *parent)
959 this->CreateNestedTree();
968 this->GetWidget<NWidgetCore>(i)->tool_tip = _road_type_infos[_cur_roadtype].
picker_tooltip[rs];
971 this->LowerWidget(_road_station_picker_orientation + WID_BROS_STATION_NE);
990 SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
1095 SetDataTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
1097 SetDataTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
1108 _nested_road_station_picker_widgets,
lengthof(_nested_road_station_picker_widgets)
1133 SetDataTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
1135 SetDataTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
1146 _nested_tram_station_picker_widgets,
lengthof(_nested_tram_station_picker_widgets)
1154 void InitializeRoadGui()
1157 _road_station_picker_orientation =
DIAGDIR_NW;
EventState
State of handling an event.
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
ViewportDragDropSelectionProcess
Drag and drop selection process, or, what to do with an area of land when you've selected it...
don't allow building on structures
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition of stuff that is very close to a company, like the company struct itself.
static void PlaceRoad_Bridge(TileIndex tile, Window *w)
Callback to start placing a bridge.
Select station (when joining stations); Window numbers:
A standard stop for trucks.
bool link_terraform_toolbar
display terraform toolbar when displaying rail, road, water and airport toolbars
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
void CheckRedrawStationCoverage(const Window *w)
Check whether we need to redraw the station coverage text.
Point pos
Location, in tile "units", of the northern tile of the selected area.
area of land of limited size
All data for a single hotkey.
High level window description.
Road stop placement (trucks)
build a complete road (not a "half" one)
static const CursorID ANIMCURSOR_DEMOLISH
704 - 707 - demolish dynamite
static EventState RoadToolbarGlobalHotkeys(int hotkey)
Handler for global hotkeys of the BuildRoadToolbarWindow.
Landscape generation (in Scenario Editor); Window numbers:
void ConnectRoadToStructure(TileIndex tile, DiagDirection direction)
If required, connects a new structure to an existing road or tram by building the missing roadbit...
bool station_show_coverage
whether to highlight coverage area
Scenario build toolbar; Window numbers:
static bool IsBridgeTile(TileIndex t)
checks if there is a bridge on this tile
Hotkey related functions.
static bool IsInsideMM(const T x, const uint min, const uint max)
Checks if a value is in an interval.
void ShowSelectStationIfNeeded(const CommandContainer &cmd, TileArea ta)
Show the station selection window when needed.
Contains enums and function declarations connected with stations GUI.
remove a complete road (not a "half" one)
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Road stop removal (trucks)
Normal amount of vertical space between two paragraphs of text.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Draw only passenger class cargoes.
Functions/types related to the road GUIs.
The passed event is not handled.
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Drag only in X axis with limited size.
Point size
Size, in tile "units", of the white/red selection area.
Window * ShowBuildRoadToolbar(RoadType roadtype)
Open the build road toolbar window.
Drag only in Y axis with limited size.
Functions related to vehicles.
A standard stop for buses.
void DrawRoadDepotSprite(int x, int y, DiagDirection dir, RoadType rt)
Draw the road depot sprite.
static RoadTypes RoadTypeToRoadTypes(RoadType rt)
Maps a RoadType to the corresponding RoadTypes value.
byte station_spread
amount a station may spread
Build depot; Window numbers:
void ToggleWidgetLoweredState(byte widget_index)
Invert the lowered/raised status of a widget.
static RoadBits GetRoadBits(TileIndex t, RoadType rt)
Get the present road bits for a specific road type.
Northeast, upper right on your monitor.
void VpSetPresizeRange(TileIndex from, TileIndex to)
Highlights all tiles between a set of two tiles.
Road stop removal (buses)
bool CanBuildVehicleInfrastructure(VehicleType type)
Check whether we can build infrastructure for the given vehicle type.
virtual void OnRealtimeTick(uint delta_ms)
Called periodically.
bool persistent_buildingtools
keep the building tools active after usage
Common return value for all commands.
Catchment for bus stops with "modified catchment" enabled.
RoadType
The different roadtypes we support.
StringID picker_title[2]
Title for the station picker for bus or truck stations.
uint16 w
The width of the area.
StationSettings station
settings related to station management
RoadStopType
Types of RoadStops.
static T SB(T &x, const uint8 s, const uint8 n, const U d)
Set n bits in x starting at bit s to d.
Functions, definitions and such used only by the GUI.
static void ToggleRoadButton_Remove(Window *w)
Toggles state of the Remove button of Build road toolbar.
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
CompanyByte _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
StringID err_remove_road
Removing a normal piece of road.
Functions related to (drawing on) viewports.
Data structure for an opened window.
bool _ctrl_pressed
Is Ctrl pressed?
virtual void OnPaint()
The window must be repainted.
static RoadBits DiagDirToRoadBits(DiagDirection d)
Create the road-part which belongs to the given DiagDirection.
Structure holding information per roadtype for several functions.
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
static const NWidgetPart _nested_road_station_picker_widgets[]
Widget definition of the build road station window.
int DrawStationCoverageAreaText(int left, int right, int top, StationCoverageType sct, int rad, bool supplies)
Calculates and draws the accepted or supplied cargo around the selected tile(s)
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
This window is used for construction; close it whenever changing company.
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
SoundSettings sound
sound effect settings
Header file for things common for tunnels and bridges.
void SetRedErrorSquare(TileIndex tile)
Set a tile to display a red error square.
ViewportPlaceMethod
Viewport place method (type of highlighted area and placed objects)
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Structure for buffering the build command when selecting a station to join.
ClientSettings _settings_client
The current settings for this game.
bool Succeeded() const
Did this command succeed?
StationCoverageType
Types of cargo to display for station coverage.
#define TILE_AREA_LOOP(var, ta)
A loop which iterates over the tiles of a TileArea.
Definition of base types and functions in a cross-platform compatible way.
A number of safeguards to prevent using unsafe methods.
List of hotkeys for a window.
rectangle (stations, depots, ...)
Road stop placement (buses)
bool IsWidgetDisabled(byte widget_index) const
Gets the enabled/disabled status of a widget.
Represents the covered area of e.g.
void CcBuildRoadTunnel(const CommandCost &result, TileIndex start_tile, uint32 p1, uint32 p2, uint32 cmd)
Callback executed after a build road tunnel command has been called.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
TileIndex _build_tunnel_endtile
The end of a tunnel; as hidden return from the tunnel build command for GUI purposes.
Functions related to stations.
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
DiagDirection
Enumeration for diagonal directions.
void VpStartPlaceSizing(TileIndex tile, ViewportPlaceMethod method, ViewportDragDropSelectionProcess process)
highlighting tiles while only going over them with the mouse
Catchment for truck stops with "modified catchment" enabled.
Catchment for all stations with "modified catchment" disabled.
#define lengthof(x)
Return the length of an fixed size array.
void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transport_type, byte road_rail_type)
Prepare the data for the build a bridge window.
Build bridge; Window numbers:
Also allow 'diagonal rectangles'. Only usable in combination with HT_RECT or HT_POINT.
Functions related to sound.
StringID err_build_road
Building a normal piece of road.
static DiagDirection GetTunnelBridgeDirection(TileIndex t)
Get the direction pointing to the other end.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
void DeleteWindowByClass(WindowClass cls)
Delete all windows of a given class.
bool Failed() const
Did this command fail?
static const RoadTypeInfo _road_type_infos[]
What errors/cursors must be shown for several types of roads.
void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method)
Selects tiles while dragging.
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
Build toolbar; Window numbers:
TileIndex tile
The base tile of the area.
No window, redirects to WC_MAIN_WINDOW.
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
static Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
static TileIndex GetOtherTunnelBridgeEnd(TileIndex t)
Determines type of the wormhole and returns its other end.
Functions related to companies.
SpriteID cursor_autoroad
Cursor for building autoroad.
static TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
static bool _remove_button_clicked
Flag whether 'remove' toggle-button is currently enabled.
StationType
Station types.
StringID err_depot
Building a depot.
area of land in X and Y directions
static bool IsNormalRoadTile(TileIndex t)
Return whether a tile is a normal road tile.
GUISettings gui
settings related to the GUI
Align toward the toolbar.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
static void PlaceRoad_BusStation(TileIndex tile)
Callback for placing a bus station.
SpriteID cursor_nwse
Cursor for building NW and SE bits.
uint32 TileIndex
The index/ID of a Tile.
bool HandlePlacePushButton(Window *w, int widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
Draw all non-passenger class cargoes.
bool modified_catchment
different-size catchment areas
Build truck station; Window numbers:
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Functions related to zooming.
Transport by road vehicle.
StringID picker_tooltip[2]
Tooltip for the station picker for bus or truck stations.
bool confirm
Play sound effect on succesful constructions or other actions.
Non-water non-rail construction.
Functions related to commands.
Coordinates of a point in 2D.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-NULL) Titem.
special mode used for highlighting while dragging (and for tunnels/docks)
StringID err_build_station[2]
Building a bus or truck station.
Functions that have tunnels and bridges in common.
Offset at right to draw the frame rectangular area.
Window * ShowBuildRoadScenToolbar()
Show the road building toolbar in the scenario editor.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
static void PlaceRoad_TruckStation(TileIndex tile)
Callback for placing a truck station.
#define CMD_MSG(x)
Used to combine a StringID with the command.
Build bus station; Window numbers:
int32 WindowNumber
Number to differentiate different windows of the same class.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows)...
Specification of a rectangle with absolute coordinates of all edges.
The passed event is handled.
Flag for invalid railtype.
Functions related to tile highlights.
Window functions not directly related to making/drawing windows.
Find a place automatically.
static void PlaceRoadStop(TileIndex start_tile, TileIndex end_tile, uint32 p2, uint32 cmd)
Place a new road stop.
SpriteID cursor_nesw
Cursor for building NE and SW bits.
GUI functions that shouldn't be here.
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
uint16 h
The height of the area.
static bool RoadToolbar_CtrlChanged(Window *w)
Updates the Remove button because of Ctrl state change.
void CcRoadStop(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Command callback for building road stops.
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen)
Resize the window.
RoadFlags
Define the values of the RoadFlags.
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
Dimensions (a width and height) of a rectangle in 2D.
bool click_beep
Beep on a random selection of buttons.
Offset at left to draw the frame rectangular area.
StringID err_remove_station[2]
Removing of a bus or truck station.
Base class for windows opened from a toolbar.
static const NWidgetPart _nested_tram_station_picker_widgets[]
Widget definition of the build tram station window.
virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
The user has dragged over the map when the tile highlight mode has been set.