Esempio n. 1
0
        void UpdateInventoryGrid()
        {
            InventoryCell[] cells = _inventory.GetCellsContent();
            for (int i = 0; i < cells.Length; i++)
            {
                InventoryCell cell = cells[i];
                InventoryItem item = DummySettings.GetItemById(cell.ItemId);
                CellView      cw   = _cellViews[i];
                cw.slot.ContextMenu.MenuItems.Clear();

                if (item != null)
                {
                    cw.name.Text    = item.Name;
                    cw.icon.Image   = item.Icon;
                    cw.icon.Visible = true;
                    cw.count.Text   = cell.ItemsCount.ToString();

                    Dictionary <InventoryItemActions, string> actions = _inventory.GetContextMenuActions(i);
                    if (actions != null)
                    {
                        foreach (KeyValuePair <InventoryItemActions, string> action in actions)
                        {
                            MenuItem menuItem = new MenuItem(action.Value);
                            menuItem.Click += (s, e) =>
                            {
                                _inventory.ApplyActionToItemInCell(action.Key, cw.id);
                                UpdateInventoryGrid();
                                UpdateEquipmentSlot();
                            };
                            cw.slot.ContextMenu.MenuItems.Add(menuItem);
                        }
                    }
                }
                else
                {
                    cw.name.Text    = "";
                    cw.icon.Visible = false;
                    cw.count.Text   = "";
                }
            }
        }