examples/options : list players as submenus

This commit is contained in:
Kazhnuz 2019-04-15 17:04:44 +02:00
parent f37eaef79a
commit a25259e6b9
2 changed files with 29 additions and 0 deletions

View file

@ -42,6 +42,8 @@ function OptionsMenu:new()
Widgets.Switch(self, "video", "borders") Widgets.Switch(self, "video", "borders")
Widgets.Switch(self, "video", "vsync") Widgets.Switch(self, "video", "vsync")
self:addPlayerMenus()
self:setLanguageMenu() self:setLanguageMenu()
Widgets.Exit(self, "main") Widgets.Exit(self, "main")
@ -64,6 +66,15 @@ function OptionsMenu:addSubMenu(name, fullname)
Widgets.SubMenu(self, name, "main", "back", 1, "<") Widgets.SubMenu(self, name, "main", "back", 1, "<")
end end
function OptionsMenu:addPlayerMenus()
for i,v in ipairs(core.input.data) do
local menu = "player" .. i
self:addMenu(menu)
Widgets.PlayerSubMenu(self, "inputs", i)
Widgets.SubMenu(self, menu, "inputs", "back", 1, "<")
end
end
function OptionsMenu:addScene(submenu, scene, fullname) function OptionsMenu:addScene(submenu, scene, fullname)
Widgets.Dummy(self, submenu, fullname) Widgets.Dummy(self, submenu, fullname)
end end

View file

@ -32,6 +32,7 @@ widgets.Exit = Widget.Text:extend()
widgets.Switch = DoubleTextWidget:extend() widgets.Switch = DoubleTextWidget:extend()
widgets.Resolution = DoubleTextWidget:extend() widgets.Resolution = DoubleTextWidget:extend()
widgets.Lang = Widget.Text:extend() widgets.Lang = Widget.Text:extend()
widgets.PlayerSubMenu = DoubleTextWidget:extend()
-- BASIC WIDGETS -- BASIC WIDGETS
-- Simple and reusables widgets -- Simple and reusables widgets
@ -196,4 +197,21 @@ function widgets.Lang:action()
--self.scene.menusystem:invalidateAllWidgets() --self.scene.menusystem:invalidateAllWidgets()
end end
-- INPUT WIDGETS
function widgets.PlayerSubMenu:new(scene, menu, sourceid)
self.scene = scene
local widgetmenu = self.scene.menusystem.menus[menu]
local font = self.scene.assets.fonts["medium"]
local label = core.lang:translate("options", "player") .. " " .. sourceid
local label2 = ">"
self.newmenu = "player" .. sourceid
widgets.PlayerSubMenu.super.new(self, widgetmenu, font, label, label2)
self.order = 0
end
function widgets.PlayerSubMenu:action()
self.scene.menusystem:switchMenu(self.newmenu)
end
return widgets return widgets