Merge branch 'master' into jgrpp

# Conflicts:
#	src/company_cmd.cpp
#	src/core/overflowsafe_type.hpp
#	src/economy.cpp
#	src/engine_base.h
#	src/ground_vehicle.cpp
#	src/group_gui.cpp
#	src/industry_cmd.cpp
#	src/industry_gui.cpp
#	src/newgrf_commons.cpp
#	src/newgrf_engine.cpp
#	src/newgrf_industries.cpp
#	src/newgrf_object.cpp
#	src/newgrf_roadstop.cpp
#	src/newgrf_station.cpp
#	src/rail_gui.cpp
#	src/road_cmd.h
#	src/road_gui.cpp
#	src/saveload/afterload.cpp
#	src/script/api/script_log.cpp
#	src/script/api/script_log.hpp
#	src/settings_gui.cpp
#	src/settingsgen/settingsgen.cpp
#	src/station_cmd.cpp
#	src/station_cmd.h
#	src/station_gui.cpp
#	src/strgen/strgen.cpp
#	src/string_func.h
#	src/string_type.h
#	src/table/settings/network_private_settings.ini
#	src/tests/math_func.cpp
#	src/textfile_gui.cpp
#	src/timetable_gui.cpp
#	src/town_cmd.cpp
#	src/vehicle.cpp
#	src/waypoint_cmd.cpp
#	src/waypoint_cmd.h
#	src/widgets/dropdown.cpp
This commit is contained in:
Jonathan G Rennison
2023-06-03 19:16:42 +01:00
101 changed files with 987 additions and 964 deletions

View File

@@ -78,7 +78,7 @@ struct ScriptListWindow : public Window {
this->vscroll = this->GetScrollbar(WID_SCRL_SCROLLBAR);
this->FinishInitNested(); // Initializes 'this->line_height' as side effect.
this->vscroll->SetCount((int)this->info_list->size() + 1);
this->vscroll->SetCount(this->info_list->size() + 1);
/* Try if we can find the currently selected AI */
this->selected = -1;
@@ -238,7 +238,7 @@ struct ScriptListWindow : public Window {
if (!gui_scope) return;
this->vscroll->SetCount((int)this->info_list->size() + 1);
this->vscroll->SetCount(this->info_list->size() + 1);
/* selected goes from -1 .. length of ai list - 1. */
this->selected = std::min(this->selected, this->vscroll->GetCount() - 2);
@@ -346,7 +346,7 @@ struct ScriptSettingsWindow : public Window {
}
}
this->vscroll->SetCount((int)this->visible_settings.size());
this->vscroll->SetCount(this->visible_settings.size());
}
void SetStringParameters(int widget) const override
@@ -720,10 +720,10 @@ struct ScriptDebugWindow : public Window {
int highlight_row; ///< The output row that matches the given string, or -1
Scrollbar *vscroll; ///< Cache of the vertical scrollbar.
ScriptLog::LogData *GetLogPointer() const
ScriptLogTypes::LogData &GetLogData() const
{
if (script_debug_company == OWNER_DEITY) return (ScriptLog::LogData *)Game::GetInstance()->GetLogPointer();
return (ScriptLog::LogData *)Company::Get(script_debug_company)->ai_instance->GetLogPointer();
if (script_debug_company == OWNER_DEITY) return Game::GetInstance()->GetLogData();
return Company::Get(script_debug_company)->ai_instance->GetLogData();
}
/**
@@ -861,9 +861,9 @@ struct ScriptDebugWindow : public Window {
/* If there are no active companies, don't display anything else. */
if (script_debug_company == INVALID_COMPANY) return;
ScriptLog::LogData *log = this->GetLogPointer();
ScriptLogTypes::LogData &log = this->GetLogData();
int scroll_count = (log == nullptr) ? 0 : log->used;
int scroll_count = (int)log.size();
if (this->vscroll->GetCount() != scroll_count) {
this->vscroll->SetCount(scroll_count);
@@ -871,16 +871,15 @@ struct ScriptDebugWindow : public Window {
this->SetWidgetDirty(WID_SCRD_SCROLLBAR);
}
if (log == nullptr) return;
if (log.empty()) return;
/* Detect when the user scrolls the window. Enable autoscroll when the
* bottom-most line becomes visible. */
if (this->last_vscroll_pos != this->vscroll->GetPosition()) {
this->autoscroll = this->vscroll->GetPosition() >= log->used - this->vscroll->GetCapacity();
this->autoscroll = this->vscroll->GetPosition() + this->vscroll->GetCapacity() >= (int)log.size();
}
if (this->autoscroll) {
int scroll_pos = std::max(0, log->used - this->vscroll->GetCapacity());
if (this->vscroll->SetPosition(scroll_pos)) {
if (this->vscroll->SetPosition((int)log.size())) {
/* We need a repaint */
this->SetWidgetDirty(WID_SCRD_SCROLLBAR);
this->SetWidgetDirty(WID_SCRD_LOG_PANEL);
@@ -916,32 +915,31 @@ struct ScriptDebugWindow : public Window {
if (widget != WID_SCRD_LOG_PANEL) return;
ScriptLog::LogData *log = this->GetLogPointer();
if (log == nullptr) return;
ScriptLogTypes::LogData &log = this->GetLogData();
if (log.empty()) return;
Rect br = r.Shrink(WidgetDimensions::scaled.bevel);
Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < log->used; i++) {
int pos = (i + log->pos + 1 - log->used + log->count) % log->count;
if (log->lines[pos] == nullptr) break;
for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && (size_t)i < log.size(); i++) {
const ScriptLogTypes::LogLine &line = log[i];
TextColour colour;
switch (log->type[pos]) {
case ScriptLog::LOG_SQ_INFO: colour = TC_BLACK; break;
case ScriptLog::LOG_SQ_ERROR: colour = TC_WHITE; break;
case ScriptLog::LOG_INFO: colour = TC_BLACK; break;
case ScriptLog::LOG_WARNING: colour = TC_YELLOW; break;
case ScriptLog::LOG_ERROR: colour = TC_RED; break;
default: colour = TC_BLACK; break;
switch (line.type) {
case ScriptLogTypes::LOG_SQ_INFO: colour = TC_BLACK; break;
case ScriptLogTypes::LOG_SQ_ERROR: colour = TC_WHITE; break;
case ScriptLogTypes::LOG_INFO: colour = TC_BLACK; break;
case ScriptLogTypes::LOG_WARNING: colour = TC_YELLOW; break;
case ScriptLogTypes::LOG_ERROR: colour = TC_RED; break;
default: colour = TC_BLACK; break;
}
/* Check if the current line should be highlighted */
if (pos == this->highlight_row) {
if (i == this->highlight_row) {
GfxFillRect(br.left, tr.top, br.right, tr.top + this->resize.step_height - 1, PC_BLACK);
if (colour == TC_BLACK) colour = TC_WHITE; // Make black text readable by inverting it to white.
}
DrawString(tr, log->lines[pos], colour, SA_LEFT | SA_FORCE);
DrawString(tr, line.text, colour, SA_LEFT | SA_FORCE);
tr.top += this->resize.step_height;
}
}
@@ -1064,11 +1062,11 @@ struct ScriptDebugWindow : public Window {
* This needs to be done in gameloop-scope, so the AI is suspended immediately. */
if (!gui_scope && data == script_debug_company && this->IsValidDebugCompany(script_debug_company) && this->break_check_enabled && !this->break_string_filter.IsEmpty()) {
/* Get the log instance of the active company */
ScriptLog::LogData *log = this->GetLogPointer();
ScriptLogTypes::LogData &log = this->GetLogData();
if (log != nullptr) {
if (!log.empty()) {
this->break_string_filter.ResetState();
this->break_string_filter.AddLine(log->lines[log->pos]);
this->break_string_filter.AddLine(log.back().text);
if (this->break_string_filter.GetState()) {
/* Pause execution of script. */
if (!this->IsDead()) {
@@ -1085,7 +1083,7 @@ struct ScriptDebugWindow : public Window {
}
/* Highlight row that matched */
this->highlight_row = log->pos;
this->highlight_row = (int)(log.size() - 1);
}
}
}
@@ -1094,8 +1092,7 @@ struct ScriptDebugWindow : public Window {
this->SelectValidDebugCompany();
ScriptLog::LogData *log = script_debug_company != INVALID_COMPANY ? this->GetLogPointer() : nullptr;
this->vscroll->SetCount((log == nullptr) ? 0 : log->used);
this->vscroll->SetCount(script_debug_company != INVALID_COMPANY ? this->GetLogData().size() : 0);
/* Update company buttons */
for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {