Add confirmation box for ItemAction

Hi,

I want to create a confirmation box (Yes/No) when user choose "Remove" operation in inventory. I tried to follow AssignHotbarItemAction example but it hards to make something similar for my case. What is the best option for this feature?
 
That's a good question. Right now the only way to do this is by making a custom Item Action to replace the remove Item Action.

But for such a generic feature I think I'll implement it for the next update. I think I'll make a generic ItemAction called ConfirmItemActionContainer, which would be an ItemAction that executes another Item Action after you press Yes, if you press No, it would go back and potentially call another Item Action.

Once I have something implemented I'll let you know and I'll send you the code
 
Please find the new Item Action below.
I haven't tested it yet so if there are any issue please do let me know. You can use the "ConfirmationPopUp" prefab that exists in the demo scene to try it out.
 

Attachments

  • ItemActionWithConfirmationPopUp.cs
    5.2 KB · Views: 2
Hi!

Scripts works but you have to change line 98
from
C#:
m_ConfirmationPopUp.SetConfirmAction(m_OnCancel);
to
C#:
m_ConfirmationPopUp.SetCancelAction(m_OnCancel);

Thanks!
 
Thanks for letting me know!
It's fixed now and this item action will be available in the next update :)
 
I think that there is one think to fix. Popup window should be destroy even if method is null. In other case after close window the game object live in scene and new are added in time. At the end we can finish the game with a few hundred inactive popup windows :p

C#:
 private void OnCancel()
        {
            if (m_ItemActionSetOnCancel == null)
            {
                ObjectPool.Destroy(m_ConfirmationPopUp.gameObject);               
                return;
            }
            
            for (int i = 0; i < m_ItemActionSetOnCancel.ItemActionCollection.Count; i++) {
                var itemAction = m_ItemActionSetOnCancel.ItemActionCollection[i];
                itemAction.InvokeAction(m_ItemInfo,m_ItemUser);
            }
            ObjectPool.Destroy(m_ConfirmationPopUp.gameObject);
        }

        /// <summary>
        /// Executed when confirm is clicked.
        /// </summary>
        private void OnConfirm()
        {
            if (m_ItemActionSetOnConfirm == null)
            {
                ObjectPool.Destroy(m_ConfirmationPopUp.gameObject);
                return;
            }

            for (int i = 0; i < m_ItemActionSetOnConfirm.ItemActionCollection.Count; i++) {
                var itemAction = m_ItemActionSetOnConfirm.ItemActionCollection[i];
                itemAction.InvokeAction(m_ItemInfo,m_ItemUser);
            }
            ObjectPool.Destroy(m_ConfirmationPopUp.gameObject);
        }
 
Top