Skip to content

Commit

Permalink
i have zero idea what i'm doing
Browse files Browse the repository at this point in the history
Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
  • Loading branch information
Octol1ttle committed Apr 2, 2024
1 parent bfbfefb commit 80240d6
Show file tree
Hide file tree
Showing 55 changed files with 400 additions and 353 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import net.minecraft.text.Text;
import ru.octol1ttle.flightassistant.compatibility.ImmediatelyFastBatchingAccessor;

public abstract class HudComponent {
public abstract class DrawHelper {
private static final int SINGLE_LINE_DRAWN = 1;

public static MutableText asText(String key, Object... args) {
Expand All @@ -18,7 +18,7 @@ public static void fill(DrawContext context, int x1, int y1, int x2, int y2, Col
context.fill(x1, y1, x2, y2, color.getRGB());
}

protected static void drawRightAlignedText(TextRenderer textRenderer, DrawContext context, Text text, int x, int y, Color color) {
public static void drawRightAlignedText(TextRenderer textRenderer, DrawContext context, Text text, int x, int y, Color color) {
drawText(textRenderer, context, text, x - textRenderer.getWidth(text), y, color);
}

Expand All @@ -34,10 +34,10 @@ public static void drawMiddleAlignedText(TextRenderer textRenderer, DrawContext
public static int drawHighlightedText(TextRenderer textRenderer, DrawContext context, Text text, int x, int y, Color color, boolean highlight) {
drawUnbatched(() -> {
if (highlight) {
HudComponent.fill(context, x - 2, y - 1, x + textRenderer.getWidth(text) + 1, y + 8, color);
HudComponent.drawText(textRenderer, context, text, x, y, getContrasting(color));
DrawHelper.fill(context, x - 2, y - 1, x + textRenderer.getWidth(text) + 1, y + 8, color);
DrawHelper.drawText(textRenderer, context, text, x, y, getContrasting(color));
} else {
HudComponent.drawText(textRenderer, context, text, x, y, color);
DrawHelper.drawText(textRenderer, context, text, x, y, color);
}
});
return SINGLE_LINE_DRAWN;
Expand Down Expand Up @@ -75,7 +75,7 @@ public static void drawBorder(DrawContext context, int x, int y, int w, Color co
context.drawBorder(x, y, w, 11, color.getRGB());
}

protected static void drawHorizontalLineDashed(DrawContext context, int x1, int x2, int y,
public static void drawHorizontalLineDashed(DrawContext context, int x1, int x2, int y,
int dashCount, Color color) {
int width = x2 - x1;
int segmentCount = dashCount * 2 - 1;
Expand All @@ -95,10 +95,4 @@ protected static void drawHorizontalLineDashed(DrawContext context, int x1, int
context.drawHorizontalLine(dx1, dx2, y, color.getRGB());
}
}

public abstract void render(DrawContext context, TextRenderer textRenderer);

public abstract void renderFaulted(DrawContext context, TextRenderer textRenderer);

public abstract String getId();
}
7 changes: 4 additions & 3 deletions src/main/java/ru/octol1ttle/flightassistant/FACallbacks.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import ru.octol1ttle.flightassistant.commands.ResetCommand;
import ru.octol1ttle.flightassistant.computers.ComputerHost;
import ru.octol1ttle.flightassistant.config.FAConfig;
import ru.octol1ttle.flightassistant.hud.HudDisplayHost;

import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;

Expand Down Expand Up @@ -43,20 +44,20 @@ private static void setupCommandRegistration() {

private static void setupWorldRender() {
WorldRenderEvents.END.register(context ->
HudRenderer.getHost().tick()
HudDisplayHost.getHost().tick()
);
}

private static void setupHudRender() {
AlternateHudRendererCallback.EVENT.register((drawContext, tickDelta) ->
HudRenderer.INSTANCE.render(MinecraftClient.getInstance(), drawContext, tickDelta)
HudDisplayHost.INSTANCE.render(MinecraftClient.getInstance(), drawContext, tickDelta)
);
}

private static void setupUseItem() {
UseItemCallback.EVENT.register((player, world, hand) -> {
ItemStack stack = player.getStackInHand(hand);
ComputerHost host = HudRenderer.getHost();
ComputerHost host = HudDisplayHost.getHost();
if (!world.isClient() || host.faulted.contains(host.firework)) {
return TypedActionResult.pass(stack);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.client.util.InputUtil;
import org.lwjgl.glfw.GLFW;
import ru.octol1ttle.flightassistant.computers.ComputerHost;
import ru.octol1ttle.flightassistant.hud.HudDisplayHost;

public class FAKeyBindings {
private static KeyBinding toggleFlightDirectors;
Expand Down Expand Up @@ -43,7 +44,7 @@ public static void setup() {
KeyBindingHelper.registerKeyBinding(lockManualFireworks);

ClientTickEvents.END_CLIENT_TICK.register(client -> {
ComputerHost host = HudRenderer.getHost();
ComputerHost host = HudDisplayHost.getHost();
if (!host.faulted.contains(host.autoflight)) {
while (toggleFlightDirectors.wasPressed()) {
host.autoflight.flightDirectorsEnabled = !host.autoflight.flightDirectorsEnabled;
Expand Down
137 changes: 0 additions & 137 deletions src/main/java/ru/octol1ttle/flightassistant/HudRenderer.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text;
import org.jetbrains.annotations.NotNull;
import ru.octol1ttle.flightassistant.HudComponent;
import ru.octol1ttle.flightassistant.DrawHelper;
import ru.octol1ttle.flightassistant.alerts.AlertSoundData;
import ru.octol1ttle.flightassistant.alerts.BaseAlert;
import ru.octol1ttle.flightassistant.alerts.IECAMAlert;
Expand All @@ -30,7 +30,7 @@ public boolean isTriggered() {

@Override
public int render(TextRenderer textRenderer, DrawContext context, int x, int y, boolean highlight) {
return HudComponent.drawHighlightedText(textRenderer, context, Text.translatable("alerts.flightassistant.autoflight.auto_firework_off"), x, y,
return DrawHelper.drawHighlightedText(textRenderer, context, Text.translatable("alerts.flightassistant.autoflight.auto_firework_off"), x, y,
FAConfig.indicator().cautionColor,
highlight && autoflight.afrwkDisconnectionForced);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text;
import org.jetbrains.annotations.NotNull;
import ru.octol1ttle.flightassistant.HudComponent;
import ru.octol1ttle.flightassistant.DrawHelper;
import ru.octol1ttle.flightassistant.alerts.AlertSoundData;
import ru.octol1ttle.flightassistant.alerts.BaseAlert;
import ru.octol1ttle.flightassistant.alerts.IECAMAlert;
Expand All @@ -30,7 +30,7 @@ public boolean isTriggered() {

@Override
public int render(TextRenderer textRenderer, DrawContext context, int x, int y, boolean highlight) {
return HudComponent.drawHighlightedText(textRenderer, context, Text.translatable("alerts.flightassistant.autoflight.autopilot_off"), x, y,
return DrawHelper.drawHighlightedText(textRenderer, context, Text.translatable("alerts.flightassistant.autoflight.autopilot_off"), x, y,
FAConfig.indicator().warningColor,
highlight && autoflight.apDisconnectionForced);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text;
import org.jetbrains.annotations.NotNull;
import ru.octol1ttle.flightassistant.HudComponent;
import ru.octol1ttle.flightassistant.DrawHelper;
import ru.octol1ttle.flightassistant.alerts.AlertSoundData;
import ru.octol1ttle.flightassistant.alerts.BaseAlert;
import ru.octol1ttle.flightassistant.alerts.IECAMAlert;
Expand Down Expand Up @@ -33,7 +33,7 @@ public boolean isTriggered() {
public int render(TextRenderer textRenderer, DrawContext context, int x, int y, boolean highlight) {
int i = 0;
for (IComputer computer : host.faulted) {
i += HudComponent.drawHighlightedText(textRenderer, context, Text.translatable("alerts.flightassistant.fault.computers." + computer.getId()), x, y,
i += DrawHelper.drawHighlightedText(textRenderer, context, Text.translatable("alerts.flightassistant.fault.computers." + computer.getId()), x, y,
FAConfig.indicator().warningColor, highlight);
y += 10;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text;
import org.jetbrains.annotations.NotNull;
import ru.octol1ttle.flightassistant.HudComponent;
import ru.octol1ttle.flightassistant.HudRenderer;
import ru.octol1ttle.flightassistant.DrawHelper;
import ru.octol1ttle.flightassistant.alerts.AlertSoundData;
import ru.octol1ttle.flightassistant.alerts.BaseAlert;
import ru.octol1ttle.flightassistant.alerts.IECAMAlert;
import ru.octol1ttle.flightassistant.config.FAConfig;
import ru.octol1ttle.flightassistant.hud.HudDisplayHost;
import ru.octol1ttle.flightassistant.hud.api.IHudDisplay;


public class IndicatorFaultAlert extends BaseAlert implements IECAMAlert {
private final HudDisplayHost renderer;

private final HudRenderer renderer;

public IndicatorFaultAlert(HudRenderer renderer) {
public IndicatorFaultAlert(HudDisplayHost renderer) {
this.renderer = renderer;
}

Expand All @@ -33,8 +33,8 @@ public boolean isTriggered() {
@Override
public int render(TextRenderer textRenderer, DrawContext context, int x, int y, boolean highlight) {
int i = 0;
for (HudComponent component : renderer.faulted) {
i += HudComponent.drawText(textRenderer, context, Text.translatable("alerts.flightassistant.fault.indicators." + component.getId()), x, y,
for (IHudDisplay display : renderer.faulted) {
i += DrawHelper.drawText(textRenderer, context, Text.translatable("alerts.flightassistant.fault.hud." + display.getId()), x, y,
FAConfig.indicator().cautionColor);
y += 10;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text;
import org.jetbrains.annotations.NotNull;
import ru.octol1ttle.flightassistant.HudComponent;
import ru.octol1ttle.flightassistant.DrawHelper;
import ru.octol1ttle.flightassistant.alerts.AlertSoundData;
import ru.octol1ttle.flightassistant.alerts.BaseAlert;
import ru.octol1ttle.flightassistant.alerts.IECAMAlert;
Expand Down Expand Up @@ -32,7 +32,7 @@ public boolean isTriggered() {

@Override
public int render(TextRenderer textRenderer, DrawContext context, int x, int y, boolean highlight) {
return HudComponent.drawHighlightedText(textRenderer, context, Text.translatable("alerts.flightassistant.firework.no_response"), x, y,
return DrawHelper.drawHighlightedText(textRenderer, context, Text.translatable("alerts.flightassistant.firework.no_response"), x, y,
FAConfig.indicator().warningColor, highlight);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import net.minecraft.text.Text;
import net.minecraft.util.Hand;
import org.jetbrains.annotations.NotNull;
import ru.octol1ttle.flightassistant.HudComponent;
import ru.octol1ttle.flightassistant.DrawHelper;
import ru.octol1ttle.flightassistant.alerts.AlertSoundData;
import ru.octol1ttle.flightassistant.alerts.BaseAlert;
import ru.octol1ttle.flightassistant.alerts.IECAMAlert;
Expand Down Expand Up @@ -44,7 +44,7 @@ public boolean isTriggered() {

@Override
public int render(TextRenderer textRenderer, DrawContext context, int x, int y, boolean highlight) {
return HudComponent.drawHighlightedText(textRenderer, context, Text.translatable("alerts.flightassistant.firework.unsafe"), x, y,
return DrawHelper.drawHighlightedText(textRenderer, context, Text.translatable("alerts.flightassistant.firework.unsafe"), x, y,
FAConfig.indicator().warningColor, highlight && data.isFlying());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text;
import org.jetbrains.annotations.NotNull;
import ru.octol1ttle.flightassistant.HudComponent;
import ru.octol1ttle.flightassistant.DrawHelper;
import ru.octol1ttle.flightassistant.alerts.AlertSoundData;
import ru.octol1ttle.flightassistant.alerts.BaseAlert;
import ru.octol1ttle.flightassistant.alerts.IECAMAlert;
Expand Down Expand Up @@ -34,7 +34,7 @@ public int render(TextRenderer textRenderer, DrawContext context, int x, int y,
? Text.translatable("alerts.flightassistant.reached_void_damage_level")
: Text.translatable("alerts.flightassistant.approaching_void_damage_level");

return HudComponent.drawHighlightedText(textRenderer, context, text, x, y,
return DrawHelper.drawHighlightedText(textRenderer, context, text, x, y,
FAConfig.indicator().warningColor, highlight);
}
}
Loading

0 comments on commit 80240d6

Please sign in to comment.