private void UseMenu_Canceled(object sender, EventArgs e)
        {
            ItemUseMenu useMenu = (sender as ItemUseMenu);

            menu_Closed(sender, e);
            var itemsMenu = (Menus.Peek() as Window_Prep_Items);

            itemsMenu.cancel_use();
            AddItemCommandMenu(itemsMenu, useMenu, true);
        }
        private void Promote(ItemUseMenu useMenu, Maybe <int> promotionId = default(Maybe <int>))
        {
            Game_Actor actor     = useMenu.Actor;
            int        itemIndex = useMenu.SelectedItem;

            Global.game_system.Preparations_Actor_Id = actor.id;
            Global.game_temp.preparations_item_index = itemIndex;

            var promotionFadeMenu = useMenu.PromotionScreenFade(promotionId);

            promotionFadeMenu.Finished += PromotionFadeMenu_Finished;
            AddMenu(promotionFadeMenu);
        }
        private void AddItemCommandMenu(Window_Prep_Items itemsMenu, ItemUseMenu useMenu = null, bool toUseItem = false)
        {
            var itemCommandMenu = itemsMenu.GetCommandMenu();

            if (toUseItem)
            {
                itemCommandMenu.ToUseItem();
            }
            if (useMenu != null)
            {
                itemCommandMenu.SetCursorLoc(useMenu.CurrentCursorLoc);
            }

            itemCommandMenu.Selected += ItemCommandMenu_Selected;
            itemCommandMenu.Canceled += ItemCommandMenu_Canceled;
            AddMenu(itemCommandMenu);
        }
        private void UseItem(
            ConfirmationMenu useConfirmMenu,
            ItemUseMenu useMenu,
            ItemRepairMenu repairMenu)
        {
            Game_Actor actor = useMenu.Actor;
            Data_Item  item  = useMenu.SelectedItemData.to_item;

            // Use -1 if nothing
            int inventoryTarget = -1;

            if (repairMenu != null)
            {
                inventoryTarget = repairMenu.SelectedItem;
            }

            // If promoting
            if (actor.PromotedBy(item))
            {
                // If there are multiple promotion choices
                if (actor.PromotedBy(item) &&
                    actor.NeedsPromotionMenu)
                {
                    Global.game_map.add_actor_unit(Constants.Team.PLAYER_TEAM, Config.OFF_MAP, actor.id, "");
                    var unit = Global.game_map.last_added_unit;

                    var promotionChoiceMenu = new PromotionChoiceMenu(unit);
                    promotionChoiceMenu.Selected  += PromotionChoiceMenu_Selected;
                    promotionChoiceMenu.Canceled  += PromotionChoiceMenu_Canceled;
                    promotionChoiceMenu.Closed    += menu_Closed;
                    promotionChoiceMenu.Confirmed += PromotionChoiceMenu_Confirmed;
                    AddMenu(promotionChoiceMenu);

                    var promotionMenuFadeIn = promotionChoiceMenu.FadeInMenu(false);
                    promotionMenuFadeIn.Finished += menu_Closed;
                    AddMenu(promotionMenuFadeIn);
                }
                else
                {
                    Promote(useMenu);
                }
            }
            else
            {
                RemoveTopMenu(useConfirmMenu);
                if (repairMenu != null)
                {
                    RemoveTopMenu(repairMenu);
                }

                Global.game_system.play_se(System_Sounds.Gain);
                Dictionary <Boosts, int> boosts = actor.item_boosts(item);
                // Apply item effect
                actor.item_effect(item, inventoryTarget);
                actor.recover_hp();

                useMenu.UseItem();
                useMenu.ShowWindow();
                if (item.is_stat_booster() || item.is_growth_booster())
                {
                    useMenu.CreateStatsPopup(item, boosts);
                }
                else if (item.can_repair)
                {
                    useMenu.CreateRepairPopup(inventoryTarget);
                }
            }
        }