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;
}
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);
}
}
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;
}
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());
}
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;
}
Aggregations