clickgui, make hud toggleable

This commit is contained in:
kawaiizenbo 2022-12-07 17:47:00 -07:00
parent 05ff377b5c
commit 411790540a
8 changed files with 173 additions and 19 deletions

View file

@ -5,11 +5,11 @@ import net.minecraft.text.Text;
public class AltManagerScreen extends Screen
{
public static AltManagerScreen INSTANCE = new AltManagerScreen();
public static AltManagerScreen INSTANCE = new AltManagerScreen(null);
protected AltManagerScreen(Text title)
protected AltManagerScreen()
{
super(title);
super(Text.literal("Alt Manager"));
}
}

View file

@ -1,14 +1,65 @@
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.gui.screen.Screen;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
public class ClickGUIScreen extends Screen
public class ClickGUIScreen extends Screen
{
public static ClickGUIScreen INSTANCE = new ClickGUIScreen(null);
protected ClickGUIScreen(Text title)
{
super(title);
}
public static ClickGUIScreen INSTANCE = new ClickGUIScreen();
public static ArrayList<ModuleButton> moduleButtons;
public ClickGUIScreen()
{
super(Text.literal("ClickGUI"));
moduleButtons = new ArrayList<>();
int yOffset;
for (Category category : Category.values())
{
yOffset = 25;
for (Module_ module : ModuleManager.INSTANCE.getModulesByCategory(category))
{
moduleButtons.add(new ModuleButton(module, 9+(module.category.ordinal()*65), yOffset));
yOffset += 10;
}
}
}
@Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta)
{
this.renderBackground(matrices);
int categoryLabelXOffset = 10;
for (Category category : Category.values())
{
textRenderer.draw(matrices, category.name, categoryLabelXOffset, 10, 0xFFFFFF);
categoryLabelXOffset += 65;
}
for (ModuleButton moduleButton : moduleButtons)
{
moduleButton.render(matrices, mouseX, mouseY);
}
}
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button)
{
for (ModuleButton modButton : moduleButtons)
{
modButton.mouseClicked((int) mouseX, (int) mouseY, button);
}
return super.mouseClicked(mouseX, mouseY, button);
}
@Override
public boolean shouldPause()
{
return false;
}
}

View file

@ -0,0 +1,43 @@
package me.kawaiizenbo.moonlight.ui.clickgui;
import me.kawaiizenbo.moonlight.module.Module_;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.util.math.MatrixStack;
public class ModuleButton
{
public Module_ module;
public int x, y, width, height = 0;
private MinecraftClient mc = MinecraftClient.getInstance();
public ModuleButton(Module_ module, int x, int y)
{
this.module = module;
this.x = x;
this.y = y;
this.width = 60;
this.height = 10;
}
public void render(MatrixStack matrices, int mouseX, int mouseY)
{
TextRenderer textRenderer = mc.textRenderer;
DrawableHelper.fill(matrices, x, y, x + width, y + height, hovered(mouseX, mouseY) ? 0xFF333333 : 0xFF222222);
textRenderer.draw(matrices, module.name, x+1, y+1, module.enabled ? 0x55FFFF : 0xFFFFFF);
}
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)
{
if (hovered(mouseX, mouseY))
{
module.toggle();
}
}
}