diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/gui/GuiHandler.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/gui/GuiHandler.java index 1691a526..3bea99fc 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/gui/GuiHandler.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/gui/GuiHandler.java @@ -26,10 +26,7 @@ public class GuiHandler { private Map uuidBonusCardMap; private Map bonusCardControlMap; private Map bonusCardIntegerMap; - private BitmapFont playerFont; - private Node playerNameNode; - private List playerOrder; - Map colorNameMap; + private static final Vector3f START = new Vector3f(-1.8f,-3.5f,0); private static final Vector3f MARGIN = new Vector3f(1.8f,0,0); @@ -41,6 +38,7 @@ public class GuiHandler { private Set selectableCards = new HashSet<>(); private BonusCard cardSelect = null; + private PlayerNameHandler playerNameHandler; public GuiHandler(MdgaApp app, Texture2D backTexture) { this.app = app; @@ -55,12 +53,8 @@ public GuiHandler(MdgaApp app, Texture2D backTexture) { public void init(){ cardLayer = new CardLayer(fpp, cardLayerCamera, backTexture); app.getStateManager().attach(cardLayer); - playerFont = app.getAssetManager().loadFont("Fonts/Gunplay.fnt"); - playerNameNode = new Node("player name node"); - app.getGuiNode().attachChild(playerNameNode); - playerOrder = new ArrayList<>(); - colorNameMap = new HashMap<>(); diceControl = createDice(); + playerNameHandler = new PlayerNameHandler(app.getGuiNode(), app.getAssetManager(), app.getContext().getSettings()); } @@ -145,58 +139,12 @@ private CardControl createCard(Asset card, Vector3f pos){ return control; } - private void drawPlayers(){ - playerNameNode.detachAllChildren(); - - float paddingTop = 10; - float paddingLeft = 15; - float margin = 35; - - for(int i = 0; i < playerOrder.size(); i++) { - Color color = playerOrder.get(i); - if(!colorNameMap.containsKey(color)) throw new RuntimeException(color + " isn't mapped to a name"); - - String name = colorNameMap.get(color); - renderName(name, paddingTop + margin * i, paddingLeft, i == 0); - } - } - - private void renderName(String name, float paddingTop, float paddingLeft, boolean first){ - BitmapText hudText = new BitmapText(playerFont); - //renderedSize = 45 - hudText.setSize(28); - hudText.setColor(first ? ColorRGBA.Blue : ColorRGBA.White); - hudText.setText(name); - int screenHeight = app.getContext().getSettings().getHeight(); - hudText.setLocalTranslation(paddingLeft, screenHeight - paddingTop, 0); - playerNameNode.attachChild(hudText); - } - - public void setPlayers(List names, List colors){ - if(names.size() != colors.size()) throw new RuntimeException("names and colors are not the same size"); - - for(int i = 0; i < names.size(); i++){ - colorNameMap.put(colors.get(i), names.get(i)); - } - - this.playerOrder = new ArrayList<>(colors); - - drawPlayers(); - } - public void addPlayer(Color color, String name){ - colorNameMap.put(color, name); - playerOrder.add(color); - drawPlayers(); + playerNameHandler.addPlayer(color, name); } public void setActivePlayer(Color color){ - Color lastFirst = playerOrder.remove(0); - playerOrder.remove(color); - playerOrder.add(0,color); - playerOrder.add(lastFirst); - - drawPlayers(); + playerNameHandler.setActivePlayer(color); } private Camera createOverlayCam(){ diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/gui/PlayerNameHandler.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/gui/PlayerNameHandler.java new file mode 100644 index 00000000..1c1e7728 --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/gui/PlayerNameHandler.java @@ -0,0 +1,115 @@ +package pp.mdga.client.gui; + +import com.jme3.asset.AssetManager; +import com.jme3.font.BitmapFont; +import com.jme3.font.BitmapText; +import com.jme3.material.Material; +import com.jme3.math.ColorRGBA; +import com.jme3.scene.Geometry; +import com.jme3.scene.Node; +import com.jme3.scene.Spatial; +import com.jme3.scene.shape.Sphere; +import com.jme3.system.AppSettings; +import com.jme3.ui.Picture; +import pp.mdga.client.Asset; +import pp.mdga.game.Color; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static com.jme3.material.Materials.UNSHADED; + +public class PlayerNameHandler { + private final BitmapFont playerFont; + private final Node playerNameNode; + private final List playerOrder; + private final Map colorNameMap; + private final AppSettings appSettings; + private final AssetManager assetManager; + + public PlayerNameHandler(Node guiNode, AssetManager assetManager, AppSettings appSettings){ + playerFont = assetManager.loadFont("Fonts/Gunplay.fnt"); + playerNameNode = new Node("player name node"); + playerOrder = new ArrayList<>(); + colorNameMap = new HashMap<>(); + guiNode.attachChild(playerNameNode); + this.appSettings = appSettings; + this.assetManager = assetManager; + } + + private void drawPlayers(){ + playerNameNode.detachAllChildren(); + + float paddingTop = 50; + float paddingLeft = 30; + float margin = 60; + + for(int i = 0; i < playerOrder.size(); i++) { + Color color = playerOrder.get(i); + if(!colorNameMap.containsKey(color)) throw new RuntimeException(color + " isn't mapped to a name"); + + Node nameParent = new Node("nameParent"); + nameParent.attachChild(createName(colorNameMap.get(color), paddingLeft, i == 0)); + nameParent.attachChild(createColor(color)); + nameParent.setLocalTranslation(50,appSettings.getWindowHeight()-paddingTop-margin*i,0); + playerNameNode.attachChild(nameParent); + } + } + + private String imagePath(Color color){ + String root = "./Images/name_pictures/"; + return switch(color){ + case ARMY -> root+"HEER_IMAGE.png"; + case NAVY -> root+"MARINE_IMAGE.png"; + case CYBER -> root+"CIR_IMAGE.png"; + case AIRFORCE -> root+"LW_IMAGE.png"; + }; + } + + private Spatial createColor(Color color) { + Picture pic = new Picture("HUD Picture"); + pic.setImage(assetManager, imagePath(color), true); + pic.setWidth(50); + pic.setHeight(50); + pic.setPosition(-pic.getWidth()/2,-pic.getHeight()/2); + return pic; + } + + private ColorRGBA playerColorToColorRGBA(Color color){ + return switch (color){ + case ARMY -> ColorRGBA.Green; + case NAVY -> ColorRGBA.Blue; + case CYBER -> ColorRGBA.Orange; + case AIRFORCE -> ColorRGBA.Black; + }; + } + + private Spatial createName(String name, float paddingLeft, boolean first){ + BitmapText hudText = new BitmapText(playerFont); + //renderedSize = 45 + hudText.setSize(28); + hudText.setColor(first ? ColorRGBA.Blue : ColorRGBA.White); + hudText.setText(name); + hudText.setLocalTranslation(paddingLeft,hudText.getHeight()/2, 0); + return hudText; + } + + public void addPlayer(Color color, String name){ + colorNameMap.put(color, name); + playerOrder.add(color); + drawPlayers(); + } + + public void setActivePlayer(Color color) { + Color lastFirst = playerOrder.remove(0); + playerOrder.remove(color); + playerOrder.add(0, color); + playerOrder.add(lastFirst); + + drawPlayers(); + } + + +} diff --git a/Projekte/mdga/client/src/main/resources/Images/name_pictures/CIR_IMAGE.png b/Projekte/mdga/client/src/main/resources/Images/name_pictures/CIR_IMAGE.png new file mode 100644 index 00000000..3e031506 Binary files /dev/null and b/Projekte/mdga/client/src/main/resources/Images/name_pictures/CIR_IMAGE.png differ diff --git a/Projekte/mdga/client/src/main/resources/Images/name_pictures/HEER_IMAGE.png b/Projekte/mdga/client/src/main/resources/Images/name_pictures/HEER_IMAGE.png new file mode 100644 index 00000000..67f03766 Binary files /dev/null and b/Projekte/mdga/client/src/main/resources/Images/name_pictures/HEER_IMAGE.png differ diff --git a/Projekte/mdga/client/src/main/resources/Images/name_pictures/LW_IMAGE.png b/Projekte/mdga/client/src/main/resources/Images/name_pictures/LW_IMAGE.png new file mode 100644 index 00000000..50ff2980 Binary files /dev/null and b/Projekte/mdga/client/src/main/resources/Images/name_pictures/LW_IMAGE.png differ diff --git a/Projekte/mdga/client/src/main/resources/Images/name_pictures/MARINE_IMAGE.png b/Projekte/mdga/client/src/main/resources/Images/name_pictures/MARINE_IMAGE.png new file mode 100644 index 00000000..be93ff8b Binary files /dev/null and b/Projekte/mdga/client/src/main/resources/Images/name_pictures/MARINE_IMAGE.png differ