Esempio n. 1
0
        private void FinishDragging()
        {
            var dragStartItem = _dragStartItem;

            _dragStartItem = null;
            _dragging      = false;
        }
Esempio n. 2
0
        private void SetCursorItem(InventoryContainerItem slot, bool isServerTransaction, MouseButton button)
        {
            if (slot.Item != null && slot.Item.Count > 0 && !(slot.Item is ItemAir))
            {
                CursorItemRenderer.IsVisible = true;
                CursorItemRenderer.Item      = slot.Item;

                HoverItem    = slot;
                SelectedItem = slot.Item;
                OnCursorItemChanged(slot, slot.Item, isServerTransaction, button);

                SetOverlayText(slot.Item);

                slot.Item = new ItemAir()
                {
                    Count = 0
                };

                OnSlotChanged(slot, slot.Item, isServerTransaction);
                //OnItemSelected(slot, slot.Item);
            }
            else
            {
                CursorItemRenderer.IsVisible = false;
                SelectedItem = null;

                OnCursorItemChanged(slot, slot.Item, isServerTransaction, button);
            }
        }
Esempio n. 3
0
 private void ContainerItemOnCursorEnter(object sender, GuiCursorEventArgs e)
 {
     if (sender is InventoryContainerItem containerItem)
     {
         HighlightedSlot = containerItem;
     }
 }
Esempio n. 4
0
 private void ContainerItemOnCursorLeave(object sender, GuiCursorEventArgs e)
 {
     if (sender is InventoryContainerItem containerItem && containerItem == HighlightedSlot)
     {
         HighlightedSlot = null;
     }
 }
Esempio n. 5
0
        protected virtual void OnCursorItemChanged(InventoryContainerItem slot, Item item, bool isServerTransaction, MouseButton button)
        {
            if (isServerTransaction)
            {
                return;
            }

            Inventory.SetCursor(item, false, slot.InventoryIndex, button);
        }
        private void ChildOnCursorLeave(object sender, GuiCursorEventArgs e)
        {
            if (sender == HoverItem)
            {
                HoverItem = null;
            }

            TextOverlay.IsVisible = false;
        }
Esempio n. 7
0
        protected override void OnCursorItemChanged(InventoryContainerItem slot, Item item)
        {
            if (Inventory is Inventory inv)
            {
                inv.SetCursor(item, false);
            }

            // Inventory.Cursor = item;
        }
        private void ChildOnCursorEnter(object sender, GuiCursorEventArgs e)
        {
            if (sender is InventoryContainerItem item)
            {
                TextOverlay.IsVisible = true;
                SetOverlayText(item);

                HoverItem = item;
            }
            //AddChild(TextOverlay);
        }
        private void InventoryItemClicked(InventoryContainerItem containerItem)
        {
            if (containerItem == null) //Release
            {
                ActiveItem = null;
                RemoveChild(TextOverlay);
                return;
            }

            ActiveItem = containerItem;
            SetOverlayText(containerItem);
        }
Esempio n. 10
0
        private void ContainerItemOnCursorLeave(object sender, GuiCursorEventArgs e)
        {
            if (sender is InventoryContainerItem containerItem && containerItem == HighlightedSlot)
            {
                HighlightedSlot = null;

                if (SelectedItem != null)
                {
                    SetOverlayText(SelectedItem);
                }
                else
                {
                    SetOverlayText(null);
                }
            }
        }
Esempio n. 11
0
        protected override void OnSlotChanged(InventoryContainerItem slot, Item item, bool isServerTransaction)
        {
            if (slot.InventoryId == 120)
            {
                //Armor
            }
            if (slot.InventoryId == 999)
            {
                //Crafting
            }
            else
            {
                Inventory.SetSlot(slot.InventoryIndex, item, isServerTransaction);
            }

            // Inventory[slot.InventoryIndex] = item;
        }
