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-08-20 01:29:05 +00:00
|
|
|
/** @file waypoint_gui.cpp Handling of waypoints gui. */
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "window_gui.h"
|
|
|
|
#include "gui.h"
|
|
|
|
#include "textbuf_gui.h"
|
2010-09-08 21:37:13 +00:00
|
|
|
#include "vehiclelist.h"
|
2008-08-20 01:29:05 +00:00
|
|
|
#include "vehicle_gui.h"
|
|
|
|
#include "viewport_func.h"
|
|
|
|
#include "strings_func.h"
|
|
|
|
#include "command_func.h"
|
2009-02-07 16:11:21 +00:00
|
|
|
#include "company_func.h"
|
2010-06-10 23:52:09 +00:00
|
|
|
#include "company_base.h"
|
2008-09-12 22:52:48 +00:00
|
|
|
#include "window_func.h"
|
2009-07-22 10:18:19 +00:00
|
|
|
#include "waypoint_base.h"
|
2021-10-31 18:39:09 +00:00
|
|
|
#include "waypoint_cmd.h"
|
2023-06-18 17:46:53 +00:00
|
|
|
#include "zoom_func.h"
|
2008-08-20 01:29:05 +00:00
|
|
|
|
2011-12-15 22:22:55 +00:00
|
|
|
#include "widgets/waypoint_widget.h"
|
2008-08-20 01:29:05 +00:00
|
|
|
|
2011-12-15 22:22:55 +00:00
|
|
|
#include "table/strings.h"
|
2009-03-25 21:38:05 +00:00
|
|
|
|
2014-04-23 20:13:33 +00:00
|
|
|
#include "safeguards.h"
|
|
|
|
|
2010-10-23 20:39:21 +00:00
|
|
|
/** GUI for accessing waypoints and buoys. */
|
2008-08-20 01:29:05 +00:00
|
|
|
struct WaypointWindow : Window {
|
|
|
|
private:
|
2010-10-23 20:39:21 +00:00
|
|
|
VehicleType vt; ///< Vehicle type using the waypoint.
|
|
|
|
Waypoint *wp; ///< Waypoint displayed by the window.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the center tile of the waypoint.
|
|
|
|
* @return The center tile if the waypoint exists, otherwise the tile with the waypoint name.
|
|
|
|
*/
|
|
|
|
TileIndex GetCenterTile() const
|
|
|
|
{
|
2010-10-24 20:59:25 +00:00
|
|
|
if (!this->wp->IsInUse()) return this->wp->xy;
|
|
|
|
|
|
|
|
TileArea ta;
|
|
|
|
this->wp->GetTileArea(&ta, this->vt == VEH_TRAIN ? STATION_WAYPOINT : STATION_BUOY);
|
|
|
|
return ta.GetCenterTile();
|
2010-10-23 20:39:21 +00:00
|
|
|
}
|
2008-08-20 01:29:05 +00:00
|
|
|
|
|
|
|
public:
|
2011-05-01 19:51:52 +00:00
|
|
|
/**
|
|
|
|
* Construct the window.
|
|
|
|
* @param desc The description of the window.
|
|
|
|
* @param window_number The window number, in this case the waypoint's ID.
|
|
|
|
*/
|
2013-05-26 19:23:42 +00:00
|
|
|
WaypointWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
|
2008-08-20 01:29:05 +00:00
|
|
|
{
|
2009-08-01 15:53:23 +00:00
|
|
|
this->wp = Waypoint::Get(window_number);
|
2009-07-22 08:59:57 +00:00
|
|
|
this->vt = (wp->string_id == STR_SV_STNAME_WAYPOINT) ? VEH_TRAIN : VEH_SHIP;
|
2009-07-21 16:30:01 +00:00
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
this->CreateNestedTree();
|
2009-08-01 17:46:31 +00:00
|
|
|
if (this->vt == VEH_TRAIN) {
|
2011-12-16 16:25:34 +00:00
|
|
|
this->GetWidget<NWidgetCore>(WID_W_SHOW_VEHICLES)->SetDataTip(STR_TRAIN, STR_STATION_VIEW_SCHEDULED_TRAINS_TOOLTIP);
|
|
|
|
this->GetWidget<NWidgetCore>(WID_W_CENTER_VIEW)->tool_tip = STR_WAYPOINT_VIEW_CENTER_TOOLTIP;
|
|
|
|
this->GetWidget<NWidgetCore>(WID_W_RENAME)->tool_tip = STR_WAYPOINT_VIEW_CHANGE_WAYPOINT_NAME;
|
2009-08-01 17:46:31 +00:00
|
|
|
}
|
2013-05-26 19:23:42 +00:00
|
|
|
this->FinishInitNested(window_number);
|
2008-08-20 01:29:05 +00:00
|
|
|
|
2014-10-21 19:16:47 +00:00
|
|
|
this->owner = this->wp->owner;
|
2011-12-15 19:54:23 +00:00
|
|
|
this->flags |= WF_DISABLE_VP_SCROLL;
|
2010-06-15 22:48:50 +00:00
|
|
|
|
2011-12-16 16:25:34 +00:00
|
|
|
NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_W_VIEWPORT);
|
2022-09-04 06:55:03 +00:00
|
|
|
nvp->InitializeViewport(this, this->GetCenterTile(), ScaleZoomGUI(ZOOM_LVL_VIEWPORT));
|
2009-07-21 16:30:01 +00:00
|
|
|
|
2009-08-01 15:53:23 +00:00
|
|
|
this->OnInvalidateData(0);
|
2008-08-20 01:29:05 +00:00
|
|
|
}
|
|
|
|
|
2023-10-13 11:59:15 +00:00
|
|
|
void Close([[maybe_unused]] int data = 0) override
|
2010-06-10 23:52:09 +00:00
|
|
|
{
|
2021-05-17 13:46:38 +00:00
|
|
|
CloseWindowById(GetWindowClassForVehicleType(this->vt), VehicleListIdentifier(VL_STATION_LIST, this->vt, this->owner, this->window_number).Pack(), false);
|
2023-05-26 11:45:18 +00:00
|
|
|
SetViewportCatchmentWaypoint(Waypoint::Get(this->window_number), false);
|
2021-05-15 21:12:25 +00:00
|
|
|
this->Window::Close();
|
2010-06-10 23:52:09 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 07:49:37 +00:00
|
|
|
void SetStringParameters(int widget) const override
|
2008-08-20 01:29:05 +00:00
|
|
|
{
|
2011-12-16 16:25:34 +00:00
|
|
|
if (widget == WID_W_CAPTION) SetDParam(0, this->wp->index);
|
2009-08-01 15:53:23 +00:00
|
|
|
}
|
2009-02-26 14:10:57 +00:00
|
|
|
|
2023-05-26 11:45:18 +00:00
|
|
|
void OnPaint() override
|
|
|
|
{
|
|
|
|
extern const Waypoint *_viewport_highlight_waypoint;
|
|
|
|
this->SetWidgetDisabledState(WID_W_CATCHMENT, !this->wp->IsInUse());
|
|
|
|
this->SetWidgetLoweredState(WID_W_CATCHMENT, _viewport_highlight_waypoint == this->wp);
|
|
|
|
|
|
|
|
this->DrawWidgets();
|
|
|
|
}
|
|
|
|
|
2023-09-16 20:20:53 +00:00
|
|
|
void OnClick([[maybe_unused]] Point pt, int widget, [[maybe_unused]] int click_count) override
|
2008-08-20 01:29:05 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
2011-12-16 16:25:34 +00:00
|
|
|
case WID_W_CENTER_VIEW: // scroll to location
|
2008-08-20 01:29:05 +00:00
|
|
|
if (_ctrl_pressed) {
|
2020-06-29 01:38:29 +00:00
|
|
|
ShowExtraViewportWindow(this->GetCenterTile());
|
2008-08-20 01:29:05 +00:00
|
|
|
} else {
|
2010-10-23 20:39:21 +00:00
|
|
|
ScrollMainWindowToTile(this->GetCenterTile());
|
2008-08-20 01:29:05 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-12-16 16:25:34 +00:00
|
|
|
case WID_W_RENAME: // rename
|
2008-08-20 01:29:05 +00:00
|
|
|
SetDParam(0, this->wp->index);
|
2011-04-17 18:42:17 +00:00
|
|
|
ShowQueryString(STR_WAYPOINT_NAME, STR_EDIT_WAYPOINT_NAME, MAX_LENGTH_STATION_NAME_CHARS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS);
|
2008-08-20 01:29:05 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 16:25:34 +00:00
|
|
|
case WID_W_SHOW_VEHICLES: // show list of vehicles having this waypoint in their orders
|
2012-10-07 12:14:39 +00:00
|
|
|
ShowVehicleListWindow(this->wp->owner, this->vt, this->wp->index);
|
2008-08-20 01:29:05 +00:00
|
|
|
break;
|
2023-05-26 11:45:18 +00:00
|
|
|
|
|
|
|
case WID_W_CATCHMENT:
|
|
|
|
SetViewportCatchmentWaypoint(Waypoint::Get(this->window_number), !this->IsWidgetLowered(WID_W_CATCHMENT));
|
|
|
|
break;
|
2008-08-20 01:29:05 +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
|
2008-08-23 16:34:05 +00:00
|
|
|
{
|
2011-03-13 21:31:29 +00:00
|
|
|
if (!gui_scope) return;
|
2009-08-01 15:53:23 +00:00
|
|
|
/* You can only change your own waypoints */
|
2011-12-16 16:25:34 +00:00
|
|
|
this->SetWidgetDisabledState(WID_W_RENAME, !this->wp->IsInUse() || (this->wp->owner != _local_company && this->wp->owner != OWNER_NONE));
|
2009-08-01 15:53:23 +00:00
|
|
|
/* Disable the widget for waypoints with no use */
|
2011-12-16 16:25:34 +00:00
|
|
|
this->SetWidgetDisabledState(WID_W_SHOW_VEHICLES, !this->wp->IsInUse());
|
2009-08-01 15:53:23 +00:00
|
|
|
|
2010-10-23 20:39:21 +00:00
|
|
|
ScrollWindowToTile(this->GetCenterTile(), this, true);
|
2008-08-23 16:34:05 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 07:49:37 +00:00
|
|
|
void OnResize() override
|
2009-11-24 21:13:36 +00:00
|
|
|
{
|
2019-04-10 21:07:06 +00:00
|
|
|
if (this->viewport != nullptr) {
|
2011-12-16 16:25:34 +00:00
|
|
|
NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_W_VIEWPORT);
|
2009-11-24 21:13:36 +00:00
|
|
|
nvp->UpdateViewportCoordinates(this);
|
2010-09-16 16:14:30 +00:00
|
|
|
this->wp->UpdateVirtCoord();
|
2010-10-23 20:51:48 +00:00
|
|
|
|
|
|
|
ScrollWindowToTile(this->GetCenterTile(), this, true); // Re-center viewport.
|
2009-11-24 21:13:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 07:49:37 +00:00
|
|
|
void OnQueryTextFinished(char *str) override
|
2008-08-20 01:29:05 +00:00
|
|
|
{
|
2019-04-10 21:07:06 +00:00
|
|
|
if (str == nullptr) return;
|
2008-09-15 19:02:50 +00:00
|
|
|
|
2021-11-14 15:39:17 +00:00
|
|
|
Command<CMD_RENAME_WAYPOINT>::Post(STR_ERROR_CAN_T_CHANGE_WAYPOINT_NAME, this->window_number, str);
|
2008-08-20 01:29:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2011-05-01 19:14:12 +00:00
|
|
|
/** The widgets of the waypoint view. */
|
2009-03-25 21:38:05 +00:00
|
|
|
static const NWidgetPart _nested_waypoint_view_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
|
2020-12-27 21:45:58 +00:00
|
|
|
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_W_RENAME), SetMinimalSize(12, 14), SetDataTip(SPR_RENAME, STR_BUOY_VIEW_CHANGE_BUOY_NAME),
|
2011-12-16 16:25:34 +00:00
|
|
|
NWidget(WWT_CAPTION, COLOUR_GREY, WID_W_CAPTION), SetDataTip(STR_WAYPOINT_VIEW_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
2020-12-27 21:45:58 +00:00
|
|
|
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_W_CENTER_VIEW), SetMinimalSize(12, 14), SetDataTip(SPR_GOTO_LOCATION, STR_BUOY_VIEW_CENTER_TOOLTIP),
|
2009-12-21 16:24:29 +00:00
|
|
|
NWidget(WWT_SHADEBOX, COLOUR_GREY),
|
2013-05-26 19:30:07 +00:00
|
|
|
NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_STICKYBOX, COLOUR_GREY),
|
2009-03-25 21:38:05 +00:00
|
|
|
EndContainer(),
|
2009-11-24 21:13:36 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY),
|
|
|
|
NWidget(WWT_INSET, COLOUR_GREY), SetPadding(2, 2, 2, 2),
|
2021-05-08 20:01:16 +00:00
|
|
|
NWidget(NWID_VIEWPORT, COLOUR_GREY, WID_W_VIEWPORT), SetMinimalSize(256, 88), SetResize(1, 1),
|
2009-03-25 21:38:05 +00:00
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2023-05-26 11:45:18 +00:00
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_W_CATCHMENT), SetMinimalSize(50, 12), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT),
|
2011-12-16 16:25:34 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_W_SHOW_VEHICLES), SetMinimalSize(15, 12), SetDataTip(STR_SHIP, STR_STATION_VIEW_SCHEDULED_SHIPS_TOOLTIP),
|
2009-11-24 21:13:36 +00:00
|
|
|
NWidget(WWT_RESIZEBOX, COLOUR_GREY),
|
2009-03-25 21:38:05 +00:00
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2011-05-01 19:14:12 +00:00
|
|
|
/** The description of the waypoint view. */
|
2023-11-02 19:33:01 +00:00
|
|
|
static WindowDesc _waypoint_view_desc(__FILE__, __LINE__,
|
2013-05-26 19:25:01 +00:00
|
|
|
WDP_AUTO, "view_waypoint", 260, 118,
|
2008-08-20 01:29:05 +00:00
|
|
|
WC_WAYPOINT_VIEW, WC_NONE,
|
2012-11-11 16:10:43 +00:00
|
|
|
0,
|
2023-09-03 20:54:13 +00:00
|
|
|
std::begin(_nested_waypoint_view_widgets), std::end(_nested_waypoint_view_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2008-08-20 01:29:05 +00:00
|
|
|
|
2011-05-01 19:14:12 +00:00
|
|
|
/**
|
|
|
|
* Show the window for the given waypoint.
|
|
|
|
* @param wp The waypoint to show the window for.
|
|
|
|
*/
|
2008-08-20 01:29:05 +00:00
|
|
|
void ShowWaypointWindow(const Waypoint *wp)
|
|
|
|
{
|
|
|
|
AllocateWindowDescFront<WaypointWindow>(&_waypoint_view_desc, wp->index);
|
|
|
|
}
|