1
0
Fork 0

Codechange: Add, remove or convert castings in AI/GS GUI files

pull/13665/head
SamuXarick 2025-02-26 15:36:31 +00:00
parent 163b658404
commit 8853d6d9cf
3 changed files with 21 additions and 21 deletions

View File

@ -218,7 +218,7 @@ struct AIConfigWindow : public Window {
if (widget >= WID_AIC_TEXTFILE && widget < WID_AIC_TEXTFILE + TFT_CONTENT_END) { if (widget >= WID_AIC_TEXTFILE && widget < WID_AIC_TEXTFILE + TFT_CONTENT_END) {
if (this->selected_slot == CompanyID::Invalid() || AIConfig::GetConfig(this->selected_slot) == nullptr) return; if (this->selected_slot == CompanyID::Invalid() || AIConfig::GetConfig(this->selected_slot) == nullptr) return;
ShowScriptTextfileWindow(this, (TextfileType)(widget - WID_AIC_TEXTFILE), this->selected_slot); ShowScriptTextfileWindow(this, static_cast<TextfileType>(widget - WID_AIC_TEXTFILE), this->selected_slot);
return; return;
} }
@ -250,23 +250,23 @@ struct AIConfigWindow : public Window {
} }
case WID_AIC_LIST: { // Select a slot case WID_AIC_LIST: { // Select a slot
this->selected_slot = (CompanyID)this->vscroll->GetScrolledRowFromWidget(pt.y, this, widget); this->selected_slot = static_cast<CompanyID>(this->vscroll->GetScrolledRowFromWidget(pt.y, this, widget));
this->InvalidateData(); this->InvalidateData();
if (click_count > 1 && IsEditable(this->selected_slot)) ShowScriptListWindow((CompanyID)this->selected_slot, _ctrl_pressed); if (click_count > 1 && IsEditable(this->selected_slot)) ShowScriptListWindow(this->selected_slot, _ctrl_pressed);
break; break;
} }
case WID_AIC_MOVE_UP: case WID_AIC_MOVE_UP:
if (IsEditable(this->selected_slot) && IsEditable((CompanyID)(this->selected_slot - 1))) { if (IsEditable(this->selected_slot) && IsEditable(static_cast<CompanyID>(this->selected_slot - 1))) {
std::swap(GetGameSettings().script_config.ai[this->selected_slot], GetGameSettings().script_config.ai[this->selected_slot - 1]); std::swap(GetGameSettings().script_config.ai[this->selected_slot], GetGameSettings().script_config.ai[this->selected_slot - 1]);
this->selected_slot = CompanyID(this->selected_slot - 1); this->selected_slot = static_cast<CompanyID>(this->selected_slot - 1);
this->vscroll->ScrollTowards(this->selected_slot.base()); this->vscroll->ScrollTowards(this->selected_slot.base());
this->InvalidateData(); this->InvalidateData();
} }
break; break;
case WID_AIC_MOVE_DOWN: case WID_AIC_MOVE_DOWN:
if (IsEditable(this->selected_slot) && IsEditable((CompanyID)(this->selected_slot + 1))) { if (IsEditable(this->selected_slot) && IsEditable(static_cast<CompanyID>(this->selected_slot + 1))) {
std::swap(GetGameSettings().script_config.ai[this->selected_slot], GetGameSettings().script_config.ai[this->selected_slot + 1]); std::swap(GetGameSettings().script_config.ai[this->selected_slot], GetGameSettings().script_config.ai[this->selected_slot + 1]);
++this->selected_slot; ++this->selected_slot;
this->vscroll->ScrollTowards(this->selected_slot.base()); this->vscroll->ScrollTowards(this->selected_slot.base());
@ -282,11 +282,11 @@ struct AIConfigWindow : public Window {
} }
case WID_AIC_CHANGE: // choose other AI case WID_AIC_CHANGE: // choose other AI
if (IsEditable(this->selected_slot)) ShowScriptListWindow((CompanyID)this->selected_slot, _ctrl_pressed); if (IsEditable(this->selected_slot)) ShowScriptListWindow(this->selected_slot, _ctrl_pressed);
break; break;
case WID_AIC_CONFIGURE: // change the settings for an AI case WID_AIC_CONFIGURE: // change the settings for an AI
ShowScriptSettingsWindow((CompanyID)this->selected_slot); ShowScriptSettingsWindow(this->selected_slot);
break; break;
case WID_AIC_CONTENT_DOWNLOAD: case WID_AIC_CONTENT_DOWNLOAD:
@ -320,8 +320,8 @@ struct AIConfigWindow : public Window {
this->SetWidgetDisabledState(WID_AIC_INCREASE_INTERVAL, GetGameSettings().difficulty.competitors_interval == MAX_COMPETITORS_INTERVAL); this->SetWidgetDisabledState(WID_AIC_INCREASE_INTERVAL, GetGameSettings().difficulty.competitors_interval == MAX_COMPETITORS_INTERVAL);
this->SetWidgetDisabledState(WID_AIC_CHANGE, !IsEditable(this->selected_slot)); this->SetWidgetDisabledState(WID_AIC_CHANGE, !IsEditable(this->selected_slot));
this->SetWidgetDisabledState(WID_AIC_CONFIGURE, this->selected_slot == CompanyID::Invalid() || config->GetConfigList()->empty()); this->SetWidgetDisabledState(WID_AIC_CONFIGURE, this->selected_slot == CompanyID::Invalid() || config->GetConfigList()->empty());
this->SetWidgetDisabledState(WID_AIC_MOVE_UP, !IsEditable(this->selected_slot) || !IsEditable((CompanyID)(this->selected_slot - 1))); this->SetWidgetDisabledState(WID_AIC_MOVE_UP, !IsEditable(this->selected_slot) || !IsEditable(static_cast<CompanyID>(this->selected_slot - 1)));
this->SetWidgetDisabledState(WID_AIC_MOVE_DOWN, !IsEditable(this->selected_slot) || !IsEditable((CompanyID)(this->selected_slot + 1))); this->SetWidgetDisabledState(WID_AIC_MOVE_DOWN, !IsEditable(this->selected_slot) || !IsEditable(static_cast<CompanyID>(this->selected_slot + 1)));
this->SetWidgetDisabledState(WID_AIC_OPEN_URL, this->selected_slot == CompanyID::Invalid() || config->GetInfo() == nullptr || config->GetInfo()->GetURL().empty()); this->SetWidgetDisabledState(WID_AIC_OPEN_URL, this->selected_slot == CompanyID::Invalid() || config->GetInfo() == nullptr || config->GetInfo()->GetURL().empty());
for (TextfileType tft = TFT_CONTENT_BEGIN; tft < TFT_CONTENT_END; tft++) { for (TextfileType tft = TFT_CONTENT_BEGIN; tft < TFT_CONTENT_END; tft++) {

View File

@ -228,19 +228,19 @@ struct GSConfigWindow : public Window {
if (widget >= WID_GSC_TEXTFILE && widget < WID_GSC_TEXTFILE + TFT_CONTENT_END) { if (widget >= WID_GSC_TEXTFILE && widget < WID_GSC_TEXTFILE + TFT_CONTENT_END) {
if (GameConfig::GetConfig() == nullptr) return; if (GameConfig::GetConfig() == nullptr) return;
ShowScriptTextfileWindow(this, (TextfileType)(widget - WID_GSC_TEXTFILE), (CompanyID)OWNER_DEITY); ShowScriptTextfileWindow(this, static_cast<TextfileType>(widget - WID_GSC_TEXTFILE), OWNER_DEITY);
return; return;
} }
switch (widget) { switch (widget) {
case WID_GSC_GSLIST: { case WID_GSC_GSLIST: {
this->InvalidateData(); this->InvalidateData();
if (click_count > 1 && _game_mode != GM_NORMAL) ShowScriptListWindow((CompanyID)OWNER_DEITY, _ctrl_pressed); if (click_count > 1 && _game_mode != GM_NORMAL) ShowScriptListWindow(OWNER_DEITY, _ctrl_pressed);
break; break;
} }
case WID_GSC_CHANGE: // choose other Game Script case WID_GSC_CHANGE: // choose other Game Script
ShowScriptListWindow((CompanyID)OWNER_DEITY, _ctrl_pressed); ShowScriptListWindow(OWNER_DEITY, _ctrl_pressed);
break; break;
case WID_GSC_CONTENT_DOWNLOAD: case WID_GSC_CONTENT_DOWNLOAD:
@ -397,7 +397,7 @@ struct GSConfigWindow : public Window {
const GameConfig *config = GameConfig::GetConfig(); const GameConfig *config = GameConfig::GetConfig();
this->SetWidgetDisabledState(WID_GSC_OPEN_URL, config->GetInfo() == nullptr || config->GetInfo()->GetURL().empty()); this->SetWidgetDisabledState(WID_GSC_OPEN_URL, config->GetInfo() == nullptr || config->GetInfo()->GetURL().empty());
for (TextfileType tft = TFT_CONTENT_BEGIN; tft < TFT_CONTENT_END; tft++) { for (TextfileType tft = TFT_CONTENT_BEGIN; tft < TFT_CONTENT_END; tft++) {
this->SetWidgetDisabledState(WID_GSC_TEXTFILE + tft, !config->GetTextfile(tft, (CompanyID)OWNER_DEITY).has_value()); this->SetWidgetDisabledState(WID_GSC_TEXTFILE + tft, !config->GetTextfile(tft, OWNER_DEITY).has_value());
} }
this->RebuildVisibleSettings(); this->RebuildVisibleSettings();
this->CloseChildWindows(WC_DROPDOWN_MENU); this->CloseChildWindows(WC_DROPDOWN_MENU);

View File

@ -198,7 +198,7 @@ struct ScriptListWindow : public Window {
switch (widget) { switch (widget) {
case WID_SCRL_LIST: { // Select one of the Scripts case WID_SCRL_LIST: { // Select one of the Scripts
int sel = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SCRL_LIST) - 1; int sel = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SCRL_LIST) - 1;
if (sel < (int)this->info_list->size()) { if (sel < static_cast<int>(this->info_list->size())) {
this->selected = sel; this->selected = sel;
this->SetDirty(); this->SetDirty();
if (click_count > 1) { if (click_count > 1) {
@ -856,7 +856,7 @@ struct ScriptDebugWindow : public Window {
void DrawWidgetCompanyButton(const Rect &r, WidgetID widget, int start) const void DrawWidgetCompanyButton(const Rect &r, WidgetID widget, int start) const
{ {
if (this->IsWidgetDisabled(widget)) return; if (this->IsWidgetDisabled(widget)) return;
CompanyID cid = (CompanyID)(widget - start); CompanyID cid = static_cast<CompanyID>(widget - start);
Dimension sprite_size = GetSpriteSize(SPR_COMPANY_ICON); Dimension sprite_size = GetSpriteSize(SPR_COMPANY_ICON);
DrawCompanyIcon(cid, CentreBounds(r.left, r.right, sprite_size.width), CentreBounds(r.top, r.bottom, sprite_size.height)); DrawCompanyIcon(cid, CentreBounds(r.left, r.right, sprite_size.width), CentreBounds(r.top, r.bottom, sprite_size.height));
} }
@ -921,7 +921,7 @@ struct ScriptDebugWindow : public Window {
ScriptLogTypes::LogData &log = this->GetLogData(); ScriptLogTypes::LogData &log = this->GetLogData();
int scroll_count = (int)log.size(); int scroll_count = static_cast<int>(log.size());
if (this->vscroll->GetCount() != scroll_count) { if (this->vscroll->GetCount() != scroll_count) {
this->vscroll->SetCount(scroll_count); this->vscroll->SetCount(scroll_count);
@ -933,10 +933,10 @@ struct ScriptDebugWindow : public Window {
/* Detect when the user scrolls the window. Enable autoscroll when the bottom-most line becomes visible. */ /* Detect when the user scrolls the window. Enable autoscroll when the bottom-most line becomes visible. */
if (this->last_vscroll_pos != this->vscroll->GetPosition()) { if (this->last_vscroll_pos != this->vscroll->GetPosition()) {
this->autoscroll = this->vscroll->GetPosition() + this->vscroll->GetCapacity() >= (int)log.size(); this->autoscroll = this->vscroll->GetPosition() + this->vscroll->GetCapacity() >= static_cast<int>(log.size());
} }
if (this->autoscroll && this->vscroll->SetPosition((int)log.size())) { if (this->autoscroll && this->vscroll->SetPosition(static_cast<int>(log.size()))) {
/* We need a repaint */ /* We need a repaint */
this->SetWidgetDirty(WID_SCRD_VSCROLLBAR); this->SetWidgetDirty(WID_SCRD_VSCROLLBAR);
this->SetWidgetDirty(WID_SCRD_LOG_PANEL); this->SetWidgetDirty(WID_SCRD_LOG_PANEL);
@ -1015,7 +1015,7 @@ struct ScriptDebugWindow : public Window {
/* Check which button is clicked */ /* Check which button is clicked */
if (IsInsideMM(widget, WID_SCRD_COMPANY_BUTTON_START, WID_SCRD_COMPANY_BUTTON_END + 1)) { if (IsInsideMM(widget, WID_SCRD_COMPANY_BUTTON_START, WID_SCRD_COMPANY_BUTTON_END + 1)) {
this->ChangeToScript((CompanyID)(widget - WID_SCRD_COMPANY_BUTTON_START), _ctrl_pressed); this->ChangeToScript(static_cast<CompanyID>(widget - WID_SCRD_COMPANY_BUTTON_START), _ctrl_pressed);
} }
switch (widget) { switch (widget) {
@ -1123,7 +1123,7 @@ struct ScriptDebugWindow : public Window {
} }
/* Highlight row that matched */ /* Highlight row that matched */
this->highlight_row = (int)(log.size() - 1); this->highlight_row = static_cast<int>(log.size() - 1);
} }
} }
} }