mirror of
https://github.com/edubart/otclient.git
synced 2025-11-30 07:26:49 +01:00
reorganize modules
This commit is contained in:
72
modules/client_options/options.lua
Normal file
72
modules/client_options/options.lua
Normal file
@@ -0,0 +1,72 @@
|
||||
Options = {}
|
||||
|
||||
-- private variables
|
||||
local options
|
||||
local fpsEnabled = false
|
||||
local vsyncEnabled = false
|
||||
|
||||
function getConfig(name, default)
|
||||
if g_configs.exists(name) then
|
||||
local val = string.trim(g_configs.get(name))
|
||||
if val == 'true' or val == 'false' then
|
||||
return toboolean(val)
|
||||
else
|
||||
return val
|
||||
end
|
||||
else
|
||||
if default ~= nil then
|
||||
g_configs.set(name, default)
|
||||
return default
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function setConfig(name, value)
|
||||
g_configs.set(name, tostring(value))
|
||||
end
|
||||
|
||||
-- private functions
|
||||
function Options.enableVsync(on)
|
||||
vsyncEnabled = on
|
||||
g_window.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.display('options.otui', { locked = true })
|
||||
|
||||
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()
|
||||
options:destroy()
|
||||
options = nil
|
||||
end
|
||||
|
||||
function Options.openWebpage()
|
||||
displayErrorBox("Error", "Not implemented yet")
|
||||
end
|
||||
|
||||
addEvent(Options.load)
|
||||
10
modules/client_options/options.otmod
Normal file
10
modules/client_options/options.otmod
Normal file
@@ -0,0 +1,10 @@
|
||||
Module
|
||||
name: client_options
|
||||
description: Create the options window
|
||||
author: OTClient team
|
||||
website: https://github.com/edubart/otclient
|
||||
|
||||
onLoad: |
|
||||
require 'options'
|
||||
return true
|
||||
|
||||
34
modules/client_options/options.otui
Normal file
34
modules/client_options/options.otui
Normal file
@@ -0,0 +1,34 @@
|
||||
MainWindow
|
||||
id: optionsWindow
|
||||
title: Options
|
||||
size: 286 100
|
||||
|
||||
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-right: 18
|
||||
|
||||
CheckBox
|
||||
id: fpsCheckBox
|
||||
text: Show frame rate
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.top: prev.bottom
|
||||
margin-top: 10
|
||||
margin-left: 18
|
||||
margin-right: 18
|
||||
|
||||
Button
|
||||
text: Ok
|
||||
width: 64
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
margin-right: 10
|
||||
margin-bottom: 10
|
||||
@onClick: Options.destroy()
|
||||
Reference in New Issue
Block a user