From 93b99aa3f09221fe681280e66307c8026ef1b00c Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 1 Mar 2017 17:21:27 +1100 Subject: [PATCH] Add multiple hotbars for inventory. You can use alt to switch between first and second hotbar. You can also use alt+number to switch to the nth hotbar. --- .../2D/Screens/Inventory/InventoryScreen.Input.cs | 3 +-- ClassicalSharp/2D/Widgets/HotbarWidget.cs | 14 +++++++++++++- ClassicalSharp/Game/Inventory.cs | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ClassicalSharp/2D/Screens/Inventory/InventoryScreen.Input.cs b/ClassicalSharp/2D/Screens/Inventory/InventoryScreen.Input.cs index 2fa96f0a7..23a278633 100644 --- a/ClassicalSharp/2D/Screens/Inventory/InventoryScreen.Input.cs +++ b/ClassicalSharp/2D/Screens/Inventory/InventoryScreen.Input.cs @@ -70,8 +70,7 @@ namespace ClassicalSharp.Gui.Screens { ArrowKeyMove(-blocksPerRow); } else if ((key == Key.Down || key == Key.Keypad2) && selIndex != -1) { ArrowKeyMove(blocksPerRow); - } else if (key >= Key.Number1 && key <= Key.Number9) { - game.Inventory.SelectedIndex = (int)key - (int)Key.Number1; + } else if (game.Gui.hudScreen.hotbar.HandlesKeyDown(key)) { } return true; } diff --git a/ClassicalSharp/2D/Widgets/HotbarWidget.cs b/ClassicalSharp/2D/Widgets/HotbarWidget.cs index 756c89c67..2aefb71f4 100644 --- a/ClassicalSharp/2D/Widgets/HotbarWidget.cs +++ b/ClassicalSharp/2D/Widgets/HotbarWidget.cs @@ -101,7 +101,19 @@ namespace ClassicalSharp.Gui.Widgets { public override bool HandlesKeyDown(Key key) { if (key >= Key.Number1 && key <= Key.Number9) { - game.Inventory.SelectedIndex = (int)key - (int)Key.Number1; + int index = (int)key - (int)Key.Number1; + + if (game.Input.AltDown) { + // Pick from first to ninth row + game.Inventory.Offset = index * Inventory.BlocksPerRow; + } else { + game.Inventory.SelectedIndex = index; + } + return true; + } else if (key == Key.AltLeft || key == Key.AltRight) { + // Alternate between first and second row + int index = game.Inventory.Offset == 0 ? 1 : 0; + game.Inventory.Offset = index * Inventory.BlocksPerRow; return true; } return false; diff --git a/ClassicalSharp/Game/Inventory.cs b/ClassicalSharp/Game/Inventory.cs index f84e63d30..1e7382f4d 100644 --- a/ClassicalSharp/Game/Inventory.cs +++ b/ClassicalSharp/Game/Inventory.cs @@ -27,7 +27,7 @@ namespace ClassicalSharp { Game game; public bool CanChangeHeldBlock = true; - public const int BlocksPerRow = 9, Rows = 2; + public const int BlocksPerRow = 9, Rows = 9; public int Offset = 0; public BlockID[] Hotbar = new BlockID[BlocksPerRow * Rows];