src/waypoint_gui.cpp
author Tero Marttila <terom@fixme.fi>
Fri, 19 Dec 2008 02:25:44 +0200
branchterom-mini
changeset 10442 7089fa402bfd
parent 10148 ad8e8a65f6a2
permissions -rw-r--r--
mini-branch
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"
10120
f158a34ecdea (svn r14304) -Fix (r14104): waypoint train list wasn't closed with the waypoint window (crashes since r14296)
smatz
parents: 9986
diff changeset
    18
#include "window_func.h"
9953
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    19
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    20
#include "table/strings.h"
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    21
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    22
struct WaypointWindow : Window {
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    23
private:
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    24
	Waypoint *wp;
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    25
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    26
	enum WaypointViewWidget {
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    27
		WAYPVW_CLOSEBOX = 0,
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    28
		WAYPVW_CAPTION,
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    29
		WAYPVW_STICKY,
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    30
		WAYPVW_VIEWPORTPANEL,
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    31
		WAYPVW_SPACER,
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    32
		WAYPVW_CENTERVIEW,
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    33
		WAYPVW_RENAME,
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    34
		WAYPVW_SHOW_TRAINS,
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
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    37
public:
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    38
	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
    39
	{
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    40
		this->wp = GetWaypoint(this->window_number);
9978
4c10b20eaf54 (svn r14135) -Codechange: Add owner to waypoints. Previously, it was guessed from rail underneath it.
belugas
parents: 9970
diff changeset
    41
		this->caption_color = this->wp->owner;
9953
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    42
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    43
		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
    44
		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
    45
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    46
		this->FindWindowPlacementAndResize(desc);
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    47
	}
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    48
10120
f158a34ecdea (svn r14304) -Fix (r14104): waypoint train list wasn't closed with the waypoint window (crashes since r14296)
smatz
parents: 9986
diff changeset
    49
	~WaypointWindow()
f158a34ecdea (svn r14304) -Fix (r14104): waypoint train list wasn't closed with the waypoint window (crashes since r14296)
smatz
parents: 9986
diff changeset
    50
	{
f158a34ecdea (svn r14304) -Fix (r14104): waypoint train list wasn't closed with the waypoint window (crashes since r14296)
smatz
parents: 9986
diff changeset
    51
		DeleteWindowById(WC_TRAINS_LIST, (this->window_number << 16) | (VEH_TRAIN << 11) | VLW_WAYPOINT_LIST | this->wp->owner);
f158a34ecdea (svn r14304) -Fix (r14104): waypoint train list wasn't closed with the waypoint window (crashes since r14296)
smatz
parents: 9986
diff changeset
    52
	}
f158a34ecdea (svn r14304) -Fix (r14104): waypoint train list wasn't closed with the waypoint window (crashes since r14296)
smatz
parents: 9986
diff changeset
    53
9953
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    54
	virtual void OnPaint()
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
		/* You can only change your own waypoints */
9978
4c10b20eaf54 (svn r14135) -Codechange: Add owner to waypoints. Previously, it was guessed from rail underneath it.
belugas
parents: 9970
diff changeset
    57
		this->SetWidgetDisabledState(WAYPVW_RENAME, !CheckOwnership(this->wp->owner));
9953
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    58
		SetDParam(0, this->wp->index);
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    59
		this->DrawWidgets();
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    60
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    61
		this->DrawViewport();
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    62
	}
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    63
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    64
	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
    65
	{
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    66
		switch (widget) {
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    67
			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
    68
				if (_ctrl_pressed) {
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    69
					ShowExtraViewPortWindow(this->wp->xy);
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    70
				} else {
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    71
					ScrollMainWindowToTile(this->wp->xy);
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
				break;
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    74
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    75
			case WAYPVW_RENAME: /* rename */
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    76
				SetDParam(0, this->wp->index);
10148
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10145
diff changeset
    77
				ShowQueryString(STR_WAYPOINT_RAW, STR_EDIT_WAYPOINT_NAME, MAX_LENGTH_WAYPOINT_NAME_BYTES, MAX_LENGTH_WAYPOINT_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT);
9953
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    78
				break;
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    79
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    80
			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
    81
				ShowVehicleListWindow(this->wp);
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    82
				break;
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    83
		}
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
9986
4ee5b226abad (svn r14143) -Codechange: Recenter viewport of waypoint window when relocating the waypoint.
frosch
parents: 9978
diff changeset
    86
	virtual void OnInvalidateData(int data)
4ee5b226abad (svn r14143) -Codechange: Recenter viewport of waypoint window when relocating the waypoint.
frosch
parents: 9978
diff changeset
    87
	{
4ee5b226abad (svn r14143) -Codechange: Recenter viewport of waypoint window when relocating the waypoint.
frosch
parents: 9978
diff changeset
    88
		int x = TileX(this->wp->xy) * TILE_SIZE;
4ee5b226abad (svn r14143) -Codechange: Recenter viewport of waypoint window when relocating the waypoint.
frosch
parents: 9978
diff changeset
    89
		int y = TileY(this->wp->xy) * TILE_SIZE;
4ee5b226abad (svn r14143) -Codechange: Recenter viewport of waypoint window when relocating the waypoint.
frosch
parents: 9978
diff changeset
    90
		ScrollWindowTo(x,y, this);
4ee5b226abad (svn r14143) -Codechange: Recenter viewport of waypoint window when relocating the waypoint.
frosch
parents: 9978
diff changeset
    91
	}
4ee5b226abad (svn r14143) -Codechange: Recenter viewport of waypoint window when relocating the waypoint.
frosch
parents: 9978
diff changeset
    92
9953
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    93
	virtual void OnQueryTextFinished(char *str)
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
    94
	{
10148
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10145
diff changeset
    95
		if (str == NULL) return;
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10145
diff changeset
    96
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10145
diff changeset
    97
		_cmd_text = str;
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10145
diff changeset
    98
		DoCommandP(0, this->window_number, 0, NULL, CMD_RENAME_WAYPOINT | CMD_MSG(STR_CANT_CHANGE_WAYPOINT_NAME));
9953
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
};
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
   102
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
   103
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
   104
{   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
   105
{    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
   106
{  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
   107
{      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
   108
{      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
   109
{ 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
   110
{ 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
   111
{ 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
   112
{   WIDGETS_END},
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
   113
};
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
   114
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
   115
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
   116
	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
   117
	WC_WAYPOINT_VIEW, WC_NONE,
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
   118
	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
   119
	_waypoint_view_widgets,
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
   120
};
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
   121
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
   122
void ShowWaypointWindow(const Waypoint *wp)
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
   123
{
9970
8608ca115990 (svn r14127) -Feature(ette): Give the the player's colour to the waypoint window been shown
belugas
parents: 9953
diff changeset
   124
	if (!wp->IsValid()) return;  // little safety
9953
42938fdeb0dc (svn r14108) -Fix(r14104): Give a more consistent naming of the new gui file
belugas
parents:
diff changeset
   125
	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
   126
}