examples/options: support language changing

This commit is contained in:
Kazhnuz 2019-04-14 18:11:44 +02:00
parent a470f53f8f
commit 853a55cda4
2 changed files with 25 additions and 0 deletions

View file

@ -42,6 +42,8 @@ function OptionsMenu:new()
Widgets.Switch(self, "video", "borders")
Widgets.Switch(self, "video", "vsync")
self:setLanguageMenu()
Widgets.Exit(self, "main")
self.menusystem:switchMenu("main")
end
@ -66,6 +68,12 @@ function OptionsMenu:addScene(submenu, scene, fullname)
Widgets.Dummy(self, submenu, fullname)
end
function OptionsMenu:setLanguageMenu()
for i,v in ipairs(core.lang.data.available) do
Widgets.Lang(self, "langs", v)
end
end
function OptionsMenu:draw()
love.graphics.setColor(.3, .1, .4, 1)
love.graphics.rectangle("fill", 0, 0, 424, 240)

View file

@ -31,6 +31,7 @@ widgets.Dummy = Widget.Text:extend()
widgets.Exit = Widget.Text:extend()
widgets.Switch = DoubleTextWidget:extend()
widgets.Resolution = DoubleTextWidget:extend()
widgets.Lang = Widget.Text:extend()
-- BASIC WIDGETS
-- Simple and reusables widgets
@ -178,5 +179,21 @@ function widgets.Resolution:action()
core.options:write()
end
-- LANGS WIDGET
-- Allow you to change the lang of the game
function widgets.Lang:new(scene, menu, lang)
self.scene = scene
local widgetmenu = self.scene.menusystem.menus[menu]
local font = self.scene.assets.fonts["medium"]
local label = core.lang:getLangName(lang)
self.lang = lang
widgets.Lang.super.new(self, widgetmenu, font, label)
end
function widgets.Lang:action()
core.options:setLanguage(self.lang)
--self.scene.menusystem:invalidateAllWidgets()
end
return widgets