Changeset - r24783:4ec9acbd5b7b
[Not reviewed]
master
0 1 0
Charles Pigott - 4 years ago 2021-02-13 18:49:50
charlespigott@googlemail.com
Change: Make order window hotkeys toggle for load & unload variants
1 file changed with 29 insertions and 47 deletions:
0 comments (0 inline, 0 general)
src/order_gui.cpp
Show inline comments
 
@@ -573,36 +573,31 @@ private:
 
		this->goto_type = type;
 
		this->SetWidgetDirty(WID_O_GOTO);
 
	}
 

	
 
	/**
 
	 * Handle the click on the full load button.
 
	 * @param load_type the way to load.
 
	 * @param load_type Load flag to apply. If matches existing load type, toggles to default of 'load if possible'.
 
	 * @param toggle If we toggle or not (used for hotkey behavior)
 
	 */
 
	void OrderClick_FullLoad(int load_type)
 
	void OrderClick_FullLoad(OrderLoadFlags load_type, bool toggle = false)
 
	{
 
		VehicleOrderID sel_ord = this->OrderGetSel();
 
		const Order *order = this->vehicle->GetOrder(sel_ord);
 

	
 
		if (order == nullptr || order->GetLoadType() == load_type) return;
 
		if (order == nullptr) return;
 

	
 
		if (load_type < 0) {
 
			load_type = order->GetLoadType() == OLF_LOAD_IF_POSSIBLE ? OLF_FULL_LOAD_ANY : OLF_LOAD_IF_POSSIBLE;
 
		if (toggle && order->GetLoadType() == load_type) {
 
			load_type = OLF_LOAD_IF_POSSIBLE; // reset to 'default'
 
		}
 
		if (order->GetLoadType() == load_type) return; // If we still match, do nothing
 

	
 
		DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_LOAD | (load_type << 4), CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
 
	}
 

	
 
	/**
 
	 * Handle the 'no loading' hotkey
 
	 */
 
	void OrderHotkey_NoLoad()
 
	{
 
		this->OrderClick_FullLoad(OLFB_NO_LOAD);
 
	}
 

	
 
	/**
 
	 * Handle the click on the service.
 
	 */
 
	void OrderClick_Service(int i)
 
	{
 
		VehicleOrderID sel_ord = this->OrderGetSel();
 

	
 
@@ -628,50 +623,37 @@ private:
 

	
 
		DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER));
 
	}
 

	
 
	/**
 
	 * Handle the click on the unload button.
 
	 * @param unload_type Unload flag to apply. If matches existing unload type, toggles to default of 'unload if possible'.
 
	 * @param toggle If we toggle or not (used for hotkey behavior)
 
	 */
 
	void OrderClick_Unload(int unload_type)
 
	void OrderClick_Unload(OrderUnloadFlags unload_type, bool toggle = false)
 
	{
 
		VehicleOrderID sel_ord = this->OrderGetSel();
 
		const Order *order = this->vehicle->GetOrder(sel_ord);
 

	
 
		if (order == nullptr || order->GetUnloadType() == unload_type) return;
 
		if (order == nullptr) return;
 

	
 
		if (unload_type < 0) {
 
			unload_type = order->GetUnloadType() == OUF_UNLOAD_IF_POSSIBLE ? OUFB_UNLOAD : OUF_UNLOAD_IF_POSSIBLE;
 
		if (toggle && order->GetUnloadType() == unload_type) {
 
			unload_type = OUF_UNLOAD_IF_POSSIBLE;
 
		}
 
		if (order->GetUnloadType() == unload_type) return; // If we still match, do nothing
 

	
 
		DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_UNLOAD | (unload_type << 4), CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
 

	
 
		/* Transfer orders with leave empty as default */
 
		if (unload_type == OUFB_TRANSFER) {
 
			DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_LOAD | (OLFB_NO_LOAD << 4), CMD_MODIFY_ORDER);
 
			this->SetWidgetDirty(WID_O_FULL_LOAD);
 
		}
 
	}
 

	
 
	/**
 
	 * Handle the transfer hotkey
 
	 */
 
	void OrderHotkey_Transfer()
 
	{
 
		this->OrderClick_Unload(OUFB_TRANSFER);
 
	}
 

	
 
	/**
 
	 * Handle the 'no unload' hotkey
 
	 */
 
	void OrderHotkey_NoUnload()
 
	{
 
		this->OrderClick_Unload(OUFB_NO_UNLOAD);
 
	}
 

	
 
	/**
 
	 * Handle the click on the nonstop button.
 
	 * @param non_stop what non-stop type to use; -1 to use the 'next' one.
 
	 */
 
	void OrderClick_Nonstop(int non_stop)
 
	{
 
		if (!this->vehicle->IsGroundVehicle()) return;
 
@@ -1259,21 +1241,21 @@ public:
 
					ShowDropDownMenu(this, this->vehicle->type == VEH_AIRCRAFT ? _order_goto_dropdown_aircraft : _order_goto_dropdown, sel, WID_O_GOTO, 0, 0);
 
				}
 
				break;
 

	
 
			case WID_O_FULL_LOAD:
 
				if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
 
					this->OrderClick_FullLoad(-1);
 
					this->OrderClick_FullLoad(OLF_FULL_LOAD_ANY, true);
 
				} else {
 
					ShowDropDownMenu(this, _order_full_load_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetLoadType(), WID_O_FULL_LOAD, 0, 2);
 
				}
 
				break;
 

	
 
			case WID_O_UNLOAD:
 
				if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
 
					this->OrderClick_Unload(-1);
 
					this->OrderClick_Unload(OUFB_UNLOAD, true);
 
				} else {
 
					ShowDropDownMenu(this, _order_unload_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetUnloadType(), WID_O_UNLOAD, 0, 8);
 
				}
 
				break;
 

	
 
			case WID_O_REFIT:
 
