feat: added jank way to scale text

This commit is contained in:
əlemi 2023-01-30 03:35:06 +01:00
parent 2e9321c305
commit a38a214a5e
No known key found for this signature in database
GPG key ID: BBCBFE5D7244634E
4 changed files with 33 additions and 18 deletions

View file

@ -21,7 +21,7 @@ public class ActiveModules extends HudModule {
@SubscribeEvent @SubscribeEvent
public void onRenderOverlay(RenderGameOverlayEvent event) { public void onRenderOverlay(RenderGameOverlayEvent event) {
if (event.getType() == ElementType.TEXT) { if (event.getType() == ElementType.TEXT) {
float offset = 0.0f; int offset = 0;
for (Module m : BoSCoVicino.mods) { for (Module m : BoSCoVicino.mods) {
if (m.enabled.get() && m.group != Group.HUD) { if (m.enabled.get() && m.group != Group.HUD) {
TextBuilder() TextBuilder()
@ -29,6 +29,7 @@ public class ActiveModules extends HudModule {
.anchor(this.anchor.get()) .anchor(this.anchor.get())
.x(this.x.get()) .x(this.x.get())
.y(this.y.get() + offset) .y(this.y.get() + offset)
.scale(this.scale.get())
.render(event.getMatrixStack(), event.getWindow()); .render(event.getMatrixStack(), event.getWindow());
offset += BoSCoVicino.minecraft.font.lineHeight; offset += BoSCoVicino.minecraft.font.lineHeight;
} }

View file

@ -26,10 +26,10 @@ public class Coordinates extends HudModule {
Vector3d position = mc.player.position(); Vector3d position = mc.player.position();
TextBuilder() TextBuilder()
.txt(String.format("[ X %.1f | %.1f Z ] %.1f Y", position.x(), position.z(), position.y())) .txt(String.format("[ X %.1f | %.1f Z ] %.1f Y", position.x(), position.z(), position.y()))
// .anchor(this.anchor.get())
.anchor(this.anchor.get()) .anchor(this.anchor.get())
.x(this.x.get()) .x(this.x.get())
.y(this.y.get()) .y(this.y.get())
.scale(this.scale.get())
.render(event.getMatrixStack(), event.getWindow()); .render(event.getMatrixStack(), event.getWindow());
} }
} }

View file

@ -13,7 +13,7 @@ public enum Anchor {
private Anchor(String in) { } private Anchor(String in) { }
public Vector2f translate(Vector2f in, int textWidth, int lineHeight, MainWindow window) { public Vector2f translate(Vector2f in, int textWidth, int lineHeight, float scale, MainWindow window) {
int offset = 0; int offset = 0;
switch (this) { switch (this) {
case BOTTOMLEFT: case BOTTOMLEFT:
@ -24,25 +24,26 @@ public enum Anchor {
} }
default: default:
} }
// TODO de-spaghetti this mess
switch (this) { switch (this) {
case TOPLEFT: case TOPLEFT:
return new Vector2f(in.x, in.y); return new Vector2f(in.x, in.y);
case TOPCENTER: case TOPCENTER:
return new Vector2f((window.getWidth()/4.0f) + in.x - (textWidth / 2), in.y); return new Vector2f((window.getWidth() / (scale * 4.0f)) + in.x - (textWidth / 2), in.y);
case TOPRIGHT: case TOPRIGHT:
return new Vector2f((window.getWidth()/2.0f) - (in.x + textWidth), in.y); return new Vector2f((window.getWidth() / (scale * 2.0f)) - (in.x + textWidth), in.y);
case MIDDLELEFT: case MIDDLELEFT:
return new Vector2f(in.x, (window.getHeight()/4.0f) + in.y - (lineHeight / 2)); return new Vector2f(in.x, (window.getHeight() / (scale * 4.0f)) + in.y - (lineHeight / 2));
case MIDDLECENTER: case MIDDLECENTER:
return new Vector2f((window.getWidth()/4.0f) + in.x - (textWidth / 2), (window.getHeight()/4.0f) + in.y - (lineHeight / 2)); return new Vector2f((window.getWidth() / (scale * 4.0f)) + in.x - (textWidth / 2), (window.getHeight() / (scale * 4.0f)) + in.y - (lineHeight / 2));
case MIDDLERIGHT: case MIDDLERIGHT:
return new Vector2f((window.getWidth()/2.0f) - (in.x + textWidth), (window.getHeight()/4.0f) + in.y - (lineHeight / 2)); return new Vector2f((window.getWidth() / (scale * 2.0f)) - (in.x + textWidth ), (window.getHeight() / (scale * 4.0f)) + in.y - (lineHeight / 2));
case BOTTOMLEFT: case BOTTOMLEFT:
return new Vector2f(in.x, (window.getHeight()/2.0f) - (in.y + lineHeight + offset)); return new Vector2f(in.x, (window.getHeight() / (scale * 2.0f)) - (in.y + lineHeight + offset));
case BOTTOMCENTER: case BOTTOMCENTER:
return new Vector2f((window.getWidth()/4.0f) + in.x - (textWidth / 2), (window.getHeight()/2.0f) - (in.y + lineHeight + offset)); return new Vector2f((window.getWidth() / (scale * 4.0f)) + in.x - (textWidth / 2), (window.getHeight() / (scale * 2.0f)) - (in.y + lineHeight + offset));
case BOTTOMRIGHT: case BOTTOMRIGHT:
return new Vector2f((window.getWidth()/2.0f) - (in.x + textWidth), (window.getHeight()/2.0f) - (in.y + lineHeight + offset)); return new Vector2f((window.getWidth() / (scale * 4.0f)) - (in.x + textWidth), (window.getHeight() / (scale * 2.0f)) - (in.y + lineHeight + offset));
default: default:
return new Vector2f(0.0f, 0.0f); return new Vector2f(0.0f, 0.0f);
} }

View file

@ -1,6 +1,7 @@
package co.fantabos.bscv.tools; package co.fantabos.bscv.tools;
import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import co.fantabos.bscv.BoSCoVicino; import co.fantabos.bscv.BoSCoVicino;
import co.fantabos.bscv.tools.Anchor; import co.fantabos.bscv.tools.Anchor;
@ -17,15 +18,17 @@ public final class Text {
String text; String text;
Anchor anchor; Anchor anchor;
Style style; Style style;
float x; int x;
float y; int y;
double scale;
private Text() { private Text() {
this.text = ""; this.text = "";
this.anchor = Anchor.TOPLEFT; this.anchor = Anchor.TOPLEFT;
this.style = Style.EMPTY.withColor(Color.fromRgb(16777215)); this.style = Style.EMPTY.withColor(Color.fromRgb(16777215));
this.x = 0.0f; this.x = 0;
this.y = 0.0f; this.y = 0;
this.scale = 1.0;
} }
public static Text TextBuilder() { public static Text TextBuilder() {
@ -47,16 +50,21 @@ public final class Text {
return this; return this;
} }
public Text x(float x) { public Text x(int x) {
this.x = x; this.x = x;
return this; return this;
} }
public Text y(float y) { public Text y(int y) {
this.y = y; this.y = y;
return this; return this;
} }
public Text scale(double scale) {
this.scale = scale;
return this;
}
public void render(MatrixStack stack, MainWindow window) { public void render(MatrixStack stack, MainWindow window) {
FontRenderer font = BoSCoVicino.minecraft.font; FontRenderer font = BoSCoVicino.minecraft.font;
ITextComponent text = new StringTextComponent(this.text).setStyle(this.style); ITextComponent text = new StringTextComponent(this.text).setStyle(this.style);
@ -64,14 +72,19 @@ public final class Text {
new Vector2f(this.x, this.y), new Vector2f(this.x, this.y),
font.width(text), font.width(text),
font.lineHeight, font.lineHeight,
(float) this.scale,
window window
); );
// TODO is there any non-deprecated way?
RenderSystem.pushMatrix();
RenderSystem.scaled(this.scale, this.scale, this.scale);
font.drawShadow( font.drawShadow(
stack, stack,
text, text,
abs_coords.x, abs_coords.x,
abs_coords.y, abs_coords.y,
0 // ???? TODO! 10 // ???? TODO!
); );
RenderSystem.popMatrix();
} }
} }