improvement: port the options to the new system
This commit is contained in:
parent
78fca02441
commit
cb626bfa4a
5 changed files with 47 additions and 117 deletions
|
@ -54,7 +54,7 @@ function list.ListMenu:finalize()
|
|||
end
|
||||
|
||||
function list.ListMenu:clone(name)
|
||||
return list.ListMenu(self.scene, name, self.x, self.y, self.w, self.itemNumber)
|
||||
return list.ListMenu(self.scene, name, self.x, self.y, self.w, self.itemNumber, self.isBoxed)
|
||||
end
|
||||
|
||||
function list.ListMenu:getSubmenuWidget()
|
||||
|
@ -97,7 +97,7 @@ end
|
|||
|
||||
function list.ListMenu:draw()
|
||||
if (self.isBoxed) then
|
||||
|
||||
love.graphics.draw(self.box, self.x - 8, self.y - 8)
|
||||
end
|
||||
self:updateView()
|
||||
local widgety = self.y
|
||||
|
|
|
@ -6,6 +6,9 @@ return {
|
|||
["textures"] = {
|
||||
{"background", "assets/backgrounds/options.png"}
|
||||
},
|
||||
["fonts"] = {
|
||||
{"small", "assets/gui/fonts/PixelOperator.ttf", 16}
|
||||
},
|
||||
["imagefonts"] = {
|
||||
{"medium", "assets/gui/fonts/SA2font"},
|
||||
},
|
||||
|
|
|
@ -11,24 +11,26 @@ function OptionsMenu:new()
|
|||
|
||||
self.assets:batchImport("scenes.menus.options.assets")
|
||||
self:addMenu("main", true)
|
||||
self:addSubMenu("video", "video")
|
||||
self:addSubMenu("audio", "audio")
|
||||
self:addSubMenu("video", "Video")
|
||||
self:addSubMenu("audio", "Audio")
|
||||
--self:addSubMenu("langs", "langs")
|
||||
self:addSubMenu("inputs", "inputs")
|
||||
self:addSubMenu("inputs", "Inputs")
|
||||
|
||||
Widgets.Resolution(self, "video")
|
||||
Widgets.Switch(self, "video", "fullscreen")
|
||||
Widgets.Switch(self, "video", "borders")
|
||||
Widgets.Switch(self, "video", "vsync")
|
||||
Widgets.Switch(self, "video", "fullscreen", "Fullscreen")
|
||||
Widgets.Switch(self, "video", "borders", "Borders")
|
||||
Widgets.Switch(self, "video", "vsync", "Vsync")
|
||||
|
||||
self:addPlayerMenus()
|
||||
|
||||
--self:setLanguageMenu()
|
||||
|
||||
Widgets.Audio(self, "audio", "sfx")
|
||||
Widgets.Audio(self, "audio", "music")
|
||||
Widgets.Audio(self, "audio", "sfx", "SFX")
|
||||
Widgets.Audio(self, "audio", "music", "Music")
|
||||
|
||||
Widgets.Exit(self, "main")
|
||||
|
||||
self.menusystem.menus["main"]:finalize()
|
||||
self.menusystem:switchMenu("main")
|
||||
|
||||
self.menusystem:setSoundFromSceneAssets("mBeep")
|
||||
|
@ -50,26 +52,24 @@ end
|
|||
-- Functions that serve the handling of menus
|
||||
|
||||
function OptionsMenu:addMenu(name, nobackbutton)
|
||||
OptionMenu(self.menusystem, name)
|
||||
OptionMenu(self, name)
|
||||
end
|
||||
|
||||
function OptionsMenu:addSubMenu(name, fullname)
|
||||
self:addMenu(name)
|
||||
Widgets.SubMenu(self, "main", name, fullname)
|
||||
Widgets.SubMenu(self, name, "main", "back", 1, "<")
|
||||
self.menusystem.menus["main"]:addSubMenu(name, fullname)
|
||||
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)
|
||||
|
||||
self.menusystem.menus["inputs"]:addSubMenu("player" .. i, "Player " .. i, "inputs")
|
||||
|
||||
local keyList = require "datas.keys"
|
||||
for j, key in ipairs(keyList) do
|
||||
Widgets.Key(self, i, key)
|
||||
end
|
||||
Widgets.SubMenu(self, menu, "inputs", "back", 1, "<")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function OptionsMenu:addScene(submenu, scene, fullname)
|
||||
|
|
|
@ -1,22 +1,15 @@
|
|||
local ListBox = require "core.modules.menusystem.listbox"
|
||||
local OptionMenu = ListBox:extend()
|
||||
local WIDTH = 424/1.4
|
||||
local HEIGHT = 240/1.9
|
||||
local RadianceListMenu = require "game.modules.menus.list"
|
||||
|
||||
local gui = require "game.modules.gui"
|
||||
local OptionMenu = RadianceListMenu.ListMenu:extend()
|
||||
local WIDTH = 128+32
|
||||
local ITEMNUMBER = 6
|
||||
|
||||
function OptionMenu:new(menusystem, name)
|
||||
local w, h = math.floor(WIDTH), math.floor(HEIGHT)
|
||||
function OptionMenu:new(scene, name)
|
||||
local w, h = math.floor(WIDTH), math.floor(17 * ITEMNUMBER)
|
||||
local screenw, screenh = core.screen:getDimensions()
|
||||
local x = (screenw/2) - (w/2)
|
||||
local y = (screenh/2) - (h/2)
|
||||
OptionMenu.super.new(self, menusystem, name, x, y, w, h, 6)
|
||||
self.box = gui.newTextBox("assets/gui/dialogbox.png", w+16, h+16)
|
||||
end
|
||||
|
||||
function OptionMenu:draw()
|
||||
love.graphics.draw(self.box, self.x-8, self.y-8)
|
||||
OptionMenu.super.draw(self)
|
||||
OptionMenu.super.new(self, scene, name, x, y, w, ITEMNUMBER, true)
|
||||
end
|
||||
|
||||
return OptionMenu
|
||||
|
|
|
@ -1,17 +1,19 @@
|
|||
local widgets = {}
|
||||
|
||||
local Widget = require "core.modules.menusystem.widgets"
|
||||
local RadianceListMenu = require "game.modules.menus.list"
|
||||
|
||||
local DoubleTextWidget = Widget.Text:extend()
|
||||
|
||||
widgets.SubMenu = DoubleTextWidget:extend()
|
||||
widgets.Dummy = Widget.Text:extend()
|
||||
widgets.Exit = Widget.Text:extend()
|
||||
widgets.Switch = DoubleTextWidget:extend()
|
||||
widgets.Resolution = DoubleTextWidget:extend()
|
||||
widgets.Lang = Widget.Text:extend()
|
||||
widgets.PlayerSubMenu = DoubleTextWidget:extend()
|
||||
widgets.Key = DoubleTextWidget:extend()
|
||||
widgets.Audio = DoubleTextWidget:extend()
|
||||
widgets.Dummy = RadianceListMenu.DualTextWidget:extend()
|
||||
widgets.Exit = RadianceListMenu.DualTextWidget:extend()
|
||||
widgets.Switch = RadianceListMenu.DualTextWidget:extend()
|
||||
widgets.Resolution = RadianceListMenu.DualTextWidget:extend()
|
||||
widgets.Lang = RadianceListMenu.DualTextWidget:extend()
|
||||
widgets.PlayerSubMenu = RadianceListMenu.DualTextWidget:extend()
|
||||
widgets.Key = RadianceListMenu.DualTextWidget:extend()
|
||||
widgets.Audio = RadianceListMenu.DualTextWidget:extend()
|
||||
|
||||
-- BASIC WIDGETS
|
||||
-- Simple and reusables widgets
|
||||
|
@ -52,10 +54,7 @@ end
|
|||
-- Dummy widget :: An empty widget to serve as a base for others
|
||||
|
||||
function widgets.Dummy:new(scene, menu, fullname)
|
||||
self.scene = scene
|
||||
local widgetmenu = self.scene.menusystem.menus[menu]
|
||||
local font = self.scene.assets.fonts["medium"]
|
||||
widgets.Dummy.super.new(self, widgetmenu, font, fullname)
|
||||
widgets.Dummy.super.new(self, scene, menu, fullname)
|
||||
end
|
||||
|
||||
function widgets.Dummy:action()
|
||||
|
@ -65,11 +64,7 @@ end
|
|||
-- Exit Widget : exit the examples
|
||||
|
||||
function widgets.Exit:new(scene, menu)
|
||||
self.scene = scene
|
||||
local widgetmenu = self.scene.menusystem.menus[menu]
|
||||
local font = self.scene.assets.fonts["medium"]
|
||||
local label = core.lang:translate("commons", "exit")
|
||||
widgets.Exit.super.new(self, widgetmenu, font, "Exit")
|
||||
widgets.Exit.super.new(self, scene, menu, "Exit", "")
|
||||
end
|
||||
|
||||
function widgets.Exit:action()
|
||||
|
@ -82,14 +77,10 @@ end
|
|||
|
||||
-- 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"]
|
||||
function widgets.Switch:new(scene, menu, keyname, label)
|
||||
self.keyname = keyname
|
||||
local label = core.lang:translate("options", keyname)
|
||||
local label2 = self:getLabel()
|
||||
widgets.Switch.super.new(self, widgetmenu, font, label, label2)
|
||||
widgets.Switch.super.new(self, scene, menu, label, label2)
|
||||
self.order = order or 0
|
||||
end
|
||||
|
||||
|
@ -138,12 +129,9 @@ 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 label = core.lang:translate("options", "resolution")
|
||||
local label2 = self:getLabel()
|
||||
widgets.Resolution.super.new(self, widgetmenu, font, label, label2)
|
||||
widgets.Resolution.super.new(self, scene, menu, label, label2)
|
||||
end
|
||||
|
||||
function widgets.Resolution:getLabel()
|
||||
|
@ -163,58 +151,16 @@ 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()
|
||||
self.scene.assets:playSFX("mSelect")
|
||||
core.options:setLanguage(self.lang)
|
||||
--self.scene.menusystem:invalidateAllWidgets()
|
||||
end
|
||||
|
||||
-- INPUT WIDGETS
|
||||
-- Widgets to handle inputs
|
||||
|
||||
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.assets:playSFX("mSelect")
|
||||
self.scene.menusystem:switchMenu(self.newmenu)
|
||||
end
|
||||
|
||||
-- Key widgets
|
||||
|
||||
function widgets.Key:new(scene, sourceid, key)
|
||||
self.scene = scene
|
||||
self.source = sourceid
|
||||
self.key = key
|
||||
|
||||
local menu = "player" .. self.source
|
||||
|
||||
local widgetmenu = self.scene.menusystem.menus[menu]
|
||||
local font = self.scene.assets.fonts["medium"]
|
||||
local label = self.key
|
||||
local label2 = self:getLabel()
|
||||
|
||||
widgets.Key.super.new(self, widgetmenu, font, label, label2)
|
||||
widgets.Key.super.new(self, scene, menu, label, label2)
|
||||
self.order = 0
|
||||
end
|
||||
|
||||
|
@ -238,23 +184,11 @@ end
|
|||
-- AUDIO FUNCTIONS
|
||||
-- Sounds/Music functions
|
||||
|
||||
function widgets.Audio:new(scene, menu, audiotype)
|
||||
self.scene = scene
|
||||
self.audiotype = key
|
||||
|
||||
|
||||
local widgetmenu = self.scene.menusystem.menus[menu]
|
||||
local font = self.scene.assets.fonts["medium"]
|
||||
function widgets.Audio:new(scene, menu, audiotype, label)
|
||||
self.audiotype = audiotype
|
||||
local label = ""
|
||||
if (self.audiotype == "sfx") then
|
||||
label = core.lang:translate("options", "sfx")
|
||||
else
|
||||
label = core.lang:translate("options", "music")
|
||||
end
|
||||
local label2 = self:getLabel()
|
||||
|
||||
widgets.Audio.super.new(self, widgetmenu, font, label, label2)
|
||||
local label2 = self:getLabel()
|
||||
widgets.Audio.super.new(self, scene, menu, label, label2)
|
||||
self.order = 0
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue