src/group_gui.cpp
author rubidium
Sat, 21 Jun 2008 13:40:17 +0000
branchnoai
changeset 11044 097ea3e7ec56
parent 10776 07203fc29812
permissions -rw-r--r--
(svn r13600) [NoAI] -Sync: with trunk r13508:13599.
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
     1
/* $Id$ */
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
     2
10455
22c441f5adf9 (svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents: 10249
diff changeset
     3
/** @file group_gui.cpp GUI for the group window. */
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
     4
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
     5
#include "stdafx.h"
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
     6
#include "openttd.h"
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
     7
#include "gui.h"
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
     8
#include "window_gui.h"
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
     9
#include "textbuf_gui.h"
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    10
#include "command_func.h"
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    11
#include "vehicle_gui.h"
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    12
#include "train.h"
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    13
#include "group.h"
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    14
#include "debug.h"
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    15
#include "strings_func.h"
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    16
#include "core/alloc_func.hpp"
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    17
#include "window_func.h"
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    18
#include "vehicle_func.h"
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    19
#include "autoreplace_gui.h"
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    20
#include "string_func.h"
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    21
#include "viewport_func.h"
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    22
#include "gfx_func.h"
9724
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
    23
#include "player_func.h"
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
    24
#include "widgets/dropdown_type.h"
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
    25
#include "widgets/dropdown_func.h"
10455
22c441f5adf9 (svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents: 10249
diff changeset
    26
#include "tilehighlight_func.h"
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    27
9724
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
    28
#include "table/strings.h"
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
    29
#include "table/sprites.h"
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    30
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
    31
typedef GUIList<const Group*> GUIGroupList;
9837
c9ec4f82e0d0 (svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents: 9826
diff changeset
    32
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    33
enum GroupListWidgets {
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    34
	GRP_WIDGET_CLOSEBOX = 0,
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    35
	GRP_WIDGET_CAPTION,
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    36
	GRP_WIDGET_STICKY,
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    37
	GRP_WIDGET_EMPTY_TOP_LEFT,
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    38
	GRP_WIDGET_ALL_VEHICLES,
9686
d3c195c226f9 (svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents: 9631
diff changeset
    39
	GRP_WIDGET_DEFAULT_VEHICLES,
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    40
	GRP_WIDGET_LIST_GROUP,
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    41
	GRP_WIDGET_LIST_GROUP_SCROLLBAR,
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    42
	GRP_WIDGET_SORT_BY_ORDER,
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    43
	GRP_WIDGET_SORT_BY_DROPDOWN,
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    44
	GRP_WIDGET_EMPTY_TOP_RIGHT,
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    45
	GRP_WIDGET_LIST_VEHICLE,
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    46
	GRP_WIDGET_LIST_VEHICLE_SCROLLBAR,
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    47
	GRP_WIDGET_CREATE_GROUP,
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    48
	GRP_WIDGET_DELETE_GROUP,
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    49
	GRP_WIDGET_RENAME_GROUP,
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    50
	GRP_WIDGET_EMPTY1,
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    51
	GRP_WIDGET_REPLACE_PROTECTION,
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    52
	GRP_WIDGET_EMPTY2,
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    53
	GRP_WIDGET_AVAILABLE_VEHICLES,
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    54
	GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN,
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    55
	GRP_WIDGET_STOP_ALL,
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    56
	GRP_WIDGET_START_ALL,
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    57
	GRP_WIDGET_EMPTY_BOTTOM_RIGHT,
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    58
	GRP_WIDGET_RESIZE,
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    59
};
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    60
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
    61
enum GroupActionListFunction {
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
    62
	GALF_REPLACE,
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
    63
	GALF_SERVICE,
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
    64
	GALF_DEPOT,
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
    65
	GALF_ADD_SHARED,
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
    66
	GALF_REMOVE_ALL,
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
    67
};
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
    68
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
    69
/**
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
    70
 * Update/redraw the group action dropdown
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
    71
 * @param w   the window the dropdown belongs to
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
    72
 * @param gid the currently selected group in the window
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
    73
 */
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
    74
static void ShowGroupActionDropdown(Window *w, GroupID gid)
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
    75
{
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
    76
	DropDownList *list = new DropDownList();
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
    77
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
    78
	list->push_back(new DropDownListStringItem(STR_REPLACE_VEHICLES,    GALF_REPLACE, false));
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
    79
	list->push_back(new DropDownListStringItem(STR_SEND_FOR_SERVICING,  GALF_SERVICE, false));
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
    80
	list->push_back(new DropDownListStringItem(STR_SEND_TRAIN_TO_DEPOT, GALF_DEPOT,   false));
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
    81
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
    82
	if (IsValidGroupID(gid)) {
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
    83
		list->push_back(new DropDownListStringItem(STR_GROUP_ADD_SHARED_VEHICLE,  GALF_ADD_SHARED, false));
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
    84
		list->push_back(new DropDownListStringItem(STR_GROUP_REMOVE_ALL_VEHICLES, GALF_REMOVE_ALL, false));
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
    85
	}
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
    86
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
    87
	ShowDropDownList(w, list, 0, GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN);
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
    88
}
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
    89
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    90
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    91
static const Widget _group_widgets[] = {
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    92
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,             STR_018B_CLOSE_WINDOW},
9694
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9686
diff changeset
    93
{    WWT_CAPTION,  RESIZE_RIGHT,    14,    11,   447,     0,    13, 0x0,                  STR_018C_WINDOW_TITLE_DRAG_THIS},
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9686
diff changeset
    94
{  WWT_STICKYBOX,     RESIZE_LR,    14,   448,   459,     0,    13, 0x0,                  STR_STICKY_BUTTON},
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
    95
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   200,    14,    25, 0x0,                  STR_NULL},
9686
d3c195c226f9 (svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents: 9631
diff changeset
    96
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   200,    26,    38, 0x0,                  STR_NULL},
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9703
diff changeset
    97
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   200,    39,    51, 0x0,                  STR_NULL},
9694
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9686
diff changeset
    98
{     WWT_MATRIX, RESIZE_BOTTOM,    14,     0,   188,    52,   168, 0x701,                STR_GROUPS_CLICK_ON_GROUP_FOR_TIP},
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9703
diff changeset
    99
{  WWT_SCROLLBAR, RESIZE_BOTTOM,    14,   189,   200,    52,   168, 0x0,                  STR_0190_SCROLL_BAR_SCROLLS_LIST},
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   100
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   201,   281,    14,    25, STR_SORT_BY,          STR_SORT_ORDER_TIP},
9724
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
   101
{   WWT_DROPDOWN,   RESIZE_NONE,    14,   282,   447,    14,    25, 0x0,                  STR_SORT_CRITERIA_TIP},
9694
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9686
diff changeset
   102
{      WWT_PANEL,  RESIZE_RIGHT,    14,   448,   459,    14,    25, 0x0,                  STR_NULL},
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9686
diff changeset
   103
{     WWT_MATRIX,     RESIZE_RB,    14,   201,   447,    26,   181, 0x701,                STR_NULL},
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9686
diff changeset
   104
{ WWT_SCROLL2BAR,    RESIZE_LRB,    14,   448,   459,    26,   181, 0x0,                  STR_0190_SCROLL_BAR_SCROLLS_LIST},
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9686
diff changeset
   105
{ WWT_PUSHIMGBTN,     RESIZE_TB,    14,     0,    23,   169,   193, 0x0,                  STR_GROUP_CREATE_TIP},
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9686
diff changeset
   106
{ WWT_PUSHIMGBTN,     RESIZE_TB,    14,    24,    47,   169,   193, 0x0,                  STR_GROUP_DELETE_TIP},
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9686
diff changeset
   107
{ WWT_PUSHIMGBTN,     RESIZE_TB,    14,    48,    71,   169,   193, 0x0,                  STR_GROUP_RENAME_TIP},
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9686
diff changeset
   108
{      WWT_PANEL,     RESIZE_TB,    14,    72,   164,   169,   193, 0x0,                  STR_NULL},
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9686
diff changeset
   109
{ WWT_PUSHIMGBTN,     RESIZE_TB,    14,   165,   188,   169,   193, 0x0,                  STR_GROUP_REPLACE_PROTECTION_TIP},
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9686
diff changeset
   110
{      WWT_PANEL,     RESIZE_TB,    14,   189,   200,   169,   193, 0x0,                  STR_NULL},
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9686
diff changeset
   111
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,   201,   306,   182,   193, 0x0,                  STR_AVAILABLE_ENGINES_TIP},
9724
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
   112
{   WWT_DROPDOWN,     RESIZE_TB,    14,   307,   423,   182,   193, STR_MANAGE_LIST,      STR_MANAGE_LIST_TIP},
9694
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9686
diff changeset
   113
{ WWT_PUSHIMGBTN,     RESIZE_TB,    14,   424,   435,   182,   193, SPR_FLAG_VEH_STOPPED, STR_MASS_STOP_LIST_TIP},
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9686
diff changeset
   114
{ WWT_PUSHIMGBTN,     RESIZE_TB,    14,   436,   447,   182,   193, SPR_FLAG_VEH_RUNNING, STR_MASS_START_LIST_TIP},
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9686
diff changeset
   115
{      WWT_PANEL,    RESIZE_RTB,    14,   448,   447,   182,   193, 0x0,                  STR_NULL},
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9686
diff changeset
   116
{  WWT_RESIZEBOX,   RESIZE_LRTB,    14,   448,   459,   182,   193, 0x0,                  STR_RESIZE_BUTTON},
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   117
{   WIDGETS_END},
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   118
};
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   119
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   120
10776
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   121
class VehicleGroupWindow : public Window, public VehicleListBase {
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   122
private:
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   123
	GroupID group_sel;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   124
	VehicleID vehicle_sel;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   125
	GUIGroupList groups;
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   126
10776
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   127
	/**
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   128
	 * (Re)Build the group list.
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   129
	 *
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   130
	 * @param owner The owner of the window
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   131
	 */
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   132
	void BuildGroupList(PlayerID owner)
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   133
	{
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   134
		if (!this->groups.NeedRebuild()) return;
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   135
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   136
		this->groups.Clear();
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   137
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   138
		const Group *g;
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   139
		FOR_ALL_GROUPS(g) {
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   140
			if (g->owner == owner && g->vehicle_type == this->vehicle_type) {
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   141
				*this->groups.Append() = g;
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   142
			}
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   143
		}
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   144
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   145
		this->groups.Compact();
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   146
		this->groups.RebuildDone();
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   147
	}
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   148
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   149
	/** Sort the groups by their name */
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   150
	static int CDECL GroupNameSorter(const Group* const *a, const Group* const *b)
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   151
	{
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   152
		static const Group *last_group[2] = { NULL, NULL };
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   153
		static char         last_name[2][64] = { "", "" };
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   154
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   155
		if (*a != last_group[0]) {
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   156
			last_group[0] = *a;
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   157
			SetDParam(0, (*a)->index);
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   158
			GetString(last_name[0], STR_GROUP_NAME, lastof(last_name[0]));
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   159
		}
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   160
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   161
		if (*b != last_group[1]) {
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   162
			last_group[1] = *b;
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   163
			SetDParam(0, (*b)->index);
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   164
			GetString(last_name[1], STR_GROUP_NAME, lastof(last_name[1]));
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   165
		}
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   166
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   167
		int r = strcmp(last_name[0], last_name[1]); // sort by name
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   168
		if (r == 0) return (*a)->index - (*b)->index;
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   169
		return r;
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   170
	}
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   171
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   172
public:
10645
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   173
	VehicleGroupWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   174
	{
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   175
		const PlayerID owner = (PlayerID)GB(this->window_number, 0, 8);
10645
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   176
		this->vehicle_type = (VehicleType)GB(this->window_number, 11, 5);
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   177
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   178
		this->caption_color = owner;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   179
		this->resize.step_width = 1;
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   180
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   181
		switch (this->vehicle_type) {
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   182
			default: NOT_REACHED();
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   183
			case VEH_TRAIN:
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   184
			case VEH_ROAD:
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   185
				this->vscroll.cap = 9;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   186
				this->vscroll2.cap = 6;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   187
				this->resize.step_height = PLY_WND_PRC__SIZE_OF_ROW_SMALL;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   188
				break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   189
			case VEH_SHIP:
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   190
			case VEH_AIRCRAFT:
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   191
				this->vscroll.cap = 9;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   192
				this->vscroll2.cap = 4;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   193
				this->resize.step_height = PLY_WND_PRC__SIZE_OF_ROW_BIG2;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   194
				break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   195
		}
9724
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
   196
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   197
		this->widget[GRP_WIDGET_LIST_GROUP].data = (this->vscroll.cap << 8) + 1;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   198
		this->widget[GRP_WIDGET_LIST_VEHICLE].data = (this->vscroll2.cap << 8) + 1;
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   199
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   200
		switch (this->vehicle_type) {
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   201
			default: NOT_REACHED();
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   202
			case VEH_TRAIN:    this->sorting = &_sorting.train;    break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   203
			case VEH_ROAD:     this->sorting = &_sorting.roadveh;  break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   204
			case VEH_SHIP:     this->sorting = &_sorting.ship;     break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   205
			case VEH_AIRCRAFT: this->sorting = &_sorting.aircraft; break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   206
		}
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   207
11044
097ea3e7ec56 (svn r13600) [NoAI] -Sync: with trunk r13508:13599.
rubidium
parents: 10776
diff changeset
   208
		this->vehicles.SetListing(*this->sorting);
097ea3e7ec56 (svn r13600) [NoAI] -Sync: with trunk r13508:13599.
rubidium
parents: 10776
diff changeset
   209
		this->vehicles.ForceRebuild();
097ea3e7ec56 (svn r13600) [NoAI] -Sync: with trunk r13508:13599.
rubidium
parents: 10776
diff changeset
   210
		this->vehicles.NeedResort();
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   211
10776
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   212
		this->groups.ForceRebuild();
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   213
		this->groups.NeedResort();
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   214
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   215
		this->group_sel = ALL_GROUP;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   216
		this->vehicle_sel = INVALID_VEHICLE;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   217
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   218
		switch (this->vehicle_type) {
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   219
			case VEH_TRAIN:
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   220
				this->widget[GRP_WIDGET_LIST_VEHICLE].tooltips = STR_883D_TRAINS_CLICK_ON_TRAIN_FOR;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   221
				this->widget[GRP_WIDGET_AVAILABLE_VEHICLES].data = STR_AVAILABLE_TRAINS;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   222
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   223
				this->widget[GRP_WIDGET_CREATE_GROUP].data = SPR_GROUP_CREATE_TRAIN;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   224
				this->widget[GRP_WIDGET_RENAME_GROUP].data = SPR_GROUP_RENAME_TRAIN;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   225
				this->widget[GRP_WIDGET_DELETE_GROUP].data = SPR_GROUP_DELETE_TRAIN;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   226
				break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   227
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   228
			case VEH_ROAD:
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   229
				this->widget[GRP_WIDGET_LIST_VEHICLE].tooltips = STR_901A_ROAD_VEHICLES_CLICK_ON;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   230
				this->widget[GRP_WIDGET_AVAILABLE_VEHICLES].data = STR_AVAILABLE_ROAD_VEHICLES;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   231
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   232
				this->widget[GRP_WIDGET_CREATE_GROUP].data = SPR_GROUP_CREATE_ROADVEH;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   233
				this->widget[GRP_WIDGET_RENAME_GROUP].data = SPR_GROUP_RENAME_ROADVEH;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   234
				this->widget[GRP_WIDGET_DELETE_GROUP].data = SPR_GROUP_DELETE_ROADVEH;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   235
				break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   236
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   237
			case VEH_SHIP:
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   238
				this->widget[GRP_WIDGET_LIST_VEHICLE].tooltips = STR_9823_SHIPS_CLICK_ON_SHIP_FOR;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   239
				this->widget[GRP_WIDGET_AVAILABLE_VEHICLES].data = STR_AVAILABLE_SHIPS;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   240
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   241
				this->widget[GRP_WIDGET_CREATE_GROUP].data = SPR_GROUP_CREATE_SHIP;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   242
				this->widget[GRP_WIDGET_RENAME_GROUP].data = SPR_GROUP_RENAME_SHIP;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   243
				this->widget[GRP_WIDGET_DELETE_GROUP].data = SPR_GROUP_DELETE_SHIP;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   244
				break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   245
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   246
			case VEH_AIRCRAFT:
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   247
				this->widget[GRP_WIDGET_LIST_VEHICLE].tooltips = STR_A01F_AIRCRAFT_CLICK_ON_AIRCRAFT;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   248
				this->widget[GRP_WIDGET_AVAILABLE_VEHICLES].data = STR_AVAILABLE_AIRCRAFT;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   249
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   250
				this->widget[GRP_WIDGET_CREATE_GROUP].data = SPR_GROUP_CREATE_AIRCRAFT;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   251
				this->widget[GRP_WIDGET_RENAME_GROUP].data = SPR_GROUP_RENAME_AIRCRAFT;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   252
				this->widget[GRP_WIDGET_DELETE_GROUP].data = SPR_GROUP_DELETE_AIRCRAFT;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   253
				break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   254
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   255
			default: NOT_REACHED();
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   256
		}
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   257
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   258
		this->FindWindowPlacementAndResize(desc);
9724
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
   259
	}
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   260
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   261
	~VehicleGroupWindow()
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   262
	{
11044
097ea3e7ec56 (svn r13600) [NoAI] -Sync: with trunk r13508:13599.
rubidium
parents: 10776
diff changeset
   263
		*this->sorting = this->vehicles.GetListing();
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   264
	}
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   265
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   266
	virtual void OnInvalidateData(int data)
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   267
	{
10776
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   268
		if (data == 0) {
11044
097ea3e7ec56 (svn r13600) [NoAI] -Sync: with trunk r13508:13599.
rubidium
parents: 10776
diff changeset
   269
			this->vehicles.ForceRebuild();
10776
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   270
			this->groups.ForceRebuild();
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   271
		} else {
11044
097ea3e7ec56 (svn r13600) [NoAI] -Sync: with trunk r13508:13599.
rubidium
parents: 10776
diff changeset
   272
			this->vehicles.ForceResort();
10776
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   273
			this->groups.ForceResort();
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   274
		}
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   275
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   276
		if (!(IsAllGroupID(this->group_sel) || IsDefaultGroupID(this->group_sel) || IsValidGroupID(this->group_sel))) {
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   277
			this->group_sel = ALL_GROUP;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   278
			HideDropDownMenu(this);
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   279
		}
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   280
		this->SetDirty();
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   281
	}
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   282
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   283
	virtual void OnPaint()
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   284
	{
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   285
		const PlayerID owner = (PlayerID)GB(this->window_number, 0, 8);
10776
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   286
		int x = this->widget[GRP_WIDGET_LIST_VEHICLE].left + 2;
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   287
		int y2 = PLY_WND_PRC__OFFSET_TOP_WIDGET;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   288
		int y1 = PLY_WND_PRC__OFFSET_TOP_WIDGET + 2;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   289
		int max;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   290
		int i;
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   291
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   292
		/* If we select the all vehicles, this->list will contain all vehicles of the player
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   293
			* else this->list will contain all vehicles which belong to the selected group */
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   294
		BuildVehicleList(this, owner, this->group_sel, IsAllGroupID(this->group_sel) ? VLW_STANDARD : VLW_GROUP_LIST);
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   295
		SortVehicleList(this);
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   296
10776
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   297
		this->BuildGroupList(owner);
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   298
		this->groups.Sort(&GroupNameSorter);
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   299
10776
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   300
		SetVScrollCount(this, this->groups.Length());
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   301
		SetVScroll2Count(this, this->vehicles.Length());
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   302
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   303
		/* The drop down menu is out, *but* it may not be used, retract it. */
10776
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   304
		if (this->vehicles.Length() == 0 && this->IsWidgetLowered(GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN)) {
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   305
			this->RaiseWidget(GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN);
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   306
			HideDropDownMenu(this);
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   307
		}
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   308
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   309
		/* Disable all lists management button when the list is empty */
10776
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   310
		this->SetWidgetsDisabledState(this->vehicles.Length() == 0 || _local_player != owner,
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   311
				GRP_WIDGET_STOP_ALL,
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   312
				GRP_WIDGET_START_ALL,
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   313
				GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN,
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   314
				WIDGET_LIST_END);
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   315
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   316
		/* Disable the group specific function when we select the default group or all vehicles */
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   317
		this->SetWidgetsDisabledState(IsDefaultGroupID(this->group_sel) || IsAllGroupID(this->group_sel) || _local_player != owner,
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   318
				GRP_WIDGET_DELETE_GROUP,
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   319
				GRP_WIDGET_RENAME_GROUP,
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   320
				GRP_WIDGET_REPLACE_PROTECTION,
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   321
				WIDGET_LIST_END);
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   322
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   323
		/* Disable remaining buttons for non-local player
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   324
			* Needed while changing _local_player, eg. by cheats
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   325
			* All procedures (eg. move vehicle to another group)
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   326
			*  verify, whether you are the owner of the vehicle,
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   327
			*  so it doesn't have to be disabled
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   328
			*/
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   329
		this->SetWidgetsDisabledState(_local_player != owner,
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   330
				GRP_WIDGET_CREATE_GROUP,
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   331
				GRP_WIDGET_AVAILABLE_VEHICLES,
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   332
				WIDGET_LIST_END);
9703
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   333
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9701
diff changeset
   334
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   335
		/* If selected_group == DEFAULT_GROUP || ALL_GROUP, draw the standard caption
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   336
				We list all vehicles or ungrouped vehicles */
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   337
		if (IsDefaultGroupID(this->group_sel) || IsAllGroupID(this->group_sel)) {
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   338
			SetDParam(0, owner);
10776
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   339
			SetDParam(1, this->vehicles.Length());
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   340
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   341
			switch (this->vehicle_type) {
9686
d3c195c226f9 (svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents: 9631
diff changeset
   342
				case VEH_TRAIN:
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   343
					this->widget[GRP_WIDGET_CAPTION].data = STR_881B_TRAINS;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   344
					this->widget[GRP_WIDGET_REPLACE_PROTECTION].data = SPR_GROUP_REPLACE_OFF_TRAIN;
9686
d3c195c226f9 (svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents: 9631
diff changeset
   345
					break;
d3c195c226f9 (svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents: 9631
diff changeset
   346
				case VEH_ROAD:
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   347
					this->widget[GRP_WIDGET_CAPTION].data = STR_9001_ROAD_VEHICLES;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   348
					this->widget[GRP_WIDGET_REPLACE_PROTECTION].data = SPR_GROUP_REPLACE_OFF_ROADVEH;
9686
d3c195c226f9 (svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents: 9631
diff changeset
   349
					break;
d3c195c226f9 (svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents: 9631
diff changeset
   350
				case VEH_SHIP:
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   351
					this->widget[GRP_WIDGET_CAPTION].data = STR_9805_SHIPS;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   352
					this->widget[GRP_WIDGET_REPLACE_PROTECTION].data = SPR_GROUP_REPLACE_OFF_SHIP;
9686
d3c195c226f9 (svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents: 9631
diff changeset
   353
					break;
d3c195c226f9 (svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents: 9631
diff changeset
   354
				case VEH_AIRCRAFT:
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   355
					this->widget[GRP_WIDGET_CAPTION].data =  STR_A009_AIRCRAFT;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   356
					this->widget[GRP_WIDGET_REPLACE_PROTECTION].data = SPR_GROUP_REPLACE_OFF_AIRCRAFT;
9686
d3c195c226f9 (svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents: 9631
diff changeset
   357
					break;
10249
58810805030e (svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents: 9869
diff changeset
   358
				default: NOT_REACHED();
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   359
			}
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   360
		} else {
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   361
			const Group *g = GetGroup(this->group_sel);
9724
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
   362
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   363
			SetDParam(0, g->index);
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   364
			SetDParam(1, g->num_vehicle);
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   365
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   366
			switch (this->vehicle_type) {
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   367
				case VEH_TRAIN:
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   368
					this->widget[GRP_WIDGET_CAPTION].data = STR_GROUP_TRAINS_CAPTION;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   369
					this->widget[GRP_WIDGET_REPLACE_PROTECTION].data = (g->replace_protection) ? SPR_GROUP_REPLACE_ON_TRAIN : SPR_GROUP_REPLACE_OFF_TRAIN;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   370
					break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   371
				case VEH_ROAD:
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   372
					this->widget[GRP_WIDGET_CAPTION].data = STR_GROUP_ROADVEH_CAPTION;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   373
					this->widget[GRP_WIDGET_REPLACE_PROTECTION].data = (g->replace_protection) ? SPR_GROUP_REPLACE_ON_ROADVEH : SPR_GROUP_REPLACE_OFF_ROADVEH;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   374
					break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   375
				case VEH_SHIP:
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   376
					this->widget[GRP_WIDGET_CAPTION].data = STR_GROUP_SHIPS_CAPTION;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   377
					this->widget[GRP_WIDGET_REPLACE_PROTECTION].data = (g->replace_protection) ? SPR_GROUP_REPLACE_ON_SHIP : SPR_GROUP_REPLACE_OFF_SHIP;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   378
					break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   379
				case VEH_AIRCRAFT:
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   380
					this->widget[GRP_WIDGET_CAPTION].data = STR_GROUP_AIRCRAFTS_CAPTION;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   381
					this->widget[GRP_WIDGET_REPLACE_PROTECTION].data = (g->replace_protection) ? SPR_GROUP_REPLACE_ON_AIRCRAFT : SPR_GROUP_REPLACE_OFF_AIRCRAFT;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   382
					break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   383
				default: NOT_REACHED();
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   384
			}
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   385
		}
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   386
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   387
		/* Set text of sort by dropdown */
11044
097ea3e7ec56 (svn r13600) [NoAI] -Sync: with trunk r13508:13599.
rubidium
parents: 10776
diff changeset
   388
		this->widget[GRP_WIDGET_SORT_BY_DROPDOWN].data = this->vehicle_sorter_names[this->vehicles.SortType()];
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   389
10645
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   390
		this->DrawWidgets();
9686
d3c195c226f9 (svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents: 9631
diff changeset
   391
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   392
		/* Draw Matrix Group
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   393
			* The selected group is drawn in white */
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   394
		StringID str_all_veh, str_no_group_veh;
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   395
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   396
		switch (this->vehicle_type) {
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   397
			case VEH_TRAIN:
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   398
				str_all_veh = STR_GROUP_ALL_TRAINS;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   399
				str_no_group_veh = STR_GROUP_DEFAULT_TRAINS;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   400
				break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   401
			case VEH_ROAD:
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   402
				str_all_veh = STR_GROUP_ALL_ROADS;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   403
				str_no_group_veh = STR_GROUP_DEFAULT_ROADS;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   404
				break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   405
			case VEH_SHIP:
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   406
				str_all_veh = STR_GROUP_ALL_SHIPS;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   407
				str_no_group_veh = STR_GROUP_DEFAULT_SHIPS;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   408
				break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   409
			case VEH_AIRCRAFT:
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   410
				str_all_veh = STR_GROUP_ALL_AIRCRAFTS;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   411
				str_no_group_veh = STR_GROUP_DEFAULT_AIRCRAFTS;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   412
				break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   413
			default: NOT_REACHED();
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   414
		}
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   415
		DrawString(10, y1, str_all_veh, IsAllGroupID(this->group_sel) ? TC_WHITE : TC_BLACK);
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   416
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   417
		y1 += 13;
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   418
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   419
		DrawString(10, y1, str_no_group_veh, IsDefaultGroupID(this->group_sel) ? TC_WHITE : TC_BLACK);
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   420
10776
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   421
		max = min(this->vscroll.pos + this->vscroll.cap, this->groups.Length());
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   422
		for (i = this->vscroll.pos ; i < max ; ++i) {
10776
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   423
			const Group *g = this->groups[i];
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   424
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   425
			assert(g->owner == owner);
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   426
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   427
			y1 += PLY_WND_PRC__SIZE_OF_ROW_TINY;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   428
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   429
			/* draw the selected group in white, else we draw it in black */
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   430
			SetDParam(0, g->index);
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   431
			DrawString(10, y1, STR_GROUP_NAME, (this->group_sel == g->index) ? TC_WHITE : TC_BLACK);
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   432
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   433
			/* draw the number of vehicles of the group */
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   434
			SetDParam(0, g->num_vehicle);
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   435
			DrawStringRightAligned(187, y1 + 1, STR_GROUP_TINY_NUM, (this->group_sel == g->index) ? TC_WHITE : TC_BLACK);
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   436
		}
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   437
11044
097ea3e7ec56 (svn r13600) [NoAI] -Sync: with trunk r13508:13599.
rubidium
parents: 10776
diff changeset
   438
		this->DrawSortButtonState(GRP_WIDGET_SORT_BY_ORDER, this->vehicles.IsDescSortOrder() ? SBS_DOWN : SBS_UP);
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   439
10776
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   440
		int list_width = this->widget[GRP_WIDGET_LIST_VEHICLE].right - this->widget[GRP_WIDGET_LIST_VEHICLE].left - 20;
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   441
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   442
		/* Draw Matrix Vehicle according to the vehicle list built before */
10776
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   443
		max = min(this->vscroll2.pos + this->vscroll2.cap, this->vehicles.Length());
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   444
		for (i = this->vscroll2.pos ; i < max ; ++i) {
10776
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   445
			const Vehicle* v = this->vehicles[i];
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   446
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   447
			assert(v->type == this->vehicle_type && v->owner == owner);
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   448
10776
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   449
			DrawVehicleImage(v, x + 19, y2 + 6, this->vehicle_sel, list_width, 0);
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   450
			DrawVehicleProfitButton(v, x, y2 + 13);
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   451
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   452
			SetDParam(0, v->unitnumber);
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   453
			DrawString(x, y2 + 2, v->IsInDepot() ? STR_021F : (v->age > v->max_age - 366 ? STR_00E3 : STR_00E2), TC_FROMSTRING);
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   454
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   455
			if (this->resize.step_height == PLY_WND_PRC__SIZE_OF_ROW_BIG2) DrawSmallOrderList(v, x + 138, y2);
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   456
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   457
			SetDParam(0, v->GetDisplayProfitThisYear());
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   458
			SetDParam(1, v->GetDisplayProfitLastYear());
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   459
			DrawString(x + 19, y2 + this->resize.step_height - 8, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, TC_FROMSTRING);
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   460
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   461
			if (IsValidGroupID(v->group_id)) {
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   462
				SetDParam(0, v->group_id);
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   463
				DrawString(x + 19, y2, STR_GROUP_TINY_NAME, TC_BLACK);
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   464
			}
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   465
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   466
			y2 += this->resize.step_height;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   467
		}
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   468
	}
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   469
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   470
	virtual void OnClick(Point pt, int widget)
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   471
	{
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   472
		if (widget != GRP_WIDGET_SORT_BY_DROPDOWN && widget != GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN) HideDropDownMenu(this);
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   473
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   474
		switch(widget) {
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   475
			case GRP_WIDGET_SORT_BY_ORDER: // Flip sorting method ascending/descending
11044
097ea3e7ec56 (svn r13600) [NoAI] -Sync: with trunk r13508:13599.
rubidium
parents: 10776
diff changeset
   476
				this->vehicles.ToggleSortOrder();
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   477
				this->SetDirty();
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   478
				break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   479
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   480
			case GRP_WIDGET_SORT_BY_DROPDOWN: // Select sorting criteria dropdown menu
11044
097ea3e7ec56 (svn r13600) [NoAI] -Sync: with trunk r13508:13599.
rubidium
parents: 10776
diff changeset
   481
				ShowDropDownMenu(this, this->vehicle_sorter_names, this->vehicles.SortType(),  GRP_WIDGET_SORT_BY_DROPDOWN, 0, (this->vehicle_type == VEH_TRAIN || this->vehicle_type == VEH_ROAD) ? 0 : (1 << 10));
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   482
				return;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   483
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   484
			case GRP_WIDGET_ALL_VEHICLES: // All vehicles button
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   485
				if (!IsAllGroupID(this->group_sel)) {
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   486
					this->group_sel = ALL_GROUP;
11044
097ea3e7ec56 (svn r13600) [NoAI] -Sync: with trunk r13508:13599.
rubidium
parents: 10776
diff changeset
   487
					this->vehicles.ForceRebuild();
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   488
					this->SetDirty();
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   489
				}
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   490
				break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   491
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   492
			case GRP_WIDGET_DEFAULT_VEHICLES: // Ungrouped vehicles button
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   493
				if (!IsDefaultGroupID(this->group_sel)) {
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   494
					this->group_sel = DEFAULT_GROUP;
11044
097ea3e7ec56 (svn r13600) [NoAI] -Sync: with trunk r13508:13599.
rubidium
parents: 10776
diff changeset
   495
					this->vehicles.ForceRebuild();
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   496
					this->SetDirty();
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   497
				}
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   498
				break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   499
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   500
			case GRP_WIDGET_LIST_GROUP: { // Matrix Group
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   501
				uint16 id_g = (pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET - 26) / PLY_WND_PRC__SIZE_OF_ROW_TINY;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   502
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   503
				if (id_g >= this->vscroll.cap) return;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   504
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   505
				id_g += this->vscroll.pos;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   506
10776
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   507
				if (id_g >= this->groups.Length()) return;
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   508
10776
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   509
				this->group_sel = this->groups[id_g]->index;;
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   510
11044
097ea3e7ec56 (svn r13600) [NoAI] -Sync: with trunk r13508:13599.
rubidium
parents: 10776
diff changeset
   511
				this->vehicles.ForceRebuild();
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   512
				this->SetDirty();
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   513
				break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   514
			}
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   515
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   516
			case GRP_WIDGET_LIST_VEHICLE: { // Matrix Vehicle
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   517
				uint32 id_v = (pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / (int)this->resize.step_height;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   518
				const Vehicle *v;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   519
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   520
				if (id_v >= this->vscroll2.cap) return; // click out of bounds
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   521
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   522
				id_v += this->vscroll2.pos;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   523
10776
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   524
				if (id_v >= this->vehicles.Length()) return; // click out of list bound
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   525
10776
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   526
				v = this->vehicles[id_v];
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   527
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   528
				this->vehicle_sel = v->index;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   529
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   530
				if (v->IsValid()) {
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   531
					SetObjectToPlaceWnd(v->GetImage(DIR_W), GetVehiclePalette(v), VHM_DRAG, this);
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   532
					_cursor.vehchain = true;
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   533
				}
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   534
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   535
				this->SetDirty();
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   536
				break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   537
			}
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   538
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   539
			case GRP_WIDGET_CREATE_GROUP: // Create a new group
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   540
				DoCommandP(0, this->vehicle_type, 0, NULL, CMD_CREATE_GROUP | CMD_MSG(STR_GROUP_CAN_T_CREATE));
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   541
				break;
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   542
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   543
			case GRP_WIDGET_DELETE_GROUP: { // Delete the selected group
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   544
				GroupID group = this->group_sel;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   545
				this->group_sel = ALL_GROUP;
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   546
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   547
				DoCommandP(0, group, 0, NULL, CMD_DELETE_GROUP | CMD_MSG(STR_GROUP_CAN_T_DELETE));
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   548
				break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   549
			}
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   550
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   551
			case GRP_WIDGET_RENAME_GROUP: { // Rename the selected roup
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   552
				assert(IsValidGroupID(this->group_sel));
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   553
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   554
				const Group *g = GetGroup(this->group_sel);
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   555
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   556
				SetDParam(0, g->index);
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   557
				ShowQueryString(STR_GROUP_NAME, STR_GROUP_RENAME_CAPTION, 31, 150, this, CS_ALPHANUMERAL);
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   558
			} break;
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   559
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   560
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   561
			case GRP_WIDGET_AVAILABLE_VEHICLES:
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   562
				ShowBuildVehicleWindow(0, this->vehicle_type);
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   563
				break;
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   564
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   565
			case GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN:
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   566
				ShowGroupActionDropdown(this, this->group_sel);
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   567
				break;
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   568
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   569
			case GRP_WIDGET_START_ALL:
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   570
			case GRP_WIDGET_STOP_ALL: { // Start/stop all vehicles of the list
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   571
				DoCommandP(0, this->group_sel, ((IsAllGroupID(this->group_sel) ? VLW_STANDARD : VLW_GROUP_LIST) & VLW_MASK)
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   572
													| (1 << 6)
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   573
													| (widget == GRP_WIDGET_START_ALL ? (1 << 5) : 0)
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   574
													| this->vehicle_type, NULL, CMD_MASS_START_STOP);
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   575
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   576
				break;
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   577
			}
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   578
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   579
			case GRP_WIDGET_REPLACE_PROTECTION:
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   580
				if (IsValidGroupID(this->group_sel)) {
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   581
					const Group *g = GetGroup(this->group_sel);
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   582
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   583
					DoCommandP(0, this->group_sel, !g->replace_protection, NULL, CMD_SET_GROUP_REPLACE_PROTECTION);
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   584
				}
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   585
				break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   586
		}
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   587
	}
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   588
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   589
	virtual void OnDragDrop(Point pt, int widget)
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   590
	{
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   591
		switch (widget) {
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   592
			case GRP_WIDGET_ALL_VEHICLES: // All vehicles
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   593
			case GRP_WIDGET_DEFAULT_VEHICLES: // Ungrouped vehicles
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   594
				DoCommandP(0, DEFAULT_GROUP, this->vehicle_sel, NULL, CMD_ADD_VEHICLE_GROUP | CMD_MSG(STR_GROUP_CAN_T_ADD_VEHICLE));
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   595
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   596
				this->vehicle_sel = INVALID_VEHICLE;
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   597
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   598
				this->SetDirty();
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   599
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   600
				break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   601
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   602
			case GRP_WIDGET_LIST_GROUP: { // Maxtrix group
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   603
				uint16 id_g = (pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET - 26) / PLY_WND_PRC__SIZE_OF_ROW_TINY;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   604
				const VehicleID vindex = this->vehicle_sel;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   605
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   606
				this->vehicle_sel = INVALID_VEHICLE;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   607
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   608
				this->SetDirty();
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   609
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   610
				if (id_g >= this->vscroll.cap) return;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   611
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   612
				id_g += this->vscroll.pos;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   613
10776
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   614
				if (id_g >= this->groups.Length()) return;
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   615
10776
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   616
				DoCommandP(0, this->groups[id_g]->index, vindex, NULL, CMD_ADD_VEHICLE_GROUP | CMD_MSG(STR_GROUP_CAN_T_ADD_VEHICLE));
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   617
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   618
				break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   619
			}
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   620
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   621
			case GRP_WIDGET_LIST_VEHICLE: { // Maxtrix vehicle
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   622
				uint32 id_v = (pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / (int)this->resize.step_height;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   623
				const Vehicle *v;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   624
				const VehicleID vindex = this->vehicle_sel;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   625
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   626
				this->vehicle_sel = INVALID_VEHICLE;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   627
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   628
				this->SetDirty();
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   629
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   630
				if (id_v >= this->vscroll2.cap) return; // click out of bounds
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   631
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   632
				id_v += this->vscroll2.pos;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   633
10776
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   634
				if (id_v >= this->vehicles.Length()) return; // click out of list bound
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   635
10776
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   636
				v = this->vehicles[id_v];
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   637
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   638
				if (vindex == v->index) {
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   639
					ShowVehicleViewWindow(v);
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   640
				}
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   641
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   642
				break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   643
			}
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   644
		}
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   645
		_cursor.vehchain = false;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   646
	}
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   647
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   648
	virtual void OnQueryTextFinished(char *str)
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   649
	{
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   650
		if (!StrEmpty(str)) {
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   651
			_cmd_text = str;
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   652
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   653
			DoCommandP(0, this->group_sel, 0, NULL, CMD_RENAME_GROUP | CMD_MSG(STR_GROUP_CAN_T_RENAME));
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   654
		}
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   655
	}
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   656
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   657
	virtual void OnResize(Point new_size, Point delta)
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   658
	{
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   659
		this->vscroll.cap += delta.y / PLY_WND_PRC__SIZE_OF_ROW_TINY;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   660
		this->vscroll2.cap += delta.y / (int)this->resize.step_height;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   661
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   662
		this->widget[GRP_WIDGET_LIST_GROUP].data = (this->vscroll.cap << 8) + 1;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   663
		this->widget[GRP_WIDGET_LIST_VEHICLE].data = (this->vscroll2.cap << 8) + 1;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   664
	}
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   665
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   666
	virtual void OnDropdownSelect(int widget, int index)
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   667
	{
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   668
		switch (widget) {
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   669
			case GRP_WIDGET_SORT_BY_DROPDOWN:
11044
097ea3e7ec56 (svn r13600) [NoAI] -Sync: with trunk r13508:13599.
rubidium
parents: 10776
diff changeset
   670
				this->vehicles.SetSortType(index);
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   671
				break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   672
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   673
			case GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN:
10776
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10645
diff changeset
   674
				assert(this->vehicles.Length() != 0);
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   675
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   676
				switch (index) {
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   677
					case GALF_REPLACE: // Replace window
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   678
						ShowReplaceGroupVehicleWindow(this->group_sel, this->vehicle_type);
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   679
						break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   680
					case GALF_SERVICE: // Send for servicing
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   681
						DoCommandP(0, this->group_sel, ((IsAllGroupID(this->group_sel) ? VLW_STANDARD : VLW_GROUP_LIST) & VLW_MASK)
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   682
									| DEPOT_MASS_SEND
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   683
									| DEPOT_SERVICE, NULL, GetCmdSendToDepot(this->vehicle_type));
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   684
						break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   685
					case GALF_DEPOT: // Send to Depots
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   686
						DoCommandP(0, this->group_sel, ((IsAllGroupID(this->group_sel) ? VLW_STANDARD : VLW_GROUP_LIST) & VLW_MASK)
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   687
									| DEPOT_MASS_SEND, NULL, GetCmdSendToDepot(this->vehicle_type));
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   688
						break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   689
					case GALF_ADD_SHARED: // Add shared Vehicles
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   690
						assert(IsValidGroupID(this->group_sel));
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   691
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   692
						DoCommandP(0, this->group_sel, this->vehicle_type, NULL, CMD_ADD_SHARED_VEHICLE_GROUP | CMD_MSG(STR_GROUP_CAN_T_ADD_SHARED_VEHICLE));
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   693
						break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   694
					case GALF_REMOVE_ALL: // Remove all Vehicles from the selected group
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   695
						assert(IsValidGroupID(this->group_sel));
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   696
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   697
						DoCommandP(0, this->group_sel, this->vehicle_type, NULL, CMD_REMOVE_ALL_VEHICLES_GROUP | CMD_MSG(STR_GROUP_CAN_T_REMOVE_ALL_VEHICLES));
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   698
						break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   699
					default: NOT_REACHED();
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   700
				}
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   701
				break;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   702
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   703
			default: NOT_REACHED();
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   704
		}
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   705
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   706
		this->SetDirty();
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   707
	}
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   708
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   709
	virtual void OnTick()
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   710
	{
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   711
		if (_pause_game != 0) return;
11044
097ea3e7ec56 (svn r13600) [NoAI] -Sync: with trunk r13508:13599.
rubidium
parents: 10776
diff changeset
   712
		if (this->groups.NeedResort() || this->vehicles.NeedResort()) {
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   713
			this->SetDirty();
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   714
		}
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   715
	}
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   716
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   717
	virtual void OnPlaceObjectAbort()
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   718
	{
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   719
			/* abort drag & drop */
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   720
			this->vehicle_sel = INVALID_VEHICLE;
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   721
			this->InvalidateWidget(GRP_WIDGET_LIST_VEHICLE);
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   722
	}
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   723
};
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   724
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   725
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   726
static const WindowDesc _group_desc = {
9694
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9686
diff changeset
   727
	WDP_AUTO, WDP_AUTO, 460, 194, 526, 246,
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   728
	WC_TRAINS_LIST, WC_NONE,
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   729
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   730
	_group_widgets,
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   731
};
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   732
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   733
void ShowPlayerGroup(PlayerID player, VehicleType vehicle_type)
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   734
{
9701
d1ac22c62f64 (svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents: 9694
diff changeset
   735
	if (!IsValidPlayer(player)) return;
d1ac22c62f64 (svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents: 9694
diff changeset
   736
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   737
	WindowClass wc;
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   738
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   739
	switch (vehicle_type) {
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   740
		default: NOT_REACHED();
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   741
		case VEH_TRAIN:    wc = WC_TRAINS_LIST;   break;
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   742
		case VEH_ROAD:     wc = WC_ROADVEH_LIST;  break;
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   743
		case VEH_SHIP:     wc = WC_SHIPS_LIST;    break;
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   744
		case VEH_AIRCRAFT: wc = WC_AIRCRAFT_LIST; break;
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   745
	}
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   746
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   747
	WindowNumber num = (vehicle_type << 11) | VLW_GROUP_LIST | player;
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   748
	DeleteWindowById(wc, num);
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
   749
	Window *w = new VehicleGroupWindow(&_group_desc, num);
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   750
	w->window_class = wc;
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents:
diff changeset
   751
}