# HG changeset patch # Parent 0b2121431b0564b53bd70cefb03e70338be14095 diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp --- a/src/ai/ai_gui.cpp +++ b/src/ai/ai_gui.cpp @@ -23,6 +23,7 @@ #include "../network/network.h" #include "../settings_func.h" #include "../network/network_content.h" +#include "../textfile_gui.h" #include "ai.hpp" #include "../script/api/script_log.hpp" @@ -563,6 +564,42 @@ new AISettingsWindow(&_ai_settings_desc, slot); } + +/** Window for displaying the textfile of a AI. */ +struct ScriptTextfileWindow : public TextfileWindow { + CompanyID slot; ///< View the textfile of this CompanyID slot. + + ScriptTextfileWindow(const WindowDesc *desc, TextfileType file_type, CompanyID slot) : TextfileWindow(desc, file_type), slot(slot) + { + this->GetWidget(WID_TF_CAPTION)->SetDataTip(STR_TEXTFILE_README_CAPTION + file_type, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS); + + const char *textfile = GetConfig(slot)->GetScriptTextfile(file_type, slot); + + this->LoadTextfile(textfile, (slot == OWNER_DEITY) ? GAME_DIR : AI_DIR); + + } + + /* virtual */ void SetStringParameters(int widget) const + { + if (widget == WID_TF_CAPTION) { + SetDParam(0, (slot == OWNER_DEITY) ? STR_CONTENT_TYPE_GAME_SCRIPT : STR_CONTENT_TYPE_AI); + SetDParamStr(1, GetConfig(slot)->GetName()); + } + } +}; + +/** + * Open the AI version of the textfile window. + * @param file_type The type of textfile to display. + * @param slot The slot the Script is using. + */ +void ShowScriptTextfileWindow(TextfileType file_type, CompanyID slot) +{ + DeleteWindowByClass(WC_TEXTFILE); + new ScriptTextfileWindow(&_textfile_desc, file_type, slot); +} + + /** Widgets for the configure AI window. */ static const NWidgetPart _nested_ai_config_widgets[] = { NWidget(NWID_HORIZONTAL), @@ -596,6 +633,11 @@ NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_CHANGE), SetFill(1, 0), SetMinimalSize(93, 12), SetDataTip(STR_AI_CONFIG_CHANGE, STR_AI_CONFIG_CHANGE_TOOLTIP), NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_CONFIGURE), SetFill(1, 0), SetMinimalSize(93, 12), SetDataTip(STR_AI_CONFIG_CONFIGURE, STR_AI_CONFIG_CONFIGURE_TOOLTIP), NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_CLOSE), SetFill(1, 0), SetMinimalSize(93, 12), SetDataTip(STR_AI_SETTINGS_CLOSE, STR_NULL), + EndContainer(), + NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7), + NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_README, STR_NULL), + NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_TEXTFILE + TFT_CHANGELOG), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_NULL), + NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_TEXTFILE + TFT_LICENSE), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_LICENCE, STR_NULL), EndContainer(), NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_CONTENT_DOWNLOAD), SetFill(1, 0), SetMinimalSize(279, 12), SetPadding(0, 7, 9, 7), SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT), EndContainer(), @@ -732,6 +774,13 @@ virtual void OnClick(Point pt, int widget, int click_count) { + if (widget >= WID_AIC_TEXTFILE && widget < WID_AIC_TEXTFILE + TFT_END) { + if (this->selected_slot == INVALID_COMPANY || GetConfig(this->selected_slot) == NULL) return; + + ShowScriptTextfileWindow((TextfileType)(widget - WID_AIC_TEXTFILE), this->selected_slot); + return; + } + switch (widget) { case WID_AIC_DECREASE: case WID_AIC_INCREASE: { @@ -822,6 +871,10 @@ this->SetWidgetDisabledState(WID_AIC_CONFIGURE, this->selected_slot == INVALID_COMPANY || GetConfig(this->selected_slot)->GetConfigList()->size() == 0); this->SetWidgetDisabledState(WID_AIC_MOVE_UP, this->selected_slot == OWNER_DEITY || this->selected_slot == INVALID_COMPANY || !IsEditable((CompanyID)(this->selected_slot - 1))); this->SetWidgetDisabledState(WID_AIC_MOVE_DOWN, this->selected_slot == OWNER_DEITY || this->selected_slot == INVALID_COMPANY || !IsEditable((CompanyID)(this->selected_slot + 1))); + + for (TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) { + this->SetWidgetDisabledState(WID_AIC_TEXTFILE + tft, this->selected_slot == INVALID_COMPANY || (GetConfig(this->selected_slot)->GetScriptTextfile(tft, this->selected_slot) == NULL)); + } } }; diff --git a/src/script/api/game/game_window.hpp.sq b/src/script/api/game/game_window.hpp.sq --- a/src/script/api/game/game_window.hpp.sq +++ b/src/script/api/game/game_window.hpp.sq @@ -180,6 +180,7 @@ SQGSWindow.DefSQConst(engine, ScriptWindow::WID_AIC_CHANGE, "WID_AIC_CHANGE"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_AIC_CONFIGURE, "WID_AIC_CONFIGURE"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_AIC_CLOSE, "WID_AIC_CLOSE"); + SQGSWindow.DefSQConst(engine, ScriptWindow::WID_AIC_TEXTFILE, "WID_AIC_TEXTFILE"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_AIC_CONTENT_DOWNLOAD, "WID_AIC_CONTENT_DOWNLOAD"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_AID_VIEW, "WID_AID_VIEW"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_AID_NAME_TEXT, "WID_AID_NAME_TEXT"); diff --git a/src/script/api/script_window.hpp b/src/script/api/script_window.hpp --- a/src/script/api/script_window.hpp +++ b/src/script/api/script_window.hpp @@ -843,6 +843,7 @@ WID_AIC_CHANGE = ::WID_AIC_CHANGE, ///< Select another AI button. WID_AIC_CONFIGURE = ::WID_AIC_CONFIGURE, ///< Change AI settings button. WID_AIC_CLOSE = ::WID_AIC_CLOSE, ///< Close window button. + WID_AIC_TEXTFILE = ::WID_AIC_TEXTFILE, ///< Open Script readme, changelog (+1) or license (+2). WID_AIC_CONTENT_DOWNLOAD = ::WID_AIC_CONTENT_DOWNLOAD, ///< Download content button. }; diff --git a/src/script/script_config.cpp b/src/script/script_config.cpp --- a/src/script/script_config.cpp +++ b/src/script/script_config.cpp @@ -13,6 +13,7 @@ #include "../settings_type.h" #include "../core/random_func.hpp" #include "script_info.hpp" +#include "../textfile_gui.h" void ScriptConfig::Change(const char *name, int version, bool force_exact_match, bool is_random) { @@ -198,3 +199,10 @@ size_t len = strlen(string); if (len > 0) string[len - 1] = '\0'; } + +const char *ScriptConfig::GetScriptTextfile(TextfileType type, CompanyID slot) const +{ + if (slot == INVALID_COMPANY || this->GetInfo() == NULL) return NULL; + + return GetTextfile(type, (slot == OWNER_DEITY) ? GAME_DIR : AI_DIR, this->GetInfo()->GetMainScript()); +} diff --git a/src/script/script_config.hpp b/src/script/script_config.hpp --- a/src/script/script_config.hpp +++ b/src/script/script_config.hpp @@ -16,6 +16,8 @@ #include #include "../core/smallmap_type.hpp" #include "../core/string_compare_type.hpp" +#include "../company_type.h" +#include "../textfile_gui.h" /** Bitmask of flags for Script settings. */ enum ScriptConfigFlags { @@ -161,6 +163,14 @@ */ void SettingsToString(char *string, size_t size) const; + /** + * Search a textfile file next to this script. + * @param type The type of the textfile to search for. + * @param slot #CompanyID to check status of. + * @return The filename for the textfile, \c NULL otherwise. + */ + const char *GetScriptTextfile(TextfileType type, CompanyID slot) const; + protected: const char *name; ///< Name of the Script int version; ///< Version of the Script diff --git a/src/widgets/ai_widget.h b/src/widgets/ai_widget.h --- a/src/widgets/ai_widget.h +++ b/src/widgets/ai_widget.h @@ -13,6 +13,7 @@ #define WIDGETS_AI_WIDGET_H #include "../company_type.h" +#include "../textfile_type.h" /** Widgets of the #AIListWindow class. */ enum AIListWidgets { @@ -47,7 +48,8 @@ WID_AIC_CHANGE, ///< Select another AI button. WID_AIC_CONFIGURE, ///< Change AI settings button. WID_AIC_CLOSE, ///< Close window button. - WID_AIC_CONTENT_DOWNLOAD, ///< Download content button. + WID_AIC_TEXTFILE, ///< Open AI readme, changelog (+1) or license (+2). + WID_AIC_CONTENT_DOWNLOAD = WID_AIC_TEXTFILE + TFT_END, ///< Download content button. }; /** Widgets of the #AIDebugWindow class. */