added highlight to bonuscards
This commit is contained in:
		@@ -28,7 +28,7 @@ public enum Asset {
 | 
			
		||||
    tree_small("Models/tree_small/tree_small.obj", "Models/tree_small/tree_small_diff.png"),
 | 
			
		||||
    tree_big("Models/tree_big/tree_big.obj", "Models/tree_big/tree_big_diff.png"),
 | 
			
		||||
    turboCard,
 | 
			
		||||
    swapCard,
 | 
			
		||||
    swapCard("Models/swapCard/swapCard.obj", "Models/swapCard/swapCard_diff.png"),
 | 
			
		||||
    shieldCard,
 | 
			
		||||
    dice("Models/dice/dice.obj", "Models/dice/dice_diff.jpeg")
 | 
			
		||||
    ;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
package pp.mdga.client;
 | 
			
		||||
 | 
			
		||||
import com.jme3.collision.CollisionResult;
 | 
			
		||||
import com.jme3.collision.CollisionResults;
 | 
			
		||||
import com.jme3.input.InputManager;
 | 
			
		||||
import com.jme3.input.KeyInput;
 | 
			
		||||
@@ -74,15 +75,15 @@ public void onAction(String name, boolean isPressed, float tpf) {
 | 
			
		||||
 | 
			
		||||
                    if(cardLayerSelect != null) {
 | 
			
		||||
                        //cardSelect
 | 
			
		||||
                        cardLayerSelect.outline();
 | 
			
		||||
                        if(cardLayerSelect.isSelectable()) gameView.getGuiHandler().selectCard(cardLayerSelect);
 | 
			
		||||
                    }
 | 
			
		||||
                    if(cardLayerSelect == null && boardSelect != null) {
 | 
			
		||||
                    else if(boardSelect != null) {
 | 
			
		||||
                        //boardSelect
 | 
			
		||||
                        if(boardSelect instanceof PieceControl pieceControl){
 | 
			
		||||
                            if(pieceControl.isSelectable()) gameView.getBoardHandler().pieceSelect(pieceControl);
 | 
			
		||||
                        }
 | 
			
		||||
                        if(boardSelect instanceof NodeControl nodeControl){
 | 
			
		||||
//                            nodeControl.outline();
 | 
			
		||||
//
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    else {
 | 
			
		||||
@@ -115,6 +116,7 @@ else if (name.equals("MouseScrollDown")) {
 | 
			
		||||
            }
 | 
			
		||||
            else if (name.equals("MouseLeft") || name.equals("MouseRight") || name.equals("MouseVertical")){
 | 
			
		||||
                hoverPiece();
 | 
			
		||||
                hoverCardOutline();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
@@ -129,6 +131,21 @@ private <T extends AbstractControl> T checkHover(Camera cam, Node root, Class<T>
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private <T extends AbstractControl> T checkHoverOrtho(Camera cam, Node root, Class<T> controlType) {
 | 
			
		||||
        CollisionResults results = new CollisionResults();
 | 
			
		||||
        Vector3f mousePos = getMousePos(cam);
 | 
			
		||||
        mousePos.setZ(cam.getLocation().getZ());
 | 
			
		||||
        Ray ray = new Ray(mousePos, getMousePos(cam).subtract(mousePos).normalize());
 | 
			
		||||
        root.collideWith(ray, results);
 | 
			
		||||
        if (results.size() > 0) {
 | 
			
		||||
            for(CollisionResult res : results ){
 | 
			
		||||
                T control = res.getGeometry().getControl(controlType);
 | 
			
		||||
                if(control != null) return control;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void hoverPiece() {
 | 
			
		||||
        if (app.getView() instanceof GameView gameView) {
 | 
			
		||||
            PieceControl control = checkPiece();
 | 
			
		||||
@@ -145,31 +162,24 @@ private void hoverPiece() {
 | 
			
		||||
 | 
			
		||||
    private void hoverCardOutline() {
 | 
			
		||||
        if (app.getView() instanceof GameView gameView) {
 | 
			
		||||
            CardControl control = checkHover(gameView.getGuiHandler().getCardLayerCamera(), gameView.getGuiHandler().getCardLayer().getRootNode(), CardControl.class);
 | 
			
		||||
            CardControl control = checkCard(gameView);
 | 
			
		||||
            if (control != null) {
 | 
			
		||||
                if(control != hoverCard){
 | 
			
		||||
                    pieceOff();
 | 
			
		||||
                    cardOff();
 | 
			
		||||
                    hoverCard = control;
 | 
			
		||||
                    hoverCard.outline();
 | 
			
		||||
                    hoverCard.hover();
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            else pieceOff();
 | 
			
		||||
            else cardOff();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void hoverAction(){
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private PieceControl checkPiece(){
 | 
			
		||||
        return checkHover(app.getCamera(), app.getRootNode(), PieceControl.class);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    private void outlineOff(OutlineControl outline) {
 | 
			
		||||
        if (outline != null) outline.deOutline();
 | 
			
		||||
        outline = null;
 | 
			
		||||
    private CardControl checkCard(GameView gameView){
 | 
			
		||||
        return checkHoverOrtho(gameView.getGuiHandler().getCardLayerCamera(), gameView.getGuiHandler().getCardLayer().getRootNode(), CardControl.class);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void pieceOff(){
 | 
			
		||||
@@ -177,9 +187,16 @@ private void pieceOff(){
 | 
			
		||||
        hoverPiece = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void cardOff(){
 | 
			
		||||
        if(hoverCard != null) hoverCard.hoverOff();
 | 
			
		||||
        hoverCard = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private Vector3f getMousePos(Camera cam){
 | 
			
		||||
        Vector2f mousePositionScreen = inputManager.getCursorPosition();
 | 
			
		||||
        return cam.getWorldCoordinates(mousePositionScreen, 0);
 | 
			
		||||
        Vector3f world = cam.getWorldCoordinates(mousePositionScreen, 0);
 | 
			
		||||
        if (cam.isParallelProjection()) world.setZ(0);
 | 
			
		||||
        return world;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public float getRotation() {
 | 
			
		||||
 
 | 
			
		||||
@@ -54,9 +54,6 @@ public void simpleInitApp() {
 | 
			
		||||
        modelSyncronizer = new ModelSyncronizer(this);
 | 
			
		||||
 | 
			
		||||
        inputManager.deleteMapping("SIMPLEAPP_Exit");
 | 
			
		||||
        inputManager.deleteMapping("FLYCAM_ZoomIn");
 | 
			
		||||
        inputManager.deleteMapping("FLYCAM_ZoomOut");
 | 
			
		||||
        inputManager.deleteMapping("FLYCAM_RotateDrag");
 | 
			
		||||
        flyCam.setEnabled(false);
 | 
			
		||||
        GuiGlobals.initialize(this);
 | 
			
		||||
 | 
			
		||||
@@ -85,9 +82,9 @@ public void simpleInitApp() {
 | 
			
		||||
        notificationSynchronizer.addTestNotification(new MovePieceNotification(player0_1, 20, 21));
 | 
			
		||||
        notificationSynchronizer.addTestNotification(new MovePieceNotification(player1, 0, true));
 | 
			
		||||
        notificationSynchronizer.addTestNotification(new MovePieceNotification(player0, 0, 7));
 | 
			
		||||
//        notificationSynchronizer.addTestNotification(new SelectableMoveNotification(new ArrayList<>(List.of(player0, player1)), new ArrayList<>(List.of(7,3)), new ArrayList<>(List.of(false, false))));
 | 
			
		||||
        notificationSynchronizer.addTestNotification(new SwapPieceNotification(player0, player0_1));
 | 
			
		||||
//        notificationSynchronizer.addTestNotification(new SelectableSwapNotification(new ArrayList<>(List.of(player0, player1)), new ArrayList<>(List.of(player0_1))));
 | 
			
		||||
//        notificationSynchronizer.addTestNotification(new SelectableMoveNotification(new ArrayList<>(List.of(player0, player1)), new ArrayList<>(List.of(7,3)), new ArrayList<>(List.of(false, true))));
 | 
			
		||||
//        notificationSynchronizer.addTestNotification(new SwapPieceNotification(player0, player0_1));
 | 
			
		||||
        notificationSynchronizer.addTestNotification(new SelectableSwapNotification(new ArrayList<>(List.of(player0, player1)), new ArrayList<>(List.of(player0_1))));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
 
 | 
			
		||||
@@ -449,10 +449,12 @@ else if(selectableEnemyPieces.contains(pieceSelected)) {
 | 
			
		||||
    public void clearSelectable(){
 | 
			
		||||
        for(PieceControl p : selectableEnemyPieces) {
 | 
			
		||||
            p.unSelect();
 | 
			
		||||
            p.unHighlight();
 | 
			
		||||
            p.setSelectable(false);
 | 
			
		||||
        }
 | 
			
		||||
        for(PieceControl p : selectableOwnPieces) {
 | 
			
		||||
            p.unSelect();
 | 
			
		||||
            p.unHighlight();
 | 
			
		||||
            p.setSelectable(false);
 | 
			
		||||
        }
 | 
			
		||||
        selectableEnemyPieces.clear();
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,7 @@
 | 
			
		||||
import com.jme3.renderer.Camera;
 | 
			
		||||
import com.jme3.renderer.RenderManager;
 | 
			
		||||
import com.jme3.renderer.ViewPort;
 | 
			
		||||
import com.jme3.scene.Spatial;
 | 
			
		||||
import com.jme3.scene.control.AbstractControl;
 | 
			
		||||
import pp.mdga.client.MdgaApp;
 | 
			
		||||
import pp.mdga.client.board.Outline.SelectObjectOutliner;
 | 
			
		||||
@@ -12,17 +13,21 @@
 | 
			
		||||
public class OutlineControl extends AbstractControl {
 | 
			
		||||
    private static final int THICKNESS_DEFAULT = 6;
 | 
			
		||||
    private final SelectObjectOutliner outlineOwn;
 | 
			
		||||
    private MdgaApp app;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public OutlineControl(MdgaApp app, FilterPostProcessor fpp){
 | 
			
		||||
        this.app = app;
 | 
			
		||||
        outlineOwn = new SelectObjectOutliner(THICKNESS_DEFAULT, fpp, app.getRenderManager(), app.getAssetManager(), app.getCamera());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public OutlineControl(MdgaApp app, FilterPostProcessor fpp, Camera cam){
 | 
			
		||||
        this.app = app;
 | 
			
		||||
        outlineOwn = new SelectObjectOutliner(THICKNESS_DEFAULT, fpp, app.getRenderManager(), app.getAssetManager(), cam);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public OutlineControl(MdgaApp app, FilterPostProcessor fpp, Camera cam, int thickness){
 | 
			
		||||
        this.app = app;
 | 
			
		||||
        outlineOwn = new SelectObjectOutliner(thickness, fpp, app.getRenderManager(), app.getAssetManager(), cam);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -48,4 +53,23 @@ protected void controlUpdate(float tpf) {
 | 
			
		||||
    protected void controlRender(RenderManager rm, ViewPort vp) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void initSpatial(){
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setSpatial(Spatial spatial){
 | 
			
		||||
        if(this.spatial == null && spatial != null){
 | 
			
		||||
            super.setSpatial(spatial);
 | 
			
		||||
            initSpatial();
 | 
			
		||||
        }
 | 
			
		||||
        else{
 | 
			
		||||
            super.setSpatial(spatial);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public MdgaApp getApp() {
 | 
			
		||||
        return app;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -32,9 +32,9 @@ public class PieceControl extends OutlineControl {
 | 
			
		||||
    private static final ColorRGBA OUTLINE_ENEMY_HOVER_COLOR = ColorRGBA.Green;
 | 
			
		||||
    private static final ColorRGBA OUTLINE_OWN_SELECT_COLOR = ColorRGBA.Cyan;
 | 
			
		||||
    private static final ColorRGBA OUTLINE_ENEMY_SELECT_COLOR = ColorRGBA.Orange;
 | 
			
		||||
    private static final int OUTLINE_HIGHLIGHT_WIDTH = 6;
 | 
			
		||||
    private static final int OUTLINE_HOVER_WIDTH = 6;
 | 
			
		||||
    private static final int OUTLINE_SELECT_WIDTH = 8;
 | 
			
		||||
    private static final int OUTLINE_HIGHLIGHT_WIDTH = 8;
 | 
			
		||||
    private static final int OUTLINE_HOVER_WIDTH = 8;
 | 
			
		||||
    private static final int OUTLINE_SELECT_WIDTH = 10;
 | 
			
		||||
 | 
			
		||||
    private final Node parentNode;
 | 
			
		||||
    private boolean enemy;
 | 
			
		||||
@@ -87,16 +87,6 @@ public void setLocation(Vector3f loc){
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setSpatial(Spatial spatial){
 | 
			
		||||
        if(this.spatial == null && spatial != null){
 | 
			
		||||
            super.setSpatial(spatial);
 | 
			
		||||
            initSpatial();
 | 
			
		||||
        }
 | 
			
		||||
        else{
 | 
			
		||||
            super.setSpatial(spatial);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void initSpatial(){
 | 
			
		||||
        setRotation(this.initRotation);
 | 
			
		||||
 | 
			
		||||
@@ -143,8 +133,6 @@ public Material getMaterial(){
 | 
			
		||||
        return ((Geometry) getSpatial()).getMaterial();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    //highlight own/enemy figure to select
 | 
			
		||||
    public void highlight(boolean enemy) {
 | 
			
		||||
        this.enemy = enemy;
 | 
			
		||||
        highlight = true;
 | 
			
		||||
@@ -153,9 +141,9 @@ public void highlight(boolean enemy) {
 | 
			
		||||
 | 
			
		||||
    public void unHighlight(){
 | 
			
		||||
        highlight = false;
 | 
			
		||||
        deOutline();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public void hover(){
 | 
			
		||||
        if(!hoverable) return;
 | 
			
		||||
        super.outline(enemy ? OUTLINE_ENEMY_HOVER_COLOR : OUTLINE_OWN_HOVER_COLOR, OUTLINE_HOVER_WIDTH);
 | 
			
		||||
@@ -194,8 +182,4 @@ public boolean isSelectable() {
 | 
			
		||||
    public void setHoverable(boolean hoverable) {
 | 
			
		||||
        this.hoverable = hoverable;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void deOutline() {
 | 
			
		||||
        super.deOutline();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,24 +1,145 @@
 | 
			
		||||
package pp.mdga.client.gui;
 | 
			
		||||
 | 
			
		||||
import com.jme3.font.BitmapFont;
 | 
			
		||||
import com.jme3.font.BitmapText;
 | 
			
		||||
import com.jme3.material.Material;
 | 
			
		||||
import com.jme3.math.ColorRGBA;
 | 
			
		||||
import com.jme3.math.Vector3f;
 | 
			
		||||
import com.jme3.post.FilterPostProcessor;
 | 
			
		||||
import com.jme3.renderer.Camera;
 | 
			
		||||
import com.jme3.renderer.RenderManager;
 | 
			
		||||
import com.jme3.renderer.ViewPort;
 | 
			
		||||
import com.jme3.scene.Geometry;
 | 
			
		||||
import com.jme3.scene.Node;
 | 
			
		||||
import com.jme3.scene.control.AbstractControl;
 | 
			
		||||
import com.jme3.scene.shape.Box;
 | 
			
		||||
import com.jme3.scene.shape.Cylinder;
 | 
			
		||||
import com.jme3.scene.shape.Sphere;
 | 
			
		||||
import pp.mdga.client.MdgaApp;
 | 
			
		||||
import pp.mdga.client.board.OutlineControl;
 | 
			
		||||
 | 
			
		||||
import java.awt.*;
 | 
			
		||||
 | 
			
		||||
public class CardControl extends OutlineControl {
 | 
			
		||||
 | 
			
		||||
    private static final ColorRGBA OUTLINE_COLOR = ColorRGBA.Yellow;
 | 
			
		||||
    private static final int OUTLINE_THICKNESS = 9;
 | 
			
		||||
 | 
			
		||||
    public CardControl(MdgaApp app, FilterPostProcessor fpp, Camera cam){
 | 
			
		||||
    private static final ColorRGBA HIGHLIGHT_COLOR = ColorRGBA.Yellow;
 | 
			
		||||
    private static final int HIGHLIGHT_WIDTH = 9;
 | 
			
		||||
 | 
			
		||||
    private static final ColorRGBA HOVER_COLOR = ColorRGBA.Green;
 | 
			
		||||
    private static final int HOVER_WIDTH = 12;
 | 
			
		||||
 | 
			
		||||
    private static final ColorRGBA SELECT_COLOR = ColorRGBA.Blue;
 | 
			
		||||
    private static final int SELECT_WIDTH = 13;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    private static final int OUTLINE_THICKNESS = 9;
 | 
			
		||||
    private boolean hoverable;
 | 
			
		||||
    private boolean highlight;
 | 
			
		||||
    private boolean selectable;
 | 
			
		||||
    private boolean select;
 | 
			
		||||
    private Node root;
 | 
			
		||||
    private BitmapText num;
 | 
			
		||||
 | 
			
		||||
    public CardControl(MdgaApp app, FilterPostProcessor fpp, Camera cam, Node root){
 | 
			
		||||
        super(app, fpp, cam, OUTLINE_THICKNESS);
 | 
			
		||||
        this.root = root;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        Node rootNum = createNum();
 | 
			
		||||
        rootNum.setLocalTranslation(new Vector3f(0.35f,0.8f,0));
 | 
			
		||||
        root.attachChild(rootNum);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private Node createNum(){
 | 
			
		||||
        Node rootNum = new Node("root Num");
 | 
			
		||||
        Geometry circle = new Geometry("circle", new Sphere(20,20,1));
 | 
			
		||||
        circle.setLocalTranslation(new Vector3f(0.01f,0.01f,1));
 | 
			
		||||
        circle.setLocalScale(0.2f);
 | 
			
		||||
        Material mat = new Material(getApp().getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
 | 
			
		||||
        mat.setColor("Color", ColorRGBA.Black);
 | 
			
		||||
        circle.setMaterial(mat);
 | 
			
		||||
        root.attachChild(circle);
 | 
			
		||||
        BitmapFont guiFont = getApp().getAssetManager().loadFont("Fonts/Gunplay.fnt");
 | 
			
		||||
        num = new BitmapText(guiFont);
 | 
			
		||||
        num.setSize(0.3f);
 | 
			
		||||
        num.setText("1");
 | 
			
		||||
        num.setColor(ColorRGBA.White);
 | 
			
		||||
        num.setLocalTranslation(-num.getLineWidth() / 2, num.getHeight() / 2, 2);
 | 
			
		||||
        rootNum.attachChild(circle);
 | 
			
		||||
        rootNum.attachChild(num);
 | 
			
		||||
        return rootNum;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setNumCard(int num){
 | 
			
		||||
        this.num.setText(String.valueOf(num));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Node getRoot() {
 | 
			
		||||
        return root;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void initSpatial(){
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public void outline(){
 | 
			
		||||
        super.outline(OUTLINE_COLOR);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void highlight() {
 | 
			
		||||
        highlight = true;
 | 
			
		||||
        super.outline(HIGHLIGHT_COLOR, HIGHLIGHT_WIDTH);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void unHighlight(){
 | 
			
		||||
        highlight = false;
 | 
			
		||||
        deOutline();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void hover(){
 | 
			
		||||
        if(!hoverable) return;
 | 
			
		||||
        super.outline(HOVER_COLOR, HOVER_WIDTH);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void hoverOff(){
 | 
			
		||||
        if(!hoverable) return;
 | 
			
		||||
 | 
			
		||||
        if(select) select();
 | 
			
		||||
        else if(highlight) highlight();
 | 
			
		||||
        else deOutline();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void select(){
 | 
			
		||||
        if(!selectable) return;
 | 
			
		||||
        select = true;
 | 
			
		||||
        super.outline(SELECT_COLOR, SELECT_WIDTH);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void unSelect(){
 | 
			
		||||
        if(!selectable) return;
 | 
			
		||||
        select = false;
 | 
			
		||||
        if(highlight) highlight();
 | 
			
		||||
        else deOutline();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setSelectable(boolean selectable){
 | 
			
		||||
        this.selectable = selectable;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isSelected() {
 | 
			
		||||
        return select;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isSelectable() {
 | 
			
		||||
        return selectable;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setHoverable(boolean hoverable) {
 | 
			
		||||
        this.hoverable = hoverable;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -3,7 +3,9 @@
 | 
			
		||||
import com.jme3.app.Application;
 | 
			
		||||
import com.jme3.app.state.AbstractAppState;
 | 
			
		||||
import com.jme3.app.state.AppStateManager;
 | 
			
		||||
import com.jme3.light.DirectionalLight;
 | 
			
		||||
import com.jme3.material.Material;
 | 
			
		||||
import com.jme3.math.ColorRGBA;
 | 
			
		||||
import com.jme3.math.Vector3f;
 | 
			
		||||
import com.jme3.post.FilterPostProcessor;
 | 
			
		||||
import com.jme3.post.filters.ComposeFilter;
 | 
			
		||||
@@ -12,6 +14,9 @@
 | 
			
		||||
import com.jme3.renderer.ViewPort;
 | 
			
		||||
import com.jme3.scene.Node;
 | 
			
		||||
import com.jme3.scene.Spatial;
 | 
			
		||||
import com.jme3.shadow.DirectionalLightShadowFilter;
 | 
			
		||||
import com.jme3.shadow.DirectionalLightShadowRenderer;
 | 
			
		||||
import com.jme3.shadow.EdgeFilteringMode;
 | 
			
		||||
import com.jme3.texture.Image;
 | 
			
		||||
import com.jme3.texture.Texture2D;
 | 
			
		||||
import pp.mdga.client.Asset;
 | 
			
		||||
@@ -48,6 +53,24 @@ public void initialize(AppStateManager stateManager, Application app ) {
 | 
			
		||||
        view.attachScene(root);
 | 
			
		||||
        fpp.setFrameBufferFormat(Image.Format.RGBA8);
 | 
			
		||||
        fpp.addFilter(new ComposeFilter(backTexture));
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        DirectionalLight sun = new DirectionalLight();
 | 
			
		||||
        sun.setColor(ColorRGBA.White);
 | 
			
		||||
        sun.setDirection(new Vector3f(1,-1,-1));
 | 
			
		||||
        root.addLight(sun);
 | 
			
		||||
 | 
			
		||||
        final int SHADOWMAP_SIZE=1024*8;
 | 
			
		||||
//        DirectionalLightShadowRenderer dlsr = new DirectionalLightShadowRenderer(app.getAssetManager(), SHADOWMAP_SIZE, 4);
 | 
			
		||||
//        dlsr.setLight(sun);
 | 
			
		||||
//        view.addProcessor(dlsr);
 | 
			
		||||
 | 
			
		||||
        DirectionalLightShadowFilter dlsf = new DirectionalLightShadowFilter(app.getAssetManager(), SHADOWMAP_SIZE, 3);
 | 
			
		||||
        dlsf.setLight(sun);
 | 
			
		||||
        dlsf.setEnabled(true);
 | 
			
		||||
        dlsf.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);
 | 
			
		||||
        fpp.addFilter(dlsf);
 | 
			
		||||
 | 
			
		||||
        view.addProcessor(fpp);
 | 
			
		||||
 | 
			
		||||
        if(!init) init = true;
 | 
			
		||||
 
 | 
			
		||||
@@ -10,9 +10,9 @@
 | 
			
		||||
 | 
			
		||||
public class DiceControl extends AbstractControl {
 | 
			
		||||
    private final Random random = new Random();
 | 
			
		||||
    private Quaternion targetRotation; // Final rotation of the dice
 | 
			
		||||
    private final Vector3f angularVelocity = new Vector3f(); // Rotational velocity (radians/sec)
 | 
			
		||||
    private float deceleration = 0.5f; // Friction-like deceleration
 | 
			
		||||
    private Quaternion targetRotation;
 | 
			
		||||
    private final Vector3f angularVelocity = new Vector3f();
 | 
			
		||||
    private float deceleration = 0.5f;
 | 
			
		||||
    private boolean isRolling = false;
 | 
			
		||||
    private boolean slerp = false;
 | 
			
		||||
    private float timeElapsed = 0.0f;
 | 
			
		||||
@@ -47,9 +47,6 @@ protected void controlUpdate(float tpf) {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                if (timeElapsed > 1.0f) timeElapsed = 1.0f;
 | 
			
		||||
//                Quaternion interpolated = new Quaternion();
 | 
			
		||||
//                interpolated.slerp(spatial.getLocalRotation(), targetRotation, progress);
 | 
			
		||||
//                spatial.setLocalRotation(interpolated);
 | 
			
		||||
                Quaternion interpolated = spatial.getLocalRotation().clone();
 | 
			
		||||
                interpolated.nlerp(targetRotation, lerp(timeElapsed));
 | 
			
		||||
                spatial.setLocalRotation(interpolated);
 | 
			
		||||
@@ -59,41 +56,36 @@ protected void controlUpdate(float tpf) {
 | 
			
		||||
                    isRolling = false;
 | 
			
		||||
                    slerp = false;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void controlRender(RenderManager rm, ViewPort vp) {
 | 
			
		||||
        // No custom rendering needed
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void rollDice(int diceNum) {
 | 
			
		||||
        if (isRolling) return; // Prevent re-rolling during animation
 | 
			
		||||
        if (isRolling) return;
 | 
			
		||||
 | 
			
		||||
        // Set high initial rotational velocity
 | 
			
		||||
        angularVelocity.set(
 | 
			
		||||
                random.nextFloat() * 1000f + 200f, // X-axis speed
 | 
			
		||||
                random.nextFloat() * 1000f + 200f, // Y-axis speed
 | 
			
		||||
                random.nextFloat() * 1000f + 200f  // Z-axis speed
 | 
			
		||||
                random.nextFloat() * 1000f + 100f,
 | 
			
		||||
                random.nextFloat() * 1000f + 100f,
 | 
			
		||||
                random.nextFloat() * 1000f + 100f
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        // Set final target rotation for the diceNum
 | 
			
		||||
        targetRotation = getRotationForDiceNum(diceNum);
 | 
			
		||||
 | 
			
		||||
        isRolling = true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private Quaternion getRotationForDiceNum(int diceNum) {
 | 
			
		||||
        // Define specific rotations for each dice face (adjust based on your dice model)
 | 
			
		||||
        return switch (diceNum) {
 | 
			
		||||
            case 1 -> new Quaternion().fromAngleAxis((float) (1 * (Math.PI / 2)), Vector3f.UNIT_X); //
 | 
			
		||||
            case 2 -> new Quaternion().fromAngleAxis((float) (1 * (Math.PI / 2)), Vector3f.UNIT_Y); //
 | 
			
		||||
            case 3 -> new Quaternion().fromAngleAxis((float) (0 * (Math.PI / 2)), Vector3f.UNIT_X); //
 | 
			
		||||
            case 4 -> new Quaternion().fromAngleAxis((float) (2 * (Math.PI / 2)), Vector3f.UNIT_Y); //
 | 
			
		||||
            case 5 -> new Quaternion().fromAngleAxis((float) (3 * (Math.PI / 2)), Vector3f.UNIT_Y); //
 | 
			
		||||
            case 6 -> new Quaternion().fromAngleAxis((float) (3 * (Math.PI / 2)), Vector3f.UNIT_X); //
 | 
			
		||||
            case 1 -> new Quaternion().fromAngleAxis((float) (1 * (Math.PI / 2)), Vector3f.UNIT_X);
 | 
			
		||||
            case 2 -> new Quaternion().fromAngleAxis((float) (1 * (Math.PI / 2)), Vector3f.UNIT_Y);
 | 
			
		||||
            case 3 -> new Quaternion().fromAngleAxis((float) (0 * (Math.PI / 2)), Vector3f.UNIT_X);
 | 
			
		||||
            case 4 -> new Quaternion().fromAngleAxis((float) (2 * (Math.PI / 2)), Vector3f.UNIT_Y);
 | 
			
		||||
            case 5 -> new Quaternion().fromAngleAxis((float) (3 * (Math.PI / 2)), Vector3f.UNIT_Y);
 | 
			
		||||
            case 6 -> new Quaternion().fromAngleAxis((float) (3 * (Math.PI / 2)), Vector3f.UNIT_X);
 | 
			
		||||
            default -> throw new IllegalArgumentException("Invalid dice number: " + diceNum);
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -7,6 +7,7 @@
 | 
			
		||||
import com.jme3.math.Vector3f;
 | 
			
		||||
import com.jme3.post.FilterPostProcessor;
 | 
			
		||||
import com.jme3.renderer.Camera;
 | 
			
		||||
import com.jme3.renderer.queue.RenderQueue;
 | 
			
		||||
import com.jme3.scene.Node;
 | 
			
		||||
import com.jme3.scene.Spatial;
 | 
			
		||||
import com.jme3.texture.Texture2D;
 | 
			
		||||
@@ -22,7 +23,9 @@ public class GuiHandler {
 | 
			
		||||
 | 
			
		||||
    private MdgaApp app;
 | 
			
		||||
    private CardLayer cardLayer;
 | 
			
		||||
    private Map<UUID, CardControl> ownCardsMap;
 | 
			
		||||
    private Map<UUID, BonusCard> uuidBonusCardMap;
 | 
			
		||||
    private Map<BonusCard, CardControl> bonusCardControlMap;
 | 
			
		||||
    private Map<BonusCard, Integer> bonusCardIntegerMap;
 | 
			
		||||
    private BitmapFont playerFont;
 | 
			
		||||
    private Node playerNameNode;
 | 
			
		||||
    private List<Color> playerOrder;
 | 
			
		||||
@@ -34,23 +37,30 @@ public class GuiHandler {
 | 
			
		||||
    private final FilterPostProcessor fpp;
 | 
			
		||||
    Texture2D backTexture;
 | 
			
		||||
    private Camera cardLayerCamera;
 | 
			
		||||
    private DiceControl diceControl;
 | 
			
		||||
 | 
			
		||||
    private Set<CardControl> selectableCards = new HashSet<>();
 | 
			
		||||
    private BonusCard cardSelect = null;
 | 
			
		||||
 | 
			
		||||
    public GuiHandler(MdgaApp app, Texture2D backTexture) {
 | 
			
		||||
        this.app = app;
 | 
			
		||||
        this.fpp = new FilterPostProcessor(app.getAssetManager());
 | 
			
		||||
        this.backTexture = backTexture;
 | 
			
		||||
        cardLayerCamera = createOverlayCam();
 | 
			
		||||
        uuidBonusCardMap = new HashMap<>();
 | 
			
		||||
        bonusCardIntegerMap = new HashMap<>();
 | 
			
		||||
        bonusCardControlMap = new HashMap<>();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void init(){
 | 
			
		||||
        cardLayer = new CardLayer(fpp, cardLayerCamera, backTexture);
 | 
			
		||||
        app.getStateManager().attach(cardLayer);
 | 
			
		||||
        ownCardsMap = new HashMap<>();
 | 
			
		||||
        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();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -60,7 +70,6 @@ public void shutdown(){
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        cardLayer = null;
 | 
			
		||||
        ownCardsMap = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private Asset bonusToAsset(BonusCard card){
 | 
			
		||||
@@ -73,15 +82,29 @@ private Asset bonusToAsset(BonusCard card){
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void addCard(BonusCard card, UUID uuid) {
 | 
			
		||||
        CardControl control = createCard(bonusToAsset(card), nextPos());
 | 
			
		||||
        ownCardsMap.put(uuid, control);
 | 
			
		||||
        cardLayer.addSpatial(control.getSpatial());
 | 
			
		||||
        if(card == BonusCard.HIDDEN) throw new RuntimeException("cant add hidden card to gui");
 | 
			
		||||
 | 
			
		||||
        uuidBonusCardMap.put(uuid, card);
 | 
			
		||||
        if(!bonusCardControlMap.containsKey(card)) {
 | 
			
		||||
            CardControl control = createCard(bonusToAsset(card), nextPos());
 | 
			
		||||
            bonusCardControlMap.put(card, control);
 | 
			
		||||
            cardLayer.addSpatial(control.getRoot());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int newNum = bonusCardIntegerMap.getOrDefault(card,0) + 1;
 | 
			
		||||
        bonusCardIntegerMap.put(card, newNum);
 | 
			
		||||
        bonusCardControlMap.get(card).setNumCard(newNum);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void showDice(){
 | 
			
		||||
        DiceControl control = createDice();
 | 
			
		||||
        cardLayer.addSpatial(control.getSpatial());
 | 
			
		||||
        control.rollDice(1);
 | 
			
		||||
    public void showDice(int rollNum){
 | 
			
		||||
        if(!(1 <= rollNum && rollNum <= 6)) throw new RuntimeException("rollNum is not in the range [1,6]");
 | 
			
		||||
 | 
			
		||||
        cardLayer.addSpatial(diceControl.getSpatial());
 | 
			
		||||
        diceControl.rollDice(rollNum);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void hideDice(){
 | 
			
		||||
        cardLayer.deleteSpatial(diceControl.getSpatial());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private DiceControl createDice() {
 | 
			
		||||
@@ -97,26 +120,23 @@ private DiceControl createDice() {
 | 
			
		||||
        return control;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void deleteCard(UUID uuid){
 | 
			
		||||
        if(!ownCardsMap.containsKey(uuid)) throw new RuntimeException("uuid dont exist in ownCardsmap");
 | 
			
		||||
 | 
			
		||||
        cardLayer.deleteSpatial(ownCardsMap.get(uuid).getSpatial());
 | 
			
		||||
        ownCardsMap.remove(uuid);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private Vector3f nextPos() {
 | 
			
		||||
        return START.add(MARGIN.mult(ownCardsMap.size()));
 | 
			
		||||
        return START.add(MARGIN.mult(bonusCardControlMap.size()));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private CardControl createCard(Asset card, Vector3f pos){
 | 
			
		||||
        Node rootCard = new Node("Root Card");
 | 
			
		||||
        Spatial spatial = app.getAssetManager().loadModel(card.getModelPath());
 | 
			
		||||
        Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
 | 
			
		||||
        mat.setTexture("ColorMap", app.getAssetManager().loadTexture(card.getDiffPath()));
 | 
			
		||||
        rootCard.attachChild(spatial);
 | 
			
		||||
        Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
 | 
			
		||||
        mat.setTexture("DiffuseMap", app.getAssetManager().loadTexture(card.getDiffPath()));
 | 
			
		||||
        spatial.setMaterial(mat);
 | 
			
		||||
        spatial.setLocalScale(1f);
 | 
			
		||||
        rootCard.setLocalTranslation(pos);
 | 
			
		||||
        spatial.setLocalTranslation(pos);
 | 
			
		||||
        spatial.rotate((float)Math.toRadians(90), (float)Math.toRadians(180), (float)Math.toRadians(180));
 | 
			
		||||
        CardControl control = new CardControl(app, fpp, cardLayer.getOverlayCam());
 | 
			
		||||
        spatial.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
 | 
			
		||||
        CardControl control = new CardControl(app, fpp, cardLayer.getOverlayCam(), rootCard);
 | 
			
		||||
        spatial.addControl(control);
 | 
			
		||||
        return control;
 | 
			
		||||
    }
 | 
			
		||||
@@ -178,9 +198,13 @@ public void setActivePlayer(Color color){
 | 
			
		||||
    private Camera createOverlayCam(){
 | 
			
		||||
        Camera originalCam = app.getCamera();
 | 
			
		||||
        Camera overlayCam = new Camera(originalCam.getWidth(), originalCam.getHeight());
 | 
			
		||||
        overlayCam.setParallelProjection(false);
 | 
			
		||||
        overlayCam.setFrustum(originalCam.getFrustumNear(), originalCam.getFrustumFar(), originalCam.getFrustumLeft(), originalCam.getFrustumRight(),originalCam.getFrustumTop(), originalCam.getFrustumBottom());
 | 
			
		||||
        overlayCam.setFov(originalCam.getFov());
 | 
			
		||||
        overlayCam.setParallelProjection(true);
 | 
			
		||||
//        overlayCam.setFrustum(originalCam.getFrustumNear(), originalCam.getFrustumFar(), originalCam.getFrustumLeft(), originalCam.getFrustumRight(),originalCam.getFrustumTop(), originalCam.getFrustumBottom());
 | 
			
		||||
        float CAMERA_ZOOM = 4;
 | 
			
		||||
        float aspect = (float) originalCam.getWidth() / originalCam.getHeight();
 | 
			
		||||
        float size = CAMERA_ZOOM;
 | 
			
		||||
        overlayCam.setFrustum(-1000, 1000, -aspect * size, aspect * size, size, -size);
 | 
			
		||||
//        overlayCam.setFov(originalCam.getFov());
 | 
			
		||||
        overlayCam.setLocation(new Vector3f(0, 0, 10));
 | 
			
		||||
        overlayCam.lookAt(new Vector3f(0,0,0), Vector3f.UNIT_Y);
 | 
			
		||||
        return overlayCam;
 | 
			
		||||
@@ -189,10 +213,12 @@ private Camera createOverlayCam(){
 | 
			
		||||
    public void test(){
 | 
			
		||||
        UUID uuid = UUID.randomUUID();
 | 
			
		||||
        addCard(BonusCard.SHIELD, uuid);
 | 
			
		||||
        addCard(BonusCard.SHIELD, UUID.randomUUID());
 | 
			
		||||
        addCard(BonusCard.TURBO, UUID.randomUUID());
 | 
			
		||||
        addCard(BonusCard.SWAP, UUID.randomUUID());
 | 
			
		||||
 | 
			
		||||
        showDice();
 | 
			
		||||
        setSelectableCards(List.of(uuid));
 | 
			
		||||
        clearSelectableCards();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Camera getCardLayerCamera() {
 | 
			
		||||
@@ -204,4 +230,52 @@ public CardLayer getCardLayer(){
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public void setSelectableCards(List<UUID> selectUuids) {
 | 
			
		||||
        for(UUID uuid : selectUuids) {
 | 
			
		||||
            selectableCards.add(bonusCardControlMap.get(uuidBonusCardMap.get(uuid)));
 | 
			
		||||
        }
 | 
			
		||||
        for(CardControl control : selectableCards){
 | 
			
		||||
            control.setSelectable(true);
 | 
			
		||||
            control.setHoverable(true);
 | 
			
		||||
            control.highlight();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void clearSelectableCards(){
 | 
			
		||||
        for(CardControl control : selectableCards){
 | 
			
		||||
            control.setSelectable(false);
 | 
			
		||||
            control.setHoverable(false);
 | 
			
		||||
            control.unHighlight();
 | 
			
		||||
            control.unSelect();
 | 
			
		||||
        }
 | 
			
		||||
        selectableCards.clear();
 | 
			
		||||
        cardSelect = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public void selectCard(CardControl cardControl) {
 | 
			
		||||
        if(cardControl.isSelected()) {
 | 
			
		||||
            cardControl.unSelect();
 | 
			
		||||
            cardSelect = null;
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            for (CardControl control : selectableCards){
 | 
			
		||||
                control.unSelect();
 | 
			
		||||
            }
 | 
			
		||||
            cardControl.select();
 | 
			
		||||
            cardSelect = getKeyByValue(bonusCardControlMap, cardControl);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static <K, V> K getKeyByValue(Map<K, V> map, V value) {
 | 
			
		||||
        for (Map.Entry<K, V> entry : map.entrySet()) {
 | 
			
		||||
            if (entry.getValue().equals(value)) {
 | 
			
		||||
                return entry.getKey();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return null; // Key not found
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2750
									
								
								Projekte/mdga/client/src/main/resources/Models/swapCard/swapCard.obj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2750
									
								
								Projekte/mdga/client/src/main/resources/Models/swapCard/swapCard.obj
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Reference in New Issue
	
	Block a user