Changeset - r25966:8233c136b1b0
[Not reviewed]
master
0 2 0
Bernard Teo - 3 years ago 2021-05-31 07:59:17
btzy1996@hotmail.com
Feature: Ctrl-Clicking GB_SHARED_ORDERS vehicle list opens order window
2 files changed with 13 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/group_gui.cpp
Show inline comments
 
/*
 
 * 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/>.
 
 */
 

	
 
/** @file group_gui.cpp GUI for the group window. */
 

	
 
#include "stdafx.h"
 
#include "textbuf_gui.h"
 
#include "command_func.h"
 
#include "vehicle_gui.h"
 
#include "vehicle_base.h"
 
#include "string_func.h"
 
#include "strings_func.h"
 
#include "window_func.h"
 
#include "vehicle_func.h"
 
#include "autoreplace_gui.h"
 
#include "company_func.h"
 
#include "widgets/dropdown_func.h"
 
#include "tilehighlight_func.h"
 
#include "vehicle_gui_base.h"
 
#include "core/geometry_func.hpp"
 
#include "company_base.h"
 
#include "company_gui.h"
 
#include "gui.h"
 

	
 
#include "widgets/group_widget.h"
 

	
 
#include "table/sprites.h"
 

	
 
#include "safeguards.h"
 

	
 
static const int LEVEL_WIDTH = 10; ///< Indenting width of a sub-group in pixels
 

	
 
typedef GUIList<const Group*> GUIGroupList;
 

	
 
static const NWidgetPart _nested_group_widgets[] = {
 
	NWidget(NWID_HORIZONTAL), // Window header
 
		NWidget(WWT_CLOSEBOX, COLOUR_GREY),
 
		NWidget(WWT_CAPTION, COLOUR_GREY, WID_GL_CAPTION),
 
		NWidget(WWT_SHADEBOX, COLOUR_GREY),
 
		NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
 
		NWidget(WWT_STICKYBOX, COLOUR_GREY),
 
	EndContainer(),
 
	NWidget(NWID_HORIZONTAL),
 
		/* left part */
 
		NWidget(NWID_VERTICAL),
 
			NWidget(WWT_PANEL, COLOUR_GREY, WID_GL_ALL_VEHICLES), SetFill(1, 0), EndContainer(),
 
			NWidget(WWT_PANEL, COLOUR_GREY, WID_GL_DEFAULT_VEHICLES), SetFill(1, 0), EndContainer(),
 
			NWidget(NWID_HORIZONTAL),
 
				NWidget(WWT_MATRIX, COLOUR_GREY, WID_GL_LIST_GROUP), SetMatrixDataTip(1, 0, STR_GROUPS_CLICK_ON_GROUP_FOR_TOOLTIP),
 
						SetFill(1, 0), SetResize(0, 1), SetScrollbar(WID_GL_LIST_GROUP_SCROLLBAR),
 
				NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_GL_LIST_GROUP_SCROLLBAR),
 
			EndContainer(),
 
			NWidget(WWT_PANEL, COLOUR_GREY, WID_GL_INFO), SetFill(1, 1), SetMinimalTextLines(3, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM), EndContainer(),
 
			NWidget(NWID_HORIZONTAL),
 
				NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_GL_CREATE_GROUP),
 
						SetDataTip(SPR_GROUP_CREATE_TRAIN, STR_GROUP_CREATE_TOOLTIP),
 
				NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_GL_DELETE_GROUP),
 
						SetDataTip(SPR_GROUP_DELETE_TRAIN, STR_GROUP_DELETE_TOOLTIP),
 
				NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_GL_RENAME_GROUP),
 
						SetDataTip(SPR_GROUP_RENAME_TRAIN, STR_GROUP_RENAME_TOOLTIP),
 
				NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_GL_LIVERY_GROUP),
 
						SetDataTip(SPR_GROUP_LIVERY_TRAIN, STR_GROUP_LIVERY_TOOLTIP),
 
				NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 0), EndContainer(),
 
				NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_GL_REPLACE_PROTECTION),
 
						SetDataTip(SPR_GROUP_REPLACE_OFF_TRAIN, STR_GROUP_REPLACE_PROTECTION_TOOLTIP),
 
			EndContainer(),
 
		EndContainer(),
 
		/* right part */
 
		NWidget(NWID_VERTICAL),
 
			NWidget(NWID_HORIZONTAL),
 
				NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GL_GROUP_BY_ORDER), SetMinimalSize(81, 12), SetDataTip(STR_STATION_VIEW_GROUP, STR_TOOLTIP_GROUP_ORDER),
 
