mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-09 07:29:44 +00:00
Change: Improve ScriptSettings windows (#11958)
This commit is contained in:
parent
0e738dda88
commit
4e26e33805
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4835,6 +4835,8 @@ STR_AI_SETTINGS_CAPTION_GAMESCRIPT :Game Script
|
||||
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
|
||||
|
@ -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.
|
||||
|
@ -379,10 +379,18 @@ struct ScriptSettingsWindow : public Window {
|
||||
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 Window {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -162,6 +162,13 @@ SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm)
|
||||
}
|
||||
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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user