Search in sources :

Example 16 with Color

use of org.terasology.nui.Color in project Terasology by MovingBlocks.

the class ColorConstraintWidgetFactory method findClosestIndex.

private float findClosestIndex(Color color) {
    int best = 0;
    float minDist = Float.MAX_VALUE;
    for (int i = 0; i < colors.size(); i++) {
        Color other = colors.get(i);
        float dr = other.rf() - color.rf();
        float dg = other.gf() - color.gf();
        float db = other.bf() - color.bf();
        // there are certainly smarter ways to measure color distance,
        // but Euclidean distance is good enough for the purpose
        float dist = dr * dr + dg * dg + db * db;
        if (dist < minDist) {
            minDist = dist;
            best = i;
        }
    }
    float max = colors.size() - 1;
    return best / max;
}
Also used : Color(org.terasology.nui.Color) ColorConstraint(org.terasology.engine.config.flexible.constraints.ColorConstraint)

Example 17 with Color

use of org.terasology.nui.Color in project Terasology by MovingBlocks.

the class JoinGameScreen method getModulesText.

private String getModulesText(Future<ServerInfoMessage> info) {
    try {
        ServerInfoMessage serverInfoMessage = info.get();
        if (serverInfoMessage == null) {
            return FontColor.getColored(translationSystem.translate("${engine:menu#connection-failed}"), Color.RED);
        }
        List<String> codedModInfo = new ArrayList<>();
        ModuleRegistry reg = moduleManager.getRegistry();
        for (NameVersion entry : serverInfoMessage.getModuleList()) {
            boolean isInstalled = reg.getModule(entry.getName(), entry.getVersion()) != null;
            Color color = isInstalled ? Color.GREEN : Color.RED;
            codedModInfo.add(FontColor.getColored(entry.toString(), color));
        }
        Collections.sort(codedModInfo, String.CASE_INSENSITIVE_ORDER);
        return Joiner.on('\n').join(codedModInfo);
    } catch (ExecutionException | InterruptedException e) {
        return FontColor.getColored(translationSystem.translate("${engine:menu#connection-failed}"), Color.RED);
    }
}
Also used : NameVersion(org.terasology.gestalt.naming.NameVersion) Color(org.terasology.nui.Color) FontColor(org.terasology.nui.FontColor) ArrayList(java.util.ArrayList) ModuleRegistry(org.terasology.gestalt.module.ModuleRegistry) ServerInfoMessage(org.terasology.engine.network.ServerInfoMessage) ExecutionException(java.util.concurrent.ExecutionException)

Example 18 with Color

use of org.terasology.nui.Color in project Terasology by MovingBlocks.

the class NameTagComponent method copyFrom.

@Override
public void copyFrom(NameTagComponent other) {
    this.yOffset = other.yOffset;
    this.text = other.text;
    this.textColor = new Color(other.textColor);
    this.scale = other.scale;
}
Also used : Color(org.terasology.nui.Color)

Example 19 with Color

use of org.terasology.nui.Color in project Terasology by MovingBlocks.

the class ColorTypeHandlerTest method testDeserializeHex.

@Test
public void testDeserializeHex() {
    PersistedData data = new PersistedString("DEADBEEF");
    Color color = handler.deserialize(data).get();
    assertEquals(0xDEADBEEF, color.rgba());
}
Also used : PersistedString(org.terasology.persistence.typeHandling.inMemory.PersistedString) Color(org.terasology.nui.Color) PersistedData(org.terasology.persistence.typeHandling.PersistedData) Test(org.junit.jupiter.api.Test)

Example 20 with Color

use of org.terasology.nui.Color in project Terasology by MovingBlocks.

the class BehaviorNodeComponent method copyFrom.

@Override
public void copyFrom(BehaviorNodeComponent other) {
    this.action = other.action;
    this.name = other.name;
    this.displayName = other.displayName;
    this.category = other.category;
    this.shape = other.shape;
    this.color = new Color(other.color);
    this.textColor = new Color(other.textColor);
    this.description = other.description;
}
Also used : Color(org.terasology.nui.Color)

Aggregations

Color (org.terasology.nui.Color)39 Test (org.junit.jupiter.api.Test)9 Vector3f (org.joml.Vector3f)5 ByteBuffer (java.nio.ByteBuffer)3 Mesh (org.terasology.engine.rendering.assets.mesh.Mesh)3 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)3 Colorc (org.terasology.nui.Colorc)3 ColorModel (java.awt.image.ColorModel)2 DataBufferInt (java.awt.image.DataBufferInt)2 Vector2f (org.joml.Vector2f)2 Vector3fc (org.joml.Vector3fc)2 Vector4f (org.joml.Vector4f)2 Test (org.junit.Test)2 ColorConstraint (org.terasology.engine.config.flexible.constraints.ColorConstraint)2 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)2 StandardMeshData (org.terasology.engine.rendering.assets.mesh.StandardMeshData)2 VertexResource (org.terasology.engine.rendering.assets.mesh.resource.VertexResource)2 VertexResourceBuilder (org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder)2 ParagraphRenderStyle (org.terasology.engine.rendering.nui.widgets.browser.ui.style.ParagraphRenderStyle)2 FastRandom (org.terasology.engine.utilities.random.FastRandom)2