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" truelight@0: #include "window.h" Celestar@568: #include "station.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: tron@1093: static void ShowBuildDockStationPicker(void); tron@1093: static void ShowBuildDocksDepotPicker(void); truelight@0: truelight@0: static byte _ship_depot_direction; truelight@0: truelight@543: void CcBuildDocks(bool success, uint tile, uint32 p1, uint32 p2) truelight@0: { truelight@0: if (success) { tron@541: SndPlayTileFx(SND_02_SPLAT, tile); truelight@0: ResetObjectToPlace(); truelight@0: } truelight@0: } truelight@0: truelight@543: void CcBuildCanal(bool success, uint tile, uint32 p1, uint32 p2) truelight@0: { tron@541: if (success) SndPlayTileFx(SND_02_SPLAT, tile); truelight@0: } truelight@0: truelight@0: truelight@0: static void PlaceDocks_Dock(uint tile) truelight@0: { truelight@0: DoCommandP(tile, 0, 0, CcBuildDocks, CMD_BUILD_DOCK | CMD_AUTO | CMD_MSG(STR_9802_CAN_T_BUILD_DOCK_HERE)); truelight@0: } truelight@0: truelight@0: static void PlaceDocks_Depot(uint tile) truelight@0: { truelight@0: DoCommandP(tile, _ship_depot_direction, 0, CcBuildDocks, CMD_BUILD_SHIP_DEPOT | CMD_AUTO | CMD_MSG(STR_3802_CAN_T_BUILD_SHIP_DEPOT)); truelight@0: } truelight@0: truelight@0: static void PlaceDocks_Buoy(uint tile) truelight@0: { truelight@0: DoCommandP(tile, 0, 0, CcBuildDocks, CMD_BUILD_BUOY | CMD_AUTO | CMD_MSG(STR_9835_CAN_T_POSITION_BUOY_HERE)); truelight@0: } truelight@0: truelight@0: static void PlaceDocks_DemolishArea(uint tile) truelight@0: { truelight@0: VpStartPlaceSizing(tile, VPM_X_AND_Y); truelight@0: } truelight@0: truelight@0: static void PlaceDocks_BuildCanal(uint tile) truelight@0: { truelight@0: VpStartPlaceSizing(tile, VPM_X_OR_Y); truelight@0: } truelight@0: truelight@0: static void PlaceDocks_BuildLock(uint tile) truelight@0: { truelight@0: DoCommandP(tile, 0, 0, CcBuildDocks, CMD_BUILD_LOCK | CMD_AUTO | CMD_MSG(STR_CANT_BUILD_LOCKS)); truelight@0: } truelight@0: truelight@0: dominik@606: static void BuildDocksClick_Canal(Window *w) truelight@0: { darkvater@756: HandlePlacePushButton(w, 3, SPR_OPENTTD_BASE + 11, 1, PlaceDocks_BuildCanal); truelight@0: } truelight@0: dominik@606: static void BuildDocksClick_Lock(Window *w) truelight@0: { darkvater@756: HandlePlacePushButton(w, 4, SPR_OPENTTD_BASE + 64, 1, PlaceDocks_BuildLock); truelight@0: } truelight@0: truelight@0: static void BuildDocksClick_Demolish(Window *w) truelight@0: { darkvater@756: HandlePlacePushButton(w, 6, ANIMCURSOR_DEMOLISH, 1, PlaceDocks_DemolishArea); truelight@0: } truelight@0: dominik@606: static void BuildDocksClick_Depot(Window *w) truelight@0: { darkvater@756: if (HandlePlacePushButton(w, 7, 0x2D1, 1, PlaceDocks_Depot)) ShowBuildDocksDepotPicker(); truelight@0: } truelight@0: dominik@606: static void BuildDocksClick_Dock(Window *w) truelight@0: { dominik@606: darkvater@756: if (HandlePlacePushButton(w, 8, 0xE54, 3, PlaceDocks_Dock)) ShowBuildDockStationPicker(); truelight@0: } truelight@0: dominik@606: static void BuildDocksClick_Buoy(Window *w) truelight@0: { darkvater@756: HandlePlacePushButton(w, 9, 0x2BE, 1, PlaceDocks_Buoy); truelight@0: } truelight@0: dominik@606: static void BuildDocksClick_Landscaping(Window *w) truelight@0: { dominik@606: ShowTerraformToolbar(); truelight@0: } truelight@0: truelight@0: typedef void OnButtonClick(Window *w); truelight@0: static OnButtonClick * const _build_docks_button_proc[] = { truelight@0: BuildDocksClick_Canal, truelight@0: BuildDocksClick_Lock, dominik@606: 0, dominik@606: BuildDocksClick_Demolish, dominik@606: BuildDocksClick_Depot, dominik@606: BuildDocksClick_Dock, dominik@606: BuildDocksClick_Buoy, dominik@606: BuildDocksClick_Landscaping, truelight@0: }; truelight@0: truelight@0: static void BuildDocksToolbWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: switch(e->event) { truelight@0: case WE_PAINT: truelight@0: DrawWindowWidgets(w); truelight@0: break; truelight@0: truelight@0: case WE_CLICK: { darkvater@756: if (e->click.widget - 3 >= 0 && e->click.widget != 5) _build_docks_button_proc[e->click.widget - 3](w); truelight@0: } break; tron@1019: celestar@937: case WE_KEYPRESS: { celestar@937: switch(e->keypress.keycode) { celestar@937: case '1': BuildDocksClick_Canal(w); break; celestar@937: case '2': BuildDocksClick_Lock(w); break; celestar@937: case '3': BuildDocksClick_Demolish(w); break; celestar@937: case '4': BuildDocksClick_Depot(w); break; celestar@937: case '5': BuildDocksClick_Dock(w); break; celestar@937: case '6': BuildDocksClick_Buoy(w); break; celestar@937: case 'l': BuildDocksClick_Landscaping(w); break; tron@1019: default: celestar@937: return; celestar@937: } celestar@937: } break; truelight@0: truelight@0: case WE_PLACE_OBJ: truelight@0: _place_proc(e->place.tile); truelight@193: break; truelight@0: truelight@0: case WE_PLACE_DRAG: { truelight@0: VpSelectTilesWithMethod(e->place.pt.x, e->place.pt.y, e->place.userdata); truelight@0: return; truelight@0: } truelight@0: truelight@0: case WE_PLACE_MOUSEUP: truelight@0: if (e->click.pt.x != -1) { truelight@0: if (e->place.userdata == VPM_X_AND_Y) truelight@0: DoCommandP(e->place.tile, e->place.starttile, 0, CcPlaySound10, CMD_CLEAR_AREA | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA)); truelight@0: else if(e->place.userdata == VPM_X_OR_Y) truelight@0: DoCommandP(e->place.tile, e->place.starttile, 0, CcBuildCanal, CMD_BUILD_CANAL | CMD_AUTO | CMD_MSG(STR_CANT_BUILD_CANALS)); 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: truelight@0: w = FindWindowById(WC_BUILD_DEPOT, 0); truelight@0: if (w != NULL) WP(w,def_d).close=true; truelight@0: break; truelight@193: truelight@0: case WE_PLACE_PRESIZE: { truelight@0: uint tile_from, tile_to; truelight@0: truelight@0: tile_from = tile_to = e->place.tile; truelight@0: switch(GetTileSlope(tile_from, NULL)) { truelight@0: case 3: tile_to += TILE_XY(-1,0); break; truelight@0: case 6: tile_to += TILE_XY(0,-1); break; truelight@0: case 9: tile_to += TILE_XY(0,1); break; truelight@0: case 12:tile_to += TILE_XY(1,0); break; truelight@0: } truelight@0: VpSetPresizeRange(tile_from, tile_to); truelight@0: } break; truelight@0: } truelight@0: } truelight@0: truelight@0: static const Widget _build_docks_toolb_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, 145, 0, 13, STR_9801_DOCK_CONSTRUCTION, STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@867: { WWT_STICKYBOX, RESIZE_NONE, 7, 146, 157, 0, 13, 0x0, STR_STICKY_BUTTON}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 0, 21, 14, 35, SPR_OPENTTD_BASE+65, STR_BUILD_CANALS_TIP}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 22, 43, 14, 35, SPR_CANALS_BASE+69, STR_BUILD_LOCKS_TIP}, dominik@606: truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 44, 47, 14, 35, 0x0, STR_NULL}, dominik@606: truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 48, 69, 14, 35, 703, STR_018D_DEMOLISH_BUILDINGS_ETC}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 70, 91, 14, 35, 748, STR_981E_BUILD_SHIP_DEPOT_FOR_BUILDING}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 92, 113, 14, 35, 746, STR_981D_BUILD_SHIP_DOCK}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 114, 135, 14, 35, 693, STR_9834_POSITION_BUOY_WHICH_CAN}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 136, 157, 14, 35, SPR_IMG_LANDSCAPING, STR_LANDSCAPING_TOOLBAR_TIP}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _build_docks_toolbar_desc = { dominik@606: 640-158, 22, 158, 36, truelight@0: WC_BUILD_TOOLBAR,0, darkvater@756: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON, truelight@0: _build_docks_toolb_widgets, truelight@0: BuildDocksToolbWndProc truelight@0: }; truelight@0: tron@1093: void ShowBuildDocksToolbar(void) truelight@0: { dominik@946: if (_current_player == OWNER_SPECTATOR) return; truelight@0: DeleteWindowById(WC_BUILD_TOOLBAR, 0); truelight@0: AllocateWindowDesc(&_build_docks_toolbar_desc); truelight@0: } truelight@0: truelight@0: static void BuildDockStationWndProc(Window *w, WindowEvent *e) truelight@0: { Celestar@568: int rad; dominik@713: truelight@0: switch(e->event) { truelight@0: case WE_PAINT: { truelight@0: if (WP(w,def_d).close) truelight@0: return; dominik@713: w->click_state = (1<<3) << _station_show_coverage; truelight@0: DrawWindowWidgets(w); Celestar@568: if (_patches.modified_catchment) { Celestar@568: rad = CA_DOCK; Celestar@568: } else { Celestar@568: rad = 4; Celestar@568: } dominik@713: dominik@713: if (_station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad); dominik@713: else SetTileSelectBigSize(0, 0, 0, 0); dominik@713: dominik@750: DrawStringCentered(74, 17, STR_3066_COVERAGE_AREA_HIGHLIGHT, 0); dominik@750: DrawStationCoverageAreaText(4, 50, (uint)-1, rad); truelight@0: } break; truelight@0: truelight@0: case WE_CLICK: { dominik@713: switch(e->click.widget) { dominik@713: case 3: case 4: dominik@713: _station_show_coverage = e->click.widget - 3; dominik@713: SndPlayFx(SND_15_BEEP); dominik@713: SetWindowDirty(w); dominik@713: break; truelight@0: } truelight@0: } break; truelight@0: truelight@0: case WE_MOUSELOOP: { truelight@0: if (WP(w,def_d).close) { truelight@0: DeleteWindow(w); truelight@0: return; truelight@0: } truelight@0: truelight@0: CheckRedrawStationCoverage(w); truelight@0: break; truelight@0: } celestar@1072: celestar@1072: case WE_DESTROY: darkvater@1116: if (!WP(w,def_d).close) darkvater@1116: ResetObjectToPlace(); celestar@1072: break; truelight@193: } truelight@0: } truelight@0: truelight@0: static const Widget _build_dock_station_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_3068_DOCK, STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 0, 147, 14, 74, 0x0, STR_NULL}, truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 14, 14, 73, 30, 40, STR_02DB_OFF, STR_3065_DON_T_HIGHLIGHT_COVERAGE}, truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 14, 74, 133, 30, 40, STR_02DA_ON, STR_3064_HIGHLIGHT_COVERAGE_AREA}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _build_dock_station_desc = { dominik@750: -1, -1, 148, 75, truelight@0: WC_BUILD_STATION,WC_BUILD_TOOLBAR, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _build_dock_station_widgets, truelight@0: BuildDockStationWndProc truelight@0: }; truelight@0: tron@1093: static void ShowBuildDockStationPicker(void) truelight@0: { truelight@0: AllocateWindowDesc(&_build_dock_station_desc); truelight@0: } truelight@0: tron@1093: static void UpdateDocksDirection(void) truelight@0: { truelight@0: if (_ship_depot_direction != 0) { truelight@0: SetTileSelectSize(1, 2); truelight@0: } else { truelight@0: SetTileSelectSize(2, 1); truelight@0: } truelight@0: } truelight@0: truelight@0: static void BuildDocksDepotWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: switch(e->event) { truelight@0: case WE_PAINT: truelight@0: w->click_state = (1<<3) << _ship_depot_direction; truelight@0: DrawWindowWidgets(w); truelight@0: truelight@0: DrawShipDepotSprite(67, 35, 0); truelight@0: DrawShipDepotSprite(35, 51, 1); truelight@0: DrawShipDepotSprite(135, 35, 2); truelight@0: DrawShipDepotSprite(167, 51, 3); truelight@0: return; truelight@0: truelight@0: case WE_CLICK: { truelight@0: switch(e->click.widget) { truelight@0: case 3: truelight@0: case 4: truelight@0: _ship_depot_direction = e->click.widget - 3; tron@541: SndPlayFx(SND_15_BEEP); truelight@0: UpdateDocksDirection(); truelight@0: SetWindowDirty(w); truelight@0: break; truelight@0: } truelight@0: } break; truelight@0: truelight@0: case WE_MOUSELOOP: truelight@0: if (WP(w,def_d).close) truelight@0: DeleteWindow(w); truelight@0: break; 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_docks_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, 203, 0, 13, STR_3800_SHIP_DEPOT_ORIENTATION, STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 0, 203, 14, 85, 0x0, STR_NULL}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 3, 100, 17, 82, 0x0, STR_3803_SELECT_SHIP_DEPOT_ORIENTATION}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 103, 200, 17, 82, 0x0, STR_3803_SELECT_SHIP_DEPOT_ORIENTATION}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _build_docks_depot_desc = { truelight@0: -1, -1, 204, 86, truelight@0: WC_BUILD_DEPOT,WC_BUILD_TOOLBAR, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _build_docks_depot_widgets, truelight@0: BuildDocksDepotWndProc truelight@0: }; truelight@0: truelight@0: tron@1093: static void ShowBuildDocksDepotPicker(void) truelight@0: { truelight@0: AllocateWindowDesc(&_build_docks_depot_desc); truelight@0: UpdateDocksDirection(); truelight@0: } truelight@0: truelight@0: tron@1093: void InitializeDockGui(void) truelight@0: { truelight@0: _ship_depot_direction = 0; truelight@0: }