Example #1
0
        private void DrawInventory(SpriteBatch b)
        {
            _inventory = new InventoryMenu(this.xPositionOnScreen + 38, this.yPositionOnScreen + 100, false, Player.Items, null, -1, 3, 0, 0, false)
            {
                showGrayedOutSlots = true
            };

            if (_configOptions.ShowInventory)
            {
                if (_configOptions.InventoryGrid)
                {
                    for (int i = 0; i < 36; i++)
                    {
                        Vector2 toDraw = new Vector2((float)(Game1.viewport.Width / 2 - Game1.tileSize * 12 / 2 + (i % 12) * Game1.tileSize) - 3, (float)(this.yPositionOnScreen + i / 12 * (Game1.tileSize) + (i / 12 - 1) * Game1.pixelZoom - (Game1.tileSize / 5)) + 111);
                        b.Draw(Game1.menuTexture, toDraw, new Rectangle?(Game1.getSourceRectForStandardTileSheet(Game1.menuTexture, 10, -1, -1)), Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0.5f);
                        if (i >= Player.maxItems)
                        {
                            b.Draw(Game1.menuTexture, toDraw, new Rectangle?(Game1.getSourceRectForStandardTileSheet(Game1.menuTexture, 57, -1, -1)), Color.White * 0.5f, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0.5f);
                        }
                    }
                }
                Vector2 toDraw1 = new Vector2((float)(Game1.viewport.Width / 2 - Game1.tileSize * 12 / 2 + Player.Items.IndexOf(Player?.CurrentItem) * Game1.tileSize) - 3, (float)(_inventory.yPositionOnScreen - Game1.tileSize * 3 / 2) + 91);
                b.Draw(Game1.menuTexture, toDraw1, new Rectangle?(Game1.getSourceRectForStandardTileSheet(Game1.menuTexture, 56, -1, -1)), Color.White * 1f);
                _inventory.draw(b);
            }
            else
            {
                _inventory.height = 0;
            }
        }
Example #2
0
    public void SaveSaveState(SaveState saveState)
    {
        InventoryData inventoryData = new InventoryData();
        InventoryMenu inventory     = InventoryMenu.inventoryMenu;

        inventoryData.quickslot1 = new WeaponData(inventory.weapon1);
        inventoryData.quickslot2 = new WeaponData(inventory.weapon2);
        //Debug.Log("Saved '" + inventory.weapon1.itemName + "' in quickslot1.");
        //Debug.Log("Saved '" + inventory.weapon2.itemName + "' in quickslot2.");**/
        //TODO quickslot 3

        Item[]     items     = inventory.GetItems();
        ItemData[] itemDatas = new ItemData[items.Length];
        for (int i = 0; i < items.Length; i++)
        {
            itemDatas[i] = GetItemData(items[i]);
            //Debug.Log("Saved '" + items[i].itemName + "' in inventory slot " + i);
        }
        inventoryData.items = itemDatas;

        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = File.Create(Application.persistentDataPath + saveState.fileName);

        bf.Serialize(file, inventoryData);
        file.Close();
        saveState.lastSaved = new DateTime().ToString();
        Debug.Log("Saved SaveState '" + saveState.name + "'.");
        SaveSaveStateList();
    }
