Skip to content

Commit

Permalink
configurable frame width & height
Browse files Browse the repository at this point in the history
Signed-off-by: Octol1ttle <[email protected]>
  • Loading branch information
Octol1ttle committed Feb 11, 2024
1 parent 6a21fe7 commit 8063763
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 30 deletions.
20 changes: 20 additions & 0 deletions src/main/java/ru/octol1ttle/flightassistant/FAModMenuImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@ public ConfigScreenFactory<?> getModConfigScreenFactory() {
)
.build()
)
.option(Option.<Float>createBuilder()
.name(Text.translatable("config.flightassistant.settings.frame_width"))
.binding(0.6f, () -> config.frameWidth, o -> config.frameWidth = o)
.controller(opt -> FloatSliderControllerBuilder.create(opt)
.range(0.3f, 0.9f)
.step(0.05f)
.formatValue(value -> Text.literal(MathHelper.floor(value * 100.0f) + "%"))
)
.build()
)
.option(Option.<Float>createBuilder()
.name(Text.translatable("config.flightassistant.settings.frame_height"))
.binding(0.6f, () -> config.frameHeight, o -> config.frameHeight = o)
.controller(opt -> FloatSliderControllerBuilder.create(opt)
.range(0.3f, 0.9f)
.step(0.05f)
.formatValue(value -> Text.literal(MathHelper.floor(value * 100.0f) + "%"))
)
.build()
)
.build()
)
).generateScreen(parent);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/ru/octol1ttle/flightassistant/HudComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public static void drawHorizontalLine(DrawContext context, float x1, float x2, f
x1 = x2;
x2 = i;
}
fill(context, x1 - 0.5f /* TODO: remove this */, y - 0.5f /* TODO: remove this */, x2 + 0.5f /* TODO: remove this */,
y + 0.5f /* TODO: remove this */, color);
fill(context, x1 - FAConfig.halfThickness(), y - FAConfig.halfThickness(), x2 + FAConfig.halfThickness(),
y + FAConfig.halfThickness(), color);
}

public static void drawVerticalLine(DrawContext context, float x, float y1, float y2, Color color) {
Expand All @@ -82,8 +82,8 @@ public static void drawVerticalLine(DrawContext context, float x, float y1, floa
y2 = i;
}

fill(context, x - 0.5f /* TODO: remove this */, y1 + 0.5f /* TODO: remove this */, x + 0.5f /* TODO: remove this */,
y2 - 0.5f /* TODO: remove this */, color);
fill(context, x - FAConfig.halfThickness(), y1 + FAConfig.halfThickness(), x + FAConfig.halfThickness(),
y2 - FAConfig.halfThickness(), color);
}

