add config system and window dragging
This commit is contained in:
		
							parent
							
								
									6e584de0e6
								
							
						
					
					
						commit
						a18cb2a137
					
				
					 22 changed files with 354 additions and 104 deletions
				
			
		
							
								
								
									
										107
									
								
								src/main/java/me/kawaiizenbo/moonlight/Config.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										107
									
								
								src/main/java/me/kawaiizenbo/moonlight/Config.java
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,107 @@ | |||
| package me.kawaiizenbo.moonlight; | ||||
| 
 | ||||
| import java.io.File; | ||||
| import java.io.FileWriter; | ||||
| import java.nio.file.Files; | ||||
| import java.util.HashMap; | ||||
| import java.util.Map; | ||||
| 
 | ||||
| import com.google.gson.Gson; | ||||
| 
 | ||||
| import me.kawaiizenbo.moonlight.module.Category; | ||||
| import me.kawaiizenbo.moonlight.module.ModuleManager; | ||||
| import me.kawaiizenbo.moonlight.module.Module_; | ||||
| import me.kawaiizenbo.moonlight.module.settings.Setting; | ||||
| import me.kawaiizenbo.moonlight.ui.clickgui.ClickGUIScreen; | ||||
| import net.minecraft.client.MinecraftClient; | ||||
| 
 | ||||
| public class Config  | ||||
| { | ||||
|     MinecraftClient mc = MinecraftClient.getInstance(); | ||||
|     public File configDir = new File(mc.runDirectory.getPath() + "/moonlight"); | ||||
|     public File configFile = new File(configDir, "config.json"); | ||||
|     public Map<String, Object> config = new HashMap<>(); | ||||
|     protected static Gson gson = new Gson(); | ||||
|      | ||||
|     public Config() | ||||
|     { | ||||
|         configDir.mkdirs(); | ||||
|     } | ||||
| 
 | ||||
|     public boolean doesConfigExist() | ||||
|     { | ||||
|         return !Files.exists(configFile.toPath()); | ||||
|     } | ||||
| 
 | ||||
|     public void loadDefaultConfig() | ||||
|     { | ||||
|         ModuleManager.INSTANCE = new ModuleManager(); | ||||
|         Map<String, Object> mi = new HashMap<>(); | ||||
|         for (Module_ m : ModuleManager.INSTANCE.modules) | ||||
| 		{ | ||||
| 			Map<String, Object> mo = new HashMap<>(); | ||||
|             mo.put("enabled", m.enabled); | ||||
| 			for (Setting s : m.settings) | ||||
| 			{ | ||||
|                 mo.put(s.name, s.value); | ||||
| 			} | ||||
|             mi.put(m.name, mo); | ||||
| 		} | ||||
|         config.put("modules", mi); | ||||
|         int xOffset = 4; | ||||
| 		int yOffset = 4; | ||||
|         Map<String, Object> pi = new HashMap<>(); | ||||
|         for (Category category : Category.values()) | ||||
| 		{  | ||||
|             Map<String, Object> po = new HashMap<>(); | ||||
| 			if (xOffset > 400) | ||||
| 			{ | ||||
| 				xOffset = 4; | ||||
| 				yOffset = 128; | ||||
| 			} | ||||
| 			po.put("x", xOffset); | ||||
|             po.put("y", yOffset); | ||||
|             po.put("collapsed", false); | ||||
|             pi.put(category.name, po); | ||||
| 			xOffset += 100; | ||||
| 		} | ||||
|         config.put("panes", pi); | ||||
|         ClickGUIScreen.INSTANCE = new ClickGUIScreen(); | ||||
|     } | ||||
| 
 | ||||
|     public void load() | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             String configText = new String(Files.readAllBytes(configFile.toPath())); | ||||
|             config = (Map<String, Object>)gson.fromJson(configText, Map.class); | ||||
|         } | ||||
|         catch (Exception e) | ||||
|         { | ||||
|             e.printStackTrace(); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public void save() | ||||
|     { | ||||
|         try | ||||
|         {  | ||||
|             if (!doesConfigExist()) configFile.createNewFile();  | ||||
|         }  | ||||
|         catch(Exception e)  | ||||
|         { | ||||
|             e.printStackTrace(); | ||||
|         } | ||||
|         try | ||||
|         { | ||||
|             String configText = gson.toJson(config); | ||||
|             FileWriter writer = new FileWriter(configFile); | ||||
|             writer.write(configText); | ||||
|             writer.close(); | ||||
|         } | ||||
|         catch (Exception e) | ||||
|         { | ||||
|             e.printStackTrace(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -3,8 +3,16 @@ package me.kawaiizenbo.moonlight; | |||
| import net.fabricmc.api.ModInitializer; | ||||
| 
 | ||||
| import org.slf4j.Logger; | ||||
| 
 | ||||
| import java.util.HashMap; | ||||
| import java.util.Map; | ||||
| import org.slf4j.LoggerFactory; | ||||
| 
 | ||||
| import me.kawaiizenbo.moonlight.module.ModuleManager; | ||||
| import me.kawaiizenbo.moonlight.module.Module_; | ||||
| import me.kawaiizenbo.moonlight.module.settings.Setting; | ||||
| import me.kawaiizenbo.moonlight.ui.clickgui.CategoryPane; | ||||
| import me.kawaiizenbo.moonlight.ui.clickgui.ClickGUIScreen; | ||||
| import me.kawaiizenbo.moonlight.util.ColorUtils; | ||||
| 
 | ||||
| public class Moonlight implements ModInitializer  | ||||
|  | @ -13,6 +21,7 @@ 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 Config CONFIG = new Config(); | ||||
| 	public static int uiColorA = 0xFF55FFFF; | ||||
| 	public static int uiColor = 0x55FFFF; | ||||
| 
 | ||||
|  | @ -20,5 +29,53 @@ public class Moonlight implements ModInitializer | |||
| 	public void onInitialize()  | ||||
| 	{ | ||||
| 		LOGGER.info("Moonlight loading..."); | ||||
| 		loadConfig(); | ||||
| 	} | ||||
| 
 | ||||
| 	public void loadConfig() | ||||
| 	{ | ||||
| 		LOGGER.info("Loading config..."); | ||||
| 		if (CONFIG.doesConfigExist()) | ||||
| 		{ | ||||
| 			CONFIG.loadDefaultConfig();  | ||||
| 			CONFIG.save(); | ||||
| 		} | ||||
| 		CONFIG.load(); | ||||
| 		for (Module_ m : ModuleManager.INSTANCE.modules) | ||||
| 		{ | ||||
| 			m.enabled = (boolean)((Map<String, Object>)((Map<String, Object>)CONFIG.config.get("modules")).get(m.name)).get("enabled"); | ||||
| 			for (Setting s : m.settings) | ||||
| 			{ | ||||
| 				s.value = ((Map<String, Object>)((Map<String, Object>)CONFIG.config.get("modules")).get(m.name)).get(s.name); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	public void saveConfig() | ||||
| 	{ | ||||
| 		LOGGER.info("Saving config..."); | ||||
| 		Map<String, Object> mi = new HashMap<>(); | ||||
|         for (Module_ m : ModuleManager.INSTANCE.modules) | ||||
| 		{ | ||||
| 			Map<String, Object> mo = new HashMap<>(); | ||||
|             mo.put("enabled", m.enabled); | ||||
| 			for (Setting s : m.settings) | ||||
| 			{ | ||||
|                 mo.put(s.name, s.value); | ||||
| 			} | ||||
|             mi.put(m.name, mo); | ||||
| 		} | ||||
|         CONFIG.config.put("modules", mi); | ||||
|         Map<String, Object> pi = new HashMap<>(); | ||||
|         for (CategoryPane c : ClickGUIScreen.INSTANCE.categoryPanes) | ||||
| 		{  | ||||
|             Map<String, Object> po = new HashMap<>(); | ||||
| 			po.put("x", c.x); | ||||
|             po.put("y", c.y); | ||||
| 			po.put("collapsed", c.collapsed); | ||||
|             pi.put(c.category.name, po); | ||||
| 		} | ||||
|         CONFIG.config.put("panes", pi); | ||||
| 		CONFIG.save(); | ||||
| 	} | ||||
| } | ||||
|  |  | |||
|  | @ -0,0 +1,25 @@ | |||
| package me.kawaiizenbo.moonlight.command.commands; | ||||
| 
 | ||||
| import com.mojang.brigadier.builder.LiteralArgumentBuilder; | ||||
| 
 | ||||
| import me.kawaiizenbo.moonlight.Moonlight; | ||||
| import me.kawaiizenbo.moonlight.command.Command; | ||||
| import net.minecraft.command.CommandSource; | ||||
| 
 | ||||
| public class Reset extends Command | ||||
| { | ||||
|     public Reset()  | ||||
|     { | ||||
|         super("reset", "Resets all config options."); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void build(LiteralArgumentBuilder<CommandSource> builder)  | ||||
|     { | ||||
|         builder.executes(context ->  | ||||
|         { | ||||
| 			Moonlight.CONFIG.loadDefaultConfig(); | ||||
| 			return SINGLE_SUCCESS; | ||||
| 		}); | ||||
|     }     | ||||
| } | ||||
|  | @ -7,6 +7,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | |||
| 
 | ||||
| import me.kawaiizenbo.moonlight.module.ModuleManager; | ||||
| import me.kawaiizenbo.moonlight.module.Module_; | ||||
| import net.minecraft.client.MinecraftClient; | ||||
| import net.minecraft.client.network.ClientPlayerEntity; | ||||
| import net.minecraft.entity.MovementType; | ||||
| import net.minecraft.util.math.Vec3d; | ||||
|  | @ -14,12 +15,30 @@ import net.minecraft.util.math.Vec3d; | |||
| @Mixin(ClientPlayerEntity.class) | ||||
| public class ClientPlayerEntityMixin  | ||||
| { | ||||
|     @Inject(method = "move", at = @At(value = "HEAD"), cancellable = true) | ||||
|     public void onMotion(MovementType type, Vec3d movement, CallbackInfo ci)  | ||||
|     @Inject(method = "move", at = @At(value = "TAIL"), cancellable = true) | ||||
|     public void onMove(MovementType type, Vec3d movement, CallbackInfo ci)  | ||||
|     { | ||||
|         for (Module_ m : ModuleManager.INSTANCE.getEnabledModules()) | ||||
|         { | ||||
|             m.onMotion(type, movement); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     @Inject(method = "tick", at = @At(value = "HEAD"), cancellable = true) | ||||
|     public void onTick(CallbackInfo ci)  | ||||
|     { | ||||
|         for (Module_ m : ModuleManager.INSTANCE.getEnabledModules())  | ||||
|         { | ||||
| 			if (MinecraftClient.getInstance().player != null) m.tick(); | ||||
| 		} | ||||
|     } | ||||
| 
 | ||||
|     @Inject(method = "init", at = @At(value = "TAIL"), cancellable = true) | ||||
|     public void onInit(CallbackInfo ci)  | ||||
|     { | ||||
|         for (Module_ m : ModuleManager.INSTANCE.getEnabledModules())  | ||||
|         { | ||||
| 			m.onEnable(); | ||||
| 		} | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -1,25 +0,0 @@ | |||
| package me.kawaiizenbo.moonlight.mixin; | ||||
| 
 | ||||
| import net.minecraft.client.MinecraftClient; | ||||
| import net.minecraft.entity.LivingEntity; | ||||
| 
 | ||||
| import me.kawaiizenbo.moonlight.module.Module_; | ||||
| import me.kawaiizenbo.moonlight.module.ModuleManager; | ||||
| 
 | ||||
| import org.spongepowered.asm.mixin.Mixin; | ||||
| import org.spongepowered.asm.mixin.injection.At; | ||||
| import org.spongepowered.asm.mixin.injection.Inject; | ||||
| import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||||
| 
 | ||||
| @Mixin(LivingEntity.class) | ||||
| public class LivingEntityMixin  | ||||
| { | ||||
|     @Inject(at = @At("HEAD"), method = "tick()V") | ||||
| 	private void init(CallbackInfo info)  | ||||
|     { | ||||
| 		for (Module_ mod : ModuleManager.INSTANCE.getEnabledModules())  | ||||
|         { | ||||
| 			if (MinecraftClient.getInstance().player != null) mod.tick(); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | @ -0,0 +1,18 @@ | |||
| package me.kawaiizenbo.moonlight.mixin; | ||||
| 
 | ||||
| import org.spongepowered.asm.mixin.Mixin; | ||||
| import org.spongepowered.asm.mixin.injection.Inject; | ||||
| import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||||
| import org.spongepowered.asm.mixin.injection.At; | ||||
| 
 | ||||
| import me.kawaiizenbo.moonlight.Moonlight; | ||||
| import net.minecraft.client.MinecraftClient; | ||||
| 
 | ||||
| @Mixin(MinecraftClient.class) | ||||
| public class MinecraftClientMixin  | ||||
| { | ||||
|     @Inject(at = @At("TAIL"), method = "scheduleStop") | ||||
| 	public void onShutdown(CallbackInfo ci) { | ||||
| 		Moonlight.INSTANCE.saveConfig(); | ||||
| 	} | ||||
| } | ||||
|  | @ -6,8 +6,8 @@ public enum Category | |||
| 	MOVEMENT("Movement", 0xFFFF55FF), | ||||
| 	RENDER("Render", 0xFF5555FF), | ||||
| 	WORLD("World", 0xFF55FF55),  | ||||
| 	PLAYER("Player", 0xFFFFFFFF), | ||||
| 	CHAT("Chat", 0xFFFFFF55); | ||||
| 	PLAYER("Player", 0xFF00AAAA), | ||||
| 	CHAT("Chat", 0xFFFFAA00); | ||||
| 	 | ||||
| 	public String name; | ||||
| 	public int color; | ||||
|  |  | |||
|  | @ -17,8 +17,7 @@ public abstract class Module_ | |||
|     public Category category; | ||||
|     public boolean enabled; | ||||
|     public ArrayList<Setting> settings; | ||||
|     public int keyBind; | ||||
| 
 | ||||
|      | ||||
|     public BooleanSetting showInModulesList = new BooleanSetting("Show in Modules List", true); | ||||
| 
 | ||||
|     public Module_(String name, String description, Category category) | ||||
|  |  | |||
|  | @ -1,5 +1,6 @@ | |||
| package me.kawaiizenbo.moonlight.module.settings; | ||||
| 
 | ||||
| import net.minecraft.client.font.TextRenderer; | ||||
| import net.minecraft.client.gui.DrawContext; | ||||
| import net.minecraft.text.Text; | ||||
| 
 | ||||
|  | @ -14,9 +15,9 @@ public class BooleanSetting extends Setting | |||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY)  | ||||
|     public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY, TextRenderer textRenderer)  | ||||
|     { | ||||
|         super.render(drawContext, x, y, mouseX, mouseY); | ||||
|         super.render(drawContext, x, y, mouseX, mouseY, textRenderer); | ||||
|         drawContext.drawTextWithShadow(textRenderer, Text.literal(name), x+2, y+8, 0xFFFFFF); | ||||
|         drawContext.fill(x+175, y+7, x+185, y+17, 0xFFFFFFFF); | ||||
|         drawContext.fill(x+176, y+8, x+184, y+16, 0xFF222222); | ||||
|  |  | |||
|  | @ -1,6 +1,7 @@ | |||
| package me.kawaiizenbo.moonlight.module.settings; | ||||
| 
 | ||||
| import me.kawaiizenbo.moonlight.util.ColorUtils; | ||||
| import net.minecraft.client.font.TextRenderer; | ||||
| import net.minecraft.client.gui.DrawContext; | ||||
| import net.minecraft.text.Text; | ||||
| 
 | ||||
|  | @ -23,9 +24,9 @@ public class ColorSetting extends Setting | |||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY)  | ||||
|     public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY, TextRenderer textRenderer)  | ||||
|     { | ||||
|         super.render(drawContext, x, y, mouseX, mouseY); | ||||
|         super.render(drawContext, x, y, mouseX, mouseY, textRenderer); | ||||
|         drawContext.drawTextWithShadow(textRenderer, Text.literal(name), x+2, y+2, 0xFFFFFF); | ||||
|         int redDisplayStartColor = ColorUtils.rgbaToInt(0, g, b, 255); | ||||
|         int redDisplayEndColor = ColorUtils.rgbaToInt(255, g, b, 255); | ||||
|  |  | |||
|  | @ -1,6 +1,7 @@ | |||
| package me.kawaiizenbo.moonlight.module.settings; | ||||
| 
 | ||||
| import me.kawaiizenbo.moonlight.util.MathUtils; | ||||
| import net.minecraft.client.font.TextRenderer; | ||||
| import net.minecraft.client.gui.DrawContext; | ||||
| import net.minecraft.text.Text; | ||||
| 
 | ||||
|  | @ -22,9 +23,9 @@ public class DoubleSetting extends Setting | |||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY)  | ||||
|     public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY, TextRenderer textRenderer)  | ||||
|     { | ||||
|         super.render(drawContext, x, y, mouseX, mouseY); | ||||
|         super.render(drawContext, x, y, mouseX, mouseY, textRenderer); | ||||
|         drawContext.drawTextWithShadow(textRenderer, Text.literal(name), x+2, y+2, 0xFFFFFF); | ||||
|         double diff = Math.min(100, Math.max(0, (mouseX - x)/1.9)); | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,20 +1,16 @@ | |||
| package me.kawaiizenbo.moonlight.module.settings; | ||||
| 
 | ||||
| import java.lang.reflect.Method; | ||||
| 
 | ||||
| import net.minecraft.client.MinecraftClient; | ||||
| import net.minecraft.client.font.TextRenderer; | ||||
| import net.minecraft.client.gui.DrawContext; | ||||
| 
 | ||||
| public class Setting  | ||||
| { | ||||
|     public String name; | ||||
|     public Method onValueChanged; | ||||
|     protected TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer; | ||||
|     public int height = 24; | ||||
|     public Object value; | ||||
| 
 | ||||
|     int x = 0, y = 0; | ||||
|     public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY) | ||||
|     public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY, TextRenderer textRenderer) | ||||
|     {  | ||||
|         this.x = x; | ||||
|         this.y = y; | ||||
|  |  | |||
|  | @ -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); | ||||
|  |  | |||
|  | @ -17,6 +17,19 @@ public class MathUtils | |||
|         return bd.doubleValue(); | ||||
|     } | ||||
| 
 | ||||
|     public static int d2iSafe(Object value) | ||||
|     { | ||||
|         int out = 0; | ||||
|         try | ||||
|         { | ||||
|             out = (int)Math.floor((double)value); | ||||
|         } catch (Exception e) | ||||
|         { | ||||
|             out = (int)value; | ||||
|         } | ||||
|         return out; | ||||
|     } | ||||
| 
 | ||||
|     public static double length2D(Vec3d vec3d)  | ||||
|     { | ||||
|         return MathHelper.sqrt((float)(vec3d.x * vec3d.x + vec3d.z * vec3d.z)); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 kawaiizenbo
						kawaiizenbo