Exemplo n.º 1
0
        protected override void ButtonClicked(GuiButton btn, MouseButton button)
        {
            if (btn is GuiItemSlot slot)
            {
                if (SharpCraft.Instance.KeyboardState.IsKeyDown(Key.LShift))
                {
                    SharpCraft.Instance.Player.FastMoveStack(slot.ID);
                }
                else if ((_draggedStack == null || _draggedStack.IsEmpty) && slot.Stack != null && !slot.Stack.IsEmpty) //when not holding anything and clicked a non-empty stack in the inventory
                {
                    int toTake = slot.Stack.Count;

                    if (button == MouseButton.Right)
                    {
                        toTake /= 2;
                        toTake  = toTake == 0 ? 1 : toTake;
                    }

                    _draggedStack = slot.Stack.Copy(toTake);

                    slot.Stack.Count -= toTake;
                }
                else
                {
                    if (slot.Stack == null || slot.Stack.IsEmpty) // when holding a non-empty stack and clicking an empty slot
                    {
                        if (button == MouseButton.Right && _draggedStack != null)
                        {
                            SharpCraft.Instance.Player.SetItemStackInInventory(btn.ID, _draggedStack.Copy(1));

                            _draggedStack.Count--;
                        }
                        else
                        {
                            SharpCraft.Instance.Player.SetItemStackInInventory(btn.ID, _draggedStack);

                            _draggedStack = null;
                        }
                    }
                    else if (_draggedStack != null && slot.Stack.ItemSame(_draggedStack))
                    {
                        int ammountToMove = button == MouseButton.Right ? 1 : Math.Min(slot.Stack.Item.GetMaxStackSize() - slot.Stack.Count, _draggedStack.Count);

                        slot.Stack.Count    += ammountToMove;
                        _draggedStack.Count -= ammountToMove;
                    }
                    else if (_draggedStack != null && !_draggedStack.IsEmpty)
                    {
                        ItemStack stackInSlot = SharpCraft.Instance.Player.GetItemStackInInventory(btn.ID);
                        SharpCraft.Instance.Player.SetItemStackInInventory(btn.ID, _draggedStack.Copy());

                        _draggedStack = stackInSlot.Copy();
                    }
                }
            }
        }
Exemplo n.º 2
0
        public virtual void OnMouseClick(int x, int y, MouseButton button)
        {
            for (int i = Buttons.Count - 1; i >= 0; i--)
            {
                GuiButton btn = Buttons[i];

                if (btn.Enabled && btn.IsMouseOver(x, y))
                {
                    ButtonClicked(btn, button);
                    break;
                }
            }
        }
Exemplo n.º 3
0
        protected override void ButtonClicked(GuiButton btn, MouseButton button)
        {
            switch (btn.ID)
            {
            case 0:
                SharpCraft.Instance.CloseGuiScreen();
                break;

            case 1:
                SharpCraft.Instance.Disconnect();

                SharpCraft.Instance.OpenGuiScreen(new GuiScreenMainMenu());
                break;

            case 2:
                SharpCraft.Instance.Close();
                break;
            }
        }
Exemplo n.º 4
0
        protected override void ButtonClicked(GuiButton btn, MouseButton button)
        {
            switch (btn.ID)
            {
            case 0:
                SharpCraft.Instance.CloseGuiScreen();
                SharpCraft.Instance.StartGame();
                break;

            case 1:
                if (SharpCraft.Instance.ConnectToServer("127.0.0.1", 25566))
                {
                    SharpCraft.Instance.CloseGuiScreen();
                }
                break;

            case 2:
                SharpCraft.Instance.Close();
                break;
            }
        }
Exemplo n.º 5
0
 protected virtual void ButtonClicked(GuiButton btn, MouseButton button)
 {
 }