mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-01-19 00:06:16 +01:00
ImageButtons in Toolbar
This commit is contained in:
parent
e14f6bbef7
commit
b3fe289fbe
@ -218,7 +218,6 @@ selector("button", "pp") {
|
|||||||
insets = new Insets3f(3, 3, 3, 3) // Adjust the border thickness
|
insets = new Insets3f(3, 3, 3, 3) // Adjust the border thickness
|
||||||
textHAlignment = HAlignment.Center
|
textHAlignment = HAlignment.Center
|
||||||
textVAlignment = VAlignment.Center
|
textVAlignment = VAlignment.Center
|
||||||
buttonCommands = stdButtonCommands
|
|
||||||
}
|
}
|
||||||
|
|
||||||
selector("slider", "pp") {
|
selector("slider", "pp") {
|
||||||
@ -387,7 +386,7 @@ selector("button-toolbar", "pp") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
selector("button-toolbar2", "pp") { playerColor ->
|
selector("button-clear", "pp") { playerColor ->
|
||||||
def validColor = playerColor ?: new ColorRGBA(0, 0, 0, 0) // Vollständig transparent
|
def validColor = playerColor ?: new ColorRGBA(0, 0, 0, 0) // Vollständig transparent
|
||||||
def playerGradientBackground = new QuadBackgroundComponent(validColor)
|
def playerGradientBackground = new QuadBackgroundComponent(validColor)
|
||||||
|
|
||||||
@ -395,12 +394,7 @@ selector("button-toolbar2", "pp") { playerColor ->
|
|||||||
playerGradientBackground.setColor(new ColorRGBA(0, 0, 0, 0)) // RGBA (Rot, Grün, Blau, Alpha)
|
playerGradientBackground.setColor(new ColorRGBA(0, 0, 0, 0)) // RGBA (Rot, Grün, Blau, Alpha)
|
||||||
|
|
||||||
background = playerGradientBackground.clone() // Setze den Hintergrund
|
background = playerGradientBackground.clone() // Setze den Hintergrund
|
||||||
insets = new Insets3f(3, 3, 3, 3) // Optional: Ränder
|
insets = new Insets3f(-3, -3, -3, -3) // Optional: Ränder
|
||||||
textHAlignment = HAlignment.Center // Text-Zentrierung
|
textHAlignment = HAlignment.Center // Text-Zentrierung
|
||||||
textVAlignment = VAlignment.Center // Text-Zentrierung
|
textVAlignment = VAlignment.Center // Text-Zentrierung
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,38 +2,92 @@ package pp.monopoly.client.gui;
|
|||||||
|
|
||||||
import com.jme3.texture.Texture;
|
import com.jme3.texture.Texture;
|
||||||
import com.simsilica.lemur.Button;
|
import com.simsilica.lemur.Button;
|
||||||
|
import com.simsilica.lemur.Command;
|
||||||
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
||||||
import com.simsilica.lemur.style.ElementId;
|
|
||||||
|
|
||||||
import pp.monopoly.client.MonopolyApp;
|
import pp.monopoly.client.MonopolyApp;
|
||||||
|
import pp.monopoly.game.server.Player;
|
||||||
|
import pp.monopoly.game.server.PlayerColor;
|
||||||
|
import pp.monopoly.notification.Sound;
|
||||||
|
|
||||||
public class ImageButton extends Button {
|
public class ImageButton extends Button {
|
||||||
|
|
||||||
private final String file;
|
private final MonopolyApp app;
|
||||||
private static MonopolyApp app;
|
private final String functionality;
|
||||||
|
private final PlayerColor playerColor;
|
||||||
public ImageButton( String s, String file, MonopolyApp app ) {
|
|
||||||
this(s, true, new ElementId(ELEMENT_ID), null, file, app);
|
public ImageButton(String functionality, MonopolyApp app) {
|
||||||
}
|
super("", "button-clear");
|
||||||
|
this.app = app;
|
||||||
public ImageButton( String s, String style, String file, MonopolyApp app ) {
|
this.functionality = functionality;
|
||||||
this(s, true, new ElementId(ELEMENT_ID), style, file, app);
|
this.playerColor = Player.getColor(app.getId());
|
||||||
}
|
|
||||||
|
updateButtonAppearance(ButtonState.ENABLED);
|
||||||
public ImageButton( String s, ElementId elementId, String file, MonopolyApp app ) {
|
addButtonCommands();
|
||||||
this(s, true, elementId, null, file, app);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ImageButton( String s, ElementId elementId, String style, String file, MonopolyApp app ) {
|
|
||||||
this(s, true, elementId, style, file, app);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ImageButton( String s, boolean applyStyles, ElementId elementId, String style, String file, MonopolyApp app ) {
|
|
||||||
super(s, false, elementId, style);
|
|
||||||
this.file = file;
|
|
||||||
ImageButton.app = app;
|
|
||||||
Texture backgroundImage = app.getAssetManager().loadTexture("Pictures/Buttons/"+file+".png");
|
|
||||||
setBackground(new QuadBackgroundComponent(backgroundImage));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the button's appearance based on its state.
|
||||||
|
*
|
||||||
|
* @param state the current button state
|
||||||
|
*/
|
||||||
|
private void updateButtonAppearance(ButtonState state) {
|
||||||
|
setBackgroundTexture(state.name().toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds button commands for state-specific actions like hover, press, enable, and disable.
|
||||||
|
*/
|
||||||
|
private void addButtonCommands() {
|
||||||
|
addCommands(ButtonAction.Enabled, source -> updateButtonAppearance(ButtonState.ENABLED));
|
||||||
|
addCommands(ButtonAction.Disabled, source -> updateButtonAppearance(ButtonState.DISABLED));
|
||||||
|
addCommands(ButtonAction.Hover, source -> {
|
||||||
|
if (isEnabled()) {
|
||||||
|
updateButtonAppearance(ButtonState.HOVER);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
addCommands(ButtonAction.HighlightOff, source -> updateButtonAppearance(isEnabled() ? ButtonState.ENABLED : ButtonState.DISABLED));
|
||||||
|
addCommands(ButtonAction.Up, source -> updateButtonAppearance(isEnabled() ? ButtonState.ENABLED : ButtonState.DISABLED));
|
||||||
|
addCommands(ButtonAction.Down, source -> {
|
||||||
|
if (isEnabled()) {
|
||||||
|
app.getGameLogic().playSound(Sound.BUTTON);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the background texture for the button based on the given state.
|
||||||
|
*
|
||||||
|
* @param state the button state (e.g., "enabled", "disabled", "hover")
|
||||||
|
*/
|
||||||
|
private void setBackgroundTexture(String state) {
|
||||||
|
String texturePath = buildTexturePath(state);
|
||||||
|
Texture texture = app.getAssetManager().loadTexture(texturePath);
|
||||||
|
setBackground(new QuadBackgroundComponent(texture));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the file path for the button texture.
|
||||||
|
*
|
||||||
|
* @param state the button state (e.g., "enabled", "disabled", "hover")
|
||||||
|
* @return the full file path to the texture
|
||||||
|
*/
|
||||||
|
private String buildTexturePath(String state) {
|
||||||
|
return String.format("Pictures/Buttons/Button_%s_%s_%s.png", functionality, playerColor.getColorName(), state);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Button states for handling appearance transitions.
|
||||||
|
*/
|
||||||
|
private enum ButtonState {
|
||||||
|
ENABLED, DISABLED, HOVER
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addClickCommands( Command<? super Button> command ) {
|
||||||
|
super.addCommands(ButtonAction.Down, command);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked") // because Java doesn't like var-arg generics
|
||||||
|
public void addClickCommands( Command<? super Button>... commands ) {
|
||||||
|
super.addCommands(ButtonAction.Down, commands);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,8 @@ public class Toolbar extends Dialog implements GameEventListener {
|
|||||||
|
|
||||||
toolbarContainer = setupToolbar();
|
toolbarContainer = setupToolbar();
|
||||||
app.getGuiNode().attachChild(toolbarContainer);
|
app.getGuiNode().attachChild(toolbarContainer);
|
||||||
|
|
||||||
|
endTurnButton.setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -175,9 +177,9 @@ public class Toolbar extends Dialog implements GameEventListener {
|
|||||||
*/
|
*/
|
||||||
private void setupActionMenu(Container container) {
|
private void setupActionMenu(Container container) {
|
||||||
Container menuContainer = container.addChild(new Container());
|
Container menuContainer = container.addChild(new Container());
|
||||||
menuContainer.addChild(createTradeButton(getCurrentPlayerColor()));
|
menuContainer.addChild(createTradeButton());
|
||||||
menuContainer.addChild(createPropertyMenuButton(getCurrentPlayerColor()));
|
menuContainer.addChild(createPropertyMenuButton());
|
||||||
menuContainer.addChild(createEndTurnButton(getCurrentPlayerColor()));
|
menuContainer.addChild(createEndTurnButton());
|
||||||
menuContainer.setBackground(null);
|
menuContainer.setBackground(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,58 +280,65 @@ public class Toolbar extends Dialog implements GameEventListener {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a trade button with the specified player color.
|
|
||||||
*
|
|
||||||
* @param playerColor The color of the player.
|
|
||||||
* @return The button representing the trade action.
|
|
||||||
*/
|
|
||||||
private Button createTradeButton(ColorRGBA playerColor) {
|
|
||||||
return createActionButton(playerColor, "icons/icon-handeln.png", 100, () -> new ChoosePartner(app).open());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
private Button createTradeButton() {
|
||||||
* Creates a property menu button with the specified player color.
|
String iconPath = "icons/icon-handeln.png";
|
||||||
*
|
// createActionButton(playerColor, "icons/icon-handeln.png", 100, () -> new ChoosePartner(app).open());
|
||||||
* @param playerColor The color of the player.
|
tradeButton = new ImageButton("generic", app);
|
||||||
* @return The button representing the property menu action.
|
tradeButton.setPreferredSize(new Vector3f(150, 50, 0));
|
||||||
*/
|
|
||||||
private Button createPropertyMenuButton(ColorRGBA playerColor) {
|
|
||||||
return createActionButton(playerColor, "icons/icon-gebaude.png", 75, () -> new BuildingAdminMenu(app).open());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an end turn button with the specified player color.
|
|
||||||
*
|
|
||||||
* @param playerColor The color of the player.
|
|
||||||
* @return The button representing the end turn action.
|
|
||||||
*/
|
|
||||||
private Button createEndTurnButton(ColorRGBA playerColor) {
|
|
||||||
return createActionButton(playerColor, "icons/icon-zugbeenden.png", 75, () -> handleEndTurn());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an action button with the specified color, icon path, icon size, and action.
|
|
||||||
*
|
|
||||||
* @param color The color of the button.
|
|
||||||
* @param iconPath The path to the icon image.
|
|
||||||
* @param iconSize The size of the icon.
|
|
||||||
* @param action The action to perform when the button is clicked.
|
|
||||||
* @return The button representing the action.
|
|
||||||
*/
|
|
||||||
private Button createActionButton(ColorRGBA color, String iconPath, int iconSize, Runnable action) {
|
|
||||||
Button button = new Button("", new ElementId("button-toolbar2"));
|
|
||||||
button.setPreferredSize(new Vector3f(150, 50, 0));
|
|
||||||
button.setBackground(createButtonBackground(color));
|
|
||||||
|
|
||||||
IconComponent icon = new IconComponent(iconPath);
|
IconComponent icon = new IconComponent(iconPath);
|
||||||
icon.setHAlignment(HAlignment.Center);
|
icon.setHAlignment(HAlignment.Center);
|
||||||
icon.setVAlignment(VAlignment.Center);
|
icon.setVAlignment(VAlignment.Center);
|
||||||
icon.setIconSize(new Vector2f(iconSize, iconSize));
|
icon.setIconSize(new Vector2f(75 , 75));
|
||||||
button.setIcon(icon);
|
tradeButton.setIcon(icon);
|
||||||
|
|
||||||
button.addClickCommands(source -> ifTopDialog(action));
|
tradeButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||||
return button;
|
new ChoosePartner(app).open();
|
||||||
|
}));
|
||||||
|
|
||||||
|
return tradeButton;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Button createPropertyMenuButton() {
|
||||||
|
|
||||||
|
String iconPath = "icons/icon-gebaude.png";
|
||||||
|
propertyMenuButton = new ImageButton("generic", app);
|
||||||
|
propertyMenuButton.setPreferredSize(new Vector3f(150, 50, 0));
|
||||||
|
|
||||||
|
IconComponent icon = new IconComponent(iconPath);
|
||||||
|
icon.setHAlignment(HAlignment.Center);
|
||||||
|
icon.setVAlignment(VAlignment.Center);
|
||||||
|
icon.setIconSize(new Vector2f(50 , 50));
|
||||||
|
propertyMenuButton.setIcon(icon);
|
||||||
|
|
||||||
|
propertyMenuButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||||
|
new BuildingAdminMenu(app).open();
|
||||||
|
}));
|
||||||
|
|
||||||
|
return propertyMenuButton;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Button createEndTurnButton() {
|
||||||
|
// return createActionButton(playerColor, "icons/icon-zugbeenden.png", 75, () -> handleEndTurn());
|
||||||
|
|
||||||
|
String iconPath = "icons/icon-zugbeenden.png";
|
||||||
|
endTurnButton = new ImageButton("generic", app);
|
||||||
|
endTurnButton.setPreferredSize(new Vector3f(150, 50, 0));
|
||||||
|
|
||||||
|
IconComponent icon = new IconComponent(iconPath);
|
||||||
|
icon.setHAlignment(HAlignment.Center);
|
||||||
|
icon.setVAlignment(VAlignment.Center);
|
||||||
|
icon.setIconSize(new Vector2f(50 , 50));
|
||||||
|
endTurnButton.setIcon(icon);
|
||||||
|
|
||||||
|
endTurnButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||||
|
app.getGameLogic().send(new EndTurn());
|
||||||
|
receivedEvent(new ButtonStatusEvent(false));
|
||||||
|
}));
|
||||||
|
|
||||||
|
return endTurnButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -501,11 +510,12 @@ public class Toolbar extends Dialog implements GameEventListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void receivedEvent(ButtonStatusEvent event) {
|
public void receivedEvent(ButtonStatusEvent event) {
|
||||||
|
System.out.println("Button status event received: " + event.buttonsEnabled()+ "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG");
|
||||||
boolean enabled = event.buttonsEnabled();
|
boolean enabled = event.buttonsEnabled();
|
||||||
canRollDice = enabled;
|
canRollDice = enabled;
|
||||||
if (tradeButton != null) tradeButton.setEnabled(enabled);
|
tradeButton.setEnabled(enabled);
|
||||||
if (propertyMenuButton != null) propertyMenuButton.setEnabled(enabled);
|
propertyMenuButton.setEnabled(enabled);
|
||||||
if (endTurnButton != null) endTurnButton.setEnabled(false);
|
endTurnButton.setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user