Codechange: move windows common to AI and GS out of ai_gui

This commit is contained in:
glx22 2023-02-04 04:17:55 +01:00 committed by Loïc Guilloux
parent 78e3c93a25
commit b080f24bd8
26 changed files with 1391 additions and 1374 deletions

View File

@ -13,10 +13,6 @@
#include "../script/api/script_event_types.hpp"
#include "../core/string_compare_type.hpp"
#include "ai_scanner.hpp"
#include <map>
/** A list that maps AI names to their AIInfo object. */
typedef std::map<const char *, class ScriptInfo *, StringCompare> ScriptInfoList;
/**
* Main AI class. Contains all functions needed to start, stop, save and load AIs.

View File

@ -62,7 +62,7 @@
cur_company.Restore();
InvalidateWindowData(WC_AI_DEBUG, 0, -1);
InvalidateWindowData(WC_SCRIPT_DEBUG, 0, -1);
return;
}
@ -113,8 +113,8 @@
cur_company.Restore();
InvalidateWindowData(WC_AI_DEBUG, 0, -1);
CloseWindowById(WC_AI_SETTINGS, company);
InvalidateWindowData(WC_SCRIPT_DEBUG, 0, -1);
CloseWindowById(WC_SCRIPT_SETTINGS, company);
}
/* static */ void AI::Pause(CompanyID company)
@ -338,9 +338,9 @@
AI::scanner_library->RescanDir();
ResetConfig();
InvalidateWindowData(WC_AI_LIST, 0, 1);
SetWindowClassesDirty(WC_AI_DEBUG);
InvalidateWindowClassesData(WC_AI_SETTINGS);
InvalidateWindowData(WC_SCRIPT_LIST, 0, 1);
SetWindowClassesDirty(WC_SCRIPT_DEBUG);
InvalidateWindowClassesData(WC_SCRIPT_SETTINGS);
}
/**

File diff suppressed because it is too large Load Diff

View File

@ -10,13 +10,6 @@
#ifndef AI_GUI_HPP
#define AI_GUI_HPP
#include "../company_type.h"
void ShowAIListWindow(CompanyID slot);
Window* ShowAIDebugWindow(CompanyID show_company = INVALID_COMPANY);
void ShowAIConfigWindow();
void ShowScriptTextfileWindow(TextfileType file_type, CompanyID slot);
void ShowAIDebugWindowIfAIError();
void InitializeAIGui();
#endif /* AI_GUI_HPP */

View File

@ -14,11 +14,11 @@
#include "../script/squirrel_class.hpp"
#include "ai_config.hpp"
#include "ai_gui.hpp"
#include "ai.hpp"
#include "../script/script_storage.hpp"
#include "../script/script_cmd.h"
#include "../script/script_gui.h"
#include "ai_info.hpp"
#include "ai_instance.hpp"
@ -64,7 +64,7 @@ void AIInstance::Died()
/* Intro is not supposed to use AI, but it may have 'dummy' AI which instant dies. */
if (_game_mode == GM_MENU) return;
ShowAIDebugWindow(_current_company);
ShowScriptDebugWindow(_current_company);
const AIInfo *info = AIConfig::GetConfig(_current_company, AIConfig::SSS_FORCE_GAME)->GetInfo();
if (info != nullptr) {

View File

@ -922,8 +922,8 @@ CommandCost CmdCompanyCtrl(DoCommandFlag flags, CompanyCtrlAction cca, CompanyID
}
InvalidateWindowClassesData(WC_GAME_OPTIONS);
InvalidateWindowClassesData(WC_AI_SETTINGS);
InvalidateWindowClassesData(WC_AI_LIST);
InvalidateWindowClassesData(WC_SCRIPT_SETTINGS);
InvalidateWindowClassesData(WC_SCRIPT_LIST);
return CommandCost();
}

View File

@ -12,10 +12,6 @@
#include "../core/string_compare_type.hpp"
#include "game_scanner.hpp"
#include <map>
/** A list that maps AI names to their AIInfo object. */
typedef std::map<const char *, class ScriptInfo *, StringCompare> ScriptInfoList;
#include "../script/api/script_event_types.hpp"

View File

