tron@2186: /* $Id$ */ tron@2186: belugas@6393: /** @file road_gui.cpp */ belugas@6393: truelight@0: #include "stdafx.h" Darkvater@1891: #include "openttd.h" tron@1363: #include "table/sprites.h" tron@507: #include "table/strings.h" rubidium@7266: #include "strings.h" tron@2163: #include "functions.h" tron@679: #include "map.h" tron@1209: #include "tile.h" truelight@0: #include "window.h" truelight@0: #include "gui.h" truelight@0: #include "viewport.h" truelight@0: #include "gfx.h" tron@337: #include "sound.h" truelight@0: #include "command.h" tron@2159: #include "variables.h" rubidium@6666: #include "road.h" rubidium@6666: #include "road_cmd.h" rubidium@6666: #include "road_map.h" rubidium@6012: #include "station_map.h" Celestar@568: //needed for catchments Celestar@568: #include "station.h" Celestar@568: truelight@0: rubidium@6693: static void ShowRVStationPicker(RoadStop::Type rs); rubidium@6247: static void ShowRoadDepotPicker(); truelight@0: truelight@0: static bool _remove_button_clicked; truelight@0: truelight@0: static byte _place_road_flag; truelight@0: rubidium@6666: static RoadType _cur_roadtype; rubidium@6666: rubidium@5587: static DiagDirection _road_depot_orientation; rubidium@5587: 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: tron@1977: static void PlaceRoad_NE(TileIndex tile) truelight@0: { truelight@0: _place_road_flag = (_tile_fract_coords.y >= 8) + 4; maedhros@6670: VpStartPlaceSizing(tile, VPM_FIX_X, DDSP_PLACE_ROAD_NE); truelight@0: } truelight@0: tron@1977: static void PlaceRoad_NW(TileIndex tile) truelight@0: { truelight@0: _place_road_flag = (_tile_fract_coords.x >= 8) + 0; maedhros@6670: VpStartPlaceSizing(tile, VPM_FIX_Y, DDSP_PLACE_ROAD_NW); truelight@0: } truelight@0: tron@1977: static void PlaceRoad_Bridge(TileIndex tile) truelight@0: { maedhros@6670: 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: rubidium@6676: /** Structure holding information per roadtype for several functions */ rubidium@6676: struct RoadTypeInfo { rubidium@6676: StringID err_build_road; ///< Building a normal piece of road rubidium@6676: StringID err_remove_road; ///< Removing a normal piece of road rubidium@6676: StringID err_depot; ///< Building a depot rubidium@6676: StringID err_build_station[2]; ///< Building a bus or truck station rubidium@6676: StringID err_remove_station[2]; ///< Removing of a bus or truck station rubidium@6676: rubidium@6693: StringID picker_title[2]; ///< Title for the station picker for bus or truck stations rubidium@6693: StringID picker_tooltip[2]; ///< Tooltip for the station picker for bus or truck stations rubidium@6693: rubidium@6676: SpriteID cursor_nesw; ///< Cursor for building NE and SW bits rubidium@6676: SpriteID cursor_nwse; ///< Cursor for building NW and SE bits rubidium@6676: }; rubidium@6676: rubidium@6676: /** What errors/cursors must be shown for several types of roads */ rubidium@6676: static const RoadTypeInfo _road_type_infos[] = { rubidium@6676: { rubidium@6676: STR_1804_CAN_T_BUILD_ROAD_HERE, rubidium@6676: STR_1805_CAN_T_REMOVE_ROAD_FROM, rubidium@6676: STR_1807_CAN_T_BUILD_ROAD_VEHICLE, rubidium@6693: { STR_1808_CAN_T_BUILD_BUS_STATION, STR_1809_CAN_T_BUILD_TRUCK_STATION }, rubidium@6693: { STR_CAN_T_REMOVE_BUS_STATION, STR_CAN_T_REMOVE_TRUCK_STATION }, rubidium@6693: { STR_3042_BUS_STATION_ORIENTATION, STR_3043_TRUCK_STATION_ORIENT }, rubidium@6693: { STR_3051_SELECT_BUS_STATION_ORIENTATION, STR_3052_SELECT_TRUCK_LOADING_BAY }, rubidium@6676: rubidium@6676: SPR_CURSOR_ROAD_NESW, rubidium@6676: SPR_CURSOR_ROAD_NWSE, rubidium@6676: }, rubidium@6691: { rubidium@6691: STR_1804_CAN_T_BUILD_TRAMWAY_HERE, rubidium@6691: STR_1805_CAN_T_REMOVE_TRAMWAY_FROM, rubidium@6691: STR_1807_CAN_T_BUILD_TRAM_VEHICLE, rubidium@6693: { STR_1808_CAN_T_BUILD_PASSENGER_TRAM_STATION, STR_1809_CAN_T_BUILD_CARGO_TRAM_STATION }, rubidium@6693: { STR_CAN_T_REMOVE_PASSENGER_TRAM_STATION, STR_CAN_T_REMOVE_CARGO_TRAM_STATION }, rubidium@6693: { STR_3042_PASSENGER_TRAM_STATION_ORIENTATION, STR_3043_CARGO_TRAM_STATION_ORIENT }, rubidium@6693: { STR_3051_SELECT_PASSENGER_TRAM_STATION_ORIENTATION, STR_3052_SELECT_CARGO_TRAM_STATION_ORIENTATION }, rubidium@6691: rubidium@6691: SPR_CURSOR_TRAMWAY_NESW, rubidium@6691: SPR_CURSOR_TRAMWAY_NWSE, rubidium@6691: }, rubidium@6676: }; rubidium@6676: tron@1977: static void PlaceRoad_Tunnel(TileIndex tile) truelight@0: { rubidium@6666: DoCommandP(tile, 0x200 | RoadTypeToRoadTypes(_cur_roadtype), 0, CcBuildRoadTunnel, CMD_BUILD_TUNNEL | CMD_AUTO | 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 rubidium@7370: if (IsTileType(tile, MP_ROAD) && GetRoadTileType(tile) == ROAD_TILE_NORMAL) { rubidium@6666: if (GetRoadBits(tile, _cur_roadtype) != ROAD_NONE) { rubidium@6666: DoCommandP(tile, _cur_roadtype << 4 | DiagDirToRoadBits(ReverseDiagDir(direction)), 0, NULL, CMD_BUILD_ROAD); rubidium@6666: } truelight@0: } truelight@0: } truelight@0: tron@1977: void CcRoadDepot(bool success, TileIndex tile, uint32 p1, uint32 p2) truelight@0: { truelight@0: if (success) { rubidium@6662: DiagDirection dir = (DiagDirection)GB(p1, 0, 2); tron@541: SndPlayTileFx(SND_1F_SPLAT, tile); truelight@0: ResetObjectToPlace(); rubidium@6662: BuildRoadOutsideStation(tile, dir); rubidium@6102: /* For a drive-through road stop build connecting road for other entrance */ rubidium@6662: 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@6676: DoCommandP(tile, _cur_roadtype << 2 | _road_depot_orientation, 0, CcRoadDepot, CMD_BUILD_ROAD_DEPOT | CMD_AUTO | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_depot)); truelight@0: } truelight@0: rubidium@6012: static void PlaceRoadStop(TileIndex tile, uint32 p2, uint32 cmd) rubidium@6012: { rubidium@6012: uint32 p1 = _road_station_picker_orientation; rubidium@6012: rubidium@6012: if (p1 >= DIAGDIR_END) { rubidium@6012: SETBIT(p2, 1); // It's a drive-through stop rubidium@6012: p1 -= DIAGDIR_END; // Adjust picker result to actual direction rubidium@6012: } rubidium@6012: DoCommandP(tile, p1, p2, CcRoadDepot, cmd); rubidium@6012: } rubidium@6012: tron@1977: static void PlaceRoad_BusStation(TileIndex tile) truelight@0: { rubidium@6012: if (_remove_button_clicked) { rubidium@6676: DoCommandP(tile, 0, RoadStop::BUS, CcPlaySound1D, CMD_REMOVE_ROAD_STOP | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_station[RoadStop::BUS])); rubidium@6012: } else { rubidium@6676: PlaceRoadStop(tile, (_ctrl_pressed << 5) | RoadTypeToRoadTypes(_cur_roadtype) << 2 | RoadStop::BUS, CMD_BUILD_ROAD_STOP | CMD_AUTO | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_station[RoadStop::BUS])); rubidium@6012: } truelight@0: } truelight@0: tron@1977: static void PlaceRoad_TruckStation(TileIndex tile) truelight@0: { rubidium@6012: if (_remove_button_clicked) { rubidium@7339: DoCommandP(tile, 0, RoadStop::TRUCK, CcPlaySound1D, CMD_REMOVE_ROAD_STOP | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_station[RoadStop::TRUCK])); rubidium@6012: } else { rubidium@6676: PlaceRoadStop(tile, (_ctrl_pressed << 5) | RoadTypeToRoadTypes(_cur_roadtype) << 2 | RoadStop::TRUCK, CMD_BUILD_ROAD_STOP | CMD_AUTO | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_station[RoadStop::TRUCK])); rubidium@6012: } truelight@0: } truelight@0: tron@1977: static void PlaceRoad_DemolishArea(TileIndex tile) truelight@0: { maedhros@6670: VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_DEMOLISH_AREA); truelight@0: } truelight@0: tron@5147: tron@5147: enum { tron@5147: RTW_ROAD_X = 3, tron@5147: RTW_ROAD_Y = 4, tron@5147: RTW_DEMOLISH = 5, tron@5147: RTW_DEPOT = 6, tron@5147: RTW_BUS_STATION = 7, tron@5147: RTW_TRUCK_STATION = 8, tron@5147: RTW_BUILD_BRIDGE = 9, tron@5147: RTW_BUILD_TUNNEL = 10, tron@5147: RTW_REMOVE = 11 tron@5147: }; tron@5147: tron@5147: truelight@0: typedef void OnButtonClick(Window *w); truelight@0: truelight@0: static void BuildRoadClick_NE(Window *w) truelight@0: { rubidium@6676: HandlePlacePushButton(w, RTW_ROAD_X, _road_type_infos[_cur_roadtype].cursor_nesw, 1, PlaceRoad_NE); truelight@0: } truelight@0: truelight@0: static void BuildRoadClick_NW(Window *w) truelight@0: { rubidium@6676: HandlePlacePushButton(w, RTW_ROAD_Y, _road_type_infos[_cur_roadtype].cursor_nwse, 1, PlaceRoad_NW); truelight@0: } truelight@0: truelight@0: truelight@0: static void BuildRoadClick_Demolish(Window *w) truelight@0: { tron@5147: HandlePlacePushButton(w, RTW_DEMOLISH, ANIMCURSOR_DEMOLISH, 1, PlaceRoad_DemolishArea); truelight@0: } truelight@0: truelight@0: static void BuildRoadClick_Depot(Window *w) truelight@0: { rubidium@7086: if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(VEH_ROAD)) return; tron@5147: if (HandlePlacePushButton(w, RTW_DEPOT, SPR_CURSOR_ROAD_DEPOT, 1, PlaceRoad_Depot)) ShowRoadDepotPicker(); truelight@0: } truelight@0: truelight@0: static void BuildRoadClick_BusStation(Window *w) truelight@0: { rubidium@7086: if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(VEH_ROAD)) return; rubidium@6693: if (HandlePlacePushButton(w, RTW_BUS_STATION, SPR_CURSOR_BUS_STATION, 1, PlaceRoad_BusStation)) ShowRVStationPicker(RoadStop::BUS); truelight@0: } truelight@0: truelight@0: static void BuildRoadClick_TruckStation(Window *w) truelight@0: { rubidium@7086: if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(VEH_ROAD)) return; rubidium@6693: if (HandlePlacePushButton(w, RTW_TRUCK_STATION, SPR_CURSOR_TRUCK_STATION, 1, PlaceRoad_TruckStation)) ShowRVStationPicker(RoadStop::TRUCK); truelight@0: } truelight@0: truelight@0: static void BuildRoadClick_Bridge(Window *w) truelight@0: { tron@5147: HandlePlacePushButton(w, RTW_BUILD_BRIDGE, SPR_CURSOR_BRIDGE, 1, PlaceRoad_Bridge); truelight@0: } truelight@0: truelight@0: static void BuildRoadClick_Tunnel(Window *w) truelight@0: { tron@5147: HandlePlacePushButton(w, RTW_BUILD_TUNNEL, SPR_CURSOR_ROAD_TUNNEL, 3, PlaceRoad_Tunnel); truelight@0: } truelight@0: truelight@0: static void BuildRoadClick_Remove(Window *w) truelight@0: { tron@5147: if (IsWindowWidgetDisabled(w, RTW_REMOVE)) return; truelight@0: SetWindowDirty(w); tron@541: SndPlayFx(SND_15_BEEP); tron@5147: ToggleWidgetLoweredState(w, RTW_REMOVE); tron@5147: SetSelectionRed(IsWindowWidgetLowered(w, RTW_REMOVE)); truelight@0: } truelight@0: truelight@0: tron@2639: static OnButtonClick* const _build_road_button_proc[] = { truelight@0: BuildRoadClick_NE, truelight@0: BuildRoadClick_NW, truelight@0: BuildRoadClick_Demolish, truelight@0: BuildRoadClick_Depot, truelight@0: BuildRoadClick_BusStation, truelight@0: BuildRoadClick_TruckStation, truelight@0: BuildRoadClick_Bridge, truelight@0: BuildRoadClick_Tunnel, tron@5682: BuildRoadClick_Remove truelight@0: }; truelight@0: belugas@4171: static void BuildRoadToolbWndProc(Window *w, WindowEvent *e) tron@2639: { tron@2639: switch (e->event) { tron@5147: case WE_CREATE: DisableWindowWidget(w, RTW_REMOVE); break; glx@5105: truelight@0: case WE_PAINT: rubidium@6012: if (IsWindowWidgetLowered(w, RTW_ROAD_X) || IsWindowWidgetLowered(w, RTW_ROAD_Y) || IsWindowWidgetLowered(w, RTW_BUS_STATION) || IsWindowWidgetLowered(w, RTW_TRUCK_STATION)) { tron@5147: EnableWindowWidget(w, RTW_REMOVE); truelight@0: } rubidium@7086: SetWindowWidgetsDisabledState(w, !CanBuildVehicleInfrastructure(VEH_ROAD), 6, 7, 8, WIDGET_LIST_END); truelight@0: DrawWindowWidgets(w); truelight@0: break; truelight@0: truelight@0: case WE_CLICK: { belugas@4634: if (e->we.click.widget >= 3) _build_road_button_proc[e->we.click.widget - 3](w); rubidium@6492: } break; truelight@0: truelight@0: case WE_KEYPRESS: belugas@4634: switch (e->we.keypress.keycode) { tron@2631: case '1': BuildRoadClick_NE(w); break; tron@2631: case '2': BuildRoadClick_NW(w); break; tron@2631: case '3': BuildRoadClick_Demolish(w); break; tron@2631: case '4': BuildRoadClick_Depot(w); break; tron@2631: case '5': BuildRoadClick_BusStation(w); break; tron@2631: case '6': BuildRoadClick_TruckStation(w); break; tron@2631: case 'B': BuildRoadClick_Bridge(w); break; tron@2631: case 'T': BuildRoadClick_Tunnel(w); break; tron@2631: case 'R': BuildRoadClick_Remove(w); break; tron@2631: default: return; truelight@0: } darkvater@756: MarkTileDirty(_thd.pos.x, _thd.pos.y); // redraw tile selection belugas@4634: e->we.keypress.cont = false; truelight@0: break; truelight@0: truelight@0: case WE_PLACE_OBJ: tron@5147: _remove_button_clicked = IsWindowWidgetLowered(w, RTW_REMOVE); belugas@4634: _place_proc(e->we.place.tile); truelight@0: break; truelight@0: truelight@0: case WE_ABORT_PLACE_OBJ: belugas@4719: RaiseWindowButtons(w); tron@5147: DisableWindowWidget(w, RTW_REMOVE); tron@5147: InvalidateWidget(w, RTW_REMOVE); truelight@0: truelight@0: w = FindWindowById(WC_BUS_STATION, 0); rubidium@6491: if (w != NULL) WP(w, def_d).close = true; truelight@0: w = FindWindowById(WC_TRUCK_STATION, 0); rubidium@6491: if (w != NULL) WP(w, def_d).close = true; truelight@0: w = FindWindowById(WC_BUILD_DEPOT, 0); rubidium@6491: if (w != NULL) WP(w, def_d).close = true; truelight@0: break; truelight@0: maedhros@6669: case WE_PLACE_DRAG: maedhros@6670: switch (e->we.place.select_proc) { maedhros@6670: case DDSP_PLACE_ROAD_NE: belugas@4634: _place_road_flag = (_place_road_flag & ~2) | ((e->we.place.pt.y & 8) >> 2); belugas@4435: break; belugas@4435: maedhros@6670: case DDSP_PLACE_ROAD_NW: belugas@4634: _place_road_flag = (_place_road_flag & ~2) | ((e->we.place.pt.x & 8) >> 2); belugas@4435: break; truelight@0: } truelight@193: maedhros@6669: 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: maedhros@6670: switch (e->we.place.select_proc) { maedhros@6670: case DDSP_BUILD_BRIDGE: maedhros@6669: ResetObjectToPlace(); maedhros@6669: ShowBuildBridgeWindow(start_tile, end_tile, 0x80 | RoadTypeToRoadTypes(_cur_roadtype)); maedhros@6669: break; maedhros@6669: maedhros@6670: case DDSP_DEMOLISH_AREA: maedhros@6669: DoCommandP(end_tile, start_tile, 0, CcPlaySound10, CMD_CLEAR_AREA | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA)); maedhros@6669: break; maedhros@6669: maedhros@6670: case DDSP_PLACE_ROAD_NE: maedhros@6670: case DDSP_PLACE_ROAD_NW: rubidium@6764: DoCommandP(end_tile, start_tile, _place_road_flag | (_cur_roadtype << 3) | _ctrl_pressed << 5, CcPlaySound1D, maedhros@6669: _remove_button_clicked ? rubidium@6676: CMD_REMOVE_LONG_ROAD | CMD_AUTO | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_road) : rubidium@6676: CMD_BUILD_LONG_ROAD | CMD_AUTO | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_road)); maedhros@6669: 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: maedhros@6678: 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; truelight@0: } truelight@0: } truelight@0: truelight@0: static const Widget _build_road_widgets[] = { rubidium@4344: { WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, tron@5682: { WWT_CAPTION, RESIZE_NONE, 7, 11, 205, 0, 13, STR_1802_ROAD_CONSTRUCTION, STR_018C_WINDOW_TITLE_DRAG_THIS}, tron@5682: { WWT_STICKYBOX, RESIZE_NONE, 7, 206, 217, 0, 13, 0x0, STR_STICKY_BUTTON}, dominik@606: Darkvater@4938: { WWT_IMGBTN, RESIZE_NONE, 7, 0, 21, 14, 35, SPR_IMG_ROAD_NW, STR_180B_BUILD_ROAD_SECTION}, Darkvater@4938: { WWT_IMGBTN, RESIZE_NONE, 7, 22, 43, 14, 35, SPR_IMG_ROAD_NE, STR_180B_BUILD_ROAD_SECTION}, Darkvater@4938: { WWT_IMGBTN, RESIZE_NONE, 7, 44, 65, 14, 35, SPR_IMG_DYNAMITE, STR_018D_DEMOLISH_BUILDINGS_ETC}, Darkvater@4938: { WWT_IMGBTN, RESIZE_NONE, 7, 66, 87, 14, 35, SPR_IMG_ROAD_DEPOT, STR_180C_BUILD_ROAD_VEHICLE_DEPOT}, Darkvater@4938: { WWT_IMGBTN, RESIZE_NONE, 7, 88, 109, 14, 35, SPR_IMG_BUS_STATION, STR_180D_BUILD_BUS_STATION}, Darkvater@4938: { WWT_IMGBTN, RESIZE_NONE, 7, 110, 131, 14, 35, SPR_IMG_TRUCK_BAY, STR_180E_BUILD_TRUCK_LOADING_BAY}, Darkvater@4938: { WWT_IMGBTN, RESIZE_NONE, 7, 132, 173, 14, 35, SPR_IMG_BRIDGE, STR_180F_BUILD_ROAD_BRIDGE}, Darkvater@4938: { WWT_IMGBTN, RESIZE_NONE, 7, 174, 195, 14, 35, SPR_IMG_ROAD_TUNNEL, STR_1810_BUILD_ROAD_TUNNEL}, Darkvater@4938: { WWT_IMGBTN, RESIZE_NONE, 7, 196, 217, 14, 35, SPR_IMG_REMOVE, STR_1811_TOGGLE_BUILD_REMOVE_FOR}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _build_road_desc = { rubidium@7341: WDP_ALIGN_TBR, 22, 218, 36, 218, 36, rubidium@5893: 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: rubidium@6691: static const Widget _build_tramway_widgets[] = { rubidium@6691: { WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, rubidium@6691: { WWT_CAPTION, RESIZE_NONE, 7, 11, 205, 0, 13, STR_1802_TRAMWAY_CONSTRUCTION, STR_018C_WINDOW_TITLE_DRAG_THIS}, rubidium@6691: { WWT_STICKYBOX, RESIZE_NONE, 7, 206, 217, 0, 13, 0x0, STR_STICKY_BUTTON}, rubidium@6691: rubidium@6691: { WWT_IMGBTN, RESIZE_NONE, 7, 0, 21, 14, 35, SPR_IMG_TRAMWAY_NW, STR_180B_BUILD_TRAMWAY_SECTION}, rubidium@6691: { WWT_IMGBTN, RESIZE_NONE, 7, 22, 43, 14, 35, SPR_IMG_TRAMWAY_NE, STR_180B_BUILD_TRAMWAY_SECTION}, rubidium@6691: { WWT_IMGBTN, RESIZE_NONE, 7, 44, 65, 14, 35, SPR_IMG_DYNAMITE, STR_018D_DEMOLISH_BUILDINGS_ETC}, rubidium@6691: { WWT_IMGBTN, RESIZE_NONE, 7, 66, 87, 14, 35, SPR_IMG_ROAD_DEPOT, STR_180C_BUILD_TRAM_VEHICLE_DEPOT}, rubidium@6691: { WWT_IMGBTN, RESIZE_NONE, 7, 88, 109, 14, 35, SPR_IMG_BUS_STATION, STR_180D_BUILD_PASSENGER_TRAM_STATION}, rubidium@6691: { WWT_IMGBTN, RESIZE_NONE, 7, 110, 131, 14, 35, SPR_IMG_TRUCK_BAY, STR_180E_BUILD_CARGO_TRAM_STATION}, rubidium@6691: rubidium@6691: { WWT_IMGBTN, RESIZE_NONE, 7, 132, 173, 14, 35, SPR_IMG_BRIDGE, STR_180F_BUILD_TRAMWAY_BRIDGE}, rubidium@6691: { WWT_IMGBTN, RESIZE_NONE, 7, 174, 195, 14, 35, SPR_IMG_ROAD_TUNNEL, STR_1810_BUILD_TRAMWAY_TUNNEL}, rubidium@6691: { WWT_IMGBTN, RESIZE_NONE, 7, 196, 217, 14, 35, SPR_IMG_REMOVE, STR_1811_TOGGLE_BUILD_REMOVE_FOR_TRAMWAYS}, rubidium@6691: { WIDGETS_END}, rubidium@6691: }; rubidium@6691: rubidium@6691: static const WindowDesc _build_tramway_desc = { rubidium@7341: WDP_ALIGN_TBR, 22, 218, 36, 218, 36, rubidium@6691: WC_BUILD_TOOLBAR, WC_NONE, rubidium@6691: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON, rubidium@6691: _build_tramway_widgets, rubidium@6691: BuildRoadToolbWndProc rubidium@6691: }; rubidium@6691: rubidium@6666: void ShowBuildRoadToolbar(RoadType roadtype) truelight@0: { Darkvater@5005: if (!IsValidPlayer(_current_player)) return; rubidium@6666: _cur_roadtype = roadtype; Darkvater@5005: truelight@0: DeleteWindowById(WC_BUILD_TOOLBAR, 0); rubidium@6691: Window *w = AllocateWindowDesc(roadtype == ROADTYPE_ROAD ? &_build_road_desc : &_build_tramway_desc); tron@5860: if (_patches.link_terraform_toolbar) ShowTerraformToolbar(w); truelight@0: } truelight@0: truelight@0: static const Widget _build_road_scen_widgets[] = { rubidium@4344: { WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, tron@5689: { WWT_CAPTION, RESIZE_NONE, 7, 11, 139, 0, 13, STR_1802_ROAD_CONSTRUCTION, STR_018C_WINDOW_TITLE_DRAG_THIS}, tron@5689: { WWT_STICKYBOX, RESIZE_NONE, 7, 140, 151, 0, 13, 0x0, STR_STICKY_BUTTON}, darkvater@661: Darkvater@4937: { WWT_IMGBTN, RESIZE_NONE, 7, 0, 21, 14, 35, SPR_IMG_ROAD_NW, STR_180B_BUILD_ROAD_SECTION}, Darkvater@4937: { WWT_IMGBTN, RESIZE_NONE, 7, 22, 43, 14, 35, SPR_IMG_ROAD_NE, STR_180B_BUILD_ROAD_SECTION}, Darkvater@4937: { WWT_IMGBTN, RESIZE_NONE, 7, 44, 65, 14, 35, SPR_IMG_DYNAMITE, STR_018D_DEMOLISH_BUILDINGS_ETC}, rubidium@4344: { WWT_EMPTY, RESIZE_NONE, 0, 0, 0, 0, 0, 0x0, STR_NULL}, rubidium@4344: { WWT_EMPTY, RESIZE_NONE, 0, 0, 0, 0, 0, 0x0, STR_NULL}, rubidium@4344: { WWT_EMPTY, RESIZE_NONE, 0, 0, 0, 0, 0, 0x0, STR_NULL}, Darkvater@4937: { WWT_IMGBTN, RESIZE_NONE, 7, 66, 107, 14, 35, SPR_IMG_BRIDGE, STR_180F_BUILD_ROAD_BRIDGE}, Darkvater@4937: { WWT_IMGBTN, RESIZE_NONE, 7, 108, 129, 14, 35, SPR_IMG_ROAD_TUNNEL, STR_1810_BUILD_ROAD_TUNNEL}, Darkvater@4937: { WWT_IMGBTN, RESIZE_NONE, 7, 130, 151, 14, 35, SPR_IMG_REMOVE, STR_1811_TOGGLE_BUILD_REMOVE_FOR}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _build_road_scen_desc = { rubidium@7341: WDP_AUTO, WDP_AUTO, 152, 36, 152, 36, rubidium@5893: 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@6247: void ShowBuildRoadScenToolbar() truelight@0: { rubidium@6779: _cur_roadtype = ROADTYPE_ROAD; truelight@0: AllocateWindowDescFront(&_build_road_scen_desc, 0); truelight@0: } truelight@0: belugas@4171: static void BuildRoadDepotWndProc(Window *w, WindowEvent *e) tron@2639: { tron@2639: switch (e->event) { belugas@4719: case WE_CREATE: LowerWindowWidget(w, _road_depot_orientation + 3); break; belugas@4719: truelight@0: case WE_PAINT: truelight@0: DrawWindowWidgets(w); truelight@0: rubidium@6666: DrawRoadDepotSprite(70, 17, DIAGDIR_NE, _cur_roadtype); rubidium@6666: DrawRoadDepotSprite(70, 69, DIAGDIR_SE, _cur_roadtype); rubidium@6666: DrawRoadDepotSprite( 2, 69, DIAGDIR_SW, _cur_roadtype); rubidium@6666: DrawRoadDepotSprite( 2, 17, DIAGDIR_NW, _cur_roadtype); truelight@0: break; truelight@0: truelight@0: case WE_CLICK: { belugas@4634: switch (e->we.click.widget) { darkvater@1116: case 3: case 4: case 5: case 6: belugas@4719: RaiseWindowWidget(w, _road_depot_orientation + 3); rubidium@5587: _road_depot_orientation = (DiagDirection)(e->we.click.widget - 3); belugas@4719: LowerWindowWidget(w, _road_depot_orientation + 3); tron@541: SndPlayFx(SND_15_BEEP); truelight@0: SetWindowDirty(w); truelight@0: break; truelight@193: } rubidium@6492: } break; truelight@193: truelight@0: case WE_MOUSELOOP: rubidium@6491: if (WP(w, def_d).close) DeleteWindow(w); truelight@0: break; celestar@1072: celestar@1072: case WE_DESTROY: rubidium@6491: if (!WP(w, def_d).close) ResetObjectToPlace(); celestar@1072: break; truelight@0: } truelight@0: } truelight@0: truelight@0: static const Widget _build_road_depot_widgets[] = { rubidium@4344: { WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@867: { WWT_CAPTION, RESIZE_NONE, 7, 11, 139, 0, 13, STR_1806_ROAD_DEPOT_ORIENTATION, STR_018C_WINDOW_TITLE_DRAG_THIS}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 7, 0, 139, 14, 121, 0x0, STR_NULL}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 14, 71, 136, 17, 66, 0x0, STR_1813_SELECT_ROAD_VEHICLE_DEPOT}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 14, 71, 136, 69, 118, 0x0, STR_1813_SELECT_ROAD_VEHICLE_DEPOT}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 14, 3, 68, 69, 118, 0x0, STR_1813_SELECT_ROAD_VEHICLE_DEPOT}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 14, 3, 68, 17, 66, 0x0, STR_1813_SELECT_ROAD_VEHICLE_DEPOT}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: rubidium@6691: static const Widget _build_tram_depot_widgets[] = { rubidium@6691: { WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, rubidium@6691: { WWT_CAPTION, RESIZE_NONE, 7, 11, 139, 0, 13, STR_1806_TRAM_DEPOT_ORIENTATION, STR_018C_WINDOW_TITLE_DRAG_THIS}, rubidium@6691: { WWT_PANEL, RESIZE_NONE, 7, 0, 139, 14, 121, 0x0, STR_NULL}, rubidium@6691: { WWT_PANEL, RESIZE_NONE, 14, 71, 136, 17, 66, 0x0, STR_1813_SELECT_TRAM_VEHICLE_DEPOT}, rubidium@6691: { WWT_PANEL, RESIZE_NONE, 14, 71, 136, 69, 118, 0x0, STR_1813_SELECT_TRAM_VEHICLE_DEPOT}, rubidium@6691: { WWT_PANEL, RESIZE_NONE, 14, 3, 68, 69, 118, 0x0, STR_1813_SELECT_TRAM_VEHICLE_DEPOT}, rubidium@6691: { WWT_PANEL, RESIZE_NONE, 14, 3, 68, 17, 66, 0x0, STR_1813_SELECT_TRAM_VEHICLE_DEPOT}, rubidium@6691: { WIDGETS_END}, rubidium@6691: }; rubidium@6691: truelight@0: static const WindowDesc _build_road_depot_desc = { rubidium@7341: 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@6691: static const WindowDesc _build_tram_depot_desc = { rubidium@7341: WDP_AUTO, WDP_AUTO, 140, 122, 140, 122, rubidium@6691: WC_BUILD_DEPOT, WC_BUILD_TOOLBAR, rubidium@6691: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, rubidium@6691: _build_tram_depot_widgets, rubidium@6691: BuildRoadDepotWndProc rubidium@6691: }; rubidium@6691: rubidium@6247: static void ShowRoadDepotPicker() truelight@0: { rubidium@6691: AllocateWindowDesc(_cur_roadtype == ROADTYPE_ROAD ? &_build_road_depot_desc : &_build_tram_depot_desc); truelight@0: } truelight@0: darkvater@987: static void RoadStationPickerWndProc(Window *w, WindowEvent *e) darkvater@987: { tron@2952: switch (e->event) { belugas@4719: case WE_CREATE: rubidium@6677: /* Trams don't have non-drivethrough stations */ rubidium@6677: if (_cur_roadtype == ROADTYPE_TRAM && _road_station_picker_orientation < DIAGDIR_END) { rubidium@6677: _road_station_picker_orientation = DIAGDIR_END; rubidium@6677: } rubidium@6677: SetWindowWidgetsDisabledState(w, _cur_roadtype == ROADTYPE_TRAM, 3, 4, 5, 6, WIDGET_LIST_END); rubidium@6677: belugas@4719: LowerWindowWidget(w, _road_station_picker_orientation + 3); rubidium@6012: LowerWindowWidget(w, _station_show_coverage + 9); belugas@4719: break; belugas@4719: truelight@0: case WE_PAINT: { rubidium@6491: if (WP(w, def_d).close) return; darkvater@987: truelight@0: DrawWindowWidgets(w); truelight@0: darkvater@987: if (_station_show_coverage) { darkvater@987: int rad = _patches.modified_catchment ? CA_TRUCK /* = CA_BUS */ : 4; darkvater@987: SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad); tron@4077: } else { darkvater@987: SetTileSelectSize(1, 1); tron@4077: } truelight@0: rubidium@7272: StationType st = (w->window_class == WC_BUS_STATION) ? STATION_BUS : STATION_TRUCK; truelight@0: rubidium@7272: StationPickerDrawSprite(103, 35, st, RAILTYPE_BEGIN, ROADTYPE_ROAD, 0); rubidium@7272: StationPickerDrawSprite(103, 85, st, RAILTYPE_BEGIN, ROADTYPE_ROAD, 1); rubidium@7272: StationPickerDrawSprite( 35, 85, st, RAILTYPE_BEGIN, ROADTYPE_ROAD, 2); rubidium@7272: StationPickerDrawSprite( 35, 35, st, RAILTYPE_BEGIN, ROADTYPE_ROAD, 3); truelight@0: rubidium@7272: StationPickerDrawSprite(171, 35, st, RAILTYPE_BEGIN, _cur_roadtype, 4); rubidium@7272: StationPickerDrawSprite(171, 85, st, RAILTYPE_BEGIN, _cur_roadtype, 5); rubidium@6012: truelight@0: DrawStationCoverageAreaText(2, 146, rubidium@7241: (w->window_class == WC_BUS_STATION) ? SCT_PASSENGERS_ONLY : SCT_NON_PASSENGERS_ONLY, Celestar@568: 3); truelight@0: truelight@0: } break; truelight@0: truelight@0: case WE_CLICK: { belugas@4634: switch (e->we.click.widget) { rubidium@6012: case 3: case 4: case 5: case 6: case 7: case 8: belugas@4719: RaiseWindowWidget(w, _road_station_picker_orientation + 3); rubidium@5587: _road_station_picker_orientation = (DiagDirection)(e->we.click.widget - 3); belugas@4719: LowerWindowWidget(w, _road_station_picker_orientation + 3); tron@541: SndPlayFx(SND_15_BEEP); truelight@0: SetWindowDirty(w); truelight@0: break; rubidium@6012: case 9: case 10: rubidium@6012: RaiseWindowWidget(w, _station_show_coverage + 9); rubidium@6012: _station_show_coverage = (e->we.click.widget != 9); rubidium@6012: LowerWindowWidget(w, _station_show_coverage + 9); tron@541: SndPlayFx(SND_15_BEEP); truelight@0: SetWindowDirty(w); truelight@0: break; truelight@0: } truelight@0: } break; truelight@193: truelight@0: case WE_MOUSELOOP: { rubidium@6491: 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@6491: if (!WP(w, def_d).close) ResetObjectToPlace(); celestar@1072: break; truelight@193: } truelight@0: } truelight@0: rubidium@6693: static const Widget _rv_station_picker_widgets[] = { rubidium@4344: { WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, rubidium@6693: { WWT_CAPTION, RESIZE_NONE, 7, 11, 206, 0, 13, STR_NULL, STR_018C_WINDOW_TITLE_DRAG_THIS}, rubidium@6012: { WWT_PANEL, RESIZE_NONE, 7, 0, 206, 14, 176, 0x0, STR_NULL}, rubidium@6693: { WWT_PANEL, RESIZE_NONE, 14, 71, 136, 17, 66, 0x0, STR_NULL}, rubidium@6693: { WWT_PANEL, RESIZE_NONE, 14, 71, 136, 69, 118, 0x0, STR_NULL}, rubidium@6693: { WWT_PANEL, RESIZE_NONE, 14, 3, 68, 69, 118, 0x0, STR_NULL}, rubidium@6693: { WWT_PANEL, RESIZE_NONE, 14, 3, 68, 17, 66, 0x0, STR_NULL}, rubidium@6693: { WWT_PANEL, RESIZE_NONE, 14, 139, 204, 17, 66, 0x0, STR_NULL}, rubidium@6693: { WWT_PANEL, RESIZE_NONE, 14, 139, 204, 69, 118, 0x0, STR_NULL}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 14, 10, 69, 133, 144, STR_02DB_OFF, STR_3065_DON_T_HIGHLIGHT_COVERAGE}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 14, 70, 129, 133, 144, STR_02DA_ON, STR_3064_HIGHLIGHT_COVERAGE_AREA}, Darkvater@4938: { WWT_LABEL, RESIZE_NONE, 7, 0, 139, 120, 133, STR_3066_COVERAGE_AREA_HIGHLIGHT, STR_NULL}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: rubidium@6693: static const WindowDesc _rv_station_picker_desc = { rubidium@7341: 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@6693: _rv_station_picker_widgets, truelight@0: RoadStationPickerWndProc truelight@0: }; truelight@0: rubidium@6693: static void ShowRVStationPicker(RoadStop::Type rs) truelight@0: { rubidium@6693: Window *w = AllocateWindowDesc(&_rv_station_picker_desc); rubidium@6693: if (w == NULL) return; truelight@0: rubidium@6701: w->window_class = (rs == RoadStop::BUS) ? WC_BUS_STATION : WC_TRUCK_STATION; rubidium@6693: w->widget[1].data = _road_type_infos[_cur_roadtype].picker_title[rs]; rubidium@6693: for (uint i = 3; i < 9; i++) w->widget[i].tooltips = _road_type_infos[_cur_roadtype].picker_tooltip[rs]; truelight@0: } truelight@0: rubidium@6247: void InitializeRoadGui() truelight@0: { rubidium@5587: _road_depot_orientation = DIAGDIR_NW; rubidium@5587: _road_station_picker_orientation = DIAGDIR_NW; truelight@0: }