2007-05-19 09:40:18 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-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"
|
2007-12-19 20:45:46 +00:00
|
|
|
#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"
|
2009-01-31 20:16:06 +00:00
|
|
|
#include "vehicle_base.h"
|
2007-05-19 09:40:18 +00:00
|
|
|
#include "group.h"
|
2007-12-21 19:49:27 +00:00
|
|
|
#include "strings_func.h"
|
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-09-30 20:51:04 +00:00
|
|
|
#include "company_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"
|
2009-11-17 09:09:20 +00:00
|
|
|
#include "vehicle_gui_base.h"
|
2010-01-15 16:41:15 +00:00
|
|
|
#include "core/geometry_func.hpp"
|
|
|
|
#include "company_base.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_CAPTION,
|
|
|
|
GRP_WIDGET_SORT_BY_ORDER,
|
|
|
|
GRP_WIDGET_SORT_BY_DROPDOWN,
|
|
|
|
GRP_WIDGET_LIST_VEHICLE,
|
|
|
|
GRP_WIDGET_LIST_VEHICLE_SCROLLBAR,
|
|
|
|
GRP_WIDGET_AVAILABLE_VEHICLES,
|
|
|
|
GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN,
|
|
|
|
GRP_WIDGET_STOP_ALL,
|
|
|
|
GRP_WIDGET_START_ALL,
|
2008-09-13 10:04:36 +00:00
|
|
|
|
|
|
|
GRP_WIDGET_ALL_VEHICLES,
|
|
|
|
GRP_WIDGET_DEFAULT_VEHICLES,
|
|
|
|
GRP_WIDGET_LIST_GROUP,
|
|
|
|
GRP_WIDGET_LIST_GROUP_SCROLLBAR,
|
|
|
|
GRP_WIDGET_CREATE_GROUP,
|
|
|
|
GRP_WIDGET_DELETE_GROUP,
|
|
|
|
GRP_WIDGET_RENAME_GROUP,
|
|
|
|
GRP_WIDGET_REPLACE_PROTECTION,
|
2007-05-19 09:40:18 +00:00
|
|
|
};
|
|
|
|
|
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();
|
|
|
|
|
2009-08-05 17:59:21 +00:00
|
|
|
list->push_back(new DropDownListStringItem(STR_VEHICLE_LIST_REPLACE_VEHICLES, GALF_REPLACE, false));
|
|
|
|
list->push_back(new DropDownListStringItem(STR_VEHICLE_LIST_SEND_FOR_SERVICING, GALF_SERVICE, false));
|
|
|
|
list->push_back(new DropDownListStringItem(STR_VEHICLE_LIST_SEND_TRAIN_TO_DEPOT, GALF_DEPOT, false));
|
2008-05-11 15:00:11 +00:00
|
|
|
|
2009-05-17 01:00:56 +00:00
|
|
|
if (Group::IsValidID(gid)) {
|
2008-05-11 15:00:11 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2009-03-22 21:16:57 +00:00
|
|
|
static const NWidgetPart _nested_group_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL), // Window header
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
|
2009-11-22 11:20:12 +00:00
|
|
|
NWidget(WWT_CAPTION, COLOUR_GREY, GRP_WIDGET_CAPTION),
|
2009-12-21 16:24:29 +00:00
|
|
|
NWidget(WWT_SHADEBOX, COLOUR_GREY),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_STICKYBOX, COLOUR_GREY),
|
2009-03-22 21:16:57 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
/* left part */
|
|
|
|
NWidget(NWID_VERTICAL),
|
2009-11-24 21:13:36 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalTextLines(1, WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM), SetFill(1, 0), EndContainer(),
|
2009-11-22 18:51:58 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, GRP_WIDGET_ALL_VEHICLES), SetMinimalSize(200, 13), SetFill(1, 0), EndContainer(),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, GRP_WIDGET_DEFAULT_VEHICLES), SetMinimalSize(200, 13), SetFill(1, 0), EndContainer(),
|
2009-03-22 21:16:57 +00:00
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-16 21:28:12 +00:00
|
|
|
NWidget(WWT_MATRIX, COLOUR_GREY, GRP_WIDGET_LIST_GROUP), SetMinimalSize(188, 0), SetDataTip(0x701, STR_GROUPS_CLICK_ON_GROUP_FOR_TOOLTIP),
|
2009-11-22 18:26:01 +00:00
|
|
|
SetFill(1, 0), SetResize(0, 1),
|
2009-11-22 11:24:30 +00:00
|
|
|
NWidget(WWT_SCROLL2BAR, COLOUR_GREY, GRP_WIDGET_LIST_GROUP_SCROLLBAR),
|
2009-03-22 21:16:57 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, GRP_WIDGET_CREATE_GROUP), SetMinimalSize(24, 25), SetFill(0, 1),
|
2009-11-13 21:42:49 +00:00
|
|
|
SetDataTip(SPR_GROUP_CREATE_TRAIN, STR_GROUP_CREATE_TOOLTIP),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, GRP_WIDGET_DELETE_GROUP), SetMinimalSize(24, 25), SetFill(0, 1),
|
2009-11-13 21:42:49 +00:00
|
|
|
SetDataTip(SPR_GROUP_DELETE_TRAIN, STR_GROUP_DELETE_TOOLTIP),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, GRP_WIDGET_RENAME_GROUP), SetMinimalSize(24, 25), SetFill(0, 1),
|
2009-11-13 21:42:49 +00:00
|
|
|
SetDataTip(SPR_GROUP_RENAME_TRAIN, STR_GROUP_RENAME_TOOLTIP),
|
2009-11-24 21:13:36 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(92, 25), SetFill(1, 1), EndContainer(),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, GRP_WIDGET_REPLACE_PROTECTION), SetMinimalSize(24, 25), SetFill(0, 1),
|
2009-11-13 21:42:49 +00:00
|
|
|
SetDataTip(SPR_GROUP_REPLACE_OFF_TRAIN, STR_GROUP_REPLACE_PROTECTION_TOOLTIP),
|
2009-11-24 21:13:36 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(12, 25), SetFill(0, 1), EndContainer(),
|
2009-03-22 21:16:57 +00:00
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
/* right part */
|
|
|
|
NWidget(NWID_VERTICAL),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-08-05 17:59:21 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, GRP_WIDGET_SORT_BY_ORDER), SetMinimalSize(81, 12), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
|
|
|
|
NWidget(WWT_DROPDOWN, COLOUR_GREY, GRP_WIDGET_SORT_BY_DROPDOWN), SetMinimalSize(167, 12), SetDataTip(0x0, STR_TOOLTIP_SORT_CRITERIAP),
|
2009-11-24 21:13:36 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(12, 12), SetResize(1, 0), EndContainer(),
|
2009-03-22 21:16:57 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_MATRIX, COLOUR_GREY, GRP_WIDGET_LIST_VEHICLE), SetMinimalSize(248, 0), SetDataTip(0x701, STR_NULL), SetResize(1, 1), SetFill(1, 0),
|
2009-11-22 11:24:30 +00:00
|
|
|
NWidget(WWT_SCROLLBAR, COLOUR_GREY, GRP_WIDGET_LIST_VEHICLE_SCROLLBAR),
|
2009-03-22 21:16:57 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, GRP_WIDGET_AVAILABLE_VEHICLES), SetMinimalSize(106, 12), SetFill(0, 1),
|
2009-11-13 21:42:49 +00:00
|
|
|
SetDataTip(0x0, STR_VEHICLE_LIST_AVAILABLE_ENGINES_TOOLTIP),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_DROPDOWN, COLOUR_GREY, GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN), SetMinimalSize(118, 12), SetFill(0, 1),
|
2009-11-13 21:42:49 +00:00
|
|
|
SetDataTip(STR_VEHICLE_LIST_MANAGE_LIST, STR_VEHICLE_LIST_MANAGE_LIST_TOOLTIP),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, GRP_WIDGET_STOP_ALL), SetMinimalSize(12, 12), SetFill(0, 1),
|
2009-11-13 21:42:49 +00:00
|
|
|
SetDataTip(SPR_FLAG_VEH_STOPPED, STR_VEHICLE_LIST_MASS_STOP_LIST_TOOLTIP),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, GRP_WIDGET_START_ALL), SetMinimalSize(12, 12), SetFill(0, 1),
|
2009-11-13 21:42:49 +00:00
|
|
|
SetDataTip(SPR_FLAG_VEH_RUNNING, STR_VEHICLE_LIST_MASS_START_LIST_TOOLTIP),
|
2009-11-24 21:13:36 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 1), SetResize(1, 0), EndContainer(),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_RESIZEBOX, COLOUR_GREY),
|
2009-03-22 21:16:57 +00:00
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-09-13 10:04:36 +00:00
|
|
|
class VehicleGroupWindow : public BaseVehicleListWindow {
|
2008-05-26 18:30:58 +00:00
|
|
|
private:
|
2009-08-24 21:51:02 +00:00
|
|
|
GroupID group_sel; ///< Selected group
|
|
|
|
VehicleID vehicle_sel; ///< Selected vehicle
|
|
|
|
GroupID group_rename; ///< Group being renamed, INVALID_GROUP if none
|
|
|
|
GUIGroupList groups; ///< List of groups
|
2009-11-16 21:28:12 +00:00
|
|
|
uint tiny_step_height; ///< Step height for the group list
|
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
|
|
|
|
*/
|
2008-09-30 20:39:50 +00:00
|
|
|
void BuildGroupList(Owner owner)
|
2008-05-26 18:30:58 +00:00
|
|
|
{
|
|
|
|
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 */
|
2009-01-10 00:31:47 +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:
|
2009-11-13 21:42:49 +00:00
|
|
|
VehicleGroupWindow(const WindowDesc *desc, WindowNumber window_number) : BaseVehicleListWindow()
|
2008-05-11 15:00:11 +00:00
|
|
|
{
|
2009-11-13 21:42:49 +00:00
|
|
|
this->CreateNestedTree(desc);
|
2008-05-11 15:00:11 +00:00
|
|
|
|
2009-11-13 21:42:49 +00:00
|
|
|
this->vehicle_type = (VehicleType)GB(window_number, 11, 5);
|
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
|
|
|
|
2009-11-13 21:42:49 +00:00
|
|
|
this->group_sel = ALL_GROUP;
|
|
|
|
this->vehicle_sel = INVALID_VEHICLE;
|
|
|
|
this->group_rename = INVALID_GROUP;
|
|
|
|
|
|
|
|
const Owner owner = (Owner)GB(window_number, 0, 8);
|
2008-06-16 17:09:52 +00:00
|
|
|
this->vehicles.SetListing(*this->sorting);
|
|
|
|
this->vehicles.ForceRebuild();
|
|
|
|
this->vehicles.NeedResort();
|
2009-11-13 21:42:49 +00:00
|
|
|
this->BuildVehicleList(owner, this->group_sel, IsAllGroupID(this->group_sel) ? VLW_STANDARD : VLW_GROUP_LIST);
|
|
|
|
this->SortVehicleList();
|
2008-05-11 14:23:45 +00:00
|
|
|
|
2008-05-26 18:30:58 +00:00
|
|
|
this->groups.ForceRebuild();
|
|
|
|
this->groups.NeedResort();
|
2009-11-13 21:42:49 +00:00
|
|
|
this->BuildGroupList(owner);
|
|
|
|
this->groups.Sort(&GroupNameSorter);
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2009-11-13 21:42:49 +00:00
|
|
|
this->GetWidget<NWidgetCore>(GRP_WIDGET_CAPTION)->widget_data = STR_VEHICLE_LIST_TRAIN_CAPTION + this->vehicle_type;
|
|
|
|
this->GetWidget<NWidgetCore>(GRP_WIDGET_LIST_VEHICLE)->tool_tip = STR_VEHICLE_LIST_TRAIN_LIST_TOOLTIP + this->vehicle_type;
|
|
|
|
this->GetWidget<NWidgetCore>(GRP_WIDGET_AVAILABLE_VEHICLES)->widget_data = STR_VEHICLE_LIST_AVAILABLE_TRAINS + this->vehicle_type;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2009-11-13 21:42:49 +00:00
|
|
|
this->GetWidget<NWidgetCore>(GRP_WIDGET_CREATE_GROUP)->widget_data += this->vehicle_type;
|
|
|
|
this->GetWidget<NWidgetCore>(GRP_WIDGET_RENAME_GROUP)->widget_data += this->vehicle_type;
|
|
|
|
this->GetWidget<NWidgetCore>(GRP_WIDGET_DELETE_GROUP)->widget_data += this->vehicle_type;
|
|
|
|
this->GetWidget<NWidgetCore>(GRP_WIDGET_REPLACE_PROTECTION)->widget_data += this->vehicle_type;
|
2009-07-22 20:17:07 +00:00
|
|
|
|
2009-11-13 21:42:49 +00:00
|
|
|
this->FinishInitNested(desc, window_number);
|
|
|
|
this->owner = owner;
|
|
|
|
}
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2009-11-13 21:42:49 +00:00
|
|
|
~VehicleGroupWindow()
|
|
|
|
{
|
|
|
|
*this->sorting = this->vehicles.GetListing();
|
|
|
|
}
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2009-11-22 18:28:14 +00:00
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
2009-11-13 21:42:49 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case GRP_WIDGET_LIST_GROUP:
|
2009-11-16 21:28:12 +00:00
|
|
|
this->tiny_step_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP;
|
|
|
|
resize->height = this->tiny_step_height;
|
|
|
|
/* Minimum height is the height of the list widget minus all and default vehicles and a bit for the bottom bar */
|
2009-11-22 18:51:58 +00:00
|
|
|
size->height = 4 * GetVehicleListHeight(this->vehicle_type, this->tiny_step_height) - (this->tiny_step_height > 25 ? 2 : 3) * this->tiny_step_height;
|
2009-11-16 21:28:12 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GRP_WIDGET_ALL_VEHICLES:
|
|
|
|
case GRP_WIDGET_DEFAULT_VEHICLES:
|
|
|
|
size->height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP;
|
2009-11-22 19:18:51 +00:00
|
|
|
size->width = max(GetStringBoundingBox(STR_GROUP_DEFAULT_TRAINS + this->vehicle_type).width, GetStringBoundingBox(STR_GROUP_ALL_TRAINS + this->vehicle_type).width);
|
|
|
|
size->width += WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT + 8 + 8;
|
2008-05-11 15:00:11 +00:00
|
|
|
break;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2009-11-13 21:42:49 +00:00
|
|
|
case GRP_WIDGET_LIST_VEHICLE:
|
2009-11-16 21:28:12 +00:00
|
|
|
resize->height = GetVehicleListHeight(this->vehicle_type, FONT_HEIGHT_NORMAL + WD_MATRIX_TOP);
|
|
|
|
size->height = 4 * resize->height;
|
2008-05-11 15:00:11 +00:00
|
|
|
break;
|
2009-11-22 19:18:51 +00:00
|
|
|
|
|
|
|
case GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN: {
|
|
|
|
static const StringID _dropdown_text[] = {STR_VEHICLE_LIST_REPLACE_VEHICLES, STR_VEHICLE_LIST_SEND_FOR_SERVICING, STR_VEHICLE_LIST_SEND_TRAIN_TO_DEPOT, STR_GROUP_ADD_SHARED_VEHICLE, STR_GROUP_REMOVE_ALL_VEHICLES};
|
|
|
|
Dimension d = {0, 0};
|
|
|
|
for (const StringID *sid = _dropdown_text; sid != endof(_dropdown_text); sid++) {
|
|
|
|
d = maxdim(d, GetStringBoundingBox(*sid));
|
|
|
|
}
|
|
|
|
d.height += padding.height;
|
|
|
|
d.width += padding.width;
|
|
|
|
*size = maxdim(*size, d);
|
|
|
|
} break;
|
2008-05-11 15:00:11 +00:00
|
|
|
}
|
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();
|
|
|
|
}
|
|
|
|
|
2009-08-24 21:51:02 +00:00
|
|
|
if (this->group_rename != INVALID_GROUP && !Group::IsValidID(this->group_rename)) {
|
|
|
|
DeleteWindowByClass(WC_QUERY_STRING);
|
|
|
|
this->group_rename = INVALID_GROUP;
|
|
|
|
}
|
|
|
|
|
2009-05-17 01:00:56 +00:00
|
|
|
if (!(IsAllGroupID(this->group_sel) || IsDefaultGroupID(this->group_sel) || Group::IsValidID(this->group_sel))) {
|
2008-05-11 15:00:11 +00:00
|
|
|
this->group_sel = ALL_GROUP;
|
|
|
|
HideDropDownMenu(this);
|
|
|
|
}
|
|
|
|
this->SetDirty();
|
|
|
|
}
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2009-11-13 21:42:49 +00:00
|
|
|
virtual void SetStringParameters(int widget) const
|
|
|
|
{
|
|
|
|
if (widget != GRP_WIDGET_CAPTION) return;
|
|
|
|
|
|
|
|
/* 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, STR_COMPANY_NAME);
|
|
|
|
SetDParam(1, GB(this->window_number, 0, 8));
|
|
|
|
SetDParam(2, this->vehicles.Length());
|
|
|
|
SetDParam(3, this->vehicles.Length());
|
|
|
|
} else {
|
|
|
|
const Group *g = Group::Get(this->group_sel);
|
|
|
|
|
|
|
|
SetDParam(0, STR_GROUP_NAME);
|
|
|
|
SetDParam(1, g->index);
|
|
|
|
SetDParam(2, g->num_vehicle);
|
|
|
|
SetDParam(3, g->num_vehicle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
2008-09-30 20:39:50 +00:00
|
|
|
const Owner owner = (Owner)GB(this->window_number, 0, 8);
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
/* If we select the all vehicles, this->list will contain all vehicles of the owner
|
|
|
|
* else this->list will contain all vehicles which belong to the selected group */
|
2008-09-13 10:04:36 +00:00
|
|
|
this->BuildVehicleList(owner, this->group_sel, IsAllGroupID(this->group_sel) ? VLW_STANDARD : VLW_GROUP_LIST);
|
|
|
|
this->SortVehicleList();
|
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
|
|
|
|
2009-09-02 07:36:39 +00:00
|
|
|
this->vscroll2.SetCount(this->groups.Length());
|
|
|
|
this->vscroll.SetCount(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-09-30 20:39:50 +00:00
|
|
|
this->SetWidgetsDisabledState(this->vehicles.Length() == 0 || _local_company != 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 */
|
2008-09-30 20:39:50 +00:00
|
|
|
this->SetWidgetsDisabledState(IsDefaultGroupID(this->group_sel) || IsAllGroupID(this->group_sel) || _local_company != owner,
|
2008-05-11 15:00:11 +00:00
|
|
|
GRP_WIDGET_DELETE_GROUP,
|
|
|
|
GRP_WIDGET_RENAME_GROUP,
|
|
|
|
GRP_WIDGET_REPLACE_PROTECTION,
|
|
|
|
WIDGET_LIST_END);
|
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
/* Disable remaining buttons for non-local companies
|
|
|
|
* Needed while changing _local_company, 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_company != owner,
|
2008-05-11 15:00:11 +00:00
|
|
|
GRP_WIDGET_CREATE_GROUP,
|
|
|
|
GRP_WIDGET_AVAILABLE_VEHICLES,
|
|
|
|
WIDGET_LIST_END);
|
|
|
|
|
2009-11-13 21:42:49 +00:00
|
|
|
/* If not a default group and the group has replace protection, show an enabled replace sprite. */
|
|
|
|
uint16 protect_sprite = SPR_GROUP_REPLACE_OFF_TRAIN;
|
|
|
|
if (!IsDefaultGroupID(this->group_sel) && !IsAllGroupID(this->group_sel) && Group::Get(this->group_sel)->replace_protection) protect_sprite = SPR_GROUP_REPLACE_ON_TRAIN;
|
|
|
|
this->GetWidget<NWidgetCore>(GRP_WIDGET_REPLACE_PROTECTION)->widget_data = protect_sprite + this->vehicle_type;
|
2007-07-14 23:10:27 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
/* Set text of sort by dropdown */
|
2009-11-13 21:42:49 +00:00
|
|
|
this->GetWidget<NWidgetCore>(GRP_WIDGET_SORT_BY_DROPDOWN)->widget_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();
|
2009-11-13 21:42:49 +00:00
|
|
|
}
|
2008-05-11 15:00:11 +00:00
|
|
|
|
2009-11-13 21:42:49 +00:00
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case GRP_WIDGET_ALL_VEHICLES:
|
2009-11-22 19:18:51 +00:00
|
|
|
DrawString(r.left + WD_FRAMERECT_LEFT + 8, r.right - WD_FRAMERECT_RIGHT - 8, r.top + WD_MATRIX_TOP,
|
2009-11-13 21:42:49 +00:00
|
|
|
STR_GROUP_ALL_TRAINS + this->vehicle_type, IsAllGroupID(this->group_sel) ? TC_WHITE : TC_BLACK);
|
|
|
|
break;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2009-11-13 21:42:49 +00:00
|
|
|
case GRP_WIDGET_DEFAULT_VEHICLES:
|
2009-11-22 19:18:51 +00:00
|
|
|
DrawString(r.left + WD_FRAMERECT_LEFT + 8, r.right - WD_FRAMERECT_RIGHT - 8, r.top + WD_MATRIX_TOP,
|
2009-11-13 21:42:49 +00:00
|
|
|
STR_GROUP_DEFAULT_TRAINS + this->vehicle_type, IsDefaultGroupID(this->group_sel) ? TC_WHITE : TC_BLACK);
|
|
|
|
break;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2009-11-13 21:42:49 +00:00
|
|
|
case GRP_WIDGET_LIST_GROUP: {
|
|
|
|
int y1 = r.top + WD_FRAMERECT_TOP + 1;
|
|
|
|
int max = min(this->vscroll2.GetPosition() + this->vscroll2.GetCapacity(), this->groups.Length());
|
2009-11-29 19:20:39 +00:00
|
|
|
for (int i = this->vscroll2.GetPosition(); i < max; ++i) {
|
2009-11-13 21:42:49 +00:00
|
|
|
const Group *g = this->groups[i];
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2009-11-13 21:42:49 +00:00
|
|
|
assert(g->owner == this->owner);
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2009-11-13 21:42:49 +00:00
|
|
|
/* draw the selected group in white, else we draw it in black */
|
|
|
|
SetDParam(0, g->index);
|
|
|
|
DrawString(r.left + WD_FRAMERECT_LEFT + 8, r.right - WD_FRAMERECT_RIGHT, y1, STR_GROUP_NAME, (this->group_sel == g->index) ? TC_WHITE : TC_BLACK);
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2009-11-13 21:42:49 +00:00
|
|
|
/* draw the number of vehicles of the group */
|
|
|
|
SetDParam(0, g->num_vehicle);
|
|
|
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y1 + 1, STR_TINY_COMMA, (this->group_sel == g->index) ? TC_WHITE : TC_BLACK, SA_RIGHT);
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2009-11-16 21:28:12 +00:00
|
|
|
y1 += this->tiny_step_height;
|
2009-11-13 21:42:49 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2009-11-13 21:42:49 +00:00
|
|
|
case GRP_WIDGET_SORT_BY_ORDER:
|
|
|
|
this->DrawSortButtonState(GRP_WIDGET_SORT_BY_ORDER, this->vehicles.IsDescSortOrder() ? SBS_DOWN : SBS_UP);
|
|
|
|
break;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2009-11-13 21:42:49 +00:00
|
|
|
case GRP_WIDGET_LIST_VEHICLE:
|
|
|
|
this->DrawVehicleListItems(this->vehicle_sel, this->resize.step_height, r);
|
|
|
|
break;
|
|
|
|
}
|
2008-05-11 15:00:11 +00:00
|
|
|
}
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2010-01-30 18:34:48 +00:00
|
|
|
virtual void OnClick(Point pt, int widget, int click_count)
|
2008-05-11 15:00:11 +00:00
|
|
|
{
|
2009-08-09 14:40:34 +00:00
|
|
|
switch (widget) {
|
2008-05-11 15:00:11 +00:00
|
|
|
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
|
2009-11-16 21:28:12 +00:00
|
|
|
uint16 id_g = (pt.y - this->GetWidget<NWidgetBase>(GRP_WIDGET_LIST_GROUP)->pos_y) / (int)this->tiny_step_height;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2009-09-02 07:36:39 +00:00
|
|
|
if (id_g >= this->vscroll2.GetCapacity()) return;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2009-09-02 07:36:39 +00:00
|
|
|
id_g += this->vscroll2.GetPosition();
|
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
|
2009-11-13 21:42:49 +00:00
|
|
|
uint32 id_v = (pt.y - this->GetWidget<NWidgetBase>(GRP_WIDGET_LIST_VEHICLE)->pos_y) / (int)this->resize.step_height;
|
2009-09-02 07:36:39 +00:00
|
|
|
if (id_v >= this->vscroll.GetCapacity()) return; // click out of bounds
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2009-09-02 07:36:39 +00:00
|
|
|
id_v += this->vscroll.GetPosition();
|
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
|
|
|
|
2009-05-22 15:13:50 +00:00
|
|
|
const Vehicle *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
|
|
|
|
2009-05-22 15:13:50 +00:00
|
|
|
SetObjectToPlaceWnd(v->GetImage(DIR_W), GetVehiclePalette(v), HT_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
|
|
|
|
2009-08-25 10:44:19 +00:00
|
|
|
case GRP_WIDGET_CREATE_GROUP: { // Create a new group
|
|
|
|
DoCommandP(0, this->vehicle_type, 0, CMD_CREATE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_CREATE), CcCreateGroup);
|
2008-05-11 15:00:11 +00:00
|
|
|
break;
|
2009-08-25 10:44:19 +00:00
|
|
|
}
|
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
|
|
|
|
2009-08-05 17:59:21 +00:00
|
|
|
DoCommandP(0, group, 0, CMD_DELETE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_DELETE));
|
2008-05-11 15:00:11 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2009-08-25 10:44:19 +00:00
|
|
|
case GRP_WIDGET_RENAME_GROUP: // Rename the selected roup
|
|
|
|
this->ShowRenameGroupWindow(this->group_sel);
|
|
|
|
break;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
case GRP_WIDGET_AVAILABLE_VEHICLES:
|
2009-01-03 16:06:58 +00:00
|
|
|
ShowBuildVehicleWindow(INVALID_TILE, this->vehicle_type);
|
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:
|
|
|
|
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)
|
2008-12-28 14:37:19 +00:00
|
|
|
| this->vehicle_type, 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
|
|
|
}
|
|
|
|
|
2009-05-18 16:21:28 +00:00
|
|
|
case GRP_WIDGET_REPLACE_PROTECTION: {
|
|
|
|
const Group *g = Group::GetIfValid(this->group_sel);
|
|
|
|
if (g != NULL) {
|
2008-12-28 14:37:19 +00:00
|
|
|
DoCommandP(0, this->group_sel, !g->replace_protection, CMD_SET_GROUP_REPLACE_PROTECTION);
|
2008-05-11 15:00:11 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-05-18 16:21:28 +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 OnDragDrop(Point pt, int widget)
|
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case GRP_WIDGET_ALL_VEHICLES: // All vehicles
|
|
|
|
case GRP_WIDGET_DEFAULT_VEHICLES: // Ungrouped vehicles
|
2009-08-05 17:59:21 +00:00
|
|
|
DoCommandP(0, DEFAULT_GROUP, this->vehicle_sel, CMD_ADD_VEHICLE_GROUP | CMD_MSG(STR_ERROR_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();
|
|
|
|
break;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-05-11 15:00:11 +00:00
|
|
|
case GRP_WIDGET_LIST_GROUP: { // Maxtrix group
|
2009-11-16 21:28:12 +00:00
|
|
|
uint16 id_g = (pt.y - this->GetWidget<NWidgetBase>(GRP_WIDGET_LIST_GROUP)->pos_y) / (int)this->tiny_step_height;
|
2008-05-11 15:00:11 +00:00
|
|
|
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
|
|
|
|
2009-09-02 07:36:39 +00:00
|
|
|
if (id_g >= this->vscroll2.GetCapacity()) return;
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2009-09-02 07:36:39 +00:00
|
|
|
id_g += this->vscroll2.GetPosition();
|
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
|
|
|
|
2009-08-05 17:59:21 +00:00
|
|
|
DoCommandP(0, this->groups[id_g]->index, vindex, CMD_ADD_VEHICLE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_ADD_VEHICLE));
|
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
|
2009-11-13 21:42:49 +00:00
|
|
|
uint32 id_v = (pt.y - this->GetWidget<NWidgetBase>(GRP_WIDGET_LIST_VEHICLE)->pos_y) / (int)this->resize.step_height;
|
2008-05-11 15:00:11 +00:00
|
|
|
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
|
|
|
|
2009-09-02 07:36:39 +00:00
|
|
|
if (id_v >= this->vscroll.GetCapacity()) return; // click out of bounds
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2009-09-02 07:36:39 +00:00
|
|
|
id_v += this->vscroll.GetPosition();
|
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
|
|
|
|
2009-11-13 18:17:46 +00:00
|
|
|
const Vehicle *v = this->vehicles[id_v];
|
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)
|
|
|
|
{
|
2009-08-24 21:51:02 +00:00
|
|
|
if (str != NULL) DoCommandP(0, this->group_rename, 0, CMD_RENAME_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_RENAME), NULL, str);
|
|
|
|
this->group_rename = INVALID_GROUP;
|
2008-05-11 15:00:11 +00:00
|
|
|
}
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2009-10-24 14:53:55 +00:00
|
|
|
virtual void OnResize()
|
2008-05-11 15:00:11 +00:00
|
|
|
{
|
2009-11-13 21:42:49 +00:00
|
|
|
NWidgetCore *nwi = this->GetWidget<NWidgetCore>(GRP_WIDGET_LIST_GROUP);
|
2009-11-16 21:28:12 +00:00
|
|
|
this->vscroll2.SetCapacity(nwi->current_y / this->tiny_step_height);
|
2009-11-13 21:42:49 +00:00
|
|
|
nwi->widget_data = (this->vscroll2.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
|
2009-10-17 14:29:10 +00:00
|
|
|
|
2009-11-13 21:42:49 +00:00
|
|
|
nwi = this->GetWidget<NWidgetCore>(GRP_WIDGET_LIST_VEHICLE);
|
2009-12-20 20:08:39 +00:00
|
|
|
this->vscroll.SetCapacityFromWidget(this, GRP_WIDGET_LIST_VEHICLE);
|
2009-11-13 21:42:49 +00:00
|
|
|
nwi->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
|
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 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
|
2008-12-28 14:37:19 +00:00
|
|
|
| DEPOT_SERVICE, GetCmdSendToDepot(this->vehicle_type));
|
2008-05-11 15:00:11 +00:00
|
|
|
break;
|
|
|
|
case GALF_DEPOT: // Send to Depots
|
|
|
|
DoCommandP(0, this->group_sel, ((IsAllGroupID(this->group_sel) ? VLW_STANDARD : VLW_GROUP_LIST) & VLW_MASK)
|
2008-12-28 14:37:19 +00:00
|
|
|
| DEPOT_MASS_SEND, GetCmdSendToDepot(this->vehicle_type));
|
2008-05-11 15:00:11 +00:00
|
|
|
break;
|
|
|
|
case GALF_ADD_SHARED: // Add shared Vehicles
|
2009-05-17 01:00:56 +00:00
|
|
|
assert(Group::IsValidID(this->group_sel));
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2009-08-05 17:59:21 +00:00
|
|
|
DoCommandP(0, this->group_sel, this->vehicle_type, CMD_ADD_SHARED_VEHICLE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_ADD_SHARED_VEHICLE));
|
2008-05-11 15:00:11 +00:00
|
|
|
break;
|
|
|
|
case GALF_REMOVE_ALL: // Remove all Vehicles from the selected group
|
2009-05-17 01:00:56 +00:00
|
|
|
assert(Group::IsValidID(this->group_sel));
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2009-08-05 17:59:21 +00:00
|
|
|
DoCommandP(0, this->group_sel, this->vehicle_type, CMD_REMOVE_ALL_VEHICLES_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_REMOVE_ALL_VEHICLES));
|
2008-05-11 15:00:11 +00:00
|
|
|
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()
|
|
|
|
{
|
2009-05-06 15:06:57 +00:00
|
|
|
if (_pause_mode != PM_UNPAUSED) 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()
|
|
|
|
{
|
2008-09-13 10:04:36 +00:00
|
|
|
/* abort drag & drop */
|
|
|
|
this->vehicle_sel = INVALID_VEHICLE;
|
2009-09-13 19:15:59 +00:00
|
|
|
this->SetWidgetDirty(GRP_WIDGET_LIST_VEHICLE);
|
2008-05-11 15:00:11 +00:00
|
|
|
}
|
2009-01-08 21:16:19 +00:00
|
|
|
|
2009-08-25 10:44:19 +00:00
|
|
|
void ShowRenameGroupWindow(GroupID group)
|
|
|
|
{
|
|
|
|
assert(Group::IsValidID(group));
|
|
|
|
this->group_rename = group;
|
|
|
|
SetDParam(0, group);
|
|
|
|
ShowQueryString(STR_GROUP_NAME, STR_GROUP_RENAME_CAPTION, MAX_LENGTH_GROUP_NAME_BYTES, MAX_LENGTH_GROUP_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT);
|
|
|
|
}
|
|
|
|
|
2009-01-08 21:16:19 +00:00
|
|
|
/**
|
|
|
|
* Tests whether a given vehicle is selected in the window, and unselects it if necessary.
|
|
|
|
* Called when the vehicle is deleted.
|
|
|
|
* @param vehicle Vehicle that is going to be deleted
|
|
|
|
*/
|
|
|
|
void UnselectVehicle(VehicleID vehicle)
|
|
|
|
{
|
|
|
|
if (this->vehicle_sel == vehicle) ResetObjectToPlace();
|
|
|
|
}
|
2008-05-11 15:00:11 +00:00
|
|
|
};
|
2007-05-19 09:40:18 +00:00
|
|
|
|
|
|
|
|
2009-11-13 21:42:49 +00:00
|
|
|
static WindowDesc _other_group_desc(
|
2009-11-28 14:42:35 +00:00
|
|
|
WDP_AUTO, 460, 246,
|
2008-09-12 21:58:36 +00:00
|
|
|
WC_INVALID, WC_NONE,
|
2009-11-24 17:28:29 +00:00
|
|
|
WDF_UNCLICK_BUTTONS,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_group_widgets, lengthof(_nested_group_widgets)
|
2009-11-13 21:42:49 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const static WindowDesc _train_group_desc(
|
2009-11-28 14:42:35 +00:00
|
|
|
WDP_AUTO, 525, 246,
|
2009-11-13 21:42:49 +00:00
|
|
|
WC_TRAINS_LIST, WC_NONE,
|
2009-11-24 17:28:29 +00:00
|
|
|
WDF_UNCLICK_BUTTONS,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_group_widgets, lengthof(_nested_group_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
void ShowCompanyGroup(CompanyID company, VehicleType vehicle_type)
|
2007-05-19 09:40:18 +00:00
|
|
|
{
|
2009-05-17 01:00:56 +00:00
|
|
|
if (!Company::IsValidID(company)) return;
|
2007-08-04 01:25:44 +00:00
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
WindowNumber num = (vehicle_type << 11) | VLW_GROUP_LIST | company;
|
2009-11-13 21:42:49 +00:00
|
|
|
if (vehicle_type == VEH_TRAIN) {
|
|
|
|
AllocateWindowDescFront<VehicleGroupWindow>(&_train_group_desc, num);
|
|
|
|
} else {
|
|
|
|
_other_group_desc.cls = GetWindowClassForVehicleType(vehicle_type);
|
|
|
|
AllocateWindowDescFront<VehicleGroupWindow>(&_other_group_desc, num);
|
|
|
|
}
|
2007-05-19 09:40:18 +00:00
|
|
|
}
|
2009-01-08 21:16:19 +00:00
|
|
|
|
2009-08-25 10:44:19 +00:00
|
|
|
/**
|
|
|
|
* Finds a group list window determined by vehicle type and owner
|
|
|
|
* @param vt vehicle type
|
|
|
|
* @param owner owner of groups
|
|
|
|
* @return pointer to VehicleGroupWindow, NULL if not found
|
|
|
|
*/
|
|
|
|
static inline VehicleGroupWindow *FindVehicleGroupWindow(VehicleType vt, Owner owner)
|
|
|
|
{
|
|
|
|
return (VehicleGroupWindow *)FindWindowById(GetWindowClassForVehicleType(vt), (vt << 11) | VLW_GROUP_LIST | owner);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens a 'Rename group' window for newly created group
|
|
|
|
* @param success did command succeed?
|
|
|
|
* @param tile unused
|
|
|
|
* @param p1 vehicle type
|
|
|
|
* @param p2 unused
|
|
|
|
* @see CmdCreateGroup
|
|
|
|
*/
|
2010-01-11 18:46:09 +00:00
|
|
|
void CcCreateGroup(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
|
2009-08-25 10:44:19 +00:00
|
|
|
{
|
2010-01-11 18:46:09 +00:00
|
|
|
if (result.Failed()) return;
|
2009-08-25 10:44:19 +00:00
|
|
|
assert(p1 <= VEH_AIRCRAFT);
|
|
|
|
|
|
|
|
VehicleGroupWindow *w = FindVehicleGroupWindow((VehicleType)p1, _current_company);
|
|
|
|
if (w != NULL) w->ShowRenameGroupWindow(_new_group_id);
|
|
|
|
}
|
|
|
|
|
2009-01-08 21:16:19 +00:00
|
|
|
/**
|
|
|
|
* Removes the highlight of a vehicle in a group window
|
|
|
|
* @param *v Vehicle to remove all highlights from
|
|
|
|
*/
|
|
|
|
void DeleteGroupHighlightOfVehicle(const Vehicle *v)
|
|
|
|
{
|
|
|
|
/* If we haven't got any vehicles on the mouse pointer, we haven't got any highlighted in any group windows either
|
|
|
|
* If that is the case, we can skip looping though the windows and save time
|
|
|
|
*/
|
|
|
|
if (_special_mouse_mode != WSM_DRAGDROP) return;
|
|
|
|
|
2009-08-25 10:44:19 +00:00
|
|
|
VehicleGroupWindow *w = FindVehicleGroupWindow(v->type, v->owner);
|
2009-01-08 21:16:19 +00:00
|
|
|
if (w != NULL) w->UnselectVehicle(v->index);
|
|
|
|
}
|