Rebase on Radiance #71

Merged
kazhnuz merged 20 commits from wip/radiance-rebase into master 2022-08-12 10:37:35 +02:00
4 changed files with 102 additions and 105 deletions
Showing only changes of commit f347f47aab - Show all commits

View file

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

View file

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

View file

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