now able to toggle hud modules

This commit is contained in:
kawaiizenbo 2024-09-07 21:21:22 -07:00
parent 8f6646b7e0
commit 90347f7476
5 changed files with 137 additions and 0 deletions

View file

@ -55,4 +55,8 @@ public class HUDModule
dragging = false; dragging = false;
} }
public void toggle()
{
enabled = !enabled;
}
} }

View file

@ -9,10 +9,12 @@ import net.minecraft.text.Text;
public class HUDEditorScreen extends Screen public class HUDEditorScreen extends Screen
{ {
public static HUDEditorScreen INSTANCE = new HUDEditorScreen(); public static HUDEditorScreen INSTANCE = new HUDEditorScreen();
HUDModuleList moduleList;
public HUDEditorScreen() public HUDEditorScreen()
{ {
super(Text.literal("HUD Editor")); super(Text.literal("HUD Editor"));
moduleList = new HUDModuleList(256, 2, false);
} }
@Override @Override
@ -23,6 +25,7 @@ public class HUDEditorScreen extends Screen
{ {
h.render(drawContext, mouseX, mouseY, textRenderer, true, h.enabled); h.render(drawContext, mouseX, mouseY, textRenderer, true, h.enabled);
} }
moduleList.render(drawContext, mouseX, mouseY, delta, textRenderer);
} }
@Override @Override
@ -32,6 +35,7 @@ public class HUDEditorScreen extends Screen
{ {
h.mouseClicked((int)mouseX, (int)mouseY, button); h.mouseClicked((int)mouseX, (int)mouseY, button);
} }
moduleList.mouseClicked((int)mouseX, (int)mouseY, button);
return super.mouseClicked(mouseX, mouseY, button); return super.mouseClicked(mouseX, mouseY, button);
} }
@ -42,6 +46,7 @@ public class HUDEditorScreen extends Screen
{ {
h.mouseReleased((int)mouseX, (int)mouseY, button); h.mouseReleased((int)mouseX, (int)mouseY, button);
} }
moduleList.mouseReleased((int)mouseX, (int)mouseY, button);
return super.mouseReleased(mouseX, mouseY, button); return super.mouseReleased(mouseX, mouseY, button);
} }

View file

@ -0,0 +1,49 @@
package me.kawaiizenbo.moonlight.ui.hud.editor;
import me.kawaiizenbo.moonlight.ui.hud.HUDModule;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
public class HUDModuleButton
{
public HUDModule module;
public int x, y, width, height = 0;
public HUDModuleButton(HUDModule module)
{
this.module = module;
this.width = 124;
this.height = 12;
}
public void render(DrawContext drawContext, int mouseX, int mouseY, int x, int y, TextRenderer textRenderer)
{
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 ? 0x55FFFF : 0xFFFFFF, false);
}
public boolean hovered(int mouseX, int mouseY)
{
return mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height;
}
public boolean mouseClicked(int mouseX, int mouseY, int button)
{
if (hovered(mouseX, mouseY))
{
if (button == 0)
{
module.toggle();
}
else if (button == 1)
{
// HUDModule Settings coming Soon TM
//MinecraftClient.getInstance().setScreen(new SettingsScreen(module));
}
return true;
}
return false;
}
}

View file

@ -0,0 +1,79 @@
package me.kawaiizenbo.moonlight.ui.hud.editor;
import java.util.ArrayList;
import me.kawaiizenbo.moonlight.ui.hud.HUDModule;
import me.kawaiizenbo.moonlight.ui.hud.HUDModuleManager;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.util.Identifier;
public class HUDModuleList
{
public int x, y, height, width = 128;
int startX, startY;
boolean dragging = false;
public boolean collapsed = false;
ArrayList<HUDModuleButton> buttons;
public HUDModuleList(int initialX, int initialY, boolean collapsed)
{
this.x = initialX;
this.y = initialY;
this.collapsed = collapsed;
buttons = new ArrayList<HUDModuleButton>();
for (HUDModule m : HUDModuleManager.INSTANCE.modules)
{
buttons.add(new HUDModuleButton(m));
}
if (buttons.size() == 0) collapsed = true;
height = (buttons.size()*12) + 18;
}
public void render(DrawContext drawContext, int mouseX, int mouseY, float delta, TextRenderer textRenderer)
{
if (dragging)
{
x = mouseX - startX;
y = mouseY - startY;
}
drawContext.fill(x, y, x+width, collapsed ? y+16 : y+height, 0xFF55FFFF);
drawContext.fill(x+2, y+2, x+(width-2), y+14, hovered(mouseX, mouseY) ? 0xFF333333 : 0xFF222222);
drawContext.drawGuiTexture(Identifier.of("moonlight", "hud"), x+2, y+2, 12, 12);
drawContext.drawText(textRenderer, "HUD Modules", x+16, y+4, 0xFFFFFFFF, false);
if (!collapsed)
{
int buttonYOffset = y+16;
for (HUDModuleButton m : buttons)
{
m.render(drawContext, mouseX, mouseY, x+2, buttonYOffset, textRenderer);
buttonYOffset += 12;
}
}
}
public boolean hovered(int mouseX, int mouseY)
{
return mouseX >= x+2 && mouseX <= x+(width-2) && mouseY >= y+2 && mouseY <= y+14;
}
public void mouseClicked(int mouseX, int mouseY, int button)
{
for (HUDModuleButton moduleButton : buttons)
{
if (moduleButton.mouseClicked(mouseX, mouseY, button)) return;
}
if (hovered(mouseX, mouseY) && button == 1) collapsed = !collapsed;
else if (hovered(mouseX, mouseY) && button == 0)
{
startX = (int)mouseX-x;
startY = (int)mouseY-y;
dragging = true;
}
}
public void mouseReleased(int mouseX, int mouseY, int button)
{
dragging = false;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 354 B