src/waypoint_gui.cpp
author belugas
Wed, 20 Aug 2008 15:27:22 +0000
changeset 9953 42938fdeb0dc
child 9970 8608ca115990
permissions -rw-r--r--
(svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
9953
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
     1
/* $Id$ */
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
     2
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
     3
/** @file waypoint_gui.cpp Handling of waypoints gui. */
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
     4
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
     5
#include "stdafx.h"
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
     6
#include "openttd.h"
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
     7
#include "window_gui.h"
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
     8
#include "gui.h"
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
     9
#include "textbuf_gui.h"
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    10
#include "vehicle_gui.h"
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    11
#include "waypoint.h"
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    12
#include "viewport_func.h"
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    13
#include "string_func.h"
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    14
#include "strings_func.h"
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    15
#include "gfx_func.h"
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    16
#include "command_func.h"
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    17
#include "functions.h"
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    18
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    19
#include "table/strings.h"
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    20
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    21
struct WaypointWindow : Window {
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    22
private:
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    23
	Waypoint *wp;
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    24
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    25
	enum WaypointViewWidget {
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    26
		WAYPVW_CLOSEBOX = 0,
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    27
		WAYPVW_CAPTION,
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    28
		WAYPVW_STICKY,
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    29
		WAYPVW_VIEWPORTPANEL,
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    30
		WAYPVW_SPACER,
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    31
		WAYPVW_CENTERVIEW,
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    32
		WAYPVW_RENAME,
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    33
		WAYPVW_SHOW_TRAINS,
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    34
	};
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    35
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    36
public:
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    37
	WaypointWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    38
	{
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    39
		this->wp = GetWaypoint(this->window_number);
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    40
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    41
		this->flags4 |= WF_DISABLE_VP_SCROLL;
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    42
		InitializeWindowViewport(this, 3, 17, 254, 86, this->wp->xy, ZOOM_LVL_MIN);
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    43
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    44
		this->FindWindowPlacementAndResize(desc);
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    45
	}
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    46
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    47
	virtual void OnPaint()
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    48
	{
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    49
		/* You can only change your own waypoints */
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    50
		this->SetWidgetDisabledState(WAYPVW_RENAME, !CheckTileOwnership(this->wp->xy));
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    51
		SetDParam(0, this->wp->index);
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    52
		this->DrawWidgets();
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    53
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    54
		this->DrawViewport();
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    55
	}
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    56
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    57
	virtual void OnClick(Point pt, int widget)
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    58
	{
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    59
		switch (widget) {
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    60
			case WAYPVW_CENTERVIEW: /* scroll to location */
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    61
				if (_ctrl_pressed) {
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    62
					ShowExtraViewPortWindow(this->wp->xy);
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    63
				} else {
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    64
					ScrollMainWindowToTile(this->wp->xy);
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    65
				}
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    66
				break;
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    67
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    68
			case WAYPVW_RENAME: /* rename */
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    69
				SetDParam(0, this->wp->index);
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    70
				ShowQueryString(STR_WAYPOINT_RAW, STR_EDIT_WAYPOINT_NAME, MAX_LENGTH_WAYPOINT_NAME_BYTES, MAX_LENGTH_WAYPOINT_NAME_PIXELS, this, CS_ALPHANUMERAL);
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    71
				break;
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    72
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    73
			case WAYPVW_SHOW_TRAINS: /* show list of trains having this waypoint in their orders*/
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    74
				ShowVehicleListWindow(this->wp);
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    75
				break;
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    76
		}
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    77
	}
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    78
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    79
	virtual void OnQueryTextFinished(char *str)
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    80
	{
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    81
		if (!StrEmpty(str)) {
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    82
			_cmd_text = str;
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    83
			DoCommandP(0, this->window_number, 0, NULL, CMD_RENAME_WAYPOINT | CMD_MSG(STR_CANT_CHANGE_WAYPOINT_NAME));
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    84
		}
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    85
	}
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    86
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    87
};
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    88
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    89
static const Widget _waypoint_view_widgets[] = {
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    90
{   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_GREY,     0,    10,     0,    13, STR_00C5,              STR_018B_CLOSE_WINDOW},                 // WAYPVW_CLOSEBOX
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    91
{    WWT_CAPTION,   RESIZE_NONE,  COLOUR_GREY,    11,   247,     0,    13, STR_WAYPOINT_VIEWPORT, STR_018C_WINDOW_TITLE_DRAG_THIS},       // WAYPVW_CAPTION
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    92
{  WWT_STICKYBOX,   RESIZE_NONE,  COLOUR_GREY,   248,   259,     0,    13, 0x0,                   STR_STICKY_BUTTON},                     // WAYPVW_STICKY
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    93
{      WWT_PANEL,   RESIZE_NONE,  COLOUR_GREY,     0,   259,    14,   105, 0x0,                   STR_NULL},                              // WAYPVW_VIEWPORTPANEL
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    94
{      WWT_INSET,   RESIZE_NONE,  COLOUR_GREY,     2,   257,    16,   103, 0x0,                   STR_NULL},                              // WAYPVW_SPACER
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    95
{ WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,     0,   121,   106,   117, STR_00E4_LOCATION,     STR_3053_CENTER_MAIN_VIEW_ON_STATION},  // WAYPVW_CENTERVIEW
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    96
{ WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,   122,   244,   106,   117, STR_0130_RENAME,       STR_CHANGE_WAYPOINT_NAME},              // WAYPVW_RENAME
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    97
{ WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,   245,   259,   106,   117, STR_TRAIN,             STR_SCHEDULED_TRAINS_TIP },             // WAYPVW_SHOW_TRAINS
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    98
{   WIDGETS_END},
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    99
};
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
   100
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
   101
static const WindowDesc _waypoint_view_desc = {
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
   102
	WDP_AUTO, WDP_AUTO, 260, 118, 260, 118,
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
   103
	WC_WAYPOINT_VIEW, WC_NONE,
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
   104
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
   105
	_waypoint_view_widgets,
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
   106
};
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
   107
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
   108
void ShowWaypointWindow(const Waypoint *wp)
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
   109
{
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
   110
	AllocateWindowDescFront<WaypointWindow>(&_waypoint_view_desc, wp->index);
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
   111
}