add settings to hud modules
This commit is contained in:
		
							parent
							
								
									90347f7476
								
							
						
					
					
						commit
						e5d1d3ef73
					
				
					 7 changed files with 119 additions and 3 deletions
				
			
		|  | @ -4,6 +4,7 @@ import me.kawaiizenbo.moonlight.module.Module; | |||
| import net.minecraft.client.MinecraftClient; | ||||
| import net.minecraft.client.font.TextRenderer; | ||||
| import net.minecraft.client.gui.DrawContext; | ||||
| import net.minecraft.util.Identifier; | ||||
| 
 | ||||
| public class ModuleButton  | ||||
| { | ||||
|  | @ -23,6 +24,7 @@ public class ModuleButton | |||
| 		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 ? 0x55FFFF : 0xFFFFFF, false); | ||||
| 		if (!module.settings.isEmpty()) drawContext.drawGuiTexture(Identifier.of("moonlight", "settings"), x+width-12, y, 12, 12); | ||||
| 	} | ||||
| 	 | ||||
| 	public boolean hovered(int mouseX, int mouseY)  | ||||
|  |  | |||
|  | @ -1,5 +1,8 @@ | |||
| package me.kawaiizenbo.moonlight.ui.hud; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| 
 | ||||
| import me.kawaiizenbo.moonlight.module.settings.Setting; | ||||
| import net.minecraft.client.MinecraftClient; | ||||
| import net.minecraft.client.font.TextRenderer; | ||||
| import net.minecraft.client.gui.DrawContext; | ||||
|  | @ -11,6 +14,7 @@ public class HUDModule | |||
|     int startX, startY; | ||||
|     boolean dragging = false; | ||||
|     public boolean enabled = false; | ||||
|     public ArrayList<Setting> settings; | ||||
|      | ||||
|     protected static MinecraftClient mc = MinecraftClient.getInstance(); | ||||
| 
 | ||||
|  | @ -19,6 +23,7 @@ public class HUDModule | |||
|     	this.name = name; | ||||
|         this.x = x; | ||||
|         this.y = y; | ||||
|         settings = new ArrayList<>(); | ||||
|     } | ||||
| 
 | ||||
|     public void render(DrawContext drawContext, int mouseX, int mouseY, TextRenderer textRenderer, boolean editMode, boolean enabled)  | ||||
|  |  | |||
|  | @ -17,6 +17,7 @@ public class HUDModuleManager | |||
| 			new Ping(2, 22), | ||||
| 			new MovementSpeed(2, 32), | ||||
| 			new Coordinates(2, 42) | ||||
| 			//new TestModuleHUD(20, 50) | ||||
| 		); | ||||
| 	} | ||||
| 	 | ||||
|  |  | |||
|  | @ -1,8 +1,10 @@ | |||
| package me.kawaiizenbo.moonlight.ui.hud.editor; | ||||
| 
 | ||||
| import me.kawaiizenbo.moonlight.ui.hud.HUDModule; | ||||
| import net.minecraft.client.MinecraftClient; | ||||
| import net.minecraft.client.font.TextRenderer; | ||||
| import net.minecraft.client.gui.DrawContext; | ||||
| import net.minecraft.util.Identifier; | ||||
| 
 | ||||
| public class HUDModuleButton  | ||||
| { | ||||
|  | @ -22,6 +24,7 @@ public class HUDModuleButton | |||
| 		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 ? 0x55FFFF : 0xFFFFFF, false); | ||||
| 		if (!module.settings.isEmpty()) drawContext.drawGuiTexture(Identifier.of("moonlight", "settings"), x+width-12, y, 12, 12); | ||||
| 	} | ||||
| 	 | ||||
| 	public boolean hovered(int mouseX, int mouseY)  | ||||
|  | @ -39,8 +42,7 @@ public class HUDModuleButton | |||
|             } | ||||
| 		    else if (button == 1) | ||||
|             { | ||||
| 		    	// HUDModule Settings coming Soon TM | ||||
|                 //MinecraftClient.getInstance().setScreen(new SettingsScreen(module)); | ||||
| 		    	if (!module.settings.isEmpty()) MinecraftClient.getInstance().setScreen(new HUDModuleSettingsScreen(module)); | ||||
|             } | ||||
| 			return true; | ||||
| 		} | ||||
|  |  | |||
|  | @ -0,0 +1,99 @@ | |||
| package me.kawaiizenbo.moonlight.ui.hud.editor; | ||||
| 
 | ||||
