added GuiHandler and showing bonuscards
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package pp.mdga.client.board;
|
||||
package pp.mdga.client;
|
||||
|
||||
enum BoardAsset {
|
||||
public enum Asset {
|
||||
bigTent,
|
||||
cardStack,
|
||||
cir,
|
||||
@@ -20,43 +20,44 @@ enum BoardAsset {
|
||||
node_start("./node_normal/node_normal.j3o", "./node_normal/node_start_diff.png"),
|
||||
node_bonus("./node_normal/node_normal.j3o", "./node_normal/node_bonus_diff.png"),
|
||||
radar,
|
||||
shieldCard,
|
||||
ship(0.8f),
|
||||
smallTent,
|
||||
swapCard,
|
||||
tank,
|
||||
turboCard,
|
||||
// world(1.2f),
|
||||
world("./world_new/world_export_new.obj", "./world_new/world_new_diff.png", 1.2f),
|
||||
shield_ring("./shield_ring/shield_ring.obj", null),
|
||||
tree_small("./tree_small/tree_small.obj", "./tree_small/tree_small_diff.png"),
|
||||
tree_big("./tree_big/tree_big.obj", "./tree_big/tree_big_diff.png");
|
||||
tree_big("./tree_big/tree_big.obj", "./tree_big/tree_big_diff.png"),
|
||||
turboCard,
|
||||
swapCard,
|
||||
shieldCard
|
||||
;
|
||||
|
||||
private final String modelPath;
|
||||
private final String diffPath;
|
||||
private final float size;
|
||||
|
||||
BoardAsset() {
|
||||
Asset() {
|
||||
String folderFileName = "./" + name() + "/" + name();
|
||||
this.modelPath = folderFileName + ".j3o";
|
||||
this.diffPath = folderFileName + "_diff.png";
|
||||
this.size = 1f;
|
||||
}
|
||||
|
||||
BoardAsset(String modelPath, String diffPath) {
|
||||
Asset(String modelPath, String diffPath) {
|
||||
this.modelPath = modelPath;
|
||||
this.diffPath = diffPath;
|
||||
this.size = 1f;
|
||||
}
|
||||
|
||||
BoardAsset(float size) {
|
||||
Asset(float size) {
|
||||
String folderFileName = "./" + name() + "/" + name();
|
||||
this.modelPath = folderFileName + ".j3o";
|
||||
this.diffPath = folderFileName + "_diff.png";
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
BoardAsset(String modelPath, String diffPath, float size){
|
||||
Asset(String modelPath, String diffPath, float size){
|
||||
this.modelPath = modelPath;
|
||||
this.diffPath = diffPath;
|
||||
this.size = size;
|
||||
@@ -6,8 +6,6 @@
|
||||
import pp.mdga.client.animation.AnimationHandler;
|
||||
import com.jme3.system.AppSettings;
|
||||
import pp.mdga.client.view.*;
|
||||
import pp.mdga.game.Color;
|
||||
import pp.mdga.notification.TskSelectNotification;
|
||||
|
||||
public class MdgaApp extends SimpleApplication {
|
||||
private AnimationHandler animationHandler;
|
||||
@@ -17,9 +15,9 @@ public class MdgaApp extends SimpleApplication {
|
||||
private ModelSyncronizer modelSyncronizer;
|
||||
|
||||
MdgaView view = null;
|
||||
private MdgaState state = MdgaState.MAIN;
|
||||
private MdgaState state = MdgaState.GAME;
|
||||
|
||||
private static float resolutionFactor = 1;
|
||||
private static float resolutionFactor = 1f;
|
||||
|
||||
public static void main(String[] args) {
|
||||
AppSettings settings = new AppSettings(true);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
package pp.mdga.client.board;
|
||||
|
||||
record AssetOnMap(BoardAsset asset, int x, int y, float rot) {}
|
||||
import pp.mdga.client.Asset;
|
||||
|
||||
record AssetOnMap(Asset asset, int x, int y, float rot) {}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package pp.mdga.client.board;
|
||||
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.post.FilterPostProcessor;
|
||||
import com.jme3.renderer.queue.RenderQueue;
|
||||
import com.jme3.scene.Node;
|
||||
import com.jme3.scene.Spatial;
|
||||
import com.jme3.scene.control.AbstractControl;
|
||||
import pp.mdga.client.Asset;
|
||||
import pp.mdga.client.MdgaApp;
|
||||
import pp.mdga.game.Color;
|
||||
|
||||
@@ -70,10 +70,10 @@ private void initMap() {
|
||||
|
||||
for (AssetOnMap assetOnMap : assetOnMaps) {
|
||||
switch (assetOnMap.asset()) {
|
||||
case lw -> addFigureToPlayerMap(assetToColor(BoardAsset.lw), assetOnMap);
|
||||
case heer -> addFigureToPlayerMap(assetToColor(BoardAsset.heer), assetOnMap);
|
||||
case cir -> addFigureToPlayerMap(assetToColor(BoardAsset.cir), assetOnMap);
|
||||
case marine -> addFigureToPlayerMap(assetToColor(BoardAsset.marine), assetOnMap);
|
||||
case lw -> addFigureToPlayerMap(assetToColor(Asset.lw), assetOnMap);
|
||||
case heer -> addFigureToPlayerMap(assetToColor(Asset.heer), assetOnMap);
|
||||
case cir -> addFigureToPlayerMap(assetToColor(Asset.cir), assetOnMap);
|
||||
case marine -> addFigureToPlayerMap(assetToColor(Asset.marine), assetOnMap);
|
||||
case node_normal, node_bonus, node_start ->
|
||||
infield.add(displayAndControl(assetOnMap, new NodeControl()));
|
||||
case node_home_black -> addHomeNode(homeNodesMap, Color.AIRFORCE, assetOnMap);
|
||||
@@ -90,7 +90,7 @@ private void initMap() {
|
||||
}
|
||||
}
|
||||
|
||||
private Color assetToColor(BoardAsset asset) {
|
||||
private Color assetToColor(Asset asset) {
|
||||
return switch (asset) {
|
||||
case lw -> Color.AIRFORCE;
|
||||
case heer -> Color.ARMY;
|
||||
@@ -100,7 +100,7 @@ private Color assetToColor(BoardAsset asset) {
|
||||
};
|
||||
}
|
||||
|
||||
private Spatial createModel(BoardAsset asset, Vector3f pos, float rot) {
|
||||
private Spatial createModel(Asset asset, Vector3f pos, float rot) {
|
||||
String modelName = asset.getModelPath();
|
||||
String texName = asset.getDiffPath();
|
||||
Spatial model = app.getAssetManager().loadModel(modelName);
|
||||
|
||||
@@ -33,7 +33,7 @@ public CameraHandler(MdgaApp app, FilterPostProcessor fpp){
|
||||
|
||||
public void init() {
|
||||
app.getFlyByCamera().setEnabled(true);
|
||||
int zoom = 15;
|
||||
int zoom = 20;
|
||||
app.getCamera().setLocation(new Vector3f(-zoom, 0, zoom));
|
||||
app.getCamera().lookAt(new Vector3f(0, 0, 0), new Vector3f(0, 0, 1));
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package pp.mdga.client.board;
|
||||
|
||||
|
||||
import pp.mdga.client.Asset;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -43,7 +46,7 @@ public static List<AssetOnMap> loadMap(String mapName) {
|
||||
|
||||
float rot = Float.parseFloat(parts[2]);
|
||||
|
||||
BoardAsset asset = getLoadedAsset(assetName);
|
||||
Asset asset = getLoadedAsset(assetName);
|
||||
assetsOnMap.add(new AssetOnMap(asset, x, y, rot));
|
||||
}
|
||||
}
|
||||
@@ -57,32 +60,32 @@ public static List<AssetOnMap> loadMap(String mapName) {
|
||||
return assetsOnMap;
|
||||
}
|
||||
|
||||
private static BoardAsset getLoadedAsset(String assetName) {
|
||||
private static Asset getLoadedAsset(String assetName) {
|
||||
return switch (assetName) {
|
||||
case "lw" -> BoardAsset.lw;
|
||||
case "cir" -> BoardAsset.cir;
|
||||
case "marine" -> BoardAsset.marine;
|
||||
case "heer" -> BoardAsset.heer;
|
||||
case "node" -> BoardAsset.node_normal;
|
||||
case "node_start" -> BoardAsset.node_start;
|
||||
case "node_bonus" -> BoardAsset.node_bonus;
|
||||
case "node_home_blue" -> BoardAsset.node_home_blue;
|
||||
case "node_home_yellow" -> BoardAsset.node_home_yellow;
|
||||
case "node_home_black" -> BoardAsset.node_home_black;
|
||||
case "node_home_green" -> BoardAsset.node_home_green;
|
||||
case "node_wait_blue" -> BoardAsset.node_wait_blue;
|
||||
case "node_wait_yellow" -> BoardAsset.node_wait_yellow;
|
||||
case "node_wait_black" -> BoardAsset.node_wait_black;
|
||||
case "node_wait_green" -> BoardAsset.node_wait_green;
|
||||
case "world" -> BoardAsset.world;
|
||||
case "jet" -> BoardAsset.jet;
|
||||
case "big_tent" -> BoardAsset.bigTent;
|
||||
case "small_tent" -> BoardAsset.smallTent;
|
||||
case "radar" -> BoardAsset.radar;
|
||||
case "ship" -> BoardAsset.ship;
|
||||
case "tank" -> BoardAsset.tank;
|
||||
case "tree_small" -> BoardAsset.tree_small;
|
||||
case "tree_big" -> BoardAsset.tree_big;
|
||||
case "lw" -> Asset.lw;
|
||||
case "cir" -> Asset.cir;
|
||||
case "marine" -> Asset.marine;
|
||||
case "heer" -> Asset.heer;
|
||||
case "node" -> Asset.node_normal;
|
||||
case "node_start" -> Asset.node_start;
|
||||
case "node_bonus" -> Asset.node_bonus;
|
||||
case "node_home_blue" -> Asset.node_home_blue;
|
||||
case "node_home_yellow" -> Asset.node_home_yellow;
|
||||
case "node_home_black" -> Asset.node_home_black;
|
||||
case "node_home_green" -> Asset.node_home_green;
|
||||
case "node_wait_blue" -> Asset.node_wait_blue;
|
||||
case "node_wait_yellow" -> Asset.node_wait_yellow;
|
||||
case "node_wait_black" -> Asset.node_wait_black;
|
||||
case "node_wait_green" -> Asset.node_wait_green;
|
||||
case "world" -> Asset.world;
|
||||
case "jet" -> Asset.jet;
|
||||
case "big_tent" -> Asset.bigTent;
|
||||
case "small_tent" -> Asset.smallTent;
|
||||
case "radar" -> Asset.radar;
|
||||
case "ship" -> Asset.ship;
|
||||
case "tank" -> Asset.tank;
|
||||
case "tree_small" -> Asset.tree_small;
|
||||
case "tree_big" -> Asset.tree_big;
|
||||
default -> throw new IllegalStateException("Unexpected value: " + assetName);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
import com.jme3.scene.Node;
|
||||
import com.jme3.scene.Spatial;
|
||||
import com.jme3.scene.control.AbstractControl;
|
||||
import pp.mdga.client.Asset;
|
||||
import pp.mdga.client.MdgaApp;
|
||||
import pp.mdga.client.board.Outline.SelectObjectOutliner;
|
||||
|
||||
@@ -107,7 +108,7 @@ public void rotateInit() {
|
||||
}
|
||||
|
||||
public void activateShield(){
|
||||
shieldRing = assetManager.loadModel(BoardAsset.shield_ring.getModelPath());
|
||||
shieldRing = assetManager.loadModel(Asset.shield_ring.getModelPath());
|
||||
shieldRing.scale(1f);
|
||||
shieldRing.rotate((float) Math.toRadians(0), 0, (float) Math.toRadians(0));
|
||||
shieldRing.setLocalTranslation(spatial.getLocalTranslation().add(new Vector3f(0,0,SHIELD_Z)));
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package pp.mdga.client.gui;
|
||||
|
||||
import com.jme3.renderer.RenderManager;
|
||||
import com.jme3.renderer.ViewPort;
|
||||
import com.jme3.scene.control.AbstractControl;
|
||||
|
||||
public class CardControl extends AbstractControl {
|
||||
|
||||
public CardControl(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void controlUpdate(float tpf) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void controlRender(RenderManager rm, ViewPort vp) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package pp.mdga.client.gui;
|
||||
|
||||
import com.jme3.app.Application;
|
||||
import com.jme3.app.state.AbstractAppState;
|
||||
import com.jme3.app.state.AppStateManager;
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.renderer.Camera;
|
||||
import com.jme3.renderer.RenderManager;
|
||||
import com.jme3.renderer.ViewPort;
|
||||
import com.jme3.scene.Node;
|
||||
import com.jme3.scene.Spatial;
|
||||
import pp.mdga.client.Asset;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class CardLayer extends AbstractAppState {
|
||||
|
||||
private Node root;
|
||||
private Application app;
|
||||
private boolean init;
|
||||
|
||||
private List<Spatial> cardBuffer;
|
||||
|
||||
|
||||
public CardLayer() {
|
||||
this.cardBuffer = new ArrayList<>();
|
||||
init = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(AppStateManager stateManager, Application app ) {
|
||||
this.app = app;
|
||||
root = new Node("Under gui viewport Root");
|
||||
|
||||
Camera originalCam = app.getCamera();
|
||||
|
||||
Camera cam = new Camera(originalCam.getWidth(), originalCam.getHeight());
|
||||
cam.setParallelProjection(false);
|
||||
cam.setFrustum(originalCam.getFrustumNear(), originalCam.getFrustumFar(), originalCam.getFrustumLeft(), originalCam.getFrustumRight(),originalCam.getFrustumTop(), originalCam.getFrustumBottom());
|
||||
cam.setFov(originalCam.getFov());
|
||||
cam.setLocation(new Vector3f(0, 0, 10));
|
||||
cam.lookAt(new Vector3f(0,0,0), Vector3f.UNIT_Y);
|
||||
|
||||
ViewPort view = app.getRenderManager().createMainView("Under gui ViewPort", cam);
|
||||
view.setEnabled(true);
|
||||
view.setClearFlags(false, true, false);
|
||||
view.attachScene(root);
|
||||
|
||||
if(!init) init = true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void render(RenderManager rm) {
|
||||
root.updateGeometricState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update( float tpf ) {
|
||||
root.updateLogicalState(tpf);
|
||||
|
||||
if (init && !cardBuffer.isEmpty()) {
|
||||
for(Spatial spatial : cardBuffer){
|
||||
root.attachChild(spatial);
|
||||
}
|
||||
cardBuffer.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void addCard(Spatial card){
|
||||
cardBuffer.add(card);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,70 @@
|
||||
package pp.mdga.client.gui;
|
||||
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.scene.Spatial;
|
||||
import pp.mdga.client.Asset;
|
||||
import pp.mdga.client.MdgaApp;
|
||||
import pp.mdga.game.BonusCard;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
public class GuiHandler {
|
||||
|
||||
private MdgaApp app;
|
||||
private CardLayer cardLayer;
|
||||
private Map<UUID, CardControl> ownCardsMap;
|
||||
|
||||
private static final Vector3f START = new Vector3f(-3,-3,0);
|
||||
private static final Vector3f MARGIN = new Vector3f(2.5f,0,0);
|
||||
|
||||
public GuiHandler(MdgaApp app) {
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
public void init(){
|
||||
cardLayer = new CardLayer();
|
||||
app.getStateManager().attach(cardLayer);
|
||||
ownCardsMap = new HashMap<>();
|
||||
|
||||
addCard(BonusCard.SHIELD, UUID.randomUUID());
|
||||
addCard(BonusCard.TURBO, UUID.randomUUID());
|
||||
addCard(BonusCard.SWAP, UUID.randomUUID());
|
||||
|
||||
}
|
||||
|
||||
private Asset bonusToAsset(BonusCard card){
|
||||
return switch (card){
|
||||
case TURBO -> Asset.turboCard;
|
||||
case SHIELD -> Asset.shieldCard;
|
||||
case SWAP -> Asset.swapCard;
|
||||
case HIDDEN -> throw new RuntimeException("HIDDEN is not allowed in GUI");
|
||||
};
|
||||
}
|
||||
|
||||
public void addCard(BonusCard card, UUID uuid) {
|
||||
CardControl control = createCard(bonusToAsset(card), nextPos());
|
||||
ownCardsMap.put(uuid, control);
|
||||
cardLayer.addCard(control.getSpatial());
|
||||
}
|
||||
|
||||
private Vector3f nextPos() {
|
||||
return START.add(MARGIN.mult(ownCardsMap.size()));
|
||||
}
|
||||
|
||||
private CardControl createCard(Asset card, Vector3f pos){
|
||||
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()));
|
||||
spatial.setMaterial(mat);
|
||||
spatial.setLocalScale(1f);
|
||||
spatial.setLocalTranslation(pos);
|
||||
spatial.rotate((float)Math.toRadians(90), (float)Math.toRadians(180), (float)Math.toRadians(180));
|
||||
CardControl control = new CardControl();
|
||||
spatial.addControl(control);
|
||||
return control;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,17 @@
|
||||
import pp.mdga.client.dialog.SingleButtonRightDialog;
|
||||
import pp.mdga.client.MdgaApp;
|
||||
import pp.mdga.client.MdgaState;
|
||||
import pp.mdga.client.gui.GuiHandler;
|
||||
import pp.mdga.game.Color;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class GameView extends MdgaView {
|
||||
private BoardHandler boardHandler;
|
||||
private CameraHandler camera;
|
||||
private GuiHandler guiHandler;
|
||||
|
||||
private SingleButtonLeftDialog leaveButton;
|
||||
private SingleButtonRightDialog continueButton;
|
||||
@@ -24,6 +31,8 @@ public GameView(MdgaApp app) {
|
||||
this.boardHandler = new BoardHandler(app, fpp);
|
||||
app.getViewPort().addProcessor(fpp);
|
||||
|
||||
this.guiHandler = new GuiHandler(app);
|
||||
|
||||
leaveButton = new SingleButtonLeftDialog(app, settingsNode, "Verlassen", () -> leaveGame());
|
||||
|
||||
continueButton = new SingleButtonRightDialog(app, node, "Weiter", () -> app.getModelSyncronizer().enter(MdgaState.CEREMONY));
|
||||
@@ -33,8 +42,9 @@ public GameView(MdgaApp app) {
|
||||
public void onEnter() {
|
||||
camera.init();
|
||||
boardHandler.init();
|
||||
|
||||
guiHandler.init();
|
||||
continueButton.show();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package pp.mdga.game;
|
||||
|
||||
public enum BonusCard {
|
||||
HIDDERN,
|
||||
HIDDEN,
|
||||
SHIELD,
|
||||
TURBO,
|
||||
SWAP
|
||||
|
||||
Reference in New Issue
Block a user