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,
132 STR_ERROR_CAN_T_BUILD_ROAD_HERE,
133 STR_ERROR_CAN_T_REMOVE_ROAD_FROM,
134 STR_ERROR_CAN_T_BUILD_ROAD_DEPOT,
135 { STR_ERROR_CAN_T_BUILD_BUS_STATION, STR_ERROR_CAN_T_BUILD_TRUCK_STATION },
136 { STR_ERROR_CAN_T_REMOVE_BUS_STATION, STR_ERROR_CAN_T_REMOVE_TRUCK_STATION },
137 { STR_STATION_BUILD_BUS_ORIENTATION, STR_STATION_BUILD_TRUCK_ORIENTATION },
138 { STR_STATION_BUILD_BUS_ORIENTATION_TOOLTIP, STR_STATION_BUILD_TRUCK_ORIENTATION_TOOLTIP },
140 SPR_CURSOR_ROAD_NESW,
141 SPR_CURSOR_ROAD_NWSE,
145 STR_ERROR_CAN_T_BUILD_TRAMWAY_HERE,
146 STR_ERROR_CAN_T_REMOVE_TRAMWAY_FROM,
147 STR_ERROR_CAN_T_BUILD_TRAM_DEPOT,
148 { STR_ERROR_CAN_T_BUILD_PASSENGER_TRAM_STATION, STR_ERROR_CAN_T_BUILD_CARGO_TRAM_STATION },
149 { STR_ERROR_CAN_T_REMOVE_PASSENGER_TRAM_STATION, STR_ERROR_CAN_T_REMOVE_CARGO_TRAM_STATION },
150 { STR_STATION_BUILD_PASSENGER_TRAM_ORIENTATION, STR_STATION_BUILD_CARGO_TRAM_ORIENTATION },
151 { STR_STATION_BUILD_PASSENGER_TRAM_ORIENTATION_TOOLTIP, STR_STATION_BUILD_CARGO_TRAM_ORIENTATION_TOOLTIP },
153 SPR_CURSOR_TRAMWAY_NESW,
154 SPR_CURSOR_TRAMWAY_NWSE,
177 if (result.
Failed())
return;
201 if (result.
Failed())
return;
206 TileArea roadstop_area(tile,
GB(p1, 0, 8),
GB(p1, 8, 8));
226 uint8 ddir = _road_station_picker_orientation;
227 SB(p2, 16, 16, INVALID_STATION);
249 if (_road_station_picker_orientation <
DIAGDIR_END) {
267 if (_road_station_picker_orientation <
DIAGDIR_END) {
276 typedef void OnButtonClick(
Window *w);
316 this->InitNested(window_number);
317 this->SetWidgetsDisabledState(
true,
322 this->OnInvalidateData();
340 if (!gui_scope)
return;
343 this->SetWidgetsDisabledState(!can_build,
365 switch (clicked_widget) {
379 this->SetWidgetDisabledState(
WID_ROT_REMOVE, !this->IsWidgetLowered(clicked_widget));
385 this->SetWidgetsDisabledState(!this->IsWidgetLowered(clicked_widget),
394 this->SetWidgetsDisabledState(
true,
398 this->SetWidgetsLoweredState(
false,
409 _one_way_button_clicked =
false;
413 this->last_started_action = widget;
418 this->last_started_action = widget;
423 this->last_started_action = widget;
428 this->last_started_action = widget;
434 ShowRoadDepotPicker(
this);
435 this->last_started_action = widget;
443 this->last_started_action = widget;
451 this->last_started_action = widget;
459 SetSelectionRed(
false);
464 this->last_started_action = widget;
469 this->last_started_action = widget;
480 default: NOT_REACHED();
496 switch (this->last_started_action) {
498 _place_road_flag = RF_DIR_X;
499 if (_tile_fract_coords.x >= 8) _place_road_flag |= RF_START_HALFROAD_X;
504 _place_road_flag = RF_DIR_Y;
505 if (_tile_fract_coords.y >= 8) _place_road_flag |= RF_START_HALFROAD_Y;
510 _place_road_flag = RF_NONE;
511 if (_tile_fract_coords.x >= 8) _place_road_flag |= RF_START_HALFROAD_X;
512 if (_tile_fract_coords.y >= 8) _place_road_flag |= RF_START_HALFROAD_Y;
521 DoCommandP(tile, _cur_roadtype << 2 | _road_depot_orientation, 0,
542 default: NOT_REACHED();
548 this->RaiseButtons();
549 this->SetWidgetsDisabledState(
true,
569 switch (select_proc) {
571 _place_road_flag &= ~RF_END_HALFROAD_X;
572 if (pt.x & 8) _place_road_flag |= RF_END_HALFROAD_X;
576 _place_road_flag &= ~RF_END_HALFROAD_Y;
577 if (pt.y & 8) _place_road_flag |= RF_END_HALFROAD_Y;
581 _place_road_flag &= ~(RF_END_HALFROAD_Y | RF_END_HALFROAD_X);
582 if (pt.y & 8) _place_road_flag |= RF_END_HALFROAD_Y;
583 if (pt.x & 8) _place_road_flag |= RF_END_HALFROAD_X;
588 ( (_tile_fract_coords.x < _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) < 16) ||
589 (_tile_fract_coords.x > _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) > 16) ))) {
591 _place_road_flag &= ~RF_DIR_Y;
594 _place_road_flag |= RF_DIR_Y;
609 switch (select_proc) {
610 default: NOT_REACHED();
627 _place_road_flag = (
RoadFlags)((_place_road_flag & RF_DIR_Y) ? (_place_road_flag & 0x07) : (_place_road_flag >> 3));
629 DoCommandP(start_tile, end_tile, _place_road_flag | (_cur_roadtype << 3) | (_one_way_button_clicked << 5),
681 switch (_game_mode) {
683 extern RoadType _last_built_roadtype;
700 static Hotkey roadtoolbar_hotkeys[] = {
717 static const NWidgetPart _nested_build_road_widgets[] = {
754 _nested_build_road_widgets,
lengthof(_nested_build_road_widgets),
755 &BuildRoadToolbarWindow::hotkeys
758 static const NWidgetPart _nested_build_tramway_widgets[] = {
794 _nested_build_tramway_widgets,
lengthof(_nested_build_tramway_widgets),
795 &BuildRoadToolbarWindow::hotkeys
808 _cur_roadtype = roadtype;
811 return AllocateWindowDescFront<BuildRoadToolbarWindow>(roadtype ==
ROADTYPE_ROAD ? &_build_road_desc : &_build_tramway_desc,
TRANSPORT_ROAD);
814 static const NWidgetPart _nested_build_road_scen_widgets[] = {
842 WDP_AUTO,
"toolbar_road_scen", 0, 0,
845 _nested_build_road_scen_widgets,
lengthof(_nested_build_road_scen_widgets),
846 &BuildRoadToolbarWindow::hotkeys
856 return AllocateWindowDescFront<BuildRoadToolbarWindow>(&_build_road_scen_desc,
TRANSPORT_ROAD);
862 this->CreateNestedTree();
866 this->GetWidget<NWidgetCore>(
WID_BROD_CAPTION)->widget_data = STR_BUILD_DEPOT_TRAM_ORIENTATION_CAPTION;
908 static const NWidgetPart _nested_build_road_depot_widgets[] = {
942 _nested_build_road_depot_widgets,
lengthof(_nested_build_road_depot_widgets)
945 static void ShowRoadDepotPicker(
Window *parent)
953 this->CreateNestedTree();
962 this->GetWidget<NWidgetCore>(i)->tool_tip = _road_type_infos[_cur_roadtype].
picker_tooltip[rs];
965 this->LowerWidget(_road_station_picker_orientation + WID_BROS_STATION_NE);
984 SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
1089 SetDataTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
1091 SetDataTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
1102 _nested_road_station_picker_widgets,
lengthof(_nested_road_station_picker_widgets)
1127 SetDataTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
1129 SetDataTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
1140 _nested_tram_station_picker_widgets,
lengthof(_nested_tram_station_picker_widgets)
1148 void InitializeRoadGui()
1151 _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.
virtual void OnTick()
Called once per (game) tick.
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)
void CcRoadStop(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
Command callback for building road stops.
bool CanBuildVehicleInfrastructure(VehicleType type)
Check whether we can build infrastructure for the given vehicle type.
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.
void CcBuildRoadTunnel(const CommandCost &result, TileIndex start_tile, uint32 p1, uint32 p2)
Callback executed after a build road tunnel command has been called.
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.
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.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset)
Mark a tile given by its index dirty for repaint.
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 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.