tron@2186: /* $Id$ */ tron@2186: glx@9574: /** @file road_gui.cpp */ glx@9574: truelight@0: #include "stdafx.h" Darkvater@1891: #include "openttd.h" truelight@0: #include "gui.h" rubidium@9723: #include "window_gui.h" rubidium@9723: #include "station_gui.h" rubidium@9723: #include "terraform_gui.h" rubidium@9723: #include "viewport_func.h" rubidium@9723: #include "gfx_func.h" rubidium@9723: #include "command_func.h" tron@2159: #include "variables.h" rubidium@9723: #include "road_type.h" glx@9624: #include "road_cmd.h" glx@9624: #include "road_map.h" rubidium@6338: #include "station_map.h" rubidium@9723: #include "functions.h" rubidium@9723: #include "window_func.h" rubidium@9723: #include "vehicle_func.h" rubidium@9723: #include "sound_func.h" rubidium@9724: #include "player_func.h" rubidium@9724: #include "settings_type.h" Celestar@568: rubidium@9724: #include "table/sprites.h" rubidium@9724: #include "table/strings.h" truelight@0: rubidium@9837: static void ShowRVStationPicker(RoadStopType rs); rubidium@6573: static void ShowRoadDepotPicker(); truelight@0: truelight@0: static bool _remove_button_clicked; rubidium@9722: static bool _one_way_button_clicked; truelight@0: rubidium@9722: /** rubidium@9722: * Define the values of the RoadFlags rubidium@9722: * @see CmdBuildLongRoad rubidium@9722: */ rubidium@9722: enum RoadFlags { rubidium@9722: RF_NONE = 0x00, rubidium@9722: RF_START_HALFROAD_Y = 0x01, // The start tile in Y-dir should have only a half road rubidium@9722: RF_END_HALFROAD_Y = 0x02, // The end tile in Y-dir should have only a half road rubidium@9722: RF_DIR_Y = 0x04, // The direction is Y-dir rubidium@9722: RF_DIR_X = RF_NONE, // Dummy; Dir X is set when RF_DIR_Y is not set rubidium@9722: RF_START_HALFROAD_X = 0x08, // The start tile in X-dir should have only a half road rubidium@9722: RF_END_HALFROAD_X = 0x10, // The end tile in X-dir should have only a half road rubidium@9722: }; rubidium@9722: DECLARE_ENUM_AS_BIT_SET(RoadFlags); rubidium@9722: rubidium@9722: static RoadFlags _place_road_flag; truelight@0: glx@9624: static RoadType _cur_roadtype; glx@9624: rubidium@5838: static DiagDirection _road_depot_orientation; rubidium@5838: static DiagDirection _road_station_picker_orientation; truelight@0: tron@1977: void CcPlaySound1D(bool success, TileIndex tile, uint32 p1, uint32 p2) truelight@0: { tron@541: if (success) SndPlayTileFx(SND_1F_SPLAT, tile); truelight@0: } truelight@0: rubidium@9722: /** rubidium@9722: * Set the initial flags for the road constuction. rubidium@9722: * The flags are: rubidium@9722: * @li The direction is the X-dir rubidium@9722: * @li The first tile has a partitial RoadBit (true or false) rubidium@9722: * rubidium@9722: * @param tile The start tile rubidium@9722: */ rubidium@9722: static void PlaceRoad_X_Dir(TileIndex tile) truelight@0: { rubidium@9722: _place_road_flag = RF_DIR_X; rubidium@9722: if (_tile_fract_coords.x >= 8) _place_road_flag |= RF_START_HALFROAD_X; rubidium@9722: VpStartPlaceSizing(tile, VPM_FIX_Y, DDSP_PLACE_ROAD_X_DIR); truelight@0: } truelight@0: rubidium@9722: /** rubidium@9722: * Set the initial flags for the road constuction. rubidium@9722: * The flags are: rubidium@9722: * @li The direction is the Y-dir rubidium@9722: * @li The first tile has a partitial RoadBit (true or false) rubidium@9722: * rubidium@9722: * @param tile The start tile rubidium@9722: */ rubidium@9722: static void PlaceRoad_Y_Dir(TileIndex tile) truelight@0: { rubidium@9722: _place_road_flag = RF_DIR_Y; rubidium@9722: if (_tile_fract_coords.y >= 8) _place_road_flag |= RF_START_HALFROAD_Y; rubidium@9722: VpStartPlaceSizing(tile, VPM_FIX_X, DDSP_PLACE_ROAD_Y_DIR); rubidium@9722: } rubidium@9722: rubidium@9722: /** rubidium@9722: * Set the initial flags for the road constuction. rubidium@9722: * The flags are: rubidium@9722: * @li The direction is not set. rubidium@9722: * @li The first tile has a partitial RoadBit (true or false) rubidium@9722: * rubidium@9722: * @param tile The start tile rubidium@9722: */ rubidium@9722: static void PlaceRoad_AutoRoad(TileIndex tile) rubidium@9722: { rubidium@9722: _place_road_flag = RF_NONE; rubidium@9722: if (_tile_fract_coords.x >= 8) _place_road_flag |= RF_START_HALFROAD_X; rubidium@9722: if (_tile_fract_coords.y >= 8) _place_road_flag |= RF_START_HALFROAD_Y; rubidium@9722: VpStartPlaceSizing(tile, VPM_X_OR_Y, DDSP_PLACE_AUTOROAD); truelight@0: } truelight@0: tron@1977: static void PlaceRoad_Bridge(TileIndex tile) truelight@0: { glx@9624: VpStartPlaceSizing(tile, VPM_X_OR_Y, DDSP_BUILD_BRIDGE); truelight@0: } truelight@0: truelight@0: tron@1977: void CcBuildRoadTunnel(bool success, TileIndex tile, uint32 p1, uint32 p2) truelight@0: { truelight@0: if (success) { tron@541: SndPlayTileFx(SND_20_SPLAT_2, tile); truelight@0: ResetObjectToPlace(); truelight@0: } else { truelight@0: SetRedErrorSquare(_build_tunnel_endtile); truelight@0: } truelight@0: } truelight@0: glx@9624: /** Structure holding information per roadtype for several functions */ glx@9624: struct RoadTypeInfo { glx@9624: StringID err_build_road; ///< Building a normal piece of road glx@9624: StringID err_remove_road; ///< Removing a normal piece of road glx@9624: StringID err_depot; ///< Building a depot glx@9624: StringID err_build_station[2]; ///< Building a bus or truck station glx@9624: StringID err_remove_station[2]; ///< Removing of a bus or truck station glx@9624: rubidium@9625: StringID picker_title[2]; ///< Title for the station picker for bus or truck stations rubidium@9625: StringID picker_tooltip[2]; ///< Tooltip for the station picker for bus or truck stations rubidium@9625: glx@9624: SpriteID cursor_nesw; ///< Cursor for building NE and SW bits glx@9624: SpriteID cursor_nwse; ///< Cursor for building NW and SE bits rubidium@9722: SpriteID cursor_autoroad; ///< Cursor for building autoroad glx@9624: }; glx@9624: glx@9624: /** What errors/cursors must be shown for several types of roads */ glx@9624: static const RoadTypeInfo _road_type_infos[] = { glx@9624: { glx@9624: STR_1804_CAN_T_BUILD_ROAD_HERE, glx@9624: STR_1805_CAN_T_REMOVE_ROAD_FROM, glx@9624: STR_1807_CAN_T_BUILD_ROAD_VEHICLE, rubidium@9625: { STR_1808_CAN_T_BUILD_BUS_STATION, STR_1809_CAN_T_BUILD_TRUCK_STATION }, rubidium@9625: { STR_CAN_T_REMOVE_BUS_STATION, STR_CAN_T_REMOVE_TRUCK_STATION }, rubidium@9625: { STR_3042_BUS_STATION_ORIENTATION, STR_3043_TRUCK_STATION_ORIENT }, rubidium@9625: { STR_3051_SELECT_BUS_STATION_ORIENTATION, STR_3052_SELECT_TRUCK_LOADING_BAY }, glx@9624: glx@9624: SPR_CURSOR_ROAD_NESW, glx@9624: SPR_CURSOR_ROAD_NWSE, rubidium@9722: SPR_CURSOR_AUTOROAD, glx@9624: }, rubidium@9625: { rubidium@9724: STR_CAN_T_BUILD_TRAMWAY_HERE, rubidium@9724: STR_CAN_T_REMOVE_TRAMWAY_FROM, rubidium@9724: STR_CAN_T_BUILD_TRAM_VEHICLE, rubidium@9724: { STR_CAN_T_BUILD_PASSENGER_TRAM_STATION, STR_CAN_T_BUILD_CARGO_TRAM_STATION }, rubidium@9724: { STR_CAN_T_REMOVE_PASSENGER_TRAM_STATION, STR_CAN_T_REMOVE_CARGO_TRAM_STATION }, rubidium@9724: { STR_PASSENGER_TRAM_STATION_ORIENTATION, STR_CARGO_TRAM_STATION_ORIENT }, rubidium@9724: { STR_SELECT_PASSENGER_TRAM_STATION_ORIENTATION, STR_SELECT_CARGO_TRAM_STATION_ORIENTATION }, rubidium@9625: rubidium@9625: SPR_CURSOR_TRAMWAY_NESW, rubidium@9625: SPR_CURSOR_TRAMWAY_NWSE, rubidium@9722: SPR_CURSOR_AUTOTRAM, rubidium@9625: }, glx@9624: }; glx@9624: tron@1977: static void PlaceRoad_Tunnel(TileIndex tile) truelight@0: { rubidium@9703: DoCommandP(tile, 0x200 | RoadTypeToRoadTypes(_cur_roadtype), 0, CcBuildRoadTunnel, CMD_BUILD_TUNNEL | CMD_MSG(STR_5016_CAN_T_BUILD_TUNNEL_HERE)); truelight@0: } truelight@0: tron@3151: static void BuildRoadOutsideStation(TileIndex tile, DiagDirection direction) truelight@0: { Darkvater@4559: tile += TileOffsByDiagDir(direction); darkvater@5: // if there is a roadpiece just outside of the station entrance, build a connecting route glx@9732: if (IsNormalRoadTile(tile)) { glx@9624: if (GetRoadBits(tile, _cur_roadtype) != ROAD_NONE) { glx@9624: DoCommandP(tile, _cur_roadtype << 4 | DiagDirToRoadBits(ReverseDiagDir(direction)), 0, NULL, CMD_BUILD_ROAD); glx@9624: } truelight@0: } truelight@0: } truelight@0: tron@1977: void CcRoadDepot(bool success, TileIndex tile, uint32 p1, uint32 p2) truelight@0: { truelight@0: if (success) { glx@9624: DiagDirection dir = (DiagDirection)GB(p1, 0, 2); tron@541: SndPlayTileFx(SND_1F_SPLAT, tile); truelight@0: ResetObjectToPlace(); glx@9624: BuildRoadOutsideStation(tile, dir); rubidium@6428: /* For a drive-through road stop build connecting road for other entrance */ rubidium@9722: if (HasBit(p2, 1)) BuildRoadOutsideStation(tile, ReverseDiagDir(dir)); truelight@0: } truelight@0: } truelight@0: tron@1977: static void PlaceRoad_Depot(TileIndex tile) truelight@0: { rubidium@9703: DoCommandP(tile, _cur_roadtype << 2 | _road_depot_orientation, 0, CcRoadDepot, CMD_BUILD_ROAD_DEPOT | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_depot)); truelight@0: } truelight@0: rubidium@6338: static void PlaceRoadStop(TileIndex tile, uint32 p2, uint32 cmd) rubidium@6338: { rubidium@6338: uint32 p1 = _road_station_picker_orientation; rubidium@6338: rubidium@6338: if (p1 >= DIAGDIR_END) { rubidium@9722: SetBit(p2, 1); // It's a drive-through stop rubidium@6338: p1 -= DIAGDIR_END; // Adjust picker result to actual direction rubidium@6338: } rubidium@6338: DoCommandP(tile, p1, p2, CcRoadDepot, cmd); rubidium@6338: } rubidium@6338: tron@1977: static void PlaceRoad_BusStation(TileIndex tile) truelight@0: { rubidium@6338: if (_remove_button_clicked) { rubidium@9837: DoCommandP(tile, 0, ROADSTOP_BUS, CcPlaySound1D, CMD_REMOVE_ROAD_STOP | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_station[ROADSTOP_BUS])); rubidium@6338: } else { rubidium@9837: PlaceRoadStop(tile, (_ctrl_pressed << 5) | RoadTypeToRoadTypes(_cur_roadtype) << 2 | ROADSTOP_BUS, CMD_BUILD_ROAD_STOP | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_station[ROADSTOP_BUS])); rubidium@6338: } truelight@0: } truelight@0: tron@1977: static void PlaceRoad_TruckStation(TileIndex tile) truelight@0: { rubidium@6338: if (_remove_button_clicked) { rubidium@9837: DoCommandP(tile, 0, ROADSTOP_TRUCK, CcPlaySound1D, CMD_REMOVE_ROAD_STOP | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_station[ROADSTOP_TRUCK])); rubidium@6338: } else { rubidium@9837: PlaceRoadStop(tile, (_ctrl_pressed << 5) | RoadTypeToRoadTypes(_cur_roadtype) << 2 | ROADSTOP_TRUCK, CMD_BUILD_ROAD_STOP | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_station[ROADSTOP_TRUCK])); rubidium@6338: } truelight@0: } truelight@0: tron@1977: static void PlaceRoad_DemolishArea(TileIndex tile) truelight@0: { glx@9624: VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_DEMOLISH_AREA); truelight@0: } truelight@0: truelight@9718: /** Enum referring to the widgets of the build road toolbar */ truelight@9718: enum RoadToolbarWidgets { truelight@9718: RTW_CLOSEBOX = 0, truelight@9718: RTW_CAPTION, truelight@9718: RTW_STICKY, truelight@9718: RTW_ROAD_X, truelight@9718: RTW_ROAD_Y, rubidium@9722: RTW_AUTOROAD, truelight@9718: RTW_DEMOLISH, truelight@9718: RTW_DEPOT, truelight@9718: RTW_BUS_STATION, truelight@9718: RTW_TRUCK_STATION, rubidium@9722: RTW_ONE_WAY, truelight@9718: RTW_BUILD_BRIDGE, truelight@9718: RTW_BUILD_TUNNEL, truelight@9718: RTW_REMOVE, tron@5147: }; tron@5147: truelight@0: typedef void OnButtonClick(Window *w); truelight@0: glx@9732: glx@9732: /** Toogles state of the Remove button of Build road toolbar glx@9732: * @param w window the button belongs to glx@9732: */ glx@9732: static void ToggleRoadButton_Remove(Window *w) glx@9732: { glx@9732: w->ToggleWidgetLoweredState(RTW_REMOVE); glx@9732: w->InvalidateWidget(RTW_REMOVE); glx@9732: _remove_button_clicked = w->IsWidgetLowered(RTW_REMOVE); glx@9732: SetSelectionRed(_remove_button_clicked); glx@9732: } glx@9732: glx@9732: /** Updates the Remove button because of Ctrl state change glx@9732: * @param w window the button belongs to glx@9732: * @return true iff the remove buton was changed glx@9732: */ glx@9732: static bool RoadToolbar_CtrlChanged(Window *w) glx@9732: { glx@9732: if (w->IsWidgetDisabled(RTW_REMOVE)) return false; glx@9732: glx@9732: /* allow ctrl to switch remove mode only for these widgets */ glx@9732: for (uint i = RTW_ROAD_X; i <= RTW_AUTOROAD; i++) { glx@9732: if (w->IsWidgetLowered(i)) { glx@9732: ToggleRoadButton_Remove(w); glx@9732: return true; glx@9732: } glx@9732: } glx@9732: glx@9732: return false; glx@9732: } glx@9732: glx@9732: rubidium@9722: /** rubidium@9722: * Function that handles the click on the rubidium@9722: * X road placement button. rubidium@9722: * rubidium@9722: * @param w The current window rubidium@9722: */ rubidium@9722: static void BuildRoadClick_X_Dir(Window *w) truelight@0: { rubidium@9722: HandlePlacePushButton(w, RTW_ROAD_X, _road_type_infos[_cur_roadtype].cursor_nwse, VHM_RECT, PlaceRoad_X_Dir); truelight@0: } truelight@0: rubidium@9722: /** rubidium@9722: * Function that handles the click on the rubidium@9722: * Y road placement button. rubidium@9722: * rubidium@9722: * @param w The current window rubidium@9722: */ rubidium@9722: static void BuildRoadClick_Y_Dir(Window *w) truelight@0: { rubidium@9722: HandlePlacePushButton(w, RTW_ROAD_Y, _road_type_infos[_cur_roadtype].cursor_nesw, VHM_RECT, PlaceRoad_Y_Dir); truelight@0: } truelight@0: rubidium@9722: /** rubidium@9722: * Function that handles the click on the rubidium@9722: * autoroad placement button. rubidium@9722: * rubidium@9722: * @param w The current window rubidium@9722: */ rubidium@9722: static void BuildRoadClick_AutoRoad(Window *w) rubidium@9722: { rubidium@9722: HandlePlacePushButton(w, RTW_AUTOROAD, _road_type_infos[_cur_roadtype].cursor_autoroad, VHM_RECT, PlaceRoad_AutoRoad); rubidium@9722: } truelight@0: truelight@0: static void BuildRoadClick_Demolish(Window *w) truelight@0: { rubidium@9722: HandlePlacePushButton(w, RTW_DEMOLISH, ANIMCURSOR_DEMOLISH, VHM_RECT, PlaceRoad_DemolishArea); truelight@0: } truelight@0: truelight@0: static void BuildRoadClick_Depot(Window *w) truelight@0: { rubidium@9631: if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(VEH_ROAD)) return; rubidium@9722: if (HandlePlacePushButton(w, RTW_DEPOT, SPR_CURSOR_ROAD_DEPOT, VHM_RECT, PlaceRoad_Depot)) ShowRoadDepotPicker(); truelight@0: } truelight@0: truelight@0: static void BuildRoadClick_BusStation(Window *w) truelight@0: { rubidium@9631: if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(VEH_ROAD)) return; rubidium@9837: if (HandlePlacePushButton(w, RTW_BUS_STATION, SPR_CURSOR_BUS_STATION, VHM_RECT, PlaceRoad_BusStation)) ShowRVStationPicker(ROADSTOP_BUS); truelight@0: } truelight@0: truelight@0: static void BuildRoadClick_TruckStation(Window *w) truelight@0: { rubidium@9631: if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(VEH_ROAD)) return; rubidium@9837: if (HandlePlacePushButton(w, RTW_TRUCK_STATION, SPR_CURSOR_TRUCK_STATION, VHM_RECT, PlaceRoad_TruckStation)) ShowRVStationPicker(ROADSTOP_TRUCK); rubidium@9722: } rubidium@9722: rubidium@9722: /** rubidium@9722: * Function that handles the click on the rubidium@9722: * one way road button. rubidium@9722: * rubidium@9722: * @param w The current window rubidium@9722: */ rubidium@9722: static void BuildRoadClick_OneWay(Window *w) rubidium@9722: { rubidium@9723: if (w->IsWidgetDisabled(RTW_ONE_WAY)) return; rubidium@9722: SetWindowDirty(w); rubidium@9723: w->ToggleWidgetLoweredState(RTW_ONE_WAY); rubidium@9722: SetSelectionRed(false); truelight@0: } truelight@0: truelight@0: static void BuildRoadClick_Bridge(Window *w) truelight@0: { rubidium@9722: HandlePlacePushButton(w, RTW_BUILD_BRIDGE, SPR_CURSOR_BRIDGE, VHM_RECT, PlaceRoad_Bridge); truelight@0: } truelight@0: truelight@0: static void BuildRoadClick_Tunnel(Window *w) truelight@0: { rubidium@9722: HandlePlacePushButton(w, RTW_BUILD_TUNNEL, SPR_CURSOR_ROAD_TUNNEL, VHM_SPECIAL, PlaceRoad_Tunnel); truelight@0: } truelight@0: truelight@0: static void BuildRoadClick_Remove(Window *w) truelight@0: { rubidium@9723: if (w->IsWidgetDisabled(RTW_REMOVE)) return; glx@9732: ToggleRoadButton_Remove(w); tron@541: SndPlayFx(SND_15_BEEP); truelight@0: } truelight@0: rubidium@9722: /** Array with the handlers of the button-clicks for the road-toolbar */ tron@2639: static OnButtonClick* const _build_road_button_proc[] = { rubidium@9722: BuildRoadClick_X_Dir, rubidium@9722: BuildRoadClick_Y_Dir, rubidium@9722: BuildRoadClick_AutoRoad, truelight@0: BuildRoadClick_Demolish, truelight@0: BuildRoadClick_Depot, truelight@0: BuildRoadClick_BusStation, truelight@0: BuildRoadClick_TruckStation, rubidium@9722: BuildRoadClick_OneWay, truelight@0: BuildRoadClick_Bridge, truelight@0: BuildRoadClick_Tunnel, tron@5933: BuildRoadClick_Remove truelight@0: }; truelight@0: rubidium@9722: /** Array with the keycode of the button-clicks for the road-toolbar */ truelight@9718: static const uint16 _road_keycodes[] = { truelight@9718: '1', truelight@9718: '2', truelight@9718: '3', truelight@9718: '4', truelight@9718: '5', truelight@9718: '6', rubidium@9722: '7', rubidium@9722: '8', truelight@9718: 'B', truelight@9718: 'T', truelight@9718: 'R', truelight@9718: }; truelight@9718: truelight@9718: /** truelight@9718: * Update the remove button lowered state of the road toolbar truelight@9718: * truelight@9718: * @param w The toolbar window truelight@9718: * @param clicked_widget The widget which the player clicked just now truelight@9718: */ rubidium@9722: static void UpdateOptionWidgetStatus(Window *w, int clicked_widget) truelight@9718: { rubidium@9722: /* The remove and the one way button state is driven rubidium@9722: * by the other buttons so they don't act on themselfs. rubidium@9722: * Both are only valid if they are able to apply as options. */ truelight@9718: switch (clicked_widget) { truelight@9718: case RTW_REMOVE: rubidium@9723: w->RaiseWidget(RTW_ONE_WAY); rubidium@9826: w->InvalidateWidget(RTW_ONE_WAY); rubidium@9722: break; rubidium@9722: case RTW_ONE_WAY: rubidium@9723: w->RaiseWidget(RTW_REMOVE); rubidium@9826: w->InvalidateWidget(RTW_REMOVE); rubidium@9722: break; rubidium@9722: case RTW_BUS_STATION: rubidium@9722: case RTW_TRUCK_STATION: rubidium@9723: w->DisableWidget(RTW_ONE_WAY); rubidium@9723: w->SetWidgetDisabledState(RTW_REMOVE, !w->IsWidgetLowered(clicked_widget)); truelight@9718: break; truelight@9718: case RTW_ROAD_X: truelight@9718: case RTW_ROAD_Y: rubidium@9722: case RTW_AUTOROAD: rubidium@9723: w->SetWidgetsDisabledState(!w->IsWidgetLowered(clicked_widget), rubidium@9722: RTW_REMOVE, rubidium@9722: RTW_ONE_WAY, rubidium@9722: WIDGET_LIST_END); truelight@9718: break; truelight@9718: default: truelight@9718: /* When any other buttons than road/station, raise and truelight@9718: * disable the removal button */ rubidium@9723: w->SetWidgetsDisabledState(true, rubidium@9722: RTW_REMOVE, rubidium@9722: RTW_ONE_WAY, rubidium@9722: WIDGET_LIST_END); rubidium@9723: w->SetWidgetsLoweredState (false, rubidium@9722: RTW_REMOVE, rubidium@9722: RTW_ONE_WAY, rubidium@9722: WIDGET_LIST_END); truelight@9718: break; truelight@9718: } truelight@9718: } truelight@9718: belugas@4171: static void BuildRoadToolbWndProc(Window *w, WindowEvent *e) tron@2639: { tron@2639: switch (e->event) { rubidium@9722: case WE_CREATE: rubidium@9723: w->SetWidgetsDisabledState(true, rubidium@9722: RTW_REMOVE, rubidium@9722: RTW_ONE_WAY, rubidium@9722: WIDGET_LIST_END); rubidium@9722: break; glx@5105: truelight@0: case WE_PAINT: rubidium@9723: w->SetWidgetsDisabledState(!CanBuildVehicleInfrastructure(VEH_ROAD), truelight@9718: RTW_DEPOT, truelight@9718: RTW_BUS_STATION, truelight@9718: RTW_TRUCK_STATION, truelight@9718: WIDGET_LIST_END); truelight@0: DrawWindowWidgets(w); truelight@0: break; truelight@0: truelight@9718: case WE_CLICK: truelight@9718: if (e->we.click.widget >= RTW_ROAD_X) { truelight@9718: _remove_button_clicked = false; rubidium@9722: _one_way_button_clicked = false; truelight@9718: _build_road_button_proc[e->we.click.widget - RTW_ROAD_X](w); truelight@9718: } rubidium@9722: UpdateOptionWidgetStatus(w, e->we.click.widget); glx@9732: if (_ctrl_pressed) RoadToolbar_CtrlChanged(w); truelight@9718: break; truelight@0: truelight@0: case WE_KEYPRESS: truelight@9718: for (uint8 i = 0; i != lengthof(_road_keycodes); i++) { truelight@9718: if (e->we.keypress.keycode == _road_keycodes[i]) { truelight@9718: e->we.keypress.cont = false; truelight@9718: _remove_button_clicked = false; rubidium@9722: _one_way_button_clicked = false; truelight@9718: _build_road_button_proc[i](w); rubidium@9722: UpdateOptionWidgetStatus(w, i + RTW_ROAD_X); glx@9732: if (_ctrl_pressed) RoadToolbar_CtrlChanged(w); truelight@9718: break; truelight@9718: } truelight@0: } darkvater@756: MarkTileDirty(_thd.pos.x, _thd.pos.y); // redraw tile selection truelight@0: break; truelight@0: truelight@0: case WE_PLACE_OBJ: rubidium@9723: _remove_button_clicked = w->IsWidgetLowered(RTW_REMOVE); rubidium@9723: _one_way_button_clicked = w->IsWidgetLowered(RTW_ONE_WAY); belugas@4634: _place_proc(e->we.place.tile); truelight@0: break; truelight@0: truelight@0: case WE_ABORT_PLACE_OBJ: rubidium@9723: w->RaiseButtons(); rubidium@9723: w->SetWidgetsDisabledState(true, rubidium@9723: RTW_REMOVE, rubidium@9723: RTW_ONE_WAY, rubidium@9723: WIDGET_LIST_END); rubidium@9723: w->InvalidateWidget(RTW_REMOVE); rubidium@9723: w->InvalidateWidget(RTW_ONE_WAY); truelight@0: truelight@0: w = FindWindowById(WC_BUS_STATION, 0); rubidium@9601: if (w != NULL) WP(w, def_d).close = true; truelight@0: w = FindWindowById(WC_TRUCK_STATION, 0); rubidium@9601: if (w != NULL) WP(w, def_d).close = true; truelight@0: w = FindWindowById(WC_BUILD_DEPOT, 0); rubidium@9601: if (w != NULL) WP(w, def_d).close = true; truelight@0: break; truelight@0: glx@9624: case WE_PLACE_DRAG: rubidium@9722: /* Here we update the end tile flags rubidium@9722: * of the road placement actions. rubidium@9722: * At first we reset the end halfroad rubidium@9722: * bits and if needed we set them again. */ glx@9624: switch (e->we.place.select_proc) { rubidium@9722: case DDSP_PLACE_ROAD_X_DIR: rubidium@9722: _place_road_flag &= ~RF_END_HALFROAD_X; rubidium@9722: if (e->we.place.pt.x & 8) _place_road_flag |= RF_END_HALFROAD_X; belugas@4435: break; belugas@4435: rubidium@9722: case DDSP_PLACE_ROAD_Y_DIR: rubidium@9722: _place_road_flag &= ~RF_END_HALFROAD_Y; rubidium@9722: if (e->we.place.pt.y & 8) _place_road_flag |= RF_END_HALFROAD_Y; rubidium@9722: break; rubidium@9722: rubidium@9722: case DDSP_PLACE_AUTOROAD: rubidium@9722: _place_road_flag &= ~(RF_END_HALFROAD_Y | RF_END_HALFROAD_X); rubidium@9722: if (e->we.place.pt.y & 8) _place_road_flag |= RF_END_HALFROAD_Y; rubidium@9722: if (e->we.place.pt.x & 8) _place_road_flag |= RF_END_HALFROAD_X; rubidium@9722: rubidium@9722: /* For autoroad we need to update the rubidium@9722: * direction of the road */ rubidium@9722: if (_thd.size.x > _thd.size.y || (_thd.size.x == _thd.size.y && rubidium@9722: ( (_tile_fract_coords.x < _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) < 16) || rubidium@9722: (_tile_fract_coords.x > _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) > 16) ))) { rubidium@9722: /* Set dir = X */ rubidium@9722: _place_road_flag &= ~RF_DIR_Y; rubidium@9722: } else { rubidium@9722: /* Set dir = Y */ rubidium@9722: _place_road_flag |= RF_DIR_Y; rubidium@9722: } rubidium@9722: belugas@4435: break; truelight@0: } truelight@193: glx@9624: VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.select_method); truelight@0: return; truelight@0: truelight@0: case WE_PLACE_MOUSEUP: belugas@4634: if (e->we.place.pt.x != -1) { belugas@4634: TileIndex start_tile = e->we.place.starttile; belugas@4634: TileIndex end_tile = e->we.place.tile; tron@1977: glx@9624: switch (e->we.place.select_proc) { glx@9624: case DDSP_BUILD_BRIDGE: glx@9624: ResetObjectToPlace(); glx@9732: ShowBuildBridgeWindow(start_tile, end_tile, TRANSPORT_ROAD, RoadTypeToRoadTypes(_cur_roadtype)); glx@9624: break; glx@9624: glx@9624: case DDSP_DEMOLISH_AREA: glx@9624: DoCommandP(end_tile, start_tile, 0, CcPlaySound10, CMD_CLEAR_AREA | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA)); glx@9624: break; glx@9624: rubidium@9722: case DDSP_PLACE_ROAD_X_DIR: rubidium@9722: case DDSP_PLACE_ROAD_Y_DIR: rubidium@9722: case DDSP_PLACE_AUTOROAD: rubidium@9722: /* Flag description: rubidium@9722: * Use the first three bits (0x07) if dir == Y rubidium@9722: * else use the last 2 bits (X dir has rubidium@9722: * not the 3rd bit set) */ rubidium@9722: _place_road_flag = (RoadFlags)((_place_road_flag & RF_DIR_Y) ? (_place_road_flag & 0x07) : (_place_road_flag >> 3)); rubidium@9722: rubidium@9722: DoCommandP(end_tile, start_tile, _place_road_flag | (_cur_roadtype << 3) | (_one_way_button_clicked << 5), CcPlaySound1D, rubidium@9722: (_ctrl_pressed || _remove_button_clicked) ? rubidium@9703: CMD_REMOVE_LONG_ROAD | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_road) : rubidium@9703: CMD_BUILD_LONG_ROAD | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_road)); glx@9624: break; truelight@0: } truelight@0: } truelight@0: break; truelight@0: truelight@0: case WE_PLACE_PRESIZE: { belugas@4634: TileIndex tile = e->we.place.tile; tron@1977: glx@9624: DoCommand(tile, 0x200 | RoadTypeToRoadTypes(_cur_roadtype), 0, DC_AUTO, CMD_BUILD_TUNNEL); tron@4000: VpSetPresizeRange(tile, _build_tunnel_endtile == 0 ? tile : _build_tunnel_endtile); truelight@0: break; truelight@0: } peter1138@2619: peter1138@2619: case WE_DESTROY: peter1138@2619: if (_patches.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0); peter1138@2619: break; glx@9732: glx@9732: case WE_CTRL_CHANGED: glx@9732: if (RoadToolbar_CtrlChanged(w)) e->we.ctrl.cont = false; glx@9732: break; truelight@0: } truelight@0: } truelight@0: truelight@9718: /** Widget definition of the build road toolbar */ truelight@0: static const Widget _build_road_widgets[] = { truelight@9718: { WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // RTW_CLOSEBOX rubidium@9722: { WWT_CAPTION, RESIZE_NONE, 7, 11, 250, 0, 13, STR_1802_ROAD_CONSTRUCTION, STR_018C_WINDOW_TITLE_DRAG_THIS}, // RTW_CAPTION rubidium@9722: { WWT_STICKYBOX, RESIZE_NONE, 7, 251, 262, 0, 13, 0x0, STR_STICKY_BUTTON}, // RTW_STICKY dominik@606: rubidium@9722: { WWT_IMGBTN, RESIZE_NONE, 7, 0, 21, 14, 35, SPR_IMG_ROAD_X_DIR, STR_180B_BUILD_ROAD_SECTION}, // RTW_ROAD_X rubidium@9722: { WWT_IMGBTN, RESIZE_NONE, 7, 22, 43, 14, 35, SPR_IMG_ROAD_Y_DIR, STR_180B_BUILD_ROAD_SECTION}, // RTW_ROAD_Y rubidium@9722: { WWT_IMGBTN, RESIZE_NONE, 7, 44, 65, 14, 35, SPR_IMG_AUTOROAD, STR_BUILD_AUTOROAD_TIP}, // RTW_AUTOROAD rubidium@9722: { WWT_IMGBTN, RESIZE_NONE, 7, 66, 87, 14, 35, SPR_IMG_DYNAMITE, STR_018D_DEMOLISH_BUILDINGS_ETC}, // RTW_DEMOLISH rubidium@9722: { WWT_IMGBTN, RESIZE_NONE, 7, 88, 109, 14, 35, SPR_IMG_ROAD_DEPOT, STR_180C_BUILD_ROAD_VEHICLE_DEPOT}, // RTW_DEPOT rubidium@9722: { WWT_IMGBTN, RESIZE_NONE, 7, 110, 131, 14, 35, SPR_IMG_BUS_STATION, STR_180D_BUILD_BUS_STATION}, // RTW_BUS_STATION rubidium@9722: { WWT_IMGBTN, RESIZE_NONE, 7, 132, 153, 14, 35, SPR_IMG_TRUCK_BAY, STR_180E_BUILD_TRUCK_LOADING_BAY}, // RTW_TRUCK_STATION rubidium@9722: { WWT_IMGBTN, RESIZE_NONE, 7, 154, 175, 14, 35, SPR_IMG_ROAD_ONE_WAY, STR_TOGGLE_ONE_WAY_ROAD}, // RTW_ONE_WAY rubidium@9722: { WWT_IMGBTN, RESIZE_NONE, 7, 176, 218, 14, 35, SPR_IMG_BRIDGE, STR_180F_BUILD_ROAD_BRIDGE}, // RTW_BUILD_BRIDGE rubidium@9722: { WWT_IMGBTN, RESIZE_NONE, 7, 219, 240, 14, 35, SPR_IMG_ROAD_TUNNEL, STR_1810_BUILD_ROAD_TUNNEL}, // RTW_BUILD_TUNNEL rubidium@9722: { WWT_IMGBTN, RESIZE_NONE, 7, 241, 262, 14, 35, SPR_IMG_REMOVE, STR_1811_TOGGLE_BUILD_REMOVE_FOR}, // RTW_REMOVE rubidium@9722: darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _build_road_desc = { rubidium@9722: WDP_ALIGN_TBR, 22, 263, 36, 263, 36, rubidium@6144: WC_BUILD_TOOLBAR, WC_NONE, darkvater@756: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON, truelight@0: _build_road_widgets, truelight@0: BuildRoadToolbWndProc truelight@0: }; truelight@0: truelight@9718: /** Widget definition of the build tram toolbar */ rubidium@9625: static const Widget _build_tramway_widgets[] = { rubidium@9724: { WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // RTW_CLOSEBOX rubidium@9724: { WWT_CAPTION, RESIZE_NONE, 7, 11, 228, 0, 13, STR_WHITE_TRAMWAY_CONSTRUCTION, STR_018C_WINDOW_TITLE_DRAG_THIS}, // RTW_CAPTION rubidium@9724: { WWT_STICKYBOX, RESIZE_NONE, 7, 229, 240, 0, 13, 0x0, STR_STICKY_BUTTON}, // RTW_STICKY rubidium@9625: rubidium@9724: { WWT_IMGBTN, RESIZE_NONE, 7, 0, 21, 14, 35, SPR_IMG_TRAMWAY_X_DIR, STR_BUILD_TRAMWAY_SECTION}, // RTW_ROAD_X rubidium@9724: { WWT_IMGBTN, RESIZE_NONE, 7, 22, 43, 14, 35, SPR_IMG_TRAMWAY_Y_DIR, STR_BUILD_TRAMWAY_SECTION}, // RTW_ROAD_Y rubidium@9724: { WWT_IMGBTN, RESIZE_NONE, 7, 44, 65, 14, 35, SPR_IMG_AUTOTRAM, STR_BUILD_AUTOTRAM_TIP}, // RTW_AUTOROAD rubidium@9724: { WWT_IMGBTN, RESIZE_NONE, 7, 66, 87, 14, 35, SPR_IMG_DYNAMITE, STR_018D_DEMOLISH_BUILDINGS_ETC}, // RTW_DEMOLISH rubidium@9724: { WWT_IMGBTN, RESIZE_NONE, 7, 88, 109, 14, 35, SPR_IMG_ROAD_DEPOT, STR_BUILD_TRAM_VEHICLE_DEPOT}, // RTW_DEPOT rubidium@9724: { WWT_IMGBTN, RESIZE_NONE, 7, 110, 131, 14, 35, SPR_IMG_BUS_STATION, STR_BUILD_PASSENGER_TRAM_STATION}, // RTW_BUS_STATION rubidium@9724: { WWT_IMGBTN, RESIZE_NONE, 7, 132, 153, 14, 35, SPR_IMG_TRUCK_BAY, STR_BUILD_CARGO_TRAM_STATION}, // RTW_TRUCK_STATION rubidium@9724: { WWT_EMPTY, RESIZE_NONE, 0, 0, 0, 0, 0, 0x0, STR_NULL}, // RTW_ONE_WAY rubidium@9724: { WWT_IMGBTN, RESIZE_NONE, 7, 154, 196, 14, 35, SPR_IMG_BRIDGE, STR_BUILD_TRAMWAY_BRIDGE}, // RTW_BUILD_BRIDGE rubidium@9724: { WWT_IMGBTN, RESIZE_NONE, 7, 197, 218, 14, 35, SPR_IMG_ROAD_TUNNEL, STR_BUILD_TRAMWAY_TUNNEL}, // RTW_BUILD_TUNNEL rubidium@9724: { WWT_IMGBTN, RESIZE_NONE, 7, 219, 240, 14, 35, SPR_IMG_REMOVE, STR_TOGGLE_BUILD_REMOVE_FOR_TRAMWAYS}, // RTW_REMOVE rubidium@9722: rubidium@9625: { WIDGETS_END}, rubidium@9625: }; rubidium@9625: rubidium@9625: static const WindowDesc _build_tramway_desc = { rubidium@9722: WDP_ALIGN_TBR, 22, 241, 36, 241, 36, rubidium@9625: WC_BUILD_TOOLBAR, WC_NONE, rubidium@9625: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON, rubidium@9625: _build_tramway_widgets, rubidium@9625: BuildRoadToolbWndProc rubidium@9625: }; rubidium@9625: glx@9624: void ShowBuildRoadToolbar(RoadType roadtype) truelight@0: { Darkvater@5005: if (!IsValidPlayer(_current_player)) return; glx@9624: _cur_roadtype = roadtype; Darkvater@5005: truelight@0: DeleteWindowById(WC_BUILD_TOOLBAR, 0); rubidium@9625: Window *w = AllocateWindowDesc(roadtype == ROADTYPE_ROAD ? &_build_road_desc : &_build_tramway_desc); tron@6111: if (_patches.link_terraform_toolbar) ShowTerraformToolbar(w); truelight@0: } truelight@0: truelight@9718: /** Widget definition of the build road toolbar in the scenario editor */ truelight@0: static const Widget _build_road_scen_widgets[] = { truelight@9718: { WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // RTW_CLOSEBOX rubidium@9722: { WWT_CAPTION, RESIZE_NONE, 7, 11, 184, 0, 13, STR_1802_ROAD_CONSTRUCTION, STR_018C_WINDOW_TITLE_DRAG_THIS}, // RTW_CAPTION rubidium@9722: { WWT_STICKYBOX, RESIZE_NONE, 7, 185, 196, 0, 13, 0x0, STR_STICKY_BUTTON}, // RTW_STICKY darkvater@661: rubidium@9722: { WWT_IMGBTN, RESIZE_NONE, 7, 0, 21, 14, 35, SPR_IMG_ROAD_X_DIR, STR_180B_BUILD_ROAD_SECTION}, // RTW_ROAD_X rubidium@9722: { WWT_IMGBTN, RESIZE_NONE, 7, 22, 43, 14, 35, SPR_IMG_ROAD_Y_DIR, STR_180B_BUILD_ROAD_SECTION}, // RTW_ROAD_Y rubidium@9722: { WWT_IMGBTN, RESIZE_NONE, 7, 44, 65, 14, 35, SPR_IMG_AUTOROAD, STR_BUILD_AUTOROAD_TIP}, // RTW_AUTOROAD rubidium@9722: { WWT_IMGBTN, RESIZE_NONE, 7, 66, 87, 14, 35, SPR_IMG_DYNAMITE, STR_018D_DEMOLISH_BUILDINGS_ETC}, // RTW_DEMOLISH truelight@9718: { WWT_EMPTY, RESIZE_NONE, 0, 0, 0, 0, 0, 0x0, STR_NULL}, // RTW_DEPOT truelight@9718: { WWT_EMPTY, RESIZE_NONE, 0, 0, 0, 0, 0, 0x0, STR_NULL}, // RTW_BUS_STATION truelight@9718: { WWT_EMPTY, RESIZE_NONE, 0, 0, 0, 0, 0, 0x0, STR_NULL}, // RTW_TRUCK_STATION rubidium@9722: { WWT_IMGBTN, RESIZE_NONE, 7, 88, 109, 14, 35, SPR_IMG_ROAD_ONE_WAY, STR_TOGGLE_ONE_WAY_ROAD}, // RTW_ONE_WAY rubidium@9722: { WWT_IMGBTN, RESIZE_NONE, 7, 110, 152, 14, 35, SPR_IMG_BRIDGE, STR_180F_BUILD_ROAD_BRIDGE}, // RTW_BUILD_BRIDGE rubidium@9722: { WWT_IMGBTN, RESIZE_NONE, 7, 153, 174, 14, 35, SPR_IMG_ROAD_TUNNEL, STR_1810_BUILD_ROAD_TUNNEL}, // RTW_BUILD_TUNNEL rubidium@9722: { WWT_IMGBTN, RESIZE_NONE, 7, 175, 196, 14, 35, SPR_IMG_REMOVE, STR_1811_TOGGLE_BUILD_REMOVE_FOR}, // RTW_REMOVE darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _build_road_scen_desc = { rubidium@9722: WDP_AUTO, WDP_AUTO, 197, 36, 197, 36, rubidium@6144: WC_SCEN_BUILD_ROAD, WC_NONE, darkvater@777: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON, truelight@0: _build_road_scen_widgets, truelight@0: BuildRoadToolbWndProc truelight@0: }; truelight@0: rubidium@6573: void ShowBuildRoadScenToolbar() truelight@0: { rubidium@9625: _cur_roadtype = ROADTYPE_ROAD; truelight@0: AllocateWindowDescFront(&_build_road_scen_desc, 0); truelight@0: } truelight@0: truelight@9718: /** Enum referring to the widgets of the build road depot window */ truelight@9718: enum BuildRoadDepotWidgets { truelight@9718: BRDW_CLOSEBOX = 0, truelight@9718: BRDW_CAPTION, truelight@9718: BRDW_BACKGROUND, truelight@9718: BRDW_DEPOT_NE, truelight@9718: BRDW_DEPOT_SE, truelight@9718: BRDW_DEPOT_SW, truelight@9718: BRDW_DEPOT_NW, truelight@9718: }; truelight@9718: belugas@4171: static void BuildRoadDepotWndProc(Window *w, WindowEvent *e) tron@2639: { tron@2639: switch (e->event) { rubidium@9723: case WE_CREATE: w->LowerWidget(_road_depot_orientation + BRDW_DEPOT_NE); break; belugas@4719: truelight@0: case WE_PAINT: truelight@0: DrawWindowWidgets(w); truelight@0: glx@9624: DrawRoadDepotSprite(70, 17, DIAGDIR_NE, _cur_roadtype); glx@9624: DrawRoadDepotSprite(70, 69, DIAGDIR_SE, _cur_roadtype); glx@9624: DrawRoadDepotSprite( 2, 69, DIAGDIR_SW, _cur_roadtype); glx@9624: DrawRoadDepotSprite( 2, 17, DIAGDIR_NW, _cur_roadtype); truelight@0: break; truelight@0: truelight@9718: case WE_CLICK: belugas@4634: switch (e->we.click.widget) { truelight@9718: case BRDW_DEPOT_NW: truelight@9718: case BRDW_DEPOT_NE: truelight@9718: case BRDW_DEPOT_SW: truelight@9718: case BRDW_DEPOT_SE: rubidium@9723: w->RaiseWidget(_road_depot_orientation + BRDW_DEPOT_NE); truelight@9718: _road_depot_orientation = (DiagDirection)(e->we.click.widget - BRDW_DEPOT_NE); rubidium@9723: w->LowerWidget(_road_depot_orientation + BRDW_DEPOT_NE); truelight@9718: SndPlayFx(SND_15_BEEP); truelight@9718: SetWindowDirty(w); truelight@9718: break; truelight@193: } truelight@9718: break; truelight@193: truelight@0: case WE_MOUSELOOP: rubidium@9601: if (WP(w, def_d).close) DeleteWindow(w); truelight@0: break; celestar@1072: celestar@1072: case WE_DESTROY: rubidium@9601: if (!WP(w, def_d).close) ResetObjectToPlace(); celestar@1072: break; truelight@0: } truelight@0: } truelight@0: truelight@9718: /** Widget definition of the build road depot window */ truelight@0: static const Widget _build_road_depot_widgets[] = { truelight@9718: { WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // BRDW_CLOSEBOX truelight@9718: { WWT_CAPTION, RESIZE_NONE, 7, 11, 139, 0, 13, STR_1806_ROAD_DEPOT_ORIENTATION, STR_018C_WINDOW_TITLE_DRAG_THIS}, // BRDW_CAPTION truelight@9718: { WWT_PANEL, RESIZE_NONE, 7, 0, 139, 14, 121, 0x0, STR_NULL}, // BRDW_BACKGROUND truelight@9718: { WWT_PANEL, RESIZE_NONE, 14, 71, 136, 17, 66, 0x0, STR_1813_SELECT_ROAD_VEHICLE_DEPOT}, // BRDW_DEPOT_NE truelight@9718: { WWT_PANEL, RESIZE_NONE, 14, 71, 136, 69, 118, 0x0, STR_1813_SELECT_ROAD_VEHICLE_DEPOT}, // BRDW_DEPOT_SE truelight@9718: { WWT_PANEL, RESIZE_NONE, 14, 3, 68, 69, 118, 0x0, STR_1813_SELECT_ROAD_VEHICLE_DEPOT}, // BRDW_DEPOT_SW truelight@9718: { WWT_PANEL, RESIZE_NONE, 14, 3, 68, 17, 66, 0x0, STR_1813_SELECT_ROAD_VEHICLE_DEPOT}, // BRDW_DEPOT_NW darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@9718: /** Widget definition of the build tram depot window */ rubidium@9625: static const Widget _build_tram_depot_widgets[] = { truelight@9718: { WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // BRDW_CLOSEBOX rubidium@9724: { WWT_CAPTION, RESIZE_NONE, 7, 11, 139, 0, 13, STR_TRAM_DEPOT_ORIENTATION, STR_018C_WINDOW_TITLE_DRAG_THIS}, // BRDW_CAPTION truelight@9718: { WWT_PANEL, RESIZE_NONE, 7, 0, 139, 14, 121, 0x0, STR_NULL}, // BRDW_BACKGROUND rubidium@9724: { WWT_PANEL, RESIZE_NONE, 14, 71, 136, 17, 66, 0x0, STR_SELECT_TRAM_VEHICLE_DEPOT}, // BRDW_DEPOT_NE rubidium@9724: { WWT_PANEL, RESIZE_NONE, 14, 71, 136, 69, 118, 0x0, STR_SELECT_TRAM_VEHICLE_DEPOT}, // BRDW_DEPOT_SE rubidium@9724: { WWT_PANEL, RESIZE_NONE, 14, 3, 68, 69, 118, 0x0, STR_SELECT_TRAM_VEHICLE_DEPOT}, // BRDW_DEPOT_SW rubidium@9724: { WWT_PANEL, RESIZE_NONE, 14, 3, 68, 17, 66, 0x0, STR_SELECT_TRAM_VEHICLE_DEPOT}, // BRDW_DEPOT_NW rubidium@9625: { WIDGETS_END}, rubidium@9625: }; rubidium@9625: truelight@0: static const WindowDesc _build_road_depot_desc = { rubidium@9694: WDP_AUTO, WDP_AUTO, 140, 122, 140, 122, Darkvater@5070: WC_BUILD_DEPOT, WC_BUILD_TOOLBAR, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _build_road_depot_widgets, truelight@0: BuildRoadDepotWndProc truelight@0: }; truelight@0: rubidium@9625: static const WindowDesc _build_tram_depot_desc = { rubidium@9694: WDP_AUTO, WDP_AUTO, 140, 122, 140, 122, rubidium@9625: WC_BUILD_DEPOT, WC_BUILD_TOOLBAR, rubidium@9625: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, rubidium@9625: _build_tram_depot_widgets, rubidium@9625: BuildRoadDepotWndProc rubidium@9625: }; rubidium@9625: rubidium@6573: static void ShowRoadDepotPicker() truelight@0: { rubidium@9625: AllocateWindowDesc(_cur_roadtype == ROADTYPE_ROAD ? &_build_road_depot_desc : &_build_tram_depot_desc); truelight@0: } truelight@0: truelight@9718: /** Enum referring to the widgets of the build road station window */ truelight@9718: enum BuildRoadStationWidgets { truelight@9718: BRSW_CLOSEBOX = 0, truelight@9718: BRSW_CAPTION, truelight@9718: BRSW_BACKGROUND, truelight@9718: BRSW_STATION_NE, truelight@9718: BRSW_STATION_SE, truelight@9718: BRSW_STATION_SW, truelight@9718: BRSW_STATION_NW, truelight@9718: BRSW_STATION_X, truelight@9718: BRSW_STATION_Y, truelight@9718: BRSW_LT_OFF, truelight@9718: BRSW_LT_ON, truelight@9718: BRSW_INFO, truelight@9718: }; truelight@9718: darkvater@987: static void RoadStationPickerWndProc(Window *w, WindowEvent *e) darkvater@987: { tron@2952: switch (e->event) { belugas@4719: case WE_CREATE: glx@9624: /* Trams don't have non-drivethrough stations */ glx@9624: if (_cur_roadtype == ROADTYPE_TRAM && _road_station_picker_orientation < DIAGDIR_END) { glx@9624: _road_station_picker_orientation = DIAGDIR_END; glx@9624: } rubidium@9723: w->SetWidgetsDisabledState(_cur_roadtype == ROADTYPE_TRAM, truelight@9718: BRSW_STATION_NE, truelight@9718: BRSW_STATION_SE, truelight@9718: BRSW_STATION_SW, truelight@9718: BRSW_STATION_NW, truelight@9718: WIDGET_LIST_END); glx@9624: rubidium@9723: w->LowerWidget(_road_station_picker_orientation + BRSW_STATION_NE); rubidium@9723: w->LowerWidget(_station_show_coverage + BRSW_LT_OFF); belugas@4719: break; belugas@4719: truelight@0: case WE_PAINT: { rubidium@9601: if (WP(w, def_d).close) return; darkvater@987: truelight@0: DrawWindowWidgets(w); truelight@0: darkvater@987: if (_station_show_coverage) { glx@9732: int rad = _patches.modified_catchment ? CA_TRUCK /* = CA_BUS */ : CA_UNMODIFIED; darkvater@987: SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad); tron@4077: } else { darkvater@987: SetTileSelectSize(1, 1); tron@4077: } truelight@0: rubidium@9686: StationType st = (w->window_class == WC_BUS_STATION) ? STATION_BUS : STATION_TRUCK; truelight@0: rubidium@9723: StationPickerDrawSprite(103, 35, st, INVALID_RAILTYPE, ROADTYPE_ROAD, 0); rubidium@9723: StationPickerDrawSprite(103, 85, st, INVALID_RAILTYPE, ROADTYPE_ROAD, 1); rubidium@9723: StationPickerDrawSprite( 35, 85, st, INVALID_RAILTYPE, ROADTYPE_ROAD, 2); rubidium@9723: StationPickerDrawSprite( 35, 35, st, INVALID_RAILTYPE, ROADTYPE_ROAD, 3); truelight@0: rubidium@9723: StationPickerDrawSprite(171, 35, st, INVALID_RAILTYPE, _cur_roadtype, 4); rubidium@9723: StationPickerDrawSprite(171, 85, st, INVALID_RAILTYPE, _cur_roadtype, 5); rubidium@6338: rubidium@9724: int text_end = DrawStationCoverageAreaText(2, 146, truelight@9641: (w->window_class == WC_BUS_STATION) ? SCT_PASSENGERS_ONLY : SCT_NON_PASSENGERS_ONLY, rubidium@9724: 3) + 4; rubidium@9724: if (text_end > w->widget[BRSW_BACKGROUND].bottom) { rubidium@9724: SetWindowDirty(w); rubidium@9724: ResizeWindowForWidget(w, BRSW_BACKGROUND, 0, text_end - w->widget[BRSW_BACKGROUND].bottom); rubidium@9724: SetWindowDirty(w); rubidium@9724: } truelight@0: truelight@0: } break; truelight@0: truelight@0: case WE_CLICK: { belugas@4634: switch (e->we.click.widget) { truelight@9718: case BRSW_STATION_NE: truelight@9718: case BRSW_STATION_SE: truelight@9718: case BRSW_STATION_SW: truelight@9718: case BRSW_STATION_NW: truelight@9718: case BRSW_STATION_X: truelight@9718: case BRSW_STATION_Y: rubidium@9723: w->RaiseWidget(_road_station_picker_orientation + BRSW_STATION_NE); truelight@9718: _road_station_picker_orientation = (DiagDirection)(e->we.click.widget - BRSW_STATION_NE); rubidium@9723: w->LowerWidget(_road_station_picker_orientation + BRSW_STATION_NE); truelight@9718: SndPlayFx(SND_15_BEEP); truelight@9718: SetWindowDirty(w); truelight@9718: break; truelight@9718: truelight@9718: case BRSW_LT_OFF: truelight@9718: case BRSW_LT_ON: rubidium@9723: w->RaiseWidget(_station_show_coverage + BRSW_LT_OFF); truelight@9718: _station_show_coverage = (e->we.click.widget != BRSW_LT_OFF); rubidium@9723: w->LowerWidget(_station_show_coverage + BRSW_LT_OFF); truelight@9718: SndPlayFx(SND_15_BEEP); truelight@9718: SetWindowDirty(w); truelight@9718: break; truelight@0: } truelight@0: } break; truelight@193: truelight@0: case WE_MOUSELOOP: { rubidium@9601: if (WP(w, def_d).close) { truelight@0: DeleteWindow(w); truelight@0: return; truelight@0: } truelight@0: truelight@0: CheckRedrawStationCoverage(w); truelight@0: } break; tron@1109: celestar@1072: case WE_DESTROY: rubidium@9601: if (!WP(w, def_d).close) ResetObjectToPlace(); celestar@1072: break; truelight@193: } truelight@0: } truelight@0: truelight@9718: /** Widget definition of the build raod station window */ rubidium@9625: static const Widget _rv_station_picker_widgets[] = { truelight@9718: { WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // BRSW_CLOSEBOX truelight@9718: { WWT_CAPTION, RESIZE_NONE, 7, 11, 206, 0, 13, STR_NULL, STR_018C_WINDOW_TITLE_DRAG_THIS}, // BRSW_CAPTION truelight@9718: { WWT_PANEL, RESIZE_NONE, 7, 0, 206, 14, 176, 0x0, STR_NULL}, // BRSW_BACKGROUND truelight@9718: truelight@9718: { WWT_PANEL, RESIZE_NONE, 14, 71, 136, 17, 66, 0x0, STR_NULL}, // BRSW_STATION_NE truelight@9718: { WWT_PANEL, RESIZE_NONE, 14, 71, 136, 69, 118, 0x0, STR_NULL}, // BRSW_STATION_SE truelight@9718: { WWT_PANEL, RESIZE_NONE, 14, 3, 68, 69, 118, 0x0, STR_NULL}, // BRSW_STATION_SW truelight@9718: { WWT_PANEL, RESIZE_NONE, 14, 3, 68, 17, 66, 0x0, STR_NULL}, // BRSW_STATION_NW truelight@9718: { WWT_PANEL, RESIZE_NONE, 14, 139, 204, 17, 66, 0x0, STR_NULL}, // BRSW_STATION_X truelight@9718: { WWT_PANEL, RESIZE_NONE, 14, 139, 204, 69, 118, 0x0, STR_NULL}, // BRSW_STATION_Y truelight@9718: truelight@9718: { WWT_TEXTBTN, RESIZE_NONE, 14, 10, 69, 133, 144, STR_02DB_OFF, STR_3065_DON_T_HIGHLIGHT_COVERAGE}, // BRSW_LT_OFF truelight@9718: { WWT_TEXTBTN, RESIZE_NONE, 14, 70, 129, 133, 144, STR_02DA_ON, STR_3064_HIGHLIGHT_COVERAGE_AREA}, // BRSW_LT_ON truelight@9718: { WWT_LABEL, RESIZE_NONE, 7, 0, 139, 120, 133, STR_3066_COVERAGE_AREA_HIGHLIGHT, STR_NULL}, // BRSW_INFO darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: rubidium@9625: static const WindowDesc _rv_station_picker_desc = { rubidium@9694: WDP_AUTO, WDP_AUTO, 207, 177, 207, 177, Darkvater@5070: WC_BUS_STATION, WC_BUILD_TOOLBAR, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, rubidium@9625: _rv_station_picker_widgets, truelight@0: RoadStationPickerWndProc truelight@0: }; truelight@0: rubidium@9837: static void ShowRVStationPicker(RoadStopType rs) truelight@0: { rubidium@9625: Window *w = AllocateWindowDesc(&_rv_station_picker_desc); rubidium@9625: if (w == NULL) return; truelight@0: rubidium@9837: w->window_class = (rs == ROADSTOP_BUS) ? WC_BUS_STATION : WC_TRUCK_STATION; truelight@9718: w->widget[BRSW_CAPTION].data = _road_type_infos[_cur_roadtype].picker_title[rs]; truelight@9718: for (uint i = BRSW_STATION_NE; i < BRSW_LT_OFF; i++) w->widget[i].tooltips = _road_type_infos[_cur_roadtype].picker_tooltip[rs]; truelight@0: } truelight@0: rubidium@6573: void InitializeRoadGui() truelight@0: { rubidium@5838: _road_depot_orientation = DIAGDIR_NW; rubidium@5838: _road_station_picker_orientation = DIAGDIR_NW; truelight@0: }