mirror of
https://github.com/GabsPuNs/Project-Zenith-Main.git
synced 2026-07-17 15:30:41 +00:00
127 lines
3.8 KiB
Plaintext
127 lines
3.8 KiB
Plaintext
<rml>
|
|
<head>
|
|
<title>Options</title>
|
|
<link type="text/template" href="window.rml" />
|
|
<style>
|
|
body
|
|
{
|
|
width: 350dp;
|
|
height: 350dp;
|
|
|
|
margin: auto;
|
|
}
|
|
|
|
div#title_bar div#icon
|
|
{
|
|
decorator: image( icon-game );
|
|
display: none;
|
|
}
|
|
|
|
form div
|
|
{
|
|
width: 200dp;
|
|
margin: auto;
|
|
}
|
|
</style>
|
|
<script>
|
|
Options = Options or {}
|
|
|
|
if Options.datamodel == nil then
|
|
-- Create a new data model
|
|
Options.datamodel = rmlui.contexts["main"]:OpenDataModel("options", {
|
|
graphics = 'ok',
|
|
options_changed = false,
|
|
audios = {
|
|
{id="reverb", label="Reverb", checked=true},
|
|
{id="3d", label="3D Spatialisation", checked=false},
|
|
}
|
|
})
|
|
end
|
|
|
|
function Options.CloseDataModel()
|
|
rmlui.contexts["main"]:CloseDataModel("options")
|
|
Options.datamodel = nil
|
|
end
|
|
|
|
function Options.Serialize(filename,options)
|
|
local file,message = io.open(filename,'w+') --w+ will erase the previous data
|
|
if file == nil then Log.Message(Log.logtype.error, "Error saving options in options.rml: " .. message) return end
|
|
--cache the function
|
|
local format = string.format
|
|
|
|
for key,value in pairs(options) do
|
|
file:write(tostring(key)..'='..tostring(value)..'\n')
|
|
end
|
|
file:close()
|
|
end
|
|
|
|
function Options.Deserialize(filename)
|
|
local ret = {} --table to return
|
|
--cache functions that are used a lot for faster lookup
|
|
local gmatch = string.gmatch
|
|
|
|
local f = io.open(filename)
|
|
if f then
|
|
for line in f:lines() do
|
|
for k,v in gmatch(line, '(%w+)=(%w+)') do ret[k] = v end
|
|
end
|
|
f:close()
|
|
else
|
|
return nil
|
|
end
|
|
|
|
return ret
|
|
end
|
|
|
|
function Options.LoadOptions(document)
|
|
local options = Options.Deserialize('options.dat')
|
|
if options == nil then return end --short circuit if the file doesn't exist
|
|
|
|
--because everything is loaded as a string, we have to fool around with the boolean variables
|
|
Options.datamodel.audios[1].checked = (options['reverb'] == 'true')
|
|
Options.datamodel.audios[2].checked = (options['3d'] == 'true')
|
|
|
|
Options.datamodel.graphics = options['graphics']
|
|
Options.datamodel.options_changed = false
|
|
end
|
|
|
|
function Options.SaveOptions(event)
|
|
if event.parameters['button'] ~= 'Accept' then
|
|
return
|
|
end
|
|
|
|
local options = {}
|
|
local params = event.parameters
|
|
options['graphics'] = params['graphics']
|
|
--because of how checkboxes won't be in the event params if they aren't checked,
|
|
--we return false if they don't exist. This is Lua's ternary operator.
|
|
options['reverb'] = params['reverb'] and true or false
|
|
options['3d'] = params['3d'] and true or false
|
|
|
|
Options.Serialize('options.dat',options)
|
|
end
|
|
</script>
|
|
</head>
|
|
<body template="luawindow" onload="Window.OnWindowLoad(document) Options.LoadOptions(document)" onkeydown="if Window.EscapePressed(event) then Options.CloseDataModel() Window.LoadMenu('main_menu',document) end">
|
|
<form data-model="options" onsubmit="Options.SaveOptions(event) Options.CloseDataModel() Window.LoadMenu('main_menu',document)" data-event-change="options_changed = true">
|
|
<div>
|
|
<p>
|
|
Graphics<br />
|
|
<label><input id="good" type="radio" name="graphics" value="good" data-checked="graphics" /> Good</label><br />
|
|
<label><input id="ok" type="radio" name="graphics" value="ok" data-checked="graphics" /> OK</label><br />
|
|
<label><input id="bad" type="radio" name="graphics" value="bad" data-checked="graphics" /> Bad</label><br />
|
|
</p>
|
|
<p data-if="graphics == 'bad'">Are you sure about this? Bad graphics are just plain <em>bad.</em></p>
|
|
<p>
|
|
Audio<br />
|
|
<span data-for="audio : audios">
|
|
<label><input data-attr-id="audio.id" type="checkbox" data-attr-name="audio.id" data-checked="audio.checked" /> {{audio.label}}</label><br />
|
|
</span>
|
|
</p>
|
|
</div>
|
|
<input type="submit" name="button" value="Accept" data-attrif-disabled="!options_changed"/>
|
|
<input type="submit" name="button" value="Cancel"/>
|
|
</form>
|
|
</body>
|
|
</rml>
|