Fix order hotkeys
This commit is contained in:
@@ -26,13 +26,13 @@ namespace citymania {
|
|||||||
|
|
||||||
typedef std::function<bool(bool)> CommandCallback;
|
typedef std::function<bool(bool)> CommandCallback;
|
||||||
|
|
||||||
extern bool _auto_command;
|
extern bool _no_estimate_command;
|
||||||
extern CommandCallback _current_callback;
|
extern CommandCallback _current_callback;
|
||||||
|
|
||||||
class Command {
|
class Command {
|
||||||
public:
|
public:
|
||||||
TileIndex tile = 0;
|
TileIndex tile = 0;
|
||||||
bool automatic = false;
|
bool no_estimate_flag = false;
|
||||||
CompanyID company = INVALID_COMPANY;
|
CompanyID company = INVALID_COMPANY;
|
||||||
StringID error = (StringID)0;
|
StringID error = (StringID)0;
|
||||||
CommandCallback callback = nullptr;
|
CommandCallback callback = nullptr;
|
||||||
@@ -50,11 +50,11 @@ public:
|
|||||||
CompanyID old = _current_company;
|
CompanyID old = _current_company;
|
||||||
if (this->company != INVALID_COMPANY)
|
if (this->company != INVALID_COMPANY)
|
||||||
_current_company = company;
|
_current_company = company;
|
||||||
_auto_command = this->automatic;
|
_no_estimate_command = this->no_estimate_flag;
|
||||||
_current_callback = this->callback;
|
_current_callback = this->callback;
|
||||||
bool res = this->_post(reinterpret_cast<::CommandCallback *>(reinterpret_cast<void(*)()>(callback)));
|
bool res = this->_post(reinterpret_cast<::CommandCallback *>(reinterpret_cast<void(*)()>(callback)));
|
||||||
_current_callback = nullptr;
|
_current_callback = nullptr;
|
||||||
_auto_command = false;
|
_no_estimate_command = false;
|
||||||
_current_company = old;
|
_current_company = old;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -86,8 +86,8 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Command &set_auto() {
|
Command &no_estimate() {
|
||||||
this->automatic = true;
|
this->no_estimate_flag = true;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ const uint32 MAX_CALLBACK_LIFETIME = 30; // it should be executed within few fr
|
|||||||
std::map<size_t, std::pair<uint32, std::vector<CommandCallback>>> _command_callbacks;
|
std::map<size_t, std::pair<uint32, std::vector<CommandCallback>>> _command_callbacks;
|
||||||
std::queue<std::pair<size_t, uint32>> _command_sent;
|
std::queue<std::pair<size_t, uint32>> _command_sent;
|
||||||
CommandCallback _current_callback = nullptr;
|
CommandCallback _current_callback = nullptr;
|
||||||
bool _auto_command = false;
|
bool _no_estimate_command = false;
|
||||||
std::queue<std::pair<size_t, CommandCallback>> _callback_queue;
|
std::queue<std::pair<size_t, CommandCallback>> _callback_queue;
|
||||||
|
|
||||||
uint GetCurrentQueueDelay();
|
uint GetCurrentQueueDelay();
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ std::tuple<bool, bool, bool> CommandHelperBase::InternalPostBefore(Commands cmd,
|
|||||||
* However, in case of incoming network commands,
|
* However, in case of incoming network commands,
|
||||||
* map generation or the pause button we do want
|
* map generation or the pause button we do want
|
||||||
* to execute. */
|
* to execute. */
|
||||||
bool estimate_only = citymania::_estimate_mod && IsLocalCompany() && !_generating_world && !network_command && !(flags & CMD_NO_EST) && !citymania::_auto_command;
|
bool estimate_only = citymania::_estimate_mod && IsLocalCompany() && !_generating_world && !network_command && !(flags & CMD_NO_EST) && !citymania::_no_estimate_command;
|
||||||
|
|
||||||
/* We're only sending the command, so don't do
|
/* We're only sending the command, so don't do
|
||||||
* fancy things for 'success'. */
|
* fancy things for 'success'. */
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
#include "widgets/order_widget.h"
|
#include "widgets/order_widget.h"
|
||||||
|
|
||||||
|
#include "citymania/cm_commands.hpp"
|
||||||
#include "citymania/cm_hotkeys.hpp"
|
#include "citymania/cm_hotkeys.hpp"
|
||||||
|
|
||||||
#include "safeguards.h"
|
#include "safeguards.h"
|
||||||
@@ -814,6 +815,7 @@ private:
|
|||||||
if (citymania::_fn_mod && this->vehicle->cur_implicit_order_index == this->OrderGetSel()) return;
|
if (citymania::_fn_mod && this->vehicle->cur_implicit_order_index == this->OrderGetSel()) return;
|
||||||
if (this->vehicle->GetNumOrders() <= 1) return;
|
if (this->vehicle->GetNumOrders() <= 1) return;
|
||||||
|
|
||||||
|
// TODO no estimate
|
||||||
Command<CMD_SKIP_TO_ORDER>::Post(_ctrl_pressed ? STR_ERROR_CAN_T_SKIP_TO_ORDER : STR_ERROR_CAN_T_SKIP_ORDER,
|
Command<CMD_SKIP_TO_ORDER>::Post(_ctrl_pressed ? STR_ERROR_CAN_T_SKIP_TO_ORDER : STR_ERROR_CAN_T_SKIP_ORDER,
|
||||||
this->vehicle->tile, this->vehicle->index, citymania::_fn_mod ? this->OrderGetSel() : ((this->vehicle->cur_implicit_order_index + 1) % this->vehicle->GetNumOrders()));
|
this->vehicle->tile, this->vehicle->index, citymania::_fn_mod ? this->OrderGetSel() : ((this->vehicle->cur_implicit_order_index + 1) % this->vehicle->GetNumOrders()));
|
||||||
}
|
}
|
||||||
@@ -1581,16 +1583,36 @@ public:
|
|||||||
|
|
||||||
if (feeder_mod != FeederOrderMod::NONE) {
|
if (feeder_mod != FeederOrderMod::NONE) {
|
||||||
if (feeder_mod == FeederOrderMod::LOAD) {
|
if (feeder_mod == FeederOrderMod::LOAD) {
|
||||||
if (Command<CMD_INSERT_ORDER>::Post(STR_ERROR_CAN_T_INSERT_NEW_ORDER, this->vehicle->tile, this->vehicle->index, 1, cmd)) {
|
if (citymania::cmd::InsertOrder(this->vehicle->index, 1, cmd)
|
||||||
Command<CMD_DELETE_ORDER>::Post(STR_ERROR_CAN_T_DELETE_THIS_ORDER, this->vehicle->tile, this->vehicle->index, 0);
|
.with_tile(this->vehicle->tile)
|
||||||
|
.with_error(STR_ERROR_CAN_T_INSERT_NEW_ORDER)
|
||||||
|
.no_estimate()
|
||||||
|
.post()) {
|
||||||
|
citymania::cmd::DeleteOrder(this->vehicle->index, 0)
|
||||||
|
.with_tile(this->vehicle->tile)
|
||||||
|
.with_error(STR_ERROR_CAN_T_DELETE_THIS_ORDER)
|
||||||
|
.no_estimate()
|
||||||
|
.post();
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (feeder_mod == FeederOrderMod::UNLOAD) { // still flushes the whole order table
|
} else if (feeder_mod == FeederOrderMod::UNLOAD) { // still flushes the whole order table
|
||||||
if (Command<CMD_INSERT_ORDER>::Post(STR_ERROR_CAN_T_INSERT_NEW_ORDER, this->vehicle->tile, this->vehicle->index, this->vehicle->GetNumOrders(), cmd)) {
|
if (citymania::cmd::InsertOrder(this->vehicle->index, this->vehicle->GetNumOrders(), cmd)
|
||||||
Command<CMD_DELETE_ORDER>::Post(STR_ERROR_CAN_T_DELETE_THIS_ORDER, this->vehicle->tile, this->vehicle->index, this->vehicle->GetNumOrders() + (int)_networking - 2);
|
.with_tile(this->vehicle->tile)
|
||||||
|
.with_error(STR_ERROR_CAN_T_INSERT_NEW_ORDER)
|
||||||
|
.no_estimate()
|
||||||
|
.post()) {
|
||||||
|
citymania::cmd::DeleteOrder(this->vehicle->index, this->vehicle->GetNumOrders() + (int)_networking - 2)
|
||||||
|
.with_tile(this->vehicle->tile)
|
||||||
|
.with_error(STR_ERROR_CAN_T_DELETE_THIS_ORDER)
|
||||||
|
.no_estimate()
|
||||||
|
.post();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (Command<CMD_INSERT_ORDER>::Post(STR_ERROR_CAN_T_INSERT_NEW_ORDER, this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), cmd)) {
|
} else if (citymania::cmd::InsertOrder(this->vehicle->index, this->OrderGetSel(), cmd)
|
||||||
|
.with_tile(this->vehicle->tile)
|
||||||
|
.with_error(STR_ERROR_CAN_T_INSERT_NEW_ORDER)
|
||||||
|
.no_estimate()
|
||||||
|
.post()) {
|
||||||
/* With quick goto the Go To button stays active */
|
/* With quick goto the Go To button stays active */
|
||||||
if (!_settings_client.gui.quick_goto) ResetObjectToPlace();
|
if (!_settings_client.gui.quick_goto) ResetObjectToPlace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -921,7 +921,7 @@ static void DoRegularFunding(Town *t)
|
|||||||
|
|
||||||
citymania::cmd::DoTownAction(t->index, HK_FUND)
|
citymania::cmd::DoTownAction(t->index, HK_FUND)
|
||||||
.with_tile(t->xy)
|
.with_tile(t->xy)
|
||||||
.set_auto()
|
.no_estimate()
|
||||||
.as_company(_local_company)
|
.as_company(_local_company)
|
||||||
.post();
|
.post();
|
||||||
t->last_funding = _tick_counter;
|
t->last_funding = _tick_counter;
|
||||||
@@ -958,7 +958,7 @@ static void DoRegularAdvertising(Town *t) {
|
|||||||
|
|
||||||
citymania::cmd::DoTownAction(t->index, HK_LADVERT)
|
citymania::cmd::DoTownAction(t->index, HK_LADVERT)
|
||||||
.with_tile(t->xy)
|
.with_tile(t->xy)
|
||||||
.set_auto()
|
.no_estimate()
|
||||||
.as_company(_local_company)
|
.as_company(_local_company)
|
||||||
.post();
|
.post();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user