Merge branch 'master' into jgrpp

# Conflicts:
#	src/error.h
#	src/error_gui.cpp
#	src/linkgraph/linkgraph_gui.cpp
#	src/misc_gui.cpp
#	src/newgrf_gui.cpp
#	src/news_gui.cpp
#	src/rail_cmd.cpp
#	src/saveload/gamelog_sl.cpp
#	src/script/api/script_text.cpp
#	src/script/script_instance.cpp
#	src/statusbar_gui.cpp
#	src/strings.cpp
#	src/strings_func.h
#	src/strings_internal.h
#	src/table/settings/gui_settings.ini
#	src/table/settings/linkgraph_settings.ini
#	src/textbuf_gui.h
This commit is contained in:
Jonathan G Rennison
2023-11-09 01:35:31 +00:00
130 changed files with 1460 additions and 1263 deletions

View File

@@ -16,6 +16,7 @@
#include "gfx_func.h"
#include "string_func.h"
#include "company_base.h"
#include "company_func.h"
#include "company_manager_face.h"
#include "strings_func.h"
#include "zoom_func.h"
@@ -41,7 +42,7 @@ static const NWidgetPart _nested_errmsg_widgets[] = {
};
static WindowDesc _errmsg_desc(
WDP_MANUAL, "error", 0, 0,
WDP_MANUAL, nullptr, 0, 0,
WC_ERRMSG, WC_NONE,
0,
_nested_errmsg_widgets, lengthof(_nested_errmsg_widgets)
@@ -61,7 +62,7 @@ static const NWidgetPart _nested_errmsg_face_widgets[] = {
};
static WindowDesc _errmsg_face_desc(
WDP_MANUAL, "error_face", 0, 0,
WDP_MANUAL, nullptr, 0, 0,
WC_ERRMSG, WC_NONE,
0,
_nested_errmsg_face_widgets, lengthof(_nested_errmsg_face_widgets)
@@ -72,24 +73,10 @@ static WindowDesc _errmsg_face_desc(
* @param data The data to copy.
*/
ErrorMessageData::ErrorMessageData(const ErrorMessageData &data) :
display_timer(data.display_timer), textref_stack_grffile(data.textref_stack_grffile), textref_stack_size(data.textref_stack_size),
display_timer(data.display_timer), params(data.params), textref_stack_grffile(data.textref_stack_grffile), textref_stack_size(data.textref_stack_size),
summary_msg(data.summary_msg), detailed_msg(data.detailed_msg), extra_msg(data.extra_msg), position(data.position), face(data.face)
{
memcpy(this->textref_stack, data.textref_stack, sizeof(this->textref_stack));
memcpy(this->decode_params, data.decode_params, sizeof(this->decode_params));
memcpy(this->strings, data.strings, sizeof(this->strings));
for (size_t i = 0; i < lengthof(this->strings); i++) {
if (this->strings[i] != nullptr) {
this->strings[i] = stredup(this->strings[i]);
this->decode_params[i] = (size_t)this->strings[i];
}
}
}
/** Free all the strings. */
ErrorMessageData::~ErrorMessageData()
{
for (size_t i = 0; i < lengthof(this->strings); i++) free(this->strings[i]);
}
/**
@@ -115,9 +102,6 @@ ErrorMessageData::ErrorMessageData(StringID summary_msg, StringID detailed_msg,
this->position.x = x;
this->position.y = y;
memset(this->decode_params, 0, sizeof(this->decode_params));
memset(this->strings, 0, sizeof(this->strings));
if (textref_stack_size > 0) MemCpyT(this->textref_stack, textref_stack, textref_stack_size);
assert(summary_msg != INVALID_STRING_ID);
@@ -130,20 +114,16 @@ ErrorMessageData::ErrorMessageData(StringID summary_msg, StringID detailed_msg,
*/
void ErrorMessageData::CopyOutDParams()
{
/* Reset parameters */
for (size_t i = 0; i < lengthof(this->strings); i++) free(this->strings[i]);
memset(this->decode_params, 0, sizeof(this->decode_params));
memset(this->strings, 0, sizeof(this->strings));
if (this->detailed_msg == STR_ERROR_OWNED_BY) {
/* The parameters are set by SetDParamsForOwnedBy. */
CompanyID company = (CompanyID)GetDParam(OWNED_BY_OWNER_IN_PARAMETERS_OFFSET);
if (company < MAX_COMPANIES) face = company;
}
/* Get parameters using type information */
if (this->textref_stack_size > 0) StartTextRefStackUsage(this->textref_stack_grffile, this->textref_stack_size, this->textref_stack);
CopyOutDParam(this->decode_params, this->strings, this->detailed_msg == INVALID_STRING_ID ? this->summary_msg : this->detailed_msg, lengthof(this->decode_params));
CopyOutDParam(this->params, 20);
if (this->textref_stack_size > 0) StopTextRefStackUsage();
if (this->detailed_msg == STR_ERROR_OWNED_BY) {
CompanyID company = (CompanyID)GetDParamX(this->decode_params, 2);
if (company < MAX_COMPANIES) face = company;
}
}
/**
@@ -153,7 +133,8 @@ void ErrorMessageData::CopyOutDParams()
*/
void ErrorMessageData::SetDParam(uint n, uint64 v)
{
this->decode_params[n] = v;
if (n >= this->params.size()) this->params.resize(n + 1);
this->params[n] = v;
}
/**
@@ -163,8 +144,8 @@ void ErrorMessageData::SetDParam(uint n, uint64 v)
*/
void ErrorMessageData::SetDParamStr(uint n, const char *str)
{
free(this->strings[n]);
this->strings[n] = stredup(str);
if (n >= this->params.size()) this->params.resize(n + 1);
this->params[n] = str;
}
/**
@@ -174,7 +155,8 @@ void ErrorMessageData::SetDParamStr(uint n, const char *str)
*/
void ErrorMessageData::SetDParamStr(uint n, const std::string &str)
{
this->SetDParamStr(n, str.c_str());
if (n >= this->params.size()) this->params.resize(n + 1);
this->params[n] = str;
}
/** The actual queue with errors. */
@@ -199,7 +181,7 @@ public:
{
switch (widget) {
case WID_EM_MESSAGE: {
CopyInDParam(0, this->decode_params, lengthof(this->decode_params));
CopyInDParam(this->params);
if (this->textref_stack_size > 0) StartTextRefStackUsage(this->textref_stack_grffile, this->textref_stack_size, this->textref_stack);
this->height_summary = GetStringHeight(this->summary_msg, size->width);
@@ -267,7 +249,7 @@ public:
void SetStringParameters(int widget) const override
{
if (widget == WID_EM_CAPTION) CopyInDParam(0, this->decode_params, lengthof(this->decode_params));
if (widget == WID_EM_CAPTION) CopyInDParam(this->params);
}
void DrawWidget(const Rect &r, int widget) const override
@@ -280,7 +262,7 @@ public:
}
case WID_EM_MESSAGE:
CopyInDParam(0, this->decode_params, lengthof(this->decode_params));
CopyInDParam(this->params);
if (this->textref_stack_size > 0) StartTextRefStackUsage(this->textref_stack_grffile, this->textref_stack_size, this->textref_stack);
if (this->detailed_msg == INVALID_STRING_ID) {