implement options
This commit is contained in:
parent
b913381d2f
commit
69ae043001
6
TODO
6
TODO
|
@ -1,17 +1,15 @@
|
||||||
modules managment interface
|
modules managment interface
|
||||||
clean sprites cache periodically
|
clean sprites cache periodically
|
||||||
load modules from zip packages
|
load modules from zip packages
|
||||||
ip/host/rsa configuration
|
|
||||||
review directories search
|
review directories search
|
||||||
left panel with dragging windows
|
left panel with dragging windows
|
||||||
console history
|
console history
|
||||||
console text selection
|
console text selection
|
||||||
console scrolling
|
console scrolling
|
||||||
padding
|
padding
|
||||||
remember password/account
|
|
||||||
scrollbar
|
scrollbar
|
||||||
make otui syntax more like css
|
make otui syntax more like css
|
||||||
a real working border and background property in otui
|
a real working border and background property in otui
|
||||||
setIcon() for buttons
|
|
||||||
load state styles in order
|
load state styles in order
|
||||||
grid layout
|
grid layout
|
||||||
|
fix moving windows and tooltips conflicts
|
|
@ -2,11 +2,62 @@ Options = {}
|
||||||
|
|
||||||
-- private variables
|
-- private variables
|
||||||
local options
|
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
|
-- public functions
|
||||||
function Options.create()
|
function Options.create()
|
||||||
options = UI.loadAndDisplay("/options/options.otui")
|
options = UI.loadAndDisplayLocked("/options/options.otui")
|
||||||
UI.root:lockChild(options)
|
|
||||||
|
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
|
end
|
||||||
|
|
||||||
function Options.destroy()
|
function Options.destroy()
|
||||||
|
@ -16,4 +67,6 @@ end
|
||||||
|
|
||||||
function Options.openWebpage()
|
function Options.openWebpage()
|
||||||
displayErrorBox("Error", "Not implemented yet")
|
displayErrorBox("Error", "Not implemented yet")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
addEvent(Options.load)
|
|
@ -1,111 +1,29 @@
|
||||||
MainWindow
|
MainWindow
|
||||||
id: optionsWindow
|
id: optionsWindow
|
||||||
title: Options
|
title: Options
|
||||||
size: 286 262
|
size: 286 100
|
||||||
|
|
||||||
// general
|
CheckBox
|
||||||
Button
|
id: vsyncCheckBox
|
||||||
text: General
|
text: Enable vertical synchronization
|
||||||
anchors.left: parent.left
|
tooltip: Limits FPS to 60
|
||||||
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
|
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.bottom: parent.bottom
|
anchors.top: parent.top
|
||||||
margin.bottom: 97
|
margin.top: 28
|
||||||
margin.left: 18
|
margin.left: 18
|
||||||
margin.right: 18
|
margin.right: 18
|
||||||
|
|
||||||
// motd
|
CheckBox
|
||||||
Button
|
id: fpsCheckBox
|
||||||
text: Motd
|
text: Show frame rate
|
||||||
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
|
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.bottom: parent.bottom
|
anchors.top: prev.bottom
|
||||||
margin.bottom: 40
|
margin.top: 10
|
||||||
margin.left: 13
|
margin.left: 18
|
||||||
margin.right: 13
|
margin.right: 18
|
||||||
|
|
||||||
// ok button
|
|
||||||
Button
|
Button
|
||||||
text: Ok
|
text: Ok
|
||||||
width: 64
|
width: 64
|
||||||
|
|
|
@ -64,6 +64,7 @@ TopPanel
|
||||||
@onClick: About.create()
|
@onClick: About.create()
|
||||||
|
|
||||||
FrameCounter
|
FrameCounter
|
||||||
|
id: frameCounter
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
anchors.right: prev.left
|
anchors.right: prev.left
|
||||||
margin.top: 8
|
margin.top: 8
|
||||||
|
|
|
@ -31,6 +31,7 @@ public:
|
||||||
bool load(const std::string& file);
|
bool load(const std::string& file);
|
||||||
bool save();
|
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; }
|
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]; }
|
std::string get(const std::string& key) { return m_confsMap[key]; }
|
||||||
|
|
||||||
|
|
|
@ -154,6 +154,7 @@ void LuaInterface::registerFunctions()
|
||||||
g_lua.registerClass<Configs>();
|
g_lua.registerClass<Configs>();
|
||||||
g_lua.bindClassStaticFunction<Configs>("set", std::bind(&Configs::set, &g_configs, _1, _2));
|
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>("get", std::bind(&Configs::get, &g_configs, _1));
|
||||||
|
g_lua.bindClassStaticFunction<Configs>("exists", std::bind(&Configs::exists, &g_configs, _1));
|
||||||
|
|
||||||
// Logger
|
// Logger
|
||||||
g_lua.registerClass<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("addEvent", std::bind(&EventDispatcher::addEvent, &g_dispatcher, _1, false));
|
||||||
g_lua.bindGlobalFunction("scheduleEvent", std::bind(&EventDispatcher::scheduleEvent, &g_dispatcher, _1, _2));
|
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("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));
|
g_lua.bindGlobalFunction("getScreenSize", std::bind(&Graphics::getScreenSize, &g_graphics));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue