optimize some code

This commit is contained in:
ThisIsALegitUsername 2023-04-05 02:10:39 +00:00
parent 55a9ab7762
commit e8497380a1
5 changed files with 31713 additions and 31699 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,26 @@
package dev.resent.util.misc;
public class TimerUtil {
private static long halfSecond = 500000000;
private long lastTime;
private long getDeltaTime(){
return (System.nanoTime()-lastTime);
}
private void updateTime(){
this.lastTime = System.nanoTime();
}
public TimerUtil() {
this.lastTime = System.nanoTime();
}
public boolean hasHalfSecondPassoed() {
if (getDeltaTime() >= halfSecond) {
updateTime();
return true;
}
else return false;
}
}

View File

@ -2,9 +2,6 @@ package dev.resent.visual.ui.clickgui.rewrite;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import dev.resent.client.Resent; import dev.resent.client.Resent;
import dev.resent.module.base.Mod; import dev.resent.module.base.Mod;
@ -21,7 +18,6 @@ import dev.resent.visual.ui.clickgui.rewrite.comp.Comp;
import dev.resent.visual.ui.clickgui.rewrite.comp.impl.CompCheck; import dev.resent.visual.ui.clickgui.rewrite.comp.impl.CompCheck;
import net.lax1dude.eaglercraft.v1_8.Mouse; import net.lax1dude.eaglercraft.v1_8.Mouse;
import net.lax1dude.eaglercraft.v1_8.internal.KeyboardConstants; import net.lax1dude.eaglercraft.v1_8.internal.KeyboardConstants;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformInput;
import net.lax1dude.eaglercraft.v1_8.opengl.GlStateManager; import net.lax1dude.eaglercraft.v1_8.opengl.GlStateManager;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.FontRenderer;
@ -33,171 +29,169 @@ import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.MathHelper; import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
public class ClickGuiRewrite extends GuiScreen{ public class ClickGuiRewrite extends GuiScreen {
public FontRenderer fr; public FontRenderer fr;
public ArrayList<Comp> comps = new ArrayList<>(); public ArrayList < Comp > comps = new ArrayList < > ();
public float x, y, width, height; public float x, y, width, height;
public Animation introAnimation; public Animation introAnimation;
public ScaledResolution sr; public ScaledResolution sr;
public boolean closing; public boolean closing, isSearchFocused;
public Mod selectedMod; public Mod selectedMod;
public String searchString = ""; public String searchString = "";
public SimpleAnimation partAnimation = new SimpleAnimation(0); public SimpleAnimation partAnimation = new SimpleAnimation(0);
public int backgroundColor = new Color(18, 18, 18).getRGB(), public int backgroundColor = new Color(18, 18, 18).getRGB(),
primaryColor = 0xFF000000, primaryColor = 0xFF000000,
secondaryColor = new Color(33, 33, 33).getRGB(), secondaryColor = new Color(33, 33, 33).getRGB(),
onSurfaceColor = new Color(3, 218, 197).getRGB(), onSurfaceColor = new Color(3, 218, 197).getRGB(),
secondaryFontColor = new Color(187, 134, 252).getRGB(); secondaryFontColor = new Color(187, 134, 252).getRGB();
public int partOffset = 0, scrollOffset = 0; public int partOffset = 0, scrollOffset = 0;
public String part = "Home"; public String part = "Home";
private boolean isSearchFocused = false;
@Override @Override
public void drawScreen(int mouseX, int mouseY, float var3) { public void drawScreen(int mouseX, int mouseY, float var3) {
int offset = 0; int offset = 0;
GlUtils.startScale((this.x + this.width) / 2, (this.y + this.height) / 2, introAnimation != null ? (float) introAnimation.getValue() : 1); GlUtils.startScale((this.x + this.width) / 2, (this.y + this.height) / 2, introAnimation != null ? (float) introAnimation.getValue() : 1);
//Navigation bar //Navigation bar
RenderUtils.drawRoundedRect(x, y, x+width-60, y+height, 32, secondaryColor); RenderUtils.drawRoundedRect(x, y, x + width - 60, y + height, 32, secondaryColor);
//Background overlay //Background overlay
RenderUtils.drawRoundedRect(x+60, y, x+width, y+height, 32, backgroundColor); RenderUtils.drawRoundedRect(x + 60, y, x + width, y + height, 32, backgroundColor);
Gui.drawRect(x+60, y, x+102, y+height, backgroundColor); Gui.drawRect(x + 60, y, x + 102, y + height, backgroundColor);
//Separating line //Separating line
Gui.drawRect(x, y+90, x+width, y+95, secondaryColor); Gui.drawRect(x, y + 90, x + width, y + 95, secondaryColor);
//Title //Title
GlStateManager.pushMatrix(); GlStateManager.pushMatrix();
GlStateManager.translate(x+80, y+36, 0); GlStateManager.translate(x + 80, y + 36, 0);
GlStateManager.scale(3.5f, 3.5f, 1); GlStateManager.scale(3.5F, 3.5F, 1);
GlStateManager.translate(-(x+80), -(y+36), 0); GlStateManager.translate(-(x + 80), -(y + 36), 0);
fr.drawString("Resent", x+80, y+36, -1, false); fr.drawString("Resent", x + 80, y + 36, -1, false);
GlStateManager.popMatrix(); GlStateManager.popMatrix();
//Navigation selection //Navigation selection
RenderUtils.drawRoundedRect(x+15, (int)y+115+partAnimation.getValue(), x+45, y+145+partAnimation.getValue(), 8, secondaryFontColor); RenderUtils.drawRoundedRect(x + 15, (int) y + 115 + partAnimation.getValue(), x + 45, y + 145 + partAnimation.getValue(), 8, secondaryFontColor);
//Navigation icons //Navigation icons
GlStateManager.color(1, 1, 1); GlStateManager.color(1, 1, 1);
mc.getTextureManager().bindTexture(new ResourceLocation("eagler:gui/house.png")); mc.getTextureManager().bindTexture(new ResourceLocation("eagler:gui/house.png"));
Gui.drawModalRectWithCustomSizedTexture(x+20, (int)y+120, 0, 0, 20, 20, 20, 20); Gui.drawModalRectWithCustomSizedTexture(x + 20, (int) y + 120, 0, 0, 20, 20, 20, 20);
mc.getTextureManager().bindTexture(new ResourceLocation("eagler:gui/gear2.png")); mc.getTextureManager().bindTexture(new ResourceLocation("eagler:gui/gear2.png"));
Gui.drawModalRectWithCustomSizedTexture(x+20, (int)y+170, 0, 0, 20, 20, 20, 20); Gui.drawModalRectWithCustomSizedTexture(x + 20, (int) y + 170, 0, 0, 20, 20, 20, 20);
//Search //Search
RenderUtils.drawRoundedRect(x+width-300, y+25, x+width-50, y+65, 9, secondaryColor); RenderUtils.drawRoundedRect(x + width - 300, y + 25, x + width - 50, y + 65, 9, secondaryColor);
GlStateManager.pushMatrix(); GlStateManager.pushMatrix();
GlStateManager.translate(x+width-290, y+40, 0); GlStateManager.translate(x + width - 290, y + 40, 0);
GlStateManager.scale(1.5f, 1.5f, 1); GlStateManager.scale(1.5F, 1.5F, 1);
GlStateManager.translate(-(x+width-290), -(y+40), 0); GlStateManager.translate(-(x + width - 290), -(y + 40), 0);
if(searchString.length() > 0) { if (searchString.length() > 0) {
fr.drawString(searchString, x+width-290, y+40, secondaryFontColor, false); fr.drawString(searchString, x + width - 290, y + 40, secondaryFontColor, false);
}else if (!isSearchFocused) { } else {
fr.drawString(EnumChatFormatting.ITALIC + "Search" + EnumChatFormatting.RESET, x+width-290, y+40, new Color(97, 97, 97).getRGB(), false); fr.drawString(EnumChatFormatting.ITALIC + "Search", x + width - 290, y + 40, new Color(97, 97, 97).getRGB(), false);
} }
if (isSearchFocused) { if (isSearchFocused) {
drawRect(x + width - (290 - fr.getStringWidth(searchString)), y+38, x + width - (289 - fr.getStringWidth(searchString)), y+50, secondaryFontColor); drawRect(x + width - 290 - fr.getStringWidth(searchString), y + 38, x + width - 289 - fr.getStringWidth(searchString), y + 50, secondaryFontColor);
} }
GlStateManager.popMatrix(); GlStateManager.popMatrix();
//Draw module button //Draw module button
for(Mod m : Resent.INSTANCE.modManager.modules){ for (Mod m: Resent.INSTANCE.modManager.modules) {
if(!m.isAdmin() && m.getName().toLowerCase().startsWith(searchString.toLowerCase()) && selectedMod == null) { if (!m.isAdmin() && m.getName().toLowerCase().startsWith(searchString.toLowerCase()) && selectedMod == null) {
if(y+115+offset+scrollOffset > y+95 && y+185+offset+scrollOffset < y+height) { if (y + 115 + offset + scrollOffset > y + 95 && y + 185 + offset + scrollOffset < y + height) {
//Body //Body
RenderUtils.drawRoundedRect(x+80, y+115+offset+scrollOffset, x+width-20, y+185+offset+scrollOffset, 16, secondaryColor); RenderUtils.drawRoundedRect(x + 80, y + 115 + offset + scrollOffset, x + width - 20, y + 185 + offset + scrollOffset, 16, secondaryColor);
//Gear //Gear
if(m.doesHaveSetting()) { if (m.doesHaveSetting()) {
GlStateManager.color(1, 1, 1); GlStateManager.color(1, 1, 1);
mc.getTextureManager().bindTexture(new ResourceLocation("/resent/gear.png")); mc.getTextureManager().bindTexture(new ResourceLocation("/resent/gear.png"));
Gui.drawModalRectWithCustomSizedTexture(x+width-60, (int)y+140+offset+scrollOffset, 0, 0, 20, 20, 20, 20); Gui.drawModalRectWithCustomSizedTexture(x + width - 60, (int) y + 140 + offset + scrollOffset, 0, 0, 20, 20, 20, 20);
} }
//RenderUtils.drawRoundedRect(x+width-60, y+140+offset, x+width-40, y+160+offset, 4, -1); //RenderUtils.drawRoundedRect(x+width-60, y+140+offset, x+width-40, y+160+offset, 4, -1);
//Toggle //Toggle
RenderUtils.drawRoundedRect(x+90, y+125+offset+scrollOffset, x+140, y+175+offset+scrollOffset, 8, new Color(66, 66, 66).getRGB()); RenderUtils.drawRoundedRect(x + 90, y + 125 + offset + scrollOffset, x + 140, y + 175 + offset + scrollOffset, 8, new Color(66, 66, 66).getRGB());
GlUtils.startScale(x+90, y+140+offset+scrollOffset, 2); GlUtils.startScale(x + 90, y + 140 + offset + scrollOffset, 2);
fr.drawString(m.getName(), x+120, y+140+offset+scrollOffset, -1, false); fr.drawString(m.getName(), x + 120, y + 140 + offset + scrollOffset, -1, false);
GlStateManager.popMatrix(); GlStateManager.popMatrix();
if(isMouseInside(mouseX, mouseY, x+80, y+115+offset+scrollOffset, x+width-20, y+185+offset+scrollOffset)) { if (isMouseInside(mouseX, mouseY, x + 80, y + 115 + offset + scrollOffset, x + width - 20, y + 185 + offset + scrollOffset)) {
fr.drawString(m.getDescription(), mouseX+8, mouseY, onSurfaceColor, false); fr.drawString(m.getDescription(), mouseX + 8, mouseY, onSurfaceColor, false);
} }
} }
offset += 80; offset += 80;
} }
} }
GlStateManager.popMatrix(); GlStateManager.popMatrix();
if(selectedMod != null){ if (selectedMod != null) {
for (Comp comp : comps) { for (Comp comp: comps) {
comp.drawScreen(mouseX, mouseY); comp.drawScreen(mouseX, mouseY);
} }
} }
if (closing) { if (closing) {
comps.clear(); comps.clear();
if(introAnimation == null) { if (introAnimation == null) {
mc.displayGuiScreen(null); mc.displayGuiScreen(null);
return; return;
} }
introAnimation.setDirection(Direction.BACKWARDS); introAnimation.setDirection(Direction.BACKWARDS);
if (introAnimation.isDone(Direction.BACKWARDS)) { if (introAnimation.isDone(Direction.BACKWARDS)) {
mc.displayGuiScreen(null); mc.displayGuiScreen(null);
} }
} }
} }
@Override @Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) { protected void mouseClicked(int mouseX, int mouseY, int mouseButton) {
if(isMouseInside(mouseX, mouseY, x+20, (int)y+170, x+40, (int)y+190)) {
partAnimation.setAnimation(50-partOffset, 10);
}else if(isMouseInside(mouseX, mouseY, x+20, (int)y+120, x+40, (int)y+140)) {
partAnimation.setAnimation(0-partOffset, 10);
}
if (isMouseInside(mouseX, mouseY, x+width-300, y+25, x+width-50, y+65)) {
isSearchFocused = true;
}
else {
isSearchFocused = false;
}
int offset = 0; if (isMouseInside(mouseX, mouseY, x + 20, (int) y + 170, x + 40, (int) y + 190)) {
partAnimation.setAnimation(50 - partOffset, 10);
for(Mod m : Resent.INSTANCE.modManager.modules){ } else if (isMouseInside(mouseX, mouseY, x + 20, (int) y + 120, x + 40, (int) y + 140)) {
if(!m.isAdmin()) { partAnimation.setAnimation(0 - partOffset, 10);
if(isMouseInside(mouseX, mouseY, x+width-60, y+140+offset, x+width-40, y+160+offset) && mouseButton == 0 && m.doesHaveSetting()){
for(Setting s : m.settings){
if(s instanceof BooleanSetting){
comps.add(new CompCheck(4, 4, selectedMod, s));
}
}
}
offset += 80;
}
} }
if(selectedMod != null){ if (isMouseInside(mouseX, mouseY, x + width - 300, y + 25, x + width - 50, y + 65)) {
for(Comp c : comps){ isSearchFocused = true;
} else {
isSearchFocused = false;
}
int offset = 0;
for (Mod m: Resent.INSTANCE.modManager.modules) {
if (!m.isAdmin()) {
if (isMouseInside(mouseX, mouseY, x + width - 60, y + 140 + offset, x + width - 40, y + 160 + offset) && mouseButton == 0 && m.doesHaveSetting()) {
for (Setting s: m.settings) {
if (s instanceof BooleanSetting) {
comps.add(new CompCheck(4, 4, selectedMod, s));
}
}
}
offset += 80;
}
}
if (selectedMod != null) {
for (Comp c: comps) {
c.mouseClicked(mouseX, mouseY, mouseButton); c.mouseClicked(mouseX, mouseY, mouseButton);
} }
} }
@ -207,11 +201,11 @@ public class ClickGuiRewrite extends GuiScreen{
@Override @Override
public void initGui() { public void initGui() {
sr = new ScaledResolution(mc); sr = new ScaledResolution(mc);
x = sr.getScaledWidth()/10; x = sr.getScaledWidth() / 10;
y = sr.getScaledHeight()/10; y = sr.getScaledHeight() / 10;
width = sr.getScaledWidth()/1.25f; width = sr.getScaledWidth() / 1.25F;
height = sr.getScaledHeight()/1.25f; height = sr.getScaledHeight() / 1.25F;
introAnimation = Theme.getAnimation(500, 1, 3, 3.8f, 1.35f, false); introAnimation = Theme.getAnimation(500, 1, 3, 3.8F, 1.35F, false);
fr = mc.fontRendererObj; fr = mc.fontRendererObj;
} }
@ -220,51 +214,47 @@ public class ClickGuiRewrite extends GuiScreen{
if (key == 0x01 || key == Minecraft.getMinecraft().gameSettings.keyBindClickGui.keyCode) { if (key == 0x01 || key == Minecraft.getMinecraft().gameSettings.keyBindClickGui.keyCode) {
closing = true; closing = true;
} }
if (isSearchFocused) {
if(selectedMod != null){ if (selectedMod != null) {
for(Comp c : comps){ for (Comp c: comps) {
c.keyTyped(par1, key); c.keyTyped(par1, key);
} }
} }
// Search box stuff // Search box stuff
else if(key == KeyboardConstants.KEY_BACK) { else if (key == KeyboardConstants.KEY_BACK && isSearchFocused) {
if(searchString.length() != 0) { if (searchString.length() != 0) {
searchString = searchString.substring(0, searchString.length()-1); searchString = searchString.substring(0, searchString.length() - 1);
} }
}else { } else {
if(searchString.length() <= 18) { if (searchString.length() <= 18 && isSearchFocused) {
String balls = ChatAllowedCharacters.filterAllowedCharacters(String.valueOf(par1)); String balls = ChatAllowedCharacters.filterAllowedCharacters(String.valueOf(par1));
if(balls != null && balls != "") { if (balls != null && balls != "") {
searchString += String.valueOf(par1); searchString += String.valueOf(par1);
scrollOffset = 0; scrollOffset = 0;
} }
} }
}
} }
} }
@Override @Override
public void handleMouseInput() throws IOException { public void handleMouseInput() throws IOException {
int scroll = Mouse.getEventDWheel(); int scroll = Mouse.getEventDWheel();
if(scroll > 0) {
scrollOffset = MathHelper.clamp_int(scrollOffset+80, getMaxScroll(), 0);
}else if(scroll < 0) {
scrollOffset = MathHelper.clamp_int(scrollOffset-80, getMaxScroll(), 0);
}
super.handleMouseInput();
}
public boolean isMouseInside(double mouseX, double mouseY, double x, double y, double width, double height) { if (scroll > 0) {
scrollOffset = MathHelper.clamp_int(scrollOffset + 80, getMaxScroll(), 0);
} else if (scroll < 0) {
scrollOffset = MathHelper.clamp_int(scrollOffset - 80, getMaxScroll(), 0);
}
super.handleMouseInput();
}
public boolean isMouseInside(double mouseX, double mouseY, double x, double y, double width, double height) {
return (mouseX >= x && mouseX <= width) && (mouseY >= y && mouseY <= height); return (mouseX >= x && mouseX <= width) && (mouseY >= y && mouseY <= height);
} }
public int getMaxScroll() { public int getMaxScroll() {
return Resent.INSTANCE.modManager.modules.size() * -68; return Resent.INSTANCE.modManager.modules.size() * -69;
} }
}
}