feat: add confirmation dialog for item dropping

This commit is contained in:
Kazhnuz 2021-04-21 19:11:52 +02:00
parent 3b28c5b776
commit 2c2bee9409
2 changed files with 13 additions and 0 deletions

View file

@ -20,6 +20,7 @@ function ConfirmDialog:new(scene, message, choice1func, choice1, choice2func, ch
self.choiceFunc[2] = choice2func or function() self:dismiss() end
self.choiceSound[1] = "mSelect"
self.choiceSound[2] = "mBack"
self.autoDismiss = false
self.darken = true
@ -75,6 +76,9 @@ function ConfirmDialog:doAction(choice)
if (self.choiceFunc[choice + 1] ~= nil) then
self.scene.assets.sfx[self.choiceSound[choice + 1]]:play()
self.choiceFunc[choice + 1]()
if (self.autoDismiss) then
self:dismiss()
end
end
end

View file

@ -13,6 +13,8 @@ local UseWidget = menu.DualTextWidget:extend()
local DESC_SIZE = 48*4
local ConfirmDialog = require "game.modules.confirmdialog"
function ItemsScreen:new(scene, menuIndex, widgetIndex)
self.menuIndex = menuIndex or 1
self.widgetIndex = widgetIndex or 1
@ -226,6 +228,13 @@ end
function DropWidget:action()
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)
self.scene.currentScreen.widgetIndex = self.widgetId
self.scene.currentScreen:removeUseMenu()