2007-05-19 09:40:18 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file group_gui.cpp GUI for the group window. */
|
2007-05-19 09:40:18 +00:00
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "openttd.h"
|
|
|
|
#include "gui.h"
|
2007-12-19 20:45:46 +00:00
|
|
|
#include "window_gui.h"
|
|
|
|
#include "textbuf_gui.h"
|
2007-12-21 21:50:46 +00:00
|
|
|
#include "command_func.h"
|
2007-05-19 09:40:18 +00:00
|
|
|
#include "vehicle_gui.h"
|
|
|
|
#include "train.h"
|
|
|
|
#include "group.h"
|
|
|
|
#include "debug.h"
|
2007-12-21 19:49:27 +00:00
|
|
|
#include "strings_func.h"
|
2007-12-25 09:48:53 +00:00
|
|
|
#include "core/alloc_func.hpp"
|
2007-12-25 11:26:07 +00:00
|
|
|
#include "window_func.h"
|
2007-12-27 13:35:39 +00:00
|
|
|
#include "vehicle_func.h"
|
2008-01-07 09:19:53 +00:00
|
|
|
#include "autoreplace_gui.h"
|
2008-01-07 14:23:25 +00:00
|
|
|
#include "string_func.h"
|
2008-01-09 09:45:45 +00:00
|
|
|
#include "viewport_func.h"
|
|
|
|
#include "gfx_func.h"
|
2008-01-12 14:10:35 +00:00
|
|
|
#include "player_func.h"
|
2008-01-16 18:25:23 +00:00
|
|
|
#include "widgets/dropdown_type.h"
|
2008-01-14 16:10:58 +00:00
|
|
|
#include "widgets/dropdown_func.h"
|
2008-05-07 13:10:15 +00:00
|
|
|
#include "tilehighlight_func.h"
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
#include "table/sprites.h"
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 14:23:45 +00:00
|
|
|
typedef GUIList<const Group*> GUIGroupList;
|
2008-03-28 16:34:50 +00:00
|
|
|
|
2007-05-19 09:40:18 +00:00
|
|
|
enum GroupListWidgets {
|
|
|
|
GRP_WIDGET_CLOSEBOX = 0,
|
|
|
|
GRP_WIDGET_CAPTION,
|
|
|
|
GRP_WIDGET_STICKY,
|
|
|
|
GRP_WIDGET_EMPTY_TOP_LEFT,
|
|
|
|
GRP_WIDGET_ALL_VEHICLES,
|
2007-07-14 23:10:27 +00:00
|
|
|
GRP_WIDGET_DEFAULT_VEHICLES,
|
2007-05-19 09:40:18 +00:00
|
|
|
GRP_WIDGET_LIST_GROUP,
|
|
|
|
GRP_WIDGET_LIST_GROUP_SCROLLBAR,
|
|
|
|
GRP_WIDGET_SORT_BY_ORDER,
|
|
|
|
GRP_WIDGET_SORT_BY_DROPDOWN,
|
|
|
|
GRP_WIDGET_EMPTY_TOP_RIGHT,
|
|
|
|
GRP_WIDGET_LIST_VEHICLE,
|
|
|
|
GRP_WIDGET_LIST_VEHICLE_SCROLLBAR,
|
|
|
|
GRP_WIDGET_CREATE_GROUP,
|
|
|
|
GRP_WIDGET_DELETE_GROUP,
|
|
|
|
GRP_WIDGET_RENAME_GROUP,
|
|
|
|
GRP_WIDGET_EMPTY1,
|
|
|
|
GRP_WIDGET_REPLACE_PROTECTION,
|
|
|
|
GRP_WIDGET_EMPTY2,
|
|
|
|
GRP_WIDGET_AVAILABLE_VEHICLES,
|
|
|
|
GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN,
|
|
|
|
GRP_WIDGET_STOP_ALL,
|
|
|
|
GRP_WIDGET_START_ALL,
|
|
|
|
GRP_WIDGET_EMPTY_BOTTOM_RIGHT,
|
|
|
|
GRP_WIDGET_RESIZE,
|
|
|
|
};
|
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
enum GroupActionListFunction {
|
|
|
|
GALF_REPLACE,
|
|
|
|
GALF_SERVICE,
|
|
|
|
GALF_DEPOT,
|
|
|
|
GALF_ADD_SHARED,
|
|
|
|
GALF_REMOVE_ALL,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update/redraw the group action dropdown
|
|
|
|
* @param w the window the dropdown belongs to
|
|
|
|
* @param gid the currently selected group in the window
|
|
|
|
*/
|
|
|
|
static void ShowGroupActionDropdown(Window *w, GroupID gid)
|
|
|
|
{
|
|
|
|
DropDownList *list = new DropDownList();
|
|
|
|
|
|
|
|
list->push_back(new DropDownListStringItem(STR_REPLACE_VEHICLES, GALF_REPLACE, false));
|
|
|
|
list->push_back(new DropDownListStringItem(STR_SEND_FOR_SERVICING, GALF_SERVICE, false));
|
|
|
|
list->push_back(new DropDownListStringItem(STR_SEND_TRAIN_TO_DEPOT, GALF_DEPOT, false));
|
|
|
|
|
|
|
|
if (IsValidGroupID(gid)) {
|
|
|
|
list->push_back(new DropDownListStringItem(STR_GROUP_ADD_SHARED_VEHICLE, GALF_ADD_SHARED, false));
|
|
|
|
list->push_back(new DropDownListStringItem(STR_GROUP_REMOVE_ALL_VEHICLES, GALF_REMOVE_ALL, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
ShowDropDownList(w, list, 0, GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN);
|
|
|
|
}
|
|
|
|
|
2007-05-19 09:40:18 +00:00
|
|
|
|
|
|
|
static const Widget _group_widgets[] = {
|
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
2007-07-27 22:13:12 +00:00
|
|
|
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 447, 0, 13, 0x0, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_STICKYBOX, RESIZE_LR, 14, 448, 459, 0, 13, 0x0, STR_STICKY_BUTTON},
|
2007-05-19 09:40:18 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 0, 200, 14, 25, 0x0, STR_NULL},
|
2007-07-14 23:10:27 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 0, 200, 26, 38, 0x0, STR_NULL},
|
2007-11-19 19:54:23 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 0, 200, 39, 51, 0x0, STR_NULL},
|
2007-07-27 22:13:12 +00:00
|
|
|
{ WWT_MATRIX, RESIZE_BOTTOM, 14, 0, 188, 52, 168, 0x701, STR_GROUPS_CLICK_ON_GROUP_FOR_TIP},
|
2007-11-19 19:54:23 +00:00
|
|
|
{ WWT_SCROLLBAR, RESIZE_BOTTOM, 14, 189, 200, 52, 168, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
2007-05-19 09:40:18 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 201, 281, 14, 25, STR_SORT_BY, STR_SORT_ORDER_TIP},
|
2008-01-17 18:49:39 +00:00
|
|
|
{ WWT_DROPDOWN, RESIZE_NONE, 14, 282, 447, 14, 25, 0x0, STR_SORT_CRITERIA_TIP},
|
2007-07-27 22:13:12 +00:00
|
|
|
{ WWT_PANEL, RESIZE_RIGHT, 14, 448, 459, 14, 25, 0x0, STR_NULL},
|
|
|
|
{ WWT_MATRIX, RESIZE_RB, 14, 201, 447, 26, 181, 0x701, STR_NULL},
|
|
|
|
{ WWT_SCROLL2BAR, RESIZE_LRB, 14, 448, 459, 26, 181, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_TB, 14, 0, 23, 169, 193, 0x0, STR_GROUP_CREATE_TIP},
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_TB, 14, 24, 47, 169, 193, 0x0, STR_GROUP_DELETE_TIP},
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_TB, 14, 48, 71, 169, 193, 0x0, STR_GROUP_RENAME_TIP},
|
|
|
|
{ WWT_PANEL, RESIZE_TB, 14, 72, 164, 169, 193, 0x0, STR_NULL},
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_TB, 14, 165, 188, 169, 193, 0x0, STR_GROUP_REPLACE_PROTECTION_TIP},
|
|
|
|
{ WWT_PANEL, RESIZE_TB, 14, 189, 200, 169, 193, 0x0, STR_NULL},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 201, 306, 182, 193, 0x0, STR_AVAILABLE_ENGINES_TIP},
|
2008-01-17 18:49:39 +00:00
|
|
|
{ WWT_DROPDOWN, RESIZE_TB, 14, 307, 423, 182, 193, STR_MANAGE_LIST, STR_MANAGE_LIST_TIP},
|
2007-07-27 22:13:12 +00:00
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_TB, 14, 424, 435, 182, 193, SPR_FLAG_VEH_STOPPED, STR_MASS_STOP_LIST_TIP},
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_TB, 14, 436, 447, 182, 193, SPR_FLAG_VEH_RUNNING, STR_MASS_START_LIST_TIP},
|
|
|
|
{ WWT_PANEL, RESIZE_RTB, 14, 448, 447, 182, 193, 0x0, STR_NULL},
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 448, 459, 182, 193, 0x0, STR_RESIZE_BUTTON},
|
2007-05-19 09:40:18 +00:00
|
|
|
{ WIDGETS_END},
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-05-26 18:30:58 +00:00
|
|
|
class VehicleGroupWindow : public Window, public VehicleListBase {
|
|
|
|
private:
|
2008-05-11 15:00:11 +00:00
|
|
|
GroupID group_sel;
|
|
|
|
VehicleID vehicle_sel;
|
|
|
|
GUIGroupList groups;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-26 18:30:58 +00:00
|
|
|
/**
|
|
|
|
* (Re)Build the group list.
|
|
|
|
*
|
|
|
|
* @param owner The owner of the window
|
|
|
|
*/
|
|
|
|
void BuildGroupList(PlayerID owner)
|
|
|
|
{
|
|
|
|
if (!this->groups.NeedRebuild()) return;
|
|
|
|
|
|
|
|
this->groups.Clear();
|
|
|
|
|
|
|
|
const Group *g;
|
|
|
|
FOR_ALL_GROUPS(g) {
|
|
|
|
if (g->owner == owner && g->vehicle_type == this->vehicle_type) {
|
|
|
|
*this->groups.Append() = g;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this->groups.Compact();
|
|
|
|
this->groups.RebuildDone();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Sort the groups by their name */
|
2008-05-27 00:13:51 +00:00
|
|
|
static int CDECL GroupNameSorter(const Group* const *a, const Group* const *b)
|
2008-05-26 18:30:58 +00:00
|
|
|
{
|
|
|
|
static const Group *last_group[2] = { NULL, NULL };
|
|
|
|
static char last_name[2][64] = { "", "" };
|
|
|
|
|
|
|
|
if (*a != last_group[0]) {
|
|
|
|
last_group[0] = *a;
|
|
|
|
SetDParam(0, (*a)->index);
|
|
|
|
GetString(last_name[0], STR_GROUP_NAME, lastof(last_name[0]));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*b != last_group[1]) {
|
|
|
|
last_group[1] = *b;
|
|
|
|
SetDParam(0, (*b)->index);
|
|
|
|
GetString(last_name[1], STR_GROUP_NAME, lastof(last_name[1]));
|
|
|
|
}
|
|
|
|
|
|
|
|
int r = strcmp(last_name[0], last_name[1]); // sort by name
|
|
|
|
if (r == 0) return (*a)->index - (*b)->index;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2008-05-13 14:43:33 +00:00
|
|
|
VehicleGroupWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
|
2008-05-11 15:00:11 +00:00
|
|
|
{
|
|
|
|
const PlayerID owner = (PlayerID)GB(this->window_number, 0, 8);
|
2008-05-13 21:50:31 +00:00
|
|
|
this->vehicle_type = (VehicleType)GB(this->window_number, 11, 5);
|
2008-05-11 15:00:11 +00:00
|
|
|
|
|
|
|
this->caption_color = owner;
|
|
|
|
this->resize.step_width = 1;
|
|
|
|
|
|
|
|
switch (this->vehicle_type) {
|
|
|
|
default: NOT_REACHED();
|
|
|
|
case VEH_TRAIN:
|
|
|
|
case VEH_ROAD:
|
|
|
|
this->vscroll.cap = 9;
|
|
|
|
this->vscroll2.cap = 6;
|
|
|
|
this->resize.step_height = PLY_WND_PRC__SIZE_OF_ROW_SMALL;
|
|
|
|
break;
|
|
|
|
case VEH_SHIP:
|
|
|
|
case VEH_AIRCRAFT:
|
|
|
|
this->vscroll.cap = 9;
|
|
|
|
this->vscroll2.cap = 4;
|
|
|
|
this->resize.step_height = PLY_WND_PRC__SIZE_OF_ROW_BIG2;
|
|
|
|
break;
|
|
|
|
}
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
this->widget[GRP_WIDGET_LIST_GROUP].data = (this->vscroll.cap << 8) + 1;
|
|
|
|
this->widget[GRP_WIDGET_LIST_VEHICLE].data = (this->vscroll2.cap << 8) + 1;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
switch (this->vehicle_type) {
|
|
|
|
default: NOT_REACHED();
|
|
|
|
case VEH_TRAIN: this->sorting = &_sorting.train; break;
|
|
|
|
case VEH_ROAD: this->sorting = &_sorting.roadveh; break;
|
|
|
|
case VEH_SHIP: this->sorting = &_sorting.ship; break;
|
|
|
|
case VEH_AIRCRAFT: this->sorting = &_sorting.aircraft; break;
|
|
|
|
}
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-06-16 17:09:52 +00:00
|
|
|
this->vehicles.SetListing(*this->sorting);
|
|
|
|
this->vehicles.ForceRebuild();
|
|
|
|
this->vehicles.NeedResort();
|
2008-05-11 14:23:45 +00:00
|
|
|
|
2008-05-26 18:30:58 +00:00
|
|
|
this->groups.ForceRebuild();
|
|
|
|
this->groups.NeedResort();
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
this->group_sel = ALL_GROUP;
|
|
|
|
this->vehicle_sel = INVALID_VEHICLE;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
switch (this->vehicle_type) {
|
|
|
|
case VEH_TRAIN:
|
|
|
|
this->widget[GRP_WIDGET_LIST_VEHICLE].tooltips = STR_883D_TRAINS_CLICK_ON_TRAIN_FOR;
|
|
|
|
this->widget[GRP_WIDGET_AVAILABLE_VEHICLES].data = STR_AVAILABLE_TRAINS;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
this->widget[GRP_WIDGET_CREATE_GROUP].data = SPR_GROUP_CREATE_TRAIN;
|
|
|
|
this->widget[GRP_WIDGET_RENAME_GROUP].data = SPR_GROUP_RENAME_TRAIN;
|
|
|
|
this->widget[GRP_WIDGET_DELETE_GROUP].data = SPR_GROUP_DELETE_TRAIN;
|
|
|
|
break;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
case VEH_ROAD:
|
|
|
|
this->widget[GRP_WIDGET_LIST_VEHICLE].tooltips = STR_901A_ROAD_VEHICLES_CLICK_ON;
|
|
|
|
this->widget[GRP_WIDGET_AVAILABLE_VEHICLES].data = STR_AVAILABLE_ROAD_VEHICLES;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
this->widget[GRP_WIDGET_CREATE_GROUP].data = SPR_GROUP_CREATE_ROADVEH;
|
|
|
|
this->widget[GRP_WIDGET_RENAME_GROUP].data = SPR_GROUP_RENAME_ROADVEH;
|
|
|
|
this->widget[GRP_WIDGET_DELETE_GROUP].data = SPR_GROUP_DELETE_ROADVEH;
|
|
|
|
break;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
case VEH_SHIP:
|
|
|
|
this->widget[GRP_WIDGET_LIST_VEHICLE].tooltips = STR_9823_SHIPS_CLICK_ON_SHIP_FOR;
|
|
|
|
this->widget[GRP_WIDGET_AVAILABLE_VEHICLES].data = STR_AVAILABLE_SHIPS;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
this->widget[GRP_WIDGET_CREATE_GROUP].data = SPR_GROUP_CREATE_SHIP;
|
|
|
|
this->widget[GRP_WIDGET_RENAME_GROUP].data = SPR_GROUP_RENAME_SHIP;
|
|
|
|
this->widget[GRP_WIDGET_DELETE_GROUP].data = SPR_GROUP_DELETE_SHIP;
|
|
|
|
break;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
case VEH_AIRCRAFT:
|
|
|
|
this->widget[GRP_WIDGET_LIST_VEHICLE].tooltips = STR_A01F_AIRCRAFT_CLICK_ON_AIRCRAFT;
|
|
|
|
this->widget[GRP_WIDGET_AVAILABLE_VEHICLES].data = STR_AVAILABLE_AIRCRAFT;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
this->widget[GRP_WIDGET_CREATE_GROUP].data = SPR_GROUP_CREATE_AIRCRAFT;
|
|
|
|
this->widget[GRP_WIDGET_RENAME_GROUP].data = SPR_GROUP_RENAME_AIRCRAFT;
|
|
|
|
this->widget[GRP_WIDGET_DELETE_GROUP].data = SPR_GROUP_DELETE_AIRCRAFT;
|
|
|
|
break;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
this->FindWindowPlacementAndResize(desc);
|
2007-05-19 09:40:18 +00:00
|
|
|
}
|
2008-01-16 18:25:23 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
~VehicleGroupWindow()
|
|
|
|
{
|
2008-06-16 17:09:52 +00:00
|
|
|
*this->sorting = this->vehicles.GetListing();
|
2008-01-16 18:25:23 +00:00
|
|
|
}
|
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
virtual void OnInvalidateData(int data)
|
|
|
|
{
|
2008-05-26 18:30:58 +00:00
|
|
|
if (data == 0) {
|
2008-06-16 17:09:52 +00:00
|
|
|
this->vehicles.ForceRebuild();
|
2008-05-26 18:30:58 +00:00
|
|
|
this->groups.ForceRebuild();
|
|
|
|
} else {
|
2008-06-16 17:09:52 +00:00
|
|
|
this->vehicles.ForceResort();
|
2008-05-26 18:30:58 +00:00
|
|
|
this->groups.ForceResort();
|
|
|
|
}
|
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
if (!(IsAllGroupID(this->group_sel) || IsDefaultGroupID(this->group_sel) || IsValidGroupID(this->group_sel))) {
|
|
|
|
this->group_sel = ALL_GROUP;
|
|
|
|
HideDropDownMenu(this);
|
|
|
|
}
|
|
|
|
this->SetDirty();
|
|
|
|
}
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
|
|
|
const PlayerID owner = (PlayerID)GB(this->window_number, 0, 8);
|
2008-05-29 07:34:40 +00:00
|
|
|
int x = this->widget[GRP_WIDGET_LIST_VEHICLE].left + 2;
|
2008-05-11 15:00:11 +00:00
|
|
|
int y2 = PLY_WND_PRC__OFFSET_TOP_WIDGET;
|
|
|
|
int y1 = PLY_WND_PRC__OFFSET_TOP_WIDGET + 2;
|
|
|
|
int max;
|
|
|
|
int i;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
/* If we select the all vehicles, this->list will contain all vehicles of the player
|
|
|
|
* else this->list will contain all vehicles which belong to the selected group */
|
|
|
|
BuildVehicleList(this, owner, this->group_sel, IsAllGroupID(this->group_sel) ? VLW_STANDARD : VLW_GROUP_LIST);
|
|
|
|
SortVehicleList(this);
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-26 18:30:58 +00:00
|
|
|
this->BuildGroupList(owner);
|
2008-05-27 00:13:51 +00:00
|
|
|
this->groups.Sort(&GroupNameSorter);
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-26 16:23:23 +00:00
|
|
|
SetVScrollCount(this, this->groups.Length());
|
|
|
|
SetVScroll2Count(this, this->vehicles.Length());
|
2007-11-15 19:18:52 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
/* The drop down menu is out, *but* it may not be used, retract it. */
|
2008-05-26 16:23:23 +00:00
|
|
|
if (this->vehicles.Length() == 0 && this->IsWidgetLowered(GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN)) {
|
2008-05-11 15:00:11 +00:00
|
|
|
this->RaiseWidget(GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN);
|
|
|
|
HideDropDownMenu(this);
|
|
|
|
}
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
/* Disable all lists management button when the list is empty */
|
2008-05-26 16:23:23 +00:00
|
|
|
this->SetWidgetsDisabledState(this->vehicles.Length() == 0 || _local_player != owner,
|
2008-05-11 15:00:11 +00:00
|
|
|
GRP_WIDGET_STOP_ALL,
|
|
|
|
GRP_WIDGET_START_ALL,
|
|
|
|
GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN,
|
|
|
|
WIDGET_LIST_END);
|
|
|
|
|
|
|
|
/* Disable the group specific function when we select the default group or all vehicles */
|
|
|
|
this->SetWidgetsDisabledState(IsDefaultGroupID(this->group_sel) || IsAllGroupID(this->group_sel) || _local_player != owner,
|
|
|
|
GRP_WIDGET_DELETE_GROUP,
|
|
|
|
GRP_WIDGET_RENAME_GROUP,
|
|
|
|
GRP_WIDGET_REPLACE_PROTECTION,
|
|
|
|
WIDGET_LIST_END);
|
|
|
|
|
|
|
|
/* Disable remaining buttons for non-local player
|
|
|
|
* Needed while changing _local_player, eg. by cheats
|
|
|
|
* All procedures (eg. move vehicle to another group)
|
|
|
|
* verify, whether you are the owner of the vehicle,
|
|
|
|
* so it doesn't have to be disabled
|
|
|
|
*/
|
|
|
|
this->SetWidgetsDisabledState(_local_player != owner,
|
|
|
|
GRP_WIDGET_CREATE_GROUP,
|
|
|
|
GRP_WIDGET_AVAILABLE_VEHICLES,
|
|
|
|
WIDGET_LIST_END);
|
|
|
|
|
|
|
|
|
|
|
|
/* If selected_group == DEFAULT_GROUP || ALL_GROUP, draw the standard caption
|
|
|
|
We list all vehicles or ungrouped vehicles */
|
|
|
|
if (IsDefaultGroupID(this->group_sel) || IsAllGroupID(this->group_sel)) {
|
|
|
|
SetDParam(0, owner);
|
2008-05-26 16:23:23 +00:00
|
|
|
SetDParam(1, this->vehicles.Length());
|
2008-05-11 15:00:11 +00:00
|
|
|
|
|
|
|
switch (this->vehicle_type) {
|
|
|
|
case VEH_TRAIN:
|
|
|
|
this->widget[GRP_WIDGET_CAPTION].data = STR_881B_TRAINS;
|
|
|
|
this->widget[GRP_WIDGET_REPLACE_PROTECTION].data = SPR_GROUP_REPLACE_OFF_TRAIN;
|
|
|
|
break;
|
|
|
|
case VEH_ROAD:
|
|
|
|
this->widget[GRP_WIDGET_CAPTION].data = STR_9001_ROAD_VEHICLES;
|
|
|
|
this->widget[GRP_WIDGET_REPLACE_PROTECTION].data = SPR_GROUP_REPLACE_OFF_ROADVEH;
|
|
|
|
break;
|
|
|
|
case VEH_SHIP:
|
|
|
|
this->widget[GRP_WIDGET_CAPTION].data = STR_9805_SHIPS;
|
|
|
|
this->widget[GRP_WIDGET_REPLACE_PROTECTION].data = SPR_GROUP_REPLACE_OFF_SHIP;
|
|
|
|
break;
|
|
|
|
case VEH_AIRCRAFT:
|
|
|
|
this->widget[GRP_WIDGET_CAPTION].data = STR_A009_AIRCRAFT;
|
|
|
|
this->widget[GRP_WIDGET_REPLACE_PROTECTION].data = SPR_GROUP_REPLACE_OFF_AIRCRAFT;
|
|
|
|
break;
|
|
|
|
default: NOT_REACHED();
|
2007-05-19 09:40:18 +00:00
|
|
|
}
|
2008-05-11 15:00:11 +00:00
|
|
|
} else {
|
|
|
|
const Group *g = GetGroup(this->group_sel);
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
SetDParam(0, g->index);
|
|
|
|
SetDParam(1, g->num_vehicle);
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
switch (this->vehicle_type) {
|
2007-07-14 23:10:27 +00:00
|
|
|
case VEH_TRAIN:
|
2008-05-11 15:00:11 +00:00
|
|
|
this->widget[GRP_WIDGET_CAPTION].data = STR_GROUP_TRAINS_CAPTION;
|
|
|
|
this->widget[GRP_WIDGET_REPLACE_PROTECTION].data = (g->replace_protection) ? SPR_GROUP_REPLACE_ON_TRAIN : SPR_GROUP_REPLACE_OFF_TRAIN;
|
2007-07-14 23:10:27 +00:00
|
|
|
break;
|
|
|
|
case VEH_ROAD:
|
2008-05-11 15:00:11 +00:00
|
|
|
this->widget[GRP_WIDGET_CAPTION].data = STR_GROUP_ROADVEH_CAPTION;
|
|
|
|
this->widget[GRP_WIDGET_REPLACE_PROTECTION].data = (g->replace_protection) ? SPR_GROUP_REPLACE_ON_ROADVEH : SPR_GROUP_REPLACE_OFF_ROADVEH;
|
2007-07-14 23:10:27 +00:00
|
|
|
break;
|
|
|
|
case VEH_SHIP:
|
2008-05-11 15:00:11 +00:00
|
|
|
this->widget[GRP_WIDGET_CAPTION].data = STR_GROUP_SHIPS_CAPTION;
|
|
|
|
this->widget[GRP_WIDGET_REPLACE_PROTECTION].data = (g->replace_protection) ? SPR_GROUP_REPLACE_ON_SHIP : SPR_GROUP_REPLACE_OFF_SHIP;
|
2007-07-14 23:10:27 +00:00
|
|
|
break;
|
|
|
|
case VEH_AIRCRAFT:
|
2008-05-11 15:00:11 +00:00
|
|
|
this->widget[GRP_WIDGET_CAPTION].data = STR_GROUP_AIRCRAFTS_CAPTION;
|
|
|
|
this->widget[GRP_WIDGET_REPLACE_PROTECTION].data = (g->replace_protection) ? SPR_GROUP_REPLACE_ON_AIRCRAFT : SPR_GROUP_REPLACE_OFF_AIRCRAFT;
|
2007-07-14 23:10:27 +00:00
|
|
|
break;
|
2008-04-18 04:54:09 +00:00
|
|
|
default: NOT_REACHED();
|
2007-05-19 09:40:18 +00:00
|
|
|
}
|
2008-05-11 15:00:11 +00:00
|
|
|
}
|
2007-07-14 23:10:27 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
/* Set text of sort by dropdown */
|
2008-06-19 19:58:30 +00:00
|
|
|
this->widget[GRP_WIDGET_SORT_BY_DROPDOWN].data = this->vehicle_sorter_names[this->vehicles.SortType()];
|
2008-05-11 15:00:11 +00:00
|
|
|
|
2008-05-17 12:48:06 +00:00
|
|
|
this->DrawWidgets();
|
2008-05-11 15:00:11 +00:00
|
|
|
|
|
|
|
/* Draw Matrix Group
|
|
|
|
* The selected group is drawn in white */
|
|
|
|
StringID str_all_veh, str_no_group_veh;
|
|
|
|
|
|
|
|
switch (this->vehicle_type) {
|
|
|
|
case VEH_TRAIN:
|
|
|
|
str_all_veh = STR_GROUP_ALL_TRAINS;
|
|
|
|
str_no_group_veh = STR_GROUP_DEFAULT_TRAINS;
|
|
|
|
break;
|
|
|
|
case VEH_ROAD:
|
|
|
|
str_all_veh = STR_GROUP_ALL_ROADS;
|
|
|
|
str_no_group_veh = STR_GROUP_DEFAULT_ROADS;
|
|
|
|
break;
|
|
|
|
case VEH_SHIP:
|
|
|
|
str_all_veh = STR_GROUP_ALL_SHIPS;
|
|
|
|
str_no_group_veh = STR_GROUP_DEFAULT_SHIPS;
|
|
|
|
break;
|
|
|
|
case VEH_AIRCRAFT:
|
|
|
|
str_all_veh = STR_GROUP_ALL_AIRCRAFTS;
|
|
|
|
str_no_group_veh = STR_GROUP_DEFAULT_AIRCRAFTS;
|
|
|
|
break;
|
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
|
|
|
DrawString(10, y1, str_all_veh, IsAllGroupID(this->group_sel) ? TC_WHITE : TC_BLACK);
|
2007-07-14 23:10:27 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
y1 += 13;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
DrawString(10, y1, str_no_group_veh, IsDefaultGroupID(this->group_sel) ? TC_WHITE : TC_BLACK);
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-26 16:23:23 +00:00
|
|
|
max = min(this->vscroll.pos + this->vscroll.cap, this->groups.Length());
|
2008-05-11 15:00:11 +00:00
|
|
|
for (i = this->vscroll.pos ; i < max ; ++i) {
|
2008-05-26 16:23:23 +00:00
|
|
|
const Group *g = this->groups[i];
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
assert(g->owner == owner);
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
y1 += PLY_WND_PRC__SIZE_OF_ROW_TINY;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
/* draw the selected group in white, else we draw it in black */
|
|
|
|
SetDParam(0, g->index);
|
|
|
|
DrawString(10, y1, STR_GROUP_NAME, (this->group_sel == g->index) ? TC_WHITE : TC_BLACK);
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
/* draw the number of vehicles of the group */
|
|
|
|
SetDParam(0, g->num_vehicle);
|
|
|
|
DrawStringRightAligned(187, y1 + 1, STR_GROUP_TINY_NUM, (this->group_sel == g->index) ? TC_WHITE : TC_BLACK);
|
|
|
|
}
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-06-16 17:09:52 +00:00
|
|
|
this->DrawSortButtonState(GRP_WIDGET_SORT_BY_ORDER, this->vehicles.IsDescSortOrder() ? SBS_DOWN : SBS_UP);
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-29 07:34:40 +00:00
|
|
|
int list_width = this->widget[GRP_WIDGET_LIST_VEHICLE].right - this->widget[GRP_WIDGET_LIST_VEHICLE].left - 20;
|
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
/* Draw Matrix Vehicle according to the vehicle list built before */
|
2008-05-26 16:23:23 +00:00
|
|
|
max = min(this->vscroll2.pos + this->vscroll2.cap, this->vehicles.Length());
|
2008-05-11 15:00:11 +00:00
|
|
|
for (i = this->vscroll2.pos ; i < max ; ++i) {
|
2008-05-26 16:23:23 +00:00
|
|
|
const Vehicle* v = this->vehicles[i];
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
assert(v->type == this->vehicle_type && v->owner == owner);
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-29 07:34:40 +00:00
|
|
|
DrawVehicleImage(v, x + 19, y2 + 6, this->vehicle_sel, list_width, 0);
|
2008-05-11 15:00:11 +00:00
|
|
|
DrawVehicleProfitButton(v, x, y2 + 13);
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
SetDParam(0, v->unitnumber);
|
|
|
|
DrawString(x, y2 + 2, v->IsInDepot() ? STR_021F : (v->age > v->max_age - 366 ? STR_00E3 : STR_00E2), TC_FROMSTRING);
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
if (this->resize.step_height == PLY_WND_PRC__SIZE_OF_ROW_BIG2) DrawSmallOrderList(v, x + 138, y2);
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
SetDParam(0, v->GetDisplayProfitThisYear());
|
|
|
|
SetDParam(1, v->GetDisplayProfitLastYear());
|
|
|
|
DrawString(x + 19, y2 + this->resize.step_height - 8, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, TC_FROMSTRING);
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
if (IsValidGroupID(v->group_id)) {
|
|
|
|
SetDParam(0, v->group_id);
|
|
|
|
DrawString(x + 19, y2, STR_GROUP_TINY_NAME, TC_BLACK);
|
2007-05-19 09:40:18 +00:00
|
|
|
}
|
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
y2 += this->resize.step_height;
|
2007-05-19 09:40:18 +00:00
|
|
|
}
|
2008-05-11 15:00:11 +00:00
|
|
|
}
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
|
{
|
|
|
|
if (widget != GRP_WIDGET_SORT_BY_DROPDOWN && widget != GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN) HideDropDownMenu(this);
|
2008-01-17 13:37:28 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
switch(widget) {
|
|
|
|
case GRP_WIDGET_SORT_BY_ORDER: // Flip sorting method ascending/descending
|
2008-06-16 17:09:52 +00:00
|
|
|
this->vehicles.ToggleSortOrder();
|
2008-05-11 15:00:11 +00:00
|
|
|
this->SetDirty();
|
|
|
|
break;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
case GRP_WIDGET_SORT_BY_DROPDOWN: // Select sorting criteria dropdown menu
|
2008-06-19 19:58:30 +00:00
|
|
|
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));
|
2008-05-11 15:00:11 +00:00
|
|
|
return;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
case GRP_WIDGET_ALL_VEHICLES: // All vehicles button
|
|
|
|
if (!IsAllGroupID(this->group_sel)) {
|
|
|
|
this->group_sel = ALL_GROUP;
|
2008-06-16 17:09:52 +00:00
|
|
|
this->vehicles.ForceRebuild();
|
2008-05-11 15:00:11 +00:00
|
|
|
this->SetDirty();
|
|
|
|
}
|
|
|
|
break;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
case GRP_WIDGET_DEFAULT_VEHICLES: // Ungrouped vehicles button
|
|
|
|
if (!IsDefaultGroupID(this->group_sel)) {
|
|
|
|
this->group_sel = DEFAULT_GROUP;
|
2008-06-16 17:09:52 +00:00
|
|
|
this->vehicles.ForceRebuild();
|
2008-05-11 15:00:11 +00:00
|
|
|
this->SetDirty();
|
|
|
|
}
|
|
|
|
break;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
case GRP_WIDGET_LIST_GROUP: { // Matrix Group
|
|
|
|
uint16 id_g = (pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET - 26) / PLY_WND_PRC__SIZE_OF_ROW_TINY;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
if (id_g >= this->vscroll.cap) return;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
id_g += this->vscroll.pos;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-26 16:23:23 +00:00
|
|
|
if (id_g >= this->groups.Length()) return;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-26 16:23:23 +00:00
|
|
|
this->group_sel = this->groups[id_g]->index;;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-06-16 17:09:52 +00:00
|
|
|
this->vehicles.ForceRebuild();
|
2008-05-11 15:00:11 +00:00
|
|
|
this->SetDirty();
|
|
|
|
break;
|
|
|
|
}
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
case GRP_WIDGET_LIST_VEHICLE: { // Matrix Vehicle
|
|
|
|
uint32 id_v = (pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / (int)this->resize.step_height;
|
|
|
|
const Vehicle *v;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
if (id_v >= this->vscroll2.cap) return; // click out of bounds
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
id_v += this->vscroll2.pos;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-26 16:23:23 +00:00
|
|
|
if (id_v >= this->vehicles.Length()) return; // click out of list bound
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-26 16:23:23 +00:00
|
|
|
v = this->vehicles[id_v];
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
this->vehicle_sel = v->index;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
if (v->IsValid()) {
|
|
|
|
SetObjectToPlaceWnd(v->GetImage(DIR_W), GetVehiclePalette(v), VHM_DRAG, this);
|
|
|
|
_cursor.vehchain = true;
|
2007-05-19 09:40:18 +00:00
|
|
|
}
|
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
this->SetDirty();
|
|
|
|
break;
|
|
|
|
}
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
case GRP_WIDGET_CREATE_GROUP: // Create a new group
|
|
|
|
DoCommandP(0, this->vehicle_type, 0, NULL, CMD_CREATE_GROUP | CMD_MSG(STR_GROUP_CAN_T_CREATE));
|
|
|
|
break;
|
2007-05-22 19:48:11 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
case GRP_WIDGET_DELETE_GROUP: { // Delete the selected group
|
|
|
|
GroupID group = this->group_sel;
|
|
|
|
this->group_sel = ALL_GROUP;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
DoCommandP(0, group, 0, NULL, CMD_DELETE_GROUP | CMD_MSG(STR_GROUP_CAN_T_DELETE));
|
|
|
|
break;
|
|
|
|
}
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
case GRP_WIDGET_RENAME_GROUP: { // Rename the selected roup
|
|
|
|
assert(IsValidGroupID(this->group_sel));
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
const Group *g = GetGroup(this->group_sel);
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
SetDParam(0, g->index);
|
|
|
|
ShowQueryString(STR_GROUP_NAME, STR_GROUP_RENAME_CAPTION, 31, 150, this, CS_ALPHANUMERAL);
|
|
|
|
} break;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
case GRP_WIDGET_AVAILABLE_VEHICLES:
|
|
|
|
ShowBuildVehicleWindow(0, this->vehicle_type);
|
|
|
|
break;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
case GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN:
|
|
|
|
ShowGroupActionDropdown(this, this->group_sel);
|
|
|
|
break;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
case GRP_WIDGET_START_ALL:
|
|
|
|
case GRP_WIDGET_STOP_ALL: { // Start/stop all vehicles of the list
|
|
|
|
DoCommandP(0, this->group_sel, ((IsAllGroupID(this->group_sel) ? VLW_STANDARD : VLW_GROUP_LIST) & VLW_MASK)
|
|
|
|
| (1 << 6)
|
|
|
|
| (widget == GRP_WIDGET_START_ALL ? (1 << 5) : 0)
|
|
|
|
| this->vehicle_type, NULL, CMD_MASS_START_STOP);
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
break;
|
2007-05-19 09:40:18 +00:00
|
|
|
}
|
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
case GRP_WIDGET_REPLACE_PROTECTION:
|
|
|
|
if (IsValidGroupID(this->group_sel)) {
|
|
|
|
const Group *g = GetGroup(this->group_sel);
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
DoCommandP(0, this->group_sel, !g->replace_protection, NULL, CMD_SET_GROUP_REPLACE_PROTECTION);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
virtual void OnDragDrop(Point pt, int widget)
|
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case GRP_WIDGET_ALL_VEHICLES: // All vehicles
|
|
|
|
case GRP_WIDGET_DEFAULT_VEHICLES: // Ungrouped vehicles
|
|
|
|
DoCommandP(0, DEFAULT_GROUP, this->vehicle_sel, NULL, CMD_ADD_VEHICLE_GROUP | CMD_MSG(STR_GROUP_CAN_T_ADD_VEHICLE));
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
this->vehicle_sel = INVALID_VEHICLE;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
this->SetDirty();
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
break;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
case GRP_WIDGET_LIST_GROUP: { // Maxtrix group
|
|
|
|
uint16 id_g = (pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET - 26) / PLY_WND_PRC__SIZE_OF_ROW_TINY;
|
|
|
|
const VehicleID vindex = this->vehicle_sel;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
this->vehicle_sel = INVALID_VEHICLE;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
this->SetDirty();
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
if (id_g >= this->vscroll.cap) return;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
id_g += this->vscroll.pos;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-26 16:23:23 +00:00
|
|
|
if (id_g >= this->groups.Length()) return;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-26 16:23:23 +00:00
|
|
|
DoCommandP(0, this->groups[id_g]->index, vindex, NULL, CMD_ADD_VEHICLE_GROUP | CMD_MSG(STR_GROUP_CAN_T_ADD_VEHICLE));
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
case GRP_WIDGET_LIST_VEHICLE: { // Maxtrix vehicle
|
|
|
|
uint32 id_v = (pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / (int)this->resize.step_height;
|
|
|
|
const Vehicle *v;
|
|
|
|
const VehicleID vindex = this->vehicle_sel;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
this->vehicle_sel = INVALID_VEHICLE;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
this->SetDirty();
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
if (id_v >= this->vscroll2.cap) return; // click out of bounds
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
id_v += this->vscroll2.pos;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-26 16:23:23 +00:00
|
|
|
if (id_v >= this->vehicles.Length()) return; // click out of list bound
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-26 16:23:23 +00:00
|
|
|
v = this->vehicles[id_v];
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
if (vindex == v->index) {
|
|
|
|
ShowVehicleViewWindow(v);
|
2007-05-19 09:40:18 +00:00
|
|
|
}
|
2008-05-11 15:00:11 +00:00
|
|
|
|
|
|
|
break;
|
2007-05-19 09:40:18 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-11 15:00:11 +00:00
|
|
|
_cursor.vehchain = false;
|
|
|
|
}
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
virtual void OnQueryTextFinished(char *str)
|
|
|
|
{
|
|
|
|
if (!StrEmpty(str)) {
|
|
|
|
_cmd_text = str;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
DoCommandP(0, this->group_sel, 0, NULL, CMD_RENAME_GROUP | CMD_MSG(STR_GROUP_CAN_T_RENAME));
|
|
|
|
}
|
|
|
|
}
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
virtual void OnResize(Point new_size, Point delta)
|
|
|
|
{
|
|
|
|
this->vscroll.cap += delta.y / PLY_WND_PRC__SIZE_OF_ROW_TINY;
|
|
|
|
this->vscroll2.cap += delta.y / (int)this->resize.step_height;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
this->widget[GRP_WIDGET_LIST_GROUP].data = (this->vscroll.cap << 8) + 1;
|
|
|
|
this->widget[GRP_WIDGET_LIST_VEHICLE].data = (this->vscroll2.cap << 8) + 1;
|
|
|
|
}
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
virtual void OnDropdownSelect(int widget, int index)
|
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case GRP_WIDGET_SORT_BY_DROPDOWN:
|
2008-06-16 17:09:52 +00:00
|
|
|
this->vehicles.SetSortType(index);
|
2008-05-11 15:00:11 +00:00
|
|
|
break;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
case GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN:
|
2008-05-26 16:23:23 +00:00
|
|
|
assert(this->vehicles.Length() != 0);
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
switch (index) {
|
|
|
|
case GALF_REPLACE: // Replace window
|
|
|
|
ShowReplaceGroupVehicleWindow(this->group_sel, this->vehicle_type);
|
|
|
|
break;
|
|
|
|
case GALF_SERVICE: // Send for servicing
|
|
|
|
DoCommandP(0, this->group_sel, ((IsAllGroupID(this->group_sel) ? VLW_STANDARD : VLW_GROUP_LIST) & VLW_MASK)
|
|
|
|
| DEPOT_MASS_SEND
|
|
|
|
| DEPOT_SERVICE, NULL, GetCmdSendToDepot(this->vehicle_type));
|
|
|
|
break;
|
|
|
|
case GALF_DEPOT: // Send to Depots
|
|
|
|
DoCommandP(0, this->group_sel, ((IsAllGroupID(this->group_sel) ? VLW_STANDARD : VLW_GROUP_LIST) & VLW_MASK)
|
|
|
|
| DEPOT_MASS_SEND, NULL, GetCmdSendToDepot(this->vehicle_type));
|
|
|
|
break;
|
|
|
|
case GALF_ADD_SHARED: // Add shared Vehicles
|
|
|
|
assert(IsValidGroupID(this->group_sel));
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
DoCommandP(0, this->group_sel, this->vehicle_type, NULL, CMD_ADD_SHARED_VEHICLE_GROUP | CMD_MSG(STR_GROUP_CAN_T_ADD_SHARED_VEHICLE));
|
|
|
|
break;
|
|
|
|
case GALF_REMOVE_ALL: // Remove all Vehicles from the selected group
|
|
|
|
assert(IsValidGroupID(this->group_sel));
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
DoCommandP(0, this->group_sel, this->vehicle_type, NULL, CMD_REMOVE_ALL_VEHICLES_GROUP | CMD_MSG(STR_GROUP_CAN_T_REMOVE_ALL_VEHICLES));
|
|
|
|
break;
|
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
|
|
|
break;
|
2008-02-17 12:21:05 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
2008-02-17 12:21:05 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
this->SetDirty();
|
2008-01-01 22:34:00 +00:00
|
|
|
}
|
2008-05-11 15:00:11 +00:00
|
|
|
|
|
|
|
virtual void OnTick()
|
|
|
|
{
|
|
|
|
if (_pause_game != 0) return;
|
2008-06-16 17:09:52 +00:00
|
|
|
if (this->groups.NeedResort() || this->vehicles.NeedResort()) {
|
2008-05-11 15:00:11 +00:00
|
|
|
this->SetDirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnPlaceObjectAbort()
|
|
|
|
{
|
|
|
|
/* abort drag & drop */
|
|
|
|
this->vehicle_sel = INVALID_VEHICLE;
|
|
|
|
this->InvalidateWidget(GRP_WIDGET_LIST_VEHICLE);
|
|
|
|
}
|
|
|
|
};
|
2007-05-19 09:40:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
static const WindowDesc _group_desc = {
|
2007-07-27 22:13:12 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 460, 194, 526, 246,
|
2007-05-19 09:40:18 +00:00
|
|
|
WC_TRAINS_LIST, WC_NONE,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
|
|
|
|
_group_widgets,
|
|
|
|
};
|
|
|
|
|
|
|
|
void ShowPlayerGroup(PlayerID player, VehicleType vehicle_type)
|
|
|
|
{
|
2007-08-04 01:25:44 +00:00
|
|
|
if (!IsValidPlayer(player)) return;
|
|
|
|
|
2007-05-19 09:40:18 +00:00
|
|
|
WindowClass wc;
|
|
|
|
|
|
|
|
switch (vehicle_type) {
|
|
|
|
default: NOT_REACHED();
|
|
|
|
case VEH_TRAIN: wc = WC_TRAINS_LIST; break;
|
|
|
|
case VEH_ROAD: wc = WC_ROADVEH_LIST; break;
|
|
|
|
case VEH_SHIP: wc = WC_SHIPS_LIST; break;
|
|
|
|
case VEH_AIRCRAFT: wc = WC_AIRCRAFT_LIST; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowNumber num = (vehicle_type << 11) | VLW_GROUP_LIST | player;
|
|
|
|
DeleteWindowById(wc, num);
|
2008-05-11 15:00:11 +00:00
|
|
|
Window *w = new VehicleGroupWindow(&_group_desc, num);
|
2007-05-19 09:40:18 +00:00
|
|
|
w->window_class = wc;
|
|
|
|
}
|