exemples/options : add resolution widget

This commit is contained in:
Kazhnuz 2019-04-13 14:34:35 +02:00
parent a370cefcd7
commit fee42e308a
2 changed files with 29 additions and 0 deletions

View file

@ -37,6 +37,7 @@ function OptionsMenu:new()
self:addSubMenu("lang", "lang")
self:addSubMenu("input", "input")
Widgets.Resolution(self, "video")
Widgets.Switch(self, "video", "fullscreen")
Widgets.Switch(self, "video", "borders")
Widgets.Switch(self, "video", "vsync")

View file

@ -30,6 +30,7 @@ widgets.SubMenu = DoubleTextWidget:extend()
widgets.Dummy = Widget.Text:extend()
widgets.Exit = Widget.Text:extend()
widgets.Switch = DoubleTextWidget:extend()
widgets.Resolution = DoubleTextWidget:extend()
-- BASIC WIDGETS
-- Simple and reusables widgets
@ -144,5 +145,32 @@ function widgets.Switch:action()
self:invalidateCanvas()
end
-- Resolution Widget
function widgets.Resolution:new(scene, menu)
self.scene = scene
local widgetmenu = self.scene.menusystem.menus[menu]
local font = self.scene.assets.fonts["medium"]
local keyname = "resolution"
local label2 = self:getLabel()
widgets.Resolution.super.new(self, widgetmenu, font, keyname, label2)
end
function widgets.Resolution:getLabel()
return "x" .. core.options.data.video.resolution
end
function widgets.Resolution:action()
if core.options.data.video.resolution == 3 then
core.options.data.video.resolution = 1
else
core.options.data.video.resolution = core.options.data.video.resolution + 1
end
self.label2 = self:getLabel()
core.screen:applySettings()
self:invalidateCanvas()
core.options:write()
end
return widgets