From bad24445a7b99b85f28edaceea3ee996b1a86d6b Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 3 Oct 2020 14:33:10 +0200 Subject: [PATCH] feat(items): initial actions menu --- .../overworld/screens/mainmenu/items.lua | 94 +++++++++++++++++-- 1 file changed, 84 insertions(+), 10 deletions(-) diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/items.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/items.lua index fd3f3d0..db817a3 100644 --- a/sonic-radiance.love/scenes/overworld/screens/mainmenu/items.lua +++ b/sonic-radiance.love/scenes/overworld/screens/mainmenu/items.lua @@ -7,6 +7,9 @@ local gui = require "game.modules.gui" local ItemWidget = menu.DualTextWidget:extend() local BackWidget = menu.DualTextWidget:extend() +local ResumeWidget = menu.DualTextWidget:extend() +local DropWidget = menu.DualTextWidget:extend() +local UseWidget = menu.DualTextWidget:extend() local DESC_SIZE = 48*4 @@ -21,12 +24,14 @@ function ItemsScreen:new(scene) end function ItemsScreen:update(dt) - local keys = self.scene:getKeys(1) - if (keys["left"].isPressed) then - self:getMenu(self.menuIndex - 1) - end - if (keys["right"].isPressed) then - self:getMenu(self.menuIndex + 1) + if (self.scene.menusystem.menus["useMenu"] == nil) then + local keys = self.scene:getKeys(1) + if (keys["left"].isPressed) then + self:getMenu(self.menuIndex - 1) + end + if (keys["right"].isPressed) then + self:getMenu(self.menuIndex + 1) + end end end @@ -47,7 +52,7 @@ end function ItemsScreen:setMenu() self.pocket = game.loot:getPocketById(self.menuIndex) local w = 128+32 - menu.ListMenu(self.scene, "menu", const.X2 - w, const.Y + 8, 128+32, 9, true) + menu.ListMenu(self.scene, "menu", const.X2 - w, const.Y + 8, w, 9, true) for i,item in ipairs(self.pocket.list) do --menu.DualTextWidget(self.scene, "menu", item.name, "x" .. item.number) ItemWidget(self.scene, self.pocket.name, item) @@ -55,6 +60,23 @@ function ItemsScreen:setMenu() BackWidget(self.scene) self.scene.menusystem.menus["menu"]:setCancelWidget() self.scene.menusystem:switchMenu("menu") + self.scene.menusystem.menus["menu"].isLocked = true +end + +function ItemsScreen:setUseMenu(item) + local w = 96 + menu.ListMenu(self.scene, "useMenu", const.X2 + 16 - w, const.Y2 - 48, w, 3, true) + UseWidget(self.scene, self.pocket.name, item) + DropWidget(self.scene, self.pocket.name, item) + ResumeWidget(self.scene) + self.scene.menusystem.menus["useMenu"]:setCancelWidget() + self.scene.menusystem:switchMenu("useMenu") + self.scene.menusystem.menus["useMenu"]:setDepth(-1) +end + +function ItemsScreen:removeUseMenu() + self.scene.menusystem.menus["useMenu"]:destroy() + self.scene.menusystem:switchMenu("menu") end function ItemsScreen:draw() @@ -109,12 +131,12 @@ function ItemsScreen:drawPocketRoll(x, y) core.screen:resetScissor() end --- Widgets +-- Items Widgets function ItemWidget:new(scene, pocket, item) self.item = item self.itemData = game.loot:getItemData(pocket, self.item.name) self.pocket = pocket - ItemWidget.super.new(self, scene, "menu", self.itemData.fullname, "x" .. self.item.number) + ItemWidget.super.new(self, scene, "menu", self.itemData.fullname, "x" .. utils.math.numberToString(self.item.number, 2)) end function ItemWidget:selectAction() @@ -122,7 +144,10 @@ function ItemWidget:selectAction() self.scene.currentScreen.effects = game.loot:getEffectStrings(self.pocket, self.item.name) end ---BackWidget +function ItemWidget:action() + self.scene.currentScreen:setUseMenu(self.item) +end + function BackWidget:new(scene) ItemWidget.super.new(self, scene, "menu", "Back", "") end @@ -136,4 +161,53 @@ function BackWidget:action() self.scene.screens.mainmenu["pause"](self.scene, "main", 3) end +-- Use Menu Widget + +function UseWidget:new(scene, pocket, item) + self.item = item + self.itemData = game.loot:getItemData(pocket, self.item.name) + self.pocket = pocket + UseWidget.super.new(self, scene, "useMenu", "Use", "") +end + +function DropWidget:new(scene, pocket, item) + self.item = item + self.itemData = game.loot:getItemData(pocket, self.item.name) + self.pocket = pocket + self.max = self.item.number + self.number = 1 + DropWidget.super.new(self, scene, "useMenu", "Drop", "<" .. utils.math.numberToString(self.number, 2) .. ">") +end + +function DropWidget:updateSelected() + local keys = self.scene:getKeys(1) + if (keys["left"].isPressed) then + if (self.number > 1) then + self.number = self.number - 1 + else + self.number = self.max + end + self.label2 = "<" .. utils.math.numberToString(self.number, 2) .. ">" + self:invalidateCanvas() + end + if (keys["right"].isPressed) then + if (self.number < self.max) then + self.number = self.number + 1 + else + self.number = 1 + end + self.label2 = "<" .. utils.math.numberToString(self.number, 2) .. ">" + self:invalidateCanvas() + end +end + + +function ResumeWidget:new(scene) + ResumeWidget.super.new(self, scene, "useMenu", "Back", "") +end + +function ResumeWidget:action() + self.scene.currentScreen:removeUseMenu() +end + return ItemsScreen