@@ -700,108 +701,110 @@ public:
 

	
 
						Group::Get(groups[id_g]->index)->folded = !groups[id_g]->folded;
 
						this->groups.ForceRebuild();
 

	
 
						this->SetDirty();
 
						break;
 
					}
 
				}
 

	
 
				this->group_sel = this->vli.index = this->groups[id_g]->index;
 

	
 
				SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
 

	
 
				this->vehgroups.ForceRebuild();
 
				this->SetDirty();
 
				break;
 
			}
 

	
 
			case WID_GL_LIST_VEHICLE: { // Matrix Vehicle
 
				uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GL_LIST_VEHICLE);
 
				if (id_v >= this->vehgroups.size()) return; // click out of list bound
 

	
 
				const GUIVehicleGroup &vehgroup = this->vehgroups[id_v];
 

	
 
				const Vehicle *v = nullptr;
 

	
 
				switch (this->grouping) {
 
					case GB_NONE: {
 
						const Vehicle *v2 = vehgroup.GetSingleVehicle();
 
						if (VehicleClicked(v2)) break;
 
						v = v2;
 
						break;
 
					}
 

	
 
					case GB_SHARED_ORDERS: {
 
						assert(vehgroup.NumVehicles() > 0);
 
						v = vehgroup.vehicles_begin[0];
 
						/*
 
						 * No VehicleClicked(v) support for now, because don't want
 
						 * to enable any contextual actions except perhaps clicking/ctrl-clicking to clone orders.
 
						 */
 
						break;
 
					}
 

	
 
					default:
 
						NOT_REACHED();
 
				}
 
				if (v) {
 
					if (_ctrl_pressed) {
 
						if (this->grouping == GB_NONE) {
 
							this->SelectGroup(v->group_id);
 
						} else {
 
							ShowOrdersWindow(v);
 
						}
 
					} else {
 
					this->vehicle_sel = v->index;
 

	
 
					if (_ctrl_pressed) {
 
						this->SelectGroup(v->group_id);
 
					}
 

	
 
					SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
 
					SetMouseCursorVehicle(v, EIT_IN_LIST);
 
					_cursor.vehchain = true;
 

	
 
					this->SetDirty();
 
				}
 
				}
 

	
 
				break;
 
			}
 

	
 
			case WID_GL_CREATE_GROUP: { // Create a new group
 
				DoCommandP(0, this->vli.vtype, this->vli.index, CMD_CREATE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_CREATE), CcCreateGroup);
 
				break;
 
			}
 

	
 
			case WID_GL_DELETE_GROUP: { // Delete the selected group
 
				this->group_confirm = this->vli.index;
 
				ShowQuery(STR_QUERY_GROUP_DELETE_CAPTION, STR_GROUP_DELETE_QUERY_TEXT, this, DeleteGroupCallback);
 
				break;
 
			}
 

	
 
			case WID_GL_RENAME_GROUP: // Rename the selected roup
 
				this->ShowRenameGroupWindow(this->vli.index, false);
 
				break;
 

	
 
			case WID_GL_LIVERY_GROUP: // Set group livery
 
				ShowCompanyLiveryWindow(this->owner, this->vli.index);
 
				break;
 

	
 
			case WID_GL_AVAILABLE_VEHICLES:
 
				ShowBuildVehicleWindow(INVALID_TILE, this->vli.vtype);
 
				break;
 

	
 
			case WID_GL_MANAGE_VEHICLES_DROPDOWN: {
 
				ShowDropDownList(this, this->BuildActionDropdownList(true, Group::IsValidID(this->vli.index)), 0, WID_GL_MANAGE_VEHICLES_DROPDOWN);
 
				break;
 
			}
 

	
 
			case WID_GL_START_ALL:
 
			case WID_GL_STOP_ALL: { // Start/stop all vehicles of the list
 
				DoCommandP(0, (1 << 1) | (widget == WID_GL_START_ALL ? (1 << 0) : 0), this->vli.Pack(), CMD_MASS_START_STOP);
 
				break;
 
			}
 

	
 
			case WID_GL_REPLACE_PROTECTION: {
 
				const Group *g = Group::GetIfValid(this->vli.index);
 
				if (g != nullptr) {
 
					DoCommandP(0, this->vli.index | (GroupFlags::GF_REPLACE_PROTECTION << 16), (HasBit(g->flags, GroupFlags::GF_REPLACE_PROTECTION) ? 0 : 1) | (_ctrl_pressed << 1), CMD_SET_GROUP_FLAG);
 
				}
 
				break;
 
			}
 
		}
 
	}
 

	
src/vehicle_gui.cpp
Show inline comments
 
@@ -1798,101 +1798,105 @@ public:
 
		this->GetWidget<NWidgetCore>(WID_VL_GROUP_BY_PULLDOWN)->widget_data = this->vehicle_group_by_names[this->grouping];
 

	
 
		/* Set text of sort by dropdown widget. */
 
		this->GetWidget<NWidgetCore>(WID_VL_SORT_BY_PULLDOWN)->widget_data = this->GetVehicleSorterNames()[this->vehgroups.SortType()];
 

	
 
		this->DrawWidgets();
 
	}
 

	
 
	void OnClick(Point pt, int widget, int click_count) override
 
	{
 
		switch (widget) {
 
			case WID_VL_SORT_ORDER: // Flip sorting method ascending/descending
 
				this->vehgroups.ToggleSortOrder();
 
				this->SetDirty();
 
				break;
 

	
 
			case WID_VL_GROUP_BY_PULLDOWN: // Select sorting criteria dropdown menu
 
				ShowDropDownMenu(this, this->vehicle_group_by_names, this->grouping, WID_VL_GROUP_BY_PULLDOWN, 0, 0);
 
				return;
 

	
 
			case WID_VL_SORT_BY_PULLDOWN: // Select sorting criteria dropdown menu
 
				ShowDropDownMenu(this, this->GetVehicleSorterNames(), this->vehgroups.SortType(), WID_VL_SORT_BY_PULLDOWN, 0,
 
						(this->vli.vtype == VEH_TRAIN || this->vli.vtype == VEH_ROAD) ? 0 : (1 << 10));
 
				return;
 

	
 
			case WID_VL_LIST: { // Matrix to show vehicles
 
				uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_VL_LIST);
 
				if (id_v >= this->vehgroups.size()) return; // click out of list bound
 

	
 
				const GUIVehicleGroup &vehgroup = this->vehgroups[id_v];
 
				switch (this->grouping) {
 
					case GB_NONE: {
 
						const Vehicle *v = vehgroup.GetSingleVehicle();
 
						if (!VehicleClicked(v)) {
 
							if (_ctrl_pressed) {
 
								ShowCompanyGroupForVehicle(v);
 
							} else {
 
								ShowVehicleViewWindow(v);
 
							}
 
						}
 
						break;
 
					}
 

	
 
					case GB_SHARED_ORDERS: {
 
						assert(vehgroup.NumVehicles() > 0);
 
						const Vehicle *v = vehgroup.vehicles_begin[0];
 
						/* We do not support VehicleClicked() here since the contextual action may only make sense for individual vehicles */
 

	
 
						if (_ctrl_pressed) {
 
							ShowOrdersWindow(v);
 
						} else {
 
						if (vehgroup.NumVehicles() == 1) {
 
							ShowVehicleViewWindow(v);
 
						} else {
 
							ShowVehicleListWindow(v);
 
						}
 
						}
 
						break;
 
					}
 

	
 
					default: NOT_REACHED();
 
				}
 

	
 
				break;
 
			}
 

	
 
			case WID_VL_AVAILABLE_VEHICLES:
 
				ShowBuildVehicleWindow(INVALID_TILE, this->vli.vtype);
 
				break;
 

	
 
			case WID_VL_MANAGE_VEHICLES_DROPDOWN: {
 
				ShowDropDownList(this, this->BuildActionDropdownList(VehicleListIdentifier::UnPack(this->window_number).type == VL_STANDARD, false), 0, WID_VL_MANAGE_VEHICLES_DROPDOWN);
 
				break;
 
			}
 

	
 
			case WID_VL_STOP_ALL:
 
			case WID_VL_START_ALL:
 
				DoCommandP(0, (1 << 1) | (widget == WID_VL_START_ALL ? (1 << 0) : 0), this->window_number, CMD_MASS_START_STOP);
 
				break;
 
		}
 
	}
 

	
 
	void OnDropdownSelect(int widget, int index) override
 
	{
 
		switch (widget) {
 
			case WID_VL_GROUP_BY_PULLDOWN:
 
				this->UpdateVehicleGroupBy(static_cast<GroupBy>(index));
 
				break;
 

	
 
			case WID_VL_SORT_BY_PULLDOWN:
 
				this->vehgroups.SetSortType(index);
 
				break;
 

	
 
			case WID_VL_MANAGE_VEHICLES_DROPDOWN:
 
				assert(this->vehicles.size() != 0);
 

	
 
				switch (index) {
 
					case ADI_REPLACE: // Replace window
 
						ShowReplaceGroupVehicleWindow(ALL_GROUP, this->vli.vtype);
 
						break;
 
					case ADI_SERVICE: // Send for servicing
 
					case ADI_DEPOT: // Send to Depots
 
						DoCommandP(0, DEPOT_MASS_SEND | (index == ADI_SERVICE ? DEPOT_SERVICE : (DepotCommand)0), this->window_number, GetCmdSendToDepot(this->vli.vtype));
 
						break;
 

	
0 comments (0 inline, 0 general)