From d38d149e365e77d23c3f00da213479f7913b870f Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 4 Oct 2020 09:26:49 +0200 Subject: [PATCH] feat: add hp/pp bar everywhere * Add a ComplexHPBar widget * Use it on the CBS * Add it on the character page * Add it on the character widget Fix #46 --- sonic-radiance.love/assets/gui/hpbar_back.png | Bin 0 -> 674 bytes sonic-radiance.love/assets/gui/hpbar_fore.png | Bin 0 -> 666 bytes .../game/modules/gui/complexhpbar.lua | 85 ++++++++++++++++++ .../game/modules/gui/statusbar.lua | 21 +++-- .../screens/mainmenu/character/basicpage.lua | 19 ++++ .../overworld/screens/mainmenu/pause.lua | 19 +++- 6 files changed, 130 insertions(+), 14 deletions(-) create mode 100644 sonic-radiance.love/assets/gui/hpbar_back.png create mode 100644 sonic-radiance.love/assets/gui/hpbar_fore.png create mode 100644 sonic-radiance.love/game/modules/gui/complexhpbar.lua diff --git a/sonic-radiance.love/assets/gui/hpbar_back.png b/sonic-radiance.love/assets/gui/hpbar_back.png new file mode 100644 index 0000000000000000000000000000000000000000..3d35718bc0dcbdd66f021dabdd1ef0dc25c43907 GIT binary patch literal 674 zcmV;T0$u%yP)EX>4Tx04R}tkv&MmKpe$iTcxG6IM_kOAwzYtAS&XhRVYG*P%E_RU~=gfG-*gu zTpR`0f`cE6RRx%k-{RDAVPqQIx48bLV{L}6cZWRPkQ)=9KT2|nOqex zax9<*6_Voz|AXJ%n#IWpHz|??dS7h&V+0890jVfq16NwdUuyz0pQJZB zTKov;+XgPKJDR))Tbr*WBLP`#607veZ@j1~@nb zMoW~v?(yzWcW?imY4`U7{e^OPy0|u500006VoOIv0RI600RN!9r;`8x010qNS#tmY zE+YT{E+YYWr9XB6000McNlirueSad^gZEa<4bO1wgWnpw> zWFU8GbZ8()Nlj2!fese{004SPL_t(Y$L*G}4S+BV1pg4rF@$$u6WAexJ`G3+2?(vt zS8iPV>8wQhBT3>IZ09TpUERj(LTfD*5!(QodW|@nalnX(L}H-%3y7*Pcu=Yo3|{W5 z1dPRg22laVVhhmF^ZY~v$`#wzy7!ykPUC7u=6?ovWdT*n1`VZ1qW^St`~Uy|07*qo IM6N<$g3i(xr2qf` literal 0 HcmV?d00001 diff --git a/sonic-radiance.love/assets/gui/hpbar_fore.png b/sonic-radiance.love/assets/gui/hpbar_fore.png new file mode 100644 index 0000000000000000000000000000000000000000..461dae47b648db94db5545165b66e624ffbaa0e8 GIT binary patch literal 666 zcmV;L0%iS)P)EX>4Tx04R}tkv&MmKpe$iTcxG6IM_kOAwzYtAS&XhRVYG*P%E_RU~=gfG-*gu zTpR`0f`cE6RRx%k-{RDAVPqQIx48bLV{L}6cZWRPkQ)=9KT2|nOqex zax9<*6_Voz|AXJ%n#IWpHz|??dS7h&V+0890jVfq16NwdUuyz0pQJZB zTKov;+XgPKJDR))Tbr*WBLP`#607veZ@j1~@nb zMoW~v?(yzWcW?imY4`U7{e^OPy0|u500006VoOIv0RI600RN!9r;`8x010qNS#tmY zE+YT{E+YYWr9XB6000McNlirueSad^gZEa<4bO1wgWnpw> zWFU8GbZ8()Nlj2!fese{0044HL_t(Y$K}?s4S+BVMA7@>u}wB%6d*XQ9Vwl! z@RKDQNmlO1PLb`L9)N7Kqh;FyQbCNKj-ScknahjO78tze>S6GmtA)WjR|De=EDHB^ zlIoA1T8D}5*wm9Di55LJD%=^&O80^pBlG!r0fy~^Ip(|JtpET307*qoM6N<$f}*w> A+W-In literal 0 HcmV?d00001 diff --git a/sonic-radiance.love/game/modules/gui/complexhpbar.lua b/sonic-radiance.love/game/modules/gui/complexhpbar.lua new file mode 100644 index 0000000..a5378ae --- /dev/null +++ b/sonic-radiance.love/game/modules/gui/complexhpbar.lua @@ -0,0 +1,85 @@ +local ComplexHPBar = Object:extend() + +local gui = require "game.modules.gui" + +local VALUE_MARGIN = 11 +local HEIGHT = 7 + +function ComplexHPBar:new(width) + self.width = width + self:setColorForeground(1, 1, 1) + self:setColorBackground(0, 0, 0) + self.background = self:createBack( "assets/gui/hpbar_back.png" ) + self.foreground = self:createBack( "assets/gui/hpbar_fore.png" ) +end + +function ComplexHPBar:setColorForeground(r, g, b) + self.barcolor = {} + self.barcolor.r = r + self.barcolor.g = g + self.barcolor.b = b +end + +function ComplexHPBar:setColorBackground(r, g, b) + self.backcolor = {} + self.backcolor.r = r + self.backcolor.g = g + self.backcolor.b = b +end + +function ComplexHPBar:createBack( filepath ) + local image = love.graphics.newImage( filepath ) + local imageWidth, imageHeight = image:getDimensions() + local middleImageWidth = imageWidth - VALUE_MARGIN*2 + + local totalWidth = self.width + 8 -- On récupère la taille à partir de la base + local middleWidth = totalWidth - VALUE_MARGIN*2 + + local iteration = math.ceil((middleWidth) / (middleImageWidth)) + local tilequad = {} + tilequad[1] = love.graphics.newQuad(0, 0, VALUE_MARGIN, imageHeight, imageWidth, imageHeight) + tilequad[2] = love.graphics.newQuad(VALUE_MARGIN, 0, middleImageWidth, imageHeight, imageWidth, imageHeight) + tilequad[3] = love.graphics.newQuad(imageWidth - VALUE_MARGIN, 0, VALUE_MARGIN, imageHeight, imageWidth, imageHeight) + + local canvas1 = love.graphics.newCanvas(middleWidth, imageHeight) + love.graphics.setCanvas( canvas1 ) + local combinedWidth = 0 + for i = 1, iteration do + love.graphics.draw(image, tilequad[2], combinedWidth, 0) + combinedWidth = combinedWidth + middleImageWidth + end + + local canvas2 = love.graphics.newCanvas(totalWidth, imageHeight) + love.graphics.setCanvas( canvas2 ) + love.graphics.draw(image, tilequad[1], 0, 0) + love.graphics.draw(canvas1, VALUE_MARGIN, 0) + love.graphics.draw(image, tilequad[3], totalWidth - 11, 0) + love.graphics.setCanvas( ) + + local imagedata = canvas2:newImageData() + local texture = love.graphics.newImage( imagedata ) + imagedata:release() + canvas2:release() + + return texture +end + +function ComplexHPBar:draw(x, y, percent) + utils.graphics.resetColor() + love.graphics.draw(self.foreground, x, y) + love.graphics.setColor(self.backcolor.r, self.backcolor.g, self.backcolor.b, 1) + love.graphics.draw(self.background, x, y) + utils.graphics.resetColor() + + love.graphics.setColor(self.barcolor.r, self.barcolor.g, self.barcolor.b, 1) + gui.drawBar(x + 4, y + 2, math.floor((self.width) * percent), HEIGHT) + utils.graphics.resetColor() +end + +function ComplexHPBar:drawWithLabels(x, y, value, valuemax) + local percent = value / valuemax + self:draw(x, y, percent) + love.graphics.print(math.floor(value) .. "/" .. valuemax, x+10, y+2) +end + +return ComplexHPBar diff --git a/sonic-radiance.love/game/modules/gui/statusbar.lua b/sonic-radiance.love/game/modules/gui/statusbar.lua index f1b8a77..922df74 100644 --- a/sonic-radiance.love/game/modules/gui/statusbar.lua +++ b/sonic-radiance.love/game/modules/gui/statusbar.lua @@ -4,6 +4,7 @@ local TweenManager = require "game.modules.tweenmanager" local gui = require "game.modules.gui" local Emblem = require "game.modules.gui.emblem" +local ComplexHPBar = require "game.modules.gui.complexhpbar" function StatusBar:new(abstract, scene) self.assets = scene.assets @@ -15,6 +16,13 @@ function StatusBar:new(abstract, scene) self.pp = self.abstract.pp self.stats = self.abstract:getStats() + self.hpbar = ComplexHPBar(58) + self.ppbar = ComplexHPBar(58) + 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) + self.tweens = TweenManager(self) end @@ -42,18 +50,9 @@ self.assets.images["statusbar"]:draw(x, y) local hpmax = self.stats.hpmax local ppmax = self.stats.ppmax -local bar1 = math.floor((self.hp/self.stats.hpmax)*58) -local bar2 = math.floor((self.pp/self.stats.ppmax)*58) - -love.graphics.setColor(248/255, 160/255, 0, 1) -gui.drawBar(x+10, y+11, bar1, 7) -love.graphics.setColor(0, 248/255, 248/255, 1) -gui.drawBar(x+22, y+23, bar2, 7) -utils.graphics.resetColor() - self.assets.fonts["hudnbrs_small"]:set() -love.graphics.print(math.floor(self.hp) .. "/" .. hpmax, x+16, y+11) -love.graphics.print(math.floor(self.pp) .. "/" .. ppmax, x+32, y+23) +self.hpbar:drawWithLabels(x + 6, y + 9, self.hp, hpmax) +self.ppbar:drawWithLabels(x + 18, y + 21, self.pp, ppmax) local lvl = self.abstract.level diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/basicpage.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/basicpage.lua index fa476f6..35239e0 100644 --- a/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/basicpage.lua +++ b/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/basicpage.lua @@ -4,12 +4,23 @@ local menu = require "game.modules.menus.fancy" local gui = require "game.modules.gui" local const = require "scenes.overworld.screens.mainmenu.const" +local ComplexHPBar = require "game.modules.gui.complexhpbar" + +local HPBAR_SIZE = 80 + 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) + + self.hpbar = ComplexHPBar(HPBAR_SIZE) + self.ppbar = ComplexHPBar(HPBAR_SIZE) + 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 BasicPage:getMenuWidgets() @@ -22,6 +33,7 @@ end function BasicPage:draw() self:drawIdentity(const.X, const.Y) + self:drawHPPP(const.X, const.Y + 48) self:drawLevel(const.X, 100) self:drawStats(const.X, 160) --self:drawWeakStrong(const.X, 160) @@ -35,6 +47,13 @@ function BasicPage:drawIdentity(x, y) self.view.scene.assets.fonts["small"]:draw(identityString, x + 6, y + 4, -1, "left") end +function BasicPage:drawHPPP(x, y) + self.view.scene.assets.fonts["hudnbrs_small"]:set() + self.hpbar:drawWithLabels(x, y - 4, self.character.hp, self.character.stats.hpmax) + local xx = x + const.CHARPAGESIZE - HPBAR_SIZE - 7 + self.ppbar:drawWithLabels(xx, y - 4, self.character.pp, self.character.stats.ppmax) +end + function BasicPage:drawLevel(x, y) local levelString = "Level: " .. self.character.level .. "\n" local levelString = levelString .. "Current exp: " .. self.character.exp .. "\n" diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/pause.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/pause.lua index b0bc6c1..93f2ec9 100644 --- a/sonic-radiance.love/scenes/overworld/screens/mainmenu/pause.lua +++ b/sonic-radiance.love/scenes/overworld/screens/mainmenu/pause.lua @@ -1,8 +1,7 @@ local ParentScreen = require "scenes.overworld.screens.parent" local PauseScreen = ParentScreen:extend() -local ListBox = require "core.modules.menusystem.listbox" -local Widget = require "core.modules.menusystem.widgets" +local ComplexHPBar = require "game.modules.gui.complexhpbar" local Emblem = require "game.modules.gui.emblem" @@ -78,6 +77,13 @@ function CharacterWidget:new(scene, 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() @@ -93,11 +99,18 @@ function CharacterWidget:drawCanvas() 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") - --text, x, y, limit, align 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