All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.codingame.gameengine.module.entities.TextBasedEntity Maven / Gradle / Ivy

package com.codingame.gameengine.module.entities;

import java.util.Objects;

/**
 * Generic type for entities containing text.
 * @param  a subclass inheriting TextureBasedEntity, used in order to return this as a T instead of a TextBasedEntity.
 */
public abstract class TextBasedEntity> extends TextureBasedEntity {
    /**
     * This is an enumeration that contains the three options for text alignment: left, center, and right.
     */
    public static enum TextAlign {
        /**
         * Align text left
         */
        LEFT(0),
        /**
         * Align text center
         */
        CENTER(1),
        /**
         * Align text right
         */
        RIGHT(2);

        private int value;

        private TextAlign(int value) {
            this.value = value;
        }

        private int getValue() {
            return value;
        }
    }

    protected String text = "";
    protected int fontSize = 26;
    protected int maxWidth = 0;
    protected TextAlign textAlign;

    /**
     * Returns the string this TextBasedEntity displays.
     * 

* Default is "" (empty string). * * @return the string of this TextBasedEntity. */ public String getText() { return text; } /** * Sets the string for this TextBasedEntity to display. * * @param text * the string for this TextBasedEntity to display. * @return this Text. * @exception NullPointerException * if text is null. */ public T setText(String text) { Objects.requireNonNull(text); this.text = text; set("text", text, null); return self(); } /** * Returns text alignment of this TextBasedEntity. *

* Default is TextAlign.LEFT (align left). * * @return the text alignment of this TextBasedEntity. */ public TextAlign getTextAlign() { return textAlign; } /** * Sets the text alignment of this TextBasedEntity. * * @param align * the text alignment of this TextBasedEntity. * @return this Text. * @exception NullPointerException * if align is null. */ public T setTextAlign(TextAlign align) { Objects.requireNonNull(align); this.textAlign = align; set("textAlign", align.getValue(), null); return self(); } /** * Returns the size of the font of this TextBasedEntity in px. *

* Default is 26. * * @return the size of the font of this TextBasedEntity. */ public int getFontSize() { return fontSize; } /** * Sets the size of the font of this TextBasedEntity in px. * * * @param fontSize * the size for the font of this TextBasedEntity. * @return this Text. */ public T setFontSize(int fontSize) { return setFontSize(fontSize, null); } /** * Sets the size of the font of this TextBasedEntity in px. * * * @param fontSize * the size for the font of this TextBasedEntity. * @param curve * the transition to animate between values of this property. * @return this Text. */ public T setFontSize(int fontSize, Curve curve) { this.fontSize = fontSize; set("fontSize", fontSize, curve); return self(); } /** * Returns the maximum width of this TextBasedEntity in pixels, before it gets ellipsed. *

* The ellipsis is applied before the entity is scaled. A max width of 0 means there is no maximum width. *

*

* Default is 0 (no max width). *

* @return the maximum width in pixels of this TextBasedEntity. */ public int getMaxWidth() { return maxWidth; } /** * Sets the maximum width of this TextBasedEntity in pixels before it gets ellipsed. *

* The ellipsis is applied before the entity is scaled. A max width of 0 means there is no maximum width. *

*

* Default is 0 (no max width). *

* * @param maxWidth * the maximum width in pixels of this TextBasedEntity. * @return this Text. */ public T setMaxWidth(int maxWidth) { if (maxWidth < 0) { throw new IllegalArgumentException("Invalid max width: " + maxWidth); } this.maxWidth = maxWidth; set("maxWidth", maxWidth, null); return self(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy