Changeset - r19068:3e8bf48b7b8a
[Not reviewed]
master
0 7 0
rubidium - 13 years ago 2012-02-12 10:58:18
rubidium@openttd.org
(svn r23936) -Feature [FS#5047]: readme/licence/changelog viewer for AI and game scripts (LordAro)
7 files changed with 75 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/ai/ai_gui.cpp
Show inline comments
 
@@ -20,12 +20,13 @@
 
#include "../window_func.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 "ai.hpp"
 
#include "../script/api/script_log.hpp"
 
#include "ai_config.hpp"
 
#include "ai_info.hpp"
 
#include "ai_instance.hpp"
 
@@ -556,12 +557,46 @@ static void ShowAISettingsWindow(Company
 
{
 
	DeleteWindowByClass(WC_AI_LIST);
 
	DeleteWindowByClass(WC_AI_SETTINGS);
 
	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),
 
		NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
 
		NWidget(WWT_CAPTION, COLOUR_MAUVE), SetDataTip(STR_AI_CONFIG_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
	EndContainer(),
 
@@ -589,12 +624,17 @@ static const NWidgetPart _nested_ai_conf
 
			NWidget(WWT_MATRIX, COLOUR_MAUVE, WID_AIC_GAMELIST), SetMinimalSize(288, 14), SetFill(1, 0), SetDataTip(0x101, STR_AI_CONFIG_GAMELIST_TOOLTIP),
 
		EndContainer(),
 
		NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7),
 
			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(),
 
};
 

	
 
/** Window definition for the configure AI window. */
 
@@ -725,12 +765,19 @@ 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: {
 
				int new_value;
 
				if (widget == WID_AIC_DECREASE) {
 
					new_value = max(0, GetGameSettings().difficulty.max_no_competitors - 1);
 
@@ -815,12 +862,16 @@ struct AIConfigWindow : public Window {
 
		this->SetWidgetDisabledState(WID_AIC_DECREASE, GetGameSettings().difficulty.max_no_competitors == 0);
 
		this->SetWidgetDisabledState(WID_AIC_INCREASE, GetGameSettings().difficulty.max_no_competitors == MAX_COMPANIES - 1);
 
		this->SetWidgetDisabledState(WID_AIC_CHANGE, this->selected_slot == INVALID_COMPANY);
 
		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));
 
		}
 
	}
 
};
 

	
 
/** Open the AI config window. */
 
void ShowAIConfigWindow()
 
{
src/script/api/game/game_window.hpp.sq
Show inline comments
 
@@ -177,12 +177,13 @@ void SQGSWindow_Register(Squirrel *engin
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_AIC_SCROLLBAR,                         "WID_AIC_SCROLLBAR");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_AIC_MOVE_UP,                           "WID_AIC_MOVE_UP");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_AIC_MOVE_DOWN,                         "WID_AIC_MOVE_DOWN");
 
	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");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_AID_SETTINGS,                          "WID_AID_SETTINGS");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_AID_SCRIPT_GAME,                       "WID_AID_SCRIPT_GAME");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_AID_RELOAD_TOGGLE,                     "WID_AID_RELOAD_TOGGLE");
src/script/api/script_window.hpp
Show inline comments
 
@@ -840,12 +840,13 @@ public:
 
		WID_AIC_SCROLLBAR                    = ::WID_AIC_SCROLLBAR,                    ///< Scrollbar to scroll through the selected AIs.
 
		WID_AIC_MOVE_UP                      = ::WID_AIC_MOVE_UP,                      ///< Move up button.
 
		WID_AIC_MOVE_DOWN                    = ::WID_AIC_MOVE_DOWN,                    ///< Move down button.
 
		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.
 
	};
 

	
 
	/** Widgets of the #AIDebugWindow class. */
 
	enum AIDebugWidgets {
 
		WID_AID_VIEW                         = ::WID_AID_VIEW,                         ///< The row of company buttons.
src/script/script_config.cpp
Show inline comments
 
@@ -10,12 +10,13 @@
 
/** @file script_config.cpp Implementation of ScriptConfig. */
 

	
 
#include "../stdafx.h"
 
#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)
 
{
 
	free(this->name);
 
	this->name = (name == NULL) ? NULL : strdup(name);
 
	this->info = (name == NULL) ? NULL : this->FindInfo(this->name, version, force_exact_match);
 
@@ -195,6 +196,13 @@ void ScriptConfig::SettingsToString(char
 
		strcat(string, ",");
 
	}
 
	/* Remove the last ',', but only if at least one setting was saved. */
 
	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());
 
}
src/script/script_config.hpp
Show inline comments
 
@@ -13,12 +13,14 @@
 
#define SCRIPT_CONFIG_HPP
 

	
 
#include <map>
 
#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 {
 
	SCRIPTCONFIG_NONE      = 0x0, ///< No flags set.
 
	SCRIPTCONFIG_RANDOM    = 0x1, ///< When randomizing the Script, pick any value between min_value and max_value when on custom difficulty setting.
 
	SCRIPTCONFIG_BOOLEAN   = 0x2, ///< This value is a boolean (either 0 (false) or 1 (true) ).
 
@@ -158,12 +160,20 @@ public:
 
	/**
 
	 * Convert the custom settings to a string that can be stored in the config
 
	 *  file or savegames.
 
	 */
 
	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
 
	class ScriptInfo *info;            ///< ScriptInfo object for related to this Script version
 
	SettingValueList settings;         ///< List with all setting=>value pairs that are configure for this Script
 
	ScriptConfigItemList *config_list; ///< List with all settings defined by this Script
src/textfile_gui.h
Show inline comments
 
@@ -9,12 +9,13 @@
 

	
 
/** @file textfile_gui.h GUI functions related to textfiles. */
 

	
 
#ifndef TEXTFILE_GUI_H
 
#define TEXTFILE_GUI_H
 

	
 
#include "fileio_type.h"
 
#include "strings_func.h"
 
#include "textfile_type.h"
 
#include "window_gui.h"
 

	
 
const char *GetTextfile(TextfileType type, Subdirectory dir, const char *filename);
 

	
src/widgets/ai_widget.h
Show inline comments
 
@@ -10,12 +10,13 @@
 
/** @file ai_widget.h Types related to the ai widgets. */
 

	
 
#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.
 
@@ -44,13 +45,14 @@ enum AIConfigWidgets {
 
	WID_AIC_SCROLLBAR,        ///< Scrollbar to scroll through the selected AIs.
 
	WID_AIC_MOVE_UP,          ///< Move up button.
 
	WID_AIC_MOVE_DOWN,        ///< Move down button.
 
	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. */
 
enum AIDebugWidgets {
 
	WID_AID_VIEW,                 ///< The row of company buttons.
 
	WID_AID_NAME_TEXT,            ///< Name of the current selected.
0 comments (0 inline, 0 general)