examples/options: add basic switches widgets
This commit is contained in:
parent
0686b70b6a
commit
defe5fea9a
2 changed files with 59 additions and 0 deletions
|
@ -37,6 +37,10 @@ function OptionsMenu:new()
|
|||
self:addSubMenu("lang", "lang")
|
||||
self:addSubMenu("input", "input")
|
||||
|
||||
Widgets.Switch(self, "video", "fullscreen")
|
||||
Widgets.Switch(self, "video", "borders")
|
||||
Widgets.Switch(self, "video", "vsync")
|
||||
|
||||
Widgets.Exit(self, "main")
|
||||
self.menusystem:switchMenu("main")
|
||||
end
|
||||
|
|
|
@ -29,6 +29,7 @@ local DoubleTextWidget = Widget.Text:extend()
|
|||
widgets.SubMenu = DoubleTextWidget:extend()
|
||||
widgets.Dummy = Widget.Text:extend()
|
||||
widgets.Exit = Widget.Text:extend()
|
||||
widgets.Switch = DoubleTextWidget:extend()
|
||||
|
||||
-- BASIC WIDGETS
|
||||
-- Simple and reusables widgets
|
||||
|
@ -90,4 +91,58 @@ function widgets.Exit:action()
|
|||
core.scenemanager:setStoredScene("mainmenu")
|
||||
end
|
||||
|
||||
-- VIDEO WIDGETS
|
||||
-- Handle graphical settings
|
||||
|
||||
-- Switch widget (One widget to handle graphical switch)
|
||||
|
||||
function widgets.Switch:new(scene, menu, keyname)
|
||||
self.scene = scene
|
||||
local widgetmenu = self.scene.menusystem.menus[menu]
|
||||
local font = self.scene.assets.fonts["medium"]
|
||||
self.keyname = keyname
|
||||
local label2 = self:getLabel()
|
||||
widgets.Switch.super.new(self, widgetmenu, font, keyname, label2)
|
||||
self.order = order or 0
|
||||
end
|
||||
|
||||
function widgets.Switch:modifyKey()
|
||||
--self.key = (self.key == false)
|
||||
if self.keyname == "fullscreen" then
|
||||
core.options.data.video.fullscreen = (core.options.data.video.fullscreen == false)
|
||||
elseif self.keyname == "borders" then
|
||||
core.options.data.video.border = (core.options.data.video.border == false)
|
||||
elseif self.keyname == "vsync" then
|
||||
core.options.data.video.vsync = (core.options.data.video.vsync == false)
|
||||
end
|
||||
core.screen:applySettings()
|
||||
end
|
||||
|
||||
function widgets.Switch:getKey()
|
||||
if self.keyname == "fullscreen" then
|
||||
self.key = core.options.data.video.fullscreen
|
||||
elseif self.keyname == "borders" then
|
||||
self.key = (core.options.data.video.border)
|
||||
elseif self.keyname == "vsync" then
|
||||
self.key = (core.options.data.video.vsync)
|
||||
end
|
||||
end
|
||||
|
||||
function widgets.Switch:getLabel()
|
||||
self:getKey()
|
||||
if (self.key) then
|
||||
return "true"
|
||||
else
|
||||
return "false"
|
||||
end
|
||||
end
|
||||
|
||||
function widgets.Switch:action()
|
||||
self:modifyKey()
|
||||
self.label2 = self:getLabel()
|
||||
self.needRedraw = true
|
||||
core.options:write()
|
||||
end
|
||||
|
||||
|
||||
return widgets
|
||||
|
|
Loading…
Reference in a new issue