summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2012-02-12 10:58:18 +0000
committerrubidium <rubidium@openttd.org>2012-02-12 10:58:18 +0000
commit6356178a259d0734c49ef5c62bfbffb86097053b (patch)
treeab99429845ab4be9a15d179887f74a52ce5a3a9a
parent58269b7ad2a70b94de104ede2c69e126b58be534 (diff)
downloadopenttd-6356178a259d0734c49ef5c62bfbffb86097053b.tar.xz
(svn r23936) -Feature [FS#5047]: readme/licence/changelog viewer for AI and game scripts (LordAro)
-rw-r--r--src/ai/ai_gui.cpp51
-rw-r--r--src/script/api/game/game_window.hpp.sq1
-rw-r--r--src/script/api/script_window.hpp1
-rw-r--r--src/script/script_config.cpp8
-rw-r--r--src/script/script_config.hpp10
-rw-r--r--src/textfile_gui.h1
-rw-r--r--src/widgets/ai_widget.h4
7 files changed, 75 insertions, 1 deletions
diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp
index 40cca3b51..2e7eab65c 100644
--- 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"
@@ -559,6 +560,40 @@ static void ShowAISettingsWindow(CompanyID slot)
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(TextfileType file_type, CompanyID slot) : TextfileWindow(file_type), slot(slot)
+ {
+ this->GetWidget<NWidgetCore>(WID_TF_CAPTION)->SetDataTip(STR_TEXTFILE_README_CAPTION + file_type, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS);
+
+ const char *textfile = GetConfig(slot)->GetTextfile(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(file_type, slot);
+}
+
+
/** Widgets for the configure AI window. */
static const NWidgetPart _nested_ai_config_widgets[] = {
NWidget(NWID_HORIZONTAL),
@@ -592,6 +627,11 @@ static const NWidgetPart _nested_ai_config_widgets[] = {
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(),
@@ -728,6 +768,13 @@ struct AIConfigWindow : public Window {
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: {
@@ -818,6 +865,10 @@ struct AIConfigWindow : public Window {
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)->GetTextfile(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
index e1c118adf..395a60c6d 100644
--- a/src/script/api/game/game_window.hpp.sq
+++ b/src/script/api/game/game_window.hpp.sq
@@ -180,6 +180,7 @@ void SQGSWindow_Register(Squirrel *engine)
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
index 0cda667db..b31c738f0 100644
--- a/src/script/api/script_window.hpp
+++ b/src/script/api/script_window.hpp
@@ -843,6 +843,7 @@ public:
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
index 70ffbfd83..7f41304d4 100644
--- 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 @@ void ScriptConfig::SettingsToString(char *string, size_t size) const
size_t len = strlen(string);
if (len > 0) string[len - 1] = '\0';
}
+
+const char *ScriptConfig::GetTextfile(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
index b6c7a8fa6..9ae6fba70 100644
--- a/src/script/script_config.hpp
+++ b/src/script/script_config.hpp
@@ -16,6 +16,8 @@
#include <list>
#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 @@ public:
*/
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 *GetTextfile(TextfileType type, CompanyID slot) const;
+
protected:
const char *name; ///< Name of the Script
int version; ///< Version of the Script
diff --git a/src/textfile_gui.h b/src/textfile_gui.h
index 846e93c56..a2d2af8f9 100644
--- a/src/textfile_gui.h
+++ b/src/textfile_gui.h
@@ -12,6 +12,7 @@
#ifndef TEXTFILE_GUI_H
#define TEXTFILE_GUI_H
+#include "fileio_type.h"
#include "strings_func.h"
#include "textfile_type.h"
#include "window_gui.h"
diff --git a/src/widgets/ai_widget.h b/src/widgets/ai_widget.h
index 4261478f5..76b22b8b4 100644
--- 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 @@ enum AIConfigWidgets {
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. */