Example #3
0
 void Start()
 {
     eq           = FindObjectOfType <InventoryMenu> ();
     lifes        = FindObjectOfType <LifeManager> ();
     door         = FindObjectOfType <OpenDoor> ();
     playerInZone = false;
 }
    public bool OnInput(InputEvent inputEvent)
    {
        if (inputEvent is InputEventKey keyEvent)
        {
            if (keyEvent.IsActionPressed("ui_cancel"))
            {
                AddChild(mainMenu);
                return(true);
            }
            //OK fine let's give the inventory menu a shot too.
            else if (keyEvent.IsActionPressed("Inventory"))
            {
                if (InventoryMenu.IsInsideTree())
                {
                    GetNode("/root").RemoveChild(InventoryMenu);
                }
                else
                {
                    GetNode("/root").AddChild(InventoryMenu);
                }
                return(true);
            }
        }

        // if(inputEvent.IsAction("RefreshMouseMode") && InventoryMenu.IsInsideTree())
        // {
        //     GD.PrintErr("Did we get this?");
        //     Input.SetMouseMode(Input.MouseMode.Visible);
        //     return true;
        // }
        return(false);
    }
        /// <summary>Main event that derived handlers use to setup necessary hooks and other things needed to take over how the stack is split.</summary>
        /// <returns>If the input was handled or consumed.</returns>
        protected override EInputHandled OpenSplitMenu()
        {
            try {
                this.PlayerInventoryMenu = this.NativeMenu.inventory;
                this.ItemsToGrabMenu     = this.NativeMenu.ItemsToGrabMenu;

                // Emulate the right click method that would normally happen (??)
                this.HoverItem = this.NativeMenu.hoveredItem;
            }
            catch (Exception e) {
                Log.Error($"[{nameof(ItemGrabMenuHandler)}.{nameof(OpenSplitMenu)}] Had an exception:\n{e}");
                return(EInputHandled.NotHandled);
            }

            // Do nothing if we're not hovering over an item, or item is single (no point in splitting)
            if (this.HoverItem == null || this.HoverItem.Stack <= 1)
            {
                return(EInputHandled.NotHandled);
            }

            this.TotalItems = this.HoverItem.Stack;
            // +1 before /2 ensures number is rounded UP
            this.StackAmount = (this.TotalItems + 1) / 2; // default at half

            // Create the split menu
            this.SplitMenu = new StackSplitMenu(OnStackAmountReceived, this.StackAmount);

            return(EInputHandled.Consumed);
        }
Example #6
0
        private static bool TryGetClickedInventoryItem(GameMenu GM, ButtonPressedEventArgs e, out Item Result, out int Index)
        {
            Result = null;
            Index  = -1;

            if (GM == null || GM.currentTab != GameMenu.inventoryTab)
            {
                return(false);
            }

            InventoryPage InvPage = GM.pages.First(x => x is InventoryPage) as InventoryPage;
            InventoryMenu InvMenu = InvPage.inventory;

            Vector2 CursorPos            = e.Cursor.ScreenPixels;
            int     ClickedItemIndex     = InvMenu.getInventoryPositionOfClick((int)CursorPos.X, (int)CursorPos.Y);
            bool    IsValidInventorySlot = ClickedItemIndex >= 0 && ClickedItemIndex < InvMenu.actualInventory.Count;

            if (!IsValidInventorySlot)
            {
                return(false);
            }

            Result = InvMenu.actualInventory[ClickedItemIndex];
            Index  = ClickedItemIndex;
            return(Result != null);
        }
            public static void Prefix(InventoryMenu __instance)
            {
                if (!IsModEnabled() || !Config.InventoryEnabled)
                {
                    return;
                }
                avoidTicks++;
                foreach (ClickableComponent clickableComponent in __instance.inventory)
                {
                    int slotNumber = Convert.ToInt32(clickableComponent.name);
                    if (clickableComponent.containsPoint(Game1.getMouseX(), Game1.getMouseY()) && slotNumber < __instance.actualInventory.Count && (__instance.actualInventory[slotNumber] == null || __instance.highlightMethod(__instance.actualInventory[slotNumber])) && slotNumber < __instance.actualInventory.Count && __instance.actualInventory[slotNumber] != null)
                    {
                        if (slotNumber == lastSlotNumber || avoidTicks < 30)
                        {
                            return;
                        }
                        avoidTicks     = 0;
                        lastSlotNumber = slotNumber;
                        if (Game1.random.NextDouble() < 0.5)
                        {
                            return;
                        }

                        MoveToRandomSlot(ref __instance.actualInventory, slotNumber);
                    }
                }
            }
Example #8
0
    public void setNewWeapon()
    {
        if (item is Weapon)
        {
            Player_weapons playerWeapons = GameObject.FindGameObjectWithTag("Player").GetComponent <Player_weapons>();
            playerWeapons.setNewWeapon((Weapon)item);
            disableFrame();
            changeColor(Color.cyan);
        }
        if (item is Potion)
        {
            Debug.Log("Wchodze w SetNewWeapon do potek " + i++);
            Potion      potion      = (Potion)item;
            PlayerStats playerStats = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerStats>();
            playerStats.addPotionValue(potion.healValue);
            InventoryMenu inventoryMenu = GameObject.FindGameObjectWithTag("Items").GetComponent <InventoryMenu>();
            //disableFrame();
            //changeColor(Color.cyan);

            PlayerInventory playerInventory = GameObject.FindGameObjectWithTag("GameManager").GetComponent <PlayerInventory>() as PlayerInventory;
            playerInventory.removeFromInventory(item);
            GameObject.Destroy(gameObject);
            inventoryMenu.updateInventory();
        }
    }