Esempio n. 12
0
        private void ContainerItemOnCursorDown(object sender, GuiCursorEventArgs e)
        {
            if (!AllowDragging)
            {
                return;
            }

            if (sender is InventoryContainerItem containerItem)
            {
                if (_dragStartItem == null && (containerItem.Item == null || containerItem.Item is ItemAir || containerItem.Item.Id <= 0) && HoverItem != null)
                {
                    _draggedContainers.Clear();
                    _dragStartItem = containerItem;
                    _dragging      = true;
                }
            }
        }
Esempio n. 13
0
        public InventoryContainerItem CreateSlot(int x, int y, int slotId, int inventoryId)
        {
            InventoryContainerItem containerItem = new InventoryContainerItem()
            {
                Margin                = new Thickness(x, y, 0, 0),
                InventoryIndex        = slotId,
                Anchor                = Alignment.TopLeft,
                AutoSizeMode          = AutoSizeMode.None,
                InventoryId           = inventoryId,
                HighlightedBackground = Color.White * 0.8f
            };

            containerItem.CursorEnter += ContainerItemOnCursorEnter;
            containerItem.CursorLeave += ContainerItemOnCursorLeave;

            containerItem.CursorPressed += ContainerItemOnCursorPressed;

            return(containerItem);
        }
Esempio n. 14
0
        private void SetCursorItem(InventoryContainerItem slot)
        {
            if (slot.Item != null && slot.Item.Count > 0 && !(slot.Item is ItemAir))
            {
                HoverItem    = slot;
                SelectedItem = slot.Item;
                OnCursorItemChanged(slot, slot.Item);

                SetOverlayText(slot.Item);

                slot.Item = new ItemAir()
                {
                    Count = 0
                };

                OnSlotChanged(slot, slot.Item);
                //OnItemSelected(slot, slot.Item);
            }
        }
Esempio n. 15
0
        private void ContainerItemOnCursorMove(object sender, GuiCursorMoveEventArgs e)
        {
            if (!AllowDragging)
            {
                return;
            }

            if (sender is InventoryContainerItem containerItem)
            {
                if (!_dragging || containerItem == _previousItem || !CanDrag())
                {
                    return;
                }

                _previousItem = containerItem;

                if (!_draggedContainers.ContainsKey(containerItem))
                {
                    _draggedContainers.Add(containerItem, containerItem.Item.Clone());
                }

                if (containerItem.Item == null || containerItem.Item.Id == HoverItem.Item.Id &&
                    containerItem.Item.Id < containerItem.Item.MaxStackSize)
                {
                    if (containerItem.Item == null)
                    {
                        containerItem.Item       = HoverItem.Item.Clone();
                        containerItem.Item.Count = 1;
                        HoverItem.Item.Count--;
                    }
                    else
                    {
                        containerItem.Item.Count += 1;
                        HoverItem.Item.Count--;
                    }
                }

                if (!CanDrag())
                {
                }
            }
        }
Esempio n. 16
0
        public GuiPlayerInventoryDialog(Player player, Inventory inventory)
        {
            Player    = player;
            Inventory = inventory;

            // Subscribe to events

            _guiHotBarInventoryItems = new InventoryContainerItem[inventory?.SlotCount ?? 0];

            if (_guiHotBarInventoryItems.Length != 46)
            {
                throw new ArgumentOutOfRangeException(nameof(inventory), inventory?.SlotCount ?? 0, "Expected player inventory containing 46 slots.");
            }

            ContentContainer.Background = GuiTextures.InventoryPlayerBackground;
            ContentContainer.Width      = ContentContainer.MinWidth = ContentContainer.MaxWidth = 176;
            ContentContainer.Height     = ContentContainer.MinHeight = ContentContainer.MaxHeight = 166;

            SetFixedSize(176, 166);

            ContentContainer.AutoSizeMode = AutoSizeMode.None;

            AddChild(_debug = new GuiAutoUpdatingTextElement(() =>
            {
                if (base.GuiRenderer == null)
                {
                    return("");
                }

                var position = Mouse.GetState().Position;

                return($"Cursor: {position}");
            }, true)
            {
                Background = new Color(Color.Black, 0.35f),
                Anchor     = Alignment.TopCenter,
                Margin     = new Thickness(0, 0, 0, 200)
            });

            var texture = player.ModelRenderer.Texture;

            if (texture == null)
            {
            }

            var modelRenderer = player.ModelRenderer;
            var mob           = new PlayerMob(player.Name, player.Level, player.Network,
                                              player.ModelRenderer.Texture, true)
            {
                ModelRenderer = modelRenderer,
            };

            ContentContainer.AddChild(_playerEntityModelView =
                                          new GuiEntityModelView(mob)
            {
                Margin            = new Thickness(7, 25),
                Width             = 49,
                Height            = 70,
                Anchor            = Alignment.TopLeft,
                AutoSizeMode      = AutoSizeMode.None,
                Background        = null,
                BackgroundOverlay = null
            });

            int lx = 7, ly = 83;

            int   idx   = 9;
            Color color = Color.Blue;

            for (int y = 0; y < 4; y++)
            {
                for (int x = 0; x < 9; x++)
                {
                    var item = new InventoryContainerItem()
                    {
                        Item = Inventory[idx],
                        HighlightedBackground = new Microsoft.Xna.Framework.Color(color, 0.5f),
                        Anchor       = Alignment.TopLeft,
                        AutoSizeMode = AutoSizeMode.None,
                        //  Name = idx.ToString(),
                        Margin = new Thickness(lx, ly, 0, 0)
                    };

                    _guiHotBarInventoryItems[idx] = item;

                    ContentContainer.AddChild(item);
                    idx++;

                    lx += item.Width;
                }

                lx = 7;

                if (idx == 36)
                {
                    idx   = 0;
                    ly    = 141;
                    color = Color.GreenYellow;
                }
                else
                {
                    ly += _guiHotBarInventoryItems[idx - 1].Height;
                }
            }

            lx = 7;
            ly = 7;
            for (int i = 0; i < 4; i++)
            {
                var element = new InventoryContainerItem()
                {
                    HighlightedBackground = new Microsoft.Xna.Framework.Color(Color.Red, 0.5f),
                    Anchor       = Alignment.TopLeft,
                    Margin       = new Thickness(ly, lx),
                    AutoSizeMode = AutoSizeMode.None,
                    //Item = Inventory[]
                };

                ContentContainer.AddChild(element);

                ly += element.Height;
            }

            var shieldSlot = new InventoryContainerItem()
            {
                HighlightedBackground = new Microsoft.Xna.Framework.Color(Color.Orange, 0.5f),
                Anchor       = Alignment.TopLeft,
                Margin       = new Thickness(61, 76),
                AutoSizeMode = AutoSizeMode.None
            };

            ContentContainer.AddChild(shieldSlot);

            AddChild(TextOverlay = new GuiTextElement(true)
            {
                HasShadow    = true,
                Background   = new Color(Color.Black, 0.35f),
                Enabled      = false,
                FontStyle    = FontStyle.DropShadow,
                TextColor    = TextColor.Yellow,
                ClipToBounds = false,
                //BackgroundOverlay = new Color(Color.Black, 0.35f),
            });

            foreach (var child in ContentContainer.ChildElements.Where(x => x is InventoryContainerItem).Cast <InventoryContainerItem>())
            {
                child.CursorPressed += InventoryItemPressed;
                child.CursorEnter   += ChildOnCursorEnter;
                child.CursorLeave   += ChildOnCursorLeave;
            }
        }
 protected override void OnCursorItemChanged(InventoryContainerItem slot, Item item)
 {
     Inventory.SetCursor(item, true);
     // Inventory.Cursor = item;
 }
Esempio n. 18
0
        //protected virtual void OnItemSelected(InventoryContainerItem slot, Item item) { }

        protected virtual void OnSlotChanged(InventoryContainerItem slot, Item item, bool isServerTransaction)
        {
        }
Esempio n. 19
0
        public GuiPlayerInventoryDialog(Player player, Inventory inventory) : base(inventory, GuiTextures.InventoryPlayerBackground, 176, 166)
        {
            Player = player;

            // Subscribe to events

            if (player != null)
            {
                var modelRenderer = player.ModelRenderer;

                var mob = new PlayerMob(player.Name, player.Level, player.Network, player.ModelRenderer.Texture)
                {
                    ModelRenderer = modelRenderer,
                };

                ContentContainer.AddChild(
                    _playerEntityModelView = new GuiEntityModelView(mob)
                {
                    Margin            = new Thickness(7, 25),
                    Width             = 49,
                    Height            = 70,
                    Anchor            = Alignment.TopLeft,
                    AutoSizeMode      = AutoSizeMode.None,
                    Background        = null,
                    BackgroundOverlay = null
                });
            }

            Color color = Color.Blue;

            foreach (var slot in AddSlots(8, 84, 9, 27, 9, 0x00))
            {
                //   slot.HighlightedBackground = new Microsoft.Xna.Framework.Color(color, 0.5f);
                slot.Item = Inventory[slot.InventoryIndex];
            }

            color = Color.Aqua;
            foreach (var slot in AddSlots(8, 142, 9, 9, 0, 0))
            {
                // slot.HighlightedBackground = new Microsoft.Xna.Framework.Color(color, 0.5f);
                slot.Item = Inventory[slot.InventoryIndex];
            }

            foreach (var slot in AddSlots(8, 8, 1, 4, 0, 120))
            {
                var  inventoryIndex = slot.InventoryIndex;
                Item item           = new ItemAir();

                switch (slot.InventoryIndex)
                {
                case 0:
                    item           = inventory.Helmet;
                    inventoryIndex = inventory.HelmetSlot;
                    break;

                case 1:
                    item           = inventory.Chestplate;
                    inventoryIndex = inventory.ChestSlot;
                    break;

                case 2:
                    item           = inventory.Leggings;
                    inventoryIndex = inventory.LeggingsSlot;
                    break;

                case 3:
                    item           = inventory.Boots;
                    inventoryIndex = inventory.BootsSlot;
                    break;
                }

                //  slot.HighlightedBackground = new Microsoft.Xna.Framework.Color(Color.Red, 0.5f);
                slot.Item           = item;
                slot.InventoryIndex = inventoryIndex;
            }

            foreach (var slot in AddSlots(98, 18, 2, 4, 41, 0))
            {
                slot.Item = Inventory[slot.InventoryIndex];
                //  slot.HighlightedBackground = new Microsoft.Xna.Framework.Color(Color.Purple, 0.5f);
            }

            CraftingOutput = AddSlot(154, 28, 45, 0);
            //  CraftingOutput.HighlightedBackground = new Microsoft.Xna.Framework.Color(Color.Purple, 0.5f);

            /*var shieldSlot = new InventoryContainerItem()
             * {
             *  HighlightedBackground = new Microsoft.Xna.Framework.Color(Color.Orange, 0.5f),
             *  Anchor = Alignment.TopLeft,
             *  Margin =  new Thickness(61, 76),
             *  AutoSizeMode = AutoSizeMode.None,
             *  Item = Inventory[40],
             *  InventoryIndex = 40
             * };
             *
             * ContentContainer.AddChild(shieldSlot);*/
        }
Esempio n. 20
0
 private void SetOverlayText(InventoryContainerItem item)
 {
     _overlayText  = item.Item?.DisplayName ?? item.Item?.Name;
     _overlayStart = 0;
     _nextUpdate   = TimeSpan.Zero;
 }
 protected override void OnSlotChanged(InventoryContainerItem slot, Item item)
 {
     Inventory.SetSlot(slot.InventoryIndex, item, true);
     // Inventory[slot.InventoryIndex] = item;
 }
Esempio n. 22
0
 protected virtual void OnCursorItemChanged(InventoryContainerItem slot, Item item)
 {
 }
        public GuiPlayerInventoryDialog(Player player, Inventory inventory)
        {
            Player    = player;
            Inventory = inventory;

            // Subscribe to events

            _guiHotBarInventoryItems = new InventoryContainerItem[inventory?.SlotCount ?? 0];

            if (_guiHotBarInventoryItems.Length != 46)
            {
                throw new ArgumentOutOfRangeException(nameof(inventory), inventory?.SlotCount ?? 0, "Expected player inventory containing 46 slots.");
            }

            ContentContainer.Background        = GuiTextures.InventoryPlayerBackground;
            ContentContainer.BackgroundOverlay = null;

            ContentContainer.Width  = ContentContainer.MinWidth = ContentContainer.MaxWidth = 176;
            ContentContainer.Height = ContentContainer.MinHeight = ContentContainer.MaxHeight = 166;

            SetFixedSize(176, 166);

            ContentContainer.AutoSizeMode = AutoSizeMode.None;

            var modelRenderer = player.ModelRenderer;
            var mob           = new PlayerMob(player.Name, player.Level, player.Network,
                                              player.ModelRenderer.Texture)
            {
                ModelRenderer = modelRenderer,
            };

            ContentContainer.AddChild(_playerEntityModelView =
                                          new GuiEntityModelView(mob)
            {
                Margin            = new Thickness(7, 25),
                Width             = 49,
                Height            = 70,
                Anchor            = Alignment.TopLeft,
                AutoSizeMode      = AutoSizeMode.None,
                Background        = null,
                BackgroundOverlay = null
            });

            Color color = Color.Blue;

            foreach (var slot in AddSlots(8, 84, 9, 27, 9, 0x00))
            {
                //   slot.HighlightedBackground = new Microsoft.Xna.Framework.Color(color, 0.5f);
                slot.Item = Inventory[slot.InventoryIndex];
            }

            color = Color.Aqua;
            foreach (var slot in AddSlots(8, 142, 9, 9, 0, 0))
            {
                // slot.HighlightedBackground = new Microsoft.Xna.Framework.Color(color, 0.5f);
                slot.Item = Inventory[slot.InventoryIndex];
            }

            foreach (var slot in AddSlots(8, 8, 1, 4, 0, 120))
            {
                var  inventoryIndex = slot.InventoryIndex;
                Item item           = new ItemAir();

                switch (slot.InventoryIndex)
                {
                case 0:
                    item           = Inventory.Helmet;
                    inventoryIndex = Inventory.HelmetSlot;
                    break;

                case 1:
                    item           = Inventory.Chestplate;
                    inventoryIndex = Inventory.ChestSlot;
                    break;

                case 2:
                    item           = Inventory.Leggings;
                    inventoryIndex = Inventory.LeggingsSlot;
                    break;

                case 3:
                    item           = Inventory.Boots;
                    inventoryIndex = Inventory.BootsSlot;
                    break;
                }

                //  slot.HighlightedBackground = new Microsoft.Xna.Framework.Color(Color.Red, 0.5f);
                slot.Item           = item;
                slot.InventoryIndex = inventoryIndex;
            }

            foreach (var slot in AddSlots(98, 18, 2, 4, 41, 0))
            {
                slot.Item = Inventory[slot.InventoryIndex];
                //  slot.HighlightedBackground = new Microsoft.Xna.Framework.Color(Color.Purple, 0.5f);
            }

            CraftingOutput = AddSlot(154, 28, 45, 0);
            //  CraftingOutput.HighlightedBackground = new Microsoft.Xna.Framework.Color(Color.Purple, 0.5f);

            /*var shieldSlot = new InventoryContainerItem()
             * {
             *  HighlightedBackground = new Microsoft.Xna.Framework.Color(Color.Orange, 0.5f),
             *  Anchor = Alignment.TopLeft,
             *  Margin =  new Thickness(61, 76),
             *  AutoSizeMode = AutoSizeMode.None,
             *  Item = Inventory[40],
             *  InventoryIndex = 40
             * };
             *
             * ContentContainer.AddChild(shieldSlot);*/
        }
Esempio n. 24
0
 protected override void OnSlotChanged(InventoryContainerItem slot, Item item, bool isServerTransaction)
 {
     Inventory.SetSlot(slot.InventoryIndex, item, isServerTransaction);
     // Inventory[slot.InventoryIndex] = item;
 }