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

View file

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

View file

@ -13,7 +13,7 @@ public enum Anchor {
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;
switch (this) {
case BOTTOMLEFT:
@ -24,25 +24,26 @@ public enum Anchor {
}
default:
}
// TODO de-spaghetti this mess
switch (this) {
case TOPLEFT:
return new Vector2f(in.x, in.y);
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:
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:
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:
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:
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:
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:
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:
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:
return new Vector2f(0.0f, 0.0f);
}

View file

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