fix last commit

This commit is contained in:
UnknownShadow200 2017-03-01 17:43:40 +11:00
parent 93b99aa3f0
commit 3384b1aa55
3 changed files with 26 additions and 10 deletions

View File

@ -173,7 +173,7 @@ namespace ClassicalSharp.Gui.Screens {
return true; return true;
} }
} }
return false; return hotbar.HandlesKeyUp(key);
} }
public void OpenTextInputBar(string text) { public void OpenTextInputBar(string text) {

View File

@ -75,6 +75,10 @@ namespace ClassicalSharp.Gui.Screens {
return true; return true;
} }
public override bool HandlesKeyUp(Key key) {
return game.Gui.hudScreen.hotbar.HandlesKeyUp(key);
}
void ArrowKeyMove(int delta) { void ArrowKeyMove(int delta) {
int startIndex = selIndex; int startIndex = selIndex;
selIndex += delta; selIndex += delta;

View File

@ -98,7 +98,7 @@ namespace ClassicalSharp.Gui.Widgets {
selTex = new Texture(0, 0, y, hSize, vSize, rec); selTex = new Texture(0, 0, y, hSize, vSize, rec);
} }
bool altHandled;
public override bool HandlesKeyDown(Key key) { public override bool HandlesKeyDown(Key key) {
if (key >= Key.Number1 && key <= Key.Number9) { if (key >= Key.Number1 && key <= Key.Number9) {
int index = (int)key - (int)Key.Number1; int index = (int)key - (int)Key.Number1;
@ -106,18 +106,30 @@ namespace ClassicalSharp.Gui.Widgets {
if (game.Input.AltDown) { if (game.Input.AltDown) {
// Pick from first to ninth row // Pick from first to ninth row
game.Inventory.Offset = index * Inventory.BlocksPerRow; game.Inventory.Offset = index * Inventory.BlocksPerRow;
game.Events.RaiseHeldBlockChanged();
altHandled = true;
} else { } else {
game.Inventory.SelectedIndex = index; game.Inventory.SelectedIndex = index;
} }
return true; return true;
} else if (key == Key.AltLeft || key == Key.AltRight) { }
return false;
}
public override bool HandlesKeyUp(Key key) {
// We need to handle these cases:
// a) user presses alt then number
// b) user presses alt
// thus we only do case b) if case a) did not happen
if (!(key == Key.AltLeft || key == Key.AltRight)) return false;
if (altHandled) { altHandled = false; return true; } // handled already
// Alternate between first and second row // Alternate between first and second row
int index = game.Inventory.Offset == 0 ? 1 : 0; int index = game.Inventory.Offset == 0 ? 1 : 0;
game.Inventory.Offset = index * Inventory.BlocksPerRow; game.Inventory.Offset = index * Inventory.BlocksPerRow;
game.Events.RaiseHeldBlockChanged();
return true; return true;
} }
return false;
}
public override bool HandlesMouseClick(int mouseX, int mouseY, MouseButton button) { public override bool HandlesMouseClick(int mouseX, int mouseY, MouseButton button) {
if (button != MouseButton.Left || !Bounds.Contains(mouseX, mouseY)) if (button != MouseButton.Left || !Bounds.Contains(mouseX, mouseY))