mirror of https://github.com/OpenTTD/OpenTTD.git
Change: Allow opening multiple script debug windows by holding Ctrl.
This commit is contained in:
parent
4a2038e301
commit
0ca4b4e146
|
@ -62,7 +62,7 @@
|
|||
|
||||
cur_company.Restore();
|
||||
|
||||
InvalidateWindowData(WC_SCRIPT_DEBUG, 0, -1);
|
||||
InvalidateWindowClassesData(WC_SCRIPT_DEBUG, -1);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -113,7 +113,7 @@
|
|||
|
||||
cur_company.Restore();
|
||||
|
||||
InvalidateWindowData(WC_SCRIPT_DEBUG, 0, -1);
|
||||
InvalidateWindowClassesData(WC_SCRIPT_DEBUG, -1);
|
||||
CloseWindowById(WC_SCRIPT_SETTINGS, company);
|
||||
}
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@
|
|||
|
||||
cur_company.Restore();
|
||||
|
||||
InvalidateWindowData(WC_SCRIPT_DEBUG, 0, -1);
|
||||
InvalidateWindowClassesData(WC_SCRIPT_DEBUG, -1);
|
||||
}
|
||||
|
||||
/* static */ void Game::Uninitialize(bool keepConfig)
|
||||
|
|
|
@ -4653,9 +4653,9 @@ STR_AI_DEBUG_MATCH_CASE :{BLACK}Match ca
|
|||
STR_AI_DEBUG_MATCH_CASE_TOOLTIP :{BLACK}Toggle matching case when comparing AI log messages against the break string
|
||||
STR_AI_DEBUG_CONTINUE :{BLACK}Continue
|
||||
STR_AI_DEBUG_CONTINUE_TOOLTIP :{BLACK}Unpause and continue the AI
|
||||
STR_AI_DEBUG_SELECT_AI_TOOLTIP :{BLACK}View debug output of this AI
|
||||
STR_AI_DEBUG_SELECT_AI_TOOLTIP :{BLACK}View debug output of this AI. Ctrl-Click to open in a new window
|
||||
STR_AI_GAME_SCRIPT :{BLACK}Game Script
|
||||
STR_AI_GAME_SCRIPT_TOOLTIP :{BLACK}Check the Game Script log
|
||||
STR_AI_GAME_SCRIPT_TOOLTIP :{BLACK}Check the Game Script log. Ctrl-Click to open in a new window
|
||||
|
||||
STR_ERROR_AI_NO_AI_FOUND :No suitable AI found to load.{}This AI is a dummy AI and won't do anything.{}You can download several AIs via the 'Online Content' system
|
||||
STR_ERROR_AI_PLEASE_REPORT_CRASH :{WHITE}One of the running scripts crashed. Please report this to the script author with a screenshot of the AI/Game Script Debug Window
|
||||
|
|
|
@ -58,5 +58,5 @@
|
|||
|
||||
/* Also still print to debug window */
|
||||
Debug(script, level, "[{}] [{}] {}", (uint)ScriptObject::GetRootCompany(), logc, line.text);
|
||||
InvalidateWindowData(WC_SCRIPT_DEBUG, 0, ScriptObject::GetRootCompany());
|
||||
InvalidateWindowClassesData(WC_SCRIPT_DEBUG, ScriptObject::GetRootCompany());
|
||||
}
|
||||
|
|
|
@ -776,7 +776,7 @@ struct ScriptDebugWindow : public Window {
|
|||
* @param desc The description of the window.
|
||||
* @param number The window number (actually unused).
|
||||
*/
|
||||
ScriptDebugWindow(WindowDesc *desc, WindowNumber number) : Window(desc), break_editbox(MAX_BREAK_STR_STRING_LENGTH)
|
||||
ScriptDebugWindow(WindowDesc *desc, WindowNumber number, Owner show_company) : Window(desc), break_editbox(MAX_BREAK_STR_STRING_LENGTH)
|
||||
{
|
||||
this->filter = ScriptDebugWindow::initial_state;
|
||||
this->break_string_filter = {&this->filter.case_sensitive_break_check, false};
|
||||
|
@ -800,7 +800,11 @@ struct ScriptDebugWindow : public Window {
|
|||
/* Restore the break string value from static variable */
|
||||
this->break_editbox.text.Assign(this->filter.break_string);
|
||||
|
||||
this->SelectValidDebugCompany();
|
||||
if (show_company == INVALID_COMPANY) {
|
||||
this->SelectValidDebugCompany();
|
||||
} else {
|
||||
this->ChangeToScript(show_company);
|
||||
}
|
||||
this->InvalidateData(-1);
|
||||
}
|
||||
|
||||
|
@ -985,11 +989,18 @@ struct ScriptDebugWindow : public Window {
|
|||
/**
|
||||
* Change all settings to select another Script.
|
||||
* @param show_ai The new AI to show.
|
||||
* @param new_window Open the script in a new window.
|
||||
*/
|
||||
void ChangeToScript(CompanyID show_script)
|
||||
void ChangeToScript(CompanyID show_script, bool new_window = false)
|
||||
{
|
||||
if (!this->IsValidDebugCompany(show_script)) return;
|
||||
|
||||
if (new_window) {
|
||||
ScriptDebugWindow::initial_state = this->filter;
|
||||
ShowScriptDebugWindow(show_script, true);
|
||||
return;
|
||||
}
|
||||
|
||||
this->filter.script_debug_company = show_script;
|
||||
|
||||
this->highlight_row = -1; // The highlight of one Script make little sense for another Script.
|
||||
|
@ -1010,12 +1021,12 @@ struct ScriptDebugWindow : public Window {
|
|||
|
||||
/* Check which button is clicked */
|
||||
if (IsInsideMM(widget, WID_SCRD_COMPANY_BUTTON_START, WID_SCRD_COMPANY_BUTTON_END + 1)) {
|
||||
ChangeToScript((CompanyID)(widget - WID_SCRD_COMPANY_BUTTON_START));
|
||||
ChangeToScript((CompanyID)(widget - WID_SCRD_COMPANY_BUTTON_START), _ctrl_pressed);
|
||||
}
|
||||
|
||||
switch (widget) {
|
||||
case WID_SCRD_SCRIPT_GAME:
|
||||
ChangeToScript(OWNER_DEITY);
|
||||
ChangeToScript(OWNER_DEITY, _ctrl_pressed);
|
||||
break;
|
||||
|
||||
case WID_SCRD_RELOAD_TOGGLE:
|
||||
|
@ -1250,14 +1261,32 @@ static WindowDesc _script_debug_desc(__FILE__, __LINE__,
|
|||
/**
|
||||
* Open the Script debug window and select the given company.
|
||||
* @param show_company Display debug information about this AI company.
|
||||
* @param new_window Show in new window instead of existing window.
|
||||
*/
|
||||
Window *ShowScriptDebugWindow(CompanyID show_company)
|
||||
Window *ShowScriptDebugWindow(CompanyID show_company, bool new_window)
|
||||
{
|
||||
if (!_networking || _network_server) {
|
||||
ScriptDebugWindow *w = (ScriptDebugWindow *)BringWindowToFrontById(WC_SCRIPT_DEBUG, 0);
|
||||
if (w == nullptr) w = new ScriptDebugWindow(&_script_debug_desc, 0);
|
||||
if (show_company != INVALID_COMPANY) w->ChangeToScript(show_company);
|
||||
return w;
|
||||
int i = 0;
|
||||
if (new_window) {
|
||||
/* find next free window number for script debug */
|
||||
while (FindWindowById(WC_SCRIPT_DEBUG, i) != nullptr) i++;
|
||||
} else {
|
||||
/* Find existing window showing show_company. */
|
||||
for (Window *w : Window::Iterate()) {
|
||||
if (w->window_class == WC_SCRIPT_DEBUG && static_cast<ScriptDebugWindow *>(w)->filter.script_debug_company == show_company) {
|
||||
return BringWindowToFrontById(w->window_class, w->window_number);
|
||||
}
|
||||
}
|
||||
|
||||
/* Maybe there's a window showing a different company which can be switched. */
|
||||
ScriptDebugWindow *w = static_cast<ScriptDebugWindow *>(FindWindowByClass(WC_SCRIPT_DEBUG));
|
||||
if (w != nullptr) {
|
||||
BringWindowToFrontById(w->window_class, w->window_number);
|
||||
w->ChangeToScript(show_company);
|
||||
return w;
|
||||
}
|
||||
}
|
||||
return new ScriptDebugWindow(&_script_debug_desc, i, show_company);
|
||||
} else {
|
||||
ShowErrorMessage(STR_ERROR_AI_DEBUG_SERVER_ONLY, INVALID_STRING_ID, WL_INFO);
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include "../textfile_type.h"
|
||||
|
||||
void ShowScriptListWindow(CompanyID slot, bool show_all);
|
||||
Window *ShowScriptDebugWindow(CompanyID show_company = INVALID_COMPANY);
|
||||
Window *ShowScriptDebugWindow(CompanyID show_company = INVALID_COMPANY, bool new_window = false);
|
||||
void ShowScriptSettingsWindow(CompanyID slot);
|
||||
void ShowScriptTextfileWindow(TextfileType file_type, CompanyID slot);
|
||||
void ShowScriptDebugWindowIfScriptError();
|
||||
|
|
|
@ -1120,7 +1120,7 @@ static CallBackFunction MenuClickHelp(int index)
|
|||
case 0: return PlaceLandBlockInfo();
|
||||
case 1: ShowHelpWindow(); break;
|
||||
case 2: IConsoleSwitch(); break;
|
||||
case 3: ShowScriptDebugWindow(); break;
|
||||
case 3: ShowScriptDebugWindow(INVALID_COMPANY, _ctrl_pressed); break;
|
||||
case 4: ShowScreenshotWindow(); break;
|
||||
case 5: ShowFramerateWindow(); break;
|
||||
case 6: ShowAboutWindow(); break;
|
||||
|
|
Loading…
Reference in New Issue