new clickgui, still need to add dragging

This commit is contained in:
kawaiizenbo 2023-06-28 22:21:04 -07:00
parent b58eedfb9c
commit 6e584de0e6
17 changed files with 129 additions and 46 deletions

View file

@ -13,6 +13,8 @@ public class Moonlight implements ModInitializer
public static final Logger LOGGER = LoggerFactory.getLogger("Moonlight"); public static final Logger LOGGER = LoggerFactory.getLogger("Moonlight");
public static final String clientTag = ColorUtils.aqua + "Moonlight Meadows"; public static final String clientTag = ColorUtils.aqua + "Moonlight Meadows";
public static final String versionTag = ColorUtils.magenta + "v0.dev"; public static final String versionTag = ColorUtils.magenta + "v0.dev";
public static int uiColorA = 0xFF55FFFF;
public static int uiColor = 0x55FFFF;
@Override @Override
public void onInitialize() public void onInitialize()

View file

@ -2,17 +2,19 @@ package me.kawaiizenbo.moonlight.module;
public enum Category public enum Category
{ {
COMBAT("Combat"), COMBAT("Combat", 0xFFFF5555),
MOVEMENT("Movement"), MOVEMENT("Movement", 0xFFFF55FF),
RENDER("Render"), RENDER("Render", 0xFF5555FF),
WORLD("World"), WORLD("World", 0xFF55FF55),
PLAYER("Player"), PLAYER("Player", 0xFFFFFFFF),
CHAT("Chat"); CHAT("Chat", 0xFFFFFF55);
public String name; public String name;
public int color;
Category(String name) Category(String name, int color)
{ {
this.name = name; this.name = name;
this.color = color;
} }
} }

View file

@ -27,6 +27,7 @@ public abstract class Module_
this.description = description; this.description = description;
this.category = category; this.category = category;
settings = new ArrayList<>(); settings = new ArrayList<>();
settings.add(showInModulesList);
} }
public void onEnable() { ModulesListOverlay.INSTANCE.update(); } public void onEnable() { ModulesListOverlay.INSTANCE.update(); }

View file

@ -1,5 +1,6 @@
package me.kawaiizenbo.moonlight.module.modules; package me.kawaiizenbo.moonlight.module.modules;
import me.kawaiizenbo.moonlight.Moonlight;
import me.kawaiizenbo.moonlight.module.Category; import me.kawaiizenbo.moonlight.module.Category;
import me.kawaiizenbo.moonlight.module.Module_; import me.kawaiizenbo.moonlight.module.Module_;
import me.kawaiizenbo.moonlight.module.settings.BooleanSetting; import me.kawaiizenbo.moonlight.module.settings.BooleanSetting;
@ -33,12 +34,18 @@ public class HUDModule extends Module_
{ {
super.onEnable(); super.onEnable();
HUDOverlay.INSTANCE.showClientTag = clientTag.value; HUDOverlay.INSTANCE.showClientTag = clientTag.value;
HUDOverlay.INSTANCE.hudColor = Moonlight.uiColorA =
ColorUtils.rgbaToInt( ColorUtils.rgbaToInt(
(int)r.value, (int)r.value,
(int)g.value, (int)g.value,
(int)b.value, (int)b.value,
255 255
); );
Moonlight.uiColor =
ColorUtils.rgbToInt(
(int)r.value,
(int)g.value,
(int)b.value
);
} }
} }

View file

@ -29,14 +29,16 @@ public class HUDOverlay
if (mc.options.debugEnabled) return; if (mc.options.debugEnabled) return;
// draw stats // draw stats
drawContext.drawTextWithShadow(textRenderer, "FPS: " + ColorUtils.gray + mc.fpsDebugString.split(" ")[0], 2, 2, hudColor); drawContext.drawTextWithShadow(textRenderer, "FPS: " + ColorUtils.gray + mc.fpsDebugString.split(" ")[0], 2, 2, Moonlight.uiColorA);
drawContext.drawTextWithShadow(textRenderer, "Ping: " + ColorUtils.gray + (mc.getNetworkHandler().getPlayerListEntry(mc.player.getUuid()) == null ? 0 : mc.getNetworkHandler().getPlayerListEntry(mc.player.getUuid()).getLatency()), 2, 12, hudColor); drawContext.drawTextWithShadow(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(textRenderer, "Meters/s: " + ColorUtils.gray + MathUtils.round(moveSpeed(), 2), 2, scaledHeight - 20, hudColor); drawContext.drawTextWithShadow(textRenderer, "Meters/s: " + ColorUtils.gray + MathUtils.round(moveSpeed(), 2), 2, scaledHeight - 20, Moonlight.uiColorA);
// draw coordinates // draw coordinates
drawContext.drawTextWithShadow(textRenderer, "X: " + ColorUtils.gray + MathUtils.round(mc.player.getX(), 1) + drawContext.drawTextWithShadow(textRenderer,
ColorUtils.reset + " Y: " + ColorUtils.gray + MathUtils.round(mc.player.getY(), 1) + "X: " + ColorUtils.gray + MathUtils.round(mc.player.getX(), 1) + ColorUtils.reset +
ColorUtils.reset + " Z: " + ColorUtils.gray + MathUtils.round(mc.player.getZ(), 1), 2, scaledHeight - 10, hudColor); " Y: " + ColorUtils.gray + MathUtils.round(mc.player.getY(), 1) + ColorUtils.reset +
" Z: " + ColorUtils.gray + MathUtils.round(mc.player.getZ(), 1), 2, scaledHeight - 10, Moonlight.uiColorA
);
// draw client tag (if enabled) // draw client tag (if enabled)
if (showClientTag) if (showClientTag)

View file

@ -3,6 +3,7 @@ package me.kawaiizenbo.moonlight.ui;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import me.kawaiizenbo.moonlight.Moonlight;
import me.kawaiizenbo.moonlight.module.ModuleManager; import me.kawaiizenbo.moonlight.module.ModuleManager;
import me.kawaiizenbo.moonlight.module.Module_; import me.kawaiizenbo.moonlight.module.Module_;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
@ -28,7 +29,7 @@ public class ModulesListOverlay
if (!m.showInModulesList.value) continue; if (!m.showInModulesList.value) continue;
int nameWidth = textRenderer.getWidth(m.name); int nameWidth = textRenderer.getWidth(m.name);
drawContext.fill(scaledWidth - nameWidth - 8, yOffset, scaledWidth, yOffset+12, 0x55222222); drawContext.fill(scaledWidth - nameWidth - 8, yOffset, scaledWidth, yOffset+12, 0x55222222);
drawContext.fill(scaledWidth - 2, yOffset, scaledWidth, yOffset+12, HUDOverlay.INSTANCE.hudColor); drawContext.fill(scaledWidth - 2, yOffset, scaledWidth, yOffset+12, Moonlight.uiColorA);
drawContext.drawText(textRenderer, m.name, scaledWidth - nameWidth - 4, yOffset + 2, 0xFFFFFFFF, false); drawContext.drawText(textRenderer, m.name, scaledWidth - nameWidth - 4, yOffset + 2, 0xFFFFFFFF, false);
yOffset += 12; yOffset += 12;
} }

View file

@ -0,0 +1,68 @@
package me.kawaiizenbo.moonlight.ui.clickgui;
import java.util.ArrayList;
import me.kawaiizenbo.moonlight.module.Category;
import me.kawaiizenbo.moonlight.module.ModuleManager;
import me.kawaiizenbo.moonlight.module.Module_;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
public class CategoryPane
{
private MinecraftClient mc = MinecraftClient.getInstance();
private TextRenderer textRenderer = mc.textRenderer;
public Category category;
public int x;
public int y;
private int height;
private int width = 96;
private boolean collapsed = false;
private ArrayList<ModuleButton> moduleButtons;
public CategoryPane(Category category, int initialX, int initialY)
{
this.category = category;
this.x = initialX;
this.y = initialY;
int buttonYOffset = y+16;
moduleButtons = new ArrayList<ModuleButton>();
for (Module_ m : ModuleManager.INSTANCE.getModulesByCategory(category))
{
moduleButtons.add(new ModuleButton(m, x+2, buttonYOffset));
buttonYOffset += 12;
}
if (moduleButtons.size() == 0) collapsed = true;
height = (moduleButtons.size()*12) + 18;
}
public void render(DrawContext drawContext, int mouseX, int mouseY, float delta)
{
drawContext.fill(x, y, x+width, collapsed ? y+16 : y+height, category.color);
drawContext.fill(x+2, y+2, x+(width-2), y+14, hovered(mouseX, mouseY) ? 0xFF333333 : 0xFF222222);
drawContext.drawText(textRenderer, category.name, x+4, y+4, 0xFFFFFFFF, false);
if (!collapsed)
{
for (ModuleButton m : moduleButtons)
{
m.render(drawContext, mouseX, mouseY);
}
}
}
public boolean hovered(int mouseX, int mouseY)
{
return mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height;
}
public void mouseClicked(int mouseX, int mouseY, int button)
{
for (ModuleButton moduleButton : moduleButtons)
{
if (moduleButton.mouseClicked(mouseX, mouseY, button)) return;
}
if (hovered(mouseX, mouseY)) collapsed = !collapsed;
}
}

View file

@ -3,56 +3,49 @@ package me.kawaiizenbo.moonlight.ui.clickgui;
import java.util.ArrayList; import java.util.ArrayList;
import me.kawaiizenbo.moonlight.module.Category; import me.kawaiizenbo.moonlight.module.Category;
import me.kawaiizenbo.moonlight.module.ModuleManager;
import me.kawaiizenbo.moonlight.module.Module_;
import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text; import net.minecraft.text.Text;
public class ClickGUIScreen extends Screen public class ClickGUIScreen extends Screen
{ {
public static ClickGUIScreen INSTANCE = new ClickGUIScreen(); public static ClickGUIScreen INSTANCE = new ClickGUIScreen();
public static ArrayList<ModuleButton> moduleButtons; public static ArrayList<CategoryPane> categoryPanes;
public ClickGUIScreen() public ClickGUIScreen()
{ {
super(Text.literal("ClickGUI")); super(Text.literal("ClickGUI"));
moduleButtons = new ArrayList<>(); int xOffset = 4;
int yOffset; int yOffset = 4;
categoryPanes = new ArrayList<CategoryPane>();
for (Category category : Category.values()) for (Category category : Category.values())
{ {
yOffset = 25; if (xOffset > 400)
for (Module_ module : ModuleManager.INSTANCE.getModulesByCategory(category))
{ {
moduleButtons.add(new ModuleButton(module, 9+(module.category.ordinal()*70), yOffset)); xOffset = 4;
yOffset += 14; yOffset = 128;
} }
categoryPanes.add(new CategoryPane(category, xOffset, yOffset));
xOffset += 100;
} }
} }
@Override @Override
public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) public void render(DrawContext drawContext, int mouseX, int mouseY, float delta)
{ {
this.renderBackground(drawContext); this.renderBackground(drawContext);
int categoryLabelXOffset = 10; for (CategoryPane category : categoryPanes)
for (Category category : Category.values())
{ {
drawContext.drawText(textRenderer, category.name, categoryLabelXOffset, 10, 0xFFFFFF, false); category.render(drawContext, mouseX, mouseY, delta);
categoryLabelXOffset += 70;
}
for (ModuleButton moduleButton : moduleButtons)
{
moduleButton.render(drawContext, mouseX, mouseY);
} }
} }
@Override @Override
public boolean mouseClicked(double mouseX, double mouseY, int button) public boolean mouseClicked(double mouseX, double mouseY, int button)
{ {
for (ModuleButton modButton : moduleButtons) for (CategoryPane category : categoryPanes)
{ {
modButton.mouseClicked((int) mouseX, (int) mouseY, button); category.mouseClicked((int) mouseX, (int) mouseY, button);
} }
return super.mouseClicked(mouseX, mouseY, button); return super.mouseClicked(mouseX, mouseY, button);
} }

View file

@ -1,5 +1,6 @@
package me.kawaiizenbo.moonlight.ui.clickgui; package me.kawaiizenbo.moonlight.ui.clickgui;
import me.kawaiizenbo.moonlight.Moonlight;
import me.kawaiizenbo.moonlight.module.Module_; import me.kawaiizenbo.moonlight.module.Module_;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer; import net.minecraft.client.font.TextRenderer;
@ -10,21 +11,21 @@ public class ModuleButton
public Module_ module; public Module_ module;
public int x, y, width, height = 0; public int x, y, width, height = 0;
private MinecraftClient mc = MinecraftClient.getInstance(); private MinecraftClient mc = MinecraftClient.getInstance();
private TextRenderer textRenderer = mc.textRenderer;
public ModuleButton(Module_ module, int x, int y) public ModuleButton(Module_ module, int initialX, int initialY)
{ {
this.module = module; this.module = module;
this.x = x; this.x = initialX;
this.y = y; this.y = initialY;
this.width = 70; this.width = 92;
this.height = 14; this.height = 12;
} }
public void render(DrawContext drawContext, int mouseX, int mouseY) public void render(DrawContext drawContext, int mouseX, int mouseY)
{ {
TextRenderer textRenderer = mc.textRenderer;
drawContext.fill(x, y, x + width, y + height, hovered(mouseX, mouseY) ? 0xFF333333 : 0xFF222222); drawContext.fill(x, y, x + width, y + height, hovered(mouseX, mouseY) ? 0xFF333333 : 0xFF222222);
drawContext.drawText(textRenderer, module.name, x+3, y+3, module.enabled ? 0x55FFFF : 0xFFFFFF, false); drawContext.drawText(textRenderer, module.name, x+2, y+2, module.enabled ? Moonlight.uiColor : 0xFFFFFF, false);
} }
public boolean hovered(int mouseX, int mouseY) public boolean hovered(int mouseX, int mouseY)
@ -32,7 +33,7 @@ public class ModuleButton
return mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height; return mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height;
} }
public void mouseClicked(int mouseX, int mouseY, int button) public boolean mouseClicked(int mouseX, int mouseY, int button)
{ {
if (hovered(mouseX, mouseY)) if (hovered(mouseX, mouseY))
{ {
@ -44,6 +45,8 @@ public class ModuleButton
{ {
MinecraftClient.getInstance().setScreen(new SettingsScreen(module)); MinecraftClient.getInstance().setScreen(new SettingsScreen(module));
} }
return true;
} }
return false;
} }
} }

View file

@ -34,7 +34,6 @@ public class SettingsScreen extends Screen
setting.render(drawContext, (width/2)-96, yOffset, mouseX, mouseY); setting.render(drawContext, (width/2)-96, yOffset, mouseX, mouseY);
yOffset += setting.height + 1; yOffset += setting.height + 1;
} }
// add keybind setting here eventually
} }
@Override @Override

View file

@ -32,4 +32,9 @@ public class ColorUtils
{ {
return ((a&0x0ff)<<24)|((r&0x0ff)<<16)|((g&0x0ff)<<8)|(b&0x0ff); return ((a&0x0ff)<<24)|((r&0x0ff)<<16)|((g&0x0ff)<<8)|(b&0x0ff);
} }
public static int rgbToInt(int r, int g, int b)
{
return ((r&0x0ff)<<16)|((g&0x0ff)<<8)|(b&0x0ff);
}
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 181 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 181 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 B