From 83a89dc69b760b86bb88a6bba4766ca2d2b8ebbc Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Tue, 31 Aug 2021 19:12:40 +0200 Subject: [PATCH] feat: initial gui version of radiance's menus --- .../game/modules/gui/boxedmenu.lua | 71 +++++++++++++++++++ .../game/modules/gui/fancymenu.lua | 32 +++++++++ 2 files changed, 103 insertions(+) create mode 100644 sonic-radiance.love/game/modules/gui/boxedmenu.lua create mode 100644 sonic-radiance.love/game/modules/gui/fancymenu.lua diff --git a/sonic-radiance.love/game/modules/gui/boxedmenu.lua b/sonic-radiance.love/game/modules/gui/boxedmenu.lua new file mode 100644 index 0000000..6812251 --- /dev/null +++ b/sonic-radiance.love/game/modules/gui/boxedmenu.lua @@ -0,0 +1,71 @@ +local ParentMenu = require "birb.modules.gui.textmenu" +local BoxedList = ParentMenu:extend() + +local gui = require "game.modules.gui" + +function BoxedList:new(name, x, y, w, slotNumber, isBoxed, smallborder) + BoxedList.super.new(self, name, "small", x, y, w, slotNumber, 0) + self.paddingLeft = 12 + self.paddingRight = 4 + + self.cursorTexture = love.graphics.newImage("assets/gui/cursor-menulist.png") + self.cursorTransition = 0 + + self.isBoxed = isBoxed + if (isBoxed) then + local border = self.h + 16 + if (smallborder == true) then + border = self.h + 8 + end + self.box = gui.newTextBox("assets/gui/dialogbox.png", w + 8, border) + end +end + +function BoxedList:finalize() + self:setCancelWidget() +end + +function BoxedList:update(dt) + BoxedList.super.update(self, dt) + self:updateCursorPosition(dt) +end + +function BoxedList:updateCursorPosition(dt) + local relativecursor = self.widget.selected - self.view.firstSlot + + local transition = self.cursorTransition - relativecursor + if math.abs(transition) < 0.1 then + self.cursorTransition = relativecursor + else + local speed = dt * 45 + local movement = ((relativecursor) - (self.cursorTransition)) + self.cursorTransition = (self.cursorTransition) + movement * speed + end +end + +function BoxedList:drawCursor() + local x, y = self:getCursorPosition() + love.graphics.draw(self.cursorTexture, x, y) +end + +function BoxedList:getCursorPosition() + local addition = self.lineHeight + local x = self.x + 6 + local y = self.y + ((self.cursorTransition) * addition) + 1 + return x, y +end + +function BoxedList:draw() + if (self.isBoxed) then + local dy = 8 + if (self.smallborder) then + dy = 4 + end + local w, h = self.box:getDimensions() + local diff = (w-self.w)/2 + love.graphics.draw(self.box, self.x - self.ox - diff, self.y - self.oy - dy) + end + BoxedList.super.draw(self) +end + +return BoxedList diff --git a/sonic-radiance.love/game/modules/gui/fancymenu.lua b/sonic-radiance.love/game/modules/gui/fancymenu.lua new file mode 100644 index 0000000..61d4c96 --- /dev/null +++ b/sonic-radiance.love/game/modules/gui/fancymenu.lua @@ -0,0 +1,32 @@ +local ParentMenu = require "birb.modules.gui.textmenu" +local FancyMenu = ParentMenu:extend() + +local gui = require "game.modules.gui" + +function FancyMenu:new(name, x, y, w, itemNumber, haveBiseau) + FancyMenu.super.new(self, name, "small", x, y, w, itemNumber) + self.biseau = utils.math.either(haveBiseau, 8, 0) + self.itemNumber = itemNumber + self.box = gui.newChoiceBack(self.w + 24) + self.cursorTexture = love.graphics.newImage("assets/gui/cursor-menulist.png") +end + +function FancyMenu:getDimensions() + local w, h = FancyMenu.super.getDimensions(self) + return w + (self.biseau*self.itemNumber), h +end + +function FancyMenu:getListPart(i) + local x, y, w, h = FancyMenu.super.getListPart(self, i) + return x + (self.biseau*i), y, w, h +end + +function FancyMenu:drawWidgetBackground(x, y, w, h) + love.graphics.draw(self.box, x - 8, y + 2) +end + +function FancyMenu:drawGraphicalCursor(x, y, w, h) + love.graphics.draw(self.cursorTexture, x - 3, y + 1) +end + +return FancyMenu