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
|
local DESC_SIZE = 48*4
|
||||||
|
|
||||||
function ItemsScreen:new(scene)
|
function ItemsScreen:new(scene, menuIndex, widgetIndex)
|
||||||
self.menuIndex = 1
|
self.menuIndex = menuIndex or 1
|
||||||
|
self.widgetIndex = widgetIndex or 1
|
||||||
self.choiceBack = gui.newChoiceBack(DESC_SIZE)
|
self.choiceBack = gui.newChoiceBack(DESC_SIZE)
|
||||||
self.descBox = gui.newTextBox("assets/gui/dialogbox.png", DESC_SIZE, 40+16)
|
self.descBox = gui.newTextBox("assets/gui/dialogbox.png", DESC_SIZE, 40+16)
|
||||||
self.effectBox = gui.newTextBox("assets/gui/dialogbox.png", DESC_SIZE, 40)
|
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
|
if (self.scene.menusystem.menus["useMenu"] == nil) then
|
||||||
local keys = self.scene:getKeys(1)
|
local keys = self.scene:getKeys(1)
|
||||||
if (keys["left"].isPressed) then
|
if (keys["left"].isPressed) then
|
||||||
|
self.widgetIndex = 1
|
||||||
self:getMenu(self.menuIndex - 1)
|
self:getMenu(self.menuIndex - 1)
|
||||||
end
|
end
|
||||||
if (keys["right"].isPressed) then
|
if (keys["right"].isPressed) then
|
||||||
|
self.widgetIndex = 1
|
||||||
self:getMenu(self.menuIndex + 1)
|
self:getMenu(self.menuIndex + 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -49,25 +52,26 @@ function ItemsScreen:getMenu(newMenuIndex)
|
||||||
self:setMenu()
|
self:setMenu()
|
||||||
end
|
end
|
||||||
|
|
||||||
function ItemsScreen:setMenu()
|
function ItemsScreen:setMenu(widgetId)
|
||||||
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, w, 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, i)
|
||||||
end
|
end
|
||||||
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
|
self.scene.menusystem.menus["menu"].isLocked = true
|
||||||
|
self.scene.menusystem.menus["menu"].widget.selected = math.max(1, self.widgetIndex)
|
||||||
end
|
end
|
||||||
|
|
||||||
function ItemsScreen:setUseMenu(item)
|
function ItemsScreen:setUseMenu(item, widgetId)
|
||||||
local w = 96
|
local w = 96
|
||||||
menu.ListMenu(self.scene, "useMenu", const.X2 + 16 - w, const.Y2 - 48, w, 3, true)
|
menu.ListMenu(self.scene, "useMenu", const.X2 + 16 - w, const.Y2 - 48, w, 3, true)
|
||||||
UseWidget(self.scene, self.pocket.name, item)
|
UseWidget(self.scene, self.pocket.name, item, widgetId)
|
||||||
DropWidget(self.scene, self.pocket.name, item)
|
DropWidget(self.scene, self.pocket.name, item, widgetId)
|
||||||
ResumeWidget(self.scene)
|
ResumeWidget(self.scene)
|
||||||
self.scene.menusystem.menus["useMenu"]:setCancelWidget()
|
self.scene.menusystem.menus["useMenu"]:setCancelWidget()
|
||||||
self.scene.menusystem:switchMenu("useMenu")
|
self.scene.menusystem:switchMenu("useMenu")
|
||||||
|
@ -132,10 +136,11 @@ function ItemsScreen:drawPocketRoll(x, y)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Items Widgets
|
-- Items Widgets
|
||||||
function ItemWidget:new(scene, pocket, item)
|
function ItemWidget:new(scene, pocket, item, widgetId)
|
||||||
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
|
||||||
|
self.widgetId = widgetId
|
||||||
ItemWidget.super.new(self, scene, "menu", self.itemData.fullname, "x" .. utils.math.numberToString(self.item.number, 2))
|
ItemWidget.super.new(self, scene, "menu", self.itemData.fullname, "x" .. utils.math.numberToString(self.item.number, 2))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -145,7 +150,7 @@ function ItemWidget:selectAction()
|
||||||
end
|
end
|
||||||
|
|
||||||
function ItemWidget:action()
|
function ItemWidget:action()
|
||||||
self.scene.currentScreen:setUseMenu(self.item)
|
self.scene.currentScreen:setUseMenu(self.item, self.widgetId)
|
||||||
end
|
end
|
||||||
|
|
||||||
function BackWidget:new(scene)
|
function BackWidget:new(scene)
|
||||||
|
@ -163,18 +168,24 @@ end
|
||||||
|
|
||||||
-- Use Menu Widget
|
-- Use Menu Widget
|
||||||
|
|
||||||
function UseWidget:new(scene, pocket, item)
|
function UseWidget:new(scene, pocket, item, widgetId)
|
||||||
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
|
||||||
|
self.widgetId = widgetId
|
||||||
UseWidget.super.new(self, scene, "useMenu", "Use", "")
|
UseWidget.super.new(self, scene, "useMenu", "Use", "")
|
||||||
end
|
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.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
|
||||||
self.max = self.item.number
|
self.max = self.item.number
|
||||||
|
self.widgetId = widgetId
|
||||||
self.number = 1
|
self.number = 1
|
||||||
DropWidget.super.new(self, scene, "useMenu", "Drop", "<" .. utils.math.numberToString(self.number, 2) .. ">")
|
DropWidget.super.new(self, scene, "useMenu", "Drop", "<" .. utils.math.numberToString(self.number, 2) .. ">")
|
||||||
end
|
end
|
||||||
|
@ -201,6 +212,12 @@ function DropWidget:updateSelected()
|
||||||
end
|
end
|
||||||
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)
|
function ResumeWidget:new(scene)
|
||||||
ResumeWidget.super.new(self, scene, "useMenu", "Back", "")
|
ResumeWidget.super.new(self, scene, "useMenu", "Back", "")
|
||||||
|
|
Loading…
Reference in a new issue