2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file dock_gui.cpp GUI to create amazing water objects. */
|
2007-02-23 18:55:07 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2008-01-06 18:56:43 +00:00
|
|
|
#include "terraform_gui.h"
|
2007-12-19 20:45:46 +00:00
|
|
|
#include "window_gui.h"
|
|
|
|
#include "station_gui.h"
|
2007-12-21 21:50:46 +00:00
|
|
|
#include "command_func.h"
|
2007-11-24 08:45:04 +00:00
|
|
|
#include "water.h"
|
2007-12-25 11:26:07 +00:00
|
|
|
#include "window_func.h"
|
2007-12-27 13:35:39 +00:00
|
|
|
#include "vehicle_func.h"
|
2007-12-29 09:24:26 +00:00
|
|
|
#include "sound_func.h"
|
2008-01-09 09:45:45 +00:00
|
|
|
#include "viewport_func.h"
|
|
|
|
#include "gfx_func.h"
|
2008-09-30 20:51:04 +00:00
|
|
|
#include "company_func.h"
|
2008-01-25 15:47:58 +00:00
|
|
|
#include "slope_func.h"
|
2008-05-07 13:10:15 +00:00
|
|
|
#include "tilehighlight_func.h"
|
2008-09-30 20:51:04 +00:00
|
|
|
#include "company_base.h"
|
2010-07-03 18:18:58 +00:00
|
|
|
#include "hotkeys.h"
|
2013-06-15 15:05:54 +00:00
|
|
|
#include "gui.h"
|
2014-09-22 08:01:25 +00:00
|
|
|
#include "zoom_func.h"
|
2023-02-10 17:18:39 +00:00
|
|
|
#include "core/backup_type.hpp"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2011-12-15 22:22:55 +00:00
|
|
|
#include "widgets/dock_widget.h"
|
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/sprites.h"
|
|
|
|
#include "table/strings.h"
|
|
|
|
|
2014-04-23 20:13:33 +00:00
|
|
|
#include "safeguards.h"
|
|
|
|
|
2008-05-24 11:19:30 +00:00
|
|
|
static void ShowBuildDockStationPicker(Window *parent);
|
|
|
|
static void ShowBuildDocksDepotPicker(Window *parent);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-08 06:55:33 +00:00
|
|
|
static Axis _ship_depot_direction;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2024-01-07 16:41:53 +00:00
|
|
|
void CcBuildDocks(const CommandCost &result, TileIndex tile, uint32_t p1, uint32_t p2, uint64_t p3, uint32_t cmd)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2010-01-11 18:46:09 +00:00
|
|
|
if (result.Failed()) return;
|
|
|
|
|
2021-02-20 18:01:04 +00:00
|
|
|
if (_settings_client.sound.confirm) SndPlayTileFx(SND_02_CONSTRUCTION_WATER, tile);
|
2010-01-11 18:46:09 +00:00
|
|
|
if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2024-01-07 16:41:53 +00:00
|
|
|
void CcPlaySound_CONSTRUCTION_WATER(const CommandCost &result, TileIndex tile, uint32_t p1, uint32_t p2, uint64_t p3, uint32_t cmd)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2021-02-20 18:01:04 +00:00
|
|
|
if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_02_CONSTRUCTION_WATER, tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-11 19:49:44 +00:00
|
|
|
/**
|
|
|
|
* Gets the other end of the aqueduct, if possible.
|
2018-10-28 02:17:36 +00:00
|
|
|
* @param tile_from The begin tile for the aqueduct.
|
|
|
|
* @param[out] tile_to The tile till where to show a selection for the aqueduct.
|
2010-12-11 19:49:44 +00:00
|
|
|
* @return The other end of the aqueduct, or otherwise a tile in line with the aqueduct to cause the right error message.
|
|
|
|
*/
|
2019-04-10 21:07:06 +00:00
|
|
|
static TileIndex GetOtherAqueductEnd(TileIndex tile_from, TileIndex *tile_to = nullptr)
|
2010-12-11 19:49:44 +00:00
|
|
|
{
|
2024-03-08 11:12:41 +00:00
|
|
|
auto [slope, z] = GetTileSlopeZ(tile_from);
|
|
|
|
DiagDirection dir = GetInclinedSlopeDirection(slope);
|
2010-12-11 19:49:44 +00:00
|
|
|
|
|
|
|
/* If the direction isn't right, just return the next tile so the command
|
|
|
|
* complains about the wrong slope instead of the ends not matching up.
|
|
|
|
* Make sure the coordinate is always a valid tile within the map, so we
|
|
|
|
* don't go "off" the map. That would cause the wrong error message. */
|
2024-03-10 13:51:08 +00:00
|
|
|
if (!IsValidDiagDirection(dir)) return TileAddXY(tile_from, TileX(tile_from) > 2 ? -1 : 1, 0);
|
2010-12-11 19:49:44 +00:00
|
|
|
|
|
|
|
/* Direction the aqueduct is built to. */
|
|
|
|
TileIndexDiff offset = TileOffsByDiagDir(ReverseDiagDir(dir));
|
|
|
|
/* The maximum length of the aqueduct. */
|
2021-01-08 10:16:18 +00:00
|
|
|
int max_length = std::min<int>(_settings_game.construction.max_bridge_length, DistanceFromEdgeDir(tile_from, ReverseDiagDir(dir)) - 1);
|
2010-12-11 19:49:44 +00:00
|
|
|
|
|
|
|
TileIndex endtile = tile_from;
|
|
|
|
for (int length = 0; IsValidTile(endtile) && TileX(endtile) != 0 && TileY(endtile) != 0; length++) {
|
2024-03-10 13:51:08 +00:00
|
|
|
endtile = TileAdd(endtile, offset);
|
2010-12-11 19:49:44 +00:00
|
|
|
|
|
|
|
if (length > max_length) break;
|
|
|
|
|
2011-11-04 10:31:46 +00:00
|
|
|
if (GetTileMaxZ(endtile) > z) {
|
2019-04-10 21:07:06 +00:00
|
|
|
if (tile_to != nullptr) *tile_to = endtile;
|
2010-12-11 19:49:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return endtile;
|
|
|
|
}
|
|
|
|
|
2013-01-08 22:46:42 +00:00
|
|
|
/** Toolbar window for constructing water infrastructure. */
|
2008-05-18 21:34:35 +00:00
|
|
|
struct BuildDocksToolbarWindow : Window {
|
2010-10-15 19:14:43 +00:00
|
|
|
DockToolbarWidgets last_clicked_widget; ///< Contains the last widget that has been clicked on this toolbar.
|
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
BuildDocksToolbarWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
|
2008-05-18 21:34:35 +00:00
|
|
|
{
|
2011-12-16 16:27:45 +00:00
|
|
|
this->last_clicked_widget = WID_DT_INVALID;
|
2022-04-15 17:32:56 +00:00
|
|
|
this->CreateNestedTree();
|
|
|
|
if (_game_mode != GM_EDITOR) {
|
|
|
|
this->GetWidget<NWidgetStacked>(WID_DT_RIVER_SEL)->SetDisplayedPlane(_settings_game.construction.enable_build_river ? 0 : SZSP_NONE);
|
|
|
|
}
|
|
|
|
this->FinishInitNested(window_number);
|
2010-09-28 21:58:06 +00:00
|
|
|
this->OnInvalidateData();
|
2008-05-29 15:13:28 +00:00
|
|
|
if (_settings_client.gui.link_terraform_toolbar) ShowTerraformToolbar(this);
|
2008-05-18 21:34:35 +00:00
|
|
|
}
|
|
|
|
|
2023-10-13 11:59:15 +00:00
|
|
|
void Close([[maybe_unused]] int data = 0) override
|
2008-05-18 21:34:35 +00:00
|
|
|
{
|
2019-07-12 19:43:58 +00:00
|
|
|
if (_game_mode == GM_NORMAL && this->IsWidgetLowered(WID_DT_STATION)) SetViewportCatchmentStation(nullptr, true);
|
2023-09-15 19:59:08 +00:00
|
|
|
if (_settings_client.gui.link_terraform_toolbar) CloseWindowById(WC_SCEN_LAND_GEN, 0, false);
|
2023-09-15 22:56:33 +00:00
|
|
|
this->Window::Close();
|
2008-05-18 21:34:35 +00:00
|
|
|
}
|
|
|
|
|
2011-03-13 21:31:29 +00:00
|
|
|
/**
|
|
|
|
* Some data on this window has become invalid.
|
|
|
|
* @param data Information about the changed data.
|
|
|
|
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
|
|
|
|
*/
|
2023-09-16 20:20:53 +00:00
|
|
|
void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
|
2010-09-28 21:58:06 +00:00
|
|
|
{
|
2011-03-13 21:31:29 +00:00
|
|
|
if (!gui_scope) return;
|
2015-02-22 15:26:27 +00:00
|
|
|
|
|
|
|
bool can_build = CanBuildVehicleInfrastructure(VEH_SHIP);
|
|
|
|
this->SetWidgetsDisabledState(!can_build,
|
2011-12-16 16:27:45 +00:00
|
|
|
WID_DT_DEPOT,
|
|
|
|
WID_DT_STATION,
|
2023-09-16 19:56:09 +00:00
|
|
|
WID_DT_BUOY);
|
2015-02-22 15:26:27 +00:00
|
|
|
if (!can_build) {
|
2023-09-15 19:59:08 +00:00
|
|
|
CloseWindowById(WC_BUILD_STATION, TRANSPORT_WATER);
|
|
|
|
CloseWindowById(WC_BUILD_DEPOT, TRANSPORT_WATER);
|
2015-02-22 15:26:27 +00:00
|
|
|
}
|
2021-01-07 22:06:23 +00:00
|
|
|
|
2021-01-08 18:48:39 +00:00
|
|
|
if (_game_mode != GM_EDITOR) {
|
|
|
|
if (!can_build) {
|
|
|
|
/* Show in the tooltip why this button is disabled. */
|
|
|
|
this->GetWidget<NWidgetCore>(WID_DT_DEPOT)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE);
|
|
|
|
this->GetWidget<NWidgetCore>(WID_DT_STATION)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE);
|
|
|
|
this->GetWidget<NWidgetCore>(WID_DT_BUOY)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE);
|
|
|
|
} else {
|
|
|
|
this->GetWidget<NWidgetCore>(WID_DT_DEPOT)->SetToolTip(STR_WATERWAYS_TOOLBAR_BUILD_DEPOT_TOOLTIP);
|
|
|
|
this->GetWidget<NWidgetCore>(WID_DT_STATION)->SetToolTip(STR_WATERWAYS_TOOLBAR_BUILD_DOCK_TOOLTIP);
|
|
|
|
this->GetWidget<NWidgetCore>(WID_DT_BUOY)->SetToolTip(STR_WATERWAYS_TOOLBAR_BUOY_TOOLTIP);
|
|
|
|
}
|
2015-02-22 15:26:27 +00:00
|
|
|
}
|
2010-09-28 21:58:06 +00:00
|
|
|
}
|
|
|
|
|
2023-12-29 19:11:59 +00:00
|
|
|
void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
|
2008-05-18 21:34:35 +00:00
|
|
|
{
|
2010-12-20 13:16:22 +00:00
|
|
|
switch (widget) {
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_DT_CANAL: // Build canal button
|
|
|
|
HandlePlacePushButton(this, WID_DT_CANAL, SPR_CURSOR_CANAL, HT_RECT);
|
2010-12-20 13:16:22 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_DT_LOCK: // Build lock button
|
|
|
|
HandlePlacePushButton(this, WID_DT_LOCK, SPR_CURSOR_LOCK, HT_SPECIAL);
|
2010-12-20 13:16:22 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_DT_DEMOLISH: // Demolish aka dynamite button
|
|
|
|
HandlePlacePushButton(this, WID_DT_DEMOLISH, ANIMCURSOR_DEMOLISH, HT_RECT | HT_DIAGONAL);
|
2010-12-20 13:16:22 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_DT_DEPOT: // Build depot button
|
|
|
|
if (HandlePlacePushButton(this, WID_DT_DEPOT, SPR_CURSOR_SHIP_DEPOT, HT_RECT)) ShowBuildDocksDepotPicker(this);
|
2010-12-20 13:16:22 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_DT_STATION: // Build station button
|
|
|
|
if (HandlePlacePushButton(this, WID_DT_STATION, SPR_CURSOR_DOCK, HT_SPECIAL)) ShowBuildDockStationPicker(this);
|
2010-12-20 13:16:22 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_DT_BUOY: // Build buoy button
|
|
|
|
HandlePlacePushButton(this, WID_DT_BUOY, SPR_CURSOR_BUOY, HT_RECT);
|
2010-12-20 13:16:22 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_DT_RIVER: // Build river button (in scenario editor)
|
2015-08-25 22:44:28 +00:00
|
|
|
if (_game_mode != GM_EDITOR && !_settings_game.construction.enable_build_river) return;
|
2019-04-11 17:37:53 +00:00
|
|
|
HandlePlacePushButton(this, WID_DT_RIVER, SPR_CURSOR_RIVER, _game_mode == GM_EDITOR ? HT_RECT | HT_DIAGONAL : HT_RECT);
|
2010-12-20 13:16:22 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_DT_BUILD_AQUEDUCT: // Build aqueduct button
|
|
|
|
HandlePlacePushButton(this, WID_DT_BUILD_AQUEDUCT, SPR_CURSOR_AQUEDUCT, HT_SPECIAL);
|
2010-12-20 13:16:22 +00:00
|
|
|
break;
|
|
|
|
|
2011-03-20 20:51:31 +00:00
|
|
|
default: return;
|
2010-12-20 13:16:22 +00:00
|
|
|
}
|
2011-03-20 20:51:31 +00:00
|
|
|
this->last_clicked_widget = (DockToolbarWidgets)widget;
|
2008-05-18 21:34:35 +00:00
|
|
|
}
|
|
|
|
|
2023-09-16 20:20:53 +00:00
|
|
|
void OnPlaceObject([[maybe_unused]] Point pt, TileIndex tile) override
|
2008-05-18 21:34:35 +00:00
|
|
|
{
|
2010-12-20 13:19:59 +00:00
|
|
|
switch (this->last_clicked_widget) {
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_DT_CANAL: // Build canal button
|
2022-11-23 22:48:19 +00:00
|
|
|
VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_CREATE_WATER);
|
2010-12-20 13:19:59 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_DT_LOCK: // Build lock button
|
2010-12-20 13:19:59 +00:00
|
|
|
DoCommandP(tile, 0, 0, CMD_BUILD_LOCK | CMD_MSG(STR_ERROR_CAN_T_BUILD_LOCKS), CcBuildDocks);
|
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_DT_DEMOLISH: // Demolish aka dynamite button
|
2010-12-20 13:19:59 +00:00
|
|
|
PlaceProc_DemolishArea(tile);
|
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_DT_DEPOT: // Build depot button
|
2010-12-20 13:19:59 +00:00
|
|
|
DoCommandP(tile, _ship_depot_direction, 0, CMD_BUILD_SHIP_DEPOT | CMD_MSG(STR_ERROR_CAN_T_BUILD_SHIP_DEPOT), CcBuildDocks);
|
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_DT_STATION: { // Build station button
|
2024-01-07 16:41:53 +00:00
|
|
|
uint32_t p2 = (uint32_t)INVALID_STATION << 16; // no station to join
|
2010-12-20 13:19:59 +00:00
|
|
|
|
|
|
|
/* tile is always the land tile, so need to evaluate _thd.pos */
|
2020-10-17 13:42:46 +00:00
|
|
|
CommandContainer cmdcont = NewCommandContainerBasic(tile, _ctrl_pressed, p2, CMD_BUILD_DOCK | CMD_MSG(STR_ERROR_CAN_T_BUILD_DOCK_HERE), CcBuildDocks);
|
2010-12-20 13:19:59 +00:00
|
|
|
|
|
|
|
/* Determine the watery part of the dock. */
|
2011-11-04 10:22:27 +00:00
|
|
|
DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile));
|
2010-12-20 13:19:59 +00:00
|
|
|
TileIndex tile_to = (dir != INVALID_DIAGDIR ? TileAddByDiagDir(tile, ReverseDiagDir(dir)) : tile);
|
|
|
|
|
|
|
|
ShowSelectStationIfNeeded(cmdcont, TileArea(tile, tile_to));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_DT_BUOY: // Build buoy button
|
2010-12-20 13:19:59 +00:00
|
|
|
DoCommandP(tile, 0, 0, CMD_BUILD_BUOY | CMD_MSG(STR_ERROR_CAN_T_POSITION_BUOY_HERE), CcBuildDocks);
|
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_DT_RIVER: // Build river button (in scenario editor)
|
2019-04-11 17:37:53 +00:00
|
|
|
VpStartPlaceSizing(tile, (_game_mode == GM_EDITOR) ? VPM_X_AND_Y : VPM_X_OR_Y, DDSP_CREATE_RIVER);
|
2010-12-20 13:19:59 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_DT_BUILD_AQUEDUCT: // Build aqueduct button
|
2010-12-20 13:19:59 +00:00
|
|
|
DoCommandP(tile, GetOtherAqueductEnd(tile), TRANSPORT_WATER << 15, CMD_BUILD_BRIDGE | CMD_MSG(STR_ERROR_CAN_T_BUILD_AQUEDUCT_HERE), CcBuildBridge);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
2008-05-18 21:34:35 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2023-09-16 20:20:53 +00:00
|
|
|
void OnPlaceDrag(ViewportPlaceMethod select_method, [[maybe_unused]] ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt) override
|
2008-05-18 21:34:35 +00:00
|
|
|
{
|
|
|
|
VpSelectTilesWithMethod(pt.x, pt.y, select_method);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2023-09-16 20:20:53 +00:00
|
|
|
void OnPlaceMouseUp([[maybe_unused]] ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt, TileIndex start_tile, TileIndex end_tile) override
|
2008-05-18 21:34:35 +00:00
|
|
|
{
|
|
|
|
if (pt.x != -1) {
|
|
|
|
switch (select_proc) {
|
2007-05-23 13:52:10 +00:00
|
|
|
case DDSP_DEMOLISH_AREA:
|
2008-05-18 21:34:35 +00:00
|
|
|
GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
|
2007-05-23 12:45:56 +00:00
|
|
|
break;
|
2007-05-23 13:52:10 +00:00
|
|
|
case DDSP_CREATE_WATER:
|
2021-02-20 18:01:04 +00:00
|
|
|
DoCommandP(end_tile, start_tile, (_game_mode == GM_EDITOR && _ctrl_pressed) ? WATER_CLASS_SEA : WATER_CLASS_CANAL, CMD_BUILD_CANAL | CMD_MSG(STR_ERROR_CAN_T_BUILD_CANALS), CcPlaySound_CONSTRUCTION_WATER);
|
2008-06-25 17:30:16 +00:00
|
|
|
break;
|
|
|
|
case DDSP_CREATE_RIVER:
|
2021-02-21 11:49:54 +00:00
|
|
|
DoCommandP(end_tile, start_tile, WATER_CLASS_RIVER | (_ctrl_pressed ? 1 << 2 : 0), CMD_BUILD_CANAL | CMD_MSG(STR_ERROR_CAN_T_PLACE_RIVERS), CcPlaySound_CONSTRUCTION_WATER);
|
2007-05-23 12:45:56 +00:00
|
|
|
break;
|
2008-05-18 21:34:35 +00:00
|
|
|
|
2007-05-23 12:45:56 +00:00
|
|
|
default: break;
|
2005-10-23 13:04:44 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2008-05-18 21:34:35 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2019-03-04 07:49:37 +00:00
|
|
|
void OnPlaceObjectAbort() override
|
2008-05-18 21:34:35 +00:00
|
|
|
{
|
2019-04-29 18:09:11 +00:00
|
|
|
if (_game_mode != GM_EDITOR && this->IsWidgetLowered(WID_DT_STATION)) SetViewportCatchmentStation(nullptr, true);
|
2019-03-30 16:58:40 +00:00
|
|
|
|
2008-05-18 21:34:35 +00:00
|
|
|
this->RaiseButtons();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2023-09-15 19:59:08 +00:00
|
|
|
CloseWindowById(WC_BUILD_STATION, TRANSPORT_WATER);
|
|
|
|
CloseWindowById(WC_BUILD_DEPOT, TRANSPORT_WATER);
|
|
|
|
CloseWindowById(WC_SELECT_STATION, 0);
|
|
|
|
CloseWindowByClass(WC_BUILD_BRIDGE);
|
2008-05-18 21:34:35 +00:00
|
|
|
}
|
2008-01-25 15:47:58 +00:00
|
|
|
|
2023-09-16 20:20:53 +00:00
|
|
|
void OnPlacePresize([[maybe_unused]] Point pt, TileIndex tile_from) override
|
2008-05-18 21:34:35 +00:00
|
|
|
{
|
2010-12-11 19:49:44 +00:00
|
|
|
TileIndex tile_to = tile_from;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
if (this->last_clicked_widget == WID_DT_BUILD_AQUEDUCT) {
|
2010-12-11 19:49:44 +00:00
|
|
|
GetOtherAqueductEnd(tile_from, &tile_to);
|
|
|
|
} else {
|
2011-11-04 10:22:27 +00:00
|
|
|
DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile_from));
|
2010-12-11 19:49:44 +00:00
|
|
|
if (IsValidDiagDirection(dir)) {
|
|
|
|
/* Locks and docks always select the tile "down" the slope. */
|
|
|
|
tile_to = TileAddByDiagDir(tile_from, ReverseDiagDir(dir));
|
|
|
|
/* Locks also select the tile "up" the slope. */
|
2011-12-16 16:27:45 +00:00
|
|
|
if (this->last_clicked_widget == WID_DT_LOCK) tile_from = TileAddByDiagDir(tile_from, dir);
|
2010-12-11 19:49:44 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-25 15:47:58 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
VpSetPresizeRange(tile_from, tile_to);
|
|
|
|
}
|
2010-07-03 18:18:58 +00:00
|
|
|
|
2013-06-15 15:28:09 +00:00
|
|
|
static HotkeyList hotkeys;
|
2008-05-18 21:34:35 +00:00
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2013-06-15 15:31:22 +00:00
|
|
|
/**
|
|
|
|
* Handler for global hotkeys of the BuildDocksToolbarWindow.
|
|
|
|
* @param hotkey Hotkey
|
|
|
|
* @return ES_HANDLED if hotkey was accepted.
|
|
|
|
*/
|
|
|
|
static EventState DockToolbarGlobalHotkeys(int hotkey)
|
|
|
|
{
|
|
|
|
if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED;
|
|
|
|
Window *w = ShowBuildDocksToolbar();
|
2019-04-10 21:07:06 +00:00
|
|
|
if (w == nullptr) return ES_NOT_HANDLED;
|
2013-06-15 15:31:22 +00:00
|
|
|
return w->OnHotkey(hotkey);
|
|
|
|
}
|
|
|
|
|
2024-01-07 16:41:53 +00:00
|
|
|
const uint16_t _dockstoolbar_aqueduct_keys[] = {'B', '8', 0};
|
2010-07-03 18:18:58 +00:00
|
|
|
|
2013-06-15 15:28:09 +00:00
|
|
|
static Hotkey dockstoolbar_hotkeys[] = {
|
2013-06-15 15:27:33 +00:00
|
|
|
Hotkey('1', "canal", WID_DT_CANAL),
|
|
|
|
Hotkey('2', "lock", WID_DT_LOCK),
|
|
|
|
Hotkey('3', "demolish", WID_DT_DEMOLISH),
|
|
|
|
Hotkey('4', "depot", WID_DT_DEPOT),
|
|
|
|
Hotkey('5', "dock", WID_DT_STATION),
|
|
|
|
Hotkey('6', "buoy", WID_DT_BUOY),
|
|
|
|
Hotkey('7', "river", WID_DT_RIVER),
|
|
|
|
Hotkey(_dockstoolbar_aqueduct_keys, "aqueduct", WID_DT_BUILD_AQUEDUCT),
|
|
|
|
HOTKEY_LIST_END
|
2010-07-03 18:18:58 +00:00
|
|
|
};
|
2013-06-15 15:31:22 +00:00
|
|
|
HotkeyList BuildDocksToolbarWindow::hotkeys("dockstoolbar", dockstoolbar_hotkeys, DockToolbarGlobalHotkeys);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-03-28 12:40:57 +00:00
|
|
|
/**
|
|
|
|
* Nested widget parts of docks toolbar, game version.
|
2011-12-16 16:27:45 +00:00
|
|
|
* Position of #WID_DT_RIVER widget has changed.
|
2009-03-28 12:40:57 +00:00
|
|
|
*/
|
2024-01-15 22:49:24 +00:00
|
|
|
static constexpr NWidgetPart _nested_build_docks_toolbar_widgets[] = {
|
2009-03-28 12:40:57 +00:00
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
|
|
|
|
NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_WATERWAYS_TOOLBAR_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
|
|
|
NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
|
2009-03-28 12:40:57 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL_LTR),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_CANAL), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_BUILD_CANAL, STR_WATERWAYS_TOOLBAR_BUILD_CANALS_TOOLTIP),
|
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_LOCK), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_BUILD_LOCK, STR_WATERWAYS_TOOLBAR_BUILD_LOCKS_TOOLTIP),
|
2009-11-24 21:13:36 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetMinimalSize(5, 22), SetFill(1, 1), EndContainer(),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_DEMOLISH), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
|
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_DEPOT), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_SHIP_DEPOT, STR_WATERWAYS_TOOLBAR_BUILD_DEPOT_TOOLTIP),
|
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_STATION), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_SHIP_DOCK, STR_WATERWAYS_TOOLBAR_BUILD_DOCK_TOOLTIP),
|
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_BUOY), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_BUOY, STR_WATERWAYS_TOOLBAR_BUOY_TOOLTIP),
|
2022-04-15 17:32:56 +00:00
|
|
|
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_DT_RIVER_SEL),
|
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_RIVER), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_BUILD_RIVER, STR_WATERWAYS_TOOLBAR_CREATE_RIVER_IN_GAME_TOOLTIP),
|
|
|
|
EndContainer(),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_BUILD_AQUEDUCT), SetMinimalSize(23, 22), SetFill(0, 1), SetDataTip(SPR_IMG_AQUEDUCT, STR_WATERWAYS_TOOLBAR_BUILD_AQUEDUCT_TOOLTIP),
|
2009-03-28 12:40:57 +00:00
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2023-11-02 19:33:01 +00:00
|
|
|
static WindowDesc _build_docks_toolbar_desc(__FILE__, __LINE__,
|
2013-05-26 19:25:01 +00:00
|
|
|
WDP_ALIGN_TOOLBAR, "toolbar_water", 0, 0,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_BUILD_TOOLBAR, WC_NONE,
|
2009-11-24 17:28:29 +00:00
|
|
|
WDF_CONSTRUCTION,
|
2023-09-03 20:54:13 +00:00
|
|
|
std::begin(_nested_build_docks_toolbar_widgets), std::end(_nested_build_docks_toolbar_widgets),
|
2013-06-15 15:30:44 +00:00
|
|
|
&BuildDocksToolbarWindow::hotkeys
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-07-04 09:27:15 +00:00
|
|
|
/**
|
|
|
|
* Open the build water toolbar window
|
|
|
|
*
|
|
|
|
* If the terraform toolbar is linked to the toolbar, that window is also opened.
|
|
|
|
*
|
2019-04-10 21:07:06 +00:00
|
|
|
* @return newly opened water toolbar, or nullptr if the toolbar could not be opened.
|
2010-07-04 09:27:15 +00:00
|
|
|
*/
|
|
|
|
Window *ShowBuildDocksToolbar()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2019-04-10 21:07:06 +00:00
|
|
|
if (!Company::IsValidID(_local_company)) return nullptr;
|
2006-10-31 21:15:56 +00:00
|
|
|
|
2023-09-15 19:59:08 +00:00
|
|
|
CloseWindowByClass(WC_BUILD_TOOLBAR);
|
2010-07-04 09:27:15 +00:00
|
|
|
return AllocateWindowDescFront<BuildDocksToolbarWindow>(&_build_docks_toolbar_desc, TRANSPORT_WATER);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2009-03-28 12:40:57 +00:00
|
|
|
/**
|
|
|
|
* Nested widget parts of docks toolbar, scenario editor version.
|
2011-12-16 16:27:45 +00:00
|
|
|
* Positions of #WID_DT_DEPOT, #WID_DT_STATION, and #WID_DT_BUOY widgets have changed.
|
2009-03-28 12:40:57 +00:00
|
|
|
*/
|
2024-01-15 22:49:24 +00:00
|
|
|
static constexpr NWidgetPart _nested_build_docks_scen_toolbar_widgets[] = {
|
2009-03-28 12:40:57 +00:00
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
|
|
|
|
NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_WATERWAYS_TOOLBAR_CAPTION_SE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
|
|
|
NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
|
2009-03-28 12:40:57 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_CANAL), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_BUILD_CANAL, STR_WATERWAYS_TOOLBAR_CREATE_LAKE_TOOLTIP),
|
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_LOCK), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_BUILD_LOCK, STR_WATERWAYS_TOOLBAR_BUILD_LOCKS_TOOLTIP),
|
2009-11-24 21:13:36 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetMinimalSize(5, 22), SetFill(1, 1), EndContainer(),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_DEMOLISH), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
|
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_RIVER), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_BUILD_RIVER, STR_WATERWAYS_TOOLBAR_CREATE_RIVER_TOOLTIP),
|
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_DT_BUILD_AQUEDUCT), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_AQUEDUCT, STR_WATERWAYS_TOOLBAR_BUILD_AQUEDUCT_TOOLTIP),
|
2009-03-28 12:40:57 +00:00
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2009-03-28 11:17:01 +00:00
|
|
|
/** Window definition for the build docks in scenario editor window. */
|
2023-11-02 19:33:01 +00:00
|
|
|
static WindowDesc _build_docks_scen_toolbar_desc(__FILE__, __LINE__,
|
2013-05-26 19:25:01 +00:00
|
|
|
WDP_AUTO, "toolbar_water_scen", 0, 0,
|
2008-06-25 17:30:16 +00:00
|
|
|
WC_SCEN_BUILD_TOOLBAR, WC_NONE,
|
2009-11-24 17:28:29 +00:00
|
|
|
WDF_CONSTRUCTION,
|
2023-09-03 20:54:13 +00:00
|
|
|
std::begin(_nested_build_docks_scen_toolbar_widgets), std::end(_nested_build_docks_scen_toolbar_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2008-06-25 17:30:16 +00:00
|
|
|
|
2010-07-04 09:27:15 +00:00
|
|
|
/**
|
|
|
|
* Open the build water toolbar window for the scenario editor.
|
|
|
|
*
|
2019-04-10 21:07:06 +00:00
|
|
|
* @return newly opened water toolbar, or nullptr if the toolbar could not be opened.
|
2010-07-04 09:27:15 +00:00
|
|
|
*/
|
|
|
|
Window *ShowBuildDocksScenToolbar()
|
2008-06-25 17:30:16 +00:00
|
|
|
{
|
2010-07-04 09:27:15 +00:00
|
|
|
return AllocateWindowDescFront<BuildDocksToolbarWindow>(&_build_docks_scen_toolbar_desc, TRANSPORT_WATER);
|
2008-06-25 17:30:16 +00:00
|
|
|
}
|
|
|
|
|
2009-03-28 12:40:57 +00:00
|
|
|
/** Widget numbers of the build-dock GUI. */
|
|
|
|
enum BuildDockStationWidgets {
|
|
|
|
BDSW_BACKGROUND, ///< Background panel.
|
|
|
|
BDSW_LT_OFF, ///< 'Off' button of coverage high light.
|
|
|
|
BDSW_LT_ON, ///< 'On' button of coverage high light.
|
|
|
|
BDSW_INFO, ///< 'Coverage highlight' label.
|
2021-05-04 11:35:27 +00:00
|
|
|
BDSW_ACCEPTANCE, ///< Acceptance info.
|
2009-03-28 12:40:57 +00:00
|
|
|
};
|
2008-05-17 20:49:45 +00:00
|
|
|
|
2009-03-28 12:40:57 +00:00
|
|
|
struct BuildDocksStationWindow : public PickerWindowBase {
|
2008-05-17 20:49:45 +00:00
|
|
|
public:
|
2013-05-26 19:23:42 +00:00
|
|
|
BuildDocksStationWindow(WindowDesc *desc, Window *parent) : PickerWindowBase(desc, parent)
|
2008-05-17 20:49:45 +00:00
|
|
|
{
|
2013-05-26 19:23:42 +00:00
|
|
|
this->InitNested(TRANSPORT_WATER);
|
2009-01-04 11:11:11 +00:00
|
|
|
this->LowerWidget(_settings_client.gui.station_show_coverage + BDSW_LT_OFF);
|
2008-05-17 20:49:45 +00:00
|
|
|
}
|
2006-10-03 20:16:20 +00:00
|
|
|
|
2023-10-13 11:59:15 +00:00
|
|
|
void Close([[maybe_unused]] int data = 0) override
|
2009-01-08 16:35:45 +00:00
|
|
|
{
|
2023-09-15 19:59:08 +00:00
|
|
|
CloseWindowById(WC_SELECT_STATION, 0);
|
2023-09-15 22:56:33 +00:00
|
|
|
this->PickerWindowBase::Close();
|
2009-01-08 16:35:45 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 07:49:37 +00:00
|
|
|
void OnPaint() override
|
2008-05-17 20:49:45 +00:00
|
|
|
{
|
2008-05-29 15:13:28 +00:00
|
|
|
int rad = (_settings_game.station.modified_catchment) ? CA_DOCK : CA_UNMODIFIED;
|
2016-11-20 01:49:10 +00:00
|
|
|
rad += _settings_game.station.catchment_increase;
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2008-05-17 20:49:45 +00:00
|
|
|
this->DrawWidgets();
|
2005-11-13 14:54:09 +00:00
|
|
|
|
2009-01-04 11:11:11 +00:00
|
|
|
if (_settings_client.gui.station_show_coverage) {
|
2007-06-08 18:15:11 +00:00
|
|
|
SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
|
|
|
|
} else {
|
|
|
|
SetTileSelectSize(1, 1);
|
|
|
|
}
|
2004-12-19 09:31:35 +00:00
|
|
|
|
2009-07-10 22:03:09 +00:00
|
|
|
/* strings such as 'Size' and 'Coverage Area' */
|
2021-05-04 11:35:27 +00:00
|
|
|
Rect r = this->GetWidget<NWidgetBase>(BDSW_ACCEPTANCE)->GetCurrentRect();
|
2023-10-28 00:34:57 +00:00
|
|
|
int top = r.top;
|
2022-09-23 08:36:22 +00:00
|
|
|
top = DrawStationCoverageAreaText(r.left, r.right, top, SCT_ALL, rad, false) + WidgetDimensions::scaled.vsep_normal;
|
2023-10-28 00:34:57 +00:00
|
|
|
top = DrawStationCoverageAreaText(r.left, r.right, top, SCT_ALL, rad, true);
|
2013-06-11 18:36:26 +00:00
|
|
|
/* Resize background if the window is too small.
|
|
|
|
* Never make the window smaller to avoid oscillating if the size change affects the acceptance.
|
|
|
|
* (This is the case, if making the window bigger moves the mouse into the window.) */
|
2021-05-04 11:35:27 +00:00
|
|
|
if (top > r.bottom) {
|
|
|
|
ResizeWindow(this, 0, top - r.bottom, false);
|
2008-01-27 11:01:10 +00:00
|
|
|
}
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2023-12-29 19:11:59 +00:00
|
|
|
void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
|
2008-05-17 20:49:45 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case BDSW_LT_OFF:
|
|
|
|
case BDSW_LT_ON:
|
2009-01-04 11:11:11 +00:00
|
|
|
this->RaiseWidget(_settings_client.gui.station_show_coverage + BDSW_LT_OFF);
|
|
|
|
_settings_client.gui.station_show_coverage = (widget != BDSW_LT_OFF);
|
|
|
|
this->LowerWidget(_settings_client.gui.station_show_coverage + BDSW_LT_OFF);
|
2012-12-23 21:09:09 +00:00
|
|
|
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
|
2008-05-17 20:49:45 +00:00
|
|
|
this->SetDirty();
|
2020-07-04 19:55:52 +00:00
|
|
|
SetViewportCatchmentStation(nullptr, true);
|
2005-11-14 19:48:04 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2008-05-17 20:49:45 +00:00
|
|
|
}
|
2005-01-20 08:36:15 +00:00
|
|
|
|
2023-09-16 20:20:53 +00:00
|
|
|
void OnRealtimeTick([[maybe_unused]] uint delta_ms) override
|
2008-05-17 20:49:45 +00:00
|
|
|
{
|
|
|
|
CheckRedrawStationCoverage(this);
|
2004-09-10 19:02:27 +00:00
|
|
|
}
|
2008-05-17 20:49:45 +00:00
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-03-28 12:40:57 +00:00
|
|
|
/** Nested widget parts of a build dock station window. */
|
2024-01-15 22:49:24 +00:00
|
|
|
static constexpr NWidgetPart _nested_build_dock_station_widgets[] = {
|
2009-03-28 12:40:57 +00:00
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
|
|
|
|
NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_STATION_BUILD_DOCK_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
2009-03-28 12:40:57 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_DARK_GREEN, BDSW_BACKGROUND),
|
2023-10-28 00:34:57 +00:00
|
|
|
NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0), SetPadding(WidgetDimensions::unscaled.picker),
|
|
|
|
NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_picker, 0),
|
|
|
|
NWidget(WWT_LABEL, COLOUR_DARK_GREEN, BDSW_INFO), SetDataTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE, STR_NULL), SetFill(1, 0),
|
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(14, 0, 14),
|
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, BDSW_LT_OFF), SetMinimalSize(60, 12), SetFill(1, 0), SetDataTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
|
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, BDSW_LT_ON), SetMinimalSize(60, 12), SetFill(1, 0), SetDataTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
|
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(WWT_EMPTY, COLOUR_GREY, BDSW_ACCEPTANCE), SetResize(0, 1), SetMinimalTextLines(2, WidgetDimensions::unscaled.vsep_normal),
|
2009-03-28 12:40:57 +00:00
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2023-11-02 19:33:01 +00:00
|
|
|
static WindowDesc _build_dock_station_desc(__FILE__, __LINE__,
|
2019-04-10 21:07:06 +00:00
|
|
|
WDP_AUTO, nullptr, 0, 0,
|
2006-11-10 19:24:14 +00:00
|
|
|
WC_BUILD_STATION, WC_BUILD_TOOLBAR,
|
2009-11-24 17:28:29 +00:00
|
|
|
WDF_CONSTRUCTION,
|
2023-09-03 20:54:13 +00:00
|
|
|
std::begin(_nested_build_dock_station_widgets), std::end(_nested_build_dock_station_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-24 11:19:30 +00:00
|
|
|
static void ShowBuildDockStationPicker(Window *parent)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-05-24 11:19:30 +00:00
|
|
|
new BuildDocksStationWindow(&_build_dock_station_desc, parent);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-05-17 20:49:45 +00:00
|
|
|
struct BuildDocksDepotWindow : public PickerWindowBase {
|
|
|
|
private:
|
|
|
|
static void UpdateDocksDirection()
|
|
|
|
{
|
|
|
|
if (_ship_depot_direction != AXIS_X) {
|
|
|
|
SetTileSelectSize(1, 2);
|
|
|
|
} else {
|
|
|
|
SetTileSelectSize(2, 1);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-05-17 20:49:45 +00:00
|
|
|
public:
|
2013-05-26 19:23:42 +00:00
|
|
|
BuildDocksDepotWindow(WindowDesc *desc, Window *parent) : PickerWindowBase(desc, parent)
|
2008-05-17 20:49:45 +00:00
|
|
|
{
|
2013-05-26 19:23:42 +00:00
|
|
|
this->InitNested(TRANSPORT_WATER);
|
2024-01-16 21:01:28 +00:00
|
|
|
this->LowerWidget(WID_BDD_X + _ship_depot_direction);
|
2008-05-17 20:49:45 +00:00
|
|
|
UpdateDocksDirection();
|
|
|
|
}
|
2006-10-03 20:16:20 +00:00
|
|
|
|
2023-12-29 19:11:59 +00:00
|
|
|
void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
|
2014-09-22 08:01:25 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case WID_BDD_X:
|
|
|
|
case WID_BDD_Y:
|
2022-09-23 08:36:22 +00:00
|
|
|
size->width = ScaleGUITrad(96) + WidgetDimensions::scaled.fullbevel.Horizontal();
|
|
|
|
size->height = ScaleGUITrad(64) + WidgetDimensions::scaled.fullbevel.Vertical();
|
2014-09-22 08:01:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-29 19:11:59 +00:00
|
|
|
void DrawWidget(const Rect &r, WidgetID widget) const override
|
2008-05-17 20:49:45 +00:00
|
|
|
{
|
2022-10-17 18:25:33 +00:00
|
|
|
DrawPixelInfo tmp_dpi;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2022-10-17 18:25:33 +00:00
|
|
|
switch (widget) {
|
|
|
|
case WID_BDD_X:
|
|
|
|
case WID_BDD_Y: {
|
|
|
|
Axis axis = widget == WID_BDD_X ? AXIS_X : AXIS_Y;
|
|
|
|
|
2023-12-20 00:15:33 +00:00
|
|
|
Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
|
|
|
|
if (FillDrawPixelInfo(&tmp_dpi, ir)) {
|
2023-01-26 18:21:36 +00:00
|
|
|
AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
|
2023-12-20 00:15:33 +00:00
|
|
|
int x = (ir.Width() - ScaleSpriteTrad(96)) / 2;
|
|
|
|
int y = (ir.Height() - ScaleSpriteTrad(64)) / 2;
|
2022-09-05 20:05:18 +00:00
|
|
|
int x1 = ScaleSpriteTrad(63);
|
|
|
|
int x2 = ScaleSpriteTrad(31);
|
|
|
|
DrawShipDepotSprite(x + (axis == AXIS_X ? x1 : x2), y + ScaleSpriteTrad(17), axis, DEPOT_PART_NORTH);
|
|
|
|
DrawShipDepotSprite(x + (axis == AXIS_X ? x2 : x1), y + ScaleSpriteTrad(33), axis, DEPOT_PART_SOUTH);
|
2022-10-17 18:25:33 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-05-17 20:49:45 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2023-12-29 19:11:59 +00:00
|
|
|
void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
|
2008-05-17 20:49:45 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
2011-12-19 20:46:17 +00:00
|
|
|
case WID_BDD_X:
|
|
|
|
case WID_BDD_Y:
|
2024-01-16 21:01:28 +00:00
|
|
|
this->RaiseWidget(WID_BDD_X + _ship_depot_direction);
|
2011-12-19 20:46:17 +00:00
|
|
|
_ship_depot_direction = (widget == WID_BDD_X ? AXIS_X : AXIS_Y);
|
2024-01-16 21:01:28 +00:00
|
|
|
this->LowerWidget(WID_BDD_X + _ship_depot_direction);
|
2012-12-23 21:09:09 +00:00
|
|
|
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
|
2008-05-17 20:49:45 +00:00
|
|
|
UpdateDocksDirection();
|
|
|
|
this->SetDirty();
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-17 20:49:45 +00:00
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2024-01-15 22:49:24 +00:00
|
|
|
static constexpr NWidgetPart _nested_build_docks_depot_widgets[] = {
|
2009-03-26 21:12:14 +00:00
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
|
|
|
|
NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_DEPOT_BUILD_SHIP_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
2009-03-26 21:12:14 +00:00
|
|
|
EndContainer(),
|
2011-12-19 20:46:17 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BDD_BACKGROUND),
|
2023-10-31 19:25:12 +00:00
|
|
|
NWidget(NWID_HORIZONTAL_LTR), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0), SetPIPRatio(1, 0, 1), SetPadding(WidgetDimensions::unscaled.picker),
|
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BDD_X), SetMinimalSize(98, 66), SetDataTip(0x0, STR_DEPOT_BUILD_SHIP_ORIENTATION_TOOLTIP),
|
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BDD_Y), SetMinimalSize(98, 66), SetDataTip(0x0, STR_DEPOT_BUILD_SHIP_ORIENTATION_TOOLTIP),
|
2009-03-26 21:12:14 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(0, 3),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2023-11-02 19:33:01 +00:00
|
|
|
static WindowDesc _build_docks_depot_desc(__FILE__, __LINE__,
|
2019-04-10 21:07:06 +00:00
|
|
|
WDP_AUTO, nullptr, 0, 0,
|
2006-11-10 19:24:14 +00:00
|
|
|
WC_BUILD_DEPOT, WC_BUILD_TOOLBAR,
|
2009-11-24 17:28:29 +00:00
|
|
|
WDF_CONSTRUCTION,
|
2023-09-03 20:54:13 +00:00
|
|
|
std::begin(_nested_build_docks_depot_widgets), std::end(_nested_build_docks_depot_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
|
2008-05-24 11:19:30 +00:00
|
|
|
static void ShowBuildDocksDepotPicker(Window *parent)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-05-24 11:19:30 +00:00
|
|
|
new BuildDocksDepotWindow(&_build_docks_depot_desc, parent);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void InitializeDockGui()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-03-08 06:55:33 +00:00
|
|
|
_ship_depot_direction = AXIS_X;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|