implement options
This commit is contained in:
parent
b913381d2f
commit
69ae043001
6
TODO
6
TODO
|
@ -1,17 +1,15 @@
|
|||
modules managment interface
|
||||
clean sprites cache periodically
|
||||
load modules from zip packages
|
||||
ip/host/rsa configuration
|
||||
review directories search
|
||||
left panel with dragging windows
|
||||
console history
|
||||
console text selection
|
||||
console scrolling
|
||||
padding
|
||||
remember password/account
|
||||
scrollbar
|
||||
make otui syntax more like css
|
||||
a real working border and background property in otui
|
||||
setIcon() for buttons
|
||||
load state styles in order
|
||||
grid layout
|
||||
grid layout
|
||||
fix moving windows and tooltips conflicts
|
|
@ -2,11 +2,62 @@ Options = {}
|
|||
|
||||
-- private variables
|
||||
local options
|
||||
local fpsEnabled = false
|
||||
local vsyncEnabled = false
|
||||
|
||||
function getConfig(name, default)
|
||||
if Configs.exists(name) then
|
||||
local val = string.trim(Configs.get(name))
|
||||
if val == 'true' or val == 'false' then
|
||||
return toboolean(val)
|
||||
else
|
||||
return val
|
||||
end
|
||||
else
|
||||
if default ~= nil then
|
||||
Configs.set(name, default)
|
||||
return default
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function setConfig(name, value)
|
||||
Configs.set(name, tostring(value))
|
||||
end
|
||||
|
||||
-- private functions
|
||||
function Options.enableVsync(on)
|
||||
vsyncEnabled = on
|
||||
setVerticalSync(on)
|
||||
setConfig('vsync', on)
|
||||
end
|
||||
|
||||
function Options.enableFps(on)
|
||||
fpsEnabled = on
|
||||
local frameCounter = UI.root:recursiveGetChildById('frameCounter')
|
||||
frameCounter:setVisible(on)
|
||||
setConfig('showfps', on)
|
||||
end
|
||||
|
||||
-- public functions
|
||||
function Options.create()
|
||||
options = UI.loadAndDisplay("/options/options.otui")
|
||||
UI.root:lockChild(options)
|
||||
options = UI.loadAndDisplayLocked("/options/options.otui")
|
||||
|
||||
local fpsBox = options:getChildById('fpsCheckBox')
|
||||
local vsyncBox = options:getChildById('vsyncCheckBox')
|
||||
|
||||
fpsBox:setChecked(fpsEnabled)
|
||||
vsyncBox:setChecked(vsyncEnabled)
|
||||
|
||||
fpsBox.onCheckChange = function(self, checked) Options.enableFps(checked) end
|
||||
vsyncBox.onCheckChange = function(self, checked) Options.enableVsync(checked) end
|
||||
end
|
||||
|
||||
function Options.load()
|
||||
Options.enableVsync(getConfig('vsync', true))
|
||||
Options.enableFps(getConfig('showfps', true))
|
||||
end
|
||||
|
||||
function Options.destroy()
|
||||
|
@ -16,4 +67,6 @@ end
|
|||
|
||||
function Options.openWebpage()
|
||||
displayErrorBox("Error", "Not implemented yet")
|
||||
end
|
||||
end
|
||||
|
||||
addEvent(Options.load)
|
|
@ -1,111 +1,29 @@
|
|||
MainWindow
|
||||
id: optionsWindow
|
||||
title: Options
|
||||
size: 286 262
|
||||
size: 286 100
|
||||
|
||||
// general
|
||||
Button
|
||||
text: General
|
||||
anchors.left: parent.left
|
||||
anchors.top: parent.top
|
||||
margin.left: 18
|
||||
margin.top: 32
|
||||
@onClick: displayErrorBox("Error", "Not implemented yet")
|
||||
|
||||
Label
|
||||
text: |-
|
||||
Change general
|
||||
game options
|
||||
anchors.left: prev.right
|
||||
anchors.top: prev.top
|
||||
margin.left: 10
|
||||
margin.top: -2
|
||||
|
||||
// graphics
|
||||
Button
|
||||
text: Graphics
|
||||
anchors.left: parent.left
|
||||
anchors.top: parent.top
|
||||
margin.left: 18
|
||||
margin.top: 65
|
||||
@onClick: displayErrorBox("Error", "Not implemented yet")
|
||||
|
||||
Label
|
||||
text: |-
|
||||
Change graphics and
|
||||
performance settings
|
||||
anchors.left: prev.right
|
||||
anchors.top: prev.top
|
||||
margin.left: 10
|
||||
margin.top: -2
|
||||
|
||||
// console
|
||||
Button
|
||||
text: Console
|
||||
anchors.left: parent.left
|
||||
anchors.top: parent.top
|
||||
margin.left: 18
|
||||
margin.top: 98
|
||||
@onClick: displayErrorBox("Error", "Not implemented yet")
|
||||
|
||||
Label
|
||||
text: Customise the console
|
||||
anchors.left: prev.right
|
||||
anchors.top: prev.top
|
||||
margin.left: 10
|
||||
margin.top: -2
|
||||
|
||||
// hotkeys
|
||||
Button
|
||||
text: Hotkeys
|
||||
anchors.left: parent.left
|
||||
anchors.top: parent.top
|
||||
margin.left: 18
|
||||
margin.top: 131
|
||||
@onClick: displayErrorBox("Error", "Not implemented yet")
|
||||
|
||||
Label
|
||||
text: Edit your hotkey texts
|
||||
anchors.left: prev.right
|
||||
anchors.top: prev.top
|
||||
margin.left: 10
|
||||
margin.top: -2
|
||||
|
||||
HorizontalSeparator
|
||||
CheckBox
|
||||
id: vsyncCheckBox
|
||||
text: Enable vertical synchronization
|
||||
tooltip: Limits FPS to 60
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
margin.bottom: 97
|
||||
anchors.top: parent.top
|
||||
margin.top: 28
|
||||
margin.left: 18
|
||||
margin.right: 18
|
||||
|
||||
// motd
|
||||
Button
|
||||
text: Motd
|
||||
anchors.left: parent.left
|
||||
anchors.bottom: parent.bottom
|
||||
margin.left: 18
|
||||
margin.bottom: 60
|
||||
@onClick: displayErrorBox("Error", "Not implemented yet")
|
||||
|
||||
Label
|
||||
text: |-
|
||||
Show the most recent
|
||||
Message of the Day
|
||||
anchors.left: prev.right
|
||||
anchors.top: prev.top
|
||||
margin.left: 10
|
||||
margin.top: -2
|
||||
|
||||
HorizontalSeparator
|
||||
CheckBox
|
||||
id: fpsCheckBox
|
||||
text: Show frame rate
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
margin.bottom: 40
|
||||
margin.left: 13
|
||||
margin.right: 13
|
||||
anchors.top: prev.bottom
|
||||
margin.top: 10
|
||||
margin.left: 18
|
||||
margin.right: 18
|
||||
|
||||
// ok button
|
||||
Button
|
||||
text: Ok
|
||||
width: 64
|
||||
|
|
|
@ -64,6 +64,7 @@ TopPanel
|
|||
@onClick: About.create()
|
||||
|
||||
FrameCounter
|
||||
id: frameCounter
|
||||
anchors.top: parent.top
|
||||
anchors.right: prev.left
|
||||
margin.top: 8
|
||||
|
|
|
@ -31,6 +31,7 @@ public:
|
|||
bool load(const std::string& file);
|
||||
bool save();
|
||||
|
||||
bool exists(const std::string& key) { return m_confsMap.find(key) != m_confsMap.end(); }
|
||||
void set(const std::string& key, const std::string& value) { m_confsMap[key] = value; }
|
||||
std::string get(const std::string& key) { return m_confsMap[key]; }
|
||||
|
||||
|
|
|
@ -154,6 +154,7 @@ void LuaInterface::registerFunctions()
|
|||
g_lua.registerClass<Configs>();
|
||||
g_lua.bindClassStaticFunction<Configs>("set", std::bind(&Configs::set, &g_configs, _1, _2));
|
||||
g_lua.bindClassStaticFunction<Configs>("get", std::bind(&Configs::get, &g_configs, _1));
|
||||
g_lua.bindClassStaticFunction<Configs>("exists", std::bind(&Configs::exists, &g_configs, _1));
|
||||
|
||||
// Logger
|
||||
g_lua.registerClass<Logger>();
|
||||
|
@ -170,5 +171,6 @@ void LuaInterface::registerFunctions()
|
|||
g_lua.bindGlobalFunction("addEvent", std::bind(&EventDispatcher::addEvent, &g_dispatcher, _1, false));
|
||||
g_lua.bindGlobalFunction("scheduleEvent", std::bind(&EventDispatcher::scheduleEvent, &g_dispatcher, _1, _2));
|
||||
g_lua.bindGlobalFunction("getMouseCursorPos", std::bind(&Platform::getMouseCursorPos, &g_platform));
|
||||
g_lua.bindGlobalFunction("setVerticalSync", std::bind(&Platform::setVerticalSync, &g_platform, _1));
|
||||
g_lua.bindGlobalFunction("getScreenSize", std::bind(&Graphics::getScreenSize, &g_graphics));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue