Working toward player species? I think?
- Left/right hand can now be permanently switched by tapping ctrl - Moved LayerHUD into .hud subpackage - Extracted PermanentHUD out of LayerHUD - Fixed the issuer of NewLocalEntityEvent
This commit is contained in:
parent
4749be6c60
commit
73ee339dcc
@ -20,8 +20,8 @@ package ru.windcorp.progressia.client;
|
||||
|
||||
import ru.windcorp.progressia.client.comms.localhost.LocalServerCommsChannel;
|
||||
import ru.windcorp.progressia.client.graphics.GUI;
|
||||
import ru.windcorp.progressia.client.graphics.world.LayerHUD;
|
||||
import ru.windcorp.progressia.client.graphics.world.LayerWorld;
|
||||
import ru.windcorp.progressia.client.graphics.world.hud.LayerHUD;
|
||||
import ru.windcorp.progressia.common.world.DefaultWorldData;
|
||||
import ru.windcorp.progressia.server.ServerState;
|
||||
import ru.windcorp.progressia.test.LayerAbout;
|
||||
|
@ -83,8 +83,8 @@ public class LocalPlayer {
|
||||
}
|
||||
|
||||
if (playerEntity != lastKnownEntity) {
|
||||
getClient().postEvent(new NewLocalEntityEvent.Immutable(getClient(), playerEntity, lastKnownEntity));
|
||||
this.lastKnownEntity = playerEntity;
|
||||
getClient().postEvent(new NewLocalEntityEvent.Immutable(getClient(), playerEntity, lastKnownEntity));
|
||||
}
|
||||
|
||||
return playerEntity;
|
||||
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package ru.windcorp.progressia.client.graphics.world.hud;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
|
||||
import ru.windcorp.progressia.client.Client;
|
||||
import ru.windcorp.progressia.client.events.NewLocalEntityEvent;
|
||||
import ru.windcorp.progressia.client.graphics.gui.GUILayer;
|
||||
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutFill;
|
||||
|
||||
public class LayerHUD extends GUILayer {
|
||||
|
||||
public LayerHUD(Client client) {
|
||||
super("LayerHUD", new LayoutFill(15));
|
||||
setCursorPolicy(CursorPolicy.INDIFFERENT);
|
||||
|
||||
client.subscribe(this);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
private void onEntityChanged(NewLocalEntityEvent e) {
|
||||
while (!getRoot().getChildren().isEmpty()) {
|
||||
getRoot().removeChild(getRoot().getChild(0));
|
||||
}
|
||||
|
||||
if (e.getNewEntity() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
getRoot().addChild(new PermanentHUD(getName(), e.getClient().getLocalPlayer()));
|
||||
getRoot().requestReassembly();
|
||||
}
|
||||
|
||||
}
|
@ -15,55 +15,38 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package ru.windcorp.progressia.client.graphics.world;
|
||||
package ru.windcorp.progressia.client.graphics.world.hud;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
|
||||
import ru.windcorp.progressia.client.Client;
|
||||
import ru.windcorp.progressia.client.events.NewLocalEntityEvent;
|
||||
import ru.windcorp.progressia.client.graphics.gui.Component;
|
||||
import ru.windcorp.progressia.client.graphics.gui.GUILayer;
|
||||
import ru.windcorp.progressia.client.graphics.gui.Group;
|
||||
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutBorderHorizontal;
|
||||
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutBorderVertical;
|
||||
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutFill;
|
||||
import ru.windcorp.progressia.client.graphics.texture.SimpleTextures;
|
||||
import ru.windcorp.progressia.client.graphics.world.LocalPlayer;
|
||||
import ru.windcorp.progressia.common.world.entity.EntityDataPlayer;
|
||||
import ru.windcorp.progressia.test.inv.SlotComponent;
|
||||
|
||||
public class LayerHUD extends GUILayer {
|
||||
public class PermanentHUD extends Component {
|
||||
|
||||
public LayerHUD(Client client) {
|
||||
super("LayerHUD", new LayoutFill(15));
|
||||
setCursorPolicy(CursorPolicy.INDIFFERENT);
|
||||
|
||||
client.subscribe(this);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
private void onEntityChanged(NewLocalEntityEvent e) {
|
||||
while (!getRoot().getChildren().isEmpty()) {
|
||||
getRoot().removeChild(getRoot().getChild(0));
|
||||
}
|
||||
public PermanentHUD(String name, LocalPlayer player) {
|
||||
super(name);
|
||||
setLayout(new LayoutBorderVertical());
|
||||
|
||||
if (e.getNewEntity() == null) {
|
||||
return;
|
||||
EntityDataPlayer entity = player.getEntity();
|
||||
if (entity == null) {
|
||||
throw new IllegalStateException("Player " + player + " does not have an associated entity");
|
||||
}
|
||||
|
||||
Component content = new Group(getName() + ".Content", new LayoutBorderVertical());
|
||||
|
||||
Group handDisplays = new Group(
|
||||
getName() + ".Hands",
|
||||
new LayoutBorderHorizontal(),
|
||||
new SlotComponent(getName() + ".Hands.LeftHand", e.getNewEntity().getLeftHand(), 0)
|
||||
new SlotComponent(getName() + ".Hands.LeftHand", entity.getLeftHand(), 0)
|
||||
.setBackground(SimpleTextures.get("gui/LeftHand")).setScale(4).setLayoutHint(LayoutBorderHorizontal.LEFT),
|
||||
new SlotComponent(getName() + ".Hands.RightHand", e.getNewEntity().getRightHand(), 0)
|
||||
new SlotComponent(getName() + ".Hands.RightHand", entity.getRightHand(), 0)
|
||||
.setBackground(SimpleTextures.get("gui/RightHand")).setScale(4).setLayoutHint(LayoutBorderHorizontal.RIGHT)
|
||||
);
|
||||
|
||||
content.addChild(handDisplays.setLayoutHint(LayoutBorderVertical.UP));
|
||||
|
||||
getRoot().addChild(content);
|
||||
getRoot().requestReassembly();
|
||||
addChild(handDisplays.setLayoutHint(LayoutBorderVertical.UP));
|
||||
}
|
||||
|
||||
}
|
@ -24,7 +24,6 @@ import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import ru.windcorp.progressia.client.graphics.Colors;
|
||||
import ru.windcorp.progressia.client.graphics.backend.GraphicsInterface;
|
||||
import ru.windcorp.progressia.client.graphics.backend.InputTracker;
|
||||
import ru.windcorp.progressia.client.graphics.gui.BasicButton;
|
||||
import ru.windcorp.progressia.client.graphics.gui.Component;
|
||||
import ru.windcorp.progressia.client.graphics.gui.Components;
|
||||
@ -41,24 +40,27 @@ import ru.windcorp.progressia.common.world.item.ItemSlot;
|
||||
import ru.windcorp.progressia.common.world.item.Items;
|
||||
|
||||
public class InventoryScreen extends Component {
|
||||
|
||||
|
||||
private static final double MIN_PICK_ALL_DELAY = Units.get("0.5 s");
|
||||
|
||||
private static boolean isLeftHandSelected = false;
|
||||
private static double controlStart = Double.NEGATIVE_INFINITY;
|
||||
|
||||
public static boolean isLeftHandSelected() {
|
||||
return InputTracker.isKeyPressed(GLFW.GLFW_KEY_LEFT_CONTROL)
|
||||
|| InputTracker.isKeyPressed(GLFW.GLFW_KEY_RIGHT_CONTROL);
|
||||
return isLeftHandSelected;
|
||||
}
|
||||
|
||||
private final ItemContainer leftHand;
|
||||
private final ItemContainer rightHand;
|
||||
private final InventoryComponent mainInventory;
|
||||
|
||||
|
||||
private double lastLeftClick = Double.NEGATIVE_INFINITY;
|
||||
private ItemSlot lastLeftClickSlot = null;
|
||||
|
||||
public InventoryScreen(String name, InventoryComponent mainInventory, EntityDataPlayer player) {
|
||||
super(name);
|
||||
|
||||
isLeftHandSelected = false;
|
||||
this.mainInventory = mainInventory;
|
||||
this.leftHand = player.getLeftHand();
|
||||
this.rightHand = player.getRightHand();
|
||||
@ -73,21 +75,38 @@ public class InventoryScreen extends Component {
|
||||
|
||||
SlotComponent leftComponent = new SlotComponent(name + ".HandLeft", leftHand, 0);
|
||||
SlotComponent rightComponent = new SlotComponent(name + ".HandRight", rightHand, 0);
|
||||
|
||||
|
||||
addChild(new HandSlots(name + ".Hands", leftComponent, rightComponent));
|
||||
|
||||
addListeners(mainInventory);
|
||||
|
||||
|
||||
mainInventory.focusNext();
|
||||
mainInventory.addListener(KeyEvent.class, input -> {
|
||||
if (input.getKey() == GLFW.GLFW_KEY_LEFT_CONTROL || input.getKey() == GLFW.GLFW_KEY_RIGHT_CONTROL) {
|
||||
double now = GraphicsInterface.getTime();
|
||||
if (input.isPress()) {
|
||||
isLeftHandSelected = !isLeftHandSelected;
|
||||
controlStart = now;
|
||||
} else if (input.isRelease()) {
|
||||
if (now - controlStart > Units.get("200 ms")) {
|
||||
isLeftHandSelected = !isLeftHandSelected;
|
||||
controlStart = Double.NEGATIVE_INFINITY;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
private void addListeners(InventoryComponent mainInventory) {
|
||||
|
||||
|
||||
ItemSlot left = leftHand.getSlot(0);
|
||||
ItemSlot right = rightHand.getSlot(0);
|
||||
|
||||
|
||||
Supplier<ItemSlot> handSlot = () -> isLeftHandSelected() ? left : right;
|
||||
|
||||
|
||||
Consumer<BasicButton> pickAll = createPickAllAction(handSlot);
|
||||
|
||||
for (DecoratedSlotComponent component : mainInventory.getSlots()) {
|
||||
@ -99,39 +118,39 @@ public class InventoryScreen extends Component {
|
||||
|
||||
private Consumer<BasicButton> createPickAllAction(Supplier<ItemSlot> handSlotChooser) {
|
||||
return button -> {
|
||||
|
||||
|
||||
ItemSlot handSlot = handSlotChooser.get();
|
||||
ItemSlot invSlot = ((DecoratedSlotComponent) button).getSlot();
|
||||
|
||||
|
||||
boolean success = false;
|
||||
|
||||
|
||||
double now = GraphicsInterface.getTime();
|
||||
if (lastLeftClickSlot == invSlot && now - lastLeftClick < MIN_PICK_ALL_DELAY) {
|
||||
|
||||
|
||||
lastLeftClickSlot = null;
|
||||
lastLeftClick = Double.NEGATIVE_INFINITY;
|
||||
|
||||
|
||||
pickAll(handSlot);
|
||||
|
||||
|
||||
success = true;
|
||||
|
||||
|
||||
} else {
|
||||
lastLeftClick = now;
|
||||
lastLeftClickSlot = invSlot;
|
||||
}
|
||||
|
||||
|
||||
if (!success && !leftHand.getSlot(0).isEmpty() && rightHand.getSlot(0).isEmpty()) {
|
||||
success = Items.pour(leftHand.getSlot(0), invSlot) != 0;
|
||||
}
|
||||
|
||||
|
||||
if (!success) {
|
||||
success = Items.pour(handSlot, invSlot) != 0;
|
||||
}
|
||||
|
||||
|
||||
if (!success) {
|
||||
success = Items.swap(handSlot, invSlot);
|
||||
}
|
||||
|
||||
|
||||
if (!success && handSlot.isEmpty()) {
|
||||
success = Items.pour(invSlot, handSlot) != 0;
|
||||
}
|
||||
@ -145,31 +164,31 @@ public class InventoryScreen extends Component {
|
||||
|
||||
private void pickAll(ItemSlot handSlot) {
|
||||
for (DecoratedSlotComponent component : mainInventory.getSlots()) {
|
||||
|
||||
|
||||
Items.pour(component.getSlot(), handSlot);
|
||||
if (handSlot.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private InputListener<KeyEvent> createRMBAction(ItemSlot invSlot, Supplier<ItemSlot> handSlotChooser) {
|
||||
return input -> {
|
||||
|
||||
|
||||
if (input.isPress() && input.isRightMouseButton()) {
|
||||
ItemSlot handSlot = handSlotChooser.get();
|
||||
|
||||
boolean success = false;
|
||||
|
||||
|
||||
if (handSlot.isEmpty()) {
|
||||
success = Items.pour(invSlot, handSlot, invSlot.getAmount() / 2) != 0;
|
||||
}
|
||||
|
||||
|
||||
if (!success) {
|
||||
success = Items.pour(handSlot, invSlot, 1) != 0;
|
||||
}
|
||||
|
||||
|
||||
if (!success) {
|
||||
success = Items.swap(handSlot, invSlot);
|
||||
}
|
||||
@ -177,34 +196,33 @@ public class InventoryScreen extends Component {
|
||||
if (success) {
|
||||
requestReassembly();
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
private InputListener<WheelScrollEvent> createWheelAction(ItemSlot invSlot, Supplier<ItemSlot> handSlotChooser) {
|
||||
return input -> {
|
||||
|
||||
|
||||
if (!input.hasVerticalMovement()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
ItemSlot handSlot = handSlotChooser.get();
|
||||
|
||||
|
||||
ItemSlot from = input.isDown() ? handSlot : invSlot;
|
||||
ItemSlot into = input.isDown() ? invSlot : handSlot;
|
||||
|
||||
|
||||
if (Items.pour(from, into, 1) != 0) {
|
||||
requestReassembly();
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user