feat: add use and drop item support
This commit is contained in:
parent
608f582cdf
commit
58989e974d
1 changed files with 28 additions and 11 deletions
|
@ -13,8 +13,9 @@ local UseWidget = menu.DualTextWidget:extend()
|
|||
|
||||
local DESC_SIZE = 48*4
|
||||
|
||||
function ItemsScreen:new(scene)
|
||||
self.menuIndex = 1
|
||||
function ItemsScreen:new(scene, menuIndex, widgetIndex)
|
||||
self.menuIndex = menuIndex or 1
|
||||
self.widgetIndex = widgetIndex or 1
|
||||
self.choiceBack = gui.newChoiceBack(DESC_SIZE)
|
||||
self.descBox = gui.newTextBox("assets/gui/dialogbox.png", DESC_SIZE, 40+16)
|
||||
self.effectBox = gui.newTextBox("assets/gui/dialogbox.png", DESC_SIZE, 40)
|
||||
|
@ -27,9 +28,11 @@ function ItemsScreen:update(dt)
|
|||
if (self.scene.menusystem.menus["useMenu"] == nil) then
|
||||
local keys = self.scene:getKeys(1)
|
||||
if (keys["left"].isPressed) then
|
||||
self.widgetIndex = 1
|
||||
self:getMenu(self.menuIndex - 1)
|
||||
end
|
||||
if (keys["right"].isPressed) then
|
||||
self.widgetIndex = 1
|
||||
self:getMenu(self.menuIndex + 1)
|
||||
end
|
||||
end
|
||||
|
@ -49,25 +52,26 @@ function ItemsScreen:getMenu(newMenuIndex)
|
|||
self:setMenu()
|
||||
end
|
||||
|
||||
function ItemsScreen:setMenu()
|
||||
function ItemsScreen:setMenu(widgetId)
|
||||
self.pocket = game.loot:getPocketById(self.menuIndex)
|
||||
local w = 128+32
|
||||
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)
|
||||
ItemWidget(self.scene, self.pocket.name, item, i)
|
||||
end
|
||||
BackWidget(self.scene)
|
||||
self.scene.menusystem.menus["menu"]:setCancelWidget()
|
||||
self.scene.menusystem:switchMenu("menu")
|
||||
self.scene.menusystem.menus["menu"].isLocked = true
|
||||
self.scene.menusystem.menus["menu"].widget.selected = math.max(1, self.widgetIndex)
|
||||
end
|
||||
|
||||
function ItemsScreen:setUseMenu(item)
|
||||
function ItemsScreen:setUseMenu(item, widgetId)
|
||||
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)
|
||||
UseWidget(self.scene, self.pocket.name, item, widgetId)
|
||||
DropWidget(self.scene, self.pocket.name, item, widgetId)
|
||||
ResumeWidget(self.scene)
|
||||
self.scene.menusystem.menus["useMenu"]:setCancelWidget()
|
||||
self.scene.menusystem:switchMenu("useMenu")
|
||||
|
@ -132,10 +136,11 @@ function ItemsScreen:drawPocketRoll(x, y)
|
|||
end
|
||||
|
||||
-- Items Widgets
|
||||
function ItemWidget:new(scene, pocket, item)
|
||||
function ItemWidget:new(scene, pocket, item, widgetId)
|
||||
self.item = item
|
||||
self.itemData = game.loot:getItemData(pocket, self.item.name)
|
||||
self.pocket = pocket
|
||||
self.widgetId = widgetId
|
||||
ItemWidget.super.new(self, scene, "menu", self.itemData.fullname, "x" .. utils.math.numberToString(self.item.number, 2))
|
||||
end
|
||||
|
||||
|
@ -145,7 +150,7 @@ function ItemWidget:selectAction()
|
|||
end
|
||||
|
||||
function ItemWidget:action()
|
||||
self.scene.currentScreen:setUseMenu(self.item)
|
||||
self.scene.currentScreen:setUseMenu(self.item, self.widgetId)
|
||||
end
|
||||
|
||||
function BackWidget:new(scene)
|
||||
|
@ -163,18 +168,24 @@ end
|
|||
|
||||
-- Use Menu Widget
|
||||
|
||||
function UseWidget:new(scene, pocket, item)
|
||||
function UseWidget:new(scene, pocket, item, widgetId)
|
||||
self.item = item
|
||||
self.itemData = game.loot:getItemData(pocket, self.item.name)
|
||||
self.pocket = pocket
|
||||
self.widgetId = widgetId
|
||||
UseWidget.super.new(self, scene, "useMenu", "Use", "")
|
||||
end
|
||||
|
||||
function DropWidget:new(scene, pocket, item)
|
||||
function UseWidget:action()
|
||||
self.scene.screens.mainmenu["useItems"](self.scene, self.pocket, self.item, self.widgetId)
|
||||
end
|
||||
|
||||
function DropWidget:new(scene, pocket, item, widgetId)
|
||||
self.item = item
|
||||
self.itemData = game.loot:getItemData(pocket, self.item.name)
|
||||
self.pocket = pocket
|
||||
self.max = self.item.number
|
||||
self.widgetId = widgetId
|
||||
self.number = 1
|
||||
DropWidget.super.new(self, scene, "useMenu", "Drop", "<" .. utils.math.numberToString(self.number, 2) .. ">")
|
||||
end
|
||||
|
@ -201,6 +212,12 @@ function DropWidget:updateSelected()
|
|||
end
|
||||
end
|
||||
|
||||
function DropWidget:action()
|
||||
game.loot:removeItem(self.pocket, self.item.name, self.number)
|
||||
self.scene.currentScreen.widgetIndex = self.widgetId
|
||||
self.scene.currentScreen:removeUseMenu()
|
||||
self.scene.currentScreen:setMenu()
|
||||
end
|
||||
|
||||
function ResumeWidget:new(scene)
|
||||
ResumeWidget.super.new(self, scene, "useMenu", "Back", "")
|
||||
|
|
Loading…
Reference in a new issue