mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2024-11-28 23:39:45 +01:00
Merge remote-tracking branch 'origin/gui' into gui
This commit is contained in:
commit
bcd6711965
@ -71,6 +71,11 @@ selector("label-Text", "pp") {
|
||||
color = buttonEnabledColor
|
||||
}
|
||||
|
||||
selector("card-label", "pp") {
|
||||
insets = new Insets3f(2, 2, 2, 2)
|
||||
color = ColorRGBA.Black
|
||||
}
|
||||
|
||||
selector("header", "pp") {
|
||||
font = font("Interface/Fonts/Metropolis/Metropolis-Bold-42.fnt")
|
||||
insets = new Insets3f(2, 2, 2, 2)
|
||||
|
@ -0,0 +1,148 @@
|
||||
package pp.monopoly.client.gui;
|
||||
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.renderer.RenderManager;
|
||||
import com.jme3.renderer.ViewPort;
|
||||
import com.jme3.scene.control.AbstractControl;
|
||||
import com.simsilica.lemur.*;
|
||||
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
||||
import com.simsilica.lemur.component.SpringGridLayout;
|
||||
import com.simsilica.lemur.style.ElementId;
|
||||
|
||||
import pp.dialog.Dialog;
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* PropertyOverviewMenu is a dialog for displaying the player's properties in the game.
|
||||
*/
|
||||
public class PropertyOverviewMenu extends Dialog {
|
||||
private final MonopolyApp app;
|
||||
private final Container mainContainer;
|
||||
private final Container displayContainer;
|
||||
private final Slider horizontalSlider;
|
||||
private final List<Container> cards;
|
||||
|
||||
/**
|
||||
* Constructs the PropertyOverviewMenu dialog.
|
||||
*
|
||||
* @param app The Monopoly application instance.
|
||||
*/
|
||||
public PropertyOverviewMenu(MonopolyApp app) {
|
||||
super(app.getDialogManager());
|
||||
this.app = app;
|
||||
|
||||
// Make the menu fullscreen
|
||||
Vector3f screenSize = new Vector3f(app.getCamera().getWidth(), app.getCamera().getHeight(), 0);
|
||||
|
||||
// Main container for the menu layout
|
||||
mainContainer = new Container();
|
||||
mainContainer.setPreferredSize(screenSize); // Make fullscreen
|
||||
mainContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(1.0f, 1.0f, 1.0f, 0.8f))); // Semi-transparent background
|
||||
|
||||
// Header label
|
||||
Label headerLabel = mainContainer.addChild(new Label("Meine Grundstücke", new ElementId("header")));
|
||||
headerLabel.setFontSize(40);
|
||||
|
||||
// Central display container (to hold the "Gebäude" cards)
|
||||
displayContainer = mainContainer.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y, FillMode.Even, FillMode.None))); // Horizontal layout
|
||||
displayContainer.setPreferredSize(new Vector3f(screenSize.x - 300, 550, 0)); // Take up the remaining width
|
||||
displayContainer.setBackground(new QuadBackgroundComponent(ColorRGBA.Gray));
|
||||
displayContainer.setLocalTranslation(0, 0, 11);
|
||||
|
||||
// Add some placeholder "Gebäude" cards to the display container
|
||||
cards = new ArrayList<>();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Container card = createGebäudeCard("Gebäude " + (i + 1), 320, 28);
|
||||
cards.add(card); // Keep track of cards for scrolling
|
||||
}
|
||||
|
||||
// Initially add only visible cards to the displayContainer
|
||||
refreshVisibleCards(0);
|
||||
|
||||
// Horizontal slider for scrolling through cards
|
||||
horizontalSlider = mainContainer.addChild(new Slider(Axis.X));
|
||||
horizontalSlider.setPreferredSize(new Vector3f(screenSize.x - 300, 20, 5));
|
||||
horizontalSlider.setModel(new DefaultRangedValueModel(0, Math.max(0, cards.size() - 5), 0));
|
||||
horizontalSlider.addControl(new SliderValueChangeListener());
|
||||
|
||||
// Add the "Zurück" button at the bottom
|
||||
Button backButton = mainContainer.addChild(new Button("Zurück", new ElementId("button")));
|
||||
backButton.setPreferredSize(new Vector3f(200, 60, 0));
|
||||
backButton.addClickCommands(source -> this.close());
|
||||
|
||||
// Attach the main container to the GUI node
|
||||
app.getGuiNode().attachChild(mainContainer);
|
||||
mainContainer.setLocalTranslation(
|
||||
0,
|
||||
app.getCamera().getHeight(), // Align to the top
|
||||
10
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a "Gebäude" card container with the given information.
|
||||
*
|
||||
* @param title The title of the card (e.g., "Gebäude 1").
|
||||
* @param propertyValue The property value.
|
||||
* @param rent The rent amount.
|
||||
* @return A styled container representing a "Gebäude" card.
|
||||
*/
|
||||
private Container createGebäudeCard(String title, int propertyValue, int rent) {
|
||||
Container card = new Container();
|
||||
card.setPreferredSize(new Vector3f(150, 200, 2)); // Increase width and height for better visibility
|
||||
card.setBackground(new QuadBackgroundComponent(ColorRGBA.Gray));
|
||||
|
||||
card.addChild(new Label(title, new ElementId("card-label"))).setFontSize(14);
|
||||
card.addChild(new Label("Grundstückswert: €" + propertyValue, new ElementId("card-label"))).setFontSize(12);
|
||||
card.addChild(new Label("Miete allein: €" + rent, new ElementId("card-label"))).setFontSize(12);
|
||||
card.addChild(new Label("1 Haus: €50", new ElementId("card-label"))).setFontSize(12);
|
||||
card.addChild(new Label("Hypothekenwert: €160", new ElementId("card-label"))).setFontSize(12);
|
||||
|
||||
return card;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the visible cards in the displayContainer based on the slider value.
|
||||
*
|
||||
* @param startIndex The starting index of the visible cards.
|
||||
*/
|
||||
private void refreshVisibleCards(int startIndex) {
|
||||
displayContainer.clearChildren(); // Remove all current children
|
||||
int maxVisible = 5; // Number of cards to display at once
|
||||
for (int i = startIndex; i < startIndex + maxVisible && i < cards.size(); i++) {
|
||||
displayContainer.addChild(cards.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom listener for slider value changes.
|
||||
*/
|
||||
private class SliderValueChangeListener extends AbstractControl {
|
||||
@Override
|
||||
protected void controlUpdate(float tpf) {
|
||||
// Get the slider's current value and refresh visible cards
|
||||
int sliderValue = (int) ((Slider) getSpatial()).getModel().getValue();
|
||||
refreshVisibleCards(sliderValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void controlRender(RenderManager renderManager, ViewPort viewPort) {
|
||||
// No rendering logic needed
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the dialog and detaches it from the GUI node.
|
||||
*/
|
||||
@Override
|
||||
public void close() {
|
||||
app.getGuiNode().detachChild(mainContainer);
|
||||
super.close();
|
||||
}
|
||||
}
|
@ -118,7 +118,8 @@ public class Toolbar extends Dialog implements GameEventListener {
|
||||
propertyMenuButton.setFontSize(30);
|
||||
propertyMenuButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
new BuildingAdminMenu(app).open();
|
||||
// new BuildingAdminMenu(app).open();
|
||||
new PropertyOverviewMenu(app).open();
|
||||
}));
|
||||
return propertyMenuButton;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user