Work
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
public enum Asset {
|
||||
bigTent,
|
||||
cardStack,
|
||||
cir("Models/+cir/cir_newOrigin.obj"),
|
||||
cir("Models/cir/cir_newOrigin.obj"),
|
||||
heer("Models/heer/heer_newOrigin.obj"),
|
||||
jet,
|
||||
lw("Models/lw/lw_newOrigin.obj"),
|
||||
|
||||
@@ -22,10 +22,15 @@ public class MdgaApp extends SimpleApplication {
|
||||
private ModelSyncronizer modelSyncronizer;
|
||||
|
||||
MdgaView view = null;
|
||||
private MdgaState state = MdgaState.MAIN;
|
||||
private MdgaState state = null;
|
||||
|
||||
private static float imageScale = 1.5f;
|
||||
|
||||
private MdgaView mainView;
|
||||
private MdgaView lobbyView;
|
||||
private MdgaView gameView;
|
||||
private MdgaView ceremonyView;
|
||||
|
||||
public static void main(String[] args) {
|
||||
AppSettings settings = new AppSettings(true);
|
||||
settings.setSamples(128);
|
||||
@@ -54,7 +59,12 @@ public void simpleInitApp() {
|
||||
inputSynchronizer = new InputSynchronizer(this);
|
||||
modelSyncronizer = new ModelSyncronizer(this);
|
||||
|
||||
enter(state);
|
||||
mainView = new MainView(this);
|
||||
lobbyView = new LobbyView(this);
|
||||
gameView = new GameView(this);
|
||||
ceremonyView = new CeremonyView(this);
|
||||
|
||||
enter(MdgaState.MAIN);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,16 +83,16 @@ public void enter(MdgaState state) {
|
||||
|
||||
switch (state) {
|
||||
case MAIN:
|
||||
view = new MainView(this);
|
||||
view = mainView;
|
||||
break;
|
||||
case LOBBY:
|
||||
view = new LobbyView(this);
|
||||
view = lobbyView;
|
||||
break;
|
||||
case GAME:
|
||||
view = new GameView(this);
|
||||
view = gameView;
|
||||
break;
|
||||
case CEREMONY:
|
||||
view = new CeremonyView(this);
|
||||
view = ceremonyView;
|
||||
break;
|
||||
case NONE:
|
||||
throw new RuntimeException("cant enter state NONE");
|
||||
@@ -93,10 +103,6 @@ public void enter(MdgaState state) {
|
||||
view.enter();
|
||||
}
|
||||
|
||||
public void afteGameCleanup() {
|
||||
//TODO
|
||||
}
|
||||
|
||||
public AnimationHandler getAnimationHandler() {
|
||||
return animationHandler;
|
||||
}
|
||||
|
||||
@@ -34,29 +34,29 @@ public class BoardHandler {
|
||||
private Map<UUID, Color> pieceColor;
|
||||
private Set<OutlineControl> outlineControls;
|
||||
|
||||
private Node node;
|
||||
private Node node = new Node();
|
||||
private Node rootNode;
|
||||
|
||||
private final FilterPostProcessor fpp;
|
||||
private FilterPostProcessor fpp;
|
||||
|
||||
private boolean isInitialised;
|
||||
|
||||
private boolean scheduleInit = false;
|
||||
private boolean scheduleShutdown = false;
|
||||
|
||||
private List<PieceControl> selectableOwnPieces = new ArrayList<>();
|
||||
private List<PieceControl> selectableEnemyPieces = new ArrayList<>();
|
||||
private PieceControl selectedOwnPiece;
|
||||
private PieceControl selectedEnemyPiece;
|
||||
private DiceControl diceControl;
|
||||
|
||||
public BoardHandler(MdgaApp app, FilterPostProcessor fpp) {
|
||||
public BoardHandler(MdgaApp app, Node node3d, FilterPostProcessor fpp) {
|
||||
if(app == null) throw new RuntimeException("app is null");
|
||||
|
||||
this.isInitialised = false;
|
||||
this.app = app;
|
||||
this.rootNode = node3d;
|
||||
this.fpp = fpp;
|
||||
selectedEnemyPiece = null;
|
||||
selectedOwnPiece = null;
|
||||
|
||||
initMap();
|
||||
}
|
||||
|
||||
@@ -66,11 +66,7 @@ private void addFigureToPlayerMap(Color col, AssetOnMap assetOnMap) {
|
||||
}
|
||||
|
||||
private void initMap() {
|
||||
if (isInitialised) return;
|
||||
|
||||
this.isInitialised = true;
|
||||
this.node = new Node("Asset Node");
|
||||
|
||||
this.pieces = new HashMap<>();
|
||||
this.colorAssetsMap = new HashMap<>();
|
||||
this.infield = new ArrayList<>(40);
|
||||
@@ -79,12 +75,12 @@ private void initMap() {
|
||||
this.waitingPiecesMap = new HashMap<>();
|
||||
this.pieceColor = new HashMap<>();
|
||||
this.outlineControls = new HashSet<>();
|
||||
|
||||
// Initialize dice
|
||||
diceControl = new DiceControl(app.getAssetManager());
|
||||
diceControl.create(new Vector3f(0, 0, 0), 0.7f, true);
|
||||
|
||||
|
||||
|
||||
|
||||
// Load assets and populate the node
|
||||
List<AssetOnMap> assetOnMaps = MapLoader.loadMap(MAP_NAME);
|
||||
|
||||
for (AssetOnMap assetOnMap : assetOnMaps) {
|
||||
@@ -103,7 +99,6 @@ private void initMap() {
|
||||
case node_wait_blue -> addHomeNode(waitingNodesMap, Color.NAVY, assetOnMap);
|
||||
case node_wait_green -> addHomeNode(waitingNodesMap, Color.ARMY, assetOnMap);
|
||||
case node_wait_yellow -> addHomeNode(waitingNodesMap, Color.CYBER, assetOnMap);
|
||||
|
||||
default -> displayAsset(assetOnMap);
|
||||
}
|
||||
}
|
||||
@@ -122,14 +117,20 @@ private Color assetToColor(Asset asset) {
|
||||
private Spatial createModel(Asset asset, Vector3f pos, float rot) {
|
||||
String modelName = asset.getModelPath();
|
||||
String texName = asset.getDiffPath();
|
||||
|
||||
// Load the model
|
||||
Spatial model = app.getAssetManager().loadModel(modelName);
|
||||
model.scale(asset.getSize());
|
||||
model.rotate((float) Math.toRadians(0), 0, (float) Math.toRadians(rot));
|
||||
model.setLocalTranslation(pos);
|
||||
model.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
|
||||
|
||||
// Set material
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
|
||||
mat.setTexture("DiffuseMap", app.getAssetManager().loadTexture(texName));
|
||||
model.setMaterial(mat);
|
||||
|
||||
// Attach to the asset node
|
||||
node.attachChild(model);
|
||||
|
||||
return model;
|
||||
@@ -332,23 +333,46 @@ public void swapPieces(UUID piece1, UUID piece2){
|
||||
}
|
||||
|
||||
public void init() {
|
||||
// outlineControls.forEach((outlineControl) -> {
|
||||
// outlineControl.outline(outlineControl.getColor());
|
||||
// });
|
||||
if (isInitialised) return;
|
||||
|
||||
rootNode.attachChild(node);
|
||||
|
||||
app.getViewPort().addProcessor(fpp);
|
||||
|
||||
isInitialised = true;
|
||||
scheduleInit = false;
|
||||
app.getRootNode().attachChild(node);
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
outlineControls.forEach((outlineControl) -> {
|
||||
outlineControl.deOutline();
|
||||
});
|
||||
if (!isInitialised) return;
|
||||
|
||||
outlineControls.forEach(OutlineControl::deOutline);
|
||||
outlineControls.clear();
|
||||
|
||||
rootNode.detachChild(node);
|
||||
|
||||
if (fpp != null) {
|
||||
app.getViewPort().removeProcessor(fpp);
|
||||
}
|
||||
|
||||
pieces.clear();
|
||||
colorAssetsMap.clear();
|
||||
homeNodesMap.clear();
|
||||
waitingNodesMap.clear();
|
||||
waitingPiecesMap.clear();
|
||||
pieceColor.clear();
|
||||
|
||||
selectableOwnPieces.clear();
|
||||
selectableEnemyPieces.clear();
|
||||
selectedEnemyPiece = null;
|
||||
selectedOwnPiece = null;
|
||||
|
||||
if (diceControl != null) {
|
||||
diceControl.hide();
|
||||
}
|
||||
|
||||
isInitialised = false;
|
||||
scheduleShutdown = false;
|
||||
app.getRootNode().detachChild(node);
|
||||
|
||||
System.gc();
|
||||
}
|
||||
|
||||
//List<Pieces>
|
||||
@@ -375,9 +399,6 @@ public void outline(int index){
|
||||
outlineControls.add(infield.get(index));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//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) {
|
||||
if(pieces.size() != moveIndexe.size() || pieces.size() != homeMoves.size()) throw new RuntimeException("arrays are not the same size");
|
||||
@@ -500,6 +521,4 @@ public void showDice(Color color){
|
||||
public void hideDice(){
|
||||
diceControl.hide();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
import com.jme3.light.DirectionalLight;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.FastMath;
|
||||
import com.jme3.math.Quaternion;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.post.FilterPostProcessor;
|
||||
import com.jme3.shadow.DirectionalLightShadowFilter;
|
||||
@@ -18,8 +19,19 @@ public class CameraHandler {
|
||||
|
||||
private static final int SHADOWMAP_SIZE = 1024 * 8;
|
||||
|
||||
private Vector3f defaultCameraPosition;
|
||||
private Quaternion defaultCameraRotation;
|
||||
|
||||
FilterPostProcessor fpp;
|
||||
DirectionalLightShadowFilter dlsf;
|
||||
|
||||
public CameraHandler(MdgaApp app, FilterPostProcessor fpp) {
|
||||
this.app = app;
|
||||
this.fpp = fpp;
|
||||
|
||||
// Save the default camera state
|
||||
this.defaultCameraPosition = app.getCamera().getLocation().clone();
|
||||
this.defaultCameraRotation = app.getCamera().getRotation().clone();
|
||||
|
||||
sun = new DirectionalLight();
|
||||
sun.setColor(ColorRGBA.White);
|
||||
@@ -28,22 +40,29 @@ public CameraHandler(MdgaApp app, FilterPostProcessor fpp){
|
||||
ambient = new AmbientLight();
|
||||
ambient.setColor(new ColorRGBA(0.3f, 0.3f, 0.3f, 1));
|
||||
|
||||
DirectionalLightShadowFilter dlsf = new DirectionalLightShadowFilter(app.getAssetManager(), SHADOWMAP_SIZE, 4);
|
||||
dlsf = new DirectionalLightShadowFilter(app.getAssetManager(), SHADOWMAP_SIZE, 4);
|
||||
dlsf.setLight(sun);
|
||||
dlsf.setEnabled(true);
|
||||
dlsf.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);
|
||||
dlsf.setShadowIntensity(0.7f);
|
||||
fpp.addFilter(dlsf);
|
||||
}
|
||||
|
||||
public void init() {
|
||||
app.getRootNode().addLight(sun);
|
||||
app.getRootNode().addLight(ambient);
|
||||
|
||||
fpp.addFilter(dlsf);
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
app.getRootNode().removeLight(sun);
|
||||
app.getRootNode().removeLight(ambient);
|
||||
|
||||
// Reset the camera to its default state
|
||||
app.getCamera().setLocation(defaultCameraPosition);
|
||||
app.getCamera().setRotation(defaultCameraRotation);
|
||||
|
||||
fpp.removeFilter(dlsf);
|
||||
}
|
||||
|
||||
public void update(float scroll, float rotation) {
|
||||
@@ -77,5 +96,4 @@ public void update(float scroll, float rotation) {
|
||||
|
||||
app.getCamera().lookAt(Vector3f.ZERO, Vector3f.UNIT_Z);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -94,6 +94,8 @@ public String getString() {
|
||||
return field.getText();
|
||||
}
|
||||
|
||||
public void setString(String string) { field.setText(string); }
|
||||
|
||||
public void reset() {
|
||||
field.setText("");
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ public HostDialog(MdgaApp app, Node node, MainView view) {
|
||||
this.view = view;
|
||||
|
||||
portInput = new InputButton(app, node, "Port: ", 5);
|
||||
portInput.setString("11111");
|
||||
|
||||
hostButton = new ButtonRight(app, node, view::forward, "Spiel hosten", 10);
|
||||
backButton = new ButtonLeft(app, node, view::back, "Zurück", 10);
|
||||
|
||||
@@ -25,6 +25,7 @@ public JoinDialog(MdgaApp app, Node node, MainView view) {
|
||||
|
||||
ipInput = new InputButton(app, node, "Ip: ", 15);
|
||||
portInput = new InputButton(app, node, "Port: ", 5);
|
||||
portInput.setString("11111");
|
||||
|
||||
joinButton = new ButtonRight(app, node, view::forward, "Spiel beitreten", 10);
|
||||
backButton = new ButtonLeft(app, node, view::back, "Zurück", 10);
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
package pp.mdga.client.dialog2;
|
||||
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.scene.Node;
|
||||
import com.simsilica.lemur.Button;
|
||||
import com.simsilica.lemur.Container;
|
||||
import com.simsilica.lemur.HAlignment;
|
||||
import com.simsilica.lemur.VAlignment;
|
||||
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
||||
import pp.mdga.client.MdgaApp;
|
||||
|
||||
public abstract class Dialog {
|
||||
protected final ColorRGBA COLOR_DEFAULT = ColorRGBA.Gray;
|
||||
protected final ColorRGBA COLOR_HOVER = ColorRGBA.DarkGray;
|
||||
|
||||
protected Container container;
|
||||
|
||||
protected final MdgaApp app;
|
||||
private final Node node;
|
||||
|
||||
protected final float vertical_step;
|
||||
protected final float horitontal_step;
|
||||
|
||||
protected float fontSize = 35;
|
||||
|
||||
public Dialog(MdgaApp app, Node node) {
|
||||
this.app = app;
|
||||
this.node = node;
|
||||
this.container = new Container();
|
||||
|
||||
this.horitontal_step = app.getCamera().getWidth() / 16;
|
||||
this.vertical_step = app.getCamera().getHeight() / 9;
|
||||
|
||||
//int val = (int) (32 * Math.min(app.getResolutionFactor() * 0.9f, 1));
|
||||
//fontSize = val;
|
||||
}
|
||||
|
||||
public void show() {
|
||||
node.attachChild(container);
|
||||
}
|
||||
|
||||
public void hide () {
|
||||
node.detachChild(container);
|
||||
}
|
||||
|
||||
protected void createButton(String label, Runnable action, Vector3f size) {
|
||||
Button button = new Button(label);
|
||||
button.addClickCommands(source -> action.run());
|
||||
button.setFontSize(fontSize);
|
||||
button.setHighlightColor(ColorRGBA.White);
|
||||
button.setColor(ColorRGBA.Black);
|
||||
button.setPreferredSize(size);
|
||||
button.setTextHAlignment(HAlignment.Center);
|
||||
button.setTextVAlignment(VAlignment.Center);
|
||||
|
||||
QuadBackgroundComponent background = new QuadBackgroundComponent(COLOR_DEFAULT);
|
||||
//background.setMargin(5 * app.getResolutionFactor(), 5 * app.getResolutionFactor());
|
||||
button.setBackground(background);
|
||||
|
||||
button.addCommands(com.simsilica.lemur.Button.ButtonAction.HighlightOn, (source) -> {
|
||||
QuadBackgroundComponent hoverBackground = new QuadBackgroundComponent(COLOR_HOVER);
|
||||
// hoverBackground.setMargin(5 * app.getResolutionFactor(), 5 * app.getResolutionFactor());
|
||||
source.setBackground(hoverBackground);
|
||||
button.setHighlightColor(ColorRGBA.White);
|
||||
button.setColor(ColorRGBA.Black);
|
||||
});
|
||||
|
||||
button.addCommands(com.simsilica.lemur.Button.ButtonAction.HighlightOff, (source) -> {
|
||||
QuadBackgroundComponent normalBackground = new QuadBackgroundComponent(COLOR_DEFAULT);
|
||||
// normalBackground.setMargin(5 * app.getResolutionFactor(), 5 * app.getResolutionFactor());
|
||||
source.setBackground(normalBackground);
|
||||
button.setHighlightColor(ColorRGBA.White);
|
||||
button.setColor(ColorRGBA.Black);
|
||||
});
|
||||
|
||||
container.addChild(button);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
package pp.mdga.client.dialog2;
|
||||
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.scene.Node;
|
||||
import com.jme3.texture.Texture;
|
||||
import com.simsilica.lemur.*;
|
||||
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
||||
import com.simsilica.lemur.component.SpringGridLayout;
|
||||
import pp.mdga.client.MdgaApp;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class SettingsDialog extends Dialog {
|
||||
private TextField nameInput;
|
||||
|
||||
//private HashMap<Slider, PercentRunnable> map = new HashMap<Slider, PercentRunnable>();
|
||||
//private HashMap<Slider, GetPercentRunnable> map2 = new HashMap<Slider, GetPercentRunnable>();
|
||||
|
||||
public SettingsDialog(MdgaApp app, Node node, String path) {
|
||||
super(app, node);
|
||||
|
||||
QuadBackgroundComponent quad1 = new QuadBackgroundComponent(ColorRGBA.Gray);
|
||||
//quad1.setMargin(100 * app.getResolutionFactor(), 50 * app.getResolutionFactor());
|
||||
container.setBackground(quad1);
|
||||
|
||||
Texture texture = app.getAssetManager().loadTexture(path);
|
||||
|
||||
QuadBackgroundComponent b = new QuadBackgroundComponent(texture);
|
||||
|
||||
Panel imagePanel = new Panel();
|
||||
imagePanel.setBackground(b);
|
||||
|
||||
// container.addChild(imagePanel).setPreferredSize(new Vector3f((texture.getImage().getWidth() / 2) * app.getResolutionFactor(), (texture.getImage().getHeight() / 2) * app.getResolutionFactor(), 0));
|
||||
|
||||
//abstandshalter
|
||||
// container.addChild(new Panel(80 * app.getResolutionFactor(), 50 * app.getResolutionFactor(), ColorRGBA.Gray));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
super.show();
|
||||
|
||||
container.setLocalTranslation(
|
||||
app.getCamera().getWidth() / 2 - container.getPreferredSize().x / 2,
|
||||
app.getCamera().getHeight() / 2 + container.getPreferredSize().y / 2,
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hide() {
|
||||
super.hide();
|
||||
}
|
||||
|
||||
public void addButton(String label, Runnable action, Vector3f size) {
|
||||
createButton(label, action, size);
|
||||
}
|
||||
|
||||
/*public void addSlider(String label, PercentRunnable action, GetPercentRunnable action2, Vector3f size, int start) {
|
||||
Container subContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y));
|
||||
|
||||
Slider slider = new Slider("slider");
|
||||
|
||||
QuadBackgroundComponent background = new QuadBackgroundComponent(ColorRGBA.DarkGray);
|
||||
slider.setBackground(background);
|
||||
|
||||
slider.setPreferredSize(size);
|
||||
slider.setModel(new DefaultRangedValueModel(0, 100, start));
|
||||
//slider.setPreferredSize(new Vector3f(150 * app.getResolutionFactor(), 30 * app.getResolutionFactor(), 0));
|
||||
slider.getDecrementButton().setText(" - ");
|
||||
slider.getIncrementButton().setText(" + ");
|
||||
// slider.getDecrementButton().setFontSize(25 * app.getResolutionFactor());
|
||||
// slider.getIncrementButton().setFontSize(25 * app.getResolutionFactor());
|
||||
|
||||
Label nameLabel = new Label(label);
|
||||
nameLabel.setFontSize(fontSize);
|
||||
nameLabel.setColor(ColorRGBA.Black);
|
||||
// nameLabel.setPreferredSize(new Vector3f(150 * app.getResolutionFactor(), 10 * app.getResolutionFactor(), 0));
|
||||
|
||||
subContainer.addChild(nameLabel);
|
||||
subContainer.addChild(slider);
|
||||
|
||||
container.addChild(subContainer);
|
||||
|
||||
map.put(slider, action);
|
||||
map2.put(slider, action2);
|
||||
|
||||
//abstandshalter
|
||||
// container.addChild(new Panel(20 * app.getResolutionFactor(), 10 * app.getResolutionFactor(), ColorRGBA.Gray));
|
||||
}
|
||||
|
||||
public void initVolume() {
|
||||
map2.forEach((slider, runnable) -> {
|
||||
double val = (double) runnable.get();
|
||||
slider.getModel().setPercent(val);
|
||||
});
|
||||
}
|
||||
|
||||
public void update() {
|
||||
map.forEach((slider, runnable) -> {
|
||||
float val = (float) slider.getModel().getPercent();
|
||||
runnable.run(val);
|
||||
});
|
||||
}*/
|
||||
}
|
||||
@@ -10,19 +10,27 @@
|
||||
import pp.mdga.client.Asset;
|
||||
|
||||
public class ActionTextHandler {
|
||||
private Node root;
|
||||
private Node node;
|
||||
|
||||
public ActionTextHandler(AppSettings appSettings, AssetManager assetManager, Node guiNode){
|
||||
root = new Node("actionTextRoot");
|
||||
guiNode.attachChild(root);
|
||||
private Node textWithSpacing;
|
||||
|
||||
root.setLocalTranslation(center(appSettings.getWidth(), appSettings.getHeight(), Vector3f.ZERO));
|
||||
public ActionTextHandler(AppSettings appSettings, AssetManager assetManager, Node node){
|
||||
BitmapFont playerFont = assetManager.loadFont("Fonts/Gunplay.fnt");
|
||||
|
||||
root.attachChild(createTextWithSpacing(playerFont, "TEST", 20f, 250));
|
||||
textWithSpacing = createTextWithSpacing(playerFont, "TEST", 20f, 250);
|
||||
|
||||
textWithSpacing.setLocalTranslation(center(appSettings.getWidth(), appSettings.getHeight(), Vector3f.ZERO));
|
||||
}
|
||||
|
||||
public static Node createTextWithSpacing(BitmapFont font, String text, float spacing, float size) {
|
||||
public void show () {
|
||||
node.attachChild(textWithSpacing);
|
||||
}
|
||||
|
||||
public void hide() {
|
||||
node.detachChild(textWithSpacing);
|
||||
}
|
||||
|
||||
private static Node createTextWithSpacing(BitmapFont font, String text, float spacing, float size) {
|
||||
Node textNode = new Node("TextWithSpacing");
|
||||
Node center = new Node();
|
||||
float xOffset = 0;
|
||||
@@ -45,9 +53,9 @@ public static Node createTextWithSpacing(BitmapFont font, String text, float spa
|
||||
private Vector3f center(float width, float height, Vector3f pos){
|
||||
return new Vector3f(pos.x+width/2, pos.y+height/2,0);
|
||||
}
|
||||
|
||||
private Vector3f centerText(float width, float height, Vector3f pos){
|
||||
return center(-width, height, pos);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
import com.jme3.renderer.queue.RenderQueue;
|
||||
import com.jme3.scene.Node;
|
||||
import com.jme3.scene.Spatial;
|
||||
import com.jme3.texture.FrameBuffer;
|
||||
import com.jme3.texture.Image;
|
||||
import com.jme3.texture.Texture2D;
|
||||
import pp.mdga.client.Asset;
|
||||
import pp.mdga.client.MdgaApp;
|
||||
@@ -29,12 +31,10 @@ public class GuiHandler {
|
||||
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;
|
||||
|
||||
@@ -42,10 +42,13 @@ public class GuiHandler {
|
||||
private BonusCard cardSelect = null;
|
||||
private PlayerNameHandler playerNameHandler;
|
||||
|
||||
public GuiHandler(MdgaApp app, Texture2D backTexture) {
|
||||
private Node rootNode;
|
||||
|
||||
public GuiHandler(MdgaApp app, Node node) {
|
||||
this.app = app;
|
||||
this.fpp = new FilterPostProcessor(app.getAssetManager());
|
||||
this.backTexture = backTexture;
|
||||
this.rootNode = node;
|
||||
|
||||
cardLayerCamera = createOverlayCam();
|
||||
uuidBonusCardMap = new HashMap<>();
|
||||
bonusCardIntegerMap = new HashMap<>();
|
||||
@@ -53,22 +56,29 @@ public GuiHandler(MdgaApp app, Texture2D backTexture) {
|
||||
}
|
||||
|
||||
public void init(){
|
||||
FrameBuffer backFrameBuffer = new FrameBuffer(app.getCamera().getWidth(), app.getCamera().getHeight(), 1);
|
||||
Texture2D backTexture = new Texture2D(app.getCamera().getWidth(), app.getCamera().getHeight(), Image.Format.RGBA8);
|
||||
backFrameBuffer.setDepthTarget(FrameBuffer.FrameBufferTarget.newTarget(Image.Format.Depth));
|
||||
backFrameBuffer.addColorTarget(FrameBuffer.FrameBufferTarget.newTarget(backTexture));
|
||||
|
||||
app.getViewPort().setOutputFrameBuffer(backFrameBuffer);
|
||||
|
||||
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());
|
||||
new ActionTextHandler(app.getContext().getSettings(), app.getAssetManager(), app.getGuiNode());
|
||||
playerNameHandler = new PlayerNameHandler(rootNode, app.getAssetManager(), app.getContext().getSettings());
|
||||
}
|
||||
|
||||
|
||||
public void shutdown(){
|
||||
if(cardLayer != null){
|
||||
cardLayer.shutdown();
|
||||
}
|
||||
|
||||
cardLayer = null;
|
||||
|
||||
app.getViewPort().setOutputFrameBuffer(null);
|
||||
}
|
||||
|
||||
private Asset bonusToAsset(BonusCard card){
|
||||
@@ -113,25 +123,6 @@ private Vector3f nextPos() {
|
||||
return START.add(MARGIN.mult(bonusCardControlMap.size()));
|
||||
}
|
||||
|
||||
private CardControl createCard(Asset card, Vector3f pos){
|
||||
Node rootCard = new Node("Root Card");
|
||||
Spatial spatial = app.getAssetManager().loadModel(card.getModelPath());
|
||||
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);
|
||||
}
|
||||
@@ -140,33 +131,6 @@ 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;
|
||||
}
|
||||
@@ -175,7 +139,6 @@ public CardLayer getCardLayer(){
|
||||
return cardLayer;
|
||||
}
|
||||
|
||||
|
||||
public void setSelectableCards_UUID(List<UUID> selectUuids) {
|
||||
for(UUID uuid : selectUuids) {
|
||||
selectableCards.add(bonusCardControlMap.get(uuidBonusCardMap.get(uuid)));
|
||||
@@ -221,28 +184,6 @@ public void selectCard(CardControl cardControl) {
|
||||
cardControl.select();
|
||||
cardSelect = getKeyByValue(bonusCardControlMap, cardControl);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static <K, V> K getKeyByValue(Map<K, V> map, V value) {
|
||||
for (Map.Entry<K, V> entry : map.entrySet()) {
|
||||
if (entry.getValue().equals(value)) {
|
||||
return entry.getKey();
|
||||
}
|
||||
}
|
||||
return null; // Key not found
|
||||
}
|
||||
|
||||
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 void shield(){
|
||||
@@ -264,5 +205,58 @@ public void turbo(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
private 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
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,16 +35,27 @@ public class PlayerNameHandler {
|
||||
private static final ColorRGBA ACTIVE_COLOR = ColorRGBA.Blue;
|
||||
private static final ColorRGBA OWN_COLOR = ColorRGBA.Cyan;
|
||||
|
||||
private final Node guiNode;
|
||||
|
||||
public PlayerNameHandler(Node guiNode, AssetManager assetManager, AppSettings appSettings){
|
||||
this.guiNode = guiNode;
|
||||
|
||||
playerFont = assetManager.loadFont("Fonts/Gunplay.fnt");
|
||||
playerNameNode = new Node("player name node");
|
||||
playerOrder = new ArrayList<>();
|
||||
colorNameMap = new HashMap<>();
|
||||
guiNode.attachChild(playerNameNode);
|
||||
this.appSettings = appSettings;
|
||||
this.assetManager = assetManager;
|
||||
}
|
||||
|
||||
public void show() {
|
||||
guiNode.attachChild(playerNameNode);
|
||||
}
|
||||
|
||||
public void hide() {
|
||||
guiNode.detachChild(playerNameNode);
|
||||
}
|
||||
|
||||
private void drawPlayers(){
|
||||
playerNameNode.detachAllChildren();
|
||||
|
||||
|
||||
@@ -144,6 +144,4 @@ private float easeInOut(float t) {
|
||||
private float easeIn(float t) {
|
||||
return t * t * t * t;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
import com.jme3.input.controls.MouseButtonTrigger;
|
||||
import com.jme3.post.FilterPostProcessor;
|
||||
import com.jme3.post.filters.ComposeFilter;
|
||||
import com.jme3.renderer.ViewPort;
|
||||
import com.jme3.shadow.DirectionalLightShadowFilter;
|
||||
import com.jme3.shadow.EdgeFilteringMode;
|
||||
import com.jme3.texture.FrameBuffer;
|
||||
@@ -34,51 +35,29 @@ public class GameView extends MdgaView {
|
||||
|
||||
private Color ownColor = null;
|
||||
|
||||
private FilterPostProcessor fpp;
|
||||
|
||||
public GameView(MdgaApp app) {
|
||||
super(app);
|
||||
|
||||
cheatButton = new ButtonRight(app, guiNode, () -> app.getModelSyncronizer().enter(MdgaState.CEREMONY), "Weiter (CHEAT)", 1);
|
||||
|
||||
FilterPostProcessor fpp = new FilterPostProcessor(app.getAssetManager());
|
||||
fpp = new FilterPostProcessor(app.getAssetManager());
|
||||
this.camera = new CameraHandler(app, fpp);
|
||||
this.boardHandler = new BoardHandler(app, fpp);
|
||||
this.boardHandler = new BoardHandler(app, rootNode, fpp);
|
||||
|
||||
//TODO sollte das onLeave nicht vlt rückgänging gemacht werden??
|
||||
app.getViewPort().addProcessor(fpp);
|
||||
|
||||
FrameBuffer backFrameBuffer = new FrameBuffer(app.getCamera().getWidth(), app.getCamera().getHeight(), 1);
|
||||
Texture2D backTexture = new Texture2D(app.getCamera().getWidth(), app.getCamera().getHeight(), Image.Format.RGBA8);
|
||||
backFrameBuffer.setDepthTarget(FrameBuffer.FrameBufferTarget.newTarget(Image.Format.Depth));
|
||||
backFrameBuffer.addColorTarget(FrameBuffer.FrameBufferTarget.newTarget(backTexture));
|
||||
app.getViewPort().setOutputFrameBuffer(backFrameBuffer);
|
||||
|
||||
this.guiHandler = new GuiHandler(app, backTexture);
|
||||
//TODO ---------------------------------------------------------
|
||||
guiHandler = new GuiHandler(app, guiNode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnter() {
|
||||
cheatButton.show();
|
||||
|
||||
camera.init();
|
||||
boardHandler.init();
|
||||
guiHandler.init();
|
||||
|
||||
cheatButton.show();
|
||||
|
||||
|
||||
// boardHandler.addPlayer(Color.AIRFORCE, test);
|
||||
// boardHandler.movePieceStart(player0, 0);
|
||||
// boardHandler.enableHover(player0);
|
||||
// boardHandler.enableHover(player1);
|
||||
// boardHandler.highlight(player0, true);
|
||||
|
||||
|
||||
|
||||
// boardHandler.outline(player0, true);
|
||||
|
||||
// boardHandler.outline(10);
|
||||
|
||||
guiHandler.test();
|
||||
app.getViewPort().addProcessor(fpp);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,6 +67,8 @@ public void onLeave() {
|
||||
guiHandler.shutdown();
|
||||
|
||||
cheatButton.hide();
|
||||
|
||||
app.getViewPort().removeProcessor(fpp);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -108,8 +89,6 @@ protected void onLeaveOverlay(Overlay overlay)
|
||||
|
||||
private void leaveGame() {
|
||||
app.getModelSyncronizer().leave();
|
||||
|
||||
app.afteGameCleanup();
|
||||
}
|
||||
|
||||
public BoardHandler getBoardHandler() {
|
||||
|
||||
@@ -70,13 +70,6 @@ public void leaveOverlay(Overlay overlay) {
|
||||
}
|
||||
|
||||
public void update(float tpf) {
|
||||
//TODO is not necessary but will show misuse of nodes
|
||||
//app.getRootNode().detachAllChildren();
|
||||
//app.getGuiNode().detachAllChildren();
|
||||
//app.getRootNode().attachChild(rootNode);
|
||||
//app.getGuiNode().attachChild(guiNode);
|
||||
//TODO ----------------------------------------------
|
||||
|
||||
videoSettingsDialog.update();
|
||||
audioSettingsDialog.update();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user