diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/InputSynchronizer.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/InputSynchronizer.java index dafebe30..a7139a34 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/InputSynchronizer.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/InputSynchronizer.java @@ -62,7 +62,7 @@ private void setupInput() { @Override public void onAction(String name, boolean isPressed, float tpf) { if (name.equals("Settings") && isPressed) { - app.getView().pressEscape(); + //app.getView().pressEscape(); } if (name.equals("RotateRightMouse")) { rightMousePressed = isPressed; diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/MdgaApp.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/MdgaApp.java index f354f693..65943b74 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/MdgaApp.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/MdgaApp.java @@ -22,21 +22,16 @@ public class MdgaApp extends SimpleApplication { private ModelSyncronizer modelSyncronizer; MdgaView view = null; - private MdgaState state = MdgaState.GAME; + private MdgaState state = MdgaState.MAIN; - private static float resolutionFactor = 1.8f; + private static float imageScale = 1.5f; public static void main(String[] args) { AppSettings settings = new AppSettings(true); settings.setSamples(128); settings.setCenterWindow(true); - - int width = (int)(1280 * resolutionFactor); - int height = (int)(720 * resolutionFactor); - - settings.setWidth(width); - settings.setHeight(height); - + settings.setWidth(1920); + settings.setHeight(1080); settings.setVSync(false); MdgaApp app = new MdgaApp(); @@ -47,52 +42,24 @@ public static void main(String[] args) { @Override public void simpleInitApp() { + GuiGlobals.initialize(this); + + inputManager.deleteMapping("SIMPLEAPP_Exit"); + + flyCam.setEnabled(false); + animationHandler = new AnimationHandler(this); acousticHandler = new AcousticHandler(this); notificationSynchronizer = new NotificationSynchronizer(this); inputSynchronizer = new InputSynchronizer(this); modelSyncronizer = new ModelSyncronizer(this); - inputManager.deleteMapping("SIMPLEAPP_Exit"); - inputManager.deleteMapping("FLYCAM_ZoomIn"); - inputManager.deleteMapping("FLYCAM_ZoomOut"); - inputManager.deleteMapping("FLYCAM_RotateDrag"); - flyCam.setEnabled(false); - GuiGlobals.initialize(this); - enter(state); - - List test = new ArrayList<>(); - UUID player0 = UUID.randomUUID(); - test.add(player0); - UUID player1 = UUID.randomUUID(); - test.add(player1); - test.add(UUID.randomUUID()); - test.add(UUID.randomUUID()); - - List test_1 = new ArrayList<>(); - UUID player0_1 = UUID.randomUUID(); - test_1.add(player0_1); - UUID player1_1 = UUID.randomUUID(); - test_1.add(player1_1); - test_1.add(UUID.randomUUID()); - test_1.add(UUID.randomUUID()); - - notificationSynchronizer.addTestNotification(new PlayerInGameNotification(Color.AIRFORCE, test, "Player 1")); - notificationSynchronizer.addTestNotification(new PlayerInGameNotification(Color.NAVY, test_1, "Player 2")); - notificationSynchronizer.addTestNotification(new MovePieceNotification(player0, 0, true)); - notificationSynchronizer.addTestNotification(new MovePieceNotification(player0_1, 20, true)); - notificationSynchronizer.addTestNotification(new MovePieceNotification(player0_1, 20, 21)); - notificationSynchronizer.addTestNotification(new MovePieceNotification(player1, 0, true)); - 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, false)))); - notificationSynchronizer.addTestNotification(new SwapPieceNotification(player0, player0_1)); -// notificationSynchronizer.addTestNotification(new SelectableSwapNotification(new ArrayList<>(List.of(player0, player1)), new ArrayList<>(List.of(player0_1)))); } @Override public void simpleUpdate(float tpf) { - view.update(); + view.update(tpf); acousticHandler.update(); notificationSynchronizer.update(); } @@ -140,8 +107,8 @@ public AcousticHandler getAcousticHandler() { public MdgaState getState() {return state; } - public float getResolutionFactor() { - return resolutionFactor; + public float getImageScale() { + return imageScale; } public MdgaView getView() { diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/acoustic/AcousticHandler.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/acoustic/AcousticHandler.java index 08979182..fcec93d3 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/acoustic/AcousticHandler.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/acoustic/AcousticHandler.java @@ -23,7 +23,7 @@ public class AcousticHandler { private GameMusic scheduled = null; // Scheduled track to play next private GameMusic old = null; // Old track being faded out - private float mainVolume = 1.0f; + private float mainVolume = 0.0f; private float musicVolume = 1.0f; private float soundVolume = 1.0f; diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/button/AbstractButton.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/AbstractButton.java new file mode 100644 index 00000000..c2715695 --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/AbstractButton.java @@ -0,0 +1,56 @@ +package pp.mdga.client.button; + +import com.jme3.font.BitmapFont; +import com.jme3.math.ColorRGBA; +import com.jme3.math.Vector2f; +import com.jme3.scene.Node; +import pp.mdga.client.MdgaApp; + +public abstract class AbstractButton { + protected static final ColorRGBA BUTTON_NORMAL = ColorRGBA.fromRGBA255(169, 165, 104, 255); + protected static final ColorRGBA BUTTON_PRESSED = ColorRGBA.fromRGBA255(105, 117, 89, 255); + protected static final ColorRGBA TEXT_NORMAL = ColorRGBA.Black; + protected static final ColorRGBA TEXT_PRESSED = ColorRGBA.fromRGBA255( 180, 195, 191, 255); + + public static final float HORIZONTAL = 16; + public static final float VERTICAL = 9; + + protected BitmapFont font; + + protected final MdgaApp app; + protected final Node node; + + protected Vector2f pos; + protected float fontSizeFactor = 1.0f; + + protected float fontSize; + protected float horizontalStep; + protected float verticalStep; + protected float heightStep; + protected float widthStep; + + protected boolean adjust = false; + + public AbstractButton(MdgaApp app, Node node) { + this.app = app; + this.node = node; + + font = app.getAssetManager().loadFont("Fonts/Gunplay.fnt"); + } + + public abstract void show(); + public abstract void hide(); + + public void setPos(Vector2f pos) { + this.pos = pos; + } + + protected void calculateRelative() { + fontSize = fontSizeFactor * 15 * (float)app.getCamera().getWidth() / 720; + + horizontalStep = (float)app.getCamera().getWidth() / HORIZONTAL; + verticalStep = (float)app.getCamera().getHeight() / VERTICAL; + heightStep = verticalStep / 2; + widthStep = horizontalStep / 2; + } +} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/button/ButtonLeft.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/ButtonLeft.java new file mode 100644 index 00000000..16933f5f --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/ButtonLeft.java @@ -0,0 +1,21 @@ +package pp.mdga.client.button; + +import com.jme3.math.Vector2f; +import com.jme3.scene.Node; +import pp.mdga.client.MdgaApp; + +public class ButtonLeft extends ClickButton { + public ButtonLeft(MdgaApp app, Node node, Runnable action, String label, int narrowFactor) { + super(app, node, action, label, new Vector2f( 5, 2), new Vector2f(0.5f * narrowFactor, 1.8f)); + } + + @Override + public void onHover() { + + } + + @Override + public void onUnHover() { + + } +} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/button/ButtonRight.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/ButtonRight.java new file mode 100644 index 00000000..aacacd4c --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/ButtonRight.java @@ -0,0 +1,23 @@ +package pp.mdga.client.button; + +import com.jme3.math.Vector2f; +import com.jme3.scene.Node; +import pp.mdga.client.MdgaApp; + +public class ButtonRight extends ClickButton { + public ButtonRight(MdgaApp app, Node node, Runnable action, String label, int narrowFactor) { + super(app, node, action, label, new Vector2f( 5, 2), new Vector2f(HORIZONTAL - 0.5f * narrowFactor, 1.8f)); + + adjust = true; + } + + @Override + public void onHover() { + + } + + @Override + public void onUnHover() { + + } +} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/button/ClickButton.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/ClickButton.java new file mode 100644 index 00000000..d496d55f --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/ClickButton.java @@ -0,0 +1,104 @@ +package pp.mdga.client.button; + +import com.jme3.math.Vector2f; +import com.jme3.math.Vector3f; +import com.jme3.scene.Node; +import com.simsilica.lemur.Button; +import com.simsilica.lemur.HAlignment; +import com.simsilica.lemur.VAlignment; +import com.simsilica.lemur.component.QuadBackgroundComponent; +import pp.mdga.client.MdgaApp; + +public abstract class ClickButton extends AbstractButton { + protected final Runnable action; + + protected String label; + protected Vector2f size; + + protected Button instance; + + ClickButton(MdgaApp app, Node node, Runnable action, String label, Vector2f size, Vector2f pos) { + super(app, node); + + this.action = action; + this.label = label; + this.pos = pos; + this.size = size; + + instance = new Button(label); + + instance.addClickCommands((_) -> action.run()); + instance.setTextHAlignment(HAlignment.Center); + instance.setTextVAlignment(VAlignment.Center); + + instance.addCommands(Button.ButtonAction.HighlightOn, (_) -> click()); + instance.addCommands(Button.ButtonAction.HighlightOff, (_) -> release()); + + instance.setFont(font); + + calculateRelative(); + setRelative(); + + release(); + } + + @Override + public void show() { + calculateRelative(); + setRelative(); + + node.attachChild(instance); + } + + @Override + public void hide() { + node.detachChild(instance); + } + + protected abstract void onHover(); + protected abstract void onUnHover(); + + private void click() { + instance.setColor(TEXT_PRESSED); + instance.setHighlightColor(TEXT_PRESSED); + + QuadBackgroundComponent background = new QuadBackgroundComponent(BUTTON_PRESSED); + instance.setBackground(background); + + onHover(); + }; + + private void release() { + instance.setColor(TEXT_NORMAL); + instance.setHighlightColor(TEXT_NORMAL); + + QuadBackgroundComponent background = new QuadBackgroundComponent(BUTTON_NORMAL); + instance.setBackground(background); + + onUnHover(); + }; + + protected void setRelative() { + instance.setFontSize(fontSize); + + instance.setPreferredSize(new Vector3f(size.x * widthStep, size.y * heightStep, 0)); + + float xAdjust = 0.0f; + if(adjust) { + xAdjust = instance.getPreferredSize().x; + } + + instance.setLocalTranslation(pos.x * horizontalStep - xAdjust, pos.y * verticalStep, -1); + + final float horizontalMid = ((float)app.getCamera().getWidth() / 2) - (instance.getPreferredSize().x / 2); + final float verticalMid = ((float)app.getCamera().getHeight() / 2) - instance.getPreferredSize().y / 2; + + if(0 == pos.x) { + instance.setLocalTranslation(horizontalMid, instance.getLocalTranslation().y, instance.getLocalTranslation().z); + } + + if(0 == pos.y) { + instance.setLocalTranslation(instance.getLocalTranslation().x, verticalMid, instance.getLocalTranslation().z); + } + } +} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/button/InputButton.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/InputButton.java new file mode 100644 index 00000000..487936a7 --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/InputButton.java @@ -0,0 +1,100 @@ +package pp.mdga.client.button; + +import com.jme3.math.Vector2f; +import com.jme3.math.Vector3f; +import com.jme3.scene.Node; +import com.simsilica.lemur.*; +import com.simsilica.lemur.component.QuadBackgroundComponent; +import pp.mdga.client.MdgaApp; + +public class InputButton extends AbstractButton { + private Label label; + private TextField field; + + private Container container = new Container(); + + private final int maxLenght; + + protected Vector2f size; + + public InputButton(MdgaApp app, Node node, String label, int maxLenght) { + super(app, node); + + this.label = new Label(label); + this.maxLenght = maxLenght; + + this.label.setColor(TEXT_NORMAL); + + field = new TextField(""); + field.setColor(TEXT_NORMAL); + field.setTextHAlignment(HAlignment.Left); + field.setTextVAlignment(VAlignment.Center); + + QuadBackgroundComponent grayBackground = new QuadBackgroundComponent(BUTTON_NORMAL); + field.setBackground(grayBackground); + + this.label.setFont(font); + field.setFont(font); + + pos = new Vector2f( 0, 0); + size = new Vector2f(5.5f, 1); + + container.addChild(this.label); + container.addChild(field); + } + + @Override + public void show() { + calculateRelative(); + setRelative(); + + node.attachChild(container); + } + + @Override + public void hide() { + node.detachChild(container); + } + + public void update() { + String text = field.getText(); + int length = text.length(); + + if (length > maxLenght) { + field.setText(text.substring(0, maxLenght)); + } + } + + protected void setRelative() { + this.label.setFontSize(fontSize); + field.setFontSize(fontSize); + + field.setPreferredSize(new Vector3f(size.x * widthStep, size.y * heightStep, 0)); + + float xAdjust = 0.0f; + if(adjust) { + xAdjust = container.getPreferredSize().x; + } + + container.setLocalTranslation(pos.x * horizontalStep - xAdjust, pos.y * verticalStep, -1); + + final float horizontalMid = ((float)app.getCamera().getWidth() / 2) - (container.getPreferredSize().x / 2); + final float verticalMid = ((float)app.getCamera().getHeight() / 2) - container.getPreferredSize().y / 2; + + if(0 == pos.x) { + container.setLocalTranslation(horizontalMid, container.getLocalTranslation().y, -1); + } + + if(0 == pos.y) { + container.setLocalTranslation(container.getLocalTranslation().x, verticalMid, -1); + } + } + + public String getString() { + return field.getText(); + } + + public void reset() { + field.setText(""); + } +} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/button/LabelButton.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/LabelButton.java new file mode 100644 index 00000000..77e8b449 --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/LabelButton.java @@ -0,0 +1,50 @@ +package pp.mdga.client.button; + +import com.jme3.math.ColorRGBA; +import com.jme3.math.Vector2f; +import com.jme3.scene.Node; +import com.simsilica.lemur.component.QuadBackgroundComponent; +import pp.mdga.client.MdgaApp; + +public class LabelButton extends ClickButton{ + LabelButton(MdgaApp app, Node node, String label, Vector2f size, Vector2f pos) { + super(app, node, () -> {}, label, size, pos); + } + + @Override + public void show() { + calculateRelative(); + setRelative(); + + instance.setFontSize(fontSize / 2); + + node.attachChild(instance); + } + + @Override + public void hide() { + node.detachChild(instance); + } + + @Override + public void onHover() { + instance.setColor(TEXT_NORMAL); + instance.setHighlightColor(TEXT_NORMAL); + + QuadBackgroundComponent background = new QuadBackgroundComponent(BUTTON_NORMAL); + instance.setBackground(background); + } + + @Override + public void onUnHover() { + instance.setColor(TEXT_NORMAL); + instance.setHighlightColor(TEXT_NORMAL); + + QuadBackgroundComponent background = new QuadBackgroundComponent(BUTTON_NORMAL); + instance.setBackground(background); + } + + public void setText(String text) { + instance.setText(text); + } +} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/button/LobbyButton.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/LobbyButton.java new file mode 100644 index 00000000..6d337b31 --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/LobbyButton.java @@ -0,0 +1,190 @@ +package pp.mdga.client.button; + +import com.jme3.light.AmbientLight; +import com.jme3.material.Material; +import com.jme3.math.ColorRGBA; +import com.jme3.math.Quaternion; +import com.jme3.math.Vector2f; +import com.jme3.math.Vector3f; +import com.jme3.renderer.queue.RenderQueue; +import com.jme3.scene.Node; +import com.jme3.scene.Spatial; +import com.simsilica.lemur.component.QuadBackgroundComponent; +import pp.mdga.client.Asset; +import pp.mdga.client.MdgaApp; +import pp.mdga.game.Color; + +public class LobbyButton extends ClickButton { + public enum Taken { + NOT, + SELF, + OTHER, + } + + static final float WIDTH = 4.0f; + + private final Node node3d; + + private boolean rotate = false; + private Spatial model; + private float rot = 180; + + private Taken taken = Taken.NOT; + + private LabelButton label; + + public LobbyButton(MdgaApp app, Node node, Node node3d, Runnable action, Color tsk) { + super(app, node, action, "", new Vector2f(WIDTH, 7), new Vector2f(0, 0)); + + this.node3d = node3d; + + label = new LabelButton(app, node, "- leer -", new Vector2f( WIDTH, 1), new Vector2f(0, 0)); + + final float mid = HORIZONTAL / 2; + final float uiSpacing = 0.4f; + final float figSpacing = 0.51f; + + float uiX = mid; + float figX = 0; + Asset asset = null; + + switch (tsk) { + case CYBER: + adjust = true; + label.adjust = true; + uiX -= 3 * uiSpacing; + uiX -= WIDTH / 2; + asset = Asset.cir; + figX -= 3 * figSpacing; + instance.setText("CIR"); + break; + case AIRFORCE: + adjust = true; + label.adjust = true; + uiX -= uiSpacing; + asset = Asset.lw; + figX -= figSpacing; + instance.setText("Luftwaffe"); + break; + case ARMY: + uiX += uiSpacing; + asset = Asset.heer; + figX += figSpacing; + instance.setText("Heer"); + break; + case NAVY: + uiX += 3 * uiSpacing; + uiX += WIDTH / 2; + asset = Asset.marine; + figX += 3 * figSpacing; + instance.setText("Marine"); + break; + } + + setPos(new Vector2f(uiX, 6)); + label.setPos(new Vector2f(uiX, 7)); + + createModel(asset, new Vector3f(figX, -0.55f, 6)); + } + + @Override + public void onHover() { + /*switch (taken) { + case NOT: + break; + case SELF: + break; + case OTHER: + break; + }*/ + + ColorRGBA buttonPressed = BUTTON_PRESSED.clone(); + buttonPressed.a = 0.3f; + + QuadBackgroundComponent background = new QuadBackgroundComponent(buttonPressed); + instance.setBackground(background); + + rotate = true; + } + + @Override + public void onUnHover() { + /*switch (taken) { + case NOT: + break; + case SELF: + break; + case OTHER: + break; + }*/ + + ColorRGBA buttonNormal = ColorRGBA.Gray.clone();// BUTTON_NORMAL.clone(); + buttonNormal.a = 0.1f; + + QuadBackgroundComponent background = new QuadBackgroundComponent(buttonNormal); + instance.setBackground(background); + + rotate = false; + } + + @Override + public void show() { + calculateRelative(); + setRelative(); + + node.attachChild(instance); + node3d.attachChild(model); + + label.show(); + } + + @Override + public void hide() { + node.detachChild(instance); + node3d.detachChild(model); + + label.hide(); + } + + public void update(float tpf) { + if(rotate) { + rot += 140.0f * tpf; + rot %= 360; + } else { + rot = 180; + } + + model.setLocalRotation(new Quaternion().fromAngles((float) Math.toRadians(90), (float) Math.toRadians(rot), (float) Math.toRadians(180))); + } + + private void createModel(Asset asset, Vector3f pos) { + String modelName = asset.getModelPath(); + String texName = asset.getDiffPath(); + + model = app.getAssetManager().loadModel(modelName); + model.scale(asset.getSize() / 2); + model.rotate((float) Math.toRadians(90), (float) Math.toRadians(rot), (float) Math.toRadians(180)); + model.setLocalTranslation(pos); + model.setShadowMode(RenderQueue.ShadowMode.CastAndReceive); + + model.setLocalTranslation(pos); + + Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md"); + mat.setTexture("DiffuseMap", app.getAssetManager().loadTexture(texName)); + model.setMaterial(mat); + } + + public Taken getTaken() { + return taken; + } + + public void setTaken(Taken taken, String name) { + this.taken = taken; + + if(taken == Taken.NOT) { + label.setText("- leer -"); + } else { + label.setText(name); + } + } +} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/button/MenuButton.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/MenuButton.java new file mode 100644 index 00000000..7217ee36 --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/MenuButton.java @@ -0,0 +1,21 @@ +package pp.mdga.client.button; + +import com.jme3.math.Vector2f; +import com.jme3.scene.Node; +import pp.mdga.client.MdgaApp; + +public class MenuButton extends ClickButton { + public MenuButton(MdgaApp app, Node node, Runnable action, String label) { + super(app, node, action, label, new Vector2f( 5.5f, 2), new Vector2f(0, 0)); + } + + @Override + public void onHover() { + + } + + @Override + public void onUnHover() { + + } +} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/button/SettingsButton.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/SettingsButton.java new file mode 100644 index 00000000..eef5c263 --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/SettingsButton.java @@ -0,0 +1,34 @@ +package pp.mdga.client.button; + +import com.jme3.math.Vector2f; +import com.jme3.scene.Node; +import com.simsilica.lemur.HAlignment; +import com.simsilica.lemur.VAlignment; +import com.simsilica.lemur.component.IconComponent; +import pp.mdga.client.MdgaApp; + +public class SettingsButton extends ClickButton { + private IconComponent icon; + + public SettingsButton(MdgaApp app, Node node, Runnable action) { + super(app, node, action, "", new Vector2f(2, 2), new Vector2f(HORIZONTAL - 0.5f, VERTICAL - 0.5f)); + + adjust = true; + + icon = new IconComponent("Images/zahnrad.png"); + icon.setIconScale(0.1f * app.getImageScale()); + icon.setHAlignment(HAlignment.Center); + icon.setVAlignment(VAlignment.Center); + instance.setIcon(icon); + } + + @Override + public void onHover() { + + } + + @Override + public void onUnHover() { + + } +} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/AudioSettingsDialog.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/AudioSettingsDialog.java new file mode 100644 index 00000000..795de3d4 --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/AudioSettingsDialog.java @@ -0,0 +1,4 @@ +package pp.mdga.client.dialog; + +public class AudioSettingsDialog { +} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/Dialog.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/Dialog.java index 421f4cff..89c39555 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/Dialog.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/Dialog.java @@ -1,82 +1,32 @@ package pp.mdga.client.dialog; -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; -import static com.jme3.math.FastMath.floor; - 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 Node node = new Node(); - protected final float vertical_step; - protected final float horitontal_step; + private final Node root; - protected float fontSize = 35; - - public Dialog(MdgaApp app, Node node) { + 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; + this.root = node; } public void show() { - node.attachChild(container); + root.attachChild(node); + + onShow(); } - public void hide () { - node.detachChild(container); + public void hide() { + root.detachChild(node); + + onHide(); } - 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); - } + protected abstract void onShow(); + protected abstract void onHide (); } - diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/GetPercentRunnable.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/GetPercentRunnable.java deleted file mode 100644 index d50a5450..00000000 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/GetPercentRunnable.java +++ /dev/null @@ -1,15 +0,0 @@ -package pp.mdga.client.dialog; - -import java.util.function.Supplier; - -public class GetPercentRunnable { - private final Supplier action; - - public GetPercentRunnable(Supplier action) { - this.action = action; - } - - public float get() { - return action.get(); - } -} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/HostDialog.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/HostDialog.java index 02522c5b..db6b7a1b 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/HostDialog.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/HostDialog.java @@ -1,143 +1,61 @@ package pp.mdga.client.dialog; -import com.jme3.math.ColorRGBA; -import com.jme3.math.Vector3f; +import com.jme3.math.Vector2f; 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 pp.mdga.client.button.ButtonLeft; +import pp.mdga.client.button.ButtonRight; +import pp.mdga.client.button.InputButton; +import pp.mdga.client.button.MenuButton; +import pp.mdga.client.view.MainView; -public class HostDialog extends Dialog { - private TextField portInput; +public class HostDialog extends Dialog { + private InputButton portInput; - public HostDialog(MdgaApp app, Node node, Runnable backAction) { + private ButtonRight hostButton; + private ButtonLeft backButton; + + private final MainView view; + + public HostDialog(MdgaApp app, Node node, MainView view) { super(app, node); - QuadBackgroundComponent quad1 = new QuadBackgroundComponent(ColorRGBA.Gray); - quad1.setMargin(100 * app.getResolutionFactor(), 50 * app.getResolutionFactor()); - container.setBackground(quad1); + this.view = view; - Texture texture = app.getAssetManager().loadTexture("Images/mdga_logo.png"); + portInput = new InputButton(app, node, "Port: ", 5); - QuadBackgroundComponent b = new QuadBackgroundComponent(texture); + hostButton = new ButtonRight(app, node, view::forward, "Spiel hosten", 10); + backButton = new ButtonLeft(app, node, view::back, "Zurück", 10); - Panel imagePanel = new Panel(); - imagePanel.setBackground(b); + float offset = 3.0f; - container.addChild(imagePanel).setPreferredSize(new Vector3f(texture.getImage().getWidth() / 4 * app.getResolutionFactor(), texture.getImage().getHeight() / 4 * app.getResolutionFactor(), 0)); - - //abstandshalter - container.addChild(new Panel(100 * app.getResolutionFactor(), 50 * app.getResolutionFactor(), ColorRGBA.Gray)); - - createTextField(); - - //abstandshalter - container.addChild(new Panel(100 * app.getResolutionFactor(), 50 * app.getResolutionFactor(), ColorRGBA.Gray)); - - Container sub = new Container(new SpringGridLayout(Axis.X, Axis.Y)); - - createButton(sub, "Abbrechen", backAction, new Vector3f(170 * app.getResolutionFactor(), 60 * app.getResolutionFactor(), 0)); - - sub.addChild(new Panel(40 * app.getResolutionFactor(), 0 * app.getResolutionFactor(), ColorRGBA.Gray)); - - createButton(sub, "Starten", () -> tryStart(), new Vector3f(170 * app.getResolutionFactor(), 60 * app.getResolutionFactor(), 0)); - - container.addChild(sub); - } - - void tryStart() { - if (null == portInput.getText()) { - portInput.setText(""); - return; - } - - int port = 0; - - try { - port = Integer.parseInt(portInput.getText()); - } catch (NumberFormatException e) { - portInput.setText(""); - return; - } - - if(port >= 1 && port <= 65535) { - app.getModelSyncronizer().setHost(port); - } - - portInput.setText(""); + portInput.setPos(new Vector2f(0, MenuButton.VERTICAL - offset)); + offset += 1.5f; } @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 - ); + protected void onShow() { + portInput.show(); + hostButton.show(); + backButton.show(); } @Override - public void hide() { - super.hide(); + protected void onHide() { + portInput.hide(); + hostButton.hide(); + backButton.hide(); } - private void createTextField() { - Container subContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y)); - - Label nameLabel = new Label("Port:\t"); - nameLabel.setFontSize(fontSize); - nameLabel.setColor(ColorRGBA.Black); - - portInput = new TextField(""); - - portInput.setColor(ColorRGBA.Black); - portInput.setTextHAlignment(HAlignment.Left); - portInput.setFontSize(fontSize); - portInput.setSingleLine(true); - - QuadBackgroundComponent grayBackground = new QuadBackgroundComponent(ColorRGBA.DarkGray); - portInput.setBackground(grayBackground); - - subContainer.addChild(nameLabel); - subContainer.addChild(portInput); - - container.addChild(subContainer); + public void update() { + portInput.update(); } - protected void createButton(Container c, 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); + public String getPort() { + return portInput.getString(); + } - 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); - }); - - c.addChild(button); + public void resetPort() { + portInput.reset(); } } diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/InterruptDialog.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/InterruptDialog.java new file mode 100644 index 00000000..4fd87803 --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/InterruptDialog.java @@ -0,0 +1,4 @@ +package pp.mdga.client.dialog; + +public class InterruptDialog { +} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/JoinDialog.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/JoinDialog.java index f89f3d74..9aa957ba 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/JoinDialog.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/JoinDialog.java @@ -1,192 +1,77 @@ package pp.mdga.client.dialog; -import com.jme3.math.ColorRGBA; -import com.jme3.math.Vector3f; +import com.jme3.math.Vector2f; 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.regex.Pattern; +import pp.mdga.client.button.ButtonLeft; +import pp.mdga.client.button.ButtonRight; +import pp.mdga.client.button.InputButton; +import pp.mdga.client.button.MenuButton; +import pp.mdga.client.view.MainView; public class JoinDialog extends Dialog { - private TextField portInput; - private TextField ipInput; + private InputButton ipInput; + private InputButton portInput; - public JoinDialog(MdgaApp app, Node node, Runnable backAction) { + private ButtonRight joinButton; + private ButtonLeft backButton; + + private final MainView view; + + public JoinDialog(MdgaApp app, Node node, MainView view) { super(app, node); - QuadBackgroundComponent quad1 = new QuadBackgroundComponent(ColorRGBA.Gray); - quad1.setMargin(100 * app.getResolutionFactor(), 50 * app.getResolutionFactor()); - container.setBackground(quad1); + this.view = view; - Texture texture = app.getAssetManager().loadTexture("Images/mdga_logo.png"); + ipInput = new InputButton(app, node, "Ip: ", 15); + portInput = new InputButton(app, node, "Port: ", 5); - QuadBackgroundComponent b = new QuadBackgroundComponent(texture); + joinButton = new ButtonRight(app, node, view::forward, "Spiel beitreten", 10); + backButton = new ButtonLeft(app, node, view::back, "Zurück", 10); - Panel imagePanel = new Panel(); - imagePanel.setBackground(b); + float offset = 3.0f; - container.addChild(imagePanel).setPreferredSize(new Vector3f(texture.getImage().getWidth() / 4 * app.getResolutionFactor(), texture.getImage().getHeight() / 4 * app.getResolutionFactor(), 0)); + ipInput.setPos(new Vector2f(0, MenuButton.VERTICAL - offset)); + offset += 1.5f; - //abstandshalter - container.addChild(new Panel(100 * app.getResolutionFactor(), 50 * app.getResolutionFactor(), ColorRGBA.Gray)); - - createIpField(); - - //abstandshalter - container.addChild(new Panel(100 * app.getResolutionFactor(), 50 * app.getResolutionFactor(), ColorRGBA.Gray)); - - createPortField(); - - //abstandshalter - container.addChild(new Panel(100 * app.getResolutionFactor(), 50 * app.getResolutionFactor(), ColorRGBA.Gray)); - - Container sub = new Container(new SpringGridLayout(Axis.X, Axis.Y)); - - createButton(sub, "Abbrechen", backAction, new Vector3f(170 * app.getResolutionFactor(), 60 * app.getResolutionFactor(), 0)); - - sub.addChild(new Panel(40 * app.getResolutionFactor(), 0 * app.getResolutionFactor(), ColorRGBA.Gray)); - - createButton(sub, "Beitreten", () -> tryJoin(), new Vector3f(170 * app.getResolutionFactor(), 60 * app.getResolutionFactor(), 0)); - - container.addChild(sub); - } - - void tryJoin() { - if (null == portInput.getText()) { - portInput.setText(""); - ipInput.setText(""); - return; - } - - int port = 0; - - try { - port = Integer.parseInt(portInput.getText()); - } catch (NumberFormatException e) { - portInput.setText(""); - ipInput.setText(""); - return; - } - - if(!(port >= 1 && port <= 65535)) { - portInput.setText(""); - ipInput.setText(""); - return; - } - - if (null == ipInput.getText()) { - portInput.setText(""); - ipInput.setText(""); - return; - } - - String ipv4Pattern = "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"; - - if(!Pattern.matches(ipv4Pattern, ipInput.getText())) { - portInput.setText(""); - ipInput.setText(""); - return; - } - - app.getModelSyncronizer().setJoin(ipInput.getText(), port); + portInput.setPos(new Vector2f(0, MenuButton.VERTICAL - offset)); + offset += 1.5f; } @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 - ); + protected void onShow() { + ipInput.show(); + portInput.show(); + joinButton.show(); + backButton.show(); } @Override - public void hide() { - super.hide(); + protected void onHide() { + ipInput.hide(); + portInput.hide(); + joinButton.hide(); + backButton.hide(); } - private void createPortField() { - Container subContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y)); - - Label nameLabel = new Label("Port:\t"); - nameLabel.setFontSize(fontSize); - nameLabel.setColor(ColorRGBA.Black); - - portInput = new TextField(""); - - portInput.setColor(ColorRGBA.Black); - portInput.setTextHAlignment(HAlignment.Left); - portInput.setFontSize(fontSize); - portInput.setSingleLine(true); - - QuadBackgroundComponent grayBackground = new QuadBackgroundComponent(ColorRGBA.DarkGray); - portInput.setBackground(grayBackground); - - subContainer.addChild(nameLabel); - subContainer.addChild(portInput); - - container.addChild(subContainer); + public void update() { + ipInput.update(); + portInput.update(); } - private void createIpField() { - Container subContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y)); - - Label nameLabel = new Label("Ip:\t"); - nameLabel.setFontSize(fontSize); - nameLabel.setColor(ColorRGBA.Black); - - ipInput = new TextField(""); - - ipInput.setColor(ColorRGBA.Black); - ipInput.setTextHAlignment(HAlignment.Left); - ipInput.setFontSize(fontSize); - ipInput.setSingleLine(true); - - QuadBackgroundComponent grayBackground = new QuadBackgroundComponent(ColorRGBA.DarkGray); - ipInput.setBackground(grayBackground); - - subContainer.addChild(nameLabel); - subContainer.addChild(ipInput); - - container.addChild(subContainer); + public String getIpt() { + return ipInput.getString(); } - protected void createButton(Container c, 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); + public void resetIp() { + ipInput.reset(); + } - QuadBackgroundComponent background = new QuadBackgroundComponent(COLOR_DEFAULT); - background.setMargin(5 * app.getResolutionFactor(), 5 * app.getResolutionFactor()); - button.setBackground(background); + public String getPort() { + return portInput.getString(); + } - 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); - }); - - c.addChild(button); + public void resetPort() { + portInput.reset(); } } diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/LobbyButtonDialog.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/LobbyButtonDialog.java deleted file mode 100644 index 5c1195d9..00000000 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/LobbyButtonDialog.java +++ /dev/null @@ -1,165 +0,0 @@ -package pp.mdga.client.dialog; - -import com.jme3.math.ColorRGBA; -import com.jme3.math.Vector3f; -import com.jme3.scene.Node; -import com.simsilica.lemur.Button; -import com.simsilica.lemur.Command; -import com.simsilica.lemur.HAlignment; -import com.simsilica.lemur.VAlignment; -import com.simsilica.lemur.component.QuadBackgroundComponent; -import pp.mdga.client.MdgaApp; -import pp.mdga.game.Color; - -public class LobbyButtonDialog extends Dialog { - private final int pos; - - private Button button; - - private Command