Example #9
0
        public GraphicsUI(GraphicsDevice graphicsDevice, GameSession gameSession) : base(new Rectangle(0, 0, graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height))
        {
            MainMenu         = new MainMenu(graphicsDevice, gameSession);
            HealthBarManager = new HealthBarManager(graphicsDevice);
            BackgroundPanel  = new BackgroundPanel(new Rectangle(0, 0, graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height), gameSession);
            LoginMenu        = new LoginMenu(new Rectangle(0, 0, graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height), gameSession);
            SettingsMenu     = new SettingsMenu(graphicsDevice, gameSession);
            InventoryMenu    = new InventoryMenu(new Rectangle(0, 0, graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height), gameSession);
            ActiveGamePanel  = new GUIPanel(new Rectangle(0, 0, graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height));
            ActiveGamePanel.AddElement(HealthBarManager);

            AddElement(ActiveGamePanel);
            AddElement(BackgroundPanel);
            AddElement(MainMenu);
            AddElement(InventoryMenu);
            AddElement(LoginMenu);
            AddElement(SettingsMenu);

            //Disable all
            foreach (GUIElement e in ContainedElements)
            {
                InitElement(e);
            }

            BackgroundPanel.Visible = true;
            BackgroundPanel.Enabled = true;

            //Constant menus
            MessageManager = new MessageManager(new Rectangle(0, 0, graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height), gameSession);
            AddElement(MessageManager);

            //Set initial menu
            SetCurrentMenu(LoginMenu);
        }
Example #10
0
        private static void ResetItemView(ref InventoryMenu instance)
        {
            modEntry.Monitor.Log("RefreshMenu");

            // update items in view
            playerInventory.Clear();

            foreach (var item in Game1.player.Items)
            {
                if (item is not Object || (!menu.ItemsWithoutQuality.Contains(item.ParentSheetIndex) && menu.Quality != ItemQuality.Normal && (item as Object).Quality != (int)menu.Quality) || !menu.FilteredItems.Exists(i => i.NameEquivalentTo(item.Name)))
                {
                    continue;
                }
                playerInventory.Add(item);
            }
            for (int i = 0; i < Game1.player.maxItems.Value; i++)
            {
                if (playerInventory.Count <= i)
                {
                    playerInventory.Add(null);
                }
            }
            inventorySlots           = new List <ClickableComponent>();
            totalCapacity            = Math.Max(48, ((playerInventory.Count - 1) / 12 + 2) * 12);
            instance.rows            = 3;
            instance.capacity        = 36;
            instance.actualInventory = playerInventory.Skip(scrolled * 12).Take(36).ToList();
            shouldResetItemView      = false;
        }
Example #11
0
    // Use this for initialization
    void Start()
    {
        MeshRenderer meshRenderer = GetComponent <MeshRenderer>();

        inventoryMenu = FindObjectOfType <InventoryMenu>();
        HideMenu();
    }
