added skybox; reworked guiHandler
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
public enum Asset {
|
||||
bigTent,
|
||||
cardStack,
|
||||
cir("Models/lcir/cir_newOrigin.obj"),
|
||||
cir("Models/cir/cir_newOrigin.obj"),
|
||||
heer("Models/heer/heer_newOrigin.obj"),
|
||||
jet,
|
||||
lw("Models/lw/lw_newOrigin.obj"),
|
||||
|
||||
@@ -71,7 +71,7 @@ public void onAction(String name, boolean isPressed, float tpf) {
|
||||
}
|
||||
if(name.equals("Click") && isPressed) {
|
||||
if (app.getView() instanceof GameView gameView) {
|
||||
CardControl cardLayerSelect = checkHover(gameView.getGuiHandler().getCardLayerCamera(), gameView.getGuiHandler().getCardLayer().getRootNode(), CardControl.class);
|
||||
CardControl cardLayerSelect = checkHover(gameView.getGuiHandler().getCardLayerCamera(), gameView.getGuiHandler().getCardLayerRootNode(), CardControl.class);
|
||||
OutlineControl boardSelect = checkHover(app.getCamera(), app.getRootNode(), OutlineControl.class);
|
||||
|
||||
if(cardLayerSelect != null) {
|
||||
@@ -185,7 +185,7 @@ private PieceControl checkPiece(){
|
||||
}
|
||||
|
||||
private CardControl checkCard(GameView gameView){
|
||||
return checkHoverOrtho(gameView.getGuiHandler().getCardLayerCamera(), gameView.getGuiHandler().getCardLayer().getRootNode(), CardControl.class);
|
||||
return checkHoverOrtho(gameView.getGuiHandler().getCardLayerCamera(), gameView.getGuiHandler().getCardLayerRootNode(), CardControl.class);
|
||||
}
|
||||
|
||||
private void pieceOff(){
|
||||
|
||||
@@ -76,10 +76,25 @@ public void simpleInitApp() {
|
||||
test_1.add(UUID.randomUUID());
|
||||
test_1.add(UUID.randomUUID());
|
||||
|
||||
List<UUID> test_2 = new ArrayList<>();
|
||||
test_2.add(UUID.randomUUID());
|
||||
test_2.add(UUID.randomUUID());
|
||||
test_2.add(UUID.randomUUID());
|
||||
test_2.add(UUID.randomUUID());
|
||||
|
||||
List<UUID> test_3 = new ArrayList<>();
|
||||
test_3.add(UUID.randomUUID());
|
||||
test_3.add(UUID.randomUUID());
|
||||
test_3.add(UUID.randomUUID());
|
||||
test_3.add(UUID.randomUUID());
|
||||
|
||||
|
||||
((GameView) view).setOwnColor(Color.NAVY);
|
||||
notificationSynchronizer.addTestNotification(new PlayerInGameNotification(Color.AIRFORCE, test, "Player 1"));
|
||||
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.CYBER, test_3, "Player 4"));
|
||||
|
||||
notificationSynchronizer.addTestNotification(new MovePieceNotification(player0, 0, true));
|
||||
notificationSynchronizer.addTestNotification(new MovePieceNotification(player0_1, 20, true));
|
||||
notificationSynchronizer.addTestNotification(new MovePieceNotification(player0_1, 20, 21));
|
||||
|
||||
@@ -74,7 +74,7 @@ private void handleGame(Notification notification) {
|
||||
BoardHandler boardHandler = gameView.getBoardHandler();
|
||||
|
||||
if (notification instanceof AcquireCardNotification n) {
|
||||
guiHandler.addCard(n.getBonusCard(), n.getCardId());
|
||||
guiHandler.addCard(n.getBonusCard());
|
||||
} else if (notification instanceof ActivePlayerNotification n) {
|
||||
guiHandler.setActivePlayer(n.getColor());
|
||||
} else if (notification instanceof CeremonyNotification) {
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
import com.jme3.post.FilterPostProcessor;
|
||||
import com.jme3.shadow.DirectionalLightShadowFilter;
|
||||
import com.jme3.shadow.EdgeFilteringMode;
|
||||
import com.jme3.util.SkyFactory;
|
||||
import com.jme3.util.SkyFactory.EnvMapType;
|
||||
import pp.mdga.client.MdgaApp;
|
||||
|
||||
public class CameraHandler {
|
||||
@@ -34,6 +36,8 @@ public CameraHandler(MdgaApp app, FilterPostProcessor fpp){
|
||||
dlsf.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);
|
||||
dlsf.setShadowIntensity(0.7f);
|
||||
fpp.addFilter(dlsf);
|
||||
|
||||
app.getRootNode().attachChild(SkyFactory.createSky(app.getAssetManager(), "Images/sky/sky.dds", EnvMapType.EquirectMap).rotate(FastMath.HALF_PI*1,0,FastMath.HALF_PI*0.2f));
|
||||
}
|
||||
|
||||
public void init() {
|
||||
|
||||
@@ -15,7 +15,7 @@ public class ActionTextHandler {
|
||||
private BitmapFont font;
|
||||
private AppSettings appSettings;
|
||||
|
||||
public ActionTextHandler(AppSettings appSettings, AssetManager assetManager, Node guiNode){
|
||||
public ActionTextHandler(Node guiNode, AssetManager assetManager, AppSettings appSettings){
|
||||
root = new Node("actionTextRoot");
|
||||
guiNode.attachChild(root);
|
||||
|
||||
@@ -75,11 +75,11 @@ private Vector3f centerText(float width, float height, Vector3f pos){
|
||||
}
|
||||
|
||||
public void activePlayer(String name, Color color){
|
||||
createTopText(new String[]{name," ist dran!"}, 10,90,new ColorRGBA[]{playerColorToColorRGBA(color),ColorRGBA.White}, 0).addControl(new ZoomControl());
|
||||
createTopText(new String[]{name," ist dran"}, 10,90,new ColorRGBA[]{playerColorToColorRGBA(color),ColorRGBA.White}, 0).addControl(new ZoomControl());
|
||||
}
|
||||
|
||||
public void ownActive(Color color){
|
||||
createTopText(new String[]{"Du"," bist dran!"}, 10,90,new ColorRGBA[]{playerColorToColorRGBA(color),ColorRGBA.White}, 0).addControl(new ZoomControl());
|
||||
createTopText(new String[]{"Du"," bist dran"}, 10,90,new ColorRGBA[]{playerColorToColorRGBA(color),ColorRGBA.White}, 0).addControl(new ZoomControl());
|
||||
}
|
||||
|
||||
public void diceNum(int diceNum, String name, Color color){
|
||||
@@ -103,6 +103,14 @@ public void ownDiceMult(int diceNum, int mult){
|
||||
createTopText(new String[]{String.valueOf(diceNum), " x" + mult + " = " + (diceNum*mult)}, 20, 100, new ColorRGBA[]{ColorRGBA.White,ColorRGBA.Red}, 0);
|
||||
}
|
||||
|
||||
public void drawCard(String name, Color color){
|
||||
createTopText(new String[]{name," erhält eine Bonuskarte"}, 7,70, new ColorRGBA[]{playerColorToColorRGBA(color),ColorRGBA.White}, 0).addControl(new ZoomControl());
|
||||
}
|
||||
|
||||
public void drawCardOwn(Color color){
|
||||
createTopText(new String[]{"Du"," erhälst eine Bonuskarte"}, 5,70, new ColorRGBA[]{playerColorToColorRGBA(color),ColorRGBA.White}, 0).addControl(new ZoomControl());
|
||||
}
|
||||
|
||||
private ColorRGBA playerColorToColorRGBA(Color color){
|
||||
return switch (color){
|
||||
case ARMY -> ColorRGBA.Green;
|
||||
|
||||
@@ -0,0 +1,214 @@
|
||||
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 java.util.*;
|
||||
|
||||
public class CardLayerHandler {
|
||||
private static final Vector3f START = new Vector3f(-1.8f, -3.5f, 0);
|
||||
private static final Vector3f MARGIN = new Vector3f(1.8f, 0, 0);
|
||||
private static final float CARDLAYER_CAMERA_ZOOM = 4;
|
||||
|
||||
private final MdgaApp app;
|
||||
private final FilterPostProcessor fpp;
|
||||
private final Texture2D backTexture;
|
||||
|
||||
private Camera cardLayerCamera;
|
||||
private CardLayer cardLayer;
|
||||
private DiceControl diceControl;
|
||||
|
||||
private final Map<BonusCard, CardControl> bonusCardControlMap = new HashMap<>();
|
||||
private final Map<BonusCard, Integer> bonusCardIntegerMap = new HashMap<>();
|
||||
private final Set<CardControl> selectableCards = new HashSet<>();
|
||||
|
||||
private BonusCard cardSelect = null;
|
||||
|
||||
public CardLayerHandler(MdgaApp app, Texture2D backTexture) {
|
||||
this.app = app;
|
||||
this.fpp = new FilterPostProcessor(app.getAssetManager());
|
||||
this.backTexture = backTexture;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
cardLayerCamera = createOverlayCam();
|
||||
cardLayer = new CardLayer(fpp, cardLayerCamera, backTexture);
|
||||
app.getStateManager().attach(cardLayer);
|
||||
diceControl = new DiceControl(app.getAssetManager());
|
||||
diceControl.create(new Vector3f(0, 0, 0), 1f, false);
|
||||
}
|
||||
|
||||
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 hideDice() {
|
||||
diceControl.hide();
|
||||
}
|
||||
|
||||
public void addCard(BonusCard card) {
|
||||
if (card == BonusCard.HIDDEN) throw new RuntimeException("Can't 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 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 card : select) {
|
||||
selectableCards.add(bonusCardControlMap.get(card));
|
||||
}
|
||||
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 Camera getCardLayerCamera() {
|
||||
return cardLayerCamera;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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);
|
||||
float aspect = (float) originalCam.getWidth() / originalCam.getHeight();
|
||||
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;
|
||||
}
|
||||
|
||||
public void test() {
|
||||
addCard(BonusCard.SHIELD);
|
||||
addCard(BonusCard.SHIELD);
|
||||
addCard(BonusCard.TURBO);
|
||||
addCard(BonusCard.SWAP);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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 CardLayer getCardLayer(){
|
||||
return cardLayer;
|
||||
}
|
||||
}
|
||||
@@ -1,270 +1,100 @@
|
||||
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.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.*;
|
||||
|
||||
import static com.jme3.material.Materials.UNSHADED;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GuiHandler {
|
||||
private final MdgaApp app;
|
||||
private final CardLayerHandler cardLayerHandler;
|
||||
private final PlayerNameHandler playerNameHandler;
|
||||
private final ActionTextHandler actionTextHandler;
|
||||
private final Color ownColor;
|
||||
|
||||
private MdgaApp app;
|
||||
private CardLayer cardLayer;
|
||||
private Map<UUID, BonusCard> uuidBonusCardMap;
|
||||
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;
|
||||
|
||||
public GuiHandler(MdgaApp app, Texture2D backTexture) {
|
||||
public GuiHandler(MdgaApp app, Texture2D backTexture, Color ownColor) {
|
||||
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);
|
||||
diceControl = new DiceControl(app.getAssetManager());
|
||||
diceControl.create(new Vector3f(0,0,0), 1f, false);
|
||||
|
||||
this.ownColor = ownColor;
|
||||
cardLayerHandler = new CardLayerHandler(app, backTexture);
|
||||
playerNameHandler = new PlayerNameHandler(app.getGuiNode(), app.getAssetManager(), app.getContext().getSettings());
|
||||
actionTextHandler = new ActionTextHandler(app.getContext().getSettings(), app.getAssetManager(), app.getGuiNode());
|
||||
actionTextHandler = new ActionTextHandler(app.getGuiNode(), app.getAssetManager(), app.getContext().getSettings());
|
||||
}
|
||||
|
||||
|
||||
public void shutdown(){
|
||||
if(cardLayer != null){
|
||||
cardLayer.shutdown();
|
||||
}
|
||||
|
||||
cardLayer = null;
|
||||
public void init() {
|
||||
cardLayerHandler.init();
|
||||
}
|
||||
|
||||
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 shutdown() {
|
||||
cardLayerHandler.shutdown();
|
||||
}
|
||||
|
||||
public void addCard(BonusCard card, UUID uuid) {
|
||||
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 rollDice(int rollNum) {
|
||||
cardLayerHandler.rollDice(rollNum);
|
||||
}
|
||||
|
||||
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() {
|
||||
cardLayerHandler.showDice();
|
||||
}
|
||||
|
||||
public void showDice(){
|
||||
cardLayer.addSpatial(diceControl.getSpatial());
|
||||
diceControl.spin();
|
||||
public void hideDice() {
|
||||
cardLayerHandler.hideDice();
|
||||
}
|
||||
|
||||
public void hideDice(){
|
||||
diceControl.hide();
|
||||
public void addCard(pp.mdga.game.BonusCard card) {
|
||||
cardLayerHandler.addCard(card);
|
||||
}
|
||||
|
||||
private Vector3f nextPos() {
|
||||
return START.add(MARGIN.mult(bonusCardControlMap.size()));
|
||||
public void clearSelectableCards() {
|
||||
cardLayerHandler.clearSelectableCards();
|
||||
}
|
||||
|
||||
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/Misc/Unshaded.j3md");
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
|
||||
// mat.setTexture("ColorMap", app.getAssetManager().loadTexture(card.getDiffPath()));
|
||||
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));
|
||||
spatial.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
|
||||
CardControl control = new CardControl(app, fpp, cardLayer.getOverlayCam(), rootCard);
|
||||
spatial.addControl(control);
|
||||
return control;
|
||||
}
|
||||
|
||||
public void addPlayer(Color color, String name, boolean own){
|
||||
playerNameHandler.addPlayer(color, name, own);
|
||||
}
|
||||
|
||||
public void setActivePlayer(Color color){
|
||||
playerNameHandler.setActivePlayer(color);
|
||||
}
|
||||
|
||||
private Camera createOverlayCam(){
|
||||
Camera originalCam = app.getCamera();
|
||||
Camera overlayCam = new Camera(originalCam.getWidth(), originalCam.getHeight());
|
||||
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;
|
||||
}
|
||||
|
||||
public void test(){
|
||||
UUID uuid = UUID.randomUUID();
|
||||
UUID uuid1 = UUID.randomUUID();
|
||||
addCard(BonusCard.SHIELD, uuid);
|
||||
addCard(BonusCard.SHIELD, UUID.randomUUID());
|
||||
addCard(BonusCard.TURBO, uuid1);
|
||||
addCard(BonusCard.SWAP, UUID.randomUUID());
|
||||
|
||||
// setSelectableCards(List.of(uuid,uuid1));
|
||||
// showDice();
|
||||
}
|
||||
|
||||
public Camera getCardLayerCamera() {
|
||||
return cardLayerCamera;
|
||||
}
|
||||
|
||||
public CardLayer getCardLayer(){
|
||||
return cardLayer;
|
||||
}
|
||||
|
||||
|
||||
public void setSelectableCards_UUID(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.setHighlight();
|
||||
}
|
||||
}
|
||||
|
||||
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 clearSelectableCards(){
|
||||
for(CardControl control : selectableCards){
|
||||
control.setSelectable(false);
|
||||
control.setHoverable(false);
|
||||
control.unHighlight();
|
||||
control.unSelect();
|
||||
}
|
||||
selectableCards.clear();
|
||||
cardSelect = null;
|
||||
public void setSelectableCards(List<pp.mdga.game.BonusCard> select) {
|
||||
cardLayerHandler.setSelectableCards(select);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
cardLayerHandler.selectCard(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
|
||||
public Camera getCardLayerCamera() {
|
||||
return cardLayerHandler.getCardLayerCamera();
|
||||
}
|
||||
|
||||
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 Node getCardLayerRootNode(){
|
||||
return cardLayerHandler.getCardLayer().getRootNode();
|
||||
}
|
||||
|
||||
public void addPlayer(Color color, String name, boolean own) {
|
||||
playerNameHandler.addPlayer(color, name, own);
|
||||
}
|
||||
|
||||
public void setActivePlayer(Color color) {
|
||||
playerNameHandler.setActivePlayer(color);
|
||||
|
||||
if (ownColor == color) actionTextHandler.ownActive(color);
|
||||
else actionTextHandler.activePlayer(playerNameHandler.getName(color), color);
|
||||
}
|
||||
|
||||
public void test() {
|
||||
cardLayerHandler.test();
|
||||
}
|
||||
|
||||
public void test2() {
|
||||
actionTextHandler.drawCardOwn(Color.NAVY);
|
||||
}
|
||||
|
||||
public void shield(){
|
||||
SymbolControl control = createSymbol(Asset.shieldSymbol);
|
||||
cardLayer.addSpatial(control.getSpatial());
|
||||
control.shield();
|
||||
cardLayerHandler.shield();
|
||||
}
|
||||
|
||||
public void swap(){
|
||||
SymbolControl control = createSymbol(Asset.swapSymbol);
|
||||
cardLayer.addSpatial(control.getSpatial());
|
||||
control.swap();
|
||||
cardLayerHandler.swap();
|
||||
}
|
||||
|
||||
public void turbo(){
|
||||
SymbolControl control = createSymbol(Asset.turboSymbol);
|
||||
cardLayer.addSpatial(control.getSpatial());
|
||||
control.turbo();
|
||||
}
|
||||
|
||||
public void test2(){
|
||||
actionTextHandler.ownDiceMult(5,2);
|
||||
cardLayerHandler.turbo();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,244 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -25,8 +25,7 @@ public class PlayerNameHandler {
|
||||
private final AssetManager assetManager;
|
||||
private Color ownColor;
|
||||
|
||||
|
||||
private static final float PADDING_TOP = 50;
|
||||
private static final float PADDING_TOP = 35;
|
||||
private static final float PADDING_LEFT = 50;
|
||||
private static final float MARGIN_NAMES = 50;
|
||||
private static final float IMAGE_SIZE = 50;
|
||||
@@ -108,5 +107,9 @@ public void setActivePlayer(Color color) {
|
||||
drawPlayers();
|
||||
}
|
||||
|
||||
public String getName(Color color){
|
||||
return colorNameMap.get(color);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,11 @@ public class ZoomControl extends AbstractControl {
|
||||
private float zoomSpeed = 1f;
|
||||
private float zoomFactor = 1f;
|
||||
|
||||
public ZoomControl(){}
|
||||
|
||||
public ZoomControl(float speed) {
|
||||
zoomSpeed = speed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSpatial(Spatial spatial){
|
||||
|
||||
@@ -1,14 +1,6 @@
|
||||
package pp.mdga.client.view;
|
||||
|
||||
import com.jme3.input.KeyInput;
|
||||
import com.jme3.input.MouseInput;
|
||||
import com.jme3.input.controls.ActionListener;
|
||||
import com.jme3.input.controls.KeyTrigger;
|
||||
import com.jme3.input.controls.MouseButtonTrigger;
|
||||
import com.jme3.post.FilterPostProcessor;
|
||||
import com.jme3.post.filters.ComposeFilter;
|
||||
import com.jme3.shadow.DirectionalLightShadowFilter;
|
||||
import com.jme3.shadow.EdgeFilteringMode;
|
||||
import com.jme3.texture.FrameBuffer;
|
||||
import com.jme3.texture.Image;
|
||||
import com.jme3.texture.Texture2D;
|
||||
@@ -21,10 +13,6 @@
|
||||
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;
|
||||
@@ -53,7 +41,7 @@ public GameView(MdgaApp app) {
|
||||
backFrameBuffer.addColorTarget(FrameBuffer.FrameBufferTarget.newTarget(backTexture));
|
||||
app.getViewPort().setOutputFrameBuffer(backFrameBuffer);
|
||||
|
||||
this.guiHandler = new GuiHandler(app, backTexture);
|
||||
this.guiHandler = new GuiHandler(app, backTexture, ownColor);
|
||||
|
||||
leaveButton = new SingleButtonLeftDialog(app, settingsNode, "Verlassen", () -> leaveGame());
|
||||
|
||||
|
||||
BIN
Projekte/mdga/client/src/main/resources/Images/sky/sky.dds
Normal file
BIN
Projekte/mdga/client/src/main/resources/Images/sky/sky.dds
Normal file
Binary file not shown.
@@ -9,24 +9,14 @@
|
||||
*/
|
||||
public class AcquireCardNotification extends Notification{
|
||||
|
||||
private UUID cardId;
|
||||
private BonusCard bonusCard;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param cardId The id of the card that was acquired.
|
||||
* @param bonusCard The type of the card that was acquired.
|
||||
*/
|
||||
public AcquireCardNotification(BonusCard bonusCard, UUID cardId) {
|
||||
public AcquireCardNotification(BonusCard bonusCard) {
|
||||
this.bonusCard = bonusCard;
|
||||
this.cardId = cardId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the id of the card that was acquired.
|
||||
* @return The id of the card that was acquired.
|
||||
*/
|
||||
public UUID getCardId() {
|
||||
return cardId;
|
||||
}
|
||||
|
||||
public BonusCard getBonusCard() {
|
||||
|
||||
Reference in New Issue
Block a user