Fixed inventory hiding and improved HUD event handling
This commit is contained in:
parent
ce573b51ce
commit
9c85164ed1
@ -21,6 +21,7 @@ import java.util.function.BooleanSupplier;
|
|||||||
|
|
||||||
import ru.windcorp.progressia.client.graphics.flat.RenderTarget;
|
import ru.windcorp.progressia.client.graphics.flat.RenderTarget;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutFill;
|
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutFill;
|
||||||
|
import ru.windcorp.progressia.client.graphics.input.InputEvent;
|
||||||
import ru.windcorp.progressia.client.graphics.model.Renderable;
|
import ru.windcorp.progressia.client.graphics.model.Renderable;
|
||||||
|
|
||||||
public class Hider extends Component {
|
public class Hider extends Component {
|
||||||
@ -37,16 +38,10 @@ public class Hider extends Component {
|
|||||||
addChild(contents);
|
addChild(contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME
|
@Override
|
||||||
//
|
protected boolean passInputToChildren(InputEvent e) {
|
||||||
// @Override
|
return !shouldHide.getAsBoolean();
|
||||||
// public void dispatchInput(Input input) {
|
}
|
||||||
// if (shouldHide.getAsBoolean()) {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// super.dispatchInput(input);
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized Component findFocused() {
|
public synchronized Component findFocused() {
|
||||||
|
@ -27,6 +27,9 @@ import ru.windcorp.progressia.client.graphics.gui.GUILayer;
|
|||||||
import ru.windcorp.progressia.client.graphics.gui.Group;
|
import ru.windcorp.progressia.client.graphics.gui.Group;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutFill;
|
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutFill;
|
||||||
import ru.windcorp.progressia.client.graphics.input.InputEvent;
|
import ru.windcorp.progressia.client.graphics.input.InputEvent;
|
||||||
|
import ru.windcorp.progressia.client.graphics.input.KeyMatcher;
|
||||||
|
import ru.windcorp.progressia.client.graphics.input.bus.InputBus;
|
||||||
|
import ru.windcorp.progressia.test.controls.TestPlayerControls;
|
||||||
|
|
||||||
public class LayerHUD extends GUILayer {
|
public class LayerHUD extends GUILayer {
|
||||||
|
|
||||||
@ -43,6 +46,27 @@ public class LayerHUD extends GUILayer {
|
|||||||
setCursorPolicy(CursorPolicy.INDIFFERENT);
|
setCursorPolicy(CursorPolicy.INDIFFERENT);
|
||||||
|
|
||||||
manager.getClient().subscribe(this);
|
manager.getClient().subscribe(this);
|
||||||
|
|
||||||
|
getRoot().addKeyListener(new KeyMatcher("Escape"), e -> {
|
||||||
|
setInventoryShown(!showInventory);
|
||||||
|
e.consume();
|
||||||
|
}, InputBus.Option.IGNORE_FOCUS);
|
||||||
|
|
||||||
|
getRoot().addKeyListener(new KeyMatcher("E"), e -> {
|
||||||
|
setInventoryShown(!showInventory);
|
||||||
|
e.consume();
|
||||||
|
}, InputBus.Option.IGNORE_FOCUS);
|
||||||
|
|
||||||
|
getRoot().addKeyListener(new KeyMatcher("Left Control"), e -> {
|
||||||
|
TestPlayerControls.getInstance().getInventoryControls().switchHandsWithCtrl(e);
|
||||||
|
e.consume();
|
||||||
|
}, InputBus.Option.IGNORE_ACTION, InputBus.Option.IGNORE_FOCUS);
|
||||||
|
|
||||||
|
getRoot().addKeyListener(new KeyMatcher("Right Control"), e -> {
|
||||||
|
TestPlayerControls.getInstance().getInventoryControls().switchHandsWithCtrl(e);
|
||||||
|
e.consume();
|
||||||
|
}, InputBus.Option.IGNORE_ACTION, InputBus.Option.IGNORE_FOCUS);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
@ -105,12 +129,16 @@ public class LayerHUD extends GUILayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleInput(InputEvent e) {
|
public void handleInput(InputEvent event) {
|
||||||
if (isHidden) {
|
if (isHidden) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
super.handleInput(e);
|
super.handleInput(event);
|
||||||
|
|
||||||
|
if (getCursorPolicy() == CursorPolicy.REQUIRE) {
|
||||||
|
event.consume();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -57,16 +57,6 @@ public class InventoryControls {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
triggers.register(
|
|
||||||
ControlTriggers.localOf(
|
|
||||||
"Test:CloseInventory",
|
|
||||||
KeyEvent.class,
|
|
||||||
this::toggleInventory,
|
|
||||||
new KeyMatcher("Escape")::matches,
|
|
||||||
e -> ClientState.getInstance().getHUD().isInventoryShown()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
triggers.register(
|
triggers.register(
|
||||||
ControlTriggers.localOf(
|
ControlTriggers.localOf(
|
||||||
"Test:HideHUD",
|
"Test:HideHUD",
|
||||||
@ -103,7 +93,7 @@ public class InventoryControls {
|
|||||||
client.getHUD().setHidden(!client.getHUD().isHidden());
|
client.getHUD().setHidden(!client.getHUD().isHidden());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void switchHandsWithCtrl(KeyEvent event) {
|
public void switchHandsWithCtrl(KeyEvent event) {
|
||||||
int change = 0;
|
int change = 0;
|
||||||
|
|
||||||
if (event.isPress()) {
|
if (event.isPress()) {
|
||||||
|
@ -170,6 +170,18 @@ public class TestPlayerControls {
|
|||||||
return movementControls;
|
return movementControls;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CameraControls getCameraControls() {
|
||||||
|
return cameraControls;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InteractionControls getInteractionControls() {
|
||||||
|
return interactionControls;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InventoryControls getInventoryControls() {
|
||||||
|
return inventoryControls;
|
||||||
|
}
|
||||||
|
|
||||||
public BlockData getSelectedBlock() {
|
public BlockData getSelectedBlock() {
|
||||||
return interactionControls.getSelectedBlock();
|
return interactionControls.getSelectedBlock();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user