TerrificTable55

Untitled

Jun 1st, 2022
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.38 KB | None | 0 0
  1. package xyz.terrifictable.module.modules.client;
  2.  
  3. import net.minecraft.client.gui.Gui;
  4. import net.minecraft.client.gui.GuiScreen;
  5. import net.minecraft.client.gui.ScaledResolution;
  6. import org.lwjgl.input.Keyboard;
  7. import xyz.terrifictable.Client;
  8. import xyz.terrifictable.module.Module;
  9. import xyz.terrifictable.util.font.MinecraftFontRenderer;
  10.  
  11. import java.io.IOException;
  12. import java.util.List;
  13.  
  14. public class ClickGuiRender extends GuiScreen {
  15.  
  16.     private ScaledResolution sr;
  17.     private MinecraftFontRenderer fr;
  18.  
  19.     public ClickGuiRender() { }
  20.  
  21.     public void onGuiClosed() {
  22.  
  23.         mc.displayGuiScreen(Client.getClickgui());
  24.  
  25.     }
  26.  
  27.     @Override
  28.     public void drawScreen(int mouseX, int mouseY, float partialTicks) {
  29.         super.drawScreen(mouseX, mouseY, partialTicks);
  30.  
  31.  
  32.         sr = new ScaledResolution(mc);
  33.         fr = Client.fr;
  34.  
  35.         int categoryIndex = 0;
  36.  
  37.         for (Module.Category category : Module.getCategorys()) {
  38.             int moduleIndex = 0;
  39.  
  40.  
  41.             // === MODULES ===
  42.             List<Module> modules = Client.getModulesByCategory(category);
  43.  
  44.             // === biggest module length ===
  45.             int maxLen_m = 0;
  46.             for (Module module : modules) {
  47.                 if (!module.name.equalsIgnoreCase("save")) {
  48.                     if (fr.getStringWidth(module.name) > maxLen_m) {
  49.                         maxLen_m = mc.fontRendererObj.getStringWidth(module.name);
  50.                     }
  51.                 }
  52.             }
  53.             // === biggest module length ===
  54.  
  55.             // === CATEGORYS ===
  56.             Gui.drawRect(2 + categoryIndex * 80, 2, (categoryIndex * 80) + fr.getStringWidth(category.name) + maxLen_m - 20, mc.fontRendererObj.FONT_HEIGHT + 7, 0x90000000);
  57.             fr.drawString(category.name, 5 + categoryIndex * 80, 5, -1);
  58.             // === CATEGORYS ===
  59.  
  60.             // Draw modules box
  61.             Gui.drawRect(2 + categoryIndex * 80, 2 + mc.fontRendererObj.FONT_HEIGHT  + 7, (categoryIndex * 80) + fr.getStringWidth(category.name) + maxLen_m - 20, (modules.size() * 12) + mc.fontRendererObj.FONT_HEIGHT + 9, 0x90000000);
  62.  
  63.             // Cycle through modules
  64.             for (Module module : Client.getModulesByCategory(category)) {
  65.                 if (!module.name.equalsIgnoreCase("save")) {
  66.                     fr.drawString(module.name, 5 + categoryIndex * 80, (moduleIndex * 12) + 20, -1); // Draw module name
  67.                     if (module.isToggled() || module.name.equalsIgnoreCase("clickgui")) {
  68.                         fr.drawString(module.name, 5 + categoryIndex * 80, (moduleIndex * 12) + 20, 0xff00ff00); // Color name green if toggled
  69.                     }
  70.  
  71.                     if (isInside(mouseX, mouseY, // check if mouse is above current module
  72.                             2 + categoryIndex * 80,
  73.                             moduleIndex * 12 + 20,
  74.                             (categoryIndex * 80) + fr.getStringWidth(category.name) + maxLen_m - 20,
  75.                             moduleIndex * 12 + 20 + mc.fontRendererObj.FONT_HEIGHT
  76.                     )) { fr.drawString(module.name, 5 + categoryIndex * 80, (moduleIndex * 12) + 20, 0xff00eeff); } // color light blue if hovered
  77.                     moduleIndex++;
  78.                 }
  79.             }
  80.  
  81.             categoryIndex++;
  82.         }
  83.     }
  84.  
  85.     @Override
  86.     protected void keyTyped(char typedChar, int keyCode) throws IOException {
  87.         // if (keyCode == Keyboard.KEY_ESCAPE) return;
  88.  
  89.         super.keyTyped(typedChar, keyCode);
  90.     }
  91.  
  92.     @Override
  93.     protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
  94.         super.mouseClicked(mouseX, mouseY, mouseButton);
  95.  
  96.         int categoryIndex = 0;
  97.         for (Module.Category category : Module.getCategorys()) { // Cycle trough Categorys
  98.             // === Longest module name ===
  99.             int maxLen_m = 0;
  100.             for (Module module : Client.getModulesByCategory(category)) {
  101.                 if (fr.getStringWidth(module.name) > maxLen_m) {
  102.                     maxLen_m = mc.fontRendererObj.getStringWidth(module.name);
  103.                 }
  104.             }
  105.             // === Longest module name ===
  106.  
  107.             // === Get which module is clicked on ===
  108.             int moduleIndex = 0;
  109.             for (Module module : Client.getModulesByCategory(category)) { // Cycle trough modules
  110.                 // Check if current module is clicked on
  111.                 if (mouseButton == 0 && isInside(mouseX,
  112.                         mouseY,
  113.                         2 + categoryIndex * 80,
  114.                         moduleIndex * 12 + 20,
  115.                         (categoryIndex * 80) + fr.getStringWidth(category.name) + maxLen_m - 20,
  116.                         (moduleIndex * 12 + 20) + mc.fontRendererObj.FONT_HEIGHT
  117.                 )) { module.toggle(); /* Toggle module */  }
  118.                 moduleIndex++;
  119.             }
  120.             // === Get which module is clicked on ===
  121.             categoryIndex++;
  122.         }
  123.     }
  124.  
  125.     @Override
  126.     protected void mouseReleased(int mouseX, int mouseY, int state) {
  127.         super.mouseReleased(mouseX, mouseY, state);
  128.     }
  129.  
  130.     @Override
  131.     public void initGui() {
  132.         super.initGui();
  133.     }
  134.  
  135.     public boolean isInside(int mouseX, int mouseY, double x, double y, double width, double height) {
  136.         return ((mouseX > x && mouseX < width) && (mouseY > y && mouseY < height));
  137.     }
  138. }
  139.  
Advertisement
Add Comment
Please, Sign In to add comment