start of hud rework

This commit is contained in:
kawaiizenbo 2024-09-07 16:14:08 -07:00
parent a3e7e885ac
commit 9ab102a648
12 changed files with 98 additions and 91 deletions

View file

@ -1,8 +1,6 @@
package me.kawaiizenbo.moonlight.ui;
import me.kawaiizenbo.moonlight.Moonlight;
import me.kawaiizenbo.moonlight.module.ModuleManager;
import me.kawaiizenbo.moonlight.module.modules.HUDModule;
import me.kawaiizenbo.moonlight.util.ColorUtils;
import me.kawaiizenbo.moonlight.util.MathUtils;
@ -10,40 +8,32 @@ import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.util.math.Vec3d;
public class HUDOverlay
public class LegacyHUD
{
public static HUDOverlay INSTANCE = new HUDOverlay();
// This is deprecated and will be removed in a later version
public static LegacyHUD INSTANCE = new LegacyHUD();
private MinecraftClient mc = MinecraftClient.getInstance();
public boolean showClientTag = ((HUDModule)ModuleManager.INSTANCE.getModuleByName("HUD")).clientTag.value;
public int hudColor = ColorUtils.rgbaToInt(
(int)((HUDModule)ModuleManager.INSTANCE.getModuleByName("HUD")).r.value,
(int)((HUDModule)ModuleManager.INSTANCE.getModuleByName("HUD")).g.value,
(int)((HUDModule)ModuleManager.INSTANCE.getModuleByName("HUD")).b.value,
255 );
public void render(DrawContext drawContext, int scaledWidth, int scaledHeight)
{
// do not draw if F3 enabled
if (mc.getDebugHud().shouldShowDebugHud()) return;
if (mc.getDebugHud().shouldShowDebugHud()) return;
// draw stats
drawContext.drawTextWithShadow(mc.textRenderer, "FPS: " + ColorUtils.gray + mc.fpsDebugString.split(" ")[0], 2, 2, Moonlight.uiColorA);
drawContext.drawTextWithShadow(mc.textRenderer, "Ping: " + ColorUtils.gray + (mc.getNetworkHandler().getPlayerListEntry(mc.player.getUuid()) == null ? 0 : mc.getNetworkHandler().getPlayerListEntry(mc.player.getUuid()).getLatency()), 2, 12, Moonlight.uiColorA);
drawContext.drawTextWithShadow(mc.textRenderer, "Meters/s: " + ColorUtils.gray + MathUtils.round(moveSpeed(), 2), 2, scaledHeight - 20, Moonlight.uiColorA);
drawContext.drawTextWithShadow(mc.textRenderer, "FPS: " + ColorUtils.gray + mc.fpsDebugString.split(" ")[0], 2, 2, 0xFF55FFFF);
drawContext.drawTextWithShadow(mc.textRenderer, "Ping: " + ColorUtils.gray + (mc.getNetworkHandler().getPlayerListEntry(mc.player.getUuid()) == null ? 0 : mc.getNetworkHandler().getPlayerListEntry(mc.player.getUuid()).getLatency()), 2, 12, 0xFF55FFFF);
drawContext.drawTextWithShadow(mc.textRenderer, "Meters/s: " + ColorUtils.gray + MathUtils.round(moveSpeed(), 2), 2, scaledHeight - 20, 0xFF55FFFF);
// draw coordinates
drawContext.drawTextWithShadow(mc.textRenderer,
"X: " + ColorUtils.gray + String.format("%.1f", mc.player.getX()) + ColorUtils.reset +
" Y: " + ColorUtils.gray + String.format("%.1f", mc.player.getY()) + ColorUtils.reset +
" Z: " + ColorUtils.gray + String.format("%.1f", mc.player.getZ()), 2, scaledHeight - 10, Moonlight.uiColorA
" Z: " + ColorUtils.gray + String.format("%.1f", mc.player.getZ()), 2, scaledHeight - 10, 0xFF55FFFF
);
// draw client tag (if enabled)
if (showClientTag)
{
drawContext.drawTextWithShadow(mc.textRenderer, Moonlight.clientTag + " " + Moonlight.versionTag,
scaledWidth - mc.textRenderer.getWidth(Moonlight.clientTag + " " + Moonlight.versionTag) - 2, scaledHeight - 10, 16777215);
}
// draw client tag
drawContext.drawTextWithShadow(mc.textRenderer, Moonlight.clientTag + " " + Moonlight.versionTag,
scaledWidth - mc.textRenderer.getWidth(Moonlight.clientTag + " " + Moonlight.versionTag) - 2, scaledHeight - 10, 16777215);
}
private double moveSpeed()

View file

@ -2,7 +2,6 @@ package me.kawaiizenbo.moonlight.ui;
import java.util.ArrayList;
import me.kawaiizenbo.moonlight.Moonlight;
import me.kawaiizenbo.moonlight.module.ModuleManager;
import me.kawaiizenbo.moonlight.module.Module;
import net.minecraft.client.MinecraftClient;
@ -26,7 +25,7 @@ public class ModulesListOverlay
if (!m.showInModulesList.value) continue;
int nameWidth = mc.textRenderer.getWidth(m.name);
drawContext.fill(scaledWidth - nameWidth - 8, yOffset, scaledWidth, yOffset+12, 0x77222222);
drawContext.fill(scaledWidth - 2, yOffset, scaledWidth, yOffset+12, Moonlight.uiColorA);
drawContext.fill(scaledWidth - 2, yOffset, scaledWidth, yOffset+12, 0xFF55FFFF);
drawContext.drawText(mc.textRenderer, m.name, scaledWidth - nameWidth - 4, yOffset + 2, 0xFFFFFFFF, false);
yOffset += 12;
}

View file

@ -1,26 +1,30 @@
package me.kawaiizenbo.moonlight.ui;
import me.kawaiizenbo.moonlight.ui.clickgui.ClickGUIScreen;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;
public class TextButton
public class SetScreenButton
{
String text;
Screen screen;
int x, y, color, width;
public TextButton(String text, int x, int y, int color)
public SetScreenButton(String text, int x, int y, int color, Screen screen)
{
this.text = text;
this.x = x;
this.y = y;
this.color = color;
this.screen = screen;
}
public void render(DrawContext drawContext, TextRenderer textRenderer, int mouseX, int mouseY)
public void render(DrawContext drawContext, TextRenderer textRenderer, int mouseX, int mouseY, int x, int y)
{
this.x = x;
this.y = y;
width = textRenderer.getWidth(text);
drawContext.fill(x-1, y-1, x + width + 1, y + 10, hovered(mouseX, mouseY) ? 0x55FFFFFF : 0);
drawContext.drawText(textRenderer, Text.literal(text), x, y, color, true);
@ -35,8 +39,7 @@ public class TextButton
{
if (hovered(mouseX, mouseY))
{
// i have no clue how to pass a method so this is kind of stupid
MinecraftClient.getInstance().setScreen(ClickGUIScreen.INSTANCE);
MinecraftClient.getInstance().setScreen(screen);
}
}
}

View file

@ -1,6 +1,5 @@
package me.kawaiizenbo.moonlight.ui.clickgui;
import me.kawaiizenbo.moonlight.Moonlight;
import me.kawaiizenbo.moonlight.module.Module;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
@ -23,7 +22,7 @@ public class ModuleButton
this.x = x;
this.y = y;
drawContext.fill(x, y, x + width, y + height, hovered(mouseX, mouseY) ? 0xFF333333 : 0xFF222222);
drawContext.drawText(textRenderer, module.name, x+2, y+2, module.enabled ? Moonlight.uiColor : 0xFFFFFF, false);
drawContext.drawText(textRenderer, module.name, x+2, y+2, module.enabled ? 0x55FFFF : 0xFFFFFF, false);
}
public boolean hovered(int mouseX, int mouseY)

View file

@ -2,7 +2,8 @@ package me.kawaiizenbo.moonlight.ui.clickgui;
import me.kawaiizenbo.moonlight.module.Module;
import me.kawaiizenbo.moonlight.module.settings.Setting;
import me.kawaiizenbo.moonlight.ui.TextButton;
import me.kawaiizenbo.moonlight.ui.SetScreenButton;
import me.kawaiizenbo.moonlight.ui.hud.HUDEditorScreen;
import me.kawaiizenbo.moonlight.util.ColorUtils;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
@ -11,7 +12,8 @@ import net.minecraft.text.Text;
public class SettingsScreen extends Screen
{
private Module module;
private TextButton backButton;
private SetScreenButton backButton;
private SetScreenButton editButton;
boolean dragging = false;
int startX, startY, x = (ClickGUIScreen.INSTANCE.width/2)-112, y = (ClickGUIScreen.INSTANCE.height/2)-96, windowWidth = 224, windowHeight = 192;
@ -19,6 +21,8 @@ public class SettingsScreen extends Screen
public SettingsScreen(Module module)
{
super(Text.literal("Settings"));
backButton = new SetScreenButton(ColorUtils.underline + "< Back", x+4, y+4, 0xFFFFFF, ClickGUIScreen.INSTANCE);
editButton = new SetScreenButton(ColorUtils.underline + "Edit", x+windowWidth-22, y+4, 0xFFFFFF, HUDEditorScreen.INSTANCE);
this.module = module;
}
@ -38,8 +42,8 @@ public class SettingsScreen extends Screen
drawContext.fill(x+2, y+2, x+(windowWidth-2), y+14, 0xFF222222);
drawContext.drawCenteredTextWithShadow(textRenderer, module.name, x+(windowWidth/2), y+4, 0xFFFFFF);
drawContext.drawText(textRenderer, module.description, x+8, y+24, 0xFFFFFF, true);
backButton = new TextButton(ColorUtils.underline + "< Back", x+4, y+4, 0xFFFFFF);
backButton.render(drawContext, textRenderer, mouseX, mouseY);
backButton.render(drawContext, textRenderer, mouseX, mouseY, x+4, y+4);
if (module.showEditButton) editButton.render(drawContext, textRenderer, mouseX, mouseY, x+windowWidth-22, y+4);
int yOffset = y+40;
for (Setting setting : module.settings)
{

View file

@ -0,0 +1,39 @@
package me.kawaiizenbo.moonlight.ui.hud;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;
public class HUDEditorScreen extends Screen
{
public static HUDEditorScreen INSTANCE = new HUDEditorScreen();
public HUDEditorScreen()
{
super(Text.literal("HUD Editor"));
}
@Override
public void render(DrawContext drawContext, int mouseX, int mouseY, float delta)
{
this.renderBackground(drawContext, mouseX, mouseY, delta);
}
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button)
{
return super.mouseClicked(mouseX, mouseY, button);
}
@Override
public boolean mouseReleased(double mouseX, double mouseY, int button)
{
return super.mouseReleased(mouseX, mouseY, button);
}
@Override
public boolean shouldPause()
{
return false;
}
}