MoonlightMeadows/src/main/java/me/kawaiizenbo/moonlight/ui/clickgui/SettingsScreen.java
2024-09-07 19:24:06 -07:00

104 lines
3.6 KiB
Java

package me.kawaiizenbo.moonlight.ui.clickgui;
import me.kawaiizenbo.moonlight.module.Module;
import me.kawaiizenbo.moonlight.module.settings.Setting;
import me.kawaiizenbo.moonlight.ui.SetScreenButton;
import me.kawaiizenbo.moonlight.ui.hud.editor.HUDEditorScreen;
import me.kawaiizenbo.moonlight.util.ColorUtils;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;
public class SettingsScreen extends Screen
{
private Module module;
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;
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;
}
@Override
public void render(DrawContext drawContext, int mouseX, int mouseY, float delta)
{
this.renderBackground(drawContext, mouseX, mouseY, delta);
// move window if dragging
if (dragging)
{
x = mouseX - startX;
y = mouseY - startY;
}
drawContext.fill(x, y, x+windowWidth, y+windowHeight, 0xFF222222);
drawContext.fill(x, y, x+windowWidth, y+16, module.category.color);
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.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)
{
setting.render(drawContext, x+16, yOffset, mouseX, mouseY, textRenderer);
yOffset += 25;
}
}
public boolean barHovered(int mouseX, int mouseY)
{
return mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + 16;
}
@Override
public boolean shouldPause()
{
return false;
}
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button)
{
if (barHovered((int)mouseX, (int)mouseY))
{
startX = (int)mouseX-x;
startY = (int)mouseY-y;
dragging = true;
}
backButton.mouseClicked((int)mouseX, (int)mouseY);
editButton.mouseClicked((int)mouseX, (int)mouseY);
for (Setting setting : module.settings)
{
setting.mouseClicked(mouseX, mouseY, button);
}
return super.mouseClicked(mouseX, mouseY, button);
}
@Override
public boolean mouseReleased(double mouseX, double mouseY, int button)
{
dragging = false;
for (Setting setting : module.settings)
{
setting.mouseReleased(mouseX, mouseY, button);
}
return super.mouseReleased(mouseX, mouseY, button);
}
@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers)
{
for (Setting setting : module.settings)
{
setting.keyPressed(keyCode, scanCode, modifiers);
}
return super.keyPressed(keyCode, scanCode, modifiers);
}
}