truelight@0: #include "stdafx.h" truelight@0: #include "ttd.h" tron@1363: #include "table/sprites.h" tron@507: #include "table/strings.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" truelight@0: #include "vehicle.h" darkvater@393: #include "station.h" truelight@1542: #include "waypoint.h" truelight@0: truelight@0: static uint _cur_railtype; truelight@0: static bool _remove_button_clicked; truelight@0: static byte _build_depot_direction; dominik@411: static byte _waypoint_count=1; darkvater@395: static byte _cur_waypoint_type; truelight@0: truelight@0: struct { truelight@0: byte orientation; truelight@0: byte numtracks; truelight@0: byte platlength; truelight@0: bool dragdrop; truelight@0: } _railstation; truelight@0: truelight@0: truelight@0: static void HandleStationPlacement(uint start, uint end); tron@1093: static void ShowBuildTrainDepotPicker(void); tron@1093: static void ShowBuildWaypointPicker(void); tron@1093: static void ShowStationBuilder(void); truelight@0: truelight@0: typedef void OnButtonClick(Window *w); truelight@0: truelight@543: void CcPlaySound1E(bool success, uint tile, uint32 p1, uint32 p2) truelight@0: { tron@541: if (success) SndPlayTileFx(SND_20_SPLAT_2, tile); truelight@0: } truelight@0: truelight@0: static void GenericPlaceRail(uint tile, int cmd) truelight@0: { truelight@0: DoCommandP(tile, _cur_railtype, cmd, CcPlaySound1E, truelight@201: _remove_button_clicked ? truelight@201: CMD_REMOVE_SINGLE_RAIL | CMD_MSG(STR_1012_CAN_T_REMOVE_RAILROAD_TRACK) | CMD_AUTO | CMD_NO_WATER : truelight@0: CMD_BUILD_SINGLE_RAIL | CMD_MSG(STR_1011_CAN_T_BUILD_RAILROAD_TRACK) | CMD_AUTO | CMD_NO_WATER truelight@0: ); truelight@0: } truelight@0: truelight@0: static void PlaceRail_N(uint tile) truelight@0: { truelight@0: int cmd = _tile_fract_coords.x > _tile_fract_coords.y ? 4 : 5; truelight@0: GenericPlaceRail(tile, cmd); truelight@0: } truelight@0: truelight@0: static void PlaceRail_NE(uint tile) truelight@0: { truelight@0: VpStartPlaceSizing(tile, VPM_FIX_Y); truelight@0: } truelight@0: truelight@0: static void PlaceRail_E(uint tile) truelight@0: { truelight@0: int cmd = _tile_fract_coords.x + _tile_fract_coords.y <= 15 ? 2 : 3; truelight@0: GenericPlaceRail(tile, cmd); truelight@0: } truelight@0: truelight@0: static void PlaceRail_NW(uint tile) truelight@0: { truelight@0: VpStartPlaceSizing(tile, VPM_FIX_X); truelight@0: } truelight@0: truelight@0: static void PlaceRail_AutoRail(uint tile) truelight@0: { truelight@0: VpStartPlaceSizing(tile, VPM_RAILDIRS); truelight@0: } truelight@0: truelight@0: static void PlaceExtraDepotRail(uint tile, uint16 extra) truelight@0: { truelight@0: byte b = _map5[tile]; truelight@0: truelight@0: if (b & 0xC0 || !(b & (extra >> 8))) truelight@0: return; truelight@0: truelight@201: DoCommandP(tile, _cur_railtype, extra & 0xFF, NULL, CMD_BUILD_SINGLE_RAIL | CMD_AUTO | CMD_NO_WATER); truelight@0: } truelight@0: truelight@0: static const uint16 _place_depot_extra[12] = { truelight@0: 0x604, 0x2102, 0x1202, 0x505, truelight@0: 0x2400, 0x2801, 0x1800, 0x1401, truelight@0: 0x2203, 0x904, 0x0A05, 0x1103, truelight@0: }; truelight@0: truelight@0: truelight@543: void CcRailDepot(bool success, uint tile, uint32 p1, uint32 p2) truelight@0: { truelight@0: if (success) { truelight@0: int dir = p2; truelight@0: tron@541: SndPlayTileFx(SND_20_SPLAT_2, tile); truelight@0: ResetObjectToPlace(); truelight@0: tron@900: tile += TileOffsByDir(dir); truelight@0: tron@1035: if (IsTileType(tile, MP_RAILWAY)) { truelight@0: PlaceExtraDepotRail(tile, _place_depot_extra[dir]); truelight@0: PlaceExtraDepotRail(tile, _place_depot_extra[dir + 4]); truelight@0: PlaceExtraDepotRail(tile, _place_depot_extra[dir + 8]); truelight@0: } truelight@201: } truelight@0: } truelight@0: truelight@0: static void PlaceRail_Depot(uint tile) truelight@0: { truelight@543: DoCommandP(tile, _cur_railtype, _build_depot_direction, CcRailDepot, truelight@0: CMD_BUILD_TRAIN_DEPOT | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_100E_CAN_T_BUILD_TRAIN_DEPOT)); truelight@0: } truelight@0: darkvater@395: static void PlaceRail_Waypoint(uint tile) truelight@0: { truelight@0: if (!_remove_button_clicked) { darkvater@395: DoCommandP(tile, _waypoint_count > 0 ? (0x100 + _cur_waypoint_type) : 0, 0, CcPlaySound1E, CMD_BUILD_TRAIN_WAYPOINT | CMD_MSG(STR_CANT_BUILD_TRAIN_WAYPOINT)); truelight@0: } else { darkvater@395: DoCommandP(tile, 0, 0, CcPlaySound1E, CMD_REMOVE_TRAIN_WAYPOINT | CMD_MSG(STR_CANT_REMOVE_TRAIN_WAYPOINT)); truelight@0: } truelight@0: } truelight@0: truelight@543: void CcStation(bool success, uint tile, uint32 p1, uint32 p2) truelight@0: { truelight@0: if (success) { tron@541: SndPlayTileFx(SND_20_SPLAT_2, tile); truelight@0: ResetObjectToPlace(); truelight@0: } truelight@0: } truelight@0: truelight@0: static void PlaceRail_Station(uint tile) truelight@0: { truelight@0: if(_remove_button_clicked) truelight@0: DoCommandP(tile, 0, 0, CcPlaySound1E, CMD_REMOVE_FROM_RAILROAD_STATION | CMD_MSG(STR_CANT_REMOVE_PART_OF_STATION)); truelight@0: else if (_railstation.dragdrop) { truelight@0: VpStartPlaceSizing(tile, VPM_X_AND_Y_LIMITED); truelight@0: VpSetPlaceSizingLimit(_patches.station_spread); truelight@0: } else { tron@449: // TODO: Custom station selector GUI. Now we just try using first custom station tron@449: // (and fall back to normal stations if it isn't available). tron@449: DoCommandP(tile, _railstation.orientation | (_railstation.numtracks<<8) | (_railstation.platlength<<16),_cur_railtype|1<<4, CcStation, truelight@0: CMD_BUILD_RAILROAD_STATION | CMD_NO_WATER | CMD_AUTO | CMD_MSG(STR_100F_CAN_T_BUILD_RAILROAD_STATION)); truelight@0: } truelight@0: } truelight@0: darkvater@58: static void GenericPlaceSignals(uint tile) truelight@0: { truelight@0: uint trackstat; truelight@0: int i; truelight@0: truelight@159: trackstat = (byte)GetTileTrackStatus(tile, TRANSPORT_RAIL); truelight@0: darkvater@1123: if ((trackstat & 0x30)) // N-S direction truelight@0: trackstat = (_tile_fract_coords.x <= _tile_fract_coords.y) ? 0x20 : 0x10; truelight@0: darkvater@1123: if ((trackstat & 0x0C)) // E-W direction truelight@0: trackstat = (_tile_fract_coords.x + _tile_fract_coords.y <= 15) ? 4 : 8; truelight@0: truelight@0: // Lookup the bit index truelight@0: i = 0; truelight@0: if (trackstat != 0) { while (!(trackstat & 1)) { i++; trackstat >>= 1; }} truelight@0: truelight@0: if (!_remove_button_clicked) { truelight@0: DoCommandP(tile, i + (_ctrl_pressed ? 8 : 0), 0, CcPlaySound1E, truelight@0: CMD_BUILD_SIGNALS | CMD_AUTO | CMD_MSG(STR_1010_CAN_T_BUILD_SIGNALS_HERE)); truelight@0: } else { truelight@0: DoCommandP(tile, i, 0, CcPlaySound1E, truelight@0: CMD_REMOVE_SIGNALS | CMD_AUTO | CMD_MSG(STR_1013_CAN_T_REMOVE_SIGNALS_FROM)); truelight@0: } truelight@0: } truelight@0: truelight@0: static void PlaceRail_Bridge(uint tile) truelight@0: { truelight@0: VpStartPlaceSizing(tile, VPM_X_OR_Y); truelight@0: } truelight@0: truelight@543: void CcBuildRailTunnel(bool success, uint 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: truelight@0: static void PlaceRail_Tunnel(uint tile) truelight@0: { truelight@543: DoCommandP(tile, _cur_railtype, 0, CcBuildRailTunnel, truelight@0: CMD_BUILD_TUNNEL | CMD_AUTO | CMD_MSG(STR_5016_CAN_T_BUILD_TUNNEL_HERE)); truelight@0: } truelight@0: truelight@0: void PlaceProc_BuyLand(uint tile) truelight@0: { truelight@0: DoCommandP(tile, 0, 0, CcPlaySound1E, CMD_PURCHASE_LAND_AREA | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_5806_CAN_T_PURCHASE_THIS_LAND)); truelight@0: } truelight@0: truelight@0: static void PlaceRail_ConvertRail(uint tile) truelight@0: { truelight@0: VpStartPlaceSizing(tile, VPM_X_AND_Y | (1<<4)); truelight@0: } truelight@0: darkvater@58: static void PlaceRail_AutoSignals(uint tile) darkvater@58: { darkvater@58: VpStartPlaceSizing(tile, VPM_SIGNALDIRS); darkvater@58: } darkvater@58: truelight@0: static void BuildRailClick_N(Window *w) truelight@0: { darkvater@756: HandlePlacePushButton(w, 4, _cur_railtype*4 + 0x4EF, 1, PlaceRail_N); truelight@0: } truelight@0: truelight@0: static void BuildRailClick_NE(Window *w) truelight@0: { darkvater@756: HandlePlacePushButton(w, 5, _cur_railtype*4 + 0x4F0, 1, PlaceRail_NE); truelight@0: } truelight@0: truelight@0: static void BuildRailClick_E(Window *w) truelight@0: { darkvater@756: HandlePlacePushButton(w, 6, _cur_railtype*4 + 0x4F1, 1, PlaceRail_E); truelight@0: } truelight@0: truelight@0: static void BuildRailClick_NW(Window *w) truelight@0: { darkvater@756: HandlePlacePushButton(w, 7, _cur_railtype*4 + 0x4F2, 1, PlaceRail_NW); dominik@606: } dominik@606: dominik@606: static void BuildRailClick_AutoRail(Window *w) dominik@606: { dominik@1070: HandlePlacePushButton(w, 8, _cur_railtype + SPR_CURSOR_AUTORAIL, VHM_RAIL, PlaceRail_AutoRail); truelight@0: } truelight@0: truelight@0: static void BuildRailClick_Demolish(Window *w) truelight@0: { darkvater@756: HandlePlacePushButton(w, 9, ANIMCURSOR_DEMOLISH, 1, PlaceProc_DemolishArea); truelight@0: } truelight@0: truelight@0: static const SpriteID _depot_cursors[] = { truelight@0: 0x510, truelight@0: SPR_OPENTTD_BASE + 14, truelight@0: SPR_OPENTTD_BASE + 15, truelight@0: }; truelight@0: truelight@0: static void BuildRailClick_Depot(Window *w) truelight@0: { darkvater@756: if (HandlePlacePushButton(w, 10, _depot_cursors[_cur_railtype], 1, PlaceRail_Depot)) ShowBuildTrainDepotPicker(); dominik@606: } dominik@606: dominik@606: static void BuildRailClick_Waypoint(Window *w) dominik@606: { dominik@606: _waypoint_count = GetCustomStationsCount(STAT_CLASS_WAYP); darkvater@756: if (HandlePlacePushButton(w, 11, SPR_OPENTTD_BASE + 7, 1, PlaceRail_Waypoint) dominik@606: && _waypoint_count > 1) dominik@606: ShowBuildWaypointPicker(); truelight@0: } truelight@0: truelight@0: static void BuildRailClick_Station(Window *w) truelight@0: { darkvater@756: if (HandlePlacePushButton(w, 12, 0x514, 1, PlaceRail_Station)) ShowStationBuilder(); truelight@0: } truelight@0: darkvater@58: static void BuildRailClick_AutoSignals(Window *w) truelight@0: { dominik@1070: HandlePlacePushButton(w, 13, ANIMCURSOR_BUILDSIGNALS, VHM_RECT, PlaceRail_AutoSignals); truelight@0: } truelight@0: truelight@0: static void BuildRailClick_Bridge(Window *w) truelight@0: { darkvater@756: HandlePlacePushButton(w, 14, 0xA21, 1, PlaceRail_Bridge); truelight@0: } truelight@0: truelight@0: static void BuildRailClick_Tunnel(Window *w) truelight@0: { darkvater@756: HandlePlacePushButton(w, 15, 0x982 + _cur_railtype, 3, PlaceRail_Tunnel); truelight@0: } truelight@0: truelight@0: static void BuildRailClick_Remove(Window *w) truelight@0: { darkvater@756: if (w->disabled_state & (1<<16)) truelight@0: return; truelight@0: SetWindowDirty(w); tron@541: SndPlayFx(SND_15_BEEP); truelight@201: darkvater@756: _thd.make_square_red = !!((w->click_state ^= (1 << 16)) & (1<<16)); tron@514: MarkTileDirty(_thd.pos.x, _thd.pos.y); darkvater@756: _remove_button_clicked = (w->click_state & (1 << 16)) != 0; truelight@201: truelight@0: // handle station builder darkvater@756: if( w->click_state & (1 << 16) ) truelight@0: { truelight@0: if(_remove_button_clicked) truelight@0: SetTileSelectSize(1, 1); truelight@0: else truelight@0: BringWindowToFrontById(WC_BUILD_STATION, 0); truelight@0: } truelight@0: } truelight@0: dominik@606: static void BuildRailClick_Convert(Window *w) truelight@0: { darkvater@756: HandlePlacePushButton(w, 17, (SPR_OPENTTD_BASE + 26) + _cur_railtype * 2, 1, PlaceRail_ConvertRail); truelight@0: } truelight@0: dominik@606: static void BuildRailClick_Landscaping(Window *w) truelight@0: { dominik@606: ShowTerraformToolbar(); truelight@0: } truelight@0: truelight@0: static void DoRailroadTrack(int mode) truelight@0: { darkvater@1227: DoCommandP(TILE_FROM_XY(_thd.selstart.x, _thd.selstart.y), TILE_FROM_XY(_thd.selend.x, _thd.selend.y), _cur_railtype | (mode << 4), NULL, truelight@201: _remove_button_clicked ? truelight@0: CMD_REMOVE_RAILROAD_TRACK | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1012_CAN_T_REMOVE_RAILROAD_TRACK) : darkvater@1227: CMD_BUILD_RAILROAD_TRACK | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1011_CAN_T_BUILD_RAILROAD_TRACK) truelight@0: ); truelight@0: } truelight@0: tron@1093: static void HandleAutodirPlacement(void) truelight@0: { truelight@0: TileHighlightData *thd = &_thd; darkvater@1227: int trackstat = thd->drawstyle & 0xF; // 0..5 truelight@201: dominik@1070: if (thd->drawstyle & HT_RAIL) { // one tile case darkvater@1227: GenericPlaceRail(TILE_FROM_XY(thd->selend.x, thd->selend.y), trackstat); darkvater@1227: return; truelight@0: } darkvater@1227: darkvater@1227: DoRailroadTrack(trackstat); truelight@0: } truelight@0: dominik@1070: static void HandleAutoSignalPlacement(void) darkvater@58: { darkvater@58: TileHighlightData *thd = &_thd; darkvater@1227: byte trackstat = thd->drawstyle & 0xF; // 0..5 truelight@201: darkvater@1123: if (thd->drawstyle == HT_RECT) { // one tile case darkvater@58: GenericPlaceSignals(TILE_FROM_XY(thd->selend.x, thd->selend.y)); darkvater@1123: return; darkvater@1123: } darkvater@58: darkvater@1123: // _patches.drag_signals_density is given as a parameter such that each user in a network darkvater@1123: // game can specify his/her own signal density darkvater@1123: DoCommandP(TILE_FROM_XY(thd->selstart.x, thd->selstart.y), TILE_FROM_XY(thd->selend.x, thd->selend.y), darkvater@1227: (_ctrl_pressed ? 1 << 3 : 0) | (trackstat << 4) | (_patches.drag_signals_density << 24), darkvater@1123: CcPlaySound1E, darkvater@1227: (_remove_button_clicked ? CMD_REMOVE_SIGNAL_TRACK | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1013_CAN_T_REMOVE_SIGNALS_FROM) : darkvater@1227: CMD_BUILD_SIGNAL_TRACK | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1010_CAN_T_BUILD_SIGNALS_HERE) ) ); darkvater@58: } darkvater@58: truelight@0: static OnButtonClick * const _build_railroad_button_proc[] = { truelight@0: BuildRailClick_N, truelight@0: BuildRailClick_NE, truelight@0: BuildRailClick_E, truelight@0: BuildRailClick_NW, dominik@606: BuildRailClick_AutoRail, truelight@0: BuildRailClick_Demolish, truelight@0: BuildRailClick_Depot, dominik@606: BuildRailClick_Waypoint, truelight@0: BuildRailClick_Station, darkvater@58: BuildRailClick_AutoSignals, truelight@0: BuildRailClick_Bridge, truelight@0: BuildRailClick_Tunnel, truelight@0: BuildRailClick_Remove, truelight@0: BuildRailClick_Convert, dominik@606: BuildRailClick_Landscaping, truelight@0: }; truelight@0: truelight@0: static const uint16 _rail_keycodes[] = { truelight@0: '1', truelight@0: '2', truelight@0: '3', truelight@0: '4', dominik@606: '5', truelight@0: '6', dominik@606: '7', // depot dominik@606: '8', // waypoint dominik@606: '9', // station dominik@606: 'S', // signals dominik@606: 'B', // bridge dominik@606: 'T', // tunnel dominik@606: 'R', // remove dominik@606: 'C', // convert rail dominik@606: 'L', // landscaping truelight@0: }; truelight@0: truelight@0: truelight@0: truelight@0: truelight@0: static void BuildRailToolbWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: switch(e->event) { truelight@0: case WE_PAINT: darkvater@756: w->disabled_state &= ~(1 << 16); darkvater@756: if (!(w->click_state & ((1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)|(1<<11)|(1<<12)|(1<<13)))) { darkvater@756: w->disabled_state |= (1 << 16); darkvater@756: w->click_state &= ~(1<<16); truelight@0: } truelight@0: DrawWindowWidgets(w); truelight@0: break; truelight@0: truelight@0: case WE_CLICK: darkvater@756: if (e->click.widget >= 4) { truelight@0: _remove_button_clicked = false; darkvater@756: _build_railroad_button_proc[e->click.widget - 4](w); truelight@0: } truelight@0: break; truelight@0: truelight@0: case WE_KEYPRESS: { truelight@0: int i; dominik@616: darkvater@756: for(i=0; i!=lengthof(_rail_keycodes); i++) { truelight@0: if (e->keypress.keycode == _rail_keycodes[i]) { truelight@0: e->keypress.cont = false; truelight@0: _remove_button_clicked = false; truelight@0: _build_railroad_button_proc[i](w); truelight@0: break; truelight@0: } darkvater@756: } darkvater@756: MarkTileDirty(_thd.pos.x, _thd.pos.y); // redraw tile selection truelight@0: break; truelight@0: } truelight@0: truelight@0: case WE_PLACE_OBJ: truelight@0: _place_proc(e->place.tile); truelight@0: return; truelight@0: truelight@0: case WE_PLACE_DRAG: { truelight@0: VpSelectTilesWithMethod(e->place.pt.x, e->place.pt.y, e->place.userdata & 0xF); truelight@0: return; truelight@0: } truelight@0: truelight@0: case WE_PLACE_MOUSEUP: truelight@0: if (e->click.pt.x != -1) { truelight@0: uint start_tile = e->place.starttile; truelight@0: uint end_tile = e->place.tile; truelight@0: truelight@0: if (e->place.userdata == VPM_X_OR_Y) { truelight@0: ResetObjectToPlace(); truelight@0: ShowBuildBridgeWindow(start_tile, end_tile, _cur_railtype); truelight@0: } else if (e->place.userdata == VPM_RAILDIRS) { truelight@0: bool old = _remove_button_clicked; truelight@0: if (_ctrl_pressed) _remove_button_clicked = true; truelight@0: HandleAutodirPlacement(); truelight@0: _remove_button_clicked = old; darkvater@58: } else if (e->place.userdata == VPM_SIGNALDIRS) { darkvater@58: HandleAutoSignalPlacement(); truelight@0: } else if (e->place.userdata == VPM_X_AND_Y) { truelight@0: DoCommandP(end_tile, start_tile, 0, CcPlaySound10, CMD_CLEAR_AREA | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA)); truelight@0: } else if (e->place.userdata == (VPM_X_AND_Y | (1<<4))) { truelight@0: DoCommandP(end_tile, start_tile, _cur_railtype, CcPlaySound10, CMD_CONVERT_RAIL | CMD_MSG(STR_CANT_CONVERT_RAIL)); truelight@0: } else if (e->place.userdata == (VPM_X_AND_Y | (2<<4))) { truelight@0: DoCommandP(end_tile, start_tile, _cur_railtype, CcPlaySound10, CMD_LEVEL_LAND | CMD_AUTO); truelight@0: } else if (e->place.userdata == VPM_X_AND_Y_LIMITED) { truelight@0: HandleStationPlacement(start_tile, end_tile); darkvater@1227: } else darkvater@1227: DoRailroadTrack(e->place.userdata & 1); truelight@0: } truelight@0: break; truelight@0: truelight@0: case WE_ABORT_PLACE_OBJ: darkvater@756: UnclickWindowButtons(w); truelight@0: SetWindowDirty(w); truelight@0: truelight@0: w = FindWindowById(WC_BUILD_STATION, 0); truelight@0: if (w != NULL) WP(w,def_d).close=true; truelight@0: w = FindWindowById(WC_BUILD_DEPOT, 0); truelight@0: if (w != NULL) WP(w,def_d).close=true; truelight@0: break; truelight@0: truelight@0: case WE_PLACE_PRESIZE: { truelight@0: uint tile = e->place.tile; truelight@0: DoCommandByTile(tile, 0, 0, DC_AUTO, CMD_BUILD_TUNNEL); truelight@0: VpSetPresizeRange(tile, _build_tunnel_endtile==0?tile:_build_tunnel_endtile); truelight@0: } break; truelight@0: } truelight@0: } truelight@0: dominik@606: truelight@0: static const Widget _build_railroad_widgets[] = { truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5,STR_018B_CLOSE_WINDOW}, truelight@867: { WWT_CAPTION, RESIZE_NONE, 7, 11, 359, 0, 13, STR_100A_RAILROAD_CONSTRUCTION, STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@867: { WWT_STICKYBOX, RESIZE_NONE, 7, 360, 371, 0, 13, 0x0, STR_STICKY_BUTTON}, truelight@0: truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 110, 113, 14, 35, 0x0, STR_NULL}, truelight@0: truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 0, 21, 14, 35, 0x4E3, STR_1018_BUILD_RAILROAD_TRACK}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 22, 43, 14, 35, 0x4E4, STR_1018_BUILD_RAILROAD_TRACK}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 44, 65, 14, 35, 0x4E5, STR_1018_BUILD_RAILROAD_TRACK}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 66, 87, 14, 35, 0x4E6, STR_1018_BUILD_RAILROAD_TRACK}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 88, 109, 14, 35, SPR_OPENTTD_BASE + 0, STR_BUILD_AUTORAIL_TIP}, truelight@0: truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 114, 135, 14, 35, 0x2BF, STR_018D_DEMOLISH_BUILDINGS_ETC}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 136, 157, 14, 35, 0x50E, STR_1019_BUILD_TRAIN_DEPOT_FOR_BUILDING}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 158, 179, 14, 35, SPR_OPENTTD_BASE + 3, STR_CONVERT_RAIL_TO_WAYPOINT_TIP}, truelight@867: truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 180, 221, 14, 35, 0x512, STR_101A_BUILD_RAILROAD_STATION}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 222, 243, 14, 35, 0x50B, STR_101B_BUILD_RAILROAD_SIGNALS}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 244, 285, 14, 35, 0xA22, STR_101C_BUILD_RAILROAD_BRIDGE}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 286, 305, 14, 35, 0x97E, STR_101D_BUILD_RAILROAD_TUNNEL}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 306, 327, 14, 35, 0x2CA, STR_101E_TOGGLE_BUILD_REMOVE_FOR}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 328, 349, 14, 35, SPR_OPENTTD_BASE + 25, STR_CONVERT_RAIL_TIP}, truelight@867: truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 350, 371, 14, 35, SPR_IMG_LANDSCAPING, STR_LANDSCAPING_TOOLBAR_TIP}, truelight@0: darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _build_railroad_desc = { dominik@606: 640-372, 22, 372, 36, truelight@0: WC_BUILD_TOOLBAR,0, darkvater@756: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON, truelight@0: _build_railroad_widgets, truelight@0: BuildRailToolbWndProc truelight@0: }; truelight@0: truelight@0: static const Widget _build_monorail_widgets[] = { truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5,STR_018B_CLOSE_WINDOW}, truelight@867: { WWT_CAPTION, RESIZE_NONE, 7, 11, 359, 0, 13, STR_100B_MONORAIL_CONSTRUCTION, STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@867: { WWT_STICKYBOX, RESIZE_NONE, 7, 360, 371, 0, 13, 0x0, STR_STICKY_BUTTON}, truelight@0: truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 110, 113, 14, 35, 0x0, STR_NULL}, truelight@0: truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 0, 21, 14, 35, 0x4E7, STR_1018_BUILD_RAILROAD_TRACK}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 22, 43, 14, 35, 0x4E8, STR_1018_BUILD_RAILROAD_TRACK}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 44, 65, 14, 35, 0x4E9, STR_1018_BUILD_RAILROAD_TRACK}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 66, 87, 14, 35, 0x4EA, STR_1018_BUILD_RAILROAD_TRACK}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 88, 109, 14, 35, SPR_OPENTTD_BASE + 1, STR_BUILD_AUTORAIL_TIP}, truelight@0: truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 114, 135, 14, 35, 0x2BF, STR_018D_DEMOLISH_BUILDINGS_ETC}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 136, 157, 14, 35, SPR_OPENTTD_BASE + 12, STR_1019_BUILD_TRAIN_DEPOT_FOR_BUILDING}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 158, 179, 14, 35, SPR_OPENTTD_BASE + 3, STR_CONVERT_RAIL_TO_WAYPOINT_TIP}, truelight@867: truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 180, 221, 14, 35, 0x512, STR_101A_BUILD_RAILROAD_STATION}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 222, 243, 14, 35, 0x50B, STR_101B_BUILD_RAILROAD_SIGNALS}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 244, 285, 14, 35, 0xA22, STR_101C_BUILD_RAILROAD_BRIDGE}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 286, 305, 14, 35, 0x97F, STR_101D_BUILD_RAILROAD_TUNNEL}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 306, 327, 14, 35, 0x2CA, STR_101E_TOGGLE_BUILD_REMOVE_FOR}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 328, 349, 14, 35, SPR_OPENTTD_BASE + 27, STR_CONVERT_RAIL_TIP}, truelight@867: truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 350, 371, 14, 35, SPR_IMG_LANDSCAPING, STR_LANDSCAPING_TOOLBAR_TIP}, dominik@606: darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _build_monorail_desc = { dominik@606: 640-372, 22, 372, 36, truelight@0: WC_BUILD_TOOLBAR,0, darkvater@756: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON, truelight@0: _build_monorail_widgets, truelight@0: BuildRailToolbWndProc truelight@0: }; truelight@0: truelight@0: static const Widget _build_maglev_widgets[] = { truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5,STR_018B_CLOSE_WINDOW}, truelight@867: { WWT_CAPTION, RESIZE_NONE, 7, 11, 359, 0, 13, STR_100C_MAGLEV_CONSTRUCTION, STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@867: { WWT_STICKYBOX, RESIZE_NONE, 7, 360, 371, 0, 13, 0x0, STR_STICKY_BUTTON}, truelight@0: truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 110, 113, 14, 35, 0x0, STR_NULL}, truelight@0: truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 0, 21, 14, 35, 0x4EB, STR_1018_BUILD_RAILROAD_TRACK}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 22, 43, 14, 35, 0x4EC, STR_1018_BUILD_RAILROAD_TRACK}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 44, 65, 14, 35, 0x4EE, STR_1018_BUILD_RAILROAD_TRACK}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 66, 87, 14, 35, 0x4ED, STR_1018_BUILD_RAILROAD_TRACK}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 88, 109, 14, 35, SPR_OPENTTD_BASE + 2, STR_BUILD_AUTORAIL_TIP}, truelight@0: truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 114, 135, 14, 35, 0x2BF, STR_018D_DEMOLISH_BUILDINGS_ETC}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 136, 157, 14, 35, SPR_OPENTTD_BASE + 13, STR_1019_BUILD_TRAIN_DEPOT_FOR_BUILDING}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 158, 179, 14, 35, SPR_OPENTTD_BASE + 3, STR_CONVERT_RAIL_TO_WAYPOINT_TIP}, truelight@867: truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 180, 221, 14, 35, 0x512, STR_101A_BUILD_RAILROAD_STATION}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 222, 243, 14, 35, 0x50B, STR_101B_BUILD_RAILROAD_SIGNALS}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 244, 285, 14, 35, 0xA22, STR_101C_BUILD_RAILROAD_BRIDGE}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 286, 305, 14, 35, 0x980, STR_101D_BUILD_RAILROAD_TUNNEL}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 306, 327, 14, 35, 0x2CA, STR_101E_TOGGLE_BUILD_REMOVE_FOR}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 328, 349, 14, 35, SPR_OPENTTD_BASE + 29, STR_CONVERT_RAIL_TIP}, truelight@867: truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 350, 371, 14, 35, SPR_IMG_LANDSCAPING, STR_LANDSCAPING_TOOLBAR_TIP}, dominik@606: darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _build_maglev_desc = { dominik@606: 640-372, 22, 372, 36, truelight@0: WC_BUILD_TOOLBAR,0, darkvater@756: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON, truelight@0: _build_maglev_widgets, truelight@0: BuildRailToolbWndProc truelight@0: }; truelight@0: truelight@0: truelight@0: static const WindowDesc * const _build_rr_desc[] = { truelight@0: &_build_railroad_desc, truelight@0: &_build_monorail_desc, truelight@0: &_build_maglev_desc, truelight@0: }; truelight@0: truelight@0: void ShowBuildRailToolbar(int index, int button) truelight@0: { truelight@0: Window *w; truelight@0: dominik@946: if (_current_player == OWNER_SPECTATOR) return; dominik@946: truelight@0: // don't recreate the window if we're clicking on a button and the window exists. truelight@0: if (button < 0 || !(w = FindWindowById(WC_BUILD_TOOLBAR, 0)) || w->wndproc != BuildRailToolbWndProc) { truelight@201: DeleteWindowById(WC_BUILD_TOOLBAR, 0); truelight@0: _cur_railtype = (byte)index; truelight@0: w = AllocateWindowDesc(_build_rr_desc[index]); truelight@0: } truelight@0: darkvater@288: _remove_button_clicked = false; truelight@0: if (w != NULL && button >= 0) _build_railroad_button_proc[button](w); truelight@0: } truelight@0: tron@449: /* TODO: For custom stations, respect their allowed platforms/lengths bitmasks! tron@449: * --pasky */ tron@449: truelight@0: static void HandleStationPlacement(uint start, uint end) truelight@0: { tron@926: uint sx = TileX(start); tron@926: uint sy = TileY(start); tron@926: uint ex = TileX(end); tron@926: uint ey = TileY(end); truelight@0: uint w,h; truelight@0: truelight@0: if (sx > ex) intswap(sx,ex); truelight@0: if (sy > ey) intswap(sy,ey); truelight@0: w = ex - sx + 1; truelight@0: h = ey - sy + 1; truelight@0: if (!_railstation.orientation) intswap(w,h); truelight@0: tron@449: // TODO: Custom station selector GUI. Now we just try using first custom station tron@449: // (and fall back to normal stations if it isn't available). tron@449: DoCommandP(TILE_XY(sx,sy), _railstation.orientation | (w<<8) | (h<<16),_cur_railtype|1<<4, CcStation, truelight@0: CMD_BUILD_RAILROAD_STATION | CMD_NO_WATER | CMD_AUTO | CMD_MSG(STR_100F_CAN_T_BUILD_RAILROAD_STATION)); truelight@0: } truelight@0: truelight@0: static void StationBuildWndProc(Window *w, WindowEvent *e) { Celestar@568: int rad; truelight@0: switch(e->event) { truelight@0: case WE_PAINT: { truelight@0: uint bits; truelight@0: truelight@0: if (WP(w,def_d).close) truelight@0: return; truelight@0: truelight@0: bits = (1<<3) << ( _railstation.orientation); truelight@0: if (_railstation.dragdrop) { truelight@0: bits |= (1<<19); truelight@0: } else { truelight@0: bits |= (1<<(5-1)) << (_railstation.numtracks); truelight@0: bits |= (1<<(12-1)) << (_railstation.platlength); truelight@0: } truelight@0: bits |= (1<<20) << (_station_show_coverage); truelight@0: w->click_state = bits; truelight@201: truelight@0: if (_railstation.dragdrop) { truelight@0: SetTileSelectSize(1, 1); truelight@0: } else { truelight@0: int x = _railstation.numtracks; truelight@0: int y = _railstation.platlength; truelight@0: if (_railstation.orientation == 0) intswap(x,y); truelight@0: if(!_remove_button_clicked) truelight@0: SetTileSelectSize(x, y); truelight@0: } truelight@201: darkvater@980: rad = (_patches.modified_catchment) ? CA_TRAIN : 4; Celestar@568: truelight@0: if (_station_show_coverage) Celestar@568: SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad); truelight@0: truelight@0: DrawWindowWidgets(w); truelight@201: truelight@0: StationPickerDrawSprite(39, 42, _cur_railtype, 2); truelight@0: StationPickerDrawSprite(107, 42, _cur_railtype, 3); truelight@0: truelight@0: DrawStringCentered(74, 15, STR_3002_ORIENTATION, 0); truelight@0: DrawStringCentered(74, 76, STR_3003_NUMBER_OF_TRACKS, 0); truelight@0: DrawStringCentered(74, 101, STR_3004_PLATFORM_LENGTH, 0); truelight@0: DrawStringCentered(74, 141, STR_3066_COVERAGE_AREA_HIGHLIGHT, 0); truelight@0: Celestar@568: DrawStationCoverageAreaText(2, 166, (uint)-1, rad); truelight@0: } break; truelight@201: truelight@0: case WE_CLICK: { truelight@0: switch(e->click.widget) { truelight@0: case 3: truelight@0: case 4: truelight@0: _railstation.orientation = e->click.widget - 3; tron@541: SndPlayFx(SND_15_BEEP); truelight@0: SetWindowDirty(w); truelight@0: break; truelight@0: truelight@0: case 5: truelight@0: case 6: truelight@0: case 7: truelight@0: case 8: truelight@0: case 9: truelight@0: case 10: truelight@0: case 11: truelight@0: _railstation.numtracks = (e->click.widget - 5) + 1; truelight@0: _railstation.dragdrop = false; tron@541: SndPlayFx(SND_15_BEEP); truelight@0: SetWindowDirty(w); truelight@0: break; truelight@0: truelight@0: case 12: truelight@0: case 13: truelight@0: case 14: truelight@0: case 15: truelight@0: case 16: truelight@0: case 17: truelight@0: case 18: truelight@0: _railstation.platlength = (e->click.widget - 12) + 1; truelight@0: _railstation.dragdrop = false; tron@541: SndPlayFx(SND_15_BEEP); truelight@0: SetWindowDirty(w); truelight@0: break; truelight@0: truelight@0: case 19: truelight@0: _railstation.dragdrop ^= true; tron@541: SndPlayFx(SND_15_BEEP); truelight@0: SetWindowDirty(w); truelight@0: break; truelight@0: truelight@0: case 20: truelight@0: case 21: truelight@0: _station_show_coverage = e->click.widget - 20; tron@541: SndPlayFx(SND_15_BEEP); truelight@0: SetWindowDirty(w); truelight@0: break; truelight@0: } truelight@0: } break; truelight@201: truelight@0: case WE_MOUSELOOP: { truelight@0: if (WP(w,def_d).close) { truelight@0: DeleteWindow(w); truelight@0: return; truelight@0: } truelight@0: CheckRedrawStationCoverage(w); truelight@0: } break; Celestar@1074: celestar@1072: case WE_DESTROY: darkvater@1116: if (!WP(w,def_d).close) darkvater@1116: ResetObjectToPlace(); celestar@1072: break; truelight@0: } truelight@0: } truelight@0: truelight@0: static const Widget _station_builder_widgets[] = { truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@867: { WWT_CAPTION, RESIZE_NONE, 7, 11, 147, 0, 13, STR_3000_RAIL_STATION_SELECTION, STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 0, 147, 14, 199, 0x0, STR_NULL}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 7, 72, 26, 73, 0x0, STR_304E_SELECT_RAILROAD_STATION}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 75, 140, 26, 73, 0x0, STR_304E_SELECT_RAILROAD_STATION}, truelight@0: truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 14, 22, 36, 87, 98, STR_00CB_1, STR_304F_SELECT_NUMBER_OF_PLATFORMS}, truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 14, 37, 51, 87, 98, STR_00CC_2, STR_304F_SELECT_NUMBER_OF_PLATFORMS}, truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 14, 52, 66, 87, 98, STR_00CD_3, STR_304F_SELECT_NUMBER_OF_PLATFORMS}, truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 14, 67, 81, 87, 98, STR_00CE_4, STR_304F_SELECT_NUMBER_OF_PLATFORMS}, truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 14, 82, 96, 87, 98, STR_00CF_5, STR_304F_SELECT_NUMBER_OF_PLATFORMS}, truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 14, 97, 111, 87, 98, STR_0335_6, STR_304F_SELECT_NUMBER_OF_PLATFORMS}, truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 14, 112, 126, 87, 98, STR_0336_7, STR_304F_SELECT_NUMBER_OF_PLATFORMS}, truelight@0: truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 14, 22, 36, 112, 123, STR_00CB_1, STR_3050_SELECT_LENGTH_OF_RAILROAD}, truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 14, 37, 51, 112, 123, STR_00CC_2, STR_3050_SELECT_LENGTH_OF_RAILROAD}, truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 14, 52, 66, 112, 123, STR_00CD_3, STR_3050_SELECT_LENGTH_OF_RAILROAD}, truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 14, 67, 81, 112, 123, STR_00CE_4, STR_3050_SELECT_LENGTH_OF_RAILROAD}, truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 14, 82, 96, 112, 123, STR_00CF_5, STR_3050_SELECT_LENGTH_OF_RAILROAD}, truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 14, 97, 111, 112, 123, STR_0335_6, STR_3050_SELECT_LENGTH_OF_RAILROAD}, truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 14, 112, 126, 112, 123, STR_0336_7, STR_3050_SELECT_LENGTH_OF_RAILROAD}, truelight@0: truelight@867: //{ WWT_CLOSEBOX, RESIZE_NONE, 14, 14, 73, 137, 148, STR_02DB_OFF, STR_3065_DON_T_HIGHLIGHT_COVERAGE}, truelight@867: //{ WWT_CLOSEBOX, RESIZE_NONE, 14, 74, 133, 137, 148, STR_02DA_ON, STR_3064_HIGHLIGHT_COVERAGE_AREA}, truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 14, 37, 111, 126, 137, STR_DRAG_DROP, STR_STATION_DRAG_DROP}, truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 14, 14, 73, 152, 163, STR_02DB_OFF, STR_3065_DON_T_HIGHLIGHT_COVERAGE}, truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 14, 74, 133, 152, 163, STR_02DA_ON, STR_3064_HIGHLIGHT_COVERAGE_AREA}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _station_builder_desc = { truelight@0: -1, -1, 148, 200, truelight@0: WC_BUILD_STATION,WC_BUILD_TOOLBAR, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _station_builder_widgets, truelight@0: StationBuildWndProc truelight@0: }; truelight@0: tron@1093: static void ShowStationBuilder(void) truelight@0: { truelight@0: AllocateWindowDesc(&_station_builder_desc); truelight@0: } truelight@0: truelight@0: static void BuildTrainDepotWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: switch(e->event) { truelight@0: case WE_PAINT: { truelight@0: int r; truelight@0: truelight@0: w->click_state = (1 << 3) << _build_depot_direction; truelight@0: DrawWindowWidgets(w); truelight@0: truelight@0: r = _cur_railtype; truelight@0: DrawTrainDepotSprite(70, 17, 0, r); truelight@0: DrawTrainDepotSprite(70, 69, 1, r); truelight@0: DrawTrainDepotSprite(2, 69, 2, r); truelight@0: DrawTrainDepotSprite(2, 17, 3, r); truelight@0: break; truelight@0: } truelight@0: case WE_CLICK: { truelight@0: switch(e->click.widget) { darkvater@1116: case 3: case 4: case 5: case 6: truelight@0: _build_depot_direction = e->click.widget - 3; tron@541: SndPlayFx(SND_15_BEEP); truelight@0: SetWindowDirty(w); truelight@0: break; truelight@0: } truelight@0: } break; truelight@201: truelight@0: case WE_MOUSELOOP: truelight@0: if (WP(w,def_d).close) truelight@0: DeleteWindow(w); truelight@0: return; celestar@1072: celestar@1072: case WE_DESTROY: darkvater@1116: if (!WP(w,def_d).close) darkvater@1116: ResetObjectToPlace(); celestar@1072: break; truelight@0: } truelight@0: } truelight@0: truelight@0: static const Widget _build_depot_widgets[] = { truelight@867: { 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_1014_TRAIN_DEPOT_ORIENTATION, STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 0, 139, 14, 121, 0x0, STR_NULL}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 71, 136, 17, 66, 0x0, STR_1020_SELECT_RAILROAD_DEPOT_ORIENTATIO}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 71, 136, 69, 118, 0x0, STR_1020_SELECT_RAILROAD_DEPOT_ORIENTATIO}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 3, 68, 69, 118, 0x0, STR_1020_SELECT_RAILROAD_DEPOT_ORIENTATIO}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 3, 68, 17, 66, 0x0, STR_1020_SELECT_RAILROAD_DEPOT_ORIENTATIO}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _build_depot_desc = { truelight@0: -1,-1, 140, 122, truelight@0: WC_BUILD_DEPOT,WC_BUILD_TOOLBAR, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _build_depot_widgets, truelight@0: BuildTrainDepotWndProc truelight@0: }; truelight@0: tron@1093: static void ShowBuildTrainDepotPicker(void) truelight@0: { truelight@0: AllocateWindowDesc(&_build_depot_desc); truelight@0: } truelight@0: darkvater@393: darkvater@395: static void BuildWaypointWndProc(Window *w, WindowEvent *e) darkvater@393: { darkvater@393: switch(e->event) { darkvater@393: case WE_PAINT: { darkvater@393: int r; darkvater@393: darkvater@395: w->click_state = (1 << 3) << _cur_waypoint_type; darkvater@393: DrawWindowWidgets(w); darkvater@393: darkvater@393: r = 4*w->hscroll.pos; dominik@415: if(r+0<=_waypoint_count) DrawWaypointSprite(2, 25, r + 0, _cur_railtype); dominik@415: if(r+1<=_waypoint_count) DrawWaypointSprite(70, 25, r + 1, _cur_railtype); dominik@415: if(r+2<=_waypoint_count) DrawWaypointSprite(138, 25, r + 2, _cur_railtype); dominik@415: if(r+3<=_waypoint_count) DrawWaypointSprite(206, 25, r + 3, _cur_railtype); dominik@415: if(r+4<=_waypoint_count) DrawWaypointSprite(274, 25, r + 4, _cur_railtype); darkvater@393: break; darkvater@393: } darkvater@393: case WE_CLICK: { darkvater@393: switch(e->click.widget) { darkvater@393: case 0: darkvater@393: ResetObjectToPlace(); darkvater@393: break; darkvater@393: case 3: darkvater@393: case 4: darkvater@393: case 5: darkvater@393: case 6: dominik@411: case 7: darkvater@395: _cur_waypoint_type = e->click.widget - 3; tron@541: SndPlayFx(SND_15_BEEP); darkvater@393: SetWindowDirty(w); darkvater@393: break; darkvater@393: } darkvater@393: break; darkvater@393: } truelight@867: darkvater@393: case WE_MOUSELOOP: darkvater@393: if (WP(w,def_d).close) darkvater@393: DeleteWindow(w); darkvater@393: return; Celestar@1074: Celestar@1074: case WE_DESTROY: Celestar@1074: ResetObjectToPlace(); Celestar@1074: break; darkvater@393: } darkvater@393: } darkvater@393: darkvater@395: static const Widget _build_waypoint_widgets[] = { truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@867: { WWT_CAPTION, RESIZE_NONE, 7, 11, 343, 0, 13, STR_WAYPOINT,STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 0, 343, 14, 91, 0x0, 0}, darkvater@393: truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 3, 68, 17, 76, 0x0, STR_WAYPOINT_GRAPHICS_TIP}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 71, 136, 17, 76, 0x0, STR_WAYPOINT_GRAPHICS_TIP}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 139, 204, 17, 76, 0x0, STR_WAYPOINT_GRAPHICS_TIP}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 207, 272, 17, 76, 0x0, STR_WAYPOINT_GRAPHICS_TIP}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 275, 340, 17, 76, 0x0, STR_WAYPOINT_GRAPHICS_TIP}, darkvater@393: darkvater@894: { WWT_HSCROLLBAR, RESIZE_NONE, 7, 1, 343, 80, 91, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, dominik@417: { WIDGETS_END}, darkvater@393: }; darkvater@393: darkvater@395: static const WindowDesc _build_waypoint_desc = { dominik@411: -1,-1, 344, 92, darkvater@393: WC_BUILD_DEPOT,WC_BUILD_TOOLBAR, darkvater@393: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, darkvater@395: _build_waypoint_widgets, darkvater@395: BuildWaypointWndProc darkvater@393: }; darkvater@393: tron@1093: static void ShowBuildWaypointPicker(void) darkvater@393: { darkvater@395: Window *w = AllocateWindowDesc(&_build_waypoint_desc); dominik@411: w->hscroll.cap = 5; dominik@411: w->hscroll.count = (uint) (_waypoint_count+4) / 5; darkvater@393: } darkvater@393: darkvater@393: tron@1093: void InitializeRailGui(void) truelight@0: { truelight@201: _build_depot_direction = 3; truelight@0: _railstation.numtracks = 1; truelight@0: _railstation.platlength = 1; truelight@0: _railstation.dragdrop = true; truelight@0: }