diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/InputSynchronizer.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/InputSynchronizer.java index ead89f62..a41f22d2 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/InputSynchronizer.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/InputSynchronizer.java @@ -96,8 +96,9 @@ else if(boardSelect != null) { } if(name.equals("Test") &&isPressed){ if(app.getView() instanceof GameView gameView){ + gameView.getGuiHandler().test2(); - gameView.getGuiHandler().showDice(); +// gameView.getGuiHandler().showDice(); // gameView.getBoardHandler().showDice(Color.AIRFORCE); } } diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/MdgaApp.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/MdgaApp.java index fd9a724d..13f426c1 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/MdgaApp.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/MdgaApp.java @@ -24,7 +24,7 @@ public class MdgaApp extends SimpleApplication { MdgaView view = null; private MdgaState state = MdgaState.GAME; - private static float resolutionFactor = 1.8f; + private static float resolutionFactor = 1.2f; public static void main(String[] args) { AppSettings settings = new AppSettings(true); diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/gui/ActionTextHandler.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/gui/ActionTextHandler.java index 82a41275..a86661db 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/gui/ActionTextHandler.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/gui/ActionTextHandler.java @@ -8,46 +8,110 @@ import com.jme3.scene.Node; import com.jme3.system.AppSettings; import pp.mdga.client.Asset; +import pp.mdga.game.Color; public class ActionTextHandler { private Node root; + private BitmapFont font; + private AppSettings appSettings; public ActionTextHandler(AppSettings appSettings, AssetManager assetManager, Node guiNode){ root = new Node("actionTextRoot"); guiNode.attachChild(root); root.setLocalTranslation(center(appSettings.getWidth(), appSettings.getHeight(), Vector3f.ZERO)); - BitmapFont playerFont = assetManager.loadFont("Fonts/Gunplay.fnt"); + font = assetManager.loadFont("Fonts/Gunplay.fnt"); + this.appSettings = appSettings; - root.attachChild(createTextWithSpacing(playerFont, "TEST", 20f, 250)); } - public static Node createTextWithSpacing(BitmapFont font, String text, float spacing, float size) { + private Node createTextWithSpacing(String[] textArr, float spacing, float size, ColorRGBA[] colorArr) { + if(textArr.length != colorArr.length) throw new RuntimeException("text and color are not the same length"); + Node textNode = new Node("TextWithSpacing"); Node center = new Node(); float xOffset = 0; + for(int i = 0; i < textArr.length; i++){ + String text = textArr[i]; + ColorRGBA color = colorArr[i]; + for (char c : text.toCharArray()) { + BitmapText letter = new BitmapText(font); + letter.setColor(color); + letter.setSize(size); + letter.setText(Character.toString(c)); + letter.setLocalTranslation(xOffset, letter.getHeight()/2, 0); + center.attachChild(letter); - for (char c : text.toCharArray()) { - BitmapText letter = new BitmapText(font); - letter.setSize(size); - letter.setText(Character.toString(c)); - letter.setLocalTranslation(xOffset, letter.getHeight()/2, 0); - center.attachChild(letter); - - xOffset += letter.getLineWidth() + spacing; + xOffset += letter.getLineWidth() + spacing; + } } + center.setLocalTranslation(new Vector3f(-xOffset/2,0,0)); textNode.attachChild(center); - return textNode; } + private Node createTextWithSpacing(String text, float spacing, float size, ColorRGBA color) { + return createTextWithSpacing(new String[]{text}, spacing, size, new ColorRGBA[]{color}); + } + private Vector3f center(float width, float height, Vector3f pos){ return new Vector3f(pos.x+width/2, pos.y+height/2,0); } + + private Node createTopText(String name, float spacing, float size, ColorRGBA color, float top){ + return createTopText(new String[]{name}, spacing, size, new ColorRGBA[]{color}, top); + } + + private Node createTopText(String[] name, float spacing, float size, ColorRGBA color[], float top){ + Node text = createTextWithSpacing(name, spacing, size, color); + text.setLocalTranslation(0, (appSettings.getHeight()/2f)*0.8f-top,0); + root.attachChild(text); + return text; + } + private Vector3f centerText(float width, float height, Vector3f pos){ return center(-width, height, pos); } + public void activePlayer(String name, Color color){ + createTopText(new String[]{name," ist dran!"}, 10,90,new ColorRGBA[]{playerColorToColorRGBA(color),ColorRGBA.White}, 0).addControl(new ZoomControl()); + } + + public void ownActive(Color color){ + createTopText(new String[]{"Du"," bist dran!"}, 10,90,new ColorRGBA[]{playerColorToColorRGBA(color),ColorRGBA.White}, 0).addControl(new ZoomControl()); + } + + public void diceNum(int diceNum, String name, Color color){ + createTopText(new String[]{name," würfelt:"}, 10,90,new ColorRGBA[]{playerColorToColorRGBA(color),ColorRGBA.White}, 0); + + createTopText(String.valueOf(diceNum), 10, 100, ColorRGBA.White, 100); + + } + + public void diceNumMult(int diceNum,int mult, String name, Color color){ + createTopText(new String[]{name," würfelt:"}, 10,90,new ColorRGBA[]{playerColorToColorRGBA(color),ColorRGBA.White}, 0); + + createTopText(new String[]{String.valueOf(diceNum), " x" + mult + " = " + (diceNum*mult)}, 20, 100, new ColorRGBA[]{ColorRGBA.White,ColorRGBA.Red}, 100); + } + + public void ownDice(int diceNum){ + createTopText(String.valueOf(diceNum), 10, 100, ColorRGBA.White, 0); + } + + public void ownDiceMult(int diceNum, int mult){ + createTopText(new String[]{String.valueOf(diceNum), " x" + mult + " = " + (diceNum*mult)}, 20, 100, new ColorRGBA[]{ColorRGBA.White,ColorRGBA.Red}, 0); + } + + private ColorRGBA playerColorToColorRGBA(Color color){ + return switch (color){ + case ARMY -> ColorRGBA.Green; + case NAVY -> ColorRGBA.Blue; + case CYBER -> ColorRGBA.Orange; + case AIRFORCE -> ColorRGBA.Black; + }; + } + + } 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 9393914b..16d726ad 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 @@ -41,6 +41,7 @@ public class GuiHandler { private Set selectableCards = new HashSet<>(); private BonusCard cardSelect = null; private PlayerNameHandler playerNameHandler; + private ActionTextHandler actionTextHandler; public GuiHandler(MdgaApp app, Texture2D backTexture) { this.app = app; @@ -59,7 +60,7 @@ public void init(){ diceControl.create(new Vector3f(0,0,0), 1f, false); playerNameHandler = new PlayerNameHandler(app.getGuiNode(), app.getAssetManager(), app.getContext().getSettings()); - new ActionTextHandler(app.getContext().getSettings(), app.getAssetManager(), app.getGuiNode()); + actionTextHandler = new ActionTextHandler(app.getContext().getSettings(), app.getAssetManager(), app.getGuiNode()); } @@ -261,8 +262,9 @@ public void turbo(){ SymbolControl control = createSymbol(Asset.turboSymbol); cardLayer.addSpatial(control.getSpatial()); control.turbo(); - } - + public void test2(){ + actionTextHandler.ownDiceMult(5,2); + } } 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 index 9d02cf48..91defbe6 100644 --- 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 @@ -80,14 +80,7 @@ private Spatial createColor(Color color) { 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, boolean first, boolean own){ BitmapText hudText = new BitmapText(playerFont); diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/gui/ZoomControl.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/gui/ZoomControl.java new file mode 100644 index 00000000..3494dac3 --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/gui/ZoomControl.java @@ -0,0 +1,77 @@ +package pp.mdga.client.gui; + +import com.jme3.renderer.RenderManager; +import com.jme3.renderer.ViewPort; +import com.jme3.scene.Spatial; +import com.jme3.scene.control.AbstractControl; + +public class ZoomControl extends AbstractControl { + private boolean zoomingIn = false; + private boolean zoomingOut = false; + private float progress = 0; + private float zoomSpeed = 1f; + private float zoomFactor = 1f; + + + @Override + public void setSpatial(Spatial spatial){ + if(this.spatial == null && spatial != null){ + super.setSpatial(spatial); + initSpatial(); + } + } + + private void initSpatial() { + zoomingIn = true; + } + + @Override + protected void controlUpdate(float tpf) { + if (zoomingIn) { + progress += tpf * zoomSpeed; + if (progress > 1) progress = 1; + spatial.setLocalScale(lerp(0, zoomFactor, easeOut(progress))); + if (progress >= 1) { + zoomingIn = false; + zoomingOut = true; + progress = 0; + } + } else if (zoomingOut) { + progress += tpf * zoomSpeed; + spatial.setLocalScale(lerp(zoomFactor, 0, easeIn(progress))); + if (progress > 1) { + zoomingOut = false; + end(); + } + } + } + + private void end(){ + spatial.removeFromParent(); + spatial.removeControl(this); + } + + @Override + protected void controlRender(RenderManager rm, ViewPort vp) { + + } + + private static float lerp(float start, float end, float t) { + return (1 - t) * start + t * end; + } + +// private static float easeOut(float t) { +// return (float) Math.sqrt(1 - Math.pow(t - 1, 2)); +// } +private float easeOut(float x) { + return x == 1 ? 1 : (float) (1 - Math.pow(2, -10 * x)); + + } +// private float easeIn(float t) { +// return t * t * t * t; +// } + private float easeIn(float x) { + return x == 0 ? 0 : (float) Math.pow(2, 10 * x - 10); + + } +}