mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2024-11-24 21:39:44 +01:00
B-Taste um Karte Kaufen Popup zu öffnen
This commit is contained in:
parent
399606d9a0
commit
91e4df7478
@ -18,6 +18,7 @@ import pp.dialog.DialogManager;
|
|||||||
import pp.graphics.Draw;
|
import pp.graphics.Draw;
|
||||||
import pp.monopoly.client.gui.SettingsMenu;
|
import pp.monopoly.client.gui.SettingsMenu;
|
||||||
import pp.monopoly.client.gui.TestWorld;
|
import pp.monopoly.client.gui.TestWorld;
|
||||||
|
import pp.monopoly.client.gui.popups.BuyCard;
|
||||||
import pp.monopoly.game.client.ClientGameLogic;
|
import pp.monopoly.game.client.ClientGameLogic;
|
||||||
import pp.monopoly.game.client.MonopolyClient;
|
import pp.monopoly.game.client.MonopolyClient;
|
||||||
import pp.monopoly.game.client.ServerConnection;
|
import pp.monopoly.game.client.ServerConnection;
|
||||||
@ -42,6 +43,11 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
|
|||||||
private MonopolyServer monopolyServer;
|
private MonopolyServer monopolyServer;
|
||||||
private NetworkSupport networkSupport;
|
private NetworkSupport networkSupport;
|
||||||
|
|
||||||
|
|
||||||
|
private BuyCard buyCard;
|
||||||
|
private boolean isBuyCardPopupOpen = false;
|
||||||
|
private final ActionListener BListener = (name, isPressed, tpf) -> handleB(isPressed);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Path to the styles script for GUI elements.
|
* Path to the styles script for GUI elements.
|
||||||
*/
|
*/
|
||||||
@ -114,6 +120,9 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
|
|||||||
inputManager.setCursorVisible(true);
|
inputManager.setCursorVisible(true);
|
||||||
inputManager.addMapping("ESC", new KeyTrigger(KeyInput.KEY_ESCAPE));
|
inputManager.addMapping("ESC", new KeyTrigger(KeyInput.KEY_ESCAPE));
|
||||||
inputManager.addListener(escapeListener, "ESC");
|
inputManager.addListener(escapeListener, "ESC");
|
||||||
|
|
||||||
|
inputManager.addMapping("B", new KeyTrigger(KeyInput.KEY_B));
|
||||||
|
inputManager.addListener(BListener, "B");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleEscape(boolean isPressed) {
|
private void handleEscape(boolean isPressed) {
|
||||||
@ -134,6 +143,25 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//logik zum wechselnden erscheinen und verschwinden beim drücken von B
|
||||||
|
private void handleB(boolean isPressed) {
|
||||||
|
if (isPressed) {
|
||||||
|
if (buyCard != null && isBuyCardPopupOpen) {
|
||||||
|
// Schließe das SettingsMenu
|
||||||
|
System.out.println("Schließe BuyCardPopup...");
|
||||||
|
buyCard.close();
|
||||||
|
buyCard = null;
|
||||||
|
setBuyCardPopupOpen(false);
|
||||||
|
} else {
|
||||||
|
// Öffne das SettingsMenu
|
||||||
|
System.out.println("Öffne BuyCardPopup...");
|
||||||
|
buyCard = new BuyCard(this);
|
||||||
|
buyCard.open();
|
||||||
|
setBuyCardPopupOpen(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void blockInputs() {
|
private void blockInputs() {
|
||||||
if (!inputBlocked) {
|
if (!inputBlocked) {
|
||||||
System.out.println("Blockiere Eingaben...");
|
System.out.println("Blockiere Eingaben...");
|
||||||
@ -196,6 +224,10 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
|
|||||||
this.isSettingsMenuOpen = isOpen;
|
this.isSettingsMenuOpen = isOpen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setBuyCardPopupOpen(boolean isOpen) {
|
||||||
|
this.isBuyCardPopupOpen = isOpen;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void simpleUpdate(float tpf) {
|
public void simpleUpdate(float tpf) {
|
||||||
if (testWorld != null) {
|
if (testWorld != null) {
|
||||||
@ -209,6 +241,10 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
|
|||||||
testWorld.initializeScene(); // Initialisiere die Szene
|
testWorld.initializeScene(); // Initialisiere die Szene
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void startBuyCard() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void returnToMenu() {
|
public void returnToMenu() {
|
||||||
guiNode.detachAllChildren(); // Entferne die GUI
|
guiNode.detachAllChildren(); // Entferne die GUI
|
||||||
StartMenu.createStartMenu(this); // Zeige das Startmenü erneut
|
StartMenu.createStartMenu(this); // Zeige das Startmenü erneut
|
||||||
|
@ -110,6 +110,16 @@ public class CreateGameMenu {
|
|||||||
}
|
}
|
||||||
}, "OpenTestWorld");
|
}, "OpenTestWorld");
|
||||||
|
|
||||||
|
app.getInputManager().addMapping("OpenBuyCard", new com.jme3.input.controls.KeyTrigger(com.jme3.input.KeyInput.KEY_B));
|
||||||
|
app.getInputManager().addListener(new com.jme3.input.controls.ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void onAction(String name, boolean isPressed, float tpf) {
|
||||||
|
if (name.equals("OpenBuyCard") && isPressed) {
|
||||||
|
app.startBuyCard(); // Öffnet die TestWorld
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, "OpenBuyCard");
|
||||||
|
|
||||||
app.getGuiNode().attachChild(menuContainer);
|
app.getGuiNode().attachChild(menuContainer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,134 @@
|
|||||||
|
package pp.monopoly.client.gui.popups;
|
||||||
|
|
||||||
|
import com.jme3.material.Material;
|
||||||
|
import com.jme3.material.RenderState.BlendMode;
|
||||||
|
import com.jme3.math.ColorRGBA;
|
||||||
|
import com.jme3.math.Vector3f;
|
||||||
|
import com.jme3.scene.Geometry;
|
||||||
|
import com.jme3.scene.shape.Quad;
|
||||||
|
import com.simsilica.lemur.*;
|
||||||
|
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
||||||
|
import com.simsilica.lemur.style.ElementId;
|
||||||
|
import pp.dialog.Dialog;
|
||||||
|
import pp.monopoly.client.MonopolyApp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SettingsMenu ist ein Overlay-Menü, das durch ESC aufgerufen werden kann.
|
||||||
|
*/
|
||||||
|
public class BuyCard extends Dialog {
|
||||||
|
private final MonopolyApp app;
|
||||||
|
private final Geometry overlayBackground;
|
||||||
|
private final Container settingsContainer;
|
||||||
|
private final Container backgroundContainer;
|
||||||
|
|
||||||
|
public BuyCard(MonopolyApp app) {
|
||||||
|
super(app.getDialogManager());
|
||||||
|
this.app = app;
|
||||||
|
|
||||||
|
// Halbtransparentes Overlay hinzufügen
|
||||||
|
overlayBackground = createOverlayBackground();
|
||||||
|
app.getGuiNode().attachChild(overlayBackground);
|
||||||
|
|
||||||
|
// Create the background container
|
||||||
|
backgroundContainer = new Container();
|
||||||
|
backgroundContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f))); // Darker background
|
||||||
|
app.getGuiNode().attachChild(backgroundContainer);
|
||||||
|
|
||||||
|
// Hauptcontainer für das Menü
|
||||||
|
settingsContainer = new Container();
|
||||||
|
settingsContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.1f, 0.1f, 0.1f, 0.9f)));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Titel
|
||||||
|
Label settingsTitle = settingsContainer.addChild(new Label("Gebäude XX", new ElementId("settings-title"))); //TODO Dynamische Gebäudezahl einfügen
|
||||||
|
settingsTitle.setFontSize(48);
|
||||||
|
|
||||||
|
// Effekt-Sound: Slider und Checkbox
|
||||||
|
Container propertyValuesContainer = settingsContainer.addChild(new Container());
|
||||||
|
propertyValuesContainer.addChild(new Label("„Preis: XXXX", new ElementId("label-Text")));//TODO Variable hier einsetzen
|
||||||
|
propertyValuesContainer.addChild(new Label("„Miete: XXXX", new ElementId("label-Text")));//TODO Variable hier einsetzen
|
||||||
|
propertyValuesContainer.addChild(new Label("„Hypothek: XXXX", new ElementId("label-Text")));//TODO Variable hier einsetzen
|
||||||
|
propertyValuesContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
||||||
|
|
||||||
|
/*Selector<String> dropdown = new Selector<>();
|
||||||
|
backgroundMusicContainer.addChild(dropdown);
|
||||||
|
|
||||||
|
Vector3f dimens = settingsContainer.getPreferredSize();
|
||||||
|
Vector3f dimens2 = dropdown.getPopupContainer().getPreferredSize();
|
||||||
|
dimens2.setX(dimens.getX());
|
||||||
|
dropdown.getPopupContainer().setPreferredSize(dimens2);*/
|
||||||
|
// Create the dropdown menu
|
||||||
|
Selector<String> dropdown = new Selector<>();
|
||||||
|
|
||||||
|
// Generate and add numbered examples to the dropdown
|
||||||
|
for (int i = 1; i <= 10; i++) { // Generate 10 examples
|
||||||
|
dropdown.getModel().add("Example " + i);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Adjust the dropdown's popup container size if necessary
|
||||||
|
Vector3f dimens = settingsContainer.getPreferredSize();
|
||||||
|
Vector3f dimens2 = dropdown.getPopupContainer().getPreferredSize();
|
||||||
|
dimens2.setX(dimens.getX());
|
||||||
|
dropdown.getPopupContainer().setPreferredSize(dimens2);
|
||||||
|
// Beenden-Button
|
||||||
|
Button quitButton = settingsContainer.addChild(new Button("Beenden", new ElementId("button")));
|
||||||
|
quitButton.setFontSize(32);
|
||||||
|
// Kaufen-Button
|
||||||
|
Button buyButton = settingsContainer.addChild(new Button("Kaufen", new ElementId("button")));
|
||||||
|
buyButton.setFontSize(32);
|
||||||
|
|
||||||
|
float padding = 10; // Padding around the settingsContainer for the background
|
||||||
|
backgroundContainer.setPreferredSize(settingsContainer.getPreferredSize().addLocal(padding, padding, 0));
|
||||||
|
|
||||||
|
|
||||||
|
// Zentriere das Menü
|
||||||
|
settingsContainer.setLocalTranslation(
|
||||||
|
(app.getCamera().getWidth() - settingsContainer.getPreferredSize().x) / 2,
|
||||||
|
(app.getCamera().getHeight() + settingsContainer.getPreferredSize().y) / 2,
|
||||||
|
4
|
||||||
|
);
|
||||||
|
|
||||||
|
backgroundContainer.setLocalTranslation(
|
||||||
|
(app.getCamera().getWidth() - settingsContainer.getPreferredSize().x - padding) / 2,
|
||||||
|
(app.getCamera().getHeight() + settingsContainer.getPreferredSize().y+ padding) / 2,
|
||||||
|
3
|
||||||
|
);
|
||||||
|
|
||||||
|
app.getGuiNode().attachChild(settingsContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Erstellt einen halbtransparenten Hintergrund für das Menü.
|
||||||
|
*
|
||||||
|
* @return Geometrie des Overlays
|
||||||
|
*/
|
||||||
|
private Geometry createOverlayBackground() {
|
||||||
|
Quad quad = new Quad(app.getCamera().getWidth(), app.getCamera().getHeight());
|
||||||
|
Geometry overlay = new Geometry("Overlay", quad);
|
||||||
|
Material material = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
||||||
|
material.setColor("Color", new ColorRGBA(0, 0, 0, 0.5f)); // Halbtransparent
|
||||||
|
material.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
|
||||||
|
overlay.setMaterial(material);
|
||||||
|
overlay.setLocalTranslation(0, 0, 0);
|
||||||
|
return overlay;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schließt das Menü und entfernt die GUI-Elemente.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
System.out.println("Schließe SettingsMenu..."); // Debugging-Ausgabe
|
||||||
|
app.getGuiNode().detachChild(settingsContainer); // Entferne das Menü
|
||||||
|
app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand
|
||||||
|
app.getGuiNode().detachChild(overlayBackground); // Entferne das Overlay
|
||||||
|
app.setSettingsMenuOpen(false); // Menü als geschlossen markieren
|
||||||
|
app.unblockInputs(); // Eingaben wieder aktivieren
|
||||||
|
System.out.println("SettingsMenu geschlossen."); // Debugging-Ausgabe
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user