Fixed text encoding, texture transparency, labels in debug layer

This commit is contained in:
OLEGSHA 2021-01-12 21:11:53 +03:00
parent 802f736e37
commit b3ce0ca3c4
4 changed files with 54 additions and 19 deletions

View File

@ -50,10 +50,10 @@ public class Colors {
}
public static Vec4 toVector(int argb, Vec4 output) {
output.w = ((argb & 0xFF000000) >>> 24) / 256f; // Alpha
output.x = ((argb & 0x00FF0000) >>> 16) / 256f; // Red
output.y = ((argb & 0x0000FF00) >>> 8) / 256f; // Green
output.z = ((argb & 0x000000FF) ) / 256f; // Blue
output.w = ((argb & 0xFF000000) >>> 24) / (float) 0xFF; // Alpha
output.x = ((argb & 0x00FF0000) >>> 16) / (float) 0xFF; // Red
output.y = ((argb & 0x0000FF00) >>> 8) / (float) 0xFF; // Green
output.z = ((argb & 0x000000FF) ) / (float) 0xFF; // Blue
return output;
}

View File

@ -6,6 +6,7 @@ import ru.windcorp.progressia.client.graphics.flat.RenderTarget;
import ru.windcorp.progressia.client.graphics.font.Font;
import ru.windcorp.progressia.client.localization.MutableString;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier;
public class Label extends Component {
@ -31,9 +32,21 @@ public class Label extends Component {
}
public Label(String name, Font font, MutableString contents) {
this(name, font, contents::get);
// Not the most elegant solution
this.mutableStringListener = this::update;
this(name, font, () -> {
contents.update();
return contents.get();
});
AtomicBoolean isUpdating = new AtomicBoolean();
this.mutableStringListener = () -> {
if (isUpdating.compareAndSet(false, true)) {
this.update();
isUpdating.set(false);
}
};
contents.addListener(mutableStringListener);
}

View File

@ -22,6 +22,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import org.lwjgl.BufferUtils;
@ -44,7 +45,7 @@ public class Resource extends Named {
}
public Reader getReader() {
return new InputStreamReader(getInputStream());
return new InputStreamReader(getInputStream(), StandardCharsets.UTF_8);
}
public String readAsString() {

View File

@ -19,6 +19,7 @@ package ru.windcorp.progressia.test;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Objects;
import java.util.function.Supplier;
import glm.vec._3.Vec3;
@ -35,6 +36,7 @@ import ru.windcorp.progressia.client.graphics.gui.Panel;
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutAlign;
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutVertical;
import ru.windcorp.progressia.client.localization.Localizer;
import ru.windcorp.progressia.client.localization.MutableString;
import ru.windcorp.progressia.client.localization.MutableStringLocalized;
import ru.windcorp.progressia.common.Units;
import ru.windcorp.progressia.common.util.dynstr.DynamicStrings;
@ -55,32 +57,32 @@ public class LayerTestGUI extends GUILayer {
panel.addChild(new Label(
"IsFlyingDisplay", font,
new MutableStringLocalized("LayerTestGUI.IsFlyingDisplay").format(tpc.isFlying())
tmp_dynFormat("LayerTestGUI.IsFlyingDisplay", tpc::isFlying)
));
panel.addChild(new Label(
"IsSprintingDisplay", font,
new MutableStringLocalized("LayerTestGUI.IsSprintingDisplay").format(tpc.isSprinting())
tmp_dynFormat("LayerTestGUI.IsSprintingDisplay", tpc::isSprinting)
));
panel.addChild(new Label(
"IsMouseCapturedDisplay", font,
new MutableStringLocalized("LayerTestGUI.IsMouseCapturedDisplay").format(tpc.isMouseCaptured())
tmp_dynFormat("LayerTestGUI.IsMouseCapturedDisplay", tpc::isMouseCaptured)
));
panel.addChild(new Label(
"CameraModeDisplay", font,
new MutableStringLocalized("LayerTestGUI.CameraModeDisplay").format(ClientState.getInstance().getCamera().getCurrentModeIndex())
tmp_dynFormat("LayerTestGUI.CameraModeDisplay", ClientState.getInstance().getCamera()::getCurrentModeIndex)
));
panel.addChild(new Label(
"GravityModeDisplay", font,
new MutableStringLocalized("LayerTestGUI.GravityModeDisplay").format(tpc.useMinecraftGravity() ? "Minecraft" : "Realistic")
tmp_dynFormat("LayerTestGUI.GravityModeDisplay", () -> tpc.useMinecraftGravity() ? "Minecraft" : "Realistic")
));
panel.addChild(new Label(
"LanguageDisplay", font,
new MutableStringLocalized("LayerTestGUI.LanguageDisplay").apply(s -> String.format(s, Localizer.getInstance().getLanguage()))
tmp_dynFormat("LayerTestGUI.LanguageDisplay", Localizer.getInstance()::getLanguage)
));
panel.addChild(new DynamicLabel(
@ -115,16 +117,16 @@ public class LayerTestGUI extends GUILayer {
panel.addChild(new Label(
"SelectedBlockDisplay", font,
new MutableStringLocalized("LayerTestGUI.SelectedBlockDisplay").format(
TestPlayerControls.getInstance().isBlockSelected() ? ">" : " ",
TestPlayerControls.getInstance().getSelectedBlock().getId()
tmp_dynFormat("LayerTestGUI.SelectedBlockDisplay",
() -> tpc.isBlockSelected() ? ">" : " ",
() -> tpc.getSelectedBlock().getId()
)
));
panel.addChild(new Label(
"SelectedTileDisplay", font,
new MutableStringLocalized("LayerTestGUI.SelectedTileDisplay").format(
TestPlayerControls.getInstance().isBlockSelected() ? " " : ">",
TestPlayerControls.getInstance().getSelectedTile().getId()
tmp_dynFormat("LayerTestGUI.SelectedTileDisplay",
() -> tpc.isBlockSelected() ? " " : ">",
() -> tpc.getSelectedTile().getId()
)
));
panel.addChild(new Label(
@ -225,6 +227,25 @@ public class LayerTestGUI extends GUILayer {
}
}
private static MutableString tmp_dynFormat(String formatKey, Supplier<?>... suppliers) {
return new MutableStringLocalized(formatKey).apply(s -> {
Object[] args = new Object[suppliers.length];
for (int i = 0; i < suppliers.length; ++i) {
Supplier<?> supplier = suppliers[i];
Object value = supplier != null ? supplier.get() : "null";
if (!(value instanceof Number)) {
value = Objects.toString(value);
}
args[i] = value;
}
return String.format(s, args);
});
}
// private static class DebugComponent extends Component {
// private final int color;
//