コード例 #1
0
        public GuiPlayerCreativeInventoryDialog(Item[] items) : base(new InventoryBase(items.Length), GuiTextures.InventoryCreativeItemSearch, 194, 135)
        {
            MultiStackContainer = new GuiScrollableMultiStackContainer()
            {
                Anchor       = Alignment.Fill,
                Orientation  = Orientation.Vertical,
                Margin       = new Thickness(8, 17, 24, 27),
                AutoSizeMode = AutoSizeMode.None,
                Height       = 90,
                MaxHeight    = 90,
                MaxWidth     = 162,
                Width        = 162
            };

            ContentContainer.AddChild(MultiStackContainer);

            GuiStackContainer stackContainer = MultiStackContainer.AddRow(RowBuilder);
            int itemsX = 0;

            for (int i = 0; i < items.Length; i++)
            {
                var slot = CreateSlot(0, 0, i, 0);

                stackContainer.AddChild(slot);

                //x += InventoryContainerItem.ItemWidth;
                itemsX++;

                if (itemsX == 9)
                {
                    itemsX         = 0;
                    stackContainer = MultiStackContainer.AddRow(RowBuilder);
                }
            }
        }
コード例 #2
0
ファイル: GuiInventoryBase.cs プロジェクト: lvyitian/Alex
        public InventoryContainerItem AddSlot(int x, int y, int slotId, int inventoryId)
        {
            var slot = CreateSlot(x, y, slotId, inventoryId);

            ContentContainer.AddChild(slot);

            return(slot);
        }
コード例 #3
0
        public InventoryContainerItem AddSlot(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;

            ContentContainer.AddChild(containerItem);

            return(containerItem);
        }
コード例 #4
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.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);*/
        }
コード例 #5
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);*/
        }
コード例 #6
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;
            }
        }