public CraftingBenchWindow(ICraftingRepository craftingRepository, InventoryWindow inventory)
        {
            WindowAreas = new[]
            {
                new CraftingWindowArea(craftingRepository, CraftingOutputIndex, 3, 3),
                new WindowArea(MainIndex, 27, 9, 3),                 // Main inventory
                new WindowArea(HotbarIndex, 9, 9, 1)                 // Hotbar
            };
            if (inventory != null)
            {
                inventory.MainInventory.CopyTo(MainInventory);
                inventory.Hotbar.CopyTo(Hotbar);
            }

            foreach (var area in WindowAreas)
            {
                area.WindowChange += (s, e) => OnWindowChange(new WindowChangeEventArgs(
                                                                  (s as WindowArea).StartIndex + e.SlotIndex, e.Value));
            }
            Copying = false;
            if (inventory != null)
            {
                inventory.WindowChange += (sender, e) =>
                {
                    if (Copying)
                    {
                        return;
                    }
                    if (e.SlotIndex >= InventoryWindow.MainIndex &&
                        e.SlotIndex < InventoryWindow.MainIndex + inventory.MainInventory.Length ||
                        e.SlotIndex >= InventoryWindow.HotbarIndex &&
                        e.SlotIndex < InventoryWindow.HotbarIndex + inventory.Hotbar.Length)
                    {
                        inventory.MainInventory.CopyTo(MainInventory);
                        inventory.Hotbar.CopyTo(Hotbar);
                    }
                }
            }
            ;
        }
示例#2
0
        public FurnaceWindow(EventScheduler scheduler, Coordinates3D coordinates,
                             IItemRepository itemRepository, InventoryWindow inventory)
        {
            ItemRepository = itemRepository;
            EventScheduler = scheduler;
            Coordinates    = coordinates;

            WindowAreas = new[]
            {
                new WindowArea(IngredientIndex, 1, 1, 1),
                new WindowArea(FuelIndex, 1, 1, 1),
                new WindowArea(OutputIndex, 1, 1, 1),
                new WindowArea(MainIndex, 27, 9, 3),
                new WindowArea(HotbarIndex, 9, 9, 1)
            };
            inventory.MainInventory.CopyTo(MainInventory);
            inventory.Hotbar.CopyTo(Hotbar);
            foreach (var area in WindowAreas)
            {
                area.WindowChange += (s, e) => OnWindowChange(new WindowChangeEventArgs(
                                                                  (s as WindowArea).StartIndex + e.SlotIndex, e.Value));
            }
            Copying = false;
            inventory.WindowChange += (sender, e) =>
            {
                if (Copying)
                {
                    return;
                }
                if (e.SlotIndex >= InventoryWindow.MainIndex &&
                    e.SlotIndex < InventoryWindow.MainIndex + inventory.MainInventory.Length ||
                    e.SlotIndex >= InventoryWindow.HotbarIndex &&
                    e.SlotIndex < InventoryWindow.HotbarIndex + inventory.Hotbar.Length)
                {
                    inventory.MainInventory.CopyTo(MainInventory);
                    inventory.Hotbar.CopyTo(Hotbar);
                }
            };
        }