2020-08-01 16:06:08 +02:00
|
|
|
local widgets = {}
|
|
|
|
|
2021-05-05 08:30:32 +02:00
|
|
|
local Widget = require "birb.modules.menusystem.widgets"
|
2020-08-19 23:25:36 +02:00
|
|
|
local RadianceListMenu = require "game.modules.menus.list"
|
|
|
|
|
2020-08-01 16:06:08 +02:00
|
|
|
local DoubleTextWidget = Widget.Text:extend()
|
|
|
|
|
|
|
|
widgets.SubMenu = DoubleTextWidget:extend()
|
2020-08-19 23:25:36 +02:00
|
|
|
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()
|
2021-04-18 16:36:40 +02:00
|
|
|
widgets.Delete = RadianceListMenu.DualTextWidget:extend()
|
2021-04-18 19:09:01 +02:00
|
|
|
widgets.DiffSwitch = RadianceListMenu.DualTextWidget:extend()
|
2020-08-01 16:06:08 +02:00
|
|
|
|
2021-05-05 08:30:32 +02:00
|
|
|
local defTransitions = require "birb.modules.transitions"
|
2021-04-18 16:36:40 +02:00
|
|
|
local ConfirmDialog = require "game.modules.confirmdialog"
|
2021-04-05 14:20:25 +02:00
|
|
|
|
2020-08-01 16:06:08 +02:00
|
|
|
-- BASIC WIDGETS
|
|
|
|
-- Simple and reusables widgets
|
|
|
|
|
|
|
|
-- DoubleText widget : a two-side text widget
|
|
|
|
|
|
|
|
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, 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, widgetmenu, font, label, label2)
|
|
|
|
self.order = order or 0
|
|
|
|
end
|
|
|
|
|
|
|
|
function widgets.SubMenu:action()
|
|
|
|
self.scene.assets:playSFX("mSelect")
|
|
|
|
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)
|
2020-08-19 23:25:36 +02:00
|
|
|
widgets.Dummy.super.new(self, scene, menu, fullname)
|
2020-08-01 16:06:08 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function widgets.Dummy:action()
|
|
|
|
-- shoosh
|
|
|
|
end
|
|
|
|
|
2021-04-18 16:36:40 +02:00
|
|
|
-- Delete Save : delete the current Save
|
|
|
|
|
|
|
|
function widgets.Delete:new(scene, menu)
|
|
|
|
widgets.Exit.super.new(self, scene, menu, "Delete save", "")
|
|
|
|
self.color = {1, 0.3, 0.3}
|
|
|
|
end
|
|
|
|
|
|
|
|
function widgets.Delete:action()
|
|
|
|
self.scene.assets:playSFX("mSelect")
|
|
|
|
|
|
|
|
local confirm = ConfirmDialog(self.scene, "Do you want to delete your save ? \nYou won't be able to recover your data.",
|
|
|
|
function() self:deleteSave() end)
|
|
|
|
confirm:setCancelChoice(2)
|
|
|
|
end
|
|
|
|
|
|
|
|
function widgets.Delete:deleteSave()
|
|
|
|
core.scenemanager:setStoredScene("mainmenu")
|
|
|
|
game:deleteCurrentSave()
|
|
|
|
core.screen:startTransition(defTransitions.default, defTransitions.circle,
|
2021-08-15 16:26:05 +02:00
|
|
|
function() scenes.menus.title(true) end,
|
2021-04-18 16:36:40 +02:00
|
|
|
424/2, 240/2)
|
|
|
|
end
|
|
|
|
|
2020-08-01 16:06:08 +02:00
|
|
|
-- Exit Widget : exit the examples
|
|
|
|
|
|
|
|
function widgets.Exit:new(scene, menu)
|
2020-08-19 23:25:36 +02:00
|
|
|
widgets.Exit.super.new(self, scene, menu, "Exit", "")
|
2020-08-01 16:06:08 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function widgets.Exit:action()
|
|
|
|
self.scene.assets:playSFX("mSelect")
|
|
|
|
core.scenemanager:setStoredScene("mainmenu")
|
2021-04-05 14:20:25 +02:00
|
|
|
core.screen:startTransition(defTransitions.default, defTransitions.default,
|
2021-08-15 16:26:05 +02:00
|
|
|
function() scenes.menus.main() end,
|
2021-04-05 14:20:25 +02:00
|
|
|
0, 0)
|
2020-08-01 16:06:08 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- VIDEO WIDGETS
|
|
|
|
-- Handle graphical settings
|
|
|
|
|
|
|
|
-- Switch widget (One widget to handle graphical switch)
|
|
|
|
|
2020-08-19 23:25:36 +02:00
|
|
|
function widgets.Switch:new(scene, menu, keyname, label)
|
2020-08-01 16:06:08 +02:00
|
|
|
self.keyname = keyname
|
|
|
|
local label2 = self:getLabel()
|
2020-08-19 23:25:36 +02:00
|
|
|
widgets.Switch.super.new(self, scene, menu, label, label2)
|
2020-09-13 16:49:50 +02:00
|
|
|
self.order = 0
|
2020-08-01 16:06:08 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function widgets.Switch:modifyKey()
|
|
|
|
--self.key = (self.key == false)
|
|
|
|
if self.keyname == "fullscreen" then
|
|
|
|
core.options.data.video.fullscreen = (core.options.data.video.fullscreen == false)
|
|
|
|
elseif self.keyname == "borders" then
|
|
|
|
core.options.data.video.border = (core.options.data.video.border == false)
|
|
|
|
elseif self.keyname == "vsync" then
|
|
|
|
core.options.data.video.vsync = (core.options.data.video.vsync == false)
|
|
|
|
end
|
|
|
|
core.screen:applySettings()
|
|
|
|
end
|
|
|
|
|
|
|
|
function widgets.Switch:getKey()
|
|
|
|
if self.keyname == "fullscreen" then
|
|
|
|
self.key = core.options.data.video.fullscreen
|
|
|
|
elseif self.keyname == "borders" then
|
|
|
|
self.key = (core.options.data.video.border)
|
|
|
|
elseif self.keyname == "vsync" then
|
|
|
|
self.key = (core.options.data.video.vsync)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function widgets.Switch:getLabel()
|
|
|
|
self:getKey()
|
|
|
|
local label = ""
|
|
|
|
if (self.key) then
|
|
|
|
label = "true"
|
|
|
|
else
|
|
|
|
label = "false"
|
|
|
|
end
|
|
|
|
|
|
|
|
return core.lang:translate("commons", label)
|
|
|
|
end
|
|
|
|
|
|
|
|
function widgets.Switch:action()
|
|
|
|
self:modifyKey()
|
|
|
|
self.scene.assets:playSFX("mSelect")
|
|
|
|
self.label2 = self:getLabel()
|
|
|
|
core.options:write()
|
|
|
|
self:invalidateCanvas()
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Resolution Widget
|
|
|
|
|
|
|
|
function widgets.Resolution:new(scene, menu)
|
|
|
|
local label = core.lang:translate("options", "resolution")
|
|
|
|
local label2 = self:getLabel()
|
2020-08-19 23:25:36 +02:00
|
|
|
widgets.Resolution.super.new(self, scene, menu, label, label2)
|
2020-08-01 16:06:08 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function widgets.Resolution:getLabel()
|
|
|
|
return "x" .. core.options.data.video.resolution
|
|
|
|
end
|
|
|
|
|
|
|
|
function widgets.Resolution:action()
|
|
|
|
if core.options.data.video.resolution == 3 then
|
|
|
|
core.options.data.video.resolution = 1
|
|
|
|
else
|
|
|
|
core.options.data.video.resolution = core.options.data.video.resolution + 1
|
|
|
|
end
|
|
|
|
self.label2 = self:getLabel()
|
|
|
|
core.screen:applySettings()
|
|
|
|
self.scene.assets:playSFX("mSelect")
|
|
|
|
self:invalidateCanvas()
|
|
|
|
core.options:write()
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Key widgets
|
|
|
|
function widgets.Key:new(scene, sourceid, key)
|
|
|
|
self.source = sourceid
|
|
|
|
self.key = key
|
|
|
|
|
|
|
|
local menu = "player" .. self.source
|
|
|
|
local label = self.key
|
|
|
|
local label2 = self:getLabel()
|
|
|
|
|
2020-08-19 23:25:36 +02:00
|
|
|
widgets.Key.super.new(self, scene, menu, label, label2)
|
2020-08-01 16:06:08 +02:00
|
|
|
self.order = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
function widgets.Key:getLabel()
|
|
|
|
return core.input.data[self.source].keys[self.key]
|
|
|
|
end
|
|
|
|
|
|
|
|
function widgets.Key:action()
|
|
|
|
self.scene.assets:playSFX("navigate")
|
|
|
|
self.scene:changeKey(self)
|
|
|
|
self.scene.menusystem:deactivate()
|
|
|
|
end
|
|
|
|
|
|
|
|
function widgets.Key:receiveKey( key )
|
|
|
|
self.scene.assets:playSFX("mSelect")
|
|
|
|
core.options:setInputKey(self.source, self.key, key)
|
|
|
|
self.label2 = self:getLabel()
|
|
|
|
self:invalidateCanvas()
|
|
|
|
end
|
|
|
|
|
|
|
|
-- AUDIO FUNCTIONS
|
|
|
|
-- Sounds/Music functions
|
|
|
|
|
2020-08-19 23:25:36 +02:00
|
|
|
function widgets.Audio:new(scene, menu, audiotype, label)
|
2020-08-01 16:06:08 +02:00
|
|
|
self.audiotype = audiotype
|
|
|
|
|
2020-08-19 23:25:36 +02:00
|
|
|
local label2 = self:getLabel()
|
|
|
|
widgets.Audio.super.new(self, scene, menu, label, label2)
|
2020-08-01 16:06:08 +02:00
|
|
|
self.order = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
function widgets.Audio:getLabel()
|
|
|
|
local value = self:getVolume()
|
|
|
|
string = utils.math.numberToString(value, 3)
|
|
|
|
local label = string .. "%"
|
|
|
|
|
|
|
|
return label
|
|
|
|
end
|
|
|
|
|
|
|
|
function widgets.Audio:getVolume()
|
|
|
|
if (self.audiotype == "sfx") then
|
|
|
|
return core.options.data.audio.sfx
|
|
|
|
else
|
|
|
|
return core.options.data.audio.music
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function widgets.Audio:setVolume(vol)
|
|
|
|
if (vol < 0) then vol = 100 end
|
|
|
|
|
|
|
|
if (self.audiotype == "sfx") then
|
|
|
|
core.options.data.audio.sfx = vol
|
|
|
|
else
|
|
|
|
core.options.data.audio.music = vol
|
|
|
|
end
|
|
|
|
|
|
|
|
self.label2 = self:getLabel()
|
|
|
|
self:invalidateCanvas()
|
|
|
|
end
|
|
|
|
|
|
|
|
function widgets.Audio:action()
|
|
|
|
local value = self:getVolume()
|
|
|
|
self:setVolume(value - 20)
|
|
|
|
self.scene.assets:playSFX("mSelect")
|
|
|
|
--self.scene.assets.music:setVolume(core.options.data.audio.music / 100)
|
|
|
|
core.options:write()
|
|
|
|
end
|
|
|
|
|
2021-04-18 19:09:01 +02:00
|
|
|
-- Switch widget (One widget to handle graphical switch)
|
|
|
|
|
|
|
|
function widgets.DiffSwitch:new(scene, menu, keyname, label)
|
|
|
|
self.keyname = keyname
|
|
|
|
local label2 = self:getLabel()
|
|
|
|
widgets.Switch.super.new(self, scene, menu, label, label2)
|
|
|
|
self.order = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
function widgets.DiffSwitch:modifyKey()
|
|
|
|
game.difficulty:toggle(self.keyname)
|
|
|
|
end
|
|
|
|
|
|
|
|
function widgets.DiffSwitch:getKey()
|
|
|
|
return game.difficulty:get(self.keyname)
|
|
|
|
end
|
|
|
|
|
|
|
|
function widgets.DiffSwitch:getLabel()
|
|
|
|
self.key = self:getKey()
|
|
|
|
local label = ""
|
|
|
|
if (self.key) then
|
|
|
|
label = "true"
|
|
|
|
else
|
|
|
|
label = "false"
|
|
|
|
end
|
|
|
|
|
|
|
|
return core.lang:translate("commons", label)
|
|
|
|
end
|
|
|
|
|
|
|
|
function widgets.DiffSwitch:action()
|
|
|
|
self:modifyKey()
|
|
|
|
self.scene.assets:playSFX("mSelect")
|
|
|
|
self.label2 = self:getLabel()
|
|
|
|
game:write()
|
|
|
|
self:invalidateCanvas()
|
|
|
|
end
|
|
|
|
|
2020-08-01 16:06:08 +02:00
|
|
|
return widgets
|