From 2c2bee9409a17946f669736fb8ccf87d0ec581b3 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Wed, 21 Apr 2021 19:11:52 +0200 Subject: [PATCH] feat: add confirmation dialog for item dropping --- sonic-radiance.love/game/modules/confirmdialog/init.lua | 4 ++++ .../scenes/overworld/screens/mainmenu/items.lua | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/sonic-radiance.love/game/modules/confirmdialog/init.lua b/sonic-radiance.love/game/modules/confirmdialog/init.lua index e5ff0b7..4a1272c 100644 --- a/sonic-radiance.love/game/modules/confirmdialog/init.lua +++ b/sonic-radiance.love/game/modules/confirmdialog/init.lua @@ -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 diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/items.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/items.lua index 1d86364..e34939e 100644 --- a/sonic-radiance.love/scenes/overworld/screens/mainmenu/items.lua +++ b/sonic-radiance.love/scenes/overworld/screens/mainmenu/items.lua @@ -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()