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);
|
||||
public PermanentHUD(String name, LocalPlayer player) {
|
||||
super(name);
|
||||
setLayout(new LayoutBorderVertical());
|
||||
|
||||
client.subscribe(this);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
private void onEntityChanged(NewLocalEntityEvent e) {
|
||||
while (!getRoot().getChildren().isEmpty()) {
|
||||
getRoot().removeChild(getRoot().getChild(0));
|
||||
EntityDataPlayer entity = player.getEntity();
|
||||
if (entity == null) {
|
||||
throw new IllegalStateException("Player " + player + " does not have an associated entity");
|
||||
}
|
||||
|
||||
if (e.getNewEntity() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
@ -44,9 +43,11 @@ 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;
|
||||
@ -59,6 +60,7 @@ public class InventoryScreen extends Component {
|
||||
public InventoryScreen(String name, InventoryComponent mainInventory, EntityDataPlayer player) {
|
||||
super(name);
|
||||
|
||||
isLeftHandSelected = false;
|
||||
this.mainInventory = mainInventory;
|
||||
this.leftHand = player.getLeftHand();
|
||||
this.rightHand = player.getRightHand();
|
||||
@ -79,6 +81,23 @@ public class InventoryScreen extends Component {
|
||||
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) {
|
||||
@ -186,7 +205,6 @@ public class InventoryScreen extends Component {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
private InputListener<WheelScrollEvent> createWheelAction(ItemSlot invSlot, Supplier<ItemSlot> handSlotChooser) {
|
||||
return input -> {
|
||||
|
||||
|
Reference in New Issue
Block a user