Example #12
0
        public override void gameWindowSizeChanged(Rectangle oldBounds, Rectangle newBounds)
        {
            this.xPositionOnScreen = Game1.viewport.Width / 2 - (800 + IClickableMenu.borderWidth * 2) / 2;
            this.yPositionOnScreen = Game1.viewport.Height / 2 - (600 + IClickableMenu.borderWidth * 2) / 2;
            this.width             = 800 + IClickableMenu.borderWidth * 2;
            this.height            = 600 + IClickableMenu.borderWidth * 2;
            base.initializeUpperRightCloseButton();
            bool flag = Game1.viewport.Width < 1500;

            if (flag)
            {
                this.xPositionOnScreen = Game1.tileSize / 2;
            }
            Game1.player.forceCanMove();
            this.inventory = new InventoryMenu(this.xPositionOnScreen + Game1.tileSize / 2 + (Game1.tileSize / 3 + Game1.tileSize / 11), this.yPositionOnScreen + IClickableMenu.spaceToClearTopBorder + IClickableMenu.borderWidth + Game1.tileSize * 5 + Game1.pixelZoom * 10, false, null, new InventoryMenu.highlightThisItem(this.HighlightItemToShip), -1, 3, 0, 0, true)
            {
                showGrayedOutSlots = true
            };
            this.upArrow         = new ClickableTextureComponent(new Rectangle(this.xPositionOnScreen + this.width + Game1.tileSize / 4, this.yPositionOnScreen + Game1.tileSize / 4, 11 * Game1.pixelZoom, 12 * Game1.pixelZoom), Game1.mouseCursors, new Rectangle(421, 459, 11, 12), (float)Game1.pixelZoom, false);
            this.downArrow       = new ClickableTextureComponent(new Rectangle(this.xPositionOnScreen + this.width + Game1.tileSize / 4, this.yPositionOnScreen + this.height - Game1.tileSize, 11 * Game1.pixelZoom, 12 * Game1.pixelZoom), Game1.mouseCursors, new Rectangle(421, 472, 11, 12), (float)Game1.pixelZoom, false);
            this.scrollBar       = new ClickableTextureComponent(new Rectangle(this.upArrow.bounds.X + Game1.pixelZoom * 3, this.upArrow.bounds.Y + this.upArrow.bounds.Height + Game1.pixelZoom, 6 * Game1.pixelZoom, 10 * Game1.pixelZoom), Game1.mouseCursors, new Rectangle(435, 463, 6, 10), (float)Game1.pixelZoom, false);
            this.scrollBarRunner = new Rectangle(this.scrollBar.bounds.X, this.upArrow.bounds.Y + this.upArrow.bounds.Height + Game1.pixelZoom, this.scrollBar.bounds.Width, this.height - Game1.tileSize - this.upArrow.bounds.Height - Game1.pixelZoom * 7);
            this.shippingBox     = new ClickableComponent(new Rectangle(this.xPositionOnScreen, this.yPositionOnScreen, this.width, this.height - Game1.tileSize * 4 + Game1.tileSize / 2 + Game1.pixelZoom), (Item)null);
            this.shippedItemButtons.Clear();
            for (int i = 0; i < 4; i++)
            {
                this.shippedItemButtons.Add(new ClickableComponent(new Rectangle(this.xPositionOnScreen + Game1.tileSize / 4, this.yPositionOnScreen + Game1.tileSize / 4 + i * ((this.height - Game1.tileSize * 4) / 4), this.width - Game1.tileSize / 2, (this.height - Game1.tileSize * 4) / 4 + Game1.pixelZoom), string.Concat(i)));
            }
        }
Example #13
0
        public static void Create(IList <InventoryItem> inventoryList)
        {
            string ItemName = ConsoleHelper.ReadString("Enter the Name of the new Item...");

            int ItemSellin = ConsoleHelper.ReadInt("Enter the 'Sell In' days of the new Item...", "The 'Sell In' days must be a number! Please try again");

            int ItemQuality = ConsoleHelper.ReadInt("Enter the Quality level of the new Item...", "The Quality level must be a number! Please try again");

            Dictionary <string, InventoryItem> InventoryChoice = new Dictionary <string, InventoryItem>
            {
                { InventoryNames.AgedBrie, new AgedBrie(ItemSellin, ItemQuality) },
                { InventoryNames.ChristmasCracker, new ChristmasCracker(ItemSellin, ItemQuality) },
                { InventoryNames.FreshItem, new FreshItem(ItemSellin, ItemQuality) },
                { InventoryNames.FrozenItem, new FrozenItem(ItemSellin, ItemQuality) },
                { InventoryNames.Soap, new Soap(ItemSellin, ItemQuality) }
            };

            if (InventoryChoice.ContainsKey(ItemName))
            {
                inventoryList.Add(InventoryChoice[ItemName]);
            }
            else
            {
                inventoryList.Add(new InvalidItem(ItemName, ItemSellin, ItemQuality));
            }

            Console.WriteLine($"{ItemName} has been added to your inventory, you now have {inventoryList.Count} items in total");
            ConsoleHelper.WriteHorizontalRule();

            InventoryMenu.Options(inventoryList);
        }
