feat(items): initial actions menu

This commit is contained in:
Kazhnuz 2020-10-03 14:33:10 +02:00
parent 68da70f7bf
commit bad24445a7

View file

@ -7,6 +7,9 @@ local gui = require "game.modules.gui"
local ItemWidget = menu.DualTextWidget:extend() local ItemWidget = menu.DualTextWidget:extend()
local BackWidget = 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 local DESC_SIZE = 48*4
@ -21,12 +24,14 @@ function ItemsScreen:new(scene)
end end
function ItemsScreen:update(dt) function ItemsScreen:update(dt)
local keys = self.scene:getKeys(1) if (self.scene.menusystem.menus["useMenu"] == nil) then
if (keys["left"].isPressed) then local keys = self.scene:getKeys(1)
self:getMenu(self.menuIndex - 1) if (keys["left"].isPressed) then
end self:getMenu(self.menuIndex - 1)
if (keys["right"].isPressed) then end
self:getMenu(self.menuIndex + 1) if (keys["right"].isPressed) then
self:getMenu(self.menuIndex + 1)
end
end end
end end
@ -47,7 +52,7 @@ end
function ItemsScreen:setMenu() function ItemsScreen:setMenu()
self.pocket = game.loot:getPocketById(self.menuIndex) self.pocket = game.loot:getPocketById(self.menuIndex)
local w = 128+32 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 for i,item in ipairs(self.pocket.list) do
--menu.DualTextWidget(self.scene, "menu", item.name, "x" .. item.number) --menu.DualTextWidget(self.scene, "menu", item.name, "x" .. item.number)
ItemWidget(self.scene, self.pocket.name, item) ItemWidget(self.scene, self.pocket.name, item)
@ -55,6 +60,23 @@ function ItemsScreen:setMenu()
BackWidget(self.scene) BackWidget(self.scene)
self.scene.menusystem.menus["menu"]:setCancelWidget() self.scene.menusystem.menus["menu"]:setCancelWidget()
self.scene.menusystem:switchMenu("menu") 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 end
function ItemsScreen:draw() function ItemsScreen:draw()
@ -109,12 +131,12 @@ function ItemsScreen:drawPocketRoll(x, y)
core.screen:resetScissor() core.screen:resetScissor()
end end
-- Widgets -- Items Widgets
function ItemWidget:new(scene, pocket, item) function ItemWidget:new(scene, pocket, item)
self.item = item self.item = item
self.itemData = game.loot:getItemData(pocket, self.item.name) self.itemData = game.loot:getItemData(pocket, self.item.name)
self.pocket = pocket 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 end
function ItemWidget:selectAction() function ItemWidget:selectAction()
@ -122,7 +144,10 @@ function ItemWidget:selectAction()
self.scene.currentScreen.effects = game.loot:getEffectStrings(self.pocket, self.item.name) self.scene.currentScreen.effects = game.loot:getEffectStrings(self.pocket, self.item.name)
end end
--BackWidget function ItemWidget:action()
self.scene.currentScreen:setUseMenu(self.item)
end
function BackWidget:new(scene) function BackWidget:new(scene)
ItemWidget.super.new(self, scene, "menu", "Back", "") ItemWidget.super.new(self, scene, "menu", "Back", "")
end end
@ -136,4 +161,53 @@ function BackWidget:action()
self.scene.screens.mainmenu["pause"](self.scene, "main", 3) self.scene.screens.mainmenu["pause"](self.scene, "main", 3)
end 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 return ItemsScreen