mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-09 07:20:04 -04:00
debugUI: entity list
This commit is contained in:
parent
10e5a70515
commit
10d2cfe261
55
src/main/java/de/bixilon/minosoft/debug/UIEntity.java
Normal file
55
src/main/java/de/bixilon/minosoft/debug/UIEntity.java
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Codename Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* 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/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.debug;
|
||||
|
||||
import de.bixilon.minosoft.game.datatypes.entities.Entity;
|
||||
import de.bixilon.minosoft.game.datatypes.entities.EntityObject;
|
||||
import de.bixilon.minosoft.game.datatypes.entities.Mob;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class UIEntity {
|
||||
static HashMap<Integer, UIEntity> entityHashMap;
|
||||
final int id;
|
||||
final Entity entity;
|
||||
|
||||
public UIEntity(int id, Entity entity) {
|
||||
if (entityHashMap == null) {
|
||||
entityHashMap = new HashMap<>();
|
||||
}
|
||||
this.id = id;
|
||||
this.entity = entity;
|
||||
entityHashMap.put(id, this);
|
||||
}
|
||||
|
||||
public static UIEntity getByID(int id) {
|
||||
return entityHashMap.get(id);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Entity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (entity instanceof Mob) {
|
||||
return String.format("%d (%s)", id, ((Mob) entity).getEntityType().name());
|
||||
}
|
||||
return String.format("%d (%s)", id, ((EntityObject) entity).getEntityType().name());
|
||||
}
|
||||
}
|
@ -13,9 +13,12 @@
|
||||
|
||||
package de.bixilon.minosoft.debug.handling;
|
||||
|
||||
import de.bixilon.minosoft.debug.UIEntity;
|
||||
import de.bixilon.minosoft.debug.gui.DebugMainWindow;
|
||||
import de.bixilon.minosoft.game.datatypes.TextComponent;
|
||||
import de.bixilon.minosoft.game.datatypes.entities.Entity;
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.scene.text.TextFlow;
|
||||
|
||||
@ -24,13 +27,12 @@ import java.util.List;
|
||||
|
||||
public class DebugUIHandler {
|
||||
List<TextComponent> toPrint = new ArrayList<>();
|
||||
List<UIEntity> entities = new ArrayList<>();
|
||||
|
||||
public void printText(TextComponent component) {
|
||||
if (DebugMainWindow.isInitialized()) {
|
||||
TextFlow chat = ((TextFlow) DebugMainWindow.getStage().getScene().lookup("#chat"));
|
||||
Platform.runLater(
|
||||
() -> chat.getChildren().add(new Text(component.getRawMessage() + "\n"))
|
||||
);
|
||||
Platform.runLater(() -> chat.getChildren().add(new Text(component.getRawMessage() + "\n")));
|
||||
} else {
|
||||
toPrint.add(component);
|
||||
}
|
||||
@ -50,5 +52,42 @@ public class DebugUIHandler {
|
||||
|
||||
public void initializedCallback() {
|
||||
printTextLeft();
|
||||
printEntitiesLeft();
|
||||
}
|
||||
|
||||
public void addEntity(Entity entity) {
|
||||
UIEntity uiEntity = new UIEntity(entity.getId(), entity);
|
||||
if (DebugMainWindow.isInitialized()) {
|
||||
ListView<UIEntity> entityList = (ListView<UIEntity>) DebugMainWindow.getStage().getScene().lookup("#entityList");
|
||||
Platform.runLater(() -> entityList.getItems().add(uiEntity));
|
||||
} else {
|
||||
entities.add(uiEntity);
|
||||
}
|
||||
}
|
||||
|
||||
private void removeEntity(int id) {
|
||||
if (DebugMainWindow.isInitialized()) {
|
||||
ListView<UIEntity> entityList = (ListView<UIEntity>) DebugMainWindow.getStage().getScene().lookup("#entityList");
|
||||
Platform.runLater(() -> entityList.getItems().remove(UIEntity.getByID(id)));
|
||||
} else {
|
||||
entities.remove(UIEntity.getByID(id));
|
||||
}
|
||||
}
|
||||
|
||||
public void printEntitiesLeft() {
|
||||
ListView<UIEntity> entityList = (ListView<UIEntity>) DebugMainWindow.getStage().getScene().lookup("#entityList");
|
||||
if (entities != null && entities.size() > 0) {
|
||||
// append here
|
||||
for (UIEntity entity : entities) {
|
||||
Platform.runLater(() -> entityList.getItems().add(entity));
|
||||
}
|
||||
entities.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void removeEntities(int[] entityIds) {
|
||||
for (int id : entityIds) {
|
||||
removeEntity(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,9 @@ package de.bixilon.minosoft.debug.handling;
|
||||
|
||||
import de.bixilon.minosoft.debug.DebugWindow;
|
||||
import de.bixilon.minosoft.protocol.packets.clientbound.play.PacketChatMessage;
|
||||
import de.bixilon.minosoft.protocol.packets.clientbound.play.PacketDestroyEntity;
|
||||
import de.bixilon.minosoft.protocol.packets.clientbound.play.PacketSpawnMob;
|
||||
import de.bixilon.minosoft.protocol.packets.clientbound.play.PacketSpawnObject;
|
||||
import de.bixilon.minosoft.protocol.protocol.PacketHandler;
|
||||
|
||||
public class DebugUIPacketHandler extends PacketHandler {
|
||||
@ -29,4 +32,19 @@ public class DebugUIPacketHandler extends PacketHandler {
|
||||
window.getUIHandler().printText(pkg.getTextComponent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(PacketSpawnMob pkg) {
|
||||
window.getUIHandler().addEntity(pkg.getMob());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(PacketSpawnObject pkg) {
|
||||
window.getUIHandler().addEntity(pkg.getObject());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(PacketDestroyEntity pkg) {
|
||||
window.getUIHandler().removeEntities(pkg.getEntityIds());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.control.ScrollPane?>
|
||||
<?import javafx.scene.control.Tab?>
|
||||
<?import javafx.scene.control.TabPane?>
|
||||
<?import javafx.scene.control.TextField?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
<?import javafx.scene.text.Text?>
|
||||
@ -22,6 +19,17 @@
|
||||
AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"/>
|
||||
</AnchorPane>
|
||||
</Tab>
|
||||
<Tab text="Entities">
|
||||
<content>
|
||||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
|
||||
<children>
|
||||
<ListView id="entityList" layoutX="14.0" layoutY="14.0" prefHeight="200.0" prefWidth="200.0"
|
||||
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
|
||||
AnchorPane.topAnchor="0.0"/>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</content>
|
||||
</Tab>
|
||||
</TabPane>
|
||||
<AnchorPane prefHeight="20.0" prefWidth="640.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
|
||||
AnchorPane.rightAnchor="0.0">
|
||||
|
Loading…
x
Reference in New Issue
Block a user