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 8e903e1b..fc972ef0 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 @@ -57,7 +57,7 @@ public void simpleInitApp() { gameView = new GameView(this); ceremonyView = new CeremonyView(this); - enter(MdgaState.LOBBY); + enter(MdgaState.MAIN); } @Override 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 index 0e2b091c..18111fd7 100644 --- 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 @@ -7,34 +7,117 @@ import com.jme3.ui.Picture; import pp.mdga.client.MdgaApp; +/** + * Represents an abstract base class for creating customizable button components in a graphical user interface. + * This class provides the framework for rendering buttons with different visual states, such as normal and pressed, + * and supports position adjustments and font customization. + * + *

Subclasses must implement the {@link #show()} and {@link #hide()} methods to define how the button + * is displayed and hidden in the application.

+ */ public abstract class AbstractButton { + /** + * Color representing the normal state of the button. + */ public static final ColorRGBA BUTTON_NORMAL = ColorRGBA.fromRGBA255(233, 236, 239, 255); - public static final ColorRGBA BUTTON_PRESSED = ColorRGBA.fromRGBA255(105, 117, 89, 255); - public static final ColorRGBA TEXT_NORMAL = ColorRGBA.Black; - public static final ColorRGBA TEXT_PRESSED = ColorRGBA.fromRGBA255( 180, 195, 191, 255); + /** + * Color representing the pressed state of the button. + */ + public static final ColorRGBA BUTTON_PRESSED = ColorRGBA.fromRGBA255(105, 117, 89, 255); + + /** + * Color representing the normal state of the button text. + */ + public static final ColorRGBA TEXT_NORMAL = ColorRGBA.Black; + + /** + * Color representing the pressed state of the button text. + */ + public static final ColorRGBA TEXT_PRESSED = ColorRGBA.fromRGBA255(180, 195, 191, 255); + + /** + * The image representing the normal state of the button. + */ protected Picture pictureNormal = new Picture("normalButton"); + + /** + * The image representing the hover state of the button. + */ protected Picture pictureHover = new Picture("normalButton"); + /** + * The number of horizontal divisions for calculating relative sizes. + */ public static final float HORIZONTAL = 16; + + /** + * The number of vertical divisions for calculating relative sizes. + */ public static final float VERTICAL = 9; + /** + * The font used for rendering text on the button. + */ protected BitmapFont font; + /** + * Reference to the application instance for accessing assets and settings. + */ protected final MdgaApp app; + + /** + * Node in the scene graph to which the button belongs. + */ protected final Node node; + /** + * The position of the button in 2D space. + */ protected Vector2f pos; + + /** + * Factor for scaling the font size. + */ protected float fontSizeFactor = 1.0f; + /** + * Computed font size based on scaling factor and screen dimensions. + */ protected float fontSize; + + /** + * Computed horizontal step size based on screen dimensions. + */ protected float horizontalStep; + + /** + * Computed vertical step size based on screen dimensions. + */ protected float verticalStep; + + /** + * Computed height step size based on vertical steps. + */ protected float heightStep; + + /** + * Computed width step size based on horizontal steps. + */ protected float widthStep; + /** + * Flag indicating whether adjustments are applied to the button. + */ protected boolean adjust = false; + /** + * Constructs an AbstractButton instance with the specified application context and scene node. + * Initializes the button's visual elements and font. + * + * @param app the application instance for accessing resources + * @param node the node in the scene graph to which the button is attached + */ public AbstractButton(MdgaApp app, Node node) { this.app = app; this.node = node; @@ -45,18 +128,33 @@ public AbstractButton(MdgaApp app, Node node) { font = app.getAssetManager().loadFont("Fonts/Gunplay.fnt"); } + /** + * Displays the button. Implementation must define how the button is rendered on the screen. + */ public abstract void show(); + + /** + * Hides the button. Implementation must define how the button is removed from the screen. + */ public abstract void hide(); + /** + * Sets the position of the button in 2D space. + * + * @param pos the position to set + */ public void setPos(Vector2f pos) { this.pos = pos; } + /** + * Calculates relative sizes and dimensions for the button based on the screen resolution. + */ protected void calculateRelative() { - fontSize = fontSizeFactor * 15 * (float)app.getCamera().getWidth() / 720; + fontSize = fontSizeFactor * 15 * (float) app.getCamera().getWidth() / 720; - horizontalStep = (float)app.getCamera().getWidth() / HORIZONTAL; - verticalStep = (float)app.getCamera().getHeight() / VERTICAL; + 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 index b60cd8cc..9525d611 100644 --- 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 @@ -5,18 +5,42 @@ import pp.mdga.client.MdgaApp; import com.jme3.ui.Picture; +/** + * Represents a specific implementation of a clickable button positioned on the left side. + * This class extends {@link ClickButton} and provides a predefined position and size for the button. + * It also includes placeholder methods for handling hover events, which can be customized as needed. + */ public class ButtonLeft extends ClickButton { + + /** + * Constructs a ButtonLeft instance with the specified properties. + * + * @param app the application instance for accessing resources and settings + * @param node the node in the scene graph to which the button belongs + * @param action the action to execute when the button is clicked + * @param label the text label to display on the button + * @param narrowFactor a factor to adjust position of the button + */ 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)); + super(app, node, action, label, new Vector2f(5, 2), new Vector2f(0.5f * narrowFactor, 1.8f)); } + /** + * Called when the button is hovered over by the pointer. + * Subclasses can override this method to define specific hover behavior. + */ @Override public void onHover() { - + // Placeholder for hover behavior } + /** + * Called when the pointer stops hovering over the button. + * Subclasses can override this method to define specific unhover behavior. + */ @Override public void onUnHover() { - + // Placeholder for unhover behavior } } + 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 index aacacd4c..d5664450 100644 --- 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 @@ -4,20 +4,45 @@ import com.jme3.scene.Node; import pp.mdga.client.MdgaApp; +/** + * Represents a specific implementation of a clickable button positioned on the right side. + * This class extends {@link ClickButton} and provides a predefined position and size for the button. + * It includes placeholder methods for handling hover events, which can be customized as needed. + */ 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)); + /** + * Constructs a ButtonRight instance with the specified properties. + * + * @param app the application instance for accessing resources and settings + * @param node the node in the scene graph to which the button belongs + * @param action the action to execute when the button is clicked + * @param label the text label to display on the button + * @param narrowFactor a factor to adjust the position of the button + */ + 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)); + + // Enable adjustments specific to this button adjust = true; } + /** + * Called when the button is hovered over by the pointer. + * Subclasses can override this method to define specific hover behavior. + */ @Override public void onHover() { - + // Placeholder for hover behavior } + /** + * Called when the pointer stops hovering over the button. + * Subclasses can override this method to define specific unhover behavior. + */ @Override public void onUnHover() { - + // Placeholder for unhover behavior } } + diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/button/CeremonyButton.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/CeremonyButton.java index b7b8f8d6..00244262 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/button/CeremonyButton.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/CeremonyButton.java @@ -13,7 +13,16 @@ import pp.mdga.client.MdgaApp; import pp.mdga.game.Color; +/** + * Represents a button used in a ceremony screen, with 3D model integration, customizable + * appearance based on type, and interactive behavior. The button can rotate and display + * different positions such as FIRST, SECOND, THIRD, and LOST. + */ public class CeremonyButton extends ClickButton { + + /** + * Enum representing the possible positions of the button in the ceremony screen. + */ public enum Pos { FIRST, SECOND, @@ -21,24 +30,58 @@ public enum Pos { LOST, } + /** + * Fixed width of the button in the UI layout. + */ static final float WIDTH = 4.0f; + /** + * Node to which the 3D model associated with this button is attached. + */ private final Node node3d; + /** + * Flag to determine if the button's 3D model should rotate. + */ private boolean rotate = false; + + /** + * The 3D model associated with the button. + */ private Spatial model; + + /** + * Current rotation angle of the button's 3D model. + */ private float rot = 180; + /** + * The taken state of the button (default is NOT taken). + */ private LobbyButton.Taken taken = LobbyButton.Taken.NOT; + /** + * A label associated with the button for displaying additional information. + */ private LabelButton label; + /** + * Constructs a CeremonyButton with specified attributes such as type, position, and label. + * The button supports both 2D and 3D components for UI and visual effects. + * + * @param app the application instance for accessing resources and settings + * @param node the node in the scene graph to which the button belongs + * @param node3d the node for 3D scene components associated with this button + * @param tsk the type/color associated with the button + * @param pos the position of the button in the ceremony layout + * @param name the label or name displayed on the button + */ public CeremonyButton(MdgaApp app, Node node, Node node3d, Color tsk, Pos pos, String name) { - super(app, node, () -> {} , "", new Vector2f(WIDTH, 7), new Vector2f(0, 0)); + super(app, node, () -> {}, "", new Vector2f(WIDTH, 7), new Vector2f(0, 0)); this.node3d = node3d; - label = new LabelButton(app, node, name, new Vector2f( WIDTH, 1), new Vector2f(0, 0), true); + label = new LabelButton(app, node, name, new Vector2f(WIDTH, 1), new Vector2f(0, 0), true); final float mid = HORIZONTAL / 2; final float uiSpacing = 1.4f; @@ -73,8 +116,6 @@ public CeremonyButton(MdgaApp app, Node node, Node node3d, Color tsk, Pos pos, S case FIRST: rotate = true; uiX = 0; - uiY -= 0; - figX = 0; figY -= 1 * figSpacingY; break; case SECOND: @@ -110,6 +151,9 @@ public CeremonyButton(MdgaApp app, Node node, Node node3d, Color tsk, Pos pos, S createModel(asset, new Vector3f(figX, figY, 6)); } + /** + * Handles hover behavior by changing the button's background appearance. + */ @Override public void onHover() { ColorRGBA buttonNormal = BUTTON_NORMAL.clone(); @@ -119,6 +163,9 @@ public void onHover() { instance.setBackground(background); } + /** + * Handles unhover behavior by resetting the button's background appearance. + */ @Override public void onUnHover() { ColorRGBA buttonNormal = BUTTON_NORMAL.clone(); @@ -128,6 +175,9 @@ public void onUnHover() { instance.setBackground(background); } + /** + * Displays the button along with its 3D model and associated label. + */ @Override public void show() { release(); @@ -141,6 +191,9 @@ public void show() { label.show(); } + /** + * Hides the button along with its 3D model and associated label. + */ @Override public void hide() { node.detachChild(instance); @@ -149,24 +202,43 @@ public void hide() { label.hide(); } + /** + * Updates the rotation of the button's 3D model over time. + * + * @param tpf time per frame, used for smooth rotation calculations + */ public void update(float tpf) { - if(rotate) { + 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))); + model.setLocalRotation(new Quaternion().fromAngles( + (float) Math.toRadians(90), + (float) Math.toRadians(rot), + (float) Math.toRadians(180) + )); } + /** + * Creates a 3D model associated with the button and applies its materials and position. + * + * @param asset the asset representing the 3D model and texture + * @param pos the initial position of the model in 3D space + */ 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.rotate( + (float) Math.toRadians(90), + (float) Math.toRadians(rot), + (float) Math.toRadians(180) + ); model.setShadowMode(RenderQueue.ShadowMode.CastAndReceive); model.setLocalTranslation(pos); 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 index cd13b787..2b1581ee 100644 --- 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 @@ -11,14 +11,43 @@ import pp.mdga.client.MdgaApp; import pp.mdga.client.acoustic.MdgaSound; +/** + * Abstract base class for creating interactive buttons with click functionality. + * This class extends {@link AbstractButton} and provides additional behavior such as + * click handling, hover effects, and alignment management. + */ public abstract class ClickButton extends AbstractButton { + + /** + * The action to be executed when the button is clicked. + */ protected final Runnable action; + /** + * The label or text displayed on the button. + */ protected String label; + + /** + * The size of the button in relative units. + */ protected Vector2f size; + /** + * The instance of the button being managed. + */ protected Button instance; + /** + * Constructs a ClickButton with the specified properties. + * + * @param app the application instance for accessing resources + * @param node the node in the scene graph to which the button belongs + * @param action the action to execute on button click + * @param label the text label displayed on the button + * @param size the size of the button + * @param pos the position of the button in relative units + */ ClickButton(MdgaApp app, Node node, Runnable action, String label, Vector2f size, Vector2f pos) { super(app, node); @@ -29,13 +58,21 @@ public abstract class ClickButton extends AbstractButton { instance = new Button(label); - instance.addClickCommands((button) -> { app.getAcousticHandler().playSound(MdgaSound.BUTTON_PRESSED); action.run(); }); + // Add click behavior + instance.addClickCommands((button) -> { + app.getAcousticHandler().playSound(MdgaSound.BUTTON_PRESSED); + action.run(); + }); + + // Set text alignment instance.setTextHAlignment(HAlignment.Center); instance.setTextVAlignment(VAlignment.Center); + // Add hover commands instance.addCommands(Button.ButtonAction.HighlightOn, (button) -> click()); instance.addCommands(Button.ButtonAction.HighlightOff, (button) -> release()); + // Set font and colors instance.setFont(font); instance.setFocusColor(TEXT_NORMAL); @@ -43,6 +80,9 @@ public abstract class ClickButton extends AbstractButton { setRelative(); } + /** + * Displays the button by attaching it and its background image to the node. + */ @Override public void show() { node.attachChild(pictureNormal); @@ -55,21 +95,34 @@ public void show() { node.attachChild(instance); } + /** + * Hides the button by detaching it and its background images from the node. + */ @Override public void hide() { node.detachChild(instance); - if(node.hasChild(pictureNormal)) { + if (node.hasChild(pictureNormal)) { node.detachChild(pictureNormal); } - if(node.hasChild(pictureHover)) { + if (node.hasChild(pictureHover)) { node.detachChild(pictureHover); } } + /** + * Abstract method to define hover behavior. Must be implemented by subclasses. + */ protected abstract void onHover(); + + /** + * Abstract method to define unhover behavior. Must be implemented by subclasses. + */ protected abstract void onUnHover(); + /** + * Handles the button click behavior, including visual feedback and sound effects. + */ protected void click() { instance.setColor(TEXT_PRESSED); instance.setHighlightColor(TEXT_PRESSED); @@ -79,15 +132,18 @@ protected void click() { app.getAcousticHandler().playSound(MdgaSound.UI_CLICK); - if(node.hasChild(pictureNormal)) { + if (node.hasChild(pictureNormal)) { node.detachChild(pictureNormal); setImageRelative(pictureHover); node.attachChild(pictureHover); } onHover(); - }; + } + /** + * Resets the button to its normal state after a click or hover event. + */ protected void release() { instance.setColor(TEXT_NORMAL); instance.setHighlightColor(TEXT_NORMAL); @@ -95,41 +151,49 @@ protected void release() { QuadBackgroundComponent background = new QuadBackgroundComponent(BUTTON_NORMAL); instance.setBackground(background); - if(node.hasChild(pictureHover)) { + if (node.hasChild(pictureHover)) { node.detachChild(pictureHover); setImageRelative(pictureNormal); node.attachChild(pictureNormal); } onUnHover(); - }; + } + /** + * Sets the relative size and position of the button based on screen dimensions. + */ protected void setRelative() { instance.setFontSize(fontSize); instance.setPreferredSize(new Vector3f(size.x * widthStep, size.y * heightStep, 0)); float xAdjust = 0.0f; - if(adjust) { + 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; + 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) { + if (0 == pos.x) { instance.setLocalTranslation(horizontalMid, instance.getLocalTranslation().y, instance.getLocalTranslation().z); } - if(0 == pos.y) { + if (0 == pos.y) { instance.setLocalTranslation(instance.getLocalTranslation().x, verticalMid, instance.getLocalTranslation().z); } } + /** + * Sets the relative size and position of the button's background image. + * + * @param picture the background image to set + */ protected void setImageRelative(Picture picture) { - if(null == picture) { + if (null == picture) { return; } @@ -145,3 +209,4 @@ protected void setImageRelative(Picture picture) { ); } } + 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 index 99034ebd..7b975b20 100644 --- 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 @@ -7,42 +7,81 @@ import com.simsilica.lemur.component.QuadBackgroundComponent; import pp.mdga.client.MdgaApp; +/** + * Represents an input button with a label and a text field, allowing users to input text. + * The button is designed for graphical user interfaces and supports configurable + * size, position, and character limit. + */ public class InputButton extends AbstractButton { + + /** + * The label associated with the input field, displayed above or beside the text field. + */ private Label label; + + /** + * The text field where users input their text. + */ private TextField field; + /** + * A container to hold the label and the text field for layout management. + */ private Container container = new Container(); + /** + * The maximum allowed length of the input text. + */ private final int maxLenght; + /** + * The size of the input button in relative units. + */ protected Vector2f size; + /** + * Constructs an InputButton with the specified label, character limit, and other properties. + * + * @param app the application instance for accessing resources + * @param node the node in the scene graph to which the input button belongs + * @param label the label displayed with the input field + * @param maxLenght the maximum number of characters allowed in the input field + */ public InputButton(MdgaApp app, Node node, String label, int maxLenght) { super(app, node); this.label = new Label(label); this.maxLenght = maxLenght; + // Configure label properties this.label.setColor(TEXT_NORMAL); + // Configure text field properties field = new TextField(""); field.setColor(TEXT_NORMAL); field.setTextHAlignment(HAlignment.Left); field.setTextVAlignment(VAlignment.Center); + // Set background for the text field QuadBackgroundComponent grayBackground = new QuadBackgroundComponent(BUTTON_NORMAL); field.setBackground(grayBackground); + // Set fonts for label and text field this.label.setFont(font); field.setFont(font); - pos = new Vector2f( 0, 0); + // Default position and size + pos = new Vector2f(0, 0); size = new Vector2f(5.5f, 1); + // Add components to the container container.addChild(this.label); container.addChild(field); } + /** + * Displays the input button by attaching it to the scene graph node. + */ @Override public void show() { calculateRelative(); @@ -51,11 +90,18 @@ public void show() { node.attachChild(container); } + /** + * Hides the input button by detaching it from the scene graph node. + */ @Override public void hide() { node.detachChild(container); } + /** + * Updates the input field, enforcing the character limit. + * Trims the text if it exceeds the maximum allowed length. + */ public void update() { String text = field.getText(); int length = text.length(); @@ -65,6 +111,9 @@ public void update() { } } + /** + * Adjusts the relative size and position of the input button based on the screen resolution. + */ protected void setRelative() { this.label.setFontSize(fontSize); field.setFontSize(fontSize); @@ -72,30 +121,45 @@ protected void setRelative() { field.setPreferredSize(new Vector3f(size.x * widthStep, size.y * heightStep, 0)); float xAdjust = 0.0f; - if(adjust) { + 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; + 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) { + if (0 == pos.x) { container.setLocalTranslation(horizontalMid, container.getLocalTranslation().y, -1); } - if(0 == pos.y) { + if (0 == pos.y) { container.setLocalTranslation(container.getLocalTranslation().x, verticalMid, -1); } } + /** + * Retrieves the text currently entered in the input field. + * + * @return the current text in the input field + */ public String getString() { return field.getText(); } - public void setString(String string) { field.setText(string); } + /** + * Sets the text of the input field to the specified string. + * + * @param string the text to set in the input field + */ + public void setString(String string) { + field.setText(string); + } + /** + * Resets the input field by clearing its text. + */ 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 index 1a80818f..dbb39da5 100644 --- 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 @@ -6,23 +6,53 @@ import com.simsilica.lemur.component.QuadBackgroundComponent; import pp.mdga.client.MdgaApp; -public class LabelButton extends ClickButton{ +/** + * A specialized button that can function as a label or a clickable button. + * It inherits from {@link ClickButton} and allows for flexible usage with or without button-like behavior. + */ +public class LabelButton extends ClickButton { + + /** + * The color of the text displayed on the label or button. + */ private ColorRGBA text = TEXT_NORMAL; + + /** + * The color of the button's background. + */ private ColorRGBA button = BUTTON_NORMAL; + /** + * Flag indicating whether this component functions as a button. + */ private boolean isButton; + /** + * Constructs a LabelButton with specified properties. + * + * @param app the application instance for accessing resources + * @param node the node in the scene graph to which the button belongs + * @param label the text displayed on the label or button + * @param size the size of the label or button + * @param pos the position of the label or button in relative units + * @param isButton whether this component acts as a button or a simple label + */ public LabelButton(MdgaApp app, Node node, String label, Vector2f size, Vector2f pos, boolean isButton) { super(app, node, () -> {}, label, size, pos); this.isButton = isButton; + // Use the same image for hover and normal states pictureHover = pictureNormal; } + /** + * Displays the label or button, attaching it to the scene graph. + * If the component is a button, it also attaches the background image. + */ @Override public void show() { - if(isButton) { + if (isButton) { node.attachChild(pictureNormal); } release(); @@ -36,18 +66,24 @@ public void show() { node.attachChild(instance); } + /** + * Hides the label or button, detaching it from the scene graph. + */ @Override public void hide() { node.detachChild(instance); - if(node.hasChild(pictureNormal)) { + if (node.hasChild(pictureNormal)) { node.detachChild(pictureNormal); } - if(node.hasChild(pictureHover)) { + if (node.hasChild(pictureHover)) { node.detachChild(pictureHover); } } + /** + * Handles hover behavior, updating the colors of the text and background. + */ @Override public void onHover() { instance.setColor(text); @@ -57,6 +93,9 @@ public void onHover() { instance.setBackground(background); } + /** + * Handles unhover behavior, restoring the colors of the text and background. + */ @Override public void onUnHover() { instance.setColor(text); @@ -66,10 +105,21 @@ public void onUnHover() { instance.setBackground(background); } + /** + * Sets the text displayed on the label or button. + * + * @param text the text to display + */ public void setText(String text) { instance.setText(text); } + /** + * Sets the colors of the text and background, and refreshes the label or button. + * + * @param text the color of the text + * @param button the color of the button's background + */ public void setColor(ColorRGBA text, ColorRGBA button) { this.text = text; this.button = button; @@ -78,3 +128,4 @@ public void setColor(ColorRGBA text, ColorRGBA button) { show(); } } + 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 index 84fe0b02..d9b96a1b 100644 --- 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 @@ -17,41 +17,102 @@ import pp.mdga.client.MdgaApp; import pp.mdga.game.Color; +/** + * Represents a button in a multiplayer lobby screen. The button supports multiple states + * (not taken, self, other) and displays a 3D model alongside its label. It can also indicate readiness + * and interactively respond to hover and click events. + */ public class LobbyButton extends ClickButton { + + /** + * Enum representing the possible ownership states of the lobby button. + */ public enum Taken { - NOT, - SELF, - OTHER, + NOT, // The button is not taken + SELF, // The button is taken by the user + OTHER // The button is taken by another user } - static final ColorRGBA LOBBY_TAKEN = ColorRGBA.fromRGBA255(193,58,59, 100); + /** + * Color for a lobby button that is taken by another user. + */ + static final ColorRGBA LOBBY_TAKEN = ColorRGBA.fromRGBA255(193, 58, 59, 100); - static final ColorRGBA LOBBY_READY = ColorRGBA.fromRGBA255(55,172,190, 100); - static final ColorRGBA LOBBY_READY_HOVER = ColorRGBA.fromRGBA255(17,211,218, 100); + /** + * Color for a lobby button that is ready but not hovered. + */ + static final ColorRGBA LOBBY_READY = ColorRGBA.fromRGBA255(55, 172, 190, 100); - static final ColorRGBA LOBBY_SELF_NORMAL = ColorRGBA.fromRGBA255(0,151,19, 100); - static final ColorRGBA LOBBY_SELF_HOVER = ColorRGBA.fromRGBA255(0,230,19, 100); + /** + * Color for a lobby button that is ready and hovered. + */ + static final ColorRGBA LOBBY_READY_HOVER = ColorRGBA.fromRGBA255(17, 211, 218, 100); + /** + * Color for a lobby button owned by the user in normal state. + */ + static final ColorRGBA LOBBY_SELF_NORMAL = ColorRGBA.fromRGBA255(0, 151, 19, 100); + + /** + * Color for a lobby button owned by the user when hovered. + */ + static final ColorRGBA LOBBY_SELF_HOVER = ColorRGBA.fromRGBA255(0, 230, 19, 100); + + /** + * Fixed width for the lobby button. + */ static final float WIDTH = 4.0f; + /** + * Node to which the 3D model associated with this button is attached. + */ private final Node node3d; + /** + * Indicates whether the 3D model should rotate. + */ private boolean rotate = false; + + /** + * The 3D model displayed alongside the button. + */ private Spatial model; + + /** + * The rotation angle of the 3D model. + */ private float rot = 180; + /** + * The current ownership state of the lobby button. + */ private Taken taken = Taken.NOT; + /** + * Label displayed on the lobby button. + */ private LabelButton label; + /** + * Indicates whether the button represents a ready state. + */ private boolean isReady = false; + /** + * Constructs a LobbyButton with specified properties, including a 3D model and label. + * + * @param app the application instance for accessing resources + * @param node the node in the scene graph to which the button belongs + * @param node3d the node for 3D scene components associated with this button + * @param action the action to execute when the button is clicked + * @param tsk the type or category of the button (e.g., CYBER, AIRFORCE) + */ 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), true); + label = new LabelButton(app, node, "- leer -", new Vector2f(WIDTH, 1), new Vector2f(0, 0), true); final float mid = HORIZONTAL / 2; final float uiSpacing = 0.4f; @@ -61,6 +122,7 @@ public LobbyButton(MdgaApp app, Node node, Node node3d, Runnable action, Color t float figX = 0; Asset asset = null; + // Configure the button based on its type switch (tsk) { case CYBER: adjust = true; @@ -100,6 +162,9 @@ public LobbyButton(MdgaApp app, Node node, Node node3d, Runnable action, Color t createModel(asset, new Vector3f(figX, -0.55f, 6)); } + /** + * Handles hover behavior, updating the button's color and enabling rotation. + */ @Override public void onHover() { ColorRGBA buttonPressed = BUTTON_PRESSED.clone(); @@ -116,7 +181,7 @@ public void onHover() { break; } - if(isReady) { + if (isReady) { buttonPressed = LOBBY_READY_HOVER; } @@ -126,6 +191,9 @@ public void onHover() { rotate = true; } + /** + * Handles unhover behavior, restoring the button's color and disabling rotation. + */ @Override public void onUnHover() { ColorRGBA buttonNormal = BUTTON_NORMAL.clone(); @@ -142,7 +210,7 @@ public void onUnHover() { break; } - if(isReady) { + if (isReady) { buttonNormal = LOBBY_READY; } @@ -152,6 +220,9 @@ public void onUnHover() { rotate = false; } + /** + * Displays the lobby button and its associated components. + */ @Override public void show() { release(); @@ -165,6 +236,9 @@ public void show() { label.show(); } + /** + * Hides the lobby button and its associated components. + */ @Override public void hide() { node.detachChild(instance); @@ -173,24 +247,43 @@ public void hide() { label.hide(); } + /** + * Updates the 3D model's rotation if the button is being hovered. + * + * @param tpf time per frame, used for smooth rotation calculations + */ public void update(float tpf) { - if(rotate) { + 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))); + model.setLocalRotation(new Quaternion().fromAngles( + (float) Math.toRadians(90), + (float) Math.toRadians(rot), + (float) Math.toRadians(180) + )); } + /** + * Creates the 3D model associated with the lobby button and applies textures and positioning. + * + * @param asset the asset representing the 3D model + * @param pos the initial position of the 3D model + */ 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.rotate( + (float) Math.toRadians(90), + (float) Math.toRadians(rot), + (float) Math.toRadians(180) + ); model.setShadowMode(RenderQueue.ShadowMode.CastAndReceive); model.setLocalTranslation(pos); @@ -200,14 +293,25 @@ private void createModel(Asset asset, Vector3f pos) { model.setMaterial(mat); } + /** + * Gets the current ownership state of the lobby button. + * + * @return the current state of the button + */ public Taken getTaken() { return taken; } + /** + * Sets the ownership state of the lobby button and updates its label accordingly. + * + * @param taken the new ownership state + * @param name the name to display on the button + */ public void setTaken(Taken taken, String name) { this.taken = taken; - if(taken == Taken.NOT) { + if (taken == Taken.NOT) { label.setText("- leer -"); isReady = false; } else { @@ -217,8 +321,14 @@ public void setTaken(Taken taken, String name) { onUnHover(); } + /** + * Sets the ready state of the lobby button and updates its appearance. + * + * @param isReady whether the button represents a ready state + */ public void setReady(boolean isReady) { this.isReady = isReady; onUnHover(); } } + 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 index 7217ee36..a66e43fd 100644 --- 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 @@ -4,18 +4,40 @@ import com.jme3.scene.Node; import pp.mdga.client.MdgaApp; +/** + * Represents a button used in menu screens for navigation or executing actions. + * Inherits from {@link ClickButton} and provides customizable text and actions. + */ public class MenuButton extends ClickButton { + + /** + * Constructs a MenuButton with specified properties. + * + * @param app the application instance for accessing resources + * @param node the node in the scene graph to which the button belongs + * @param action the action to execute when the button is clicked + * @param label the text label displayed on the button + */ public MenuButton(MdgaApp app, Node node, Runnable action, String label) { - super(app, node, action, label, new Vector2f( 5.5f, 2), new Vector2f(0, 0)); + super(app, node, action, label, new Vector2f(5.5f, 2), new Vector2f(0, 0)); } + /** + * Called when the button is hovered over. Can be overridden to define hover-specific behavior. + * Currently, no additional behavior is implemented. + */ @Override public void onHover() { - + // Placeholder for hover behavior } + /** + * Called when the pointer stops hovering over the button. Can be overridden to define unhover-specific behavior. + * Currently, no additional behavior is implemented. + */ @Override public void onUnHover() { - + // Placeholder for unhover behavior } } + 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 index af0e257d..6c235097 100644 --- 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 @@ -7,15 +7,34 @@ import com.simsilica.lemur.component.IconComponent; import pp.mdga.client.MdgaApp; +/** + * Represents a button in the settings menu, designed to display an icon and handle hover effects. + * Inherits from {@link ClickButton} and customizes its behavior for settings functionality. + */ public class SettingsButton extends ClickButton { + + /** + * The icon displayed on the button, which changes based on hover state. + */ private IconComponent icon; + /** + * Constructs a SettingsButton with a predefined size and position. + * + * @param app the application instance for accessing resources + * @param node the node in the scene graph to which the button belongs + * @param action the action to execute when the button is clicked + */ public SettingsButton(MdgaApp app, Node node, Runnable action) { super(app, node, action, "", new Vector2f(2, 2), new Vector2f(HORIZONTAL - 0.5f, VERTICAL - 0.5f)); + // Enable adjustment for positioning adjust = true; } + /** + * Displays the settings button by attaching it to the scene graph. + */ @Override public void show() { release(); @@ -27,6 +46,9 @@ public void show() { node.attachChild(instance); } + /** + * Handles hover behavior by changing the icon to the hover state. + */ @Override public void onHover() { icon = new IconComponent("Images/Settings_Button_hover.png"); @@ -37,6 +59,9 @@ public void onHover() { instance.setIcon(icon); } + /** + * Handles unhover behavior by restoring the icon to the normal state. + */ @Override public void onUnHover() { icon = new IconComponent("Images/Settings_Button_normal.png"); @@ -47,3 +72,4 @@ public void onUnHover() { instance.setIcon(icon); } } + diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/button/SliderButton.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/SliderButton.java index 4dbccf91..4a4ebf51 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/button/SliderButton.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/SliderButton.java @@ -7,24 +7,50 @@ import com.simsilica.lemur.component.QuadBackgroundComponent; import pp.mdga.client.MdgaApp; +/** + * Represents a slider button component with a label, providing functionality for + * adjusting values in a graphical user interface. It includes increment, decrement, + * and thumb buttons, allowing for interactive adjustments. + */ public class SliderButton extends AbstractButton { + + /** + * The label displayed next to the slider. + */ private Label label; + /** + * The slider component for adjusting values. + */ private Slider slider; + /** + * A container to hold the label and slider for layout management. + */ private Container container = new Container(); + /** + * The size of the slider button in relative units. + */ protected Vector2f size; + /** + * Constructs a SliderButton with the specified label. + * + * @param app the application instance for accessing resources + * @param node the node in the scene graph to which the slider button belongs + * @param label the text label displayed alongside the slider + */ public SliderButton(MdgaApp app, Node node, String label) { super(app, node); this.label = new Label(label); - this.label.setColor(TEXT_NORMAL); + // Configure the slider slider = new Slider("slider"); + // Configure decrement button slider.getDecrementButton().setText(" - "); slider.getDecrementButton().setFont(font); slider.getDecrementButton().setFocusColor(TEXT_NORMAL); @@ -32,6 +58,7 @@ public SliderButton(MdgaApp app, Node node, String label) { slider.getDecrementButton().setColor(TEXT_NORMAL); slider.getDecrementButton().setHighlightColor(TEXT_NORMAL); + // Configure increment button slider.getIncrementButton().setText(" + "); slider.getIncrementButton().setFont(font); slider.getIncrementButton().setFocusColor(TEXT_NORMAL); @@ -39,25 +66,32 @@ public SliderButton(MdgaApp app, Node node, String label) { slider.getIncrementButton().setColor(TEXT_NORMAL); slider.getIncrementButton().setHighlightColor(TEXT_NORMAL); + // Configure thumb button slider.getThumbButton().setText("X"); slider.getThumbButton().setFont(font); slider.getThumbButton().setFocusColor(TEXT_NORMAL); slider.getThumbButton().setColor(TEXT_NORMAL); slider.getThumbButton().setHighlightColor(TEXT_NORMAL); + // Set slider background QuadBackgroundComponent background = new QuadBackgroundComponent(BUTTON_NORMAL); slider.setBackground(background); + // Configure the label font this.label.setFont(font); - pos = new Vector2f( 0, 0); + // Default position and size + pos = new Vector2f(0, 0); size = new Vector2f(5.5f, 1); + // Add label and slider to container container.addChild(this.label); - container.addChild(slider); } + /** + * Displays the slider button by attaching its container to the scene graph. + */ @Override public void show() { calculateRelative(); @@ -66,44 +100,64 @@ public void show() { node.attachChild(container); } + /** + * Hides the slider button by detaching its container from the scene graph. + */ @Override public void hide() { node.detachChild(container); } + /** + * Sets the relative size and position of the slider button based on screen resolution. + */ protected void setRelative() { this.label.setFontSize(fontSize); + // Set font sizes for slider components slider.getDecrementButton().setFontSize(fontSize); slider.getIncrementButton().setFontSize(fontSize); slider.getThumbButton().setFontSize(fontSize); + // Set slider size slider.setPreferredSize(new Vector3f(size.x * widthStep, size.y * heightStep, 0)); float xAdjust = 0.0f; - if(adjust) { + if (adjust) { xAdjust = container.getPreferredSize().x; } + // Set container position 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; + 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) { + if (0 == pos.x) { container.setLocalTranslation(horizontalMid, container.getLocalTranslation().y, -1); } - if(0 == pos.y) { + if (0 == pos.y) { container.setLocalTranslation(container.getLocalTranslation().x, verticalMid, -1); } } + /** + * Retrieves the current percentage value of the slider. + * + * @return the current percentage value as a float + */ public float getPercent() { return (float) slider.getModel().getPercent(); } + /** + * Sets the slider to the specified percentage value. + * + * @param percent the percentage value to set + */ public void setPercent(float percent) { slider.getModel().setPercent(percent); } } +