Example #14
0
    private void Initialize()
    {
        if (parentMenu == null)
        {
            parentMenu = GetComponentInParent <InventoryMenu>();
        }
        Debug.Assert(parentMenu != null);

        if (button == null)
        {
            button = GetComponent <Button>();
        }
        Debug.Assert(button != null);

        if (images == null)
        {
            images = new List <Image>();
            foreach (var image in GetComponentsInChildren <Image>())
            {
                images.Add(image);
            }
        }

        if (text == null)
        {
            text = GetComponentInChildren <Text>();
        }
        Debug.Assert(text != null);

        okChoices.Add(new ButtonChoice("OK", DoNothing));

        isInitialized = true;
    }
        /*********
        ** Public methods
        *********/
        /// <summary>Construct an instance.</summary>
        /// <param name="menu">The underlying chest menu.</param>
        /// <param name="chest">The selected chest.</param>
        /// <param name="chests">The available chests.</param>
        /// <param name="config">The mod configuration.</param>
        public ManageChestOverlay(ItemGrabMenu menu, ManagedChest chest, ManagedChest[] chests, ModConfig config)
            : base(keepAlive: () => Game1.activeClickableMenu is ItemGrabMenu)
        {
            // menu
            this.Menu = menu;
#if SDV_1_2
            this.MenuInventoryMenu = ((ItemGrabMenu)Game1.activeClickableMenu).ItemsToGrabMenu;
#else
            this.MenuInventoryMenu = (InventoryMenu)typeof(ItemGrabMenu).GetField("ItemsToGrabMenu", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(menu);
            if (this.MenuInventoryMenu == null)
            {
                throw new InvalidOperationException("The menu doesn't seem to have a player inventory.");
            }
#endif
            this.DefaultChestHighlighter     = menu.inventory.highlightMethod;
            this.DefaultInventoryHighlighter = this.MenuInventoryMenu.highlightMethod;

            // chests & config
            this.Chest  = chest;
            this.Chests = chests;
            this.Groups = chests.Select(p => p.GetGroup()).Distinct().OrderBy(p => p).ToArray();
            this.Config = config;

            // components
            this.ReinitialiseComponents();
        }
Example #16
0
 void Awake()
 {
     inventoryPanel = GameObject.FindGameObjectWithTag("inventory");
     inventoryMenu  = GameObject.FindGameObjectWithTag("Items").GetComponent <InventoryMenu>();
     opened         = false;
     inventoryPanel.SetActive(false);
 }
Example #17
0
    void Start()
    {
        anim          = GetComponent <Animator> ();
        pause         = FindObjectOfType <PauseMenu> ();
        eq            = FindObjectOfType <InventoryMenu> ();
        myRigidBody2D = GetComponent <Rigidbody2D> ();

        AudioSource[] audios = GetComponents <AudioSource> ();
        jumpAudio         = audios [1];
        placeBombAudio    = audios [2];
        gravityWatchAudio = audios [3];
        fireResAudio      = audios [4];
        miniAudio         = audios [5];


        gravityStore        = myRigidBody2D.gravityScale;
        isBombPlaced        = false;
        isFireResActive     = false;
        isMini              = false;
        minimaliseMultipler = 1f;

        redColor    = new Color(1, 0, 0);
        normalColor = new Color(1, 1, 1);
        blueColor   = new Color(0.5f, 0.5f, 1f, 0.5f);
    }
Example #18
0
 private void Start()
 {
     inventoryMenu = FindObjectOfType <InventoryMenu>();
     meshRenderer  = GetComponent <MeshRenderer>();
     collider      = GetComponent <Collider>();
     pickupsound   = GetComponent <AudioSource>();
 }
Example #19
0
        public static void TakeToPlayer(InventoryMenu invPlayer, InventoryMenu invChest)
        {
            var invPlayerAdd   = new List <Item>();
            var invChestRemove = new List <Item>();

            StockToPlayer(invPlayer, invChest);
            for (var i = 0; i < Inventory.GetSpots(true); i++)
            {
                var itemPlayer = invPlayer.actualInventory[i];
                if (itemPlayer != null)
                {
                    continue;
                }
                foreach (var itemChest in invChest.actualInventory)
                {
                    if (itemChest == null || invChestRemove.Contains(itemChest))
                    {
                        continue;
                    }
                    invPlayerAdd.Add(itemChest);
                    invChestRemove.Add(itemChest);
                    break;
                }
            }
            foreach (var itemAdd in invPlayerAdd)
            {
                Inventory.AddItem(invPlayer, itemAdd, Inventory.GetSpots(true));
            }
            foreach (var itemRemove in invChestRemove)
            {
                Inventory.RemoveItem(invChest, itemRemove, Inventory.GetSpots());
            }
        }
Example #20
0
 public PostBundleSetupEvent(List <ClickableTextureComponent> ingredientList, List <ClickableTextureComponent> ingredientSlots, InventoryMenu inventory, Bundle currentBundle)
 {
     this.ingredientList  = ingredientList;
     this.ingredientSlots = ingredientSlots;
     this.inventory       = inventory;
     this.currentBundle   = currentBundle;
 }
Example #21
0
        public static void StockToPlayer(InventoryMenu invPlayer, InventoryMenu invChest)
        {
            var invChestRemove = new List <Item>();

            foreach (var itemPlayer in invPlayer.actualInventory)
            {
                if (itemPlayer.IsNull() || itemPlayer.GetMaxStack() < 0 || itemPlayer.IsFull())
                {
                    continue;
                }
                foreach (var itemChest in invChest.actualInventory)
                {
                    if (itemChest.IsNull() || !itemPlayer.SameKind(itemChest) || invChestRemove.Contains(itemChest))
                    {
                        continue;
                    }
                    var intStackMix = itemChest.Stack + itemPlayer.Stack;
                    var intStackMax = itemPlayer.GetMaxStack();
                    if (intStackMix > intStackMax)
                    {
                        itemChest.Stack -= intStackMax - itemPlayer.Stack;
                        itemPlayer.MaxStack();
                    }
                    else
                    {
                        itemPlayer.Stack += itemChest.Stack;
                        invChestRemove.Add(itemChest);
                    }
                }
            }
            foreach (var itemRemove in invChestRemove)
            {
                Inventory.RemoveItem(invChest, itemRemove, Inventory.GetSpots());
            }
        }
Example #22
0
        public static void TakeToChest(InventoryMenu invPlayer, InventoryMenu invChest)
        {
            var invChestAdd     = new List <Item>();
            var invPlayerRemove = new List <Item>();

            StockToChest(invPlayer, invChest);
            for (var i = 0; i < Inventory.GetSpotsFree(invChest); i++)
            {
                for (var iPlayer = !Data.SlotLock.ToBool ? 0 : Inventory.GetSpotsLine();
                     iPlayer < Inventory.GetSpots(true);
                     iPlayer++)
                {
                    var itemPlayer = invPlayer.actualInventory[iPlayer];
                    if (itemPlayer.IsNull() || invPlayerRemove.Contains(itemPlayer))
                    {
                        continue;
                    }
                    invChestAdd.Add(itemPlayer);
                    invPlayerRemove.Add(itemPlayer);
                    break;
                }
            }
            foreach (var itemAdd in invChestAdd)
            {
                Inventory.AddItem(invChest, itemAdd, Inventory.GetSpots(), true);
            }
            foreach (var itemRemove in invPlayerRemove)
            {
                Inventory.RemoveItem(invPlayer, itemRemove, Inventory.GetSpots(true));
            }
        }
        /// <summary>Main event that derived handlers use to setup necessary hooks and other things needed to take over how the stack is split.</summary>
        /// <returns>If the input was handled or consumed.</returns>
        protected override EInputHandled OpenSplitMenu()
        {
            try
            {
                this.PlayerInventoryMenu = this.NativeMenu.inventory;
                this.ItemsToGrabMenu     = this.NativeMenu.ItemsToGrabMenu;

                // Emulate the right click method that would normally happen.
                this.HoverItem = this.NativeMenu.hoveredItem;
            }
            catch (Exception e)
            {
                this.Monitor.Log($"Failed to get properties from native menu: {e}", LogLevel.Error);
                return(EInputHandled.NotHandled);
            }

            // Do nothing if we're not hovering over an item
            if (this.HoverItem == null || this.HoverItem.Stack <= 1)
            {
                return(EInputHandled.NotHandled);
            }

            this.TotalItems  = this.HoverItem.Stack;
            this.StackAmount = (int)Math.Ceiling(this.TotalItems / 2.0); // default at half

            // Create the split menu
            this.SplitMenu = new StackSplitMenu(OnStackAmountReceived, this.StackAmount);

            return(EInputHandled.Consumed);
        }
        /// <summary>Updates the number of items being held by the player based on what was input to the split menu.</summary>
        /// <param name="item">The selected item.</param>
        /// <param name="who">The player that selected the items.</param>
        /// <param name="inventory">Either the player inventory or the shop inventory.</param>
        /// <param name="callback">The native callback to invoke to continue with the regular behavior after we've modified the stack.</param>
        private void MoveItems(Item item, SFarmer who, InventoryMenu inventory, ItemGrabMenu.behaviorOnItemSelect callback)
        {
            Debug.Assert(this.StackAmount > 0);

            // Get the held item now that it's been set by the native receiveRightClick call
            var heldItem = this.HeldItem;

            if (heldItem != null)
            {
                // update held item stack and item stack
                int numCurrentlyHeld = heldItem.Stack; // How many we're actually holding.
                int numInPile        = this.HoverItem.Stack + item.Stack;
                int wantToHold       = Math.Min(this.TotalItems, Math.Max(this.StackAmount, 0));

                this.HoverItem.Stack = this.TotalItems - wantToHold;
                heldItem.Stack       = wantToHold;

                item.Stack = wantToHold;

                // Remove the empty item from the inventory
                if (this.HoverItem.Stack <= 0)
                {
                    int index = inventory.actualInventory.IndexOf(this.HoverItem);
                    if (index > -1)
                    {
                        inventory.actualInventory[index] = null;
                    }
                }
            }

            RestoreNativeCallbacks();

            // Update stack to the amount set from OnStackAmountReceived
            callback?.Invoke(item, who);
        }
Example #25
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome back, Allison!");

            IList <InventoryItem> InventoryList = new List <InventoryItem>();

            InventoryMenu.Options(InventoryList);
        }
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="menu">The underlying chest menu.</param>
 /// <param name="chest">The selected chest.</param>
 /// <param name="chests">The available chests.</param>
 /// <param name="config">The mod configuration.</param>
 /// <param name="keys">The configured key bindings.</param>
 /// <param name="events">The SMAPI events available for mods.</param>
 /// <param name="input">An API for checking and changing input state.</param>
 /// <param name="translations">Provides translations stored in the mod's folder.</param>
 /// <param name="showAutomateOptions">Whether to show Automate options.</param>
 public ChestOverlay(ItemGrabMenu menu, ManagedChest chest, ManagedChest[] chests, ModConfig config, ModConfigKeys keys, IModEvents events, IInputHelper input, ITranslationHelper translations, bool showAutomateOptions)
     : base(menu, chest, chests, config, keys, events, input, translations, showAutomateOptions, keepAlive: () => Game1.activeClickableMenu is ItemGrabMenu, topOffset: -Game1.pixelZoom * 9)
 {
     this.Menu = menu;
     this.MenuInventoryMenu           = menu.ItemsToGrabMenu;
     this.DefaultChestHighlighter     = menu.inventory.highlightMethod;
     this.DefaultInventoryHighlighter = this.MenuInventoryMenu.highlightMethod;
 }
    void Start()

    {
        //instantaniatevars
        meshRenderer  = GetComponent <MeshRenderer>();
        collider      = GetComponent <Collider>();
        inventoryMenu = FindObjectOfType <InventoryMenu>();
    }
Example #28
0
 void Awake()
 {
     if (instance != null)
     {
         Debug.LogWarning("More than one instance of inventory menu found!");
     }
     instance = this;
 }
Example #29
0
 private void setupMenu()
 {
     noteTexture = Game1.temporaryContent.Load <Texture2D>(BundleTextureName);
     inventory   = new InventoryMenu(xPositionOnScreen + 128, yPositionOnScreen + 140, true, null, Utility.highlightSmallObjects, 36, 6, 8, 8, false)
     {
         capacity = 36
     };
 }
Example #30
0
 private void Start()
 {
     pauseMenu     = GetComponent <PauseMenu>();
     inventoryMenu = GetComponent <InventoryMenu>();
     pauseMenu.Initialize(pauseMenuPanel);
     inventoryMenu.Initialize(inventoryMenuPanel);
     shipSelectionMenu.Initialize(shipSelectionMenuPanel);
 }