From 853a55cda407f377a929a425281882cc3e89561a Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 14 Apr 2019 18:11:44 +0200 Subject: [PATCH] examples/options: support language changing --- examples/menus/options/init.lua | 8 ++++++++ examples/menus/options/widgets.lua | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/examples/menus/options/init.lua b/examples/menus/options/init.lua index 68aca6d..97d73ec 100644 --- a/examples/menus/options/init.lua +++ b/examples/menus/options/init.lua @@ -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) diff --git a/examples/menus/options/widgets.lua b/examples/menus/options/widgets.lua index 7046bc8..eb148d7 100644 --- a/examples/menus/options/widgets.lua +++ b/examples/menus/options/widgets.lua @@ -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