added select nodes, cards & pieces
This commit is contained in:
		@@ -1,7 +1,7 @@
 | 
			
		||||
package pp.mdga.client;
 | 
			
		||||
 | 
			
		||||
public enum Asset {
 | 
			
		||||
    bigTent,
 | 
			
		||||
    bigTent(0.8f),
 | 
			
		||||
    cardStack,
 | 
			
		||||
    cir,
 | 
			
		||||
    heer,
 | 
			
		||||
@@ -23,7 +23,6 @@ public enum Asset {
 | 
			
		||||
    ship(0.8f),
 | 
			
		||||
    smallTent,
 | 
			
		||||
    tank,
 | 
			
		||||
//    world(1.2f),
 | 
			
		||||
    world("Models/world_new/world_export_new.obj", "Models/world_new/world_new_diff.png", 1.2f),
 | 
			
		||||
    shield_ring("Models/shield_ring/shield_ring.obj", null),
 | 
			
		||||
    tree_small("Models/tree_small/tree_small.obj", "Models/tree_small/tree_small_diff.png"),
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,22 @@
 | 
			
		||||
package pp.mdga.client;
 | 
			
		||||
 | 
			
		||||
import com.jme3.collision.CollisionResults;
 | 
			
		||||
import com.jme3.input.InputManager;
 | 
			
		||||
import com.jme3.input.KeyInput;
 | 
			
		||||
import com.jme3.input.MouseInput;
 | 
			
		||||
import com.jme3.input.controls.*;
 | 
			
		||||
import com.jme3.math.Ray;
 | 
			
		||||
import com.jme3.math.Vector2f;
 | 
			
		||||
import com.jme3.math.Vector3f;
 | 
			
		||||
import com.jme3.renderer.Camera;
 | 
			
		||||
import com.jme3.scene.Node;
 | 
			
		||||
import com.jme3.scene.control.AbstractControl;
 | 
			
		||||
import com.jme3.scene.control.Control;
 | 
			
		||||
import pp.mdga.client.board.NodeControl;
 | 
			
		||||
import pp.mdga.client.board.OutlineControl;
 | 
			
		||||
import pp.mdga.client.board.PieceControl;
 | 
			
		||||
import pp.mdga.client.gui.CardControl;
 | 
			
		||||
import pp.mdga.client.view.GameView;
 | 
			
		||||
 | 
			
		||||
public class InputSynchronizer {
 | 
			
		||||
 | 
			
		||||
@@ -13,12 +26,13 @@ public class InputSynchronizer {
 | 
			
		||||
    protected boolean rightMousePressed = false;
 | 
			
		||||
    private float rotationAngle = 180f;
 | 
			
		||||
    private int scrollValue = 0;
 | 
			
		||||
    private CardControl hoverCard;
 | 
			
		||||
 | 
			
		||||
    InputSynchronizer(MdgaApp app) {
 | 
			
		||||
        this.app = app;
 | 
			
		||||
 | 
			
		||||
        this.inputManager = app.getInputManager();
 | 
			
		||||
 | 
			
		||||
        hoverCard = null;
 | 
			
		||||
        setupInput();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -28,13 +42,19 @@ private void setupInput() {
 | 
			
		||||
        inputManager.addMapping("RotateRightMouse", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
 | 
			
		||||
        inputManager.addMapping("MouseLeft", new MouseAxisTrigger(MouseInput.AXIS_X, false)); // Left movement
 | 
			
		||||
        inputManager.addMapping("MouseRight", new MouseAxisTrigger(MouseInput.AXIS_X, true)); // Right movement
 | 
			
		||||
        inputManager.addMapping("MouseVertical", new MouseAxisTrigger(MouseInput.AXIS_Y, false), new MouseAxisTrigger(MouseInput.AXIS_Y, true)); //Mouse Up Down movement
 | 
			
		||||
        inputManager.addMapping("MouseScrollUp", new MouseAxisTrigger(MouseInput.AXIS_WHEEL, false)); // Scroll up
 | 
			
		||||
        inputManager.addMapping("MouseScrollDown", new MouseAxisTrigger(MouseInput.AXIS_WHEEL, true)); // Scroll down
 | 
			
		||||
        inputManager.addMapping("Test", new KeyTrigger(KeyInput.KEY_J));
 | 
			
		||||
        inputManager.addMapping("Click", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
 | 
			
		||||
 | 
			
		||||
        inputManager.addListener(actionListener, "Settings", "RotateRightMouse");
 | 
			
		||||
 | 
			
		||||
        inputManager.addListener(actionListener, "Settings", "RotateRightMouse", "Click", "Test");
 | 
			
		||||
        inputManager.addListener(analogListener, "MouseLeft", "MouseRight", "MouseScrollUp", "MouseScrollDown");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean test = false;
 | 
			
		||||
 | 
			
		||||
    private final ActionListener actionListener = new ActionListener() {
 | 
			
		||||
        @Override
 | 
			
		||||
        public void onAction(String name, boolean isPressed, float tpf) {
 | 
			
		||||
@@ -44,6 +64,36 @@ public void onAction(String name, boolean isPressed, float tpf) {
 | 
			
		||||
            if (name.equals("RotateRightMouse")) {
 | 
			
		||||
                rightMousePressed = isPressed;
 | 
			
		||||
            }
 | 
			
		||||
            if(name.equals("Click") && isPressed) {
 | 
			
		||||
                //check Hover cardLayer
 | 
			
		||||
                //check Hover board
 | 
			
		||||
                if (app.getView() instanceof GameView gameView) {
 | 
			
		||||
                    CardControl cardLayerSelect = checkHover(gameView.getGuiHandler().getCardLayerCamera(), gameView.getGuiHandler().getCardLayer().getRootNode(), CardControl.class);
 | 
			
		||||
                    OutlineControl boardSelect = checkHover(app.getCamera(), app.getRootNode(), OutlineControl.class);
 | 
			
		||||
 | 
			
		||||
                    if(cardLayerSelect != null) {
 | 
			
		||||
                        //cardSelect
 | 
			
		||||
                        cardLayerSelect.outline();
 | 
			
		||||
                    }
 | 
			
		||||
                    if(cardLayerSelect == null && boardSelect != null) {
 | 
			
		||||
                        //boardSelect
 | 
			
		||||
                        if(boardSelect instanceof PieceControl pieceControl){
 | 
			
		||||
                            pieceControl.outline(true);
 | 
			
		||||
                        }
 | 
			
		||||
                        if(boardSelect instanceof NodeControl nodeControl){
 | 
			
		||||
                            nodeControl.outline();
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    else{
 | 
			
		||||
                        //both null
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
            if(name.equals("Test") &&isPressed){
 | 
			
		||||
                test = true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
@@ -52,16 +102,56 @@ public void onAction(String name, boolean isPressed, float tpf) {
 | 
			
		||||
        public void onAnalog(String name, float value, float tpf) {
 | 
			
		||||
            if (name.equals("MouseLeft") && rightMousePressed) {
 | 
			
		||||
                rotationAngle -= value * 360f;
 | 
			
		||||
            } else if (name.equals("MouseRight") && rightMousePressed) {
 | 
			
		||||
            }
 | 
			
		||||
            else if (name.equals("MouseRight") && rightMousePressed) {
 | 
			
		||||
                rotationAngle += value * 360f;
 | 
			
		||||
            } else if (name.equals("MouseScrollUp")) {
 | 
			
		||||
            }
 | 
			
		||||
            else if (name.equals("MouseScrollUp")) {
 | 
			
		||||
                scrollValue = Math.max(1, scrollValue - 5);
 | 
			
		||||
            } else if (name.equals("MouseScrollDown")) {
 | 
			
		||||
            }
 | 
			
		||||
            else if (name.equals("MouseScrollDown")) {
 | 
			
		||||
                scrollValue = Math.min(100, scrollValue + 5);
 | 
			
		||||
            }
 | 
			
		||||
            else if (name.equals("MouseLeft") || name.equals("MouseRight") || name.equals("MouseVertical")){
 | 
			
		||||
//                hoverCardOutline();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    private <T extends AbstractControl> T checkHover(Camera cam, Node root, Class<T> controlType) {
 | 
			
		||||
        CollisionResults results = new CollisionResults();
 | 
			
		||||
        Ray ray = new Ray(cam.getLocation(), getMousePos(cam).subtract(cam.getLocation()).normalize());
 | 
			
		||||
        root.collideWith(ray, results);
 | 
			
		||||
        if (results.size() > 0) {
 | 
			
		||||
            return results.getClosestCollision().getGeometry().getControl(controlType);
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void hoverCardOutline() {
 | 
			
		||||
        if (app.getView() instanceof GameView gameView) {
 | 
			
		||||
            CardControl control = checkHover(gameView.getGuiHandler().getCardLayerCamera(), gameView.getGuiHandler().getCardLayer().getRootNode(), CardControl.class);
 | 
			
		||||
            if (control != null) {
 | 
			
		||||
                if(control != hoverCard){
 | 
			
		||||
                    hoverCardOff();
 | 
			
		||||
                    hoverCard = control;
 | 
			
		||||
                    hoverCard.outline();
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            else hoverCardOff();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void hoverCardOff() {
 | 
			
		||||
        if (hoverCard != null) hoverCard.deOutline();
 | 
			
		||||
        hoverCard = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private Vector3f getMousePos(Camera cam){
 | 
			
		||||
        Vector2f mousePositionScreen = inputManager.getCursorPosition();
 | 
			
		||||
        return cam.getWorldCoordinates(mousePositionScreen, 0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public float getRotation() {
 | 
			
		||||
        return (rotationAngle / 2) % 360;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -81,9 +81,8 @@ private void handleGame(Notification notification) {
 | 
			
		||||
            // Handle DicingNotification
 | 
			
		||||
        } else if (notification instanceof DrawCardNotification) {
 | 
			
		||||
            // Handle DrawCardNotification
 | 
			
		||||
        } else if (notification instanceof HomeMoveNotification) {
 | 
			
		||||
            HomeMoveNotification n = (HomeMoveNotification)notification;
 | 
			
		||||
            gameView.getBoardHandler().moveHomePiece(n.getPieceId(), n.getHomeIndex());
 | 
			
		||||
        } else if (notification instanceof HomeMoveNotification home) {
 | 
			
		||||
            gameView.getBoardHandler().moveHomePiece(home.getPieceId(), home.getHomeIndex());
 | 
			
		||||
        } else if (notification instanceof InterruptNotification) {
 | 
			
		||||
            // Handle InterruptNotification
 | 
			
		||||
        } else if (notification instanceof MovePieceNotification) {
 | 
			
		||||
 
 | 
			
		||||
@@ -66,6 +66,9 @@ private void initMap() {
 | 
			
		||||
        this.waitingPiecesMap = new HashMap<>();
 | 
			
		||||
        this.pieceColor = new HashMap<>();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        List<AssetOnMap> assetOnMaps = MapLoader.loadMap(MAP_NAME);
 | 
			
		||||
 | 
			
		||||
        for (AssetOnMap assetOnMap : assetOnMaps) {
 | 
			
		||||
 
 | 
			
		||||
@@ -54,6 +54,7 @@ private void hideOutlineFilterEffect(Spatial model) {
 | 
			
		||||
        outlineFilter.getOutlinePreFilter().setEnabled(false);
 | 
			
		||||
        fpp.removeFilter(outlineFilter);
 | 
			
		||||
        outlineViewport.detachScene(model);
 | 
			
		||||
        outlineViewport.clearProcessors();
 | 
			
		||||
        renderManager.removePreView(outlineViewport);
 | 
			
		||||
        outlineViewport = null;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -10,15 +10,19 @@
 | 
			
		||||
import pp.mdga.client.board.Outline.SelectObjectOutliner;
 | 
			
		||||
 | 
			
		||||
public class OutlineControl extends AbstractControl {
 | 
			
		||||
    private static final int OUTLINE_THICKNESS = 4;
 | 
			
		||||
    public final SelectObjectOutliner outlineOwn;
 | 
			
		||||
    private int thickness = 4;
 | 
			
		||||
    private final SelectObjectOutliner outlineOwn;
 | 
			
		||||
 | 
			
		||||
    public OutlineControl(MdgaApp app, FilterPostProcessor fpp){
 | 
			
		||||
        outlineOwn = new SelectObjectOutliner(OUTLINE_THICKNESS, fpp, app.getRenderManager(), app.getAssetManager(), app.getCamera());
 | 
			
		||||
        outlineOwn = new SelectObjectOutliner(thickness, fpp, app.getRenderManager(), app.getAssetManager(), app.getCamera());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public OutlineControl(MdgaApp app, FilterPostProcessor fpp, Camera cam){
 | 
			
		||||
        outlineOwn = new SelectObjectOutliner(OUTLINE_THICKNESS, fpp, app.getRenderManager(), app.getAssetManager(), cam);
 | 
			
		||||
        outlineOwn = new SelectObjectOutliner(thickness, fpp, app.getRenderManager(), app.getAssetManager(), cam);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public OutlineControl(MdgaApp app, FilterPostProcessor fpp, Camera cam, int thickness){
 | 
			
		||||
        outlineOwn = new SelectObjectOutliner(thickness, fpp, app.getRenderManager(), app.getAssetManager(), cam);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -11,14 +11,14 @@
 | 
			
		||||
 | 
			
		||||
public class CardControl extends OutlineControl {
 | 
			
		||||
 | 
			
		||||
    private static final ColorRGBA OUTLINE_COLOR = ColorRGBA.White;
 | 
			
		||||
    private static final ColorRGBA OUTLINE_COLOR = ColorRGBA.Yellow;
 | 
			
		||||
    private static final int OUTLINE_THICKNESS = 7;
 | 
			
		||||
 | 
			
		||||
    public CardControl(MdgaApp app, FilterPostProcessor fpp, Camera cam){
 | 
			
		||||
        super(app, fpp, cam);
 | 
			
		||||
        super(app, fpp, cam, OUTLINE_THICKNESS);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void outline(){
 | 
			
		||||
        super.outline(OUTLINE_COLOR);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -88,4 +88,8 @@ public void deleteCard(Spatial spatial){
 | 
			
		||||
    public Camera getOverlayCam(){
 | 
			
		||||
        return overlayCam;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Node getRootNode(){
 | 
			
		||||
        return root;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -33,15 +33,17 @@ public class GuiHandler {
 | 
			
		||||
 | 
			
		||||
    private final FilterPostProcessor fpp;
 | 
			
		||||
    Texture2D backTexture;
 | 
			
		||||
    private Camera cardLayerCamera;
 | 
			
		||||
 | 
			
		||||
    public GuiHandler(MdgaApp app, Texture2D backTexture) {
 | 
			
		||||
        this.app = app;
 | 
			
		||||
        this.fpp = new FilterPostProcessor(app.getAssetManager());
 | 
			
		||||
        this.backTexture = backTexture;
 | 
			
		||||
        cardLayerCamera = createOverlayCam();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void init(){
 | 
			
		||||
        cardLayer = new CardLayer(fpp, createOverlayCam(), backTexture);
 | 
			
		||||
        cardLayer = new CardLayer(fpp, cardLayerCamera, backTexture);
 | 
			
		||||
        app.getStateManager().attach(cardLayer);
 | 
			
		||||
        ownCardsMap = new HashMap<>();
 | 
			
		||||
        playerFont = app.getAssetManager().loadFont("Fonts/Gunplay.fnt");
 | 
			
		||||
@@ -167,7 +169,14 @@ public void test(){
 | 
			
		||||
        addCard(BonusCard.TURBO, UUID.randomUUID());
 | 
			
		||||
        addCard(BonusCard.SWAP, UUID.randomUUID());
 | 
			
		||||
 | 
			
		||||
        ownCardsMap.get(uuid).outline();
 | 
			
		||||
//        ownCardsMap.get(uuid).outline();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Camera getCardLayerCamera() {
 | 
			
		||||
        return cardLayerCamera;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public CardLayer getCardLayer(){
 | 
			
		||||
        return cardLayer;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -69,20 +69,12 @@ public void onEnter() {
 | 
			
		||||
 | 
			
		||||
        boardHandler.addPlayer(Color.AIRFORCE, test);
 | 
			
		||||
        boardHandler.movePieceStart(player0, 0);
 | 
			
		||||
        boardHandler.outline(player0, true);
 | 
			
		||||
//        boardHandler.outline(player0, true);
 | 
			
		||||
 | 
			
		||||
        boardHandler.outline(10);
 | 
			
		||||
//        boardHandler.outline(10);
 | 
			
		||||
 | 
			
		||||
        app.getInputManager().addMapping("Test", new KeyTrigger(KeyInput.KEY_J));
 | 
			
		||||
        app.getInputManager().addListener(new ActionListener() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onAction(String name, boolean isPressed, float tpf) {
 | 
			
		||||
                if(name.equals("Test") && isPressed){
 | 
			
		||||
        guiHandler.test();
 | 
			
		||||
    }
 | 
			
		||||
            }
 | 
			
		||||
        }, "Test");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onLeave() {
 | 
			
		||||
@@ -118,4 +110,8 @@ private void leaveGame() {
 | 
			
		||||
    public BoardHandler getBoardHandler() {
 | 
			
		||||
        return  boardHandler;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public GuiHandler getGuiHandler() {
 | 
			
		||||
        return guiHandler;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user