| import me.kawaiizenbo.moonlight.module.settings.Setting; | ||||
| import me.kawaiizenbo.moonlight.ui.SetScreenButton; | ||||
| import me.kawaiizenbo.moonlight.ui.hud.HUDModule; | ||||
| 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 HUDModuleSettingsScreen extends Screen  | ||||
| { | ||||
| 	// adapted for hud modules | ||||
|     private HUDModule module; | ||||
|     private SetScreenButton backButton; | ||||
| 
 | ||||
|     boolean dragging = false; | ||||
|     int startX, startY, x = (HUDEditorScreen.INSTANCE.width/2)-112, y = (HUDEditorScreen.INSTANCE.height/2)-96, windowWidth = 224, windowHeight = 192; | ||||
| 
 | ||||
|     public HUDModuleSettingsScreen(HUDModule module)  | ||||
|     { | ||||
|         super(Text.literal("Settings")); | ||||
|         backButton = new SetScreenButton(ColorUtils.underline + "< Back", x+4, 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, 0xFF55FFFF); | ||||
|         drawContext.fill(x+2, y+2, x+(windowWidth-2), y+14, 0xFF222222); | ||||
|         drawContext.drawCenteredTextWithShadow(textRenderer, module.name, x+(windowWidth/2), y+4, 0xFFFFFF); | ||||
|         backButton.render(drawContext, textRenderer, mouseX, mouseY, x+4, y+4); | ||||
| 		int yOffset = y+24; | ||||
| 		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); | ||||
|         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); | ||||
|     } | ||||
| } | ||||
|  | @ -1,22 +1,29 @@ | |||
| package me.kawaiizenbo.moonlight.ui.hud.modules; | ||||
| 
 | ||||
| import me.kawaiizenbo.moonlight.module.settings.DoubleSetting; | ||||
| import me.kawaiizenbo.moonlight.module.settings.StringSetting; | ||||
| import me.kawaiizenbo.moonlight.ui.hud.HUDModule; | ||||
| import net.minecraft.client.font.TextRenderer; | ||||
| import net.minecraft.client.gui.DrawContext; | ||||
| 
 | ||||
| public class TestModuleHUD extends HUDModule | ||||
| { | ||||
| 	public StringSetting text = new StringSetting("Text", "hii :3"); | ||||
| 	public DoubleSetting number = new DoubleSetting("test", 1, 0, 10, 0); | ||||
| 	 | ||||
| 	public TestModuleHUD(int x, int y)  | ||||
| 	{ | ||||
| 		super("Test HUD Module", x, y); | ||||
| 		this.width = 96; | ||||
| 		this.height = 8; | ||||
| 		settings.add(text); | ||||
| 		settings.add(number); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void render(DrawContext drawContext, int mouseX, int mouseY, TextRenderer textRenderer, boolean editMode, boolean enabled)  | ||||
| 	{ | ||||
| 		super.render(drawContext, mouseX, mouseY, textRenderer, editMode, enabled); | ||||
| 		drawContext.drawText(textRenderer, "Text Text Text Test :3", x, y, 0xFFFFFF, false); | ||||
| 		drawContext.drawText(textRenderer, text.value, x, y, 0xFFFFFF, false); | ||||
| 	} | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 kawaiizenbo
						kawaiizenbo