truelight@0: #include "stdafx.h" truelight@0: #include "ttd.h" tron@507: #include "table/strings.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: truelight@0: static void ShowBuildDockStationPicker(); truelight@0: static void ShowBuildDocksDepotPicker(); 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: truelight@0: static void BuildDocksClick_Dock(Window *w) truelight@0: { truelight@0: truelight@0: if (HandlePlacePushButton(w, 2, 0xE54, 3, PlaceDocks_Dock)) ShowBuildDockStationPicker(); truelight@0: } truelight@0: truelight@0: static void BuildDocksClick_Depot(Window *w) truelight@0: { truelight@0: if (HandlePlacePushButton(w, 3, 0x2D1, 1, PlaceDocks_Depot)) ShowBuildDocksDepotPicker(); truelight@0: } truelight@0: truelight@0: static void BuildDocksClick_Buoy(Window *w) truelight@0: { truelight@0: HandlePlacePushButton(w, 4, 0x2BE, 1, PlaceDocks_Buoy); truelight@0: } truelight@0: truelight@0: static void BuildDocksClick_Demolish(Window *w) truelight@0: { truelight@0: HandlePlacePushButton(w, 5, ANIMCURSOR_DEMOLISH, 1, PlaceDocks_DemolishArea); truelight@0: } truelight@0: truelight@0: static void BuildDocksClick_Lower(Window *w) truelight@0: { truelight@0: HandlePlacePushButton(w, 6, ANIMCURSOR_LOWERLAND, 2, PlaceProc_LowerLand); truelight@0: } truelight@0: truelight@0: static void BuildDocksClick_Raise(Window *w) truelight@0: { truelight@0: HandlePlacePushButton(w, 7, ANIMCURSOR_RAISELAND, 2, PlaceProc_RaiseLand); truelight@0: } truelight@0: truelight@0: static void BuildDocksClick_Purchase(Window *w) truelight@0: { truelight@0: HandlePlacePushButton(w, 8, 0x12B8, 1, PlaceProc_BuyLand); truelight@0: } truelight@0: truelight@0: static void BuildDocksClick_Canal(Window *w) truelight@0: { truelight@0: HandlePlacePushButton(w, 9, SPR_OPENTTD_BASE + 11, 1, PlaceDocks_BuildCanal); truelight@0: } truelight@0: truelight@0: static void BuildDocksClick_Lock(Window *w) truelight@0: { truelight@0: HandlePlacePushButton(w, 10, SPR_OPENTTD_BASE + 64, 1, PlaceDocks_BuildLock); truelight@0: } truelight@0: truelight@0: typedef void OnButtonClick(Window *w); truelight@0: static OnButtonClick * const _build_docks_button_proc[] = { truelight@0: BuildDocksClick_Dock, truelight@0: BuildDocksClick_Depot, truelight@0: BuildDocksClick_Buoy, truelight@0: BuildDocksClick_Demolish, truelight@0: BuildDocksClick_Lower, truelight@0: BuildDocksClick_Raise, truelight@0: BuildDocksClick_Purchase, truelight@0: BuildDocksClick_Canal, truelight@0: BuildDocksClick_Lock, 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: { truelight@0: if (e->click.widget - 2 >= 0) _build_docks_button_proc[e->click.widget - 2](w); truelight@0: } 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: truelight@0: w->click_state = 0; 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@0: { WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@0: { WWT_CAPTION, 7, 11, 197, 0, 13, STR_9801_DOCK_CONSTRUCTION, STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@0: { WWT_PANEL, 7, 0, 21, 14, 35, 746, STR_981D_BUILD_SHIP_DOCK}, truelight@0: { WWT_PANEL, 7, 22, 43, 14, 35, 748, STR_981E_BUILD_SHIP_DEPOT_FOR_BUILDING}, truelight@0: { WWT_PANEL, 7, 44, 65, 14, 35, 693, STR_9834_POSITION_BUOY_WHICH_CAN}, truelight@0: { WWT_PANEL, 7, 66, 87, 14, 35, 703, STR_018D_DEMOLISH_BUILDINGS_ETC}, truelight@0: { WWT_PANEL, 7, 88, 109, 14, 35, 695, STR_018E_LOWER_A_CORNER_OF_LAND}, truelight@0: { WWT_PANEL, 7, 110, 131, 14, 35, 694, STR_018F_RAISE_A_CORNER_OF_LAND}, truelight@0: { WWT_PANEL, 7, 132, 153, 14, 35, 4791, STR_0329_PURCHASE_LAND_FOR_FUTURE}, truelight@0: { WWT_PANEL, 7, 154, 175, 14, 35, SPR_OPENTTD_BASE+65, STR_BUILD_CANALS_TIP}, truelight@0: { WWT_PANEL, 7, 176, 197, 14, 35, SPR_CANALS_BASE+69, STR_BUILD_LOCKS_TIP}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _build_docks_toolbar_desc = { truelight@0: 640-197, 22, 198, 36, truelight@0: WC_BUILD_TOOLBAR,0, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _build_docks_toolb_widgets, truelight@0: BuildDocksToolbWndProc truelight@0: }; truelight@0: truelight@0: void ShowBuildDocksToolbar() truelight@0: { 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: { truelight@0: switch(e->event) { truelight@0: case WE_PAINT: { truelight@0: if (WP(w,def_d).close) truelight@0: return; truelight@0: DrawWindowWidgets(w); truelight@0: DrawStationCoverageAreaText(2, 15, (uint)-1); truelight@0: } break; truelight@0: truelight@0: case WE_CLICK: { truelight@0: if (e->click.widget == 0) { truelight@0: ResetObjectToPlace(); 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: } truelight@193: } truelight@0: } truelight@0: truelight@0: static const Widget _build_dock_station_widgets[] = { truelight@0: { WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@0: { WWT_CAPTION, 7, 11, 147, 0, 13, STR_3068_DOCK, STR_018C_WINDOW_TITLE_DRAG_THIS}, darkvater@176: { WWT_PANEL, 7, 0, 147, 14, 45, 0x0, STR_NULL}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _build_dock_station_desc = { truelight@0: -1, -1, 148, 46, 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: truelight@0: static void ShowBuildDockStationPicker() truelight@0: { truelight@0: AllocateWindowDesc(&_build_dock_station_desc); truelight@0: } truelight@0: truelight@0: static void UpdateDocksDirection() 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 0: truelight@0: ResetObjectToPlace(); truelight@0: break; 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; truelight@0: } truelight@0: } truelight@0: truelight@0: static const Widget _build_docks_depot_widgets[] = { truelight@0: { WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@0: { WWT_CAPTION, 7, 11, 203, 0, 13, STR_3800_SHIP_DEPOT_ORIENTATION, STR_018C_WINDOW_TITLE_DRAG_THIS}, darkvater@176: { WWT_PANEL, 7, 0, 203, 14, 85, 0x0, STR_NULL}, truelight@0: { WWT_PANEL, 14, 3, 100, 17, 82, 0x0, STR_3803_SELECT_SHIP_DEPOT_ORIENTATION}, truelight@0: { WWT_PANEL, 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: truelight@0: static void ShowBuildDocksDepotPicker() truelight@0: { truelight@0: AllocateWindowDesc(&_build_docks_depot_desc); truelight@0: UpdateDocksDirection(); truelight@0: } truelight@0: truelight@0: truelight@0: void InitializeDockGui() truelight@0: { truelight@0: _ship_depot_direction = 0; truelight@0: }