diff --git a/TODO b/TODO index c3fc4d94..0a5d740b 100644 --- a/TODO +++ b/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 \ No newline at end of file +grid layout +fix moving windows and tooltips conflicts \ No newline at end of file diff --git a/modules/options/options.lua b/modules/options/options.lua index ade5a6fa..035d775f 100644 --- a/modules/options/options.lua +++ b/modules/options/options.lua @@ -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 \ No newline at end of file +end + +addEvent(Options.load) \ No newline at end of file diff --git a/modules/options/options.otui b/modules/options/options.otui index 90cf0187..47aaa87b 100644 --- a/modules/options/options.otui +++ b/modules/options/options.otui @@ -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 + CheckBox + id: vsyncCheckBox + text: Enable vertical synchronization + tooltip: Limits FPS to 60 anchors.left: parent.left + anchors.right: parent.right anchors.top: parent.top + margin.top: 28 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 + margin.right: 18 - HorizontalSeparator + CheckBox + id: fpsCheckBox + text: Show frame rate anchors.left: parent.left anchors.right: parent.right - anchors.bottom: parent.bottom - margin.bottom: 97 + anchors.top: prev.bottom + margin.top: 10 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 - anchors.left: parent.left - anchors.right: parent.right - anchors.bottom: parent.bottom - margin.bottom: 40 - margin.left: 13 - margin.right: 13 - - // ok button Button text: Ok width: 64 diff --git a/modules/topmenu/topmenu.otui b/modules/topmenu/topmenu.otui index 87193739..50d444ab 100644 --- a/modules/topmenu/topmenu.otui +++ b/modules/topmenu/topmenu.otui @@ -64,6 +64,7 @@ TopPanel @onClick: About.create() FrameCounter + id: frameCounter anchors.top: parent.top anchors.right: prev.left margin.top: 8 diff --git a/src/framework/core/configs.h b/src/framework/core/configs.h index 82115250..496b9ece 100644 --- a/src/framework/core/configs.h +++ b/src/framework/core/configs.h @@ -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]; } diff --git a/src/framework/luascript/luafunctions.cpp b/src/framework/luascript/luafunctions.cpp index 026720a8..9eaed458 100644 --- a/src/framework/luascript/luafunctions.cpp +++ b/src/framework/luascript/luafunctions.cpp @@ -154,6 +154,7 @@ void LuaInterface::registerFunctions() g_lua.registerClass(); g_lua.bindClassStaticFunction("set", std::bind(&Configs::set, &g_configs, _1, _2)); g_lua.bindClassStaticFunction("get", std::bind(&Configs::get, &g_configs, _1)); + g_lua.bindClassStaticFunction("exists", std::bind(&Configs::exists, &g_configs, _1)); // Logger g_lua.registerClass(); @@ -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)); }