Make lobby buttons colored

This commit is contained in:
Felix
2024-11-20 15:21:07 +01:00
parent d87acd46cc
commit 02ce0df614
4 changed files with 141 additions and 4 deletions

View File

@@ -1,5 +1,6 @@
package pp.mdga.client;
import pp.mdga.client.view.LobbyView;
import pp.mdga.notification.*;
import java.util.ArrayList;
@@ -44,14 +45,16 @@ private void handleMain(Notification notification) {
}
private void handleLobby(Notification notification) {
LobbyView view = (LobbyView) app.getView();
if (notification instanceof TskSelectNotification) {
TskSelectNotification n = (TskSelectNotification)notification;
} else if (notification instanceof TskUnselectNotification) {
} else if (notification instanceof GameNotification) {
app.enter(MdgaState.GAME);
} else if (notification instanceof InterruptNotification) {
//TODO gibt es einen intterupt in der lobby?????
} else {
throw new RuntimeException("notification not expected: " + notification.toString());
}

View File

@@ -1,18 +1,39 @@
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<Button> clickCommand;
private boolean taken = false;
public LobbyButtonDialog(MdgaApp app, Node node, String label, Runnable action, int pos) {
super(app, node);
clickCommand = (Button source) -> {
//action.run();
toggleButton();
};
this.pos = pos;
createButton(label, action, new Vector3f(170 * app.getResolutionFactor(), 250 * app.getResolutionFactor(), 0));
this.button = new Button(label);
this.button.setFontSize(fontSize);
createNotTakenButton(new Vector3f(170 * app.getResolutionFactor(), 250 * app.getResolutionFactor(), 0));
}
@Override
@@ -29,4 +50,101 @@ public void show() {
public void hide() {
super.hide();
}
public void setTaken(boolean isTaken, boolean self) {
taken = isTaken;
if(isTaken) {
createTakenButton(new Vector3f(170 * app.getResolutionFactor(), 250 * app.getResolutionFactor(), 0), self);
} else {
createNotTakenButton(new Vector3f(170 * app.getResolutionFactor(), 250 * app.getResolutionFactor(), 0));
}
}
protected void createNotTakenButton(Vector3f size) {
button.setHighlightColor(ColorRGBA.White);
button.setColor(ColorRGBA.Black);
button.setPreferredSize(size);
button.setTextHAlignment(HAlignment.Center);
button.setTextVAlignment(VAlignment.Center);
if(button.getClickCommands() != null) {
button.removeClickCommands(clickCommand);
}
button.addClickCommands(clickCommand);
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);
}
private void toggleButton() {
setTaken(!taken, true);
}
protected void createTakenButton(Vector3f size, boolean self) {
ColorRGBA color_a;
ColorRGBA color_b;
if(button.getClickCommands() != null) {
button.removeClickCommands(clickCommand);
}
if(!self) {
color_a = ColorRGBA.Red;
color_b = ColorRGBA.Red;
} else {
color_a = ColorRGBA.Green;
color_b = ColorRGBA.Yellow;
button.addClickCommands(clickCommand);
}
button.setHighlightColor(ColorRGBA.White);
button.setColor(ColorRGBA.Black);
button.setPreferredSize(size);
button.setTextHAlignment(HAlignment.Center);
button.setTextVAlignment(VAlignment.Center);
QuadBackgroundComponent background = new QuadBackgroundComponent(color_a);
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_b);
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_a);
normalBackground.setMargin(5 * app.getResolutionFactor(), 5 * app.getResolutionFactor());
source.setBackground(normalBackground);
button.setHighlightColor(ColorRGBA.White);
button.setColor(ColorRGBA.Black);
});
container.addChild(button);
}
}

View File

@@ -6,6 +6,7 @@
import pp.mdga.client.dialog.SingleButtonRightDialog;
import pp.mdga.client.MdgaApp;
import pp.mdga.client.MdgaState;
import pp.mdga.game.Color;
import java.util.ArrayList;
@@ -51,6 +52,10 @@ public void onLeave() {
readyButton.hide();
leaveButton.hide();
}
public void setTaken(Color color, boolean isTaken, boolean isSelf) {
lobbyButtons.get(color.ordinal()).setTaken(isTaken, isSelf);
}
}

View File

@@ -8,13 +8,16 @@
public class TskSelectNotification extends Notification{
private Color color;
private String name;
/**
* Constructor.
* @param color the color of the player that is in the game.
* @param name the name of the player that is in the game.
*/
TskSelectNotification(Color color) {
TskSelectNotification(Color color, String name) {
this.color = color;
this.name = name;
}
/**
@@ -24,4 +27,12 @@ public class TskSelectNotification extends Notification{
public Color getColor() {
return color;
}
/**
* Get the name of the player that is in the game.
* @return the name of the player that is in the game.
*/
public String getName() {
return name;
}
}