From cf5da3177ddae3b245e428a63f54273024188efe Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 29 Aug 2020 17:26:38 +0200 Subject: [PATCH] feat: add the page system for the character view Fix #59 --- .../screens/mainmenu/character/basicpage.lua | 75 +++++++++++++++++++ .../{character.lua => character/init.lua} | 62 ++++++++------- .../overworld/screens/mainmenu/const.lua | 1 + 3 files changed, 110 insertions(+), 28 deletions(-) create mode 100644 sonic-radiance.love/scenes/overworld/screens/mainmenu/character/basicpage.lua rename sonic-radiance.love/scenes/overworld/screens/mainmenu/{character.lua => character/init.lua} (50%) diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/basicpage.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/basicpage.lua new file mode 100644 index 0000000..fa476f6 --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/basicpage.lua @@ -0,0 +1,75 @@ +local BasicPage = Object:extend() + +local menu = require "game.modules.menus.fancy" +local gui = require "game.modules.gui" +local const = require "scenes.overworld.screens.mainmenu.const" + +function BasicPage:new(view, character) + self.view = view + self.character = game.characters.list[character] + + self.statBox = gui.newTextBox("assets/gui/dialogbox.png", const.CHARPAGESIZE, 48+8) + self.nameBox = gui.newTextBox("assets/gui/dialogbox.png", const.CHARPAGESIZE, 40) +end + +function BasicPage:getMenuWidgets() + +end + +function BasicPage:update(dt) + +end + +function BasicPage:draw() + self:drawIdentity(const.X, const.Y) + self:drawLevel(const.X, 100) + self:drawStats(const.X, 160) + --self:drawWeakStrong(const.X, 160) +end + +function BasicPage:drawIdentity(x, y) + local identityString = self.character.fullname .. "\n" + identityString = identityString .. "Class: " .. self.character.data.class + + love.graphics.draw(self.nameBox, x, y) + self.view.scene.assets.fonts["small"]:draw(identityString, x + 6, y + 4, -1, "left") +end + +function BasicPage:drawLevel(x, y) + local levelString = "Level: " .. self.character.level .. "\n" + local levelString = levelString .. "Current exp: " .. self.character.exp .. "\n" + local levelString = levelString .. "Next level: " .. self.character.exp_next + + love.graphics.draw(self.statBox, x, y) + self.view.scene.assets.fonts["small"]:draw(levelString, x + 6, y + 4, -1, "left") +end + +function BasicPage:drawStats(x, y) + local statString = "ATK " .. self.character.stats.attack .. "0" .. "\n" + statString = statString .. "DEF " .. self.character.stats.defense .. "0" .. "\n" + + local statString2 = "POW " .. self.character.stats.power .. "0" .. "\n" + statString2 = statString2 .. "MND " .. self.character.stats.mind .. "0" .. "\n" + + local statString3 = "SPD " .. self.character.stats.speed .. "0" .. "\n" + statString3 = statString3 .. "TEK " .. self.character.stats.technic .. "0" + + local pos1 = const.CHARPAGESIZE * (1/3) + local pos2 = const.CHARPAGESIZE * (2/3) + + love.graphics.draw(self.nameBox, x, y) + + self.view.scene.assets.fonts["small"]:draw(statString, x + 6, y + 4, -1, "left") + self.view.scene.assets.fonts["small"]:draw(statString2, x + 6 + pos1, y + 4, -1, "left") + self.view.scene.assets.fonts["small"]:draw(statString3, x + 6 + pos2, y + 4, -1, "left") +end + +function BasicPage:drawWeakStrong(x, y) + local weakString = "Weak to: Earth, Lightning" + local strongString = "Resist To: Fire" + + love.graphics.draw(self.nameBox, x, y) + self.view.scene.assets.fonts["small"]:draw(weakString .. "\n" .. strongString, x + 6, y + 4, -1, "left") +end + +return BasicPage diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/character.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/init.lua similarity index 50% rename from sonic-radiance.love/scenes/overworld/screens/mainmenu/character.lua rename to sonic-radiance.love/scenes/overworld/screens/mainmenu/character/init.lua index ef97682..546677c 100644 --- a/sonic-radiance.love/scenes/overworld/screens/mainmenu/character.lua +++ b/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/init.lua @@ -5,24 +5,53 @@ local menu = require "game.modules.menus.fancy" local gui = require "game.modules.gui" local const = require "scenes.overworld.screens.mainmenu.const" +local BasicPage = require "scenes.overworld.screens.mainmenu.character.basicpage" +local pageList = {BasicPage} + local ReturnWidget = menu.BaseWidget:extend() function CharacterScreen:new(scene, character) self.character = game.characters.list[character] self.charName = character - self.statBox = gui.newTextBox("assets/gui/dialogbox.png", 176, 48+8) - self.nameBox = gui.newTextBox("assets/gui/dialogbox.png", 176, 40) + self.page = BasicPage(self, character) + self.pageIndex = 1 self.artwork = love.graphics.newImage("datas/gamedata/characters/" .. character .. "/artwork.png") self.artworkOrigin = require("datas.gamedata.characters." .. character .. ".artwork") CharacterScreen.super.new(self, scene, self.character.name) end +function CharacterScreen:update(dt) + local keys = self.scene:getKeys(1) + if (keys["left"].isPressed) then + self:setPage(self.pageIndex - 1) + end + if (keys["right"].isPressed) then + self:setPage(self.pageIndex + 1) + end +end + +function CharacterScreen:setPage(newPageIndex) + local newPageIndex = newPageIndex or 1 + if (newPageIndex > #pageList) then + newPageIndex = 1 + end + if (newPageIndex < 1) then + newPageIndex = #pageList + end + + self.pageIndex = newPageIndex + self.page = pageList[self.pageIndex](self, self.charName) + self.scene.menusystem:reset() + self:setMenu() +end + function CharacterScreen:setMenu() local itemNumber = 1 local y = const.Y2 - (16*itemNumber) + 2 menu.FancyMenu(self.scene, "menu", const.X2 - 128 - 14, y, 128, 1, false) + self.page:getMenuWidgets() --menu.BaseWidget(self.scene, "equip", "Change talent", ">") --menu.BaseWidget(self.scene, "equip", "Battle skills", ">") --menu.BaseWidget(self.scene, "equip", "Equipement", ">") @@ -34,33 +63,10 @@ function CharacterScreen:setMenu() end function CharacterScreen:draw() - love.graphics.draw(self.nameBox, const.X, const.Y) - love.graphics.draw(self.statBox, const.X, 100) - love.graphics.draw(self.nameBox, const.X, 160) self.scene.assets.fonts["small"]:setLineHeight(16/18) - local identityString = self.character.fullname .. "\n" - identityString = identityString .. "Class: " .. self.character.data.class - self.scene.assets.fonts["small"]:draw(identityString, const.X + 6, const.Y +4, -1, "left") - - local levelString = "Level: " .. self.character.level .. "\n" - local levelString = levelString .. "Current exp: " .. self.character.exp .. "\n" - local levelString = levelString .. "Next level: " .. self.character.exp_next - - self.scene.assets.fonts["small"]:draw(levelString, const.X + 6, 104, -1, "left") - - local statString = "ATK " .. self.character.stats.attack .. "0" .. "\n" - statString = statString .. "DEF " .. self.character.stats.defense .. "0" .. "\n" - statString2 = "POW " .. self.character.stats.power .. "0" .. "\n" - statString2 = statString2 .. "MND " .. self.character.stats.mind .. "0" .. "\n" - statString3 = "SPD " .. self.character.stats.speed .. "0" .. "\n" - statString3 = statString3 .. "TEK " .. self.character.stats.technic .. "0" - - local separatorString = ">" .. "\n" .. ">" .. "\n" .. ">" .. "\n" .. ">" .. "\n" .. ">" .. "\n" .. ">" - self.scene.assets.fonts["small"]:draw(statString, const.X + 6, 164, -1, "left") - self.scene.assets.fonts["small"]:draw(statString2, const.X + 6 + (176/3), 164, -1, "left") - self.scene.assets.fonts["small"]:draw(statString3, const.X + 6 + ((176*2)/3), 164, -1, "left") - --self.scene.assets.fonts["small"]:draw(separatorString, 88, 120, -1, "left") - --self.scene.assets.fonts["small"]:draw("Weak to: Earth, Lightning \nResist To: Fire", 24+76, 181, -1, "left") + if (self.page ~= nil) then + self.page:draw() + end end function CharacterScreen:drawBackground() diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/const.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/const.lua index cbfad36..59dc89c 100644 --- a/sonic-radiance.love/scenes/overworld/screens/mainmenu/const.lua +++ b/sonic-radiance.love/scenes/overworld/screens/mainmenu/const.lua @@ -6,5 +6,6 @@ ConstMenu.WIDTH = 424 - 56 ConstMenu.HEIGHT = 240 - 80 ConstMenu.X2 = 424 - 28 ConstMenu.Y2 = 240 - 40 +ConstMenu.CHARPAGESIZE = 176 return ConstMenu