add config system and window dragging
This commit is contained in:
parent
6e584de0e6
commit
a18cb2a137
22 changed files with 354 additions and 104 deletions
|
@ -7,15 +7,13 @@ import me.kawaiizenbo.moonlight.util.ColorUtils;
|
|||
import me.kawaiizenbo.moonlight.util.MathUtils;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
public class HUDOverlay
|
||||
public class HUDOverlay
|
||||
{
|
||||
public static HUDOverlay INSTANCE = new HUDOverlay();
|
||||
private MinecraftClient mc = MinecraftClient.getInstance();
|
||||
TextRenderer textRenderer = mc.textRenderer;
|
||||
public boolean showClientTag = ((HUDModule)ModuleManager.INSTANCE.getModuleByName("HUD")).clientTag.value;
|
||||
public int hudColor = ColorUtils.rgbaToInt(
|
||||
(int)((HUDModule)ModuleManager.INSTANCE.getModuleByName("HUD")).r.value,
|
||||
|
@ -29,12 +27,12 @@ public class HUDOverlay
|
|||
if (mc.options.debugEnabled) return;
|
||||
|
||||
// draw stats
|
||||
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, Moonlight.uiColorA);
|
||||
drawContext.drawTextWithShadow(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, 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);
|
||||
|
||||
// draw coordinates
|
||||
drawContext.drawTextWithShadow(textRenderer,
|
||||
drawContext.drawTextWithShadow(mc.textRenderer,
|
||||
"X: " + ColorUtils.gray + MathUtils.round(mc.player.getX(), 1) + ColorUtils.reset +
|
||||
" 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
|
||||
|
@ -43,8 +41,8 @@ public class HUDOverlay
|
|||
// draw client tag (if enabled)
|
||||
if (showClientTag)
|
||||
{
|
||||
drawContext.drawTextWithShadow(textRenderer, Moonlight.clientTag + " " + Moonlight.versionTag,
|
||||
scaledWidth - textRenderer.getWidth(Moonlight.clientTag + " " + Moonlight.versionTag) - 2, scaledHeight - 10, 16777215);
|
||||
drawContext.drawTextWithShadow(mc.textRenderer, Moonlight.clientTag + " " + Moonlight.versionTag,
|
||||
scaledWidth - mc.textRenderer.getWidth(Moonlight.clientTag + " " + Moonlight.versionTag) - 2, scaledHeight - 10, 16777215);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,21 +1,18 @@
|
|||
package me.kawaiizenbo.moonlight.ui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
|
||||
import me.kawaiizenbo.moonlight.Moonlight;
|
||||
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 ModulesListOverlay
|
||||
{
|
||||
public static ModulesListOverlay INSTANCE = new ModulesListOverlay();
|
||||
private MinecraftClient mc = MinecraftClient.getInstance();
|
||||
TextRenderer textRenderer = mc.textRenderer;
|
||||
private ArrayList<Module_> enabledModules = ModuleManager.INSTANCE.getEnabledModules();
|
||||
|
||||
public void render(DrawContext drawContext, int scaledWidth, int scaledHeight)
|
||||
|
@ -27,10 +24,10 @@ public class ModulesListOverlay
|
|||
for (Module_ m : enabledModules)
|
||||
{
|
||||
if (!m.showInModulesList.value) continue;
|
||||
int nameWidth = textRenderer.getWidth(m.name);
|
||||
int nameWidth = mc.textRenderer.getWidth(m.name);
|
||||
drawContext.fill(scaledWidth - nameWidth - 8, yOffset, scaledWidth, yOffset+12, 0x55222222);
|
||||
drawContext.fill(scaledWidth - 2, yOffset, scaledWidth, yOffset+12, Moonlight.uiColorA);
|
||||
drawContext.drawText(textRenderer, m.name, scaledWidth - nameWidth - 4, yOffset + 2, 0xFFFFFFFF, false);
|
||||
drawContext.drawText(mc.textRenderer, m.name, scaledWidth - nameWidth - 4, yOffset + 2, 0xFFFFFFFF, false);
|
||||
yOffset += 12;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public class TextButton
|
|||
public void render(DrawContext drawContext, TextRenderer textRenderer, int mouseX, int mouseY)
|
||||
{
|
||||
width = textRenderer.getWidth(text);
|
||||
drawContext.fill(x-1, y-1, x + width + 1, y + 10, hovered(mouseX, mouseY) ? 0xFF444444 : 0xFF222222);
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,56 +5,57 @@ 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 int x, y, height, width = 96;
|
||||
int startX, startY;
|
||||
boolean dragging = false;
|
||||
public boolean collapsed = false;
|
||||
ArrayList<ModuleButton> moduleButtons;
|
||||
|
||||
public CategoryPane(Category category, int initialX, int initialY)
|
||||
public CategoryPane(Category category, int initialX, int initialY, boolean collapsed)
|
||||
{
|
||||
this.category = category;
|
||||
this.x = initialX;
|
||||
this.y = initialY;
|
||||
int buttonYOffset = y+16;
|
||||
this.collapsed = collapsed;
|
||||
moduleButtons = new ArrayList<ModuleButton>();
|
||||
for (Module_ m : ModuleManager.INSTANCE.getModulesByCategory(category))
|
||||
{
|
||||
moduleButtons.add(new ModuleButton(m, x+2, buttonYOffset));
|
||||
buttonYOffset += 12;
|
||||
moduleButtons.add(new ModuleButton(m));
|
||||
}
|
||||
if (moduleButtons.size() == 0) collapsed = true;
|
||||
height = (moduleButtons.size()*12) + 18;
|
||||
}
|
||||
|
||||
public void render(DrawContext drawContext, int mouseX, int mouseY, float delta)
|
||||
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, 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)
|
||||
{
|
||||
int buttonYOffset = y+16;
|
||||
for (ModuleButton m : moduleButtons)
|
||||
{
|
||||
m.render(drawContext, mouseX, mouseY);
|
||||
m.render(drawContext, mouseX, mouseY, x+2, buttonYOffset, textRenderer);
|
||||
buttonYOffset += 12;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hovered(int mouseX, int mouseY)
|
||||
{
|
||||
return mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height;
|
||||
return mouseX >= x+2 && mouseX <= x+(width-2) && mouseY >= y+2 && mouseY <= y+14;
|
||||
}
|
||||
|
||||
public void mouseClicked(int mouseX, int mouseY, int button)
|
||||
|
@ -63,6 +64,17 @@ public class CategoryPane
|
|||
{
|
||||
if (moduleButton.mouseClicked(mouseX, mouseY, button)) return;
|
||||
}
|
||||
if (hovered(mouseX, mouseY)) collapsed = !collapsed;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package me.kawaiizenbo.moonlight.ui.clickgui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
import me.kawaiizenbo.moonlight.Moonlight;
|
||||
import me.kawaiizenbo.moonlight.module.Category;
|
||||
import me.kawaiizenbo.moonlight.util.MathUtils;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.text.Text;
|
||||
|
@ -10,23 +13,19 @@ import net.minecraft.text.Text;
|
|||
public class ClickGUIScreen extends Screen
|
||||
{
|
||||
public static ClickGUIScreen INSTANCE = new ClickGUIScreen();
|
||||
public static ArrayList<CategoryPane> categoryPanes;
|
||||
public ArrayList<CategoryPane> categoryPanes;
|
||||
|
||||
public ClickGUIScreen()
|
||||
{
|
||||
super(Text.literal("ClickGUI"));
|
||||
int xOffset = 4;
|
||||
int yOffset = 4;
|
||||
categoryPanes = new ArrayList<CategoryPane>();
|
||||
Map<String, Object> panePos = ((Map<String, Object>)Moonlight.INSTANCE.CONFIG.config.get("panes"));
|
||||
for (Category category : Category.values())
|
||||
{
|
||||
if (xOffset > 400)
|
||||
{
|
||||
xOffset = 4;
|
||||
yOffset = 128;
|
||||
}
|
||||
categoryPanes.add(new CategoryPane(category, xOffset, yOffset));
|
||||
xOffset += 100;
|
||||
int xOffset = MathUtils.d2iSafe(((Map<String, Object>)panePos.get(category.name)).get("x"));
|
||||
int yOffset = MathUtils.d2iSafe(((Map<String, Object>)panePos.get(category.name)).get("y"));
|
||||
boolean collapsed = (boolean)((Map<String, Object>)panePos.get(category.name)).get("collapsed");
|
||||
categoryPanes.add(new CategoryPane(category, xOffset, yOffset, collapsed));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,7 +35,7 @@ public class ClickGUIScreen extends Screen
|
|||
this.renderBackground(drawContext);
|
||||
for (CategoryPane category : categoryPanes)
|
||||
{
|
||||
category.render(drawContext, mouseX, mouseY, delta);
|
||||
category.render(drawContext, mouseX, mouseY, delta, textRenderer);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,6 +48,16 @@ public class ClickGUIScreen extends Screen
|
|||
}
|
||||
return super.mouseClicked(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseReleased(double mouseX, double mouseY, int button)
|
||||
{
|
||||
for (CategoryPane category : categoryPanes)
|
||||
{
|
||||
category.mouseReleased((int) mouseX, (int) mouseY, button);
|
||||
}
|
||||
return super.mouseReleased(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldPause()
|
||||
|
|
|
@ -10,20 +10,18 @@ public class ModuleButton
|
|||
{
|
||||
public Module_ module;
|
||||
public int x, y, width, height = 0;
|
||||
private MinecraftClient mc = MinecraftClient.getInstance();
|
||||
private TextRenderer textRenderer = mc.textRenderer;
|
||||
|
||||
public ModuleButton(Module_ module, int initialX, int initialY)
|
||||
public ModuleButton(Module_ module)
|
||||
{
|
||||
this.module = module;
|
||||
this.x = initialX;
|
||||
this.y = initialY;
|
||||
this.width = 92;
|
||||
this.height = 12;
|
||||
}
|
||||
|
||||
public void render(DrawContext drawContext, int mouseX, int mouseY)
|
||||
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 ? Moonlight.uiColor : 0xFFFFFF, false);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,10 @@ public class SettingsScreen extends Screen
|
|||
private Module_ module;
|
||||
private TextButton backButton;
|
||||
|
||||
protected SettingsScreen(Module_ module)
|
||||
boolean dragging = false;
|
||||
int startX, startY, x = 4, y = 4, windowWidth = 224, windowHeight = 192;
|
||||
|
||||
public SettingsScreen(Module_ module)
|
||||
{
|
||||
super(Text.literal("Settings"));
|
||||
this.module = module;
|
||||
|
@ -23,18 +26,32 @@ public class SettingsScreen extends Screen
|
|||
public void render(DrawContext drawContext, int mouseX, int mouseY, float delta)
|
||||
{
|
||||
this.renderBackground(drawContext);
|
||||
drawContext.fill((width/2)-112, (height/2)-96, (width/2)+112, (height/2)+96, 0xFF222222);
|
||||
drawContext.drawCenteredTextWithShadow(textRenderer, module.name, width/2, (height/2)-88, 0xFFFFFF);
|
||||
drawContext.drawTextWithShadow(textRenderer, Text.literal(module.description), (width/2)-104, (height/2)-72, 0xFFFFFF);
|
||||
backButton = new TextButton(ColorUtils.underline + "< Back", (width/2)-104, (height/2)-88, 0xFFFFFF);
|
||||
|
||||
// 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 Settings: "+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);
|
||||
int yOffset = (height/2)-56;
|
||||
int yOffset = y+40;
|
||||
for (Setting setting : module.settings)
|
||||
{
|
||||
setting.render(drawContext, (width/2)-96, yOffset, mouseX, mouseY);
|
||||
setting.render(drawContext, x+16, yOffset, mouseX, mouseY, textRenderer);
|
||||
yOffset += setting.height + 1;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean barHovered(int mouseX, int mouseY)
|
||||
{
|
||||
return mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + 16;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldPause()
|
||||
|
@ -45,6 +62,12 @@ public class SettingsScreen extends Screen
|
|||
@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);
|
||||
for (Setting setting : module.settings)
|
||||
{
|
||||
|
@ -56,6 +79,7 @@ public class SettingsScreen extends Screen
|
|||
@Override
|
||||
public boolean mouseReleased(double mouseX, double mouseY, int button)
|
||||
{
|
||||
dragging = false;
|
||||
for (Setting setting : module.settings)
|
||||
{
|
||||
setting.mouseReleased(mouseX, mouseY, button);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue