mirror of https://github.com/OpenTTD/OpenTTD
Encoded error message was previously static to avoid memmory allocation, however this causes complications.pull/13829/head
parent
0cd87bc8c1
commit
a87b804386
|
@ -235,7 +235,7 @@ std::tuple<bool, bool, bool> CommandHelperBase::InternalPostBefore(Commands cmd,
|
|||
* @param err_message Message prefix to show on error.
|
||||
* @param my_cmd Is the command from this client?
|
||||
*/
|
||||
void CommandHelperBase::InternalPostResult(const CommandCost &res, TileIndex tile, bool estimate_only, bool only_sending, StringID err_message, bool my_cmd)
|
||||
void CommandHelperBase::InternalPostResult(CommandCost &res, TileIndex tile, bool estimate_only, bool only_sending, StringID err_message, bool my_cmd)
|
||||
{
|
||||
int x = TileX(tile) * TILE_SIZE;
|
||||
int y = TileY(tile) * TILE_SIZE;
|
||||
|
@ -407,8 +407,6 @@ void CommandCost::AddCost(const CommandCost &ret)
|
|||
}
|
||||
}
|
||||
|
||||
/* static */ EncodedString CommandCost::encoded_message;
|
||||
|
||||
/**
|
||||
* Return an error status, with string and parameter.
|
||||
* @param str StringID of error.
|
||||
|
|
|
@ -87,7 +87,7 @@ protected:
|
|||
static void InternalDoBefore(bool top_level, bool test);
|
||||
static void InternalDoAfter(CommandCost &res, DoCommandFlags flags, bool top_level, bool test);
|
||||
static std::tuple<bool, bool, bool> InternalPostBefore(Commands cmd, CommandFlags flags, TileIndex tile, StringID err_message, bool network_command);
|
||||
static void InternalPostResult(const CommandCost &res, TileIndex tile, bool estimate_only, bool only_sending, StringID err_message, bool my_cmd);
|
||||
static void InternalPostResult(CommandCost &res, TileIndex tile, bool estimate_only, bool only_sending, StringID err_message, bool my_cmd);
|
||||
static bool InternalExecutePrepTest(CommandFlags cmd_flags, TileIndex tile, Backup<CompanyID> &cur_company);
|
||||
static std::tuple<bool, bool, bool> InternalExecuteValidateTestAndPrepExec(CommandCost &res, CommandFlags cmd_flags, bool estimate_only, bool network_command, Backup<CompanyID> &cur_company);
|
||||
static CommandCost InternalExecuteProcessResult(Commands cmd, CommandFlags cmd_flags, const CommandCost &res_test, const CommandCost &res_exec, Money extra_cash, TileIndex tile, Backup<CompanyID> &cur_company);
|
||||
|
|
|
@ -28,8 +28,7 @@ class CommandCost {
|
|||
bool success; ///< Whether the command went fine up to this moment
|
||||
Owner owner = CompanyID::Invalid(); ///< Originator owner of error.
|
||||
StringID extra_message = INVALID_STRING_ID; ///< Additional warning message for when success is unset
|
||||
|
||||
static EncodedString encoded_message; ///< Encoded error message, used if the error message includes parameters.
|
||||
EncodedString encoded_message{}; ///< Encoded error message, used if the error message includes parameters.
|
||||
|
||||
public:
|
||||
/**
|
||||
|
@ -70,18 +69,18 @@ public:
|
|||
* @note Do not set an encoded message if the error is not for the local player, as it will never be seen.
|
||||
* @param message EncodedString message to set.
|
||||
*/
|
||||
static void SetEncodedMessage(EncodedString &&message)
|
||||
void SetEncodedMessage(EncodedString &&message)
|
||||
{
|
||||
CommandCost::encoded_message = std::move(message);
|
||||
this->encoded_message = std::move(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last encoded error message.
|
||||
* @returns Reference to the encoded message.
|
||||
*/
|
||||
static EncodedString &GetEncodedMessage()
|
||||
EncodedString &GetEncodedMessage()
|
||||
{
|
||||
return CommandCost::encoded_message;
|
||||
return this->encoded_message;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -50,7 +50,7 @@ typedef std::list<ErrorMessageData> ErrorList;
|
|||
void ScheduleErrorMessage(ErrorList &datas);
|
||||
void ScheduleErrorMessage(const ErrorMessageData &data);
|
||||
|
||||
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, const CommandCost &cc);
|
||||
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc);
|
||||
void ShowErrorMessage(EncodedString &&summary_msg, EncodedString &&detailed_msg, WarningLevel wl, int x = 0, int y = 0, EncodedString &&extra_msg = {}, CompanyID company = CompanyID::Invalid());
|
||||
bool HideActiveErrorMessage();
|
||||
|
||||
|
|
|
@ -287,7 +287,7 @@ void UnshowCriticalError()
|
|||
* @param y World Y position (TileVirtY) of the error location. Set both x and y to 0 to just center the message when there is no related error tile.
|
||||
* @param cc CommandCost containing the optional detailed and extra error messages shown in the second and third lines (can be empty).
|
||||
*/
|
||||
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, const CommandCost &cc)
|
||||
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc)
|
||||
{
|
||||
EncodedString error = std::move(cc.GetEncodedMessage());
|
||||
if (error.empty()) error = GetEncodedStringIfValid(cc.GetErrorMessage());
|
||||
|
|
Loading…
Reference in New Issue