new clickgui, still need to add dragging
This commit is contained in:
		
							parent
							
								
									b58eedfb9c
								
							
						
					
					
						commit
						6e584de0e6
					
				
					 17 changed files with 129 additions and 46 deletions
				
			
		|  | @ -13,6 +13,8 @@ public class Moonlight implements ModInitializer | |||
| 	public static final Logger LOGGER = LoggerFactory.getLogger("Moonlight"); | ||||
| 	public static final String clientTag = ColorUtils.aqua + "Moonlight Meadows"; | ||||
| 	public static final String versionTag = ColorUtils.magenta + "v0.dev"; | ||||
| 	public static int uiColorA = 0xFF55FFFF; | ||||
| 	public static int uiColor = 0x55FFFF; | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void onInitialize()  | ||||
|  |  | |||
|  | @ -2,17 +2,19 @@ package me.kawaiizenbo.moonlight.module; | |||
| 
 | ||||
| public enum Category  | ||||
| { | ||||
| 	COMBAT("Combat"), | ||||
| 	MOVEMENT("Movement"), | ||||
| 	RENDER("Render"), | ||||
| 	WORLD("World"),  | ||||
| 	PLAYER("Player"), | ||||
| 	CHAT("Chat"); | ||||
| 	COMBAT("Combat", 0xFFFF5555), | ||||
| 	MOVEMENT("Movement", 0xFFFF55FF), | ||||
| 	RENDER("Render", 0xFF5555FF), | ||||
| 	WORLD("World", 0xFF55FF55),  | ||||
| 	PLAYER("Player", 0xFFFFFFFF), | ||||
| 	CHAT("Chat", 0xFFFFFF55); | ||||
| 	 | ||||
| 	public String name; | ||||
| 	public int color; | ||||
| 	 | ||||
| 	Category(String name)  | ||||
| 	Category(String name, int color)  | ||||
|     { | ||||
| 		this.name = name; | ||||
| 		this.color = color; | ||||
| 	} | ||||
| } | ||||
|  |  | |||
|  | @ -27,6 +27,7 @@ public abstract class Module_ | |||
|         this.description = description; | ||||
|         this.category = category; | ||||
|         settings = new ArrayList<>(); | ||||
|         settings.add(showInModulesList); | ||||
|     } | ||||
| 
 | ||||
|     public void onEnable() { ModulesListOverlay.INSTANCE.update(); } | ||||
|  |  | |||
|  | @ -1,5 +1,6 @@ | |||
| package me.kawaiizenbo.moonlight.module.modules; | ||||
| 
 | ||||
| import me.kawaiizenbo.moonlight.Moonlight; | ||||
| import me.kawaiizenbo.moonlight.module.Category; | ||||
| import me.kawaiizenbo.moonlight.module.Module_; | ||||
| import me.kawaiizenbo.moonlight.module.settings.BooleanSetting; | ||||
|  | @ -33,12 +34,18 @@ public class HUDModule extends Module_ | |||
|     { | ||||
|         super.onEnable(); | ||||
|         HUDOverlay.INSTANCE.showClientTag = clientTag.value; | ||||
|         HUDOverlay.INSTANCE.hudColor =  | ||||
|         Moonlight.uiColorA =  | ||||
|         ColorUtils.rgbaToInt( | ||||
|             (int)r.value, | ||||
|             (int)g.value, | ||||
|             (int)b.value, | ||||
|             255  | ||||
|         ); | ||||
|         Moonlight.uiColor =  | ||||
|         ColorUtils.rgbToInt( | ||||
|             (int)r.value, | ||||
|             (int)g.value, | ||||
|             (int)b.value | ||||
|         ); | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -29,14 +29,16 @@ public class HUDOverlay | |||
|         if (mc.options.debugEnabled) return; | ||||
| 
 | ||||
|         // draw stats | ||||
| 		drawContext.drawTextWithShadow(textRenderer, "FPS: " + ColorUtils.gray + mc.fpsDebugString.split(" ")[0], 2, 2, hudColor); | ||||
| 		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, "Meters/s: " + ColorUtils.gray + MathUtils.round(moveSpeed(), 2), 2, scaledHeight - 20, 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, Moonlight.uiColorA); | ||||
| 		drawContext.drawTextWithShadow(textRenderer, "Meters/s: " + ColorUtils.gray + MathUtils.round(moveSpeed(), 2), 2, scaledHeight - 20, Moonlight.uiColorA); | ||||
| 
 | ||||
|         // draw coordinates | ||||
|         drawContext.drawTextWithShadow(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, hudColor); | ||||
|         drawContext.drawTextWithShadow(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 | ||||
|         ); | ||||
| 
 | ||||
