feat: add confirmation dialog for item dropping
This commit is contained in:
parent
3b28c5b776
commit
2c2bee9409
2 changed files with 13 additions and 0 deletions
|
@ -20,6 +20,7 @@ function ConfirmDialog:new(scene, message, choice1func, choice1, choice2func, ch
|
||||||
self.choiceFunc[2] = choice2func or function() self:dismiss() end
|
self.choiceFunc[2] = choice2func or function() self:dismiss() end
|
||||||
self.choiceSound[1] = "mSelect"
|
self.choiceSound[1] = "mSelect"
|
||||||
self.choiceSound[2] = "mBack"
|
self.choiceSound[2] = "mBack"
|
||||||
|
self.autoDismiss = false
|
||||||
|
|
||||||
self.darken = true
|
self.darken = true
|
||||||
|
|
||||||
|
@ -75,6 +76,9 @@ function ConfirmDialog:doAction(choice)
|
||||||
if (self.choiceFunc[choice + 1] ~= nil) then
|
if (self.choiceFunc[choice + 1] ~= nil) then
|
||||||
self.scene.assets.sfx[self.choiceSound[choice + 1]]:play()
|
self.scene.assets.sfx[self.choiceSound[choice + 1]]:play()
|
||||||
self.choiceFunc[choice + 1]()
|
self.choiceFunc[choice + 1]()
|
||||||
|
if (self.autoDismiss) then
|
||||||
|
self:dismiss()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,8 @@ local UseWidget = menu.DualTextWidget:extend()
|
||||||
|
|
||||||
local DESC_SIZE = 48*4
|
local DESC_SIZE = 48*4
|
||||||
|
|
||||||
|
local ConfirmDialog = require "game.modules.confirmdialog"
|
||||||
|
|
||||||
function ItemsScreen:new(scene, menuIndex, widgetIndex)
|
function ItemsScreen:new(scene, menuIndex, widgetIndex)
|
||||||
self.menuIndex = menuIndex or 1
|
self.menuIndex = menuIndex or 1
|
||||||
self.widgetIndex = widgetIndex or 1
|
self.widgetIndex = widgetIndex or 1
|
||||||
|
@ -226,6 +228,13 @@ end
|
||||||
|
|
||||||
function DropWidget:action()
|
function DropWidget:action()
|
||||||
self.scene.assets:playSFX("mSelect")
|
self.scene.assets:playSFX("mSelect")
|
||||||
|
local confirm = ConfirmDialog(self.scene, "Do you want to drop these items ? \nYou won't be able to recover them.",
|
||||||
|
function() self:drop() end)
|
||||||
|
confirm:setCancelChoice(2)
|
||||||
|
confirm.autoDismiss = true
|
||||||
|
end
|
||||||
|
|
||||||
|
function DropWidget:drop()
|
||||||
game.loot:removeItem(self.pocket, self.item.name, self.number)
|
game.loot:removeItem(self.pocket, self.item.name, self.number)
|
||||||
self.scene.currentScreen.widgetIndex = self.widgetId
|
self.scene.currentScreen.widgetIndex = self.widgetId
|
||||||
self.scene.currentScreen:removeUseMenu()
|
self.scene.currentScreen:removeUseMenu()
|
||||||
|
|
Loading…
Reference in a new issue