2008-08-20 01:29:05 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
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"
|
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
|
|
|
|
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.
|
|
|
|
*/
|
2009-08-01 15:53:23 +00:00
|
|
|
WaypointWindow(const WindowDesc *desc, WindowNumber window_number) : Window()
|
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
|
|
|
|
2009-08-01 15:53:23 +00:00
|
|
|
this->CreateNestedTree(desc);
|
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
|
|
|
}
|
2009-08-01 15:53:23 +00:00
|
|
|
this->FinishInitNested(desc, window_number);
|
2008-08-20 01:29:05 +00:00
|
|
|
|
2010-06-15 22:48:50 +00:00
|
|
|
if (this->wp->owner != OWNER_NONE) 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);
|
2011-11-24 18:55:56 +00:00
|
|
|
nvp->InitializeViewport(this, this->GetCenterTile(), 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
|
|
|
}
|
|
|
|
|
2010-06-10 23:52:09 +00:00
|
|
|
~WaypointWindow()
|
|
|
|
{
|
|
|
|
Owner owner = this->owner;
|
2011-02-23 18:39:56 +00:00
|
|
|
|
|
|
|
/* Buoys have no owner and can be used by everyone. Show only 'our' vehicles */
|
2010-06-10 23:52:09 +00:00
|
|
|
if (!Company::IsValidID(owner)) owner = _local_company;
|
2011-02-23 18:39:56 +00:00
|
|
|
|
|
|
|
/* Well, spectators otoh */
|
|
|
|
if (Company::IsValidID(owner)) DeleteWindowById(GetWindowClassForVehicleType(this->vt), VehicleListIdentifier(VL_STATION_LIST, this->vt, owner, this->window_number).Pack(), false);
|
2010-06-10 23:52:09 +00:00
|
|
|
}
|
|
|
|
|
2009-08-01 15:53:23 +00:00
|
|
|
virtual void SetStringParameters(int widget) const
|
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
|
|
|
|
2010-01-30 18:34:48 +00:00
|
|
|
virtual void OnClick(Point pt, int widget, int click_count)
|
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) {
|
2010-10-23 20:39:21 +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
|
2010-06-11 00:18:28 +00:00
|
|
|
ShowVehicleListWindow(this->owner, this->vt, this->wp->index);
|
2008-08-20 01:29:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
|
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
|
|
|
}
|
|
|
|
|
2009-11-24 21:13:36 +00:00
|
|
|
virtual void OnResize()
|
|
|
|
{
|
|
|
|
if (this->viewport != NULL) {
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-20 01:29:05 +00:00
|
|
|
virtual void OnQueryTextFinished(char *str)
|
|
|
|
{
|
2008-09-15 19:02:50 +00:00
|
|
|
if (str == NULL) return;
|
|
|
|
|
2009-08-05 17:59:21 +00:00
|
|
|
DoCommandP(0, this->window_number, 0, CMD_RENAME_WAYPOINT | CMD_MSG(STR_ERROR_CAN_T_CHANGE_WAYPOINT_NAME), NULL, 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),
|
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),
|
2009-12-21 16:24:29 +00:00
|
|
|
NWidget(WWT_SHADEBOX, 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),
|
2011-12-16 16:25:34 +00:00
|
|
|
NWidget(NWID_VIEWPORT, COLOUR_GREY, WID_W_VIEWPORT), SetMinimalSize(256, 88), SetPadding(1, 1, 1, 1), SetResize(1, 1),
|
2009-03-25 21:38:05 +00:00
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2011-12-16 16:25:34 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_W_CENTER_VIEW), SetMinimalSize(100, 12), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_BUTTON_LOCATION, STR_BUOY_VIEW_CENTER_TOOLTIP),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_W_RENAME), SetMinimalSize(100, 12), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_BUTTON_RENAME, STR_BUOY_VIEW_CHANGE_BUOY_NAME),
|
|
|
|
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. */
|
2009-03-15 15:12:06 +00:00
|
|
|
static const WindowDesc _waypoint_view_desc(
|
2009-11-28 14:42:35 +00:00
|
|
|
WDP_AUTO, 260, 118,
|
2008-08-20 01:29:05 +00:00
|
|
|
WC_WAYPOINT_VIEW, WC_NONE,
|
2009-11-24 17:28:29 +00:00
|
|
|
WDF_UNCLICK_BUTTONS,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_waypoint_view_widgets, lengthof(_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);
|
|
|
|
}
|