diff --git a/sonic-radiance.love/scenes/battlesystem/controller/menu.lua b/sonic-radiance.love/scenes/battlesystem/controller/menu.lua index 5cd4d68..b523a1b 100644 --- a/sonic-radiance.love/scenes/battlesystem/controller/menu.lua +++ b/sonic-radiance.love/scenes/battlesystem/controller/menu.lua @@ -1,7 +1,15 @@ +local ListBox = require "core.modules.menusystem.listbox" +local Widget = require "core.modules.menusystem.widgets" + local MenuConstructor = Object:extend() +local CharacterMenu = ListBox:extend() +local CharMenuWidget = Widget.Text:extend() + local BaseMenu = {"attack", "techs", "object", "defend", "flee", "back"} local MENUPOS_X1, MENUPOS_X2, MENUPOS_Y = 32, 32, 110 +local MENU_WIDTH, MENU_ITEM_HEIGHT = 112, 17 +local MENU_ITEM_NUMBER = 6 function MenuConstructor:new( controller ) self.controller = controller @@ -14,11 +22,30 @@ function MenuConstructor:new( controller ) self.texture = love.graphics.newImage("assets/gui/attacklist.png") self.cursorTexture = love.graphics.newImage("assets/gui/cursor-menulist.png") self.font = love.graphics.newFont("assets/gui/fonts/PixelOperator.ttf", 16) + self.controller.assets:addFont("small", "assets/gui/fonts/PixelOperator.ttf", 16) self.cursor = 1 self.cursorTransition = 1 self.view = 1 end +function MenuConstructor:reconstruct(character) + self.controller.menusystem:reset() + self:build(character) + + self.controller.menusystem:switchMenu("BaseMenu") +end + +function MenuConstructor:build(character) + self:buildBaseMenu(character) +end + +function MenuConstructor:buildBaseMenu(character) + CharacterMenu(self.controller, "BaseMenu", MENUPOS_X1 - 16, MENUPOS_Y) + for i,v in ipairs(BaseMenu) do + CharMenuWidget(self.controller, "BaseMenu", "small", v, "", character) + end +end + function MenuConstructor:set(currentCharacter) self.isActive = true self.cursor = 1 @@ -27,6 +54,8 @@ function MenuConstructor:set(currentCharacter) self.character = currentCharacter + --self:reconstruct(currentCharacter) + self.menu[2] = self:getSkillList() self.menu[3] = {"healitems", "rings", "wisps", "other", "back"} @@ -157,4 +186,43 @@ function MenuConstructor:draw() end end +-- CHARACTER_MENU +-- The actuals menus in the character menu + +function CharacterMenu:new(scene, name, x, y) + self.scene = scene + local w, h = MENU_WIDTH, MENU_ITEM_NUMBER * MENU_ITEM_HEIGHT + CharacterMenu.super.new(self, scene.menusystem, name, x, y, w, h, MENU_ITEM_NUMBER) +end + +function CharacterMenu:drawCursor() + CharacterMenu.super.drawCursor(self) + --local addition = 16 + --love.graphics.draw(self.cursorTexture, self.x - 12, self.y + (self.cursorTransition) * addition + 2 ) +end + +-- WIDGETS +-- All widgets used by the Characters menus + +function CharMenuWidget:new(scene, menu_name, font_name, label1, label2, character) + self.character = character + local menu = scene.menusystem.menus[menu_name] or error("menu " ..menu_name .. " doesn't exist") + local font = scene.assets.fonts[font_name] or error("font " ..font_name .. " doesn't exist") + CharMenuWidget.super.new(self, menu, font, label1) + self.label2 = label2 or "" +end + +function CharMenuWidget:drawCanvas() + local h + local asset = love.graphics.newImage("assets/gui/attacklist.png") + love.graphics.draw(asset, 0, (self.height - 13) / 2) + h = math.floor(self.height / 2) - (self.font:getHeight() / 2) + love.graphics.setColor(0, 0, 0, .8) + self.font:print(self.label, 17, h, "left") + self.font:print(self.label2, self.width - 8, h, "right") + utils.graphics.resetColor() + self.font:print(self.label, 16, h, "left") + self.font:print(self.label2, self.width - 9, h, "right") +end + return MenuConstructor