public static void drawBox(DrawContext context, float x, float y, float w, Color color) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public class FAConfig {
public float frameWidth = 0.6f;
@SerialEntry
public float frameHeight = 0.6f;
@SerialEntry
public float frameThickness = 1.0f;

public static void setup() {
HANDLER.load();
Expand Down Expand Up @@ -69,6 +67,10 @@ public static HudConfig hud() {
return HANDLER.instance().notFlyingNoElytra;
}

public static float halfThickness() {
return 0.5f;
}

public enum BatchedRendering implements NameableEnum {
NO_BATCHING,
BATCH_PER_COMPONENT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void render(DrawContext context, TextRenderer textRenderer) {
for (AbstractAlert alert : alert.activeAlerts) {
if (!renderedCentered) {
renderedCentered = alert.renderCentered(textRenderer, context, dim.xMid,
dim.hScreen * 0.5f + 10, time.highlight);
dim.yMid + 10, time.highlight);
}

if (!alert.hidden) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public void render(DrawContext context, TextRenderer textRenderer) {

if (FAConfig.hud().altitude_showGround) {
Color color = data.altitude < safeLevel ? FAConfig.hud().warningTextColor : FAConfig.hud().frameColor;
drawText(textRenderer, context, Text.translatable(data.groundLevel == data.voidLevel ? "flightassistant.void_level" : "flightassistant.ground_level"), xAltText - 10, bottom + 3, color);
drawText(textRenderer, context, asText("%d", i(data.heightAboveGround)), xAltText, bottom + 3, color);
drawBox(context, xAltText - 2, bottom + 1.5f, 28, color);
drawText(textRenderer, context, Text.translatable(data.groundLevel == data.voidLevel ? "flightassistant.void_level" : "flightassistant.ground_level"), xAltText - 10, bottom, color);
drawText(textRenderer, context, asText("%d", i(data.heightAboveGround)), xAltText, bottom, color);
drawBox(context, xAltText - 2, bottom - 1.5f, 28, color);
}

if (FAConfig.hud().altitude_showScale) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public ElytraHealthIndicator(Dimensions dim, AirDataComputer data) {

@Override
public void render(DrawContext context, TextRenderer textRenderer) {
float x = dim.wScreen * FAConfig.hud().elytra_x;
float y = dim.hScreen * FAConfig.hud().elytra_y;
float x = dim.xMid;
float y = dim.bFrame;

if (FAConfig.hud().elytra_showHealth && data.elytraHealth != null) {
Color color;
Expand All @@ -42,7 +42,7 @@ public void render(DrawContext context, TextRenderer textRenderer) {
@Override
public void renderFaulted(DrawContext context, TextRenderer textRenderer) {
drawText(textRenderer, context, Text.translatable("flightassistant.elytra_health_short"),
dim.wScreen * FAConfig.hud().elytra_x, dim.hScreen * FAConfig.hud().elytra_y,
dim.wFrame * FAConfig.hud().elytra_x, dim.hFrame * FAConfig.hud().elytra_y,
FAConfig.hud().warningTextColor);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public void render(DrawContext context, TextRenderer textRenderer) {

float l = x - 3;
float r = x + 3;
float t = y - 3 - 0.5f /* TODO: remove this */;
float b = y + 3 - 0.5f /* TODO: remove this */;
float t = y - 3 - FAConfig.halfThickness();
float b = y + 3 - FAConfig.halfThickness();

Color color = gpws.getGPWSLampColor();
drawVerticalLine(context, l, t, b, color);
Expand All @@ -57,8 +57,8 @@ public void render(DrawContext context, TextRenderer textRenderer) {
drawHorizontalLine(context, l, r, b, color);

drawVerticalLine(context, x, t - 5, t, color);
drawHorizontalLine(context, l - 4, l, y - 0.5f /* TODO: remove this */, color);
drawHorizontalLine(context, r, r + 4, y - 0.5f /* TODO: remove this */, color);
drawHorizontalLine(context, l - 4, l, y - FAConfig.halfThickness(), color);
drawHorizontalLine(context, r, r + 4, y - FAConfig.halfThickness(), color);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public void render(DrawContext context, TextRenderer textRenderer) {
return;
}

float x = dim.wScreen * FAConfig.hud().location_x;
float y = dim.hScreen * FAConfig.hud().location_y;
float x = dim.lFrame + 15;
float y = dim.bFrame;

int xLoc = i((float) data.position.x);
int zLoc = i((float) data.position.z);
Expand All @@ -36,7 +36,7 @@ public void render(DrawContext context, TextRenderer textRenderer) {
@Override
public void renderFaulted(DrawContext context, TextRenderer textRenderer) {
drawText(textRenderer, context, Text.translatable("flightassistant.location_short"),
dim.wScreen * FAConfig.hud().location_x, dim.hScreen * FAConfig.hud().location_y, FAConfig.hud().warningTextColor);
dim.wFrame * FAConfig.hud().location_x, dim.hFrame * FAConfig.hud().location_y, FAConfig.hud().warningTextColor);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ private void drawReferenceMark(DrawContext context, float yHorizon, float degree
}

private void drawDegreeBar(TextRenderer textRenderer, DrawContext context, float degree, float y) {

if (y < dim.tFrame || y > dim.bFrame) {
return;
}
Expand All @@ -129,10 +128,8 @@ private void drawDegreeBar(TextRenderer textRenderer, DrawContext context, float
y - fontVerticalOffset, color);
}

// TODO: this is absolutely terrible. the amount of imprecision this causes is absurd. (but that can be said about all rendering code here)
private static class PitchIndicatorData {
public float width;
public float mid;
public float margin;
public float sideWidth;
public float l1;
Expand All @@ -141,15 +138,14 @@ private static class PitchIndicatorData {
public float r2;

public void update(Dimensions dim) {
width = i(dim.wScreen / 3.0f);
float left = width;
width = dim.wFrame * 0.5f;
float left = dim.lFrame + (width * 0.5f);

mid = i((width * 0.5f) + left);
margin = i(width * 0.3d);
l1 = left + margin;
l2 = mid - 7;
l2 = dim.xMid - 7;
sideWidth = l2 - l1;
r1 = mid + 8;
r1 = dim.xMid + 8;
r2 = r1 + sideWidth;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ public void render(DrawContext context, TextRenderer textRenderer) {
drawBox(context, xSpeedText - 29.5f, dim.yMid - 4.5f, 30, FAConfig.hud().frameColor);

float frameWidth = dim.rFrame - dim.lFrame;
drawText(textRenderer, context, Text.translatable("flightassistant.ground_speed_short", String.format("%.2f", data.velocityPerSecond.horizontalLength())), dim.lFrame + frameWidth * 0.25f, dim.hScreen * 0.8f, FAConfig.hud().frameColor);
drawText(textRenderer, context, Text.translatable("flightassistant.vertical_speed_short", String.format("%.2f", data.velocityPerSecond.y)), dim.lFrame + frameWidth * 0.75f - 7, dim.hScreen * 0.8f, data.velocityPerSecond.y <= -10.0f ? FAConfig.hud().warningTextColor : FAConfig.hud().frameColor);
// TODO: separate indicator
drawText(textRenderer, context, Text.translatable("flightassistant.ground_speed_short", String.format("%.2f", data.velocityPerSecond.horizontalLength())), dim.lFrame + frameWidth * 0.25f, dim.bFrame, FAConfig.hud().frameColor);
drawText(textRenderer, context, Text.translatable("flightassistant.vertical_speed_short", String.format("%.2f", data.velocityPerSecond.y)), dim.lFrame + frameWidth * 0.75f - 7, dim.bFrame, data.velocityPerSecond.y <= -10.0f ? FAConfig.hud().warningTextColor : FAConfig.hud().frameColor);
}


Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/flightassistant/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"config.flightassistant.options.batching.batch_per_component": "Batch Per Component",
"config.flightassistant.options.batching.single_batch": "Single Batch",
"config.flightassistant.settings.hud_scale": "HUD Scale",
"config.flightassistant.settings.frame_width": "HUD Frame Width",
"config.flightassistant.settings.frame_height": "HUD Frame Height",

"commands.flightassistant.no_such_waypoint": "There is no waypoint at that index",
"commands.flightassistant.nothing_to_clear": "There are no waypoints to clear",
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/flightassistant/lang/ru_ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"config.flightassistant.options.batching.batch_per_component": "Группировать по компонентам",
"config.flightassistant.options.batching.single_batch": "Группировать всё целиком",
"config.flightassistant.settings.hud_scale": "Масштаб HUD",
"config.flightassistant.settings.frame_width": "Ширина рамки HUD",
"config.flightassistant.settings.frame_height": "Высота рамки HUD",

"commands.flightassistant.no_such_waypoint": "На указанной позиции нет точки назначения",
"commands.flightassistant.nothing_to_clear": "Нет точек назначения для очищения",
Expand Down

0 comments on commit 8063763

Please sign in to comment.