mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 11:34:54 +02:00
implement options
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user