@@ -1358,17 +1340,17 @@ public:
 
		switch (widget) {
 
			case WID_O_NON_STOP:
 
				this->OrderClick_Nonstop(index);
 
				break;
 

	
 
			case WID_O_FULL_LOAD:
 
				this->OrderClick_FullLoad(index);
 
				this->OrderClick_FullLoad((OrderLoadFlags)index);
 
				break;
 

	
 
			case WID_O_UNLOAD:
 
				this->OrderClick_Unload(index);
 
				this->OrderClick_Unload((OrderUnloadFlags)index);
 
				break;
 

	
 
			case WID_O_GOTO:
 
				switch (index) {
 
					case 0: this->OrderClick_Goto(OPOS_GOTO); break;
 
					case 1: this->OrderClick_NearestDepot(); break;
 
@@ -1431,23 +1413,23 @@ public:
 

	
 
	EventState OnHotkey(int hotkey) override
 
	{
 
		if (this->vehicle->owner != _local_company) return ES_NOT_HANDLED;
 

	
 
		switch (hotkey) {
 
			case OHK_SKIP:           this->OrderClick_Skip();          break;
 
			case OHK_DELETE:         this->OrderClick_Delete();        break;
 
			case OHK_SKIP:           this->OrderClick_Skip(); break;
 
			case OHK_DELETE:         this->OrderClick_Delete(); break;
 
			case OHK_GOTO:           this->OrderClick_Goto(OPOS_GOTO); break;
 
			case OHK_NONSTOP:        this->OrderClick_Nonstop(-1);     break;
 
			case OHK_FULLLOAD:       this->OrderClick_FullLoad(-1);    break;
 
			case OHK_UNLOAD:         this->OrderClick_Unload(-1);      break;
 
			case OHK_NEAREST_DEPOT:  this->OrderClick_NearestDepot();  break;
 
			case OHK_ALWAYS_SERVICE: this->OrderClick_Service(-1);     break;
 
			case OHK_TRANSFER:       this->OrderHotkey_Transfer();     break;
 
			case OHK_NO_UNLOAD:      this->OrderHotkey_NoUnload();     break;
 
			case OHK_NO_LOAD:        this->OrderHotkey_NoLoad();       break;
 
			case OHK_NONSTOP:        this->OrderClick_Nonstop(-1); break;
 
			case OHK_FULLLOAD:       this->OrderClick_FullLoad(OLF_FULL_LOAD_ANY, true); break;
 
			case OHK_UNLOAD:         this->OrderClick_Unload(OUFB_UNLOAD, true); break;
 
			case OHK_NEAREST_DEPOT:  this->OrderClick_NearestDepot(); break;
 
			case OHK_ALWAYS_SERVICE: this->OrderClick_Service(-1); break;
 
			case OHK_TRANSFER:       this->OrderClick_Unload(OUFB_TRANSFER, true); break;
 
			case OHK_NO_UNLOAD:      this->OrderClick_Unload(OUFB_NO_UNLOAD, true); break;
 
			case OHK_NO_LOAD:        this->OrderClick_FullLoad(OLFB_NO_LOAD, true); break;
 
			default: return ES_NOT_HANDLED;
 
		}
 
		return ES_HANDLED;
 
	}
 

	
 
	void OnPlaceObject(Point pt, TileIndex tile) override
0 comments (0 inline, 0 general)