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(); } } } }
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; } } }
protected override void ButtonClicked(GuiButton btn, MouseButton button) { switch (btn.ID) { case 0: SharpCraft.Instance.CloseGuiScreen(); SharpCraft.Instance.StartGame(); break; case 2: SharpCraft.Instance.Close(); break; } }
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; } }
protected virtual void ButtonClicked(GuiButton btn, MouseButton button) { }