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:
OLEGSHA 2021-09-04 17:12:54 +03:00
parent 4749be6c60
commit 73ee339dcc
Signed by: OLEGSHA
GPG Key ID: E57A4B08D64AFF7A
5 changed files with 120 additions and 69 deletions

View File

@ -20,8 +20,8 @@ package ru.windcorp.progressia.client;
import ru.windcorp.progressia.client.comms.localhost.LocalServerCommsChannel; import ru.windcorp.progressia.client.comms.localhost.LocalServerCommsChannel;
import ru.windcorp.progressia.client.graphics.GUI; 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.LayerWorld;
import ru.windcorp.progressia.client.graphics.world.hud.LayerHUD;
import ru.windcorp.progressia.common.world.DefaultWorldData; import ru.windcorp.progressia.common.world.DefaultWorldData;
import ru.windcorp.progressia.server.ServerState; import ru.windcorp.progressia.server.ServerState;
import ru.windcorp.progressia.test.LayerAbout; import ru.windcorp.progressia.test.LayerAbout;

View File

@ -83,8 +83,8 @@ public class LocalPlayer {
} }
if (playerEntity != lastKnownEntity) { if (playerEntity != lastKnownEntity) {
getClient().postEvent(new NewLocalEntityEvent.Immutable(getClient(), playerEntity, lastKnownEntity));
this.lastKnownEntity = playerEntity; this.lastKnownEntity = playerEntity;
getClient().postEvent(new NewLocalEntityEvent.Immutable(getClient(), playerEntity, lastKnownEntity));
} }
return playerEntity; return playerEntity;

View File

@ -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();
}
}

View File

@ -15,55 +15,38 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * 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.Component;
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.LayoutBorderHorizontal; 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.LayoutBorderVertical;
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutFill;
import ru.windcorp.progressia.client.graphics.texture.SimpleTextures; 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; import ru.windcorp.progressia.test.inv.SlotComponent;
public class LayerHUD extends GUILayer { public class PermanentHUD extends Component {
public LayerHUD(Client client) { public PermanentHUD(String name, LocalPlayer player) {
super("LayerHUD", new LayoutFill(15)); super(name);
setCursorPolicy(CursorPolicy.INDIFFERENT); setLayout(new LayoutBorderVertical());
client.subscribe(this); EntityDataPlayer entity = player.getEntity();
} if (entity == null) {
throw new IllegalStateException("Player " + player + " does not have an associated entity");
@Subscribe
private void onEntityChanged(NewLocalEntityEvent e) {
while (!getRoot().getChildren().isEmpty()) {
getRoot().removeChild(getRoot().getChild(0));
} }
if (e.getNewEntity() == null) {
return;
}
Component content = new Group(getName() + ".Content", new LayoutBorderVertical());
Group handDisplays = new Group( Group handDisplays = new Group(
getName() + ".Hands", getName() + ".Hands",
new LayoutBorderHorizontal(), 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), .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) .setBackground(SimpleTextures.get("gui/RightHand")).setScale(4).setLayoutHint(LayoutBorderHorizontal.RIGHT)
); );
content.addChild(handDisplays.setLayoutHint(LayoutBorderVertical.UP)); addChild(handDisplays.setLayoutHint(LayoutBorderVertical.UP));
getRoot().addChild(content);
getRoot().requestReassembly();
} }
} }

View File

@ -24,7 +24,6 @@ import org.lwjgl.glfw.GLFW;
import ru.windcorp.progressia.client.graphics.Colors; import ru.windcorp.progressia.client.graphics.Colors;
import ru.windcorp.progressia.client.graphics.backend.GraphicsInterface; 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.BasicButton;
import ru.windcorp.progressia.client.graphics.gui.Component; import ru.windcorp.progressia.client.graphics.gui.Component;
import ru.windcorp.progressia.client.graphics.gui.Components; 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 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() { public static boolean isLeftHandSelected() {
return InputTracker.isKeyPressed(GLFW.GLFW_KEY_LEFT_CONTROL) return isLeftHandSelected;
|| InputTracker.isKeyPressed(GLFW.GLFW_KEY_RIGHT_CONTROL);
} }
private final ItemContainer leftHand; private final ItemContainer leftHand;
@ -59,6 +60,7 @@ public class InventoryScreen extends Component {
public InventoryScreen(String name, InventoryComponent mainInventory, EntityDataPlayer player) { public InventoryScreen(String name, InventoryComponent mainInventory, EntityDataPlayer player) {
super(name); super(name);
isLeftHandSelected = false;
this.mainInventory = mainInventory; this.mainInventory = mainInventory;
this.leftHand = player.getLeftHand(); this.leftHand = player.getLeftHand();
this.rightHand = player.getRightHand(); this.rightHand = player.getRightHand();
@ -79,6 +81,23 @@ public class InventoryScreen extends Component {
addListeners(mainInventory); addListeners(mainInventory);
mainInventory.focusNext(); 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) { private void addListeners(InventoryComponent mainInventory) {
@ -186,7 +205,6 @@ public class InventoryScreen extends Component {
}; };
} }
private InputListener<WheelScrollEvent> createWheelAction(ItemSlot invSlot, Supplier<ItemSlot> handSlotChooser) { private InputListener<WheelScrollEvent> createWheelAction(ItemSlot invSlot, Supplier<ItemSlot> handSlotChooser) {
return input -> { return input -> {