From a95c562a7f4ffcb3b45834be20156be93ee666b2 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 12 Mar 2021 22:17:33 +0100 Subject: [PATCH] chore: extract character menu and widgets --- .../screens/mainmenu/common/charmenu.lua | 12 ++++ .../screens/mainmenu/common/charwidget.lua | 53 ++++++++++++++++ .../overworld/screens/mainmenu/pause.lua | 62 ++----------------- 3 files changed, 69 insertions(+), 58 deletions(-) create mode 100644 sonic-radiance.love/scenes/overworld/screens/mainmenu/common/charmenu.lua create mode 100644 sonic-radiance.love/scenes/overworld/screens/mainmenu/common/charwidget.lua diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/common/charmenu.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/common/charmenu.lua new file mode 100644 index 0000000..97a35b3 --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/screens/mainmenu/common/charmenu.lua @@ -0,0 +1,12 @@ +local baseMenu = require "game.modules.menus.parents.menu" +local CharacterMenu = baseMenu:extend() + +local const = require "scenes.overworld.screens.mainmenu.const" + +function CharacterMenu:new(scene) + local x = const.X + 136 + local w = const.WIDTH - x + 28 + CharacterMenu.super.new(self, scene, "character", x, const.Y, w, const.HEIGHT, 4) +end + +return CharacterMenu diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/common/charwidget.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/common/charwidget.lua new file mode 100644 index 0000000..b1e6ea4 --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/screens/mainmenu/common/charwidget.lua @@ -0,0 +1,53 @@ +local baseWidget = require "game.modules.menus.parents.widget" +local CharacterWidget = baseWidget:extend() + +local ComplexHPBar = require "game.modules.gui.complexhpbar" +local Emblem = require "game.modules.gui.emblem" + +-- Hero custom widget +-- +function CharacterWidget:new(scene, name) + self.charName = name + self.emblem = Emblem(game.characters.list[name], scene) + self.font2 = scene.assets.fonts["hudnbrs_small"] + CharacterWidget.super.new(self, scene, "character") + + self.hpbar = ComplexHPBar(88) + self.ppbar = ComplexHPBar(88) + self.hpbar:setColorForeground(248 / 255, 160 / 255, 0, 1) + self.hpbar:setColorBackground(112 / 255, 0, 0) + self.ppbar:setColorForeground(0, 248 / 255, 248 / 255, 1) + self.ppbar:setColorBackground(0, 54 / 255, 229 / 255) +end + +function CharacterWidget:drawCanvas() + local character = game.characters.list[self.charName] + self.font:setFilter("shadow") + local debut = 0 + local xDebut = 32 + self.font:draw(character.fullname, xDebut, debut, -1, "left") + local yLvl = debut + 16 + local xLvl = xDebut + self.scene.assets.images["lvl"]:draw(xLvl, yLvl) + self.scene.assets.images["exp"]:draw(xLvl, yLvl + 10) + self.font2:print(character.level, xLvl + 19, yLvl, "left") + local expString = character.exp .. "/" .. character.exp_next + self.font2:print(expString, xLvl + 19, yLvl + 10, "left") +end + +function CharacterWidget:draw(x, y) + local character = game.characters.list[self.charName] + self.emblem:draw(x, y + 6) + + local xDebut = x + 52 + local yDebut = y + 15 + self.scene.assets.fonts["hudnbrs_small"]:set() + self.hpbar:drawWithLabels(xDebut + 53, yDebut, character.hp, character.stats.hpmax) + self.ppbar:drawWithLabels(xDebut + 64, yDebut + 11, character.pp, character.stats.ppmax) + + if self.canvas.texture ~= nil then + love.graphics.draw(self.canvas.texture, x - self.ox, y - self.oy) + end +end + +return CharacterWidget diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/pause.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/pause.lua index 87234d4..6c2ad53 100644 --- a/sonic-radiance.love/scenes/overworld/screens/mainmenu/pause.lua +++ b/sonic-radiance.love/scenes/overworld/screens/mainmenu/pause.lua @@ -1,16 +1,12 @@ local ParentScreen = require "scenes.overworld.screens.parent" local PauseScreen = ParentScreen:extend() -local ComplexHPBar = require "game.modules.gui.complexhpbar" - -local Emblem = require "game.modules.gui.emblem" - local menu = require "game.modules.menus.fancy" -local baseMenu = require "game.modules.menus.parents.menu" -local baseWidget = require "game.modules.menus.parents.widget" -local CharacterMenu = baseMenu:extend() -local CharacterWidget = baseWidget:extend() +local baseCharacterMenu = require "scenes.overworld.screens.mainmenu.common.charmenu" +local baseCharacterWidget = require "scenes.overworld.screens.mainmenu.common.charwidget" +local CharacterMenu = baseCharacterMenu:extend() +local CharacterWidget = baseCharacterWidget:extend() local TeamWidget = menu.BaseWidget:extend() local ViewWidget = menu.BaseWidget:extend() @@ -61,62 +57,12 @@ function PauseScreen:draw() end -- Character menu -function CharacterMenu:new(scene) - local x = const.X + 136 - local w = const.WIDTH - x + 28 - CharacterMenu.super.new(self, scene, "character", x, const.Y, w, const.HEIGHT, 4) -end - function CharacterMenu:cancelAction() self.scene.menusystem:switchMenu("main") end -- Hero custom widget -- -function CharacterWidget:new(scene, name) - self.charName = name - self.emblem = Emblem(game.characters.list[name], scene) - self.font2 = scene.assets.fonts["hudnbrs_small"] - CharacterWidget.super.new(self, scene, "character") - - self.hpbar = ComplexHPBar(88) - self.ppbar = ComplexHPBar(88) - self.hpbar:setColorForeground(248/255, 160/255, 0, 1) - self.hpbar:setColorBackground(112/255, 0, 0) - self.ppbar:setColorForeground(0, 248/255, 248/255, 1) - self.ppbar:setColorBackground(0, 54/255, 229/255) -end - -function CharacterWidget:drawCanvas() - local character = game.characters.list[self.charName] - self.font:setFilter("shadow") - local debut = 0 - local xDebut = 32 - self.font:draw(character.fullname, xDebut, debut, -1, "left") - local yLvl = debut + 16 - local xLvl = xDebut - self.scene.assets.images["lvl"]:draw(xLvl, yLvl) - self.scene.assets.images["exp"]:draw(xLvl, yLvl + 10) - self.font2:print(character.level, xLvl + 19, yLvl, "left") - local expString = character.exp .. "/" .. character.exp_next - self.font2:print(expString, xLvl + 19, yLvl + 10, "left") -end - -function CharacterWidget:draw(x, y) - local character = game.characters.list[self.charName] - self.emblem:draw(x, y+6) - - local xDebut = x + 52 - local yDebut = y + 15 - self.scene.assets.fonts["hudnbrs_small"]:set() - self.hpbar:drawWithLabels(xDebut + 53, yDebut, character.hp, character.stats.hpmax) - self.ppbar:drawWithLabels(xDebut + 64, yDebut + 11, character.pp, character.stats.ppmax) - - if self.canvas.texture ~= nil then - love.graphics.draw(self.canvas.texture, x - self.ox, y - self.oy) - end -end - function CharacterWidget:action() self.scene.screens.mainmenu.character(self.scene, self.charName) end