Changeset - r28639:c49fb80b1404
[Not reviewed]
master
0 5 0
Loïc Guilloux - 10 months ago 2024-02-02 18:08:05
glx22@users.noreply.github.com
Change: Improve ScriptSettings windows (#11958)
5 files changed with 87 insertions and 16 deletions:
0 comments (0 inline, 0 general)
src/game/game_gui.cpp
Show inline comments
 
@@ -199,10 +199,18 @@ struct GSConfigWindow : public Window {
 
					TextColour colour;
 
					uint idx = 0;
 
					if (config_item.description.empty()) {
 
						str = STR_JUST_STRING1;
 
						if (Game::GetInstance() == nullptr && config_item.random_deviation != 0) {
 
							str = STR_AI_SETTINGS_JUST_DEVIATION;
 
						} else {
 
							str = STR_JUST_STRING1;
 
						}
 
						colour = TC_ORANGE;
 
					} else {
 
						str = STR_AI_SETTINGS_SETTING;
 
						if (Game::GetInstance() == nullptr && config_item.random_deviation != 0) {
 
							str = STR_AI_SETTINGS_SETTING_DEVIATION;
 
						} else {
 
							str = STR_AI_SETTINGS_SETTING;
 
						}
 
						colour = TC_LIGHT_BLUE;
 
						SetDParamStr(idx++, config_item.description);
 
					}
 
@@ -216,13 +224,36 @@ struct GSConfigWindow : public Window {
 
						} else {
 
							DrawArrowButtons(br.left, y + button_y_offset, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, editable && current_value > config_item.min_value, editable && current_value < config_item.max_value);
 
						}
 
						auto config_iterator = config_item.labels.find(current_value);
 
						if (config_iterator != config_item.labels.end()) {
 
							SetDParam(idx++, STR_JUST_RAW_STRING);
 
							SetDParamStr(idx++, config_iterator->second);
 

	
 
						if (Game::GetInstance() != nullptr || config_item.random_deviation == 0) {
 
							auto config_iterator = config_item.labels.find(current_value);
 
							if (config_iterator != config_item.labels.end()) {
 
								SetDParam(idx++, STR_JUST_RAW_STRING);
 
								SetDParamStr(idx++, config_iterator->second);
 
							} else {
 
								SetDParam(idx++, STR_JUST_INT);
 
								SetDParam(idx++, current_value);
 
							}
 
						} else {
 
							SetDParam(idx++, STR_JUST_INT);
 
							SetDParam(idx++, current_value);
 
							int min_deviated = std::max(config_item.min_value, current_value - config_item.random_deviation);
 
							auto config_iterator = config_item.labels.find(min_deviated);
 
							if (config_iterator != config_item.labels.end()) {
 
								SetDParam(idx++, STR_JUST_RAW_STRING);
 
								SetDParamStr(idx++, config_iterator->second);
 
							} else {
 
								SetDParam(idx++, STR_JUST_INT);
 
								SetDParam(idx++, min_deviated);
 
							}
 

	
 
							int max_deviated = std::min(config_item.max_value, current_value + config_item.random_deviation);
 
							config_iterator = config_item.labels.find(max_deviated);
 
							if (config_iterator != config_item.labels.end()) {
 
								SetDParam(idx++, STR_JUST_RAW_STRING);
 
								SetDParamStr(idx++, config_iterator->second);
 
							} else {
 
								SetDParam(idx++, STR_JUST_INT);
 
								SetDParam(idx++, max_deviated);
 
							}
 
						}
 
					}
 

	
src/lang/english.txt
Show inline comments
 
@@ -4835,6 +4835,8 @@ STR_AI_SETTINGS_CAPTION_GAMESCRIPT      
 
STR_AI_SETTINGS_CLOSE                                           :{BLACK}Close
 
STR_AI_SETTINGS_RESET                                           :{BLACK}Reset
 
STR_AI_SETTINGS_SETTING                                         :{RAW_STRING}: {ORANGE}{STRING1}
 
STR_AI_SETTINGS_SETTING_DEVIATION                               :{RAW_STRING}: {ORANGE}[{STRING1}, {STRING1}]
 
STR_AI_SETTINGS_JUST_DEVIATION                                  :[{STRING1}, {STRING1}]
 

	
 

	
 
# Textfile window
src/script/api/script_info_docs.hpp
Show inline comments
 
@@ -239,6 +239,7 @@ public:
 
	 *    [user_configured_value - random_deviation, user_configured_value + random_deviation] (inclusive).
 
	 *    random_deviation sign is ignored and the value is clamped in the range [0, MAX(int32_t)] (inclusive).
 
	 *    The randomisation will happen just before the Script start.
 
	 *    Not allowed if the CONFIG_BOOLEAN flag is set, otherwise optional.
 
	 *  - step_size The increase/decrease of the value every time the user
 
	 *    clicks one of the up/down arrow buttons. Optional, default is 1.
 
	 *  - flags Bitmask of some flags, see ScriptConfigFlags. Required.
src/script/script_gui.cpp
Show inline comments
 
@@ -379,10 +379,18 @@ struct ScriptSettingsWindow : public Win
 
			TextColour colour;
 
			uint idx = 0;
 
			if (config_item.description.empty()) {
 
				str = STR_JUST_STRING1;
 
				if (this->slot != OWNER_DEITY && !Company::IsValidID(this->slot) && config_item.random_deviation != 0) {
 
					str = STR_AI_SETTINGS_JUST_DEVIATION;
 
				} else {
 
					str = STR_JUST_STRING1;
 
				}
 
				colour = TC_ORANGE;
 
			} else {
 
				str = STR_AI_SETTINGS_SETTING;
 
				if (this->slot != OWNER_DEITY && !Company::IsValidID(this->slot) && config_item.random_deviation != 0) {
 
					str = STR_AI_SETTINGS_SETTING_DEVIATION;
 
				} else {
 
					str = STR_AI_SETTINGS_SETTING;
 
				}
 
				colour = TC_LIGHT_BLUE;
 
				SetDParamStr(idx++, config_item.description);
 
			}
 
@@ -397,13 +405,35 @@ struct ScriptSettingsWindow : public Win
 
					DrawArrowButtons(br.left, y + button_y_offset, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, editable && current_value > config_item.min_value, editable && current_value < config_item.max_value);
 
				}
 

	
 
				auto config_iterator = config_item.labels.find(current_value);
 
				if (config_iterator != config_item.labels.end()) {
 
					SetDParam(idx++, STR_JUST_RAW_STRING);
 
					SetDParamStr(idx++, config_iterator->second);
 
				if (this->slot == OWNER_DEITY || Company::IsValidID(this->slot) || config_item.random_deviation == 0) {
 
					auto config_iterator = config_item.labels.find(current_value);
 
					if (config_iterator != config_item.labels.end()) {
 
						SetDParam(idx++, STR_JUST_RAW_STRING);
 
						SetDParamStr(idx++, config_iterator->second);
 
					} else {
 
						SetDParam(idx++, STR_JUST_INT);
 
						SetDParam(idx++, current_value);
 
					}
 
				} else {
 
					SetDParam(idx++, STR_JUST_INT);
 
					SetDParam(idx++, current_value);
 
					int min_deviated = std::max(config_item.min_value, current_value - config_item.random_deviation);
 
					auto config_iterator = config_item.labels.find(min_deviated);
 
					if (config_iterator != config_item.labels.end()) {
 
						SetDParam(idx++, STR_JUST_RAW_STRING);
 
						SetDParamStr(idx++, config_iterator->second);
 
					} else {
 
						SetDParam(idx++, STR_JUST_INT);
 
						SetDParam(idx++, min_deviated);
 
					}
 

	
 
					int max_deviated = std::min(config_item.max_value, current_value + config_item.random_deviation);
 
					config_iterator = config_item.labels.find(max_deviated);
 
					if (config_iterator != config_item.labels.end()) {
 
						SetDParam(idx++, STR_JUST_RAW_STRING);
 
						SetDParamStr(idx++, config_iterator->second);
 
					} else {
 
						SetDParam(idx++, STR_JUST_INT);
 
						SetDParam(idx++, max_deviated);
 
					}
 
				}
 
			}
 

	
src/script/script_info.cpp
Show inline comments
 
@@ -162,6 +162,13 @@ SQInteger ScriptInfo::AddSetting(HSQUIRR
 
	}
 
	sq_pop(vm, 1);
 

	
 
	/* Don't allow both random_deviation and SCRIPTCONFIG_BOOLEAN to
 
	 * be set for the same config item. */
 
	if ((items & 0x200) != 0 && (config.flags & SCRIPTCONFIG_BOOLEAN) != 0) {
 
		this->engine->ThrowError("setting both random_deviation and CONFIG_BOOLEAN is not allowed");
 
		return SQ_ERROR;
 
	}
 

	
 
	/* Reset the bit for random_deviation as it's optional. */
 
	items &= ~0x200;
 

	
0 comments (0 inline, 0 general)