@ -96,7 +96,7 @@
cur_company.Restore();
InvalidateWindowData(WC_AI_DEBUG, 0, -1);
InvalidateWindowData(WC_SCRIPT_DEBUG, 0, -1);
}
/* static */ void Game::Uninitialize(bool keepConfig)
@ -201,9 +201,9 @@
Game::scanner_library->RescanDir();
ResetConfig();
InvalidateWindowData(WC_AI_LIST, 0, 1);
SetWindowClassesDirty(WC_AI_DEBUG);
InvalidateWindowClassesData(WC_AI_SETTINGS);
InvalidateWindowData(WC_SCRIPT_LIST, 0, 1);
SetWindowClassesDirty(WC_SCRIPT_DEBUG);
InvalidateWindowClassesData(WC_SCRIPT_SETTINGS);
InvalidateWindowClassesData(WC_GAME_OPTIONS);
}

View File

@ -8,39 +8,20 @@
/** @file game_gui.cpp %Window for configuring the Game Script */
#include "../stdafx.h"
#include "../table/sprites.h"
#include "../error.h"
#include "../settings_gui.h"
#include "../querystring_gui.h"
#include "../stringfilter_type.h"
#include "../company_base.h"
#include "../company_gui.h"
#include "../strings_func.h"
#include "../window_func.h"
#include "../window_type.h"
#include "../gfx_func.h"
#include "../command_func.h"
#include "../network/network.h"
#include "../settings_func.h"
#include "../network/network_content.h"
#include "../textfile_gui.h"
#include "../widgets/dropdown_type.h"
#include "../widgets/dropdown_func.h"
#include "../hotkeys.h"
#include "../core/geometry_func.hpp"
#include "../guitimer_func.h"
#include "../company_cmd.h"
#include "../misc_cmd.h"
#include "game.hpp"
#include "game_gui.hpp"
#include "../ai/ai_config.hpp"
#include "../ai/ai_gui.hpp"
#include "../widgets/game_widget.h"
#include "game_config.hpp"
#include "game_info.hpp"
#include "../script/script_gui.h"
#include "../table/strings.h"
#include "../game/game.hpp"
#include "../game/game_config.hpp"
#include "../game/game_info.hpp"
#include "../game/game_instance.hpp"
#include "../safeguards.h"
@ -125,7 +106,7 @@ struct GSConfigWindow : public Window {
void Close() override
{
CloseWindowByClass(WC_AI_LIST);
CloseWindowByClass(WC_SCRIPT_LIST);
this->Window::Close();
}
@ -267,12 +248,12 @@ struct GSConfigWindow : public Window {
switch (widget) {
case WID_GSC_GSLIST: {
this->InvalidateData();
if (click_count > 1 && _game_mode != GM_NORMAL) ShowAIListWindow((CompanyID)OWNER_DEITY);
if (click_count > 1 && _game_mode != GM_NORMAL) ShowScriptListWindow((CompanyID)OWNER_DEITY);
break;
}
case WID_GSC_CHANGE: // choose other Game Script
ShowAIListWindow((CompanyID)OWNER_DEITY);
ShowScriptListWindow((CompanyID)OWNER_DEITY);
break;
case WID_GSC_CONTENT_DOWNLOAD:

View File

@ -14,7 +14,7 @@
#include "../script/script_storage.hpp"
#include "../script/script_cmd.h"
#include "../ai/ai_gui.hpp"
#include "../script/script_gui.h"
#include "game_config.hpp"
#include "game_info.hpp"
#include "game_instance.hpp"
@ -67,7 +67,7 @@ void GameInstance::Died()
{
ScriptInstance::Died();
ShowAIDebugWindow(OWNER_DEITY);
ShowScriptDebugWindow(OWNER_DEITY);
const GameInfo *info = Game::GetInfo();
if (info != nullptr) {

View File

@ -11,7 +11,7 @@
#include "landscape.h"
#include "news_func.h"
#include "ai/ai.hpp"
#include "ai/ai_gui.hpp"
#include "script/script_gui.h"
#include "newgrf.h"
#include "newgrf_house.h"
#include "economy_func.h"
@ -100,7 +100,7 @@ void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settin
InitializeGraphGui();
InitializeObjectGui();
InitializeTownGui();
InitializeAIGui();
InitializeScriptGui();
InitializeTrees();
InitializeIndustries();
InitializeObjects();

View File

@ -40,7 +40,7 @@
#include "../company_func.h"
#include "../road_cmd.h"
#include "../ai/ai.hpp"
#include "../ai/ai_gui.hpp"
#include "../script/script_gui.h"
#include "../game/game.hpp"
#include "../town.h"
#include "../economy_base.h"
@ -552,7 +552,7 @@ static void StartScripts()
if (Company::IsValidAiID(c->index)) AI::StartNew(c->index, false);
}
ShowAIDebugWindowIfAIError();
ShowScriptDebugWindowIfScriptError();
}
/**

View File

@ -9,6 +9,8 @@ add_files(
script_config.cpp
script_config.hpp
script_fatalerror.hpp
script_gui.h
script_gui.cpp
script_info.cpp
script_info.hpp
script_info_dummy.cpp

View File

@ -18,7 +18,7 @@
#include "../script_info.hpp"
#include "../script_instance.hpp"
#include "script_log.hpp"
#include "../../ai/ai_gui.hpp"
#include "../script_gui.h"
#include "../../settings_type.h"
#include "../../network/network.h"
#include "../../misc_cmd.h"
@ -57,7 +57,7 @@
/* Inform script developer that their script has been paused and
* needs manual action to continue. */
ShowAIDebugWindow(ScriptObject::GetRootCompany());
ShowScriptDebugWindow(ScriptObject::GetRootCompany());
if ((_pause_mode & PM_PAUSED_NORMAL) == PM_UNPAUSED) {
ScriptObject::Command<CMD_PAUSE>::Do(PM_PAUSED_NORMAL, true);

View File

@ -75,7 +75,7 @@
/* Also still print to debug window */
Debug(script, level, "[{}] [{}] {}", (uint)ScriptObject::GetRootCompany(), logc, log->lines[log->pos]);
InvalidateWindowData(WC_AI_DEBUG, 0, ScriptObject::GetRootCompany());
InvalidateWindowData(WC_SCRIPT_DEBUG, 0, ScriptObject::GetRootCompany());
}
/* static */ void ScriptLog::FreeLogPointer()

1256
src/script/script_gui.cpp Normal file

File diff suppressed because it is too large Load Diff

23
src/script/script_gui.h Normal file
View File

@ -0,0 +1,23 @@
/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file script_gui.hpp %Window for configuring the scripts */
#ifndef SCRIPT_GUI_HPP
#define SCRIPT_GUI_HPP
#include "../company_type.h"
#include "../textfile_type.h"
void ShowScriptListWindow(CompanyID slot);
Window *ShowScriptDebugWindow(CompanyID show_company = INVALID_COMPANY);
void ShowScriptSettingsWindow(CompanyID slot);
void ShowScriptTextfileWindow(TextfileType file_type, CompanyID slot);
void ShowScriptDebugWindowIfScriptError();
void InitializeScriptGui();
#endif /* SCRIPT_GUI_HPP */

View File

@ -779,7 +779,7 @@ cat = SC_EXPERT
var = gui.ai_developer_tools
flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC
def = false
post_cb = [](auto) { InvalidateWindowClassesData(WC_AI_SETTINGS); }
post_cb = [](auto) { InvalidateWindowClassesData(WC_SCRIPT_SETTINGS); }
cat = SC_EXPERT
[SDTC_BOOL]

View File

@ -34,6 +34,7 @@
#include "news_gui.h"
#include "ai/ai_gui.hpp"
#include "game/game_gui.hpp"
#include "script/script_gui.h"
#include "tilehighlight_func.h"
#include "smallmap_gui.h"
#include "graph_gui.h"
@ -1163,7 +1164,7 @@ static CallBackFunction MenuClickHelp(int index)
switch (index) {
case 0: return PlaceLandBlockInfo();
case 2: IConsoleSwitch(); break;
case 3: ShowAIDebugWindow(); break;
case 3: ShowScriptDebugWindow(); break;
case 4: ShowScreenshotWindow(); break;
case 5: ShowFramerateWindow(); break;
case 6: ShowAboutWindow(); break;
@ -2073,7 +2074,7 @@ struct MainToolbarWindow : Window {
case MTHK_BUILD_AIRPORT: ShowBuildAirToolbar(); break;
case MTHK_BUILD_TREES: ShowBuildTreesToolbar(); break;
case MTHK_MUSIC: ShowMusicWindow(); break;
case MTHK_AI_DEBUG: ShowAIDebugWindow(); break;
case MTHK_SCRIPT_DEBUG: ShowScriptDebugWindow(); break;
case MTHK_SMALL_SCREENSHOT: MakeScreenshotWithConfirm(SC_VIEWPORT); break;
case MTHK_ZOOMEDIN_SCREENSHOT: MakeScreenshotWithConfirm(SC_ZOOMEDIN); break;
case MTHK_DEFAULTZOOM_SCREENSHOT: MakeScreenshotWithConfirm(SC_DEFAULTZOOM); break;
@ -2187,7 +2188,7 @@ static Hotkey maintoolbar_hotkeys[] = {
Hotkey(WKC_SHIFT | WKC_F10, "build_airport", MTHK_BUILD_AIRPORT),
Hotkey(WKC_SHIFT | WKC_F11, "build_trees", MTHK_BUILD_TREES),
Hotkey(WKC_SHIFT | WKC_F12, "music", MTHK_MUSIC),
Hotkey((uint16)0, "ai_debug", MTHK_AI_DEBUG),
Hotkey((uint16)0, "ai_debug", MTHK_SCRIPT_DEBUG),
Hotkey(WKC_CTRL | 'S', "small_screenshot", MTHK_SMALL_SCREENSHOT),
Hotkey(WKC_CTRL | 'P', "zoomedin_screenshot", MTHK_ZOOMEDIN_SCREENSHOT),
Hotkey(WKC_CTRL | 'D', "defaultzoom_screenshot", MTHK_DEFAULTZOOM_SCREENSHOT),

View File

@ -41,7 +41,7 @@ enum MainToolbarHotkeys {
MTHK_BUILD_TREES,
MTHK_MUSIC,
MTHK_LANDINFO,
MTHK_AI_DEBUG,
MTHK_SCRIPT_DEBUG,
MTHK_SMALL_SCREENSHOT,
MTHK_ZOOMEDIN_SCREENSHOT,
MTHK_DEFAULTZOOM_SCREENSHOT,

View File

@ -44,6 +44,7 @@ add_files(
rail_widget.h
road_widget.h
screenshot_widget.h
script_widget.h
settings_widget.h
sign_widget.h
slider.cpp

View File

@ -10,28 +10,8 @@
#ifndef WIDGETS_AI_WIDGET_H
#define WIDGETS_AI_WIDGET_H
#include "../company_type.h"
#include "../textfile_type.h"
/** Widgets of the #AIListWindow class. */
enum AIListWidgets {
WID_AIL_CAPTION, ///< Caption of the window.
WID_AIL_LIST, ///< The matrix with all available AIs.
WID_AIL_SCROLLBAR, ///< Scrollbar next to the AI list.
WID_AIL_INFO_BG, ///< Panel to draw some AI information on.
WID_AIL_ACCEPT, ///< Accept button.
WID_AIL_CANCEL, ///< Cancel button.
};
/** Widgets of the #AISettingsWindow class. */
enum AISettingsWidgets {
WID_AIS_CAPTION, ///< Caption of the window.
WID_AIS_BACKGROUND, ///< Panel to draw the settings on.
WID_AIS_SCROLLBAR, ///< Scrollbar to scroll through all settings.
WID_AIS_ACCEPT, ///< Accept button.
WID_AIS_RESET, ///< Reset button.
};
/** Widgets of the #AIConfigWindow class. */
enum AIConfigWidgets {
WID_AIC_BACKGROUND, ///< Window background.
@ -49,22 +29,4 @@ enum AIConfigWidgets {
WID_AIC_CONTENT_DOWNLOAD = WID_AIC_TEXTFILE + TFT_END, ///< Download content button.
};
/** Widgets of the #AIDebugWindow class. */
enum AIDebugWidgets {
WID_AID_VIEW, ///< The row of company buttons.
WID_AID_NAME_TEXT, ///< Name of the current selected.
WID_AID_SETTINGS, ///< Settings button.
WID_AID_SCRIPT_GAME, ///< Game Script button.
WID_AID_RELOAD_TOGGLE, ///< Reload button.
WID_AID_LOG_PANEL, ///< Panel where the log is in.
WID_AID_SCROLLBAR, ///< Scrollbar of the log panel.
WID_AID_COMPANY_BUTTON_START, ///< Buttons in the VIEW.
WID_AID_COMPANY_BUTTON_END = WID_AID_COMPANY_BUTTON_START + MAX_COMPANIES - 1, ///< Last possible button in the VIEW.
WID_AID_BREAK_STRING_WIDGETS, ///< The panel to handle the breaking on string.
WID_AID_BREAK_STR_ON_OFF_BTN, ///< Enable breaking on string.
WID_AID_BREAK_STR_EDIT_BOX, ///< Edit box for the string to break on.
WID_AID_MATCH_CASE_BTN, ///< Checkbox to use match caching or not.
WID_AID_CONTINUE_BTN, ///< Continue button.
};
#endif /* WIDGETS_AI_WIDGET_H */

View File

@ -5,7 +5,7 @@
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file ai_widget.h Types related to the ai widgets. */
/** @file game_widget.h Types related to the GS widgets. */
#ifndef WIDGETS_GS_WIDGET_H
#define WIDGETS_GS_WIDGET_H

View File

@ -0,0 +1,52 @@
/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file script_widget.h Types related to the script widgets. */
#ifndef WIDGETS_SCRIPT_WIDGET_H
#define WIDGETS_SCRIPT_WIDGET_H
#include "../company_type.h"
/** Widgets of the #ScriptListWindow class. */
enum ScriptListWidgets {
WID_SCRL_CAPTION, ///< Caption of the window.
WID_SCRL_LIST, ///< The matrix with all available Scripts.
WID_SCRL_SCROLLBAR, ///< Scrollbar next to the Script list.
WID_SCRL_INFO_BG, ///< Panel to draw some Script information on.
WID_SCRL_ACCEPT, ///< Accept button.
WID_SCRL_CANCEL, ///< Cancel button.
};
/** Widgets of the #ScriptSettingsWindow class. */
enum ScriptSettingsWidgets {
WID_SCRS_CAPTION, ///< Caption of the window.
WID_SCRS_BACKGROUND, ///< Panel to draw the settings on.
WID_SCRS_SCROLLBAR, ///< Scrollbar to scroll through all settings.
WID_SCRS_ACCEPT, ///< Accept button.
WID_SCRS_RESET, ///< Reset button.
};
/** Widgets of the #ScriptDebugWindow class. */
enum ScriptDebugWidgets {
WID_SCRD_VIEW, ///< The row of company buttons.
WID_SCRD_NAME_TEXT, ///< Name of the current selected.
WID_SCRD_SETTINGS, ///< Settings button.
WID_SCRD_SCRIPT_GAME, ///< Game Script button.
WID_SCRD_RELOAD_TOGGLE, ///< Reload button.
WID_SCRD_LOG_PANEL, ///< Panel where the log is in.
WID_SCRD_SCROLLBAR, ///< Scrollbar of the log panel.
WID_SCRD_COMPANY_BUTTON_START, ///< Buttons in the VIEW.
WID_SCRD_COMPANY_BUTTON_END = WID_SCRD_COMPANY_BUTTON_START + MAX_COMPANIES - 1, ///< Last possible button in the VIEW.
WID_SCRD_BREAK_STRING_WIDGETS, ///< The panel to handle the breaking on string.
WID_SCRD_BREAK_STR_ON_OFF_BTN, ///< Enable breaking on string.
WID_SCRD_BREAK_STR_EDIT_BOX, ///< Edit box for the string to break on.
WID_SCRD_MATCH_CASE_BTN, ///< Checkbox to use match caching or not.
WID_SCRD_CONTINUE_BTN, ///< Continue button.
};
#endif /* WIDGETS_SCRIPT_WIDGET_H */

View File

@ -1367,8 +1367,8 @@ static uint GetWindowZPriority(WindowClass wc)
case WC_CUSTOM_CURRENCY:
case WC_NETWORK_WINDOW:
case WC_GRF_PARAMETERS:
case WC_AI_LIST:
case WC_AI_SETTINGS:
case WC_SCRIPT_LIST:
case WC_SCRIPT_SETTINGS:
case WC_TEXTFILE:
++z_priority;
FALLTHROUGH;

View File

@ -162,10 +162,10 @@ enum WindowClass {
/**
* AI settings; %Window numbers:
* - 0 = #AISettingsWidgets
* Script settings; %Window numbers:
* - 0 = #ScriptSettingsWidgets
*/
WC_AI_SETTINGS,
WC_SCRIPT_SETTINGS,
/**
* NewGRF parameters; %Window numbers:
@ -271,10 +271,10 @@ enum WindowClass {
WC_SIGN_LIST,
/**
* AI list; %Window numbers:
* - 0 = #AIListWidgets
* Scripts list; %Window numbers:
* - 0 = #ScriptListWidgets
*/
WC_AI_LIST,
WC_SCRIPT_LIST,
/**
* Goals list; %Window numbers:
@ -650,10 +650,10 @@ enum WindowClass {
/**
* AI debug window; %Window numbers:
* - 0 = #AIDebugWidgets
* Script debug window; %Window numbers:
* - 0 = #ScriptDebugWidgets
*/
WC_AI_DEBUG,
WC_SCRIPT_DEBUG,
/**
* NewGRF inspect (debug); %Window numbers: