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.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.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 net.lax1dude.eaglercraft.v1_8.Mouse;
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.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
@ -33,171 +29,169 @@ import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
public class ClickGuiRewrite extends GuiScreen{
public class ClickGuiRewrite extends GuiScreen {
public FontRenderer fr;
public ArrayList<Comp> comps = new ArrayList<>();
public FontRenderer fr;
public ArrayList < Comp > comps = new ArrayList < > ();
public float x, y, width, height;
public Animation introAnimation;
public ScaledResolution sr;
public boolean closing;
public boolean closing, isSearchFocused;
public Mod selectedMod;
public String searchString = "";
public SimpleAnimation partAnimation = new SimpleAnimation(0);
public int backgroundColor = new Color(18, 18, 18).getRGB(),
primaryColor = 0xFF000000,
secondaryColor = new Color(33, 33, 33).getRGB(),
onSurfaceColor = new Color(3, 218, 197).getRGB(),
secondaryFontColor = new Color(187, 134, 252).getRGB();
primaryColor = 0xFF000000,
secondaryColor = new Color(33, 33, 33).getRGB(),
onSurfaceColor = new Color(3, 218, 197).getRGB(),
secondaryFontColor = new Color(187, 134, 252).getRGB();
public int partOffset = 0, scrollOffset = 0;
public String part = "Home";
private boolean isSearchFocused = false;
@Override
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);
//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
RenderUtils.drawRoundedRect(x+60, y, x+width, y+height, 32, backgroundColor);
Gui.drawRect(x+60, y, x+102, y+height, backgroundColor);
RenderUtils.drawRoundedRect(x + 60, y, x + width, y + height, 32, backgroundColor);
Gui.drawRect(x + 60, y, x + 102, y + height, backgroundColor);
//Separating line
Gui.drawRect(x, y+90, x+width, y+95, secondaryColor);
Gui.drawRect(x, y + 90, x + width, y + 95, secondaryColor);
//Title
GlStateManager.pushMatrix();
GlStateManager.translate(x+80, y+36, 0);
GlStateManager.scale(3.5f, 3.5f, 1);
GlStateManager.translate(-(x+80), -(y+36), 0);
fr.drawString("Resent", x+80, y+36, -1, false);
GlStateManager.translate(x + 80, y + 36, 0);
GlStateManager.scale(3.5F, 3.5F, 1);
GlStateManager.translate(-(x + 80), -(y + 36), 0);
fr.drawString("Resent", x + 80, y + 36, -1, false);
GlStateManager.popMatrix();
//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
GlStateManager.color(1, 1, 1);
GlStateManager.color(1, 1, 1);
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"));
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
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.translate(x+width-290, y+40, 0);
GlStateManager.scale(1.5f, 1.5f, 1);
GlStateManager.translate(-(x+width-290), -(y+40), 0);
if(searchString.length() > 0) {
fr.drawString(searchString, x+width-290, y+40, secondaryFontColor, false);
}else if (!isSearchFocused) {
fr.drawString(EnumChatFormatting.ITALIC + "Search" + EnumChatFormatting.RESET, x+width-290, y+40, new Color(97, 97, 97).getRGB(), false);
GlStateManager.translate(x + width - 290, y + 40, 0);
GlStateManager.scale(1.5F, 1.5F, 1);
GlStateManager.translate(-(x + width - 290), -(y + 40), 0);
if (searchString.length() > 0) {
fr.drawString(searchString, x + width - 290, y + 40, secondaryFontColor, false);
} else {
fr.drawString(EnumChatFormatting.ITALIC + "Search", x + width - 290, y + 40, new Color(97, 97, 97).getRGB(), false);
}
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();
//Draw module button
for(Mod m : Resent.INSTANCE.modManager.modules){
if(!m.isAdmin() && m.getName().toLowerCase().startsWith(searchString.toLowerCase()) && selectedMod == null) {
if(y+115+offset+scrollOffset > y+95 && y+185+offset+scrollOffset < y+height) {
//Body
RenderUtils.drawRoundedRect(x+80, y+115+offset+scrollOffset, x+width-20, y+185+offset+scrollOffset, 16, secondaryColor);
//Gear
if(m.doesHaveSetting()) {
GlStateManager.color(1, 1, 1);
mc.getTextureManager().bindTexture(new ResourceLocation("/resent/gear.png"));
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);
//Toggle
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);
fr.drawString(m.getName(), x+120, y+140+offset+scrollOffset, -1, false);
GlStateManager.popMatrix();
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);
}
}
offset += 80;
}
for (Mod m: Resent.INSTANCE.modManager.modules) {
if (!m.isAdmin() && m.getName().toLowerCase().startsWith(searchString.toLowerCase()) && selectedMod == null) {
if (y + 115 + offset + scrollOffset > y + 95 && y + 185 + offset + scrollOffset < y + height) {
//Body
RenderUtils.drawRoundedRect(x + 80, y + 115 + offset + scrollOffset, x + width - 20, y + 185 + offset + scrollOffset, 16, secondaryColor);
//Gear
if (m.doesHaveSetting()) {
GlStateManager.color(1, 1, 1);
mc.getTextureManager().bindTexture(new ResourceLocation("/resent/gear.png"));
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);
//Toggle
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);
fr.drawString(m.getName(), x + 120, y + 140 + offset + scrollOffset, -1, false);
GlStateManager.popMatrix();
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);
}
}
offset += 80;
}
}
GlStateManager.popMatrix();
if(selectedMod != null){
for (Comp comp : comps) {
if (selectedMod != null) {
for (Comp comp: comps) {
comp.drawScreen(mouseX, mouseY);
}
}
if (closing) {
comps.clear();
if(introAnimation == null) {
mc.displayGuiScreen(null);
return;
}
if (introAnimation == null) {
mc.displayGuiScreen(null);
return;
}
introAnimation.setDirection(Direction.BACKWARDS);
if (introAnimation.isDone(Direction.BACKWARDS)) {
mc.displayGuiScreen(null);
}
}
}
@Override
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;
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 (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(selectedMod != null){
for(Comp c : comps){
if (isMouseInside(mouseX, mouseY, x + width - 300, y + 25, x + width - 50, y + 65)) {
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);
}
}
@ -207,11 +201,11 @@ public class ClickGuiRewrite extends GuiScreen{
@Override
public void initGui() {
sr = new ScaledResolution(mc);
x = sr.getScaledWidth()/10;
y = sr.getScaledHeight()/10;
width = sr.getScaledWidth()/1.25f;
height = sr.getScaledHeight()/1.25f;
introAnimation = Theme.getAnimation(500, 1, 3, 3.8f, 1.35f, false);
x = sr.getScaledWidth() / 10;
y = sr.getScaledHeight() / 10;
width = sr.getScaledWidth() / 1.25F;
height = sr.getScaledHeight() / 1.25F;
introAnimation = Theme.getAnimation(500, 1, 3, 3.8F, 1.35F, false);
fr = mc.fontRendererObj;
}
@ -220,51 +214,47 @@ public class ClickGuiRewrite extends GuiScreen{
if (key == 0x01 || key == Minecraft.getMinecraft().gameSettings.keyBindClickGui.keyCode) {
closing = true;
}
if (isSearchFocused) {
if(selectedMod != null){
for(Comp c : comps){
c.keyTyped(par1, key);
}
}
// Search box stuff
else if(key == KeyboardConstants.KEY_BACK) {
if(searchString.length() != 0) {
searchString = searchString.substring(0, searchString.length()-1);
}
}else {
if(searchString.length() <= 18) {
String balls = ChatAllowedCharacters.filterAllowedCharacters(String.valueOf(par1));
if(balls != null && balls != "") {
searchString += String.valueOf(par1);
scrollOffset = 0;
}
}
}
if (selectedMod != null) {
for (Comp c: comps) {
c.keyTyped(par1, key);
}
}
// Search box stuff
else if (key == KeyboardConstants.KEY_BACK && isSearchFocused) {
if (searchString.length() != 0) {
searchString = searchString.substring(0, searchString.length() - 1);
}
} else {
if (searchString.length() <= 18 && isSearchFocused) {
String balls = ChatAllowedCharacters.filterAllowedCharacters(String.valueOf(par1));
if (balls != null && balls != "") {
searchString += String.valueOf(par1);
scrollOffset = 0;
}
}
}
}
@Override
public void handleMouseInput() throws IOException {
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 void handleMouseInput() throws IOException {
int scroll = Mouse.getEventDWheel();
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);
}
public int getMaxScroll() {
return Resent.INSTANCE.modManager.modules.size() * -68;
}
}
public int getMaxScroll() {
return Resent.INSTANCE.modManager.modules.size() * -69;
}
}