Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/options/options.js
Show All 27 Lines | |||||
*/ | */ | ||||
var g_OptionControlHeight = 26; | var g_OptionControlHeight = 26; | ||||
/** | /** | ||||
* Vertical distance between two consecutive options. | * Vertical distance between two consecutive options. | ||||
*/ | */ | ||||
var g_OptionControlDist = 2; | var g_OptionControlDist = 2; | ||||
/** | /** | ||||
elexis: That `toFixed(2)` already was a workaround and should be replaced with something more solid. | |||||
Not Done Inline ActionsDo you want to add a precision to the options.json? vladislavbelov: Do you want to add a precision to the `options.json`? | |||||
Not Done Inline ActionsIf we had a stepWidth and a warning if ((maxValue - minValue) / stepWidth) % 1 != 0 then we don't need two arguments, nor doing the math to find out the stepWidth. I don't see a use case for 0.124 or 0.3333333 stepWidth. At least the latter case should be solvable somehow. elexis: If we had a `stepWidth` and a warning if `((maxValue - minValue) / stepWidth) % 1 != 0` then we… | |||||
* Horizontal indentation to distinguish options that depend on another option. | * Horizontal indentation to distinguish options that depend on another option. | ||||
*/ | */ | ||||
var g_DependentLabelIndentation = 25; | var g_DependentLabelIndentation = 25; | ||||
/** | /** | ||||
* Color used to indicate that the string entered by the player isn't a sane color. | * Color used to indicate that the string entered by the player isn't a sane color. | ||||
*/ | */ | ||||
var g_InsaneColor = "255 0 255"; | var g_InsaneColor = "255 0 255"; | ||||
▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | "initGUI": (option, control) => { | ||||
}; | }; | ||||
} | } | ||||
}, | }, | ||||
"slider": | "slider": | ||||
{ | { | ||||
"configToValue": value => +value, | "configToValue": value => +value, | ||||
"valueToGui": (value, control) => { | "valueToGui": (value, control) => { | ||||
control.value = +value; | control.value = +value; | ||||
control.children[0].caption = value; | |||||
}, | }, | ||||
"guiToValue": control => control.value, | "guiToValue": control => control.value, | ||||
"guiSetter": "onValueChange", | "guiSetter": "onValueChange", | ||||
Not Done Inline ActionsCan't you use 1/step_size rather? wraitii: Can't you use 1/step_size rather? | |||||
"initGUI": (option, control) => { | "initGUI": (option, control) => { | ||||
control.max_value = option.max; | |||||
control.min_value = option.min; | control.min_value = option.min; | ||||
control.max_value = option.max; | |||||
control.step_size = option.step_size; | |||||
}, | }, | ||||
"tooltip": (value, option) => | "tooltip": (value, option) => | ||||
sprintf(translateWithContext("slider number", "Value: %(val)s (min: %(min)s, max: %(max)s)"), { | sprintf(translateWithContext("slider number", "Value: %(val)s (min: %(min)s, max: %(max)s)"), { | ||||
"val": value.toFixed(2), | "val": value, | ||||
"min": option.min.toFixed(2), | "min": option.min, | ||||
"max": option.max.toFixed(2) | "max": option.max | ||||
}) | }), | ||||
"onGUISet": (value, control, option) => { | |||||
control.children[0].caption = value; | |||||
} | |||||
} | } | ||||
}; | }; | ||||
function init(data, hotloadData) | function init(data, hotloadData) | ||||
{ | { | ||||
g_ChangedKeys = hotloadData ? hotloadData.changedKeys : new Set(); | g_ChangedKeys = hotloadData ? hotloadData.changedKeys : new Set(); | ||||
g_TabCategorySelected = hotloadData ? hotloadData.tabCategorySelected : 0; | g_TabCategorySelected = hotloadData ? hotloadData.tabCategorySelected : 0; | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | for (let i = 0; i < g_Options[g_TabCategorySelected].options.length; ++i) | ||||
control[optionType.guiSetter] = function() { | control[optionType.guiSetter] = function() { | ||||
let value = optionType.guiToValue(control); | let value = optionType.guiToValue(control); | ||||
if (optionType.sanitizeValue) | if (optionType.sanitizeValue) | ||||
optionType.sanitizeValue(value, control, option); | optionType.sanitizeValue(value, control, option); | ||||
if (optionType.onGUISet) | |||||
optionType.onGUISet(value, control, option); | |||||
control.tooltip = option.tooltip + (optionType.tooltip ? "\n" + optionType.tooltip(value, option) : ""); | control.tooltip = option.tooltip + (optionType.tooltip ? "\n" + optionType.tooltip(value, option) : ""); | ||||
Engine.ConfigDB_CreateValue("user", option.config, String(value)); | Engine.ConfigDB_CreateValue("user", option.config, String(value)); | ||||
Engine.ConfigDB_SetChanges("user", true); | Engine.ConfigDB_SetChanges("user", true); | ||||
g_ChangedKeys.add(option.config); | g_ChangedKeys.add(option.config); | ||||
fireConfigChangeHandlers(new Set([option.config])); | fireConfigChangeHandlers(new Set([option.config])); | ||||
▲ Show 20 Lines • Show All 136 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
That toFixed(2) already was a workaround and should be replaced with something more solid.
With this patch, they should become unneeded altogether. It's the responsability of the options.json file to ensure that there are only numbers with N digits, right?