merge development into test #26
@@ -127,8 +127,8 @@ private <T extends AbstractControl> T checkHover(Camera cam, Node root, Class<T>
|
|||||||
CollisionResults results = new CollisionResults();
|
CollisionResults results = new CollisionResults();
|
||||||
Ray ray = new Ray(cam.getLocation(), getMousePos(cam).subtract(cam.getLocation()).normalize());
|
Ray ray = new Ray(cam.getLocation(), getMousePos(cam).subtract(cam.getLocation()).normalize());
|
||||||
root.collideWith(ray, results);
|
root.collideWith(ray, results);
|
||||||
if (results.size() > 0) {
|
for(CollisionResult collisionResult : results){
|
||||||
return results.getClosestCollision().getGeometry().getControl(controlType);
|
if(collisionResult.getGeometry().getControl(controlType) != null) return collisionResult.getGeometry().getControl(controlType);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package pp.mdga.client;
|
package pp.mdga.client;
|
||||||
|
|
||||||
import com.jme3.app.SimpleApplication;
|
import com.jme3.app.SimpleApplication;
|
||||||
import com.jme3.renderer.RenderManager;
|
|
||||||
import com.simsilica.lemur.GuiGlobals;
|
import com.simsilica.lemur.GuiGlobals;
|
||||||
import pp.mdga.client.acoustic.AcousticHandler;
|
import pp.mdga.client.acoustic.AcousticHandler;
|
||||||
import pp.mdga.client.animation.AnimationHandler;
|
import pp.mdga.client.animation.AnimationHandler;
|
||||||
@@ -19,7 +18,7 @@ public class MdgaApp extends SimpleApplication {
|
|||||||
private AcousticHandler acousticHandler;
|
private AcousticHandler acousticHandler;
|
||||||
private NotificationSynchronizer notificationSynchronizer;
|
private NotificationSynchronizer notificationSynchronizer;
|
||||||
private InputSynchronizer inputSynchronizer;
|
private InputSynchronizer inputSynchronizer;
|
||||||
private ModelSyncronizer modelSyncronizer;
|
private ModelSynchronizer modelSynchronizer;
|
||||||
|
|
||||||
MdgaView view = null;
|
MdgaView view = null;
|
||||||
private MdgaState state = MdgaState.GAME;
|
private MdgaState state = MdgaState.GAME;
|
||||||
@@ -52,7 +51,7 @@ public void simpleInitApp() {
|
|||||||
acousticHandler = new AcousticHandler(this);
|
acousticHandler = new AcousticHandler(this);
|
||||||
notificationSynchronizer = new NotificationSynchronizer(this);
|
notificationSynchronizer = new NotificationSynchronizer(this);
|
||||||
inputSynchronizer = new InputSynchronizer(this);
|
inputSynchronizer = new InputSynchronizer(this);
|
||||||
modelSyncronizer = new ModelSyncronizer(this);
|
modelSynchronizer = new ModelSynchronizer(this);
|
||||||
|
|
||||||
inputManager.deleteMapping("SIMPLEAPP_Exit");
|
inputManager.deleteMapping("SIMPLEAPP_Exit");
|
||||||
flyCam.setEnabled(false);
|
flyCam.setEnabled(false);
|
||||||
@@ -90,19 +89,19 @@ public void simpleInitApp() {
|
|||||||
|
|
||||||
|
|
||||||
((GameView) view).setOwnColor(Color.NAVY);
|
((GameView) view).setOwnColor(Color.NAVY);
|
||||||
notificationSynchronizer.addTestNotification(new PlayerInGameNotification(Color.AIRFORCE, test, "Player 1"));
|
// notificationSynchronizer.addTestNotification(new PlayerInGameNotification(Color.AIRFORCE, test, "Player 1"));
|
||||||
notificationSynchronizer.addTestNotification(new PlayerInGameNotification(Color.NAVY, test_1, "Player 2"));
|
// notificationSynchronizer.addTestNotification(new PlayerInGameNotification(Color.NAVY, test_1, "Player 2"));
|
||||||
notificationSynchronizer.addTestNotification(new PlayerInGameNotification(Color.ARMY, test_2, "Player 3"));
|
// notificationSynchronizer.addTestNotification(new PlayerInGameNotification(Color.ARMY, test_2, "Player 3"));
|
||||||
notificationSynchronizer.addTestNotification(new PlayerInGameNotification(Color.CYBER, test_3, "Player 4"));
|
// notificationSynchronizer.addTestNotification(new PlayerInGameNotification(Color.CYBER, test_3, "Player 4"));
|
||||||
|
|
||||||
notificationSynchronizer.addTestNotification(new MovePieceNotification(player0, 0, true));
|
// notificationSynchronizer.addTestNotification(new MovePieceNotification(player0, 0, true));
|
||||||
notificationSynchronizer.addTestNotification(new MovePieceNotification(player0_1, 20, true));
|
// notificationSynchronizer.addTestNotification(new MovePieceNotification(player0_1, 20, true));
|
||||||
notificationSynchronizer.addTestNotification(new MovePieceNotification(player0_1, 20, 21));
|
// notificationSynchronizer.addTestNotification(new MovePieceNotification(player0_1, 20, 21));
|
||||||
notificationSynchronizer.addTestNotification(new MovePieceNotification(player1, 0, true));
|
// notificationSynchronizer.addTestNotification(new MovePieceNotification(player1, 0, true));
|
||||||
notificationSynchronizer.addTestNotification(new MovePieceNotification(player0, 0, 7));
|
// 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, true))));
|
// 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 SwapPieceNotification(player0, player0_1));
|
||||||
notificationSynchronizer.addTestNotification(new SelectableSwapNotification(new ArrayList<>(List.of(player0, player1)), new ArrayList<>(List.of(player0_1))));
|
// notificationSynchronizer.addTestNotification(new SelectableSwapNotification(new ArrayList<>(List.of(player0, player1)), new ArrayList<>(List.of(player0_1))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -163,8 +162,8 @@ public MdgaView getView() {
|
|||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ModelSyncronizer getModelSyncronizer() {
|
public ModelSynchronizer getModelSyncronizer() {
|
||||||
return modelSyncronizer;
|
return modelSynchronizer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputSynchronizer getInputSyncronizer() { return inputSynchronizer; }
|
public InputSynchronizer getInputSyncronizer() { return inputSynchronizer; }
|
||||||
|
|||||||
@@ -3,10 +3,10 @@
|
|||||||
import pp.mdga.client.view.LobbyView;
|
import pp.mdga.client.view.LobbyView;
|
||||||
import pp.mdga.game.Color;
|
import pp.mdga.game.Color;
|
||||||
|
|
||||||
public class ModelSyncronizer {
|
public class ModelSynchronizer {
|
||||||
private MdgaApp app;
|
private MdgaApp app;
|
||||||
|
|
||||||
ModelSyncronizer(MdgaApp app) {
|
ModelSynchronizer(MdgaApp app) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,11 +55,9 @@ private void handleMain(Notification notification) {
|
|||||||
private void handleLobby(Notification notification) {
|
private void handleLobby(Notification notification) {
|
||||||
LobbyView lobbyView = (LobbyView) app.getView();
|
LobbyView lobbyView = (LobbyView) app.getView();
|
||||||
|
|
||||||
if (notification instanceof TskSelectNotification) {
|
if (notification instanceof TskSelectNotification n) {
|
||||||
TskSelectNotification n = (TskSelectNotification)notification;
|
|
||||||
lobbyView.setTaken(n.getColor(), true, n.isSelf(), n.getName());
|
lobbyView.setTaken(n.getColor(), true, n.isSelf(), n.getName());
|
||||||
} else if (notification instanceof TskUnselectNotification) {
|
} else if (notification instanceof TskUnselectNotification n) {
|
||||||
TskUnselectNotification n = (TskUnselectNotification)notification;
|
|
||||||
lobbyView.setTaken(n.getColor(), false, false, null);
|
lobbyView.setTaken(n.getColor(), false, false, null);
|
||||||
} else if (notification instanceof GameNotification) {
|
} else if (notification instanceof GameNotification) {
|
||||||
app.enter(MdgaState.GAME);
|
app.enter(MdgaState.GAME);
|
||||||
@@ -114,6 +112,7 @@ private void handleGame(Notification notification) {
|
|||||||
boardHandler.addPlayer(n.getColor(),n.getPiecesList());
|
boardHandler.addPlayer(n.getColor(),n.getPiecesList());
|
||||||
guiHandler.addPlayer(n.getColor(),n.getName());
|
guiHandler.addPlayer(n.getColor(),n.getName());
|
||||||
} else if (notification instanceof ResumeNotification) {
|
} else if (notification instanceof ResumeNotification) {
|
||||||
|
//TODO
|
||||||
} else if (notification instanceof RollDiceNotification n) {
|
} else if (notification instanceof RollDiceNotification n) {
|
||||||
if(n.getColor() == gameView.getOwnColor()){
|
if(n.getColor() == gameView.getOwnColor()){
|
||||||
guiHandler.rollDice(n.getEyes(), n.isTurbo() ? n.getMultiplier() : -1);
|
guiHandler.rollDice(n.getEyes(), n.isTurbo() ? n.getMultiplier() : -1);
|
||||||
|
|||||||
@@ -21,9 +21,6 @@ public class BoardHandler {
|
|||||||
|
|
||||||
private final MdgaApp app;
|
private final MdgaApp app;
|
||||||
|
|
||||||
private final PileControl drawPile = null;
|
|
||||||
private final PileControl discardPile = null;
|
|
||||||
|
|
||||||
private ArrayList<NodeControl> infield;
|
private ArrayList<NodeControl> infield;
|
||||||
private Map<UUID, PieceControl> pieces;
|
private Map<UUID, PieceControl> pieces;
|
||||||
|
|
||||||
@@ -32,7 +29,6 @@ public class BoardHandler {
|
|||||||
private Map<Color, List<NodeControl>> waitingNodesMap;
|
private Map<Color, List<NodeControl>> waitingNodesMap;
|
||||||
private Map<Color, List<PieceControl>> waitingPiecesMap;
|
private Map<Color, List<PieceControl>> waitingPiecesMap;
|
||||||
private Map<UUID, Color> pieceColor;
|
private Map<UUID, Color> pieceColor;
|
||||||
private Set<OutlineControl> outlineControls;
|
|
||||||
|
|
||||||
private Node node;
|
private Node node;
|
||||||
|
|
||||||
@@ -40,11 +36,9 @@ public class BoardHandler {
|
|||||||
|
|
||||||
private boolean isInitialised;
|
private boolean isInitialised;
|
||||||
|
|
||||||
private boolean scheduleInit = false;
|
private List<PieceControl> selectableOwnPieces;
|
||||||
private boolean scheduleShutdown = false;
|
private List<PieceControl> selectableEnemyPieces;
|
||||||
|
private List<NodeControl> outlineNodes;
|
||||||
private List<PieceControl> selectableOwnPieces = new ArrayList<>();
|
|
||||||
private List<PieceControl> selectableEnemyPieces = new ArrayList<>();
|
|
||||||
private PieceControl selectedOwnPiece;
|
private PieceControl selectedOwnPiece;
|
||||||
private PieceControl selectedEnemyPiece;
|
private PieceControl selectedEnemyPiece;
|
||||||
private DiceControl diceControl;
|
private DiceControl diceControl;
|
||||||
@@ -52,12 +46,29 @@ public class BoardHandler {
|
|||||||
public BoardHandler(MdgaApp app, FilterPostProcessor fpp) {
|
public BoardHandler(MdgaApp app, FilterPostProcessor fpp) {
|
||||||
if(app == null) throw new RuntimeException("app is null");
|
if(app == null) throw new RuntimeException("app is null");
|
||||||
|
|
||||||
this.isInitialised = false;
|
|
||||||
this.app = app;
|
this.app = app;
|
||||||
this.fpp = fpp;
|
this.fpp = fpp;
|
||||||
selectedEnemyPiece = null;
|
isInitialised = false;
|
||||||
|
|
||||||
|
node = new Node("BoardHandler root node");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init() {
|
||||||
|
isInitialised = true;
|
||||||
|
selectableOwnPieces = new ArrayList<>();
|
||||||
|
selectableEnemyPieces = new ArrayList<>();
|
||||||
|
outlineNodes = new ArrayList<>();
|
||||||
selectedOwnPiece = null;
|
selectedOwnPiece = null;
|
||||||
|
selectedEnemyPiece = null;
|
||||||
initMap();
|
initMap();
|
||||||
|
app.getRootNode().attachChild(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void shutdown(){
|
||||||
|
clearSelectable();
|
||||||
|
isInitialised = false;
|
||||||
|
initMap();
|
||||||
|
app.getRootNode().detachChild(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addFigureToPlayerMap(Color col, AssetOnMap assetOnMap) {
|
private void addFigureToPlayerMap(Color col, AssetOnMap assetOnMap) {
|
||||||
@@ -66,25 +77,16 @@ private void addFigureToPlayerMap(Color col, AssetOnMap assetOnMap) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initMap() {
|
private void initMap() {
|
||||||
if (isInitialised) return;
|
pieces = new HashMap<>();
|
||||||
|
colorAssetsMap = new HashMap<>();
|
||||||
this.isInitialised = true;
|
infield = new ArrayList<>(40);
|
||||||
this.node = new Node("Asset Node");
|
homeNodesMap = new HashMap<>();
|
||||||
|
waitingNodesMap = new HashMap<>();
|
||||||
this.pieces = new HashMap<>();
|
waitingPiecesMap = new HashMap<>();
|
||||||
this.colorAssetsMap = new HashMap<>();
|
pieceColor = new HashMap<>();
|
||||||
this.infield = new ArrayList<>(40);
|
|
||||||
this.homeNodesMap = new HashMap<>();
|
|
||||||
this.waitingNodesMap = new HashMap<>();
|
|
||||||
this.waitingPiecesMap = new HashMap<>();
|
|
||||||
this.pieceColor = new HashMap<>();
|
|
||||||
this.outlineControls = new HashSet<>();
|
|
||||||
diceControl = new DiceControl(app.getAssetManager());
|
diceControl = new DiceControl(app.getAssetManager());
|
||||||
diceControl.create(new Vector3f(0,0,0), 0.7f, true);
|
diceControl.create(new Vector3f(0,0,0), 0.7f, true);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
List<AssetOnMap> assetOnMaps = MapLoader.loadMap(MAP_NAME);
|
List<AssetOnMap> assetOnMaps = MapLoader.loadMap(MAP_NAME);
|
||||||
|
|
||||||
for (AssetOnMap assetOnMap : assetOnMaps) {
|
for (AssetOnMap assetOnMap : assetOnMaps) {
|
||||||
@@ -168,7 +170,7 @@ private float getRotationMove(Vector3f prev, Vector3f next) {
|
|||||||
return newRot;
|
return newRot;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void movePiece_rek(UUID uuid, int curIndex, int moveIndex){
|
private void movePieceRek(UUID uuid, int curIndex, int moveIndex){
|
||||||
if (curIndex == moveIndex) return;
|
if (curIndex == moveIndex) return;
|
||||||
|
|
||||||
curIndex = (curIndex + 1) % infield.size();
|
curIndex = (curIndex + 1) % infield.size();
|
||||||
@@ -180,7 +182,7 @@ private void movePiece_rek(UUID uuid, int curIndex, int moveIndex){
|
|||||||
|
|
||||||
movePieceToNode(pieceControl, nodeControl);
|
movePieceToNode(pieceControl, nodeControl);
|
||||||
|
|
||||||
movePiece_rek(uuid, curIndex, moveIndex);
|
movePieceRek(uuid, curIndex, moveIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T, E> List<T> addItemToMapList(Map<E,List<T>> map, E key, T item){
|
private <T, E> List<T> addItemToMapList(Map<E,List<T>> map, E key, T item){
|
||||||
@@ -190,11 +192,10 @@ private <T, E> List<T> addItemToMapList(Map<E,List<T>> map, E key, T item){
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T, E> List<T> removeItemFromMapList(Map<E,List<T>> map, E key, T item){
|
private <T, E> void removeItemFromMapList(Map<E,List<T>> map, E key, T item){
|
||||||
List<T> list = map.getOrDefault(key, new ArrayList<>());
|
List<T> list = map.getOrDefault(key, new ArrayList<>());
|
||||||
list.remove(item);
|
list.remove(item);
|
||||||
map.put(key, list);
|
map.put(key, list);
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Vector3f getWaitingPos(Color color){
|
private Vector3f getWaitingPos(Color color){
|
||||||
@@ -273,7 +274,7 @@ public void movePieceStart(UUID uuid, int nodeIndex){
|
|||||||
public void movePiece(UUID uuid, int curIndex, int moveIndex){
|
public void movePiece(UUID uuid, int curIndex, int moveIndex){
|
||||||
if (!isInitialised) throw new RuntimeException("BoardHandler is not initialized");
|
if (!isInitialised) throw new RuntimeException("BoardHandler is not initialized");
|
||||||
|
|
||||||
movePiece_rek(uuid, curIndex, moveIndex);
|
movePieceRek(uuid, curIndex, moveIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void throwPiece(UUID uuid){
|
public void throwPiece(UUID uuid){
|
||||||
@@ -312,47 +313,25 @@ public void suppressShield(UUID uuid){
|
|||||||
public void swapPieces(UUID piece1, UUID piece2){
|
public void swapPieces(UUID piece1, UUID piece2){
|
||||||
if (!isInitialised) throw new RuntimeException("BoardHandler is not initialized");
|
if (!isInitialised) throw new RuntimeException("BoardHandler is not initialized");
|
||||||
|
|
||||||
PieceControl piece1_control = pieces.get(piece1);
|
PieceControl piece1Control = pieces.get(piece1);
|
||||||
PieceControl piece2_control = pieces.get(piece2);
|
PieceControl piece2Control = pieces.get(piece2);
|
||||||
|
|
||||||
if(piece1_control == null) throw new RuntimeException("piece1 UUID is not valid");
|
if(piece1Control == null) throw new RuntimeException("piece1 UUID is not valid");
|
||||||
if(piece2_control == null) throw new RuntimeException("piece2 UUID is not valid");
|
if(piece2Control == null) throw new RuntimeException("piece2 UUID is not valid");
|
||||||
|
|
||||||
float rot1 = piece1_control.getRotation();
|
float rot1 = piece1Control.getRotation();
|
||||||
float rot2 = piece2_control.getRotation();
|
float rot2 = piece2Control.getRotation();
|
||||||
|
|
||||||
piece1_control.setRotation(rot2);
|
piece1Control.setRotation(rot2);
|
||||||
piece2_control.setRotation(rot1);
|
piece2Control.setRotation(rot1);
|
||||||
|
|
||||||
Vector3f pos1 = piece1_control.getLocation().clone();
|
Vector3f pos1 = piece1Control.getLocation().clone();
|
||||||
Vector3f pos2 = piece2_control.getLocation().clone();
|
Vector3f pos2 = piece2Control.getLocation().clone();
|
||||||
|
|
||||||
piece1_control.setLocation(pos2);
|
piece1Control.setLocation(pos2);
|
||||||
piece2_control.setLocation(pos1);
|
piece2Control.setLocation(pos1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init() {
|
|
||||||
// outlineControls.forEach((outlineControl) -> {
|
|
||||||
// outlineControl.outline(outlineControl.getColor());
|
|
||||||
// });
|
|
||||||
|
|
||||||
isInitialised = true;
|
|
||||||
scheduleInit = false;
|
|
||||||
app.getRootNode().attachChild(node);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void shutdown(){
|
|
||||||
outlineControls.forEach((outlineControl) -> {
|
|
||||||
outlineControl.deOutline();
|
|
||||||
});
|
|
||||||
|
|
||||||
isInitialised = false;
|
|
||||||
scheduleShutdown = false;
|
|
||||||
app.getRootNode().detachChild(node);
|
|
||||||
}
|
|
||||||
|
|
||||||
//List<Pieces>
|
|
||||||
//List<NodesIndexe>
|
|
||||||
public void highlight(UUID uuid, boolean bool){
|
public void highlight(UUID uuid, boolean bool){
|
||||||
if (!isInitialised) throw new RuntimeException("BoardHandler is not initialized");
|
if (!isInitialised) throw new RuntimeException("BoardHandler is not initialized");
|
||||||
|
|
||||||
@@ -361,23 +340,6 @@ public void highlight(UUID uuid, boolean bool){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deOutline(UUID uuid){
|
|
||||||
if (!isInitialised) throw new RuntimeException("BoardHandler is not initialized");
|
|
||||||
|
|
||||||
pieces.get(uuid).deOutline();
|
|
||||||
|
|
||||||
outlineControls.remove(pieces.get(uuid));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void outline(int index){
|
|
||||||
// infield.get(index).outline();
|
|
||||||
|
|
||||||
outlineControls.add(infield.get(index));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//called when (dice) moveNum is received from server to display the movable pieces and corresponding moveNodes
|
//called when (dice) moveNum is received from server to display the movable pieces and corresponding moveNodes
|
||||||
public void outlineMove(List<UUID> pieces, List<Integer> moveIndexe, List<Boolean> homeMoves) {
|
public void outlineMove(List<UUID> pieces, List<Integer> moveIndexe, List<Boolean> homeMoves) {
|
||||||
if(pieces.size() != moveIndexe.size() || pieces.size() != homeMoves.size()) throw new RuntimeException("arrays are not the same size");
|
if(pieces.size() != moveIndexe.size() || pieces.size() != homeMoves.size()) throw new RuntimeException("arrays are not the same size");
|
||||||
@@ -403,6 +365,7 @@ public void outlineMove(List<UUID> pieces, List<Integer> moveIndexe, List<Boolea
|
|||||||
pieceControl.highlight(false);
|
pieceControl.highlight(false);
|
||||||
pieceControl.setHoverable(true);
|
pieceControl.setHoverable(true);
|
||||||
pieceControl.setSelectable(true);
|
pieceControl.setSelectable(true);
|
||||||
|
outlineNodes.add(nodeControl);
|
||||||
selectableOwnPieces.add(pieceControl);
|
selectableOwnPieces.add(pieceControl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -490,18 +453,16 @@ public void clearSelectable(){
|
|||||||
p.unHighlight();
|
p.unHighlight();
|
||||||
p.setSelectable(false);
|
p.setSelectable(false);
|
||||||
}
|
}
|
||||||
|
for(NodeControl n : outlineNodes){
|
||||||
|
n.deOutline();
|
||||||
|
}
|
||||||
|
outlineNodes.clear();
|
||||||
selectableEnemyPieces.clear();
|
selectableEnemyPieces.clear();
|
||||||
selectableOwnPieces.clear();
|
selectableOwnPieces.clear();
|
||||||
selectedEnemyPiece = null;
|
selectedEnemyPiece = null;
|
||||||
selectedOwnPiece = null;
|
selectedOwnPiece = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deOutline(int index){
|
|
||||||
infield.get(index).deOutline();
|
|
||||||
|
|
||||||
outlineControls.remove(infield.get(index));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void enableHover(UUID uuid){
|
public void enableHover(UUID uuid){
|
||||||
pieces.get(uuid).setHoverable(true);
|
pieces.get(uuid).setHoverable(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ public void init() {
|
|||||||
|
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
cardLayerHandler.shutdown();
|
cardLayerHandler.shutdown();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void rollDice(int rollNum, int mult) {
|
public void rollDice(int rollNum, int mult) {
|
||||||
|
|||||||
@@ -1,244 +0,0 @@
|
|||||||
package pp.mdga.client.gui;
|
|
||||||
|
|
||||||
import com.jme3.material.Material;
|
|
||||||
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;
|
|
||||||
import pp.mdga.client.Asset;
|
|
||||||
import pp.mdga.client.MdgaApp;
|
|
||||||
import pp.mdga.game.BonusCard;
|
|
||||||
import pp.mdga.game.Color;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class GuiHandler_old {
|
|
||||||
private MdgaApp app;
|
|
||||||
private CardLayer cardLayer;
|
|
||||||
private Map<BonusCard, CardControl> bonusCardControlMap;
|
|
||||||
private Map<BonusCard, Integer> bonusCardIntegerMap;
|
|
||||||
|
|
||||||
private static final Vector3f START = new Vector3f(-1.8f,-3.5f,0);
|
|
||||||
private static final Vector3f MARGIN = new Vector3f(1.8f,0,0);
|
|
||||||
|
|
||||||
private final FilterPostProcessor fpp;
|
|
||||||
Texture2D backTexture;
|
|
||||||
private Camera cardLayerCamera;
|
|
||||||
private DiceControl diceControl;
|
|
||||||
|
|
||||||
private Set<CardControl> selectableCards = new HashSet<>();
|
|
||||||
private BonusCard cardSelect = null;
|
|
||||||
private PlayerNameHandler playerNameHandler;
|
|
||||||
private ActionTextHandler actionTextHandler;
|
|
||||||
|
|
||||||
private static final float CARDLAYER_CAMERA_ZOOM = 4;
|
|
||||||
|
|
||||||
public GuiHandler_old(MdgaApp app, Texture2D backTexture) {
|
|
||||||
this.app = app;
|
|
||||||
this.fpp = new FilterPostProcessor(app.getAssetManager());
|
|
||||||
this.backTexture = backTexture;
|
|
||||||
cardLayerCamera = createOverlayCam();
|
|
||||||
bonusCardIntegerMap = new HashMap<>();
|
|
||||||
bonusCardControlMap = new HashMap<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
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");
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private Vector3f nextPos() {
|
|
||||||
return START.add(MARGIN.mult(bonusCardControlMap.size()));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private Camera createOverlayCam(){
|
|
||||||
Camera originalCam = app.getCamera();
|
|
||||||
Camera overlayCam = new Camera(originalCam.getWidth(), originalCam.getHeight());
|
|
||||||
overlayCam.setParallelProjection(true);
|
|
||||||
final float aspect = (float) originalCam.getWidth() / originalCam.getHeight();
|
|
||||||
final float size = CARDLAYER_CAMERA_ZOOM;
|
|
||||||
overlayCam.setFrustum(-1000, 1000, -aspect * size, aspect * size, size, -size);
|
|
||||||
overlayCam.setLocation(new Vector3f(0, 0, 10));
|
|
||||||
overlayCam.lookAt(new Vector3f(0,0,0), Vector3f.UNIT_Y);
|
|
||||||
return overlayCam;
|
|
||||||
}
|
|
||||||
|
|
||||||
private <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
|
|
||||||
}
|
|
||||||
|
|
||||||
private SymbolControl createSymbol(Asset asset){
|
|
||||||
Spatial spatial = app.getAssetManager().loadModel(asset.getModelPath());
|
|
||||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
|
||||||
mat.setTexture("ColorMap", app.getAssetManager().loadTexture(asset.getDiffPath()));
|
|
||||||
spatial.setMaterial(mat);
|
|
||||||
spatial.setLocalScale(1f);
|
|
||||||
spatial.rotate((float)Math.toRadians(90), (float)Math.toRadians(180), (float)Math.toRadians(180));
|
|
||||||
SymbolControl control = new SymbolControl();
|
|
||||||
spatial.addControl(control);
|
|
||||||
return control;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Public methods****************************************************************************************************
|
|
||||||
|
|
||||||
public void init(){
|
|
||||||
cardLayer = new CardLayer(fpp, cardLayerCamera, backTexture);
|
|
||||||
app.getStateManager().attach(cardLayer);
|
|
||||||
diceControl = new DiceControl(app.getAssetManager());
|
|
||||||
diceControl.create(new Vector3f(0,0,0), 1f, false);
|
|
||||||
|
|
||||||
playerNameHandler = new PlayerNameHandler(app.getGuiNode(), app.getAssetManager(), app.getContext().getSettings());
|
|
||||||
actionTextHandler = new ActionTextHandler(app.getGuiNode(), app.getAssetManager(), app.getContext().getSettings());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void shutdown(){
|
|
||||||
if(cardLayer != null){
|
|
||||||
cardLayer.shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
cardLayer = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void rollDice(int rollNum){
|
|
||||||
if(!(1 <= rollNum && rollNum <= 6)) throw new RuntimeException("rollNum is not in the range [1,6]");
|
|
||||||
diceControl.rollDice(rollNum);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void showDice(){
|
|
||||||
cardLayer.addSpatial(diceControl.getSpatial());
|
|
||||||
diceControl.spin();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addCard(BonusCard card) {
|
|
||||||
if(card == BonusCard.HIDDEN) throw new RuntimeException("cant add hidden card to gui");
|
|
||||||
|
|
||||||
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 hideDice(){
|
|
||||||
diceControl.hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addPlayer(Color color, String name, boolean own){
|
|
||||||
playerNameHandler.addPlayer(color, name, own);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setActivePlayer(Color color){
|
|
||||||
playerNameHandler.setActivePlayer(color);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Camera getCardLayerCamera() {
|
|
||||||
return cardLayerCamera;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CardLayer getCardLayer(){
|
|
||||||
return cardLayer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clearSelectableCards(){
|
|
||||||
for(CardControl control : selectableCards){
|
|
||||||
control.setSelectable(false);
|
|
||||||
control.setHoverable(false);
|
|
||||||
control.unHighlight();
|
|
||||||
control.unSelect();
|
|
||||||
}
|
|
||||||
selectableCards.clear();
|
|
||||||
cardSelect = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSelectableCards(List<BonusCard> select) {
|
|
||||||
for(BonusCard uuid : select) {
|
|
||||||
selectableCards.add(bonusCardControlMap.get(uuid));
|
|
||||||
}
|
|
||||||
for(CardControl control : selectableCards){
|
|
||||||
control.setSelectable(true);
|
|
||||||
control.setHoverable(true);
|
|
||||||
control.setHighlight();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 void shield(){
|
|
||||||
SymbolControl control = createSymbol(Asset.shieldSymbol);
|
|
||||||
cardLayer.addSpatial(control.getSpatial());
|
|
||||||
control.shield();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void swap(){
|
|
||||||
SymbolControl control = createSymbol(Asset.swapSymbol);
|
|
||||||
cardLayer.addSpatial(control.getSpatial());
|
|
||||||
control.swap();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void turbo(){
|
|
||||||
SymbolControl control = createSymbol(Asset.turboSymbol);
|
|
||||||
cardLayer.addSpatial(control.getSpatial());
|
|
||||||
control.turbo();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void test(){
|
|
||||||
addCard(BonusCard.SHIELD);
|
|
||||||
addCard(BonusCard.SHIELD);
|
|
||||||
addCard(BonusCard.TURBO);
|
|
||||||
addCard(BonusCard.SWAP);
|
|
||||||
|
|
||||||
// setSelectableCards(List.of(uuid,uuid1));
|
|
||||||
// showDice();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void test2(){
|
|
||||||
actionTextHandler.drawCardOwn(Color.NAVY);
|
|
||||||
}
|
|
||||||
|
|
||||||
private CardControl createCard(Asset card, Vector3f pos){
|
|
||||||
Node rootCard = new Node("Root Card");
|
|
||||||
Spatial spatial = app.getAssetManager().loadModel(card.getModelPath());
|
|
||||||
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.rotate((float)Math.toRadians(90), (float)Math.toRadians(180), (float)Math.toRadians(180));
|
|
||||||
spatial.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
|
|
||||||
CardControl control = new CardControl(app, fpp, cardLayer.getOverlayCam(), rootCard);
|
|
||||||
spatial.addControl(control);
|
|
||||||
return control;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user