|         // draw client tag (if enabled) | ||||
|         if (showClientTag) | ||||
|  |  | |||
|  | @ -3,6 +3,7 @@ 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; | ||||
|  | @ -28,7 +29,7 @@ public class ModulesListOverlay | |||
|             if (!m.showInModulesList.value) continue; | ||||
|             int nameWidth = textRenderer.getWidth(m.name); | ||||
|             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); | ||||
|             yOffset += 12; | ||||
|         } | ||||
|  |  | |||
|  | @ -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; | ||||
| 	} | ||||
| } | ||||
|  | @ -3,56 +3,49 @@ 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.DrawContext; | ||||
| import net.minecraft.client.gui.screen.Screen; | ||||
| import net.minecraft.text.Text; | ||||
| 
 | ||||
| public class ClickGUIScreen extends Screen  | ||||
| public class ClickGUIScreen extends Screen | ||||
| { | ||||
| 	public static ClickGUIScreen INSTANCE = new ClickGUIScreen(); | ||||
| 	public static ArrayList<ModuleButton> moduleButtons; | ||||
|     public static ClickGUIScreen INSTANCE = new ClickGUIScreen(); | ||||
|     public static ArrayList<CategoryPane> categoryPanes; | ||||
| 	 | ||||
| 	public ClickGUIScreen()  | ||||
| 	{ | ||||
| 		super(Text.literal("ClickGUI")); | ||||
| 		moduleButtons = new ArrayList<>(); | ||||
| 		int yOffset; | ||||
| 		int xOffset = 4; | ||||
| 		int yOffset = 4; | ||||
| 		categoryPanes = new ArrayList<CategoryPane>(); | ||||
| 		for (Category category : Category.values()) | ||||
| 		{  | ||||
| 			yOffset = 25; | ||||
| 			for (Module_ module : ModuleManager.INSTANCE.getModulesByCategory(category)) | ||||
| 			if (xOffset > 400) | ||||
| 			{ | ||||
| 				moduleButtons.add(new ModuleButton(module, 9+(module.category.ordinal()*70), yOffset)); | ||||
| 				yOffset += 14; | ||||
| 				xOffset = 4; | ||||
| 				yOffset = 128; | ||||
| 			} | ||||
| 			categoryPanes.add(new CategoryPane(category, xOffset, yOffset)); | ||||
| 			xOffset += 100; | ||||
| 		} | ||||
| 		 | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void render(DrawContext drawContext, int mouseX, int mouseY, float delta)  | ||||
| 	{ | ||||
| 		this.renderBackground(drawContext); | ||||
| 		int categoryLabelXOffset = 10; | ||||
| 		for (Category category : Category.values()) | ||||
| 		for (CategoryPane category : categoryPanes) | ||||
| 		{ | ||||
| 			drawContext.drawText(textRenderer, category.name, categoryLabelXOffset, 10, 0xFFFFFF, false); | ||||
| 			categoryLabelXOffset += 70; | ||||
| 		} | ||||
| 		for (ModuleButton moduleButton : moduleButtons) | ||||
| 		{ | ||||
| 			moduleButton.render(drawContext, mouseX, mouseY); | ||||
| 			category.render(drawContext, mouseX, mouseY, delta); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	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); | ||||
| 	} | ||||
|  |  | |||
|  | @ -1,5 +1,6 @@ | |||
| package me.kawaiizenbo.moonlight.ui.clickgui; | ||||
| 
 | ||||
| import me.kawaiizenbo.moonlight.Moonlight; | ||||
| import me.kawaiizenbo.moonlight.module.Module_; | ||||
| import net.minecraft.client.MinecraftClient; | ||||
| import net.minecraft.client.font.TextRenderer; | ||||
|  | @ -10,21 +11,21 @@ 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 x, int y)  | ||||
| 	public ModuleButton(Module_ module, int initialX, int initialY)  | ||||
|     { | ||||
| 		this.module = module; | ||||
| 		this.x = x; | ||||
| 		this.y = y; | ||||
| 		this.width = 70; | ||||
| 		this.height = 14; | ||||
| 		this.x = initialX; | ||||
| 		this.y = initialY; | ||||
| 		this.width = 92; | ||||
| 		this.height = 12; | ||||
| 	} | ||||
| 
 | ||||
|     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.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)  | ||||
|  | @ -32,7 +33,7 @@ public class ModuleButton | |||
| 		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))  | ||||
|         { | ||||
|  | @ -44,6 +45,8 @@ public class ModuleButton | |||
|             { | ||||
|                 MinecraftClient.getInstance().setScreen(new SettingsScreen(module)); | ||||
|             } | ||||
| 			return true; | ||||
| 		} | ||||
| 		return false; | ||||
| 	} | ||||
| } | ||||
|  |  | |||
|  | @ -34,7 +34,6 @@ public class SettingsScreen extends Screen | |||
| 			setting.render(drawContext, (width/2)-96, yOffset, mouseX, mouseY); | ||||
| 			yOffset += setting.height + 1; | ||||
| 		} | ||||
|         // add keybind setting here eventually | ||||
| 	} | ||||
|      | ||||
|     @Override | ||||
|  |  | |||
|  | @ -32,4 +32,9 @@ public class ColorUtils | |||
|     { | ||||
|         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); | ||||
|     } | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 kawaiizenbo
						kawaiizenbo