Adding a string option for the CSV Separator
Here's how you can do it:
In your onInit routine, place the following code:
Code:
OptionsManager.registerOption2("GENPUNC", false, "option_header_game", "option_label_GENPUNC", "option_entry_stringer",
{ baselabel = "option_val_comma", baseval = ",", default = "," });
'GENPUNC' or whatever you want to use instead of that will be the reference you later use to get the value of the setting.
The false parameter tells the option manager it is an option that should be stored in the campaign database (true causes it to be stored in the campaign registry).
'option_header_game' tells the Options Manager to put the setting into the games settings area (see the strings\strings_utility.xml file for the constants you can use to control where the option appears)
'option_label_GENPUNC' tells the Options Manager to look for this string resource for the label you want assigned on the options manager. It looks like this:
Code:
<string name="option_label_GENPUNC">Generators: Punctuation to separate items in a series</string>
'option_entry_stringer' is the windowless you want to use to handle the interaction with the user. There is not currently a built-in routine to handle what you are looking for, but this code below is fully tested and will handle a string option setting that is free-form:
Code:
<windowclass name="option_entry_stringer">
<margins control="0,0,0,2" />
<script>
local sOptionKey = nil;
local sDefaultVal = "";
local enable_update = true;
function setLabel(sLabel)
label.setValue(sLabel);
end
function setReadOnly(bValue)
stringer.setReadOnly(bValue);
end
function initialize(sKey, aCustom)
sOptionKey = sKey;
if sOptionKey then
if aCustom then
sDefaultVal = aCustom.baseval or "";
end
enable_update = false;
local sValue = OptionsManager.getOption(sOptionKey);
stringer.setValue(sValue);
enable_update = true;
end
end
function onHover(bOnWindow)
if bOnWindow then
setFrame("rowshade");
else
setFrame(nil);
end
end
function onValueChanged()
if enable_update and sOptionKey then
local sValue = stringer.getValue();
OptionsManager.setOption(sOptionKey, sValue);
end
end
</script>
The last parameter is an array passed to control behavior. Since this is a freeform string, I don't set up a series of labels, but you could conceivably setup a series of "|" (pipe) delimited string resource names of labels to use. (or lablesraw if you don't want resources).
What I have up there will make the default be a comma, and the 'option_val_comma' is a string resource you set up in your xml file like this:
Code:
<string name="option_val_comma">,</string>
Where you need to get the current CSV setting, you would do something like this:
Code:
local sSeparator=OptionsManager.getOption("GENPUNC");
If you needed to (not sure why you would need to), you could use the Options Manager to register a callback to your code if the value of your setting changes. (see the Options Manager registerCallback and unregisterCallback routines).