Compare commits

..

1 commit

Author SHA1 Message Date
Kazhnuz
67358a424a chore: rename objects to classes 2022-07-27 22:06:01 +02:00
4 changed files with 104 additions and 101 deletions

View file

@ -1,8 +0,0 @@
local consts = {}
consts.OPTION_MENU = "optionMenu"
consts.BORDERS_W = 96
consts.BORDERS_H = 24
consts.NBR_ELEMS = 8
return consts

View file

@ -24,12 +24,10 @@
local Scene = require "birb.modules.scenes"
local OptionsMenu = Scene:extend()
local ListBox = require "birb.modules.menusystem.menus.listbox"
local Widgets = require "scenes.menus.options.widgets"
local Menu = require "scenes.menus.options.menu"
local consts = require "scenes.menus.options.consts"
function OptionsMenu:start()
function OptionsMenu:new()
OptionsMenu.super.new(self)
self.assets:addImageFont("medium", "assets/fonts/medium")
self.assets:setMusic("assets/music/options.ogg")
@ -40,31 +38,26 @@ function OptionsMenu:start()
self.assets:playMusic()
self.menu = Menu("medium");
self:addMenu("main", true)
self:addSubMenu("video", "video")
Widgets.Resolution(self, "video")
Widgets.Switch("fullscreen")
Widgets.Switch("borders")
Widgets.Switch("vsync")
self:addSubMenu("audio", "audio")
Widgets.Audio("sfx")
Widgets.Audio("music")
self:addSubMenu("langs", "langs")
self:setLanguageMenu()
self:addSubMenu("inputs", "inputs")
Widgets.Resolution(self, "video")
Widgets.Switch(self, "video", "fullscreen")
Widgets.Switch(self, "video", "borders")
Widgets.Switch(self, "video", "vsync")
self:addPlayerMenus()
local menu = self.menusystem.menus[consts.OPTION_MENU]
menu:switch("main")
self:setLanguageMenu()
Widgets.Audio(self, "audio", "sfx")
Widgets.Audio(self, "audio", "music")
Widgets.Exit(self, "main")
self.menusystem:switchMenu(consts.OPTION_MENU)
self.menusystem:switchMenu("main")
self.menusystem:setSoundFromSceneAssets("navigate")
@ -76,19 +69,29 @@ end
-- Functions that serve the handling of menus
function OptionsMenu:addMenu(name, nobackbutton)
Menu("medium")
local screenHeight, screenWidth = core.screen:getDimensions()
local w, h = 424/2, 240 - 48
local x, y = w / 2, 24
ListBox(self.menusystem, name, x, y, w, h, 8)
end
function OptionsMenu:addSubMenu(name, fullname)
local menu = self.menusystem.menus[consts.OPTION_MENU]
menu:addSubmenu(name, core.lang:translate("options", fullname), "main")
self:addMenu(name)
Widgets.SubMenu(self, "main", name, fullname)
Widgets.SubMenu(self, name, "main", "back", 1, "<")
end
function OptionsMenu:addPlayerMenus()
for key, _ in pairs(core.input.data[1].keys) do
-- FIXME: make sure that you can use the order you want for the keys list
-- instead of a random one
Widgets.Key(key)
for i,v in ipairs(core.input.data) do
local menu = "player" .. i
self:addMenu(menu)
Widgets.PlayerSubMenu(self, "inputs", i)
for k,w in pairs(v.keys) do
-- FIXME: make sure that you can use the order you want for the keys list
-- instead of a random one
Widgets.Key(self, i, k)
end
Widgets.SubMenu(self, menu, "inputs", "back", 1, "<")
end
end
@ -97,8 +100,8 @@ function OptionsMenu:addScene(submenu, scene, fullname)
end
function OptionsMenu:setLanguageMenu()
for i,lang in ipairs(core.lang.data.available) do
Widgets.Lang(lang)
for i,v in ipairs(core.lang.data.available) do
Widgets.Lang(self, "langs", v)
end
end
@ -118,7 +121,6 @@ end
function OptionsMenu:draw()
love.graphics.setColor(.3, .1, .4, 1)
love.graphics.rectangle("fill", 0, 0, 424, 240)
utils.graphics.resetColor()
end
return OptionsMenu

View file

@ -1,14 +0,0 @@
local TextMenu = require "birb.modules.menusystem.textmenu"
local OptionMenu = TextMenu:extend()
local consts = require "examples.scenes.menus.options.consts"
function OptionMenu:new(font)
local screenWidth, _ = core.screen:getDimensions()
local w = screenWidth - (consts.BORDERS_W*2)
local x = consts.BORDERS_W
local y = consts.BORDERS_H
OptionMenu.super.new(self, consts.OPTION_MENU, font, x, y, w, consts.NBR_ELEMS, 8)
end
return OptionMenu

View file

@ -23,15 +23,15 @@
local widgets = {}
local Widget = require "birb.modules.menusystem.textmenu.widgets.basic"
local DoubleTextWidget = Widget:extend()
local Widget = require "birb.modules.menusystem.menus.widgets"
local DoubleTextWidget = Widget.Text:extend()
widgets.SubMenu = DoubleTextWidget:extend()
widgets.Dummy = Widget:extend()
widgets.Exit = Widget:extend()
widgets.Dummy = Widget.Text:extend()
widgets.Exit = Widget.Text:extend()
widgets.Switch = DoubleTextWidget:extend()
widgets.Resolution = DoubleTextWidget:extend()
widgets.Lang = Widget:extend()
widgets.Lang = Widget.Text:extend()
widgets.PlayerSubMenu = DoubleTextWidget:extend()
widgets.Key = DoubleTextWidget:extend()
widgets.Audio = DoubleTextWidget:extend()
@ -41,33 +41,44 @@ widgets.Audio = DoubleTextWidget:extend()
-- DoubleText widget : a two-side text widget
function DoubleTextWidget:new(label1, label2)
DoubleTextWidget.super.new(self, "optionMenu", label1, "left")
local label2 = label2 or ""
self:addLabel(label2, "right")
function DoubleTextWidget:new(menu, font, label1, label2)
DoubleTextWidget.super.new(self, menu, font, label1)
self.label2 = label2 or ""
end
function DoubleTextWidget:drawCanvas()
local w, h
w = math.floor(self.width)
h = math.floor(self.height / 2) - (self.font:getHeight() / 2)
self.font:draw(self.label, 4, h, -1, "left")
self.font:draw(self.label2, w-4, h, -1, "right")
end
-- Submenu widget :: go to a submenu
function widgets.SubMenu:new(scene, newmenu, fullname, order, label2)
function widgets.SubMenu:new(scene, menu, newmenu, fullname, order, label2)
self.scene = scene
local widgetmenu = self.scene.menusystem.menus[menu]
local font = self.scene.assets.fonts["medium"]
local label = core.lang:translate("options", fullname)
local label2 = label2 or ">"
self.newmenu = newmenu
widgets.SubMenu.super.new(self, label, label2)
widgets.SubMenu.super.new(self, widgetmenu, font, label, label2)
self.order = order or 0
end
function widgets.SubMenu:action()
self.scene.assets:playSFX("confirm")
self.menu:switch(self.newmenu)
self.scene.menusystem:switchMenu(self.newmenu)
end
-- Dummy widget :: An empty widget to serve as a base for others
function widgets.Dummy:new(scene, menu, fullname)
self.scene = scene
widgets.Dummy.super.new(self, menu, fullname)
local widgetmenu = self.scene.menusystem.menus[menu]
local font = self.scene.assets.fonts["medium"]
widgets.Dummy.super.new(self, widgetmenu, font, fullname)
end
function widgets.Dummy:action()
@ -78,12 +89,14 @@ end
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, "optionMenu", label, "left")
widgets.Exit.super.new(self, widgetmenu, font, "Exit")
end
function widgets.Exit:action()
self.assets:playSFX("confirm")
self.scene.assets:playSFX("confirm")
core.scenemanager:setStoredScene("mainmenu")
end
@ -92,11 +105,14 @@ end
-- Switch widget (One widget to handle graphical switch)
function widgets.Switch:new(keyname)
function widgets.Switch:new(scene, menu, keyname)
self.scene = scene
local widgetmenu = self.scene.menusystem.menus[menu]
local font = self.scene.assets.fonts["medium"]
self.keyname = keyname
local label = core.lang:translate("options", keyname)
local label2 = self:getLabel()
widgets.Switch.super.new(self, label, label2)
widgets.Switch.super.new(self, widgetmenu, font, label, label2)
self.order = 0
end
@ -136,19 +152,21 @@ end
function widgets.Switch:action()
self:modifyKey()
local scene = core.scenemanager.currentScene
scene.assets:playSFX("confirm")
self:replaceLabel(2, self:getLabel())
self.scene.assets:playSFX("confirm")
self.label2 = self:getLabel()
core.options:write()
self:invalidateCanvas()
end
-- Resolution Widget
function widgets.Resolution:new()
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, label, label2)
widgets.Resolution.super.new(self, widgetmenu, font, label, label2)
end
function widgets.Resolution:getLabel()
@ -161,10 +179,9 @@ function widgets.Resolution:action()
else
core.options.data.video.resolution = core.options.data.video.resolution + 1
end
self:replaceLabel(2, self:getLabel())
self.label2 = self:getLabel()
core.screen:applySettings()
local scene = core.scenemanager.currentScene
scene.assets:playSFX("confirm")
self.scene.assets:playSFX("confirm")
self:invalidateCanvas()
core.options:write()
end
@ -172,15 +189,17 @@ end
-- LANGS WIDGET
-- Allow you to change the lang of the game
function widgets.Lang:new(lang)
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, "optionMenu", label, "left")
widgets.Lang.super.new(self, widgetmenu, font, label)
end
function widgets.Lang:action()
local scene = core.scenemanager.currentScene
scene.assets:playSFX("confirm")
self.scene.assets:playSFX("confirm")
core.options:setLanguage(self.lang)
--self.scene.menusystem:invalidateAllWidgets()
end
@ -190,31 +209,35 @@ end
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, label, label2)
widgets.PlayerSubMenu.super.new(self, widgetmenu, font, label, label2)
self.order = 0
end
function widgets.PlayerSubMenu:action()
local scene = core.scenemanager.currentScene
scene.assets:playSFX("confirm")
scene.menusystem:switchMenu(self.newmenu)
self.scene.assets:playSFX("confirm")
self.scene.menusystem:switchMenu(self.newmenu)
end
-- Key widgets
function widgets.Key:new(key)
self.source = 1
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, label, label2)
widgets.Key.super.new(self, widgetmenu, font, label, label2)
self.order = 0
end
@ -223,27 +246,28 @@ function widgets.Key:getLabel()
end
function widgets.Key:action()
local scene = core.scenemanager.currentScene
scene.assets:playSFX("navigate")
scene:changeKey(self)
scene.menusystem:deactivate()
self.scene.assets:playSFX("navigate")
self.scene:changeKey(self)
self.scene.menusystem:deactivate()
end
function widgets.Key:receiveKey( key )
local scene = core.scenemanager.currentScene
scene.assets:playSFX("confirm")
self.scene.assets:playSFX("confirm")
core.options:setInputKey(self.source, self.key, key)
self:replaceLabel(2, self:getLabel())
self.label2 = self:getLabel()
self:invalidateCanvas()
end
-- AUDIO FUNCTIONS
-- Sounds/Music functions
function widgets.Audio:new(audiotype)
function widgets.Audio:new(scene, menu, audiotype)
self.scene = scene
self.audiotype = audiotype
local widgetmenu = self.scene.menusystem.menus[menu]
local font = self.scene.assets.fonts["medium"]
self.audiotype = audiotype
local label = ""
if (self.audiotype == "sfx") then
@ -253,7 +277,7 @@ function widgets.Audio:new(audiotype)
end
local label2 = self:getLabel()
widgets.Audio.super.new(self, label, label2)
widgets.Audio.super.new(self, widgetmenu, font, label, label2)
self.order = 0
end
@ -282,16 +306,15 @@ function widgets.Audio:setVolume(vol)
core.options.data.audio.music = vol
end
self:replaceLabel(2, self:getLabel())
self.label2 = self:getLabel()
self:invalidateCanvas()
end
function widgets.Audio:action()
local value = self:getVolume()
self:setVolume(value - 20)
local scene = core.scenemanager.currentScene
scene.assets:playSFX("confirm")
core.music:applyVolume()
self.scene.assets:playSFX("confirm")
self.scene.assets.music:setVolume(core.options.data.audio.music / 100)
core.options:write()
end