| 1 | /*
|
| 2 | * This file is part of the Combatant Client distribution.
|
| 3 | * Copyright (c) 2026 pivosos2007.
|
| 4 | *
|
| 5 | * Licensed under the GNU General Public License v3.0.
|
| 6 | */
|
| 7 |
|
| 8 | package combatant.client.features.gui.clickgui;
|
| 9 |
|
| 10 | import combatant.client.render.engine.text.BuiltinFontCatalog;
|
| 11 | import combatant.client.addon.ClickGuiSectionManager;
|
| 12 | import combatant.client.features.gui.clickgui.settings.*;
|
| 13 | import combatant.client.render.engine.math.HudScale;
|
| 14 | import combatant.client.render.engine.renderer.RenderWarpStack;
|
| 15 | import combatant.client.util.screen.ClientScreen;
|
| 16 | import net.minecraft.client.Minecraft;
|
| 17 | import net.minecraft.client.gui.GuiGraphicsExtractor;
|
| 18 | import net.minecraft.util.StringUtil;
|
| 19 | import net.minecraft.world.item.ItemStack;
|
| 20 | import org.lwjgl.glfw.GLFW;
|
| 21 | import combatant.client.config.ConfigSerializer;
|
| 22 | import combatant.client.features.gui.clickgui.editor.ClickGuiTextEditorState;
|
| 23 | import combatant.client.features.gui.clickgui.picker.ClickGuiPickerState;
|
| 24 | import combatant.client.features.gui.clickgui.protocol.CombatProtocolHeuristicsEditorState;
|
| 25 | import combatant.client.features.gui.clickgui.sections.ClickGuiSection;
|
| 26 | import combatant.client.features.gui.clickgui.sections.settings.SettingsTabRuntime;
|
| 27 | import combatant.client.features.gui.hud.draggable.DraggableHudElementRegistry;
|
| 28 | import combatant.client.features.gui.hud.nondraggable.impl.DynamicIsland;
|
| 29 | import combatant.client.features.module.ModuleManager;
|
| 30 | import combatant.client.mixininterface.IGuiGraphics;
|
| 31 | import combatant.client.render.engine.animation.AnimationUtility;
|
| 32 | import combatant.client.render.engine.color.RenderColor;
|
| 33 | import combatant.client.render.engine.core.CombatantRenderSystem;
|
| 34 | import combatant.client.render.engine.core.RenderPhase;
|
| 35 | import combatant.client.render.engine.core.RenderPhaseScope;
|
| 36 | import combatant.client.render.engine.core.ViewportContext;
|
| 37 | import combatant.client.render.engine.profiler.ProfilerPhase;
|
| 38 | import combatant.client.render.engine.profiler.RenderProfiler2D;
|
| 39 | import combatant.client.render.engine.profiler.TracyGpuProfiler;
|
| 40 | import combatant.client.render.engine.renderer.Renderer2D;
|
| 41 | import combatant.client.render.engine.renderer.ui.draw.UiMeshGeometry;
|
| 42 | import combatant.client.render.engine.text.Fonts;
|
| 43 | import combatant.client.render.engine.text.TextRenderer;
|
| 44 | import combatant.client.render.engine.text.TextSizing;
|
| 45 | import combatant.client.render.helpers.ScissorFunction;
|
| 46 | import combatant.client.render.helpers.SystemCursor;
|
| 47 | import combatant.client.util.input.KeyUtil;
|
| 48 | import combatant.client.util.text.ClipboardUtil;
|
| 49 | import combatant.client.features.gui.clickgui.sound.GuiSound;
|
| 50 |
|
| 51 | import java.nio.file.Path;
|
| 52 | import java.util.*;
|
| 53 | import java.util.concurrent.CompletableFuture;
|
| 54 |
|
| 55 | import static combatant.client.features.theme.Theme.theme;
|
| 56 |
|
| 57 | public enum ClickGuiRenderer {
|
| 58 | ;
|
| 59 |
|
| 60 | private static final Minecraft MC = Minecraft.getInstance();
|
| 61 | private static final String MODULES_TAB_ID = "combatant:modules";
|
| 62 | private static final String SETTINGS_TAB_ID = "combatant:settings";
|
| 63 | private static final String MAP_TAB_ID = "combatant:map";
|
| 64 | private static final float TAB_HEIGHT = 34f;
|
| 65 | private static final float TAB_GAP = 0f;
|
| 66 | private static final float TAB_PAD_X = 18f;
|
| 67 | private static final float TAB_FONT = 17f;
|
| 68 | private static final float TAB_MIN_W = 96f;
|
| 69 | private static float[] tabX = new float[0];
|
| 70 | private static float[] tabW = new float[0];
|
| 71 | private static final float LIFECYCLE_OPEN_SPEED = 9.5f;
|
| 72 | private static final float LIFECYCLE_CLOSE_SPEED = 8.0f;
|
| 73 | private static final float INPUT_READY_PROGRESS = 0.72f;
|
| 74 | private static final Set<Integer> pendingBindKeys = new LinkedHashSet<>();
|
| 75 | private static final List<PickerIcon> pickerIcons = new ArrayList<>();
|
| 76 | private static final java.util.ArrayList<TextBatchItem> TEXT_BATCH = new java.util.ArrayList<>();
|
| 77 | private static final int TEXT_WIDTH_CACHE_LIMIT = 4096;
|
| 78 | private static final int TEXT_HEIGHT_CACHE_LIMIT = 256;
|
| 79 | private static final Map<TextMeasureKey, Float> TEXT_WIDTH_CACHE = new LinkedHashMap<>(512, 0.75f, true) {
|
| 80 | @Override
|
| 81 | protected boolean removeEldestEntry(Map.Entry<TextMeasureKey, Float> eldest) {
|
| 82 | return size() > TEXT_WIDTH_CACHE_LIMIT;
|
| 83 | }
|
| 84 | };
|
| 85 | private static final Map<TextHeightKey, Float> TEXT_HEIGHT_CACHE = new LinkedHashMap<>(64, 0.75f, true) {
|
| 86 | @Override
|
| 87 | protected boolean removeEldestEntry(Map.Entry<TextHeightKey, Float> eldest) {
|
| 88 | return size() > TEXT_HEIGHT_CACHE_LIMIT;
|
| 89 | }
|
| 90 | };
|
| 91 | public static boolean waitingForKey = false;
|
| 92 | public static Object keyBindOwner = null;
|
| 93 | private static int colorClipboard = 0xFFFFFFFF;
|
| 94 | private static boolean init = false;
|
| 95 | private static float mouseX, mouseY;
|
| 96 | private static boolean cursorShown = false;
|
| 97 | private static int fbWidth, fbHeight;
|
| 98 | private static TextRenderer interRegular;
|
| 99 | private static TextRenderer interMedium;
|
| 100 | private static TextRenderer onestMedium;
|
| 101 | private static TextRenderer onestBold;
|
| 102 | private static TextRenderer monsterratRegular;
|
| 103 | private static long boundFontGeneration = Long.MIN_VALUE;
|
| 104 | private static String activeTabId = MODULES_TAB_ID;
|
| 105 | private static float tabBarX, tabBarY, tabBarW, tabBarH;
|
| 106 | private static float tabTargetX, tabTargetW;
|
| 107 | private static float tabAnimX, tabAnimW;
|
| 108 | private static boolean tabAnimInit = false;
|
| 109 | private static long lastTabAnimNs = System.nanoTime();
|
| 110 | private static float lifecycleAnim = 0.0f;
|
| 111 | private static boolean closingForExit = false;
|
| 112 | private static boolean finishingClose = false;
|
| 113 | private static long lastLifecycleAnimNs = System.nanoTime();
|
| 114 | private static float modulesAreaX, modulesAreaY, modulesAreaW, modulesAreaH;
|
| 115 | private static CompletableFuture<Void> pendingSaveTask;
|
| 116 | private static ClickGuiTextEditorState textEditor = null;
|
| 117 | private static ClickGuiPickerState picker = null;
|
| 118 | private static CombatProtocolHeuristicsEditorState protocolHeuristicsEditor = null;
|
| 119 | private static TextSetting inlineTextOwner = null;
|
| 120 | private static StringBuilder inlineTextBuffer = null;
|
| 121 | private static float inlineTextX, inlineTextY, inlineTextW, inlineTextH;
|
| 122 | private static boolean pickerIconScissorActive = false;
|
| 123 | private static float pickerIconScissorX, pickerIconScissorY, pickerIconScissorW, pickerIconScissorH;
|
| 124 | private static Renderer2D renderer;
|
| 125 | private static float renderAlphaMultiplier = 1.0f;
|
| 126 | private static boolean verticalAlphaFadeEnabled;
|
| 127 | private static float verticalAlphaFadeStart;
|
| 128 | private static float verticalAlphaFadeEnd;
|
| 129 | private static ClickGuiScreen mainScreen;
|
| 130 | private static ClickGuiPickerScreen pickerScreen;
|
| 131 | private static boolean textBatchActive;
|
| 132 |
|
| 133 | // =========================
|
| 134 | // API for MIXIN MOUSE
|
| 135 | // =========================
|
| 136 | public static void onMouseMove(double x, double y) {
|
| 137 | updateMouse(x, y, false);
|
| 138 | if (picker != null) {
|
| 139 | picker.handleMouseMove(mouseX, mouseY);
|
| 140 | }
|
| 141 | if (protocolHeuristicsEditor != null) {
|
| 142 | protocolHeuristicsEditor.handleMouseMove(mouseX, mouseY);
|
| 143 | }
|
| 144 | if (textEditor != null) {
|
| 145 | textEditor.handleMouseMove(mouseX, mouseY);
|
| 146 | }
|
| 147 | }
|
| 148 |
|
| 149 | public static void onMouseButton(double x, double y, int button, boolean pressed) {
|
| 150 | updateMouse(x, y, false);
|
| 151 | handleMouseButton(button, pressed);
|
| 152 | }
|
| 153 |
|
| 154 | public static void onMouseScroll(double x, double y, double delta) {
|
| 155 | updateMouse(x, y, false);
|
| 156 | handleMouseScroll(delta);
|
| 157 | }
|
| 158 |
|
| 159 | public static void onMouseMoveScaled(double x, double y) {
|
| 160 | updateMouse(x, y, true);
|
| 161 | if (picker != null) {
|
| 162 | picker.handleMouseMove(mouseX, mouseY);
|
| 163 | }
|
| 164 | if (protocolHeuristicsEditor != null) {
|
| 165 | protocolHeuristicsEditor.handleMouseMove(mouseX, mouseY);
|
| 166 | }
|
| 167 | if (textEditor != null) {
|
| 168 | textEditor.handleMouseMove(mouseX, mouseY);
|
| 169 | }
|
| 170 | }
|
| 171 |
|
| 172 | public static void onMouseButtonScaled(double x, double y, int button, boolean pressed) {
|
| 173 | updateMouse(x, y, true);
|
| 174 | handleMouseButton(button, pressed);
|
| 175 | }
|
| 176 |
|
| 177 | public static void onMouseScrollScaled(double x, double y, double delta) {
|
| 178 | updateMouse(x, y, true);
|
| 179 | handleMouseScroll(delta);
|
| 180 | }
|
| 181 |
|
| 182 | public static void onEditorMouseMoveScaled(double x, double y) {
|
| 183 | updateMouse(x, y, true);
|
| 184 | }
|
| 185 |
|
| 186 | public static void onEditorMouseButtonScaled(double x, double y, int button, boolean pressed) {
|
| 187 | updateMouse(x, y, true);
|
| 188 | if (waitingForKey) {
|
| 189 | if (pressed) addPendingMouseButton(button);
|
| 190 | return;
|
| 191 | }
|
| 192 | if (textEditor != null) {
|
| 193 | if (pressed) {
|
| 194 | textEditor.handleMouseDown(mouseX, mouseY, button);
|
| 195 | } else {
|
| 196 | textEditor.handleMouseUp(mouseX, mouseY, button);
|
| 197 | }
|
| 198 | return;
|
| 199 | }
|
| 200 | if (isSettingsTabActive()) {
|
| 201 | SettingsTabRuntime.handleEditorMouseButton(mouseX, mouseY, button, pressed);
|
| 202 | }
|
| 203 | }
|
| 204 |
|
| 205 | public static void onEditorMouseScrollScaled(double x, double y, double delta) {
|
| 206 | updateMouse(x, y, true);
|
| 207 | if (delta != 0.0) {
|
| 208 | GuiSound.SCROLL.feedback();
|
| 209 | }
|
| 210 | if (textEditor != null) {
|
| 211 | textEditor.scroll(delta);
|
| 212 | return;
|
| 213 | }
|
| 214 | if (isSettingsTabActive()) {
|
| 215 | SettingsTabRuntime.handleEditorMouseScroll(mouseX, mouseY, delta);
|
| 216 | }
|
| 217 | }
|
| 218 |
|
| 219 | public static boolean onEditorCharTyped(char c) {
|
| 220 | return onCharTyped(c);
|
| 221 | }
|
| 222 |
|
| 223 | public static boolean onEditorKey(int key, int scancode, int action, int mods) {
|
| 224 | return onKey(key, scancode, action, mods);
|
| 225 | }
|
| 226 |
|
| 227 | public static void closeGuiEditor() {
|
| 228 | SettingsTabRuntime.closeGuiEditor();
|
| 229 | }
|
| 230 |
|
| 231 | private static void handleMouseButton(int button, boolean pressed) {
|
| 232 | if (!isInputReady()) return;
|
| 233 | if (waitingForKey) {
|
| 234 | if (pressed) addPendingMouseButton(button);
|
| 235 | return;
|
| 236 | }
|
| 237 |
|
| 238 | if (textEditor != null) {
|
| 239 | if (pressed) {
|
| 240 | textEditor.handleMouseDown(mouseX, mouseY, button);
|
| 241 | } else {
|
| 242 | textEditor.handleMouseUp(mouseX, mouseY, button);
|
| 243 | }
|
| 244 | return;
|
| 245 | }
|
| 246 |
|
| 247 | if (protocolHeuristicsEditor != null) {
|
| 248 | if (pressed) {
|
| 249 | protocolHeuristicsEditor.handleMouseDown(mouseX, mouseY, button);
|
| 250 | } else {
|
| 251 | protocolHeuristicsEditor.handleMouseUp(mouseX, mouseY, button);
|
| 252 | }
|
| 253 | return;
|
| 254 | }
|
| 255 |
|
| 256 | if (pressed && handleTabClick(mouseX, mouseY)) {
|
| 257 | return;
|
| 258 | }
|
| 259 |
|
| 260 | if (picker != null) {
|
| 261 | if (pressed) {
|
| 262 | picker.handleMouseDown(mouseX, mouseY, button);
|
| 263 | } else {
|
| 264 | picker.handleMouseUp(mouseX, mouseY, button);
|
| 265 | }
|
| 266 | return;
|
| 267 | }
|
| 268 |
|
| 269 | if (!pressed) {
|
| 270 | getActiveSection().mouseReleased(mouseX, mouseY, button);
|
| 271 | return;
|
| 272 | }
|
| 273 |
|
| 274 | getActiveSection().mousePressed(mouseX, mouseY, button);
|
| 275 | }
|
| 276 |
|
| 277 | private static void handleMouseScroll(double delta) {
|
| 278 | if (!isInputReady()) return;
|
| 279 | if (delta != 0.0) {
|
| 280 | GuiSound.SCROLL.feedback();
|
| 281 | }
|
| 282 |
|
| 283 | if (textEditor != null) {
|
| 284 | textEditor.scroll(delta);
|
| 285 | return;
|
| 286 | }
|
| 287 |
|
| 288 | if (protocolHeuristicsEditor != null) {
|
| 289 | protocolHeuristicsEditor.scroll(delta);
|
| 290 | return;
|
| 291 | }
|
| 292 |
|
| 293 | if (picker != null) {
|
| 294 | picker.scroll(delta);
|
| 295 | return;
|
| 296 | }
|
| 297 |
|
| 298 | getActiveSection().mouseScrolled(mouseX, mouseY, delta);
|
| 299 | }
|
| 300 |
|
| 301 | private static void updateMouse(double x, double y, boolean fromScaledCoords) {
|
| 302 | if (MC == null || MC.getWindow() == null) {
|
| 303 | mouseX = (float) x;
|
| 304 | mouseY = (float) y;
|
| 305 | return;
|
| 306 | }
|
| 307 | if (fromScaledCoords) {
|
| 308 | double scaledW = MC.getWindow().getGuiScaledWidth();
|
| 309 | double scaledH = MC.getWindow().getGuiScaledHeight();
|
| 310 | double fbW = MC.getWindow().getWidth();
|
| 311 | double fbH = MC.getWindow().getHeight();
|
| 312 | double sx = scaledW > 0 ? fbW / scaledW : MC.getWindow().getGuiScale();
|
| 313 | double sy = scaledH > 0 ? fbH / scaledH : MC.getWindow().getGuiScale();
|
| 314 | double fbX = x * sx;
|
| 315 | double fbY = y * sy;
|
| 316 | float uiScale = HudScale.scale((int) fbW, (int) fbH);
|
| 317 | mouseX = (float) (fbX / uiScale);
|
| 318 | mouseY = (float) (fbY / uiScale);
|
| 319 | return;
|
| 320 | }
|
| 321 | double scale = MC.getWindow().getGuiScale();
|
| 322 | double fbW = MC.getWindow().getWidth();
|
| 323 | double fbH = MC.getWindow().getHeight();
|
| 324 | double fbX = x * scale;
|
| 325 | double fbY = y * scale;
|
| 326 | float uiScale = HudScale.scale((int) fbW, (int) fbH);
|
| 327 | mouseX = (float) (fbX / uiScale);
|
| 328 | mouseY = (float) (fbY / uiScale);
|
| 329 | }
|
| 330 |
|
| 331 | // =========================
|
| 332 | // API for MIXIN KEYBOARD
|
| 333 | // =========================
|
| 334 | public static boolean onCharTyped(char c) {
|
| 335 | if (!ModuleManager.isEnabled("clickgui")) return false;
|
| 336 | if (textEditor != null) {
|
| 337 | textEditor.insertChar(c);
|
| 338 | return true;
|
| 339 | }
|
| 340 | if (picker != null) {
|
| 341 | if (picker.isListening()) {
|
| 342 | picker.insertChar(c);
|
| 343 | return true;
|
| 344 | }
|
| 345 | return false;
|
| 346 | }
|
| 347 | if (protocolHeuristicsEditor != null) {
|
| 348 | return protocolHeuristicsEditor.charTyped(c);
|
| 349 | }
|
| 350 | if (inlineTextOwner != null && inlineTextBuffer != null) {
|
| 351 | if (StringUtil.isAllowedChatCharacter(c)) {
|
| 352 | inlineTextBuffer.append(c);
|
| 353 | return true;
|
| 354 | }
|
| 355 | return false;
|
| 356 | }
|
| 357 | return getActiveSection().charTyped(c, 0);
|
| 358 | }
|
| 359 |
|
| 360 | public static boolean onFilesDrop(List<Path> paths) {
|
| 361 | if (!ModuleManager.isEnabled("clickgui")) return false;
|
| 362 | if (textEditor != null || picker != null || protocolHeuristicsEditor != null) return false;
|
| 363 | return getActiveSection().onFilesDrop(paths);
|
| 364 | }
|
| 365 |
|
| 366 | public static boolean onKey(int key, int scancode, int action, int mods) {
|
| 367 | if (!ModuleManager.isEnabled("clickgui")) return false;
|
| 368 |
|
| 369 | if (textEditor != null) {
|
| 370 | if (action == GLFW.GLFW_PRESS || action == GLFW.GLFW_REPEAT) {
|
| 371 | boolean shift = (mods & GLFW.GLFW_MOD_SHIFT) != 0;
|
| 372 | boolean ctrl = (mods & GLFW.GLFW_MOD_CONTROL) != 0;
|
| 373 | switch (key) {
|
| 374 | case GLFW.GLFW_KEY_ESCAPE -> closeTextEditor(false);
|
| 375 | case GLFW.GLFW_KEY_ENTER, GLFW.GLFW_KEY_KP_ENTER -> textEditor.insertNewline();
|
| 376 | case GLFW.GLFW_KEY_BACKSPACE -> textEditor.backspace();
|
| 377 | case GLFW.GLFW_KEY_DELETE -> textEditor.deleteForward();
|
| 378 | case GLFW.GLFW_KEY_LEFT -> textEditor.moveCaret(-1, shift);
|
| 379 | case GLFW.GLFW_KEY_RIGHT -> textEditor.moveCaret(1, shift);
|
| 380 | case GLFW.GLFW_KEY_UP -> textEditor.moveCaretVertical(-1, shift);
|
| 381 | case GLFW.GLFW_KEY_DOWN -> textEditor.moveCaretVertical(1, shift);
|
| 382 | case GLFW.GLFW_KEY_HOME -> textEditor.moveCaretToStart(shift);
|
| 383 | case GLFW.GLFW_KEY_END -> textEditor.moveCaretToEnd(shift);
|
| 384 | default -> {
|
| 385 | if (key == GLFW.GLFW_KEY_V && ctrl) textEditor.pasteFromClipboard();
|
| 386 | if (key == GLFW.GLFW_KEY_C && ctrl) textEditor.copySelection();
|
| 387 | if (key == GLFW.GLFW_KEY_A && ctrl) textEditor.selectAll();
|
| 388 | }
|
| 389 | }
|
| 390 | }
|
| 391 | return true;
|
| 392 | }
|
| 393 |
|
| 394 | if (protocolHeuristicsEditor != null) {
|
| 395 | return protocolHeuristicsEditor.keyPressed(key, scancode, action, mods);
|
| 396 | }
|
| 397 |
|
| 398 | if (picker != null) {
|
| 399 | if (action == GLFW.GLFW_PRESS || action == GLFW.GLFW_REPEAT) {
|
| 400 | boolean ctrl = (mods & GLFW.GLFW_MOD_CONTROL) != 0;
|
| 401 | switch (key) {
|
| 402 | case GLFW.GLFW_KEY_ESCAPE -> closePicker();
|
| 403 | case GLFW.GLFW_KEY_ENTER, GLFW.GLFW_KEY_KP_ENTER -> picker.stopListening();
|
| 404 | case GLFW.GLFW_KEY_BACKSPACE -> picker.backspace();
|
| 405 | default -> {
|
| 406 | if (key == GLFW.GLFW_KEY_F && ctrl) picker.toggleListening();
|
| 407 | }
|
| 408 | }
|
| 409 | }
|
| 410 | return true;
|
| 411 | }
|
| 412 |
|
| 413 | if (inlineTextOwner != null && inlineTextBuffer != null) {
|
| 414 | if (action == GLFW.GLFW_PRESS || action == GLFW.GLFW_REPEAT) {
|
| 415 | boolean ctrl = (mods & GLFW.GLFW_MOD_CONTROL) != 0;
|
| 416 | switch (key) {
|
| 417 | case GLFW.GLFW_KEY_ESCAPE -> finishInlineText(false);
|
| 418 | case GLFW.GLFW_KEY_ENTER, GLFW.GLFW_KEY_KP_ENTER -> finishInlineText(true);
|
| 419 | case GLFW.GLFW_KEY_BACKSPACE, GLFW.GLFW_KEY_DELETE -> inlineBackspace();
|
| 420 | default -> {
|
| 421 | if (key == GLFW.GLFW_KEY_V && ctrl) inlinePaste();
|
| 422 | }
|
| 423 | }
|
| 424 | }
|
| 425 | return true;
|
| 426 | }
|
| 427 |
|
| 428 | if (waitingForKey) {
|
| 429 |
|
| 430 | if (key == GLFW.GLFW_KEY_ESCAPE) {
|
| 431 | submitKeySelection((String) null);
|
| 432 | finishKeyBind();
|
| 433 | return true;
|
| 434 | }
|
| 435 |
|
| 436 | if (action == GLFW.GLFW_PRESS) {
|
| 437 | if (key == GLFW.GLFW_KEY_ENTER || key == GLFW.GLFW_KEY_KP_ENTER) {
|
| 438 | submitKeySelection(pendingBindKeys);
|
| 439 | finishKeyBind();
|
| 440 | return true;
|
| 441 | }
|
| 442 |
|
| 443 | addPendingKey(key, scancode);
|
| 444 | }
|
| 445 |
|
| 446 | return true;
|
| 447 | }
|
| 448 |
|
| 449 | if (action == GLFW.GLFW_PRESS || action == GLFW.GLFW_REPEAT) {
|
| 450 | return getActiveSection().keyPressed(key, scancode, mods);
|
| 451 | }
|
| 452 | return false;
|
| 453 | }
|
| 454 |
|
| 455 | // =========================
|
| 456 | // INIT
|
| 457 | // =========================
|
| 458 | public static void init() {
|
| 459 | if (init) return;
|
| 460 | init = true;
|
| 461 | activeTabId = MODULES_TAB_ID;
|
| 462 | for (ClickGuiTabEntry tab : currentTabs()) {
|
| 463 | if (MODULES_TAB_ID.equals(tab.id())) {
|
| 464 | tab.section().onSelected();
|
| 465 | } else {
|
| 466 | tab.section().onDeselected();
|
| 467 | }
|
| 468 | }
|
| 469 | }
|
| 470 |
|
| 471 | public static void beginOpenAnimation() {
|
| 472 | init();
|
| 473 | closingForExit = false;
|
| 474 | finishingClose = false;
|
| 475 | lifecycleAnim = 0.0f;
|
| 476 | tabAnimInit = false;
|
| 477 | lastLifecycleAnimNs = System.nanoTime();
|
| 478 |
|
| 479 | ClickGuiSection active = getActiveSection();
|
| 480 | if (active != null && (MODULES_TAB_ID.equals(activeTabId) || SETTINGS_TAB_ID.equals(activeTabId))) {
|
| 481 | active.onDeselected();
|
| 482 | }
|
| 483 | if (active != null) active.onSelected();
|
| 484 | }
|
| 485 |
|
| 486 | public static void beginCloseAnimation() {
|
| 487 | if (finishingClose) return;
|
| 488 | init();
|
| 489 | closingForExit = true;
|
| 490 | lastLifecycleAnimNs = System.nanoTime();
|
| 491 | ClickGuiSearch.deactivate();
|
| 492 | closeTextEditor(false);
|
| 493 | clearInlineText();
|
| 494 | clearPicker();
|
| 495 | for (ClickGuiTabEntry tab : currentTabs()) {
|
| 496 | tab.section().onDeselected();
|
| 497 | }
|
| 498 | detachScreenForExitOverlay();
|
| 499 | releaseCursorForGameplay();
|
| 500 | }
|
| 501 |
|
| 502 | // =========================
|
| 503 | // CURSOR OPEN/CLOSE
|
| 504 | // =========================
|
| 505 |
|
| 506 | private static void detachScreenForExitOverlay() {
|
| 507 | if (MC == null) return;
|
| 508 | if (ClientScreen.current() instanceof ClickGuiScreen cs) {
|
| 509 | mainScreen = cs;
|
| 510 | }
|
| 511 | if (ClientScreen.current() instanceof ClickGuiScreen
|
| 512 | || ClientScreen.current() instanceof ClickGuiPickerScreen
|
| 513 | || ClientScreen.current() instanceof ClickGuiEditorScreen) {
|
| 514 | ClientScreen.show(MC, null);
|
| 515 | }
|
| 516 | }
|
| 517 |
|
| 518 | public static boolean isLifecycleActive() {
|
| 519 | return ModuleManager.isEnabled("clickgui") || closingForExit || lifecycleAnim > 0.001f;
|
| 520 | }
|
| 521 |
|
| 522 | public static boolean isClosingForExit() {
|
| 523 | return closingForExit;
|
| 524 | }
|
| 525 |
|
| 526 | /**
|
| 527 | * The Map section owns the entire viewport and renders from Xaero map data, not the live
|
| 528 | * GameRenderer world target. While it is the active main ClickGUI section there is no reason
|
| 529 | * to submit the 3D world or Combatant HUD layers hidden behind it.
|
| 530 | */
|
| 531 | public static boolean suppressesBackgroundRendering() {
|
| 532 | return MC != null
|
| 533 | && ClientScreen.current() instanceof ClickGuiScreen
|
| 534 | && MAP_TAB_ID.equals(activeTabId)
|
| 535 | && !closingForExit
|
| 536 | && lifecycleAnim > 0.001f;
|
| 537 | }
|
| 538 |
|
| 539 | private static boolean isInputReady() {
|
| 540 | return ModuleManager.isEnabled("clickgui") && !closingForExit && lifecycleAnim >= INPUT_READY_PROGRESS;
|
| 541 | }
|
| 542 |
|
| 543 | public static void finishCloseImmediately() {
|
| 544 | closingForExit = false;
|
| 545 | lifecycleAnim = 0.0f;
|
| 546 | onClose();
|
| 547 | clearScreens();
|
| 548 | }
|
| 549 |
|
| 550 | public static void onClose() {
|
| 551 | if (!cursorShown) return;
|
| 552 | long handle = MC.getWindow().handle();
|
| 553 |
|
| 554 | GLFW.glfwSetInputMode(handle, GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_DISABLED);
|
| 555 | SystemCursor.invalidate();
|
| 556 | cursorShown = false;
|
| 557 | DraggableHudElementRegistry.setForceVisible(false);
|
| 558 | ClickGuiSearch.deactivate();
|
| 559 | closeTextEditor(false);
|
| 560 | clearInlineText();
|
| 561 | clearPicker();
|
| 562 |
|
| 563 | requestConfigSave();
|
| 564 | }
|
| 565 |
|
| 566 | public static void releaseCursorForGameplay() {
|
| 567 | if (MC == null || MC.getWindow() == null) return;
|
| 568 | if (ClientScreen.current() == null) {
|
| 569 | try {
|
| 570 | MC.mouseHandler.grabMouse();
|
| 571 | SystemCursor.invalidate();
|
| 572 | } catch (Throwable ignored) {
|
| 573 | GLFW.glfwSetInputMode(MC.getWindow().handle(), GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_DISABLED);
|
| 574 | SystemCursor.invalidate();
|
| 575 | }
|
| 576 | } else {
|
| 577 | GLFW.glfwSetInputMode(MC.getWindow().handle(), GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_DISABLED);
|
| 578 | SystemCursor.invalidate();
|
| 579 | }
|
| 580 | cursorShown = false;
|
| 581 | DraggableHudElementRegistry.setForceVisible(false);
|
| 582 | }
|
| 583 |
|
| 584 | public static void ensureCursorShown() {
|
| 585 | if (cursorShown) return;
|
| 586 | if (MC == null || MC.getWindow() == null) return;
|
| 587 | GLFW.glfwSetInputMode(
|
| 588 | MC.getWindow().handle(),
|
| 589 | GLFW.GLFW_CURSOR,
|
| 590 | GLFW.GLFW_CURSOR_NORMAL
|
| 591 | );
|
| 592 | SystemCursor.invalidate();
|
| 593 | cursorShown = true;
|
| 594 | }
|
| 595 |
|
| 596 | public static void renderEngine(Renderer2D rendererIn, TextRenderer fallback, GuiGraphicsExtractor ctx, float tickDelta) {
|
| 597 | try (ProfilerPhase.Scope frameScope = ProfilerPhase.scope("2d:clickgui:render");
|
| 598 | RenderProfiler2D.Section ignoredFrame = RenderProfiler2D.section("render")) {
|
| 599 | boolean enabled = ModuleManager.isEnabled("clickgui");
|
| 600 | long now = System.nanoTime();
|
| 601 | boolean mainScreenActive = ClientScreen.current() instanceof ClickGuiScreen;
|
| 602 | boolean pickerScreenActive = ClientScreen.current() instanceof ClickGuiPickerScreen;
|
| 603 |
|
| 604 | if (!enabled && !closingForExit && lifecycleAnim <= 0.001f) {
|
| 605 | ClickGuiRenderer.onClose();
|
| 606 | return;
|
| 607 | }
|
| 608 |
|
| 609 | if (ClientScreen.current() != null && !mainScreenActive && !pickerScreenActive) {
|
| 610 | if (closingForExit) finishCloseImmediately();
|
| 611 | return;
|
| 612 | }
|
| 613 | // Screen renders ClickGUI directly; no extra gating needed here.
|
| 614 |
|
| 615 | init();
|
| 616 | if (enabled && closingForExit) {
|
| 617 | closingForExit = false;
|
| 618 | getActiveSection().onSelected();
|
| 619 | }
|
| 620 | updateLifecycleAnim(now, enabled && !closingForExit);
|
| 621 | renderer = rendererIn;
|
| 622 | pickerIcons.clear();
|
| 623 |
|
| 624 | SystemCursor.beginFrame(ctx);
|
| 625 | try {
|
| 626 | if (enabled && !closingForExit && !cursorShown) {
|
| 627 | GLFW.glfwSetInputMode(
|
| 628 | MC.getWindow().handle(),
|
| 629 | GLFW.GLFW_CURSOR,
|
| 630 | GLFW.GLFW_CURSOR_NORMAL
|
| 631 | );
|
| 632 | SystemCursor.invalidate();
|
| 633 | cursorShown = true;
|
| 634 | }
|
| 635 | int fbw = MC.getWindow().getWidth();
|
| 636 | int fbh = MC.getWindow().getHeight();
|
| 637 | int vw = Math.max(1, Math.round(HudScale.virtualWidth(fbw, fbh)));
|
| 638 | int vh = Math.max(1, Math.round(HudScale.virtualHeight(fbw, fbh)));
|
| 639 | fbWidth = vw;
|
| 640 | fbHeight = vh;
|
| 641 |
|
| 642 | try (ProfilerPhase.Scope layoutScope = ProfilerPhase.scope("2d:clickgui:layout");
|
| 643 | RenderProfiler2D.Section ignoredLayout = RenderProfiler2D.section("layout");
|
| 644 | TracyGpuProfiler.Scope gpuScope = TracyGpuProfiler.beginZone("2d:clickgui:layout")) {
|
| 645 | layout(vw, vh);
|
| 646 | updateTabAnim(now);
|
| 647 | }
|
| 648 |
|
| 649 | if (pickerScreenActive) {
|
| 650 | try (ProfilerPhase.Scope pickerScope = ProfilerPhase.scope("2d:clickgui:modal");
|
| 651 | RenderProfiler2D.Section ignoredPicker = RenderProfiler2D.section("modal");
|
| 652 | TracyGpuProfiler.Scope gpuScope = TracyGpuProfiler.beginZone("2d:clickgui:modal")) {
|
| 653 | if (protocolHeuristicsEditor != null) {
|
| 654 | protocolHeuristicsEditor.render(vw, vh);
|
| 655 | } else {
|
| 656 | renderPicker(vw, vh);
|
| 657 | }
|
| 658 | }
|
| 659 | try (ProfilerPhase.Scope textEditorScope = ProfilerPhase.scope("2d:clickgui:text_editor");
|
| 660 | RenderProfiler2D.Section ignoredTextEditor = RenderProfiler2D.section("text_editor");
|
| 661 | TracyGpuProfiler.Scope gpuScope = TracyGpuProfiler.beginZone("2d:clickgui:text_editor")) {
|
| 662 | if (!closingForExit) {
|
| 663 | renderTextEditor(vw, vh);
|
| 664 | }
|
| 665 | }
|
| 666 | return;
|
| 667 | }
|
| 668 |
|
| 669 | try (ProfilerPhase.Scope sectionScope = ProfilerPhase.scope("2d:clickgui:section");
|
| 670 | RenderProfiler2D.Section ignoredSection = RenderProfiler2D.section("section");
|
| 671 | TracyGpuProfiler.Scope gpuScope = TracyGpuProfiler.beginZone("2d:clickgui:section")) {
|
| 672 | getActiveSection().render(mouseX, mouseY);
|
| 673 | }
|
| 674 | try (ProfilerPhase.Scope tabsScope = ProfilerPhase.scope("2d:clickgui:tabs");
|
| 675 | RenderProfiler2D.Section ignoredTabs = RenderProfiler2D.section("tabs");
|
| 676 | TracyGpuProfiler.Scope gpuScope = TracyGpuProfiler.beginZone("2d:clickgui:tabs")) {
|
| 677 | drawTabs();
|
| 678 | }
|
| 679 | try (ProfilerPhase.Scope textEditorScope = ProfilerPhase.scope("2d:clickgui:text_editor");
|
| 680 | RenderProfiler2D.Section ignoredTextEditor = RenderProfiler2D.section("text_editor");
|
| 681 | TracyGpuProfiler.Scope gpuScope = TracyGpuProfiler.beginZone("2d:clickgui:text_editor")) {
|
| 682 | if (!closingForExit) {
|
| 683 | renderTextEditor(vw, vh);
|
| 684 | }
|
| 685 | }
|
| 686 |
|
| 687 | if (closingForExit && lifecycleAnim <= 0.001f && sectionsClosed()) {
|
| 688 | completeCloseAnimation();
|
| 689 | }
|
| 690 | } finally {
|
| 691 | SystemCursor.endFrame();
|
| 692 | }
|
| 693 | }
|
| 694 | }
|
| 695 |
|
| 696 | public static boolean shouldRenderAsTopLayer() {
|
| 697 | return MC != null && (ClientScreen.current() instanceof ClickGuiPickerScreen
|
| 698 | || ClientScreen.current() instanceof ClickGuiEditorScreen);
|
| 699 | }
|
| 700 |
|
| 701 | public static void renderScreen(GuiGraphicsExtractor ctx, float tickDelta) {
|
| 702 | if (!(ClientScreen.current() instanceof ClickGuiScreen)) return;
|
| 703 |
|
| 704 | CombatantRenderSystem.ensureFrameContext();
|
| 705 | ViewportContext.beginCurrentStratumUnscaledLogical(ctx);
|
| 706 | try {
|
| 707 | Renderer2D.COLOR.begin();
|
| 708 | renderEngine(Renderer2D.COLOR, TextRenderer.get(), ctx, tickDelta);
|
| 709 | DynamicIsland.renderClickGuiShell(
|
| 710 | Renderer2D.COLOR,
|
| 711 | TextRenderer.get(),
|
| 712 | ctx,
|
| 713 | tickDelta,
|
| 714 | fbWidth,
|
| 715 | fbHeight
|
| 716 | );
|
| 717 | Renderer2D.COLOR.render();
|
| 718 | } finally {
|
| 719 | ViewportContext.endCurrentStratum(ctx);
|
| 720 | }
|
| 721 | }
|
| 722 |
|
| 723 | public static void renderTopLayer(GuiGraphicsExtractor ctx, float tickDelta) {
|
| 724 | if (!shouldRenderAsTopLayer()) return;
|
| 725 |
|
| 726 | CombatantRenderSystem.ensureFrameContext();
|
| 727 | ViewportContext.beginUnscaledLogical(ctx);
|
| 728 | try (RenderPhaseScope phaseScope = CombatantRenderSystem.phase(RenderPhase.SCREEN_TOP, "2d:clickgui_top")) {
|
| 729 | SystemCursor.beginFrame(ctx);
|
| 730 | try {
|
| 731 | Renderer2D.COLOR.begin();
|
| 732 | if (ClientScreen.current() instanceof ClickGuiEditorScreen) {
|
| 733 | renderEditor(Renderer2D.COLOR, TextRenderer.get(), ctx, tickDelta);
|
| 734 | } else {
|
| 735 | renderEngine(Renderer2D.COLOR, TextRenderer.get(), ctx, tickDelta);
|
| 736 | }
|
| 737 | Renderer2D.COLOR.render();
|
| 738 | if (ClientScreen.current() instanceof ClickGuiPickerScreen) {
|
| 739 | processPickerIcons(ctx);
|
| 740 | }
|
| 741 | } finally {
|
| 742 | SystemCursor.endFrame();
|
| 743 | }
|
| 744 | }
|
| 745 | ViewportContext.end(ctx);
|
| 746 | }
|
| 747 |
|
| 748 | public static void renderEditor(Renderer2D rendererIn, TextRenderer fallback, GuiGraphicsExtractor ctx, float tickDelta) {
|
| 749 | if (MC == null || MC.getWindow() == null) return;
|
| 750 | init();
|
| 751 | renderer = rendererIn;
|
| 752 | int fbw = MC.getWindow().getWidth();
|
| 753 | int fbh = MC.getWindow().getHeight();
|
| 754 | int vw = Math.max(1, Math.round(HudScale.virtualWidth(fbw, fbh)));
|
| 755 | int vh = Math.max(1, Math.round(HudScale.virtualHeight(fbw, fbh)));
|
| 756 | fbWidth = vw;
|
| 757 | fbHeight = vh;
|
| 758 | SystemCursor.beginFrame(ctx);
|
| 759 | try {
|
| 760 | SettingsTabRuntime.renderEditor(rendererIn, fallback, ctx, tickDelta, vw, vh, mouseX, mouseY);
|
| 761 | } finally {
|
| 762 | SystemCursor.endFrame();
|
| 763 | }
|
| 764 | }
|
| 765 |
|
| 766 | public static void renderModulesPreview(float x, float y, float w, float h) {
|
| 767 | if (renderer == null) return;
|
| 768 | init();
|
| 769 | ClickGuiSection modulesSection = sectionById(MODULES_TAB_ID);
|
| 770 | if (modulesSection == null) return;
|
| 771 | float pad = 8f;
|
| 772 | float areaX = x + pad;
|
| 773 | float areaY = y + pad;
|
| 774 | float areaW = Math.max(1f, w - pad * 2f);
|
| 775 | float areaH = Math.max(1f, h - pad * 2f);
|
| 776 | modulesSection.layout(areaX, areaY, areaW, areaH);
|
| 777 | float mx = -10_000f;
|
| 778 | float my = -10_000f;
|
| 779 | modulesSection.render(mx, my);
|
| 780 | }
|
| 781 |
|
| 782 | private static void layout(int fbw, int fbh) {
|
| 783 | List<ClickGuiTabEntry> tabs = currentTabs();
|
| 784 | ensureActiveTab(tabs);
|
| 785 | float contentMarginX = 28f;
|
| 786 | float contentTop = 52f;
|
| 787 | float contentBottom = 18f;
|
| 788 | modulesAreaX = contentMarginX;
|
| 789 | modulesAreaY = contentTop;
|
| 790 | modulesAreaW = Math.max(1f, fbw - contentMarginX * 2f);
|
| 791 | modulesAreaH = Math.max(1f, fbh - contentTop - contentBottom);
|
| 792 | for (ClickGuiTabEntry tab : tabs) {
|
| 793 | if (tab.section().usesFullViewport()) {
|
| 794 | tab.section().layout(0.0f, 0.0f, fbw, fbh);
|
| 795 | } else {
|
| 796 | tab.section().layout(modulesAreaX, modulesAreaY, modulesAreaW, modulesAreaH);
|
| 797 | }
|
| 798 | }
|
| 799 |
|
| 800 | tabBarH = TAB_HEIGHT;
|
| 801 | tabBarY = 10f;
|
| 802 | ensureTabCapacity(tabs.size());
|
| 803 | float totalTabs = 0f;
|
| 804 | for (int t = 0; t < tabs.size(); t++) {
|
| 805 | float wTab = textWidth(getSfProDisplaySemibold(), tabs.get(t).label(), TAB_FONT) + TAB_PAD_X * 2f;
|
| 806 | if (wTab < TAB_MIN_W) wTab = TAB_MIN_W;
|
| 807 | tabW[t] = wTab;
|
| 808 | totalTabs += wTab;
|
| 809 | }
|
| 810 | if (!tabs.isEmpty()) {
|
| 811 | totalTabs += TAB_GAP * (tabs.size() - 1);
|
| 812 | }
|
| 813 | tabBarW = totalTabs;
|
| 814 | tabBarX = (fbw - totalTabs) * 0.5f;
|
| 815 | float cx = tabBarX;
|
| 816 | for (int t = 0; t < tabs.size(); t++) {
|
| 817 | tabX[t] = cx;
|
| 818 | cx += tabW[t] + TAB_GAP;
|
| 819 | }
|
| 820 |
|
| 821 | int activeIdx = 0;
|
| 822 | for (int t = 0; t < tabs.size(); t++) {
|
| 823 | if (tabs.get(t).id().equals(activeTabId)) {
|
| 824 | activeIdx = t;
|
| 825 | break;
|
| 826 | }
|
| 827 | }
|
| 828 | tabTargetX = tabX[activeIdx];
|
| 829 | tabTargetW = tabW[activeIdx];
|
| 830 | if (!tabAnimInit) {
|
| 831 | tabAnimX = tabTargetX;
|
| 832 | tabAnimW = tabTargetW;
|
| 833 | tabAnimInit = true;
|
| 834 | lastTabAnimNs = System.nanoTime();
|
| 835 | }
|
| 836 | }
|
| 837 |
|
| 838 | private static void updateTabAnim(long now) {
|
| 839 | float dt = (now - lastTabAnimNs) / 1_000_000_000f;
|
| 840 | lastTabAnimNs = now;
|
| 841 | if (dt < 0f) dt = 0f;
|
| 842 | float speed = 16f;
|
| 843 | float step = Math.min(1f, dt * speed);
|
| 844 | tabAnimX += (tabTargetX - tabAnimX) * step;
|
| 845 | tabAnimW += (tabTargetW - tabAnimW) * step;
|
| 846 | }
|
| 847 |
|
| 848 | private static void updateLifecycleAnim(long now, boolean opening) {
|
| 849 | float dt = (now - lastLifecycleAnimNs) / 1_000_000_000f;
|
| 850 | lastLifecycleAnimNs = now;
|
| 851 | if (dt < 0f) dt = 0f;
|
| 852 | float target = opening ? 1.0f : 0.0f;
|
| 853 | float speed = opening ? LIFECYCLE_OPEN_SPEED : LIFECYCLE_CLOSE_SPEED;
|
| 854 | lifecycleAnim = AnimationUtility.approach(lifecycleAnim, target, dt, speed);
|
| 855 | lifecycleAnim = AnimationUtility.snap(lifecycleAnim, target, 0.002f);
|
| 856 | }
|
| 857 |
|
| 858 | private static boolean sectionsClosed() {
|
| 859 | return !getActiveSection().isVisible();
|
| 860 | }
|
| 861 |
|
| 862 | private static void completeCloseAnimation() {
|
| 863 | if (finishingClose) return;
|
| 864 | finishingClose = true;
|
| 865 | closingForExit = false;
|
| 866 | onClose();
|
| 867 | if (MC != null && (ClientScreen.current() instanceof ClickGuiScreen
|
| 868 | || ClientScreen.current() instanceof ClickGuiPickerScreen
|
| 869 | || ClientScreen.current() instanceof ClickGuiEditorScreen)) {
|
| 870 | ClientScreen.show(MC, null);
|
| 871 | }
|
| 872 | clearScreens();
|
| 873 | finishingClose = false;
|
| 874 | }
|
| 875 |
|
| 876 | private static void drawTabs() {
|
| 877 | float eased = easeOutCubic(lifecycleAnim);
|
| 878 | if (eased <= 0.001f) return;
|
| 879 | List<ClickGuiTabEntry> tabs = currentTabs();
|
| 880 | ensureActiveTab(tabs);
|
| 881 | if (tabs.isEmpty()) return;
|
| 882 | boolean islandShell = DynamicIsland.shouldOwnClickGuiTabShell();
|
| 883 | if (islandShell) return;
|
| 884 |
|
| 885 | TextRenderer tabFont = getOnestBold();
|
| 886 | float y = tabBarY - (1.0f - eased) * 18.0f;
|
| 887 | float outerRadius = tabBarH * 0.5f;
|
| 888 | float outerPad = 4.0f;
|
| 889 | float innerX = tabAnimX + outerPad;
|
| 890 | float innerY = y + outerPad;
|
| 891 | float innerW = Math.max(1.0f, tabAnimW - outerPad * 2.0f);
|
| 892 | float innerH = Math.max(1.0f, tabBarH - outerPad * 2.0f);
|
| 893 | float innerRadius = innerH * 0.5f;
|
| 894 |
|
| 895 | int outerLeft = scaleAlpha(mixColor(theme().surface(), theme().windowBg(), 0.34f), eased);
|
| 896 | int outerRight = scaleAlpha(mixColor(theme().surfaceHover(), theme().windowBg(), 0.22f), eased);
|
| 897 | int outerStrokeLeft = scaleAlpha(mixColor(theme().strokeSoft(), theme().accentSoft(), 0.18f), 0.72f * eased);
|
| 898 | int outerStrokeRight = scaleAlpha(mixColor(theme().strokeSoft(), theme().textPrimary(), 0.08f), 0.58f * eased);
|
| 899 |
|
| 900 | int activeLeft = scaleAlpha(mixColor(theme().accentSoft(), theme().accent(), 0.18f), eased);
|
| 901 | int activeRight = scaleAlpha(mixColor(theme().accent(), theme().textPrimary(), 0.08f), eased);
|
| 902 | int activeStrokeLeft = scaleAlpha(mixColor(theme().accentSoft(), theme().textPrimary(), 0.20f), 0.88f * eased);
|
| 903 | int activeStrokeRight = scaleAlpha(theme().accent(), 0.92f * eased);
|
| 904 |
|
| 905 | try (RenderWarpStack.Scope ignored = Renderer2D.pushPerspectiveWarp(
|
| 906 | tabBarX,
|
| 907 | y,
|
| 908 | tabBarW,
|
| 909 | tabBarH,
|
| 910 | 0.0f,
|
| 911 | -5.0f * (1.0f - eased),
|
| 912 | 0.0f,
|
| 913 | 3.2f,
|
| 914 | 0.80f,
|
| 915 | 0.965f + 0.035f * eased
|
| 916 | )) {
|
| 917 | if (!islandShell) {
|
| 918 | drawRoundedRectShadow(
|
| 919 | tabBarX,
|
| 920 | y,
|
| 921 | tabBarW,
|
| 922 | tabBarH,
|
| 923 | outerRadius,
|
| 924 | 10.0f,
|
| 925 | 1.5f,
|
| 926 | scaleAlpha(0xCC000000, 0.34f * eased)
|
| 927 | );
|
| 928 | drawRoundedRectGradient(tabBarX, y, tabBarW, tabBarH, outerRadius, outerLeft, outerRight, 0.0f);
|
| 929 | drawRoundedRectStrokeGradient(tabBarX, y, tabBarW, tabBarH, outerRadius, 1.0f, outerStrokeLeft, outerStrokeRight, 0.0f);
|
| 930 | }
|
| 931 |
|
| 932 | drawRoundedRectGlow(
|
| 933 | innerX,
|
| 934 | innerY,
|
| 935 | innerW,
|
| 936 | innerH,
|
| 937 | innerRadius,
|
| 938 | 10.0f,
|
| 939 | scaleAlpha(theme().accentSoft(), 0.30f * eased)
|
| 940 | );
|
| 941 | drawRoundedRectGradient(innerX, innerY, innerW, innerH, innerRadius, activeLeft, activeRight, 0.0f);
|
| 942 | drawRoundedRectStrokeGradient(innerX, innerY, innerW, innerH, innerRadius, 1.0f, activeStrokeLeft, activeStrokeRight, 0.0f);
|
| 943 |
|
| 944 | for (int i = 0; i < tabs.size(); i++) {
|
| 945 | float x = tabX[i];
|
| 946 | float w = tabW[i];
|
| 947 | ClickGuiTabEntry tab = tabs.get(i);
|
| 948 | boolean active = tab.id().equals(activeTabId);
|
| 949 | boolean hovered = !closingForExit && mouseX >= x && mouseX <= x + w && mouseY >= y && mouseY <= y + tabBarH;
|
| 950 | if (i > 0) {
|
| 951 | float sepH = tabBarH - outerPad * 3.4f;
|
| 952 | float sepY = y + (tabBarH - sepH) * 0.5f;
|
| 953 | drawRect(x, sepY, 1.0f, sepH, scaleAlpha(theme().strokeSoft(), 0.32f * eased));
|
| 954 | }
|
| 955 | int textCol = active ? theme().textPrimary() : theme().textMuted();
|
| 956 | if (!active && hovered) {
|
| 957 | textCol = mixColor(textCol, theme().textPrimary(), 0.55f);
|
| 958 | }
|
| 959 | textCol = scaleAlpha(textCol, eased);
|
| 960 | float textH = textHeight(tabFont, TAB_FONT);
|
| 961 | float textY = y + (tabBarH - textH) * 0.5f - 0.35f;
|
| 962 | float labelW = textWidth(tabFont, tab.label(), TAB_FONT);
|
| 963 | float textX = x + (w - labelW) * 0.5f;
|
| 964 | drawText(tabFont, tab.label(), textX, textY, TAB_FONT, textCol, false);
|
| 965 | }
|
| 966 | }
|
| 967 | }
|
| 968 |
|
| 969 | private static boolean handleTabClick(float mx, float my) {
|
| 970 | if (!isInputReady()) return false;
|
| 971 | if (mx < tabBarX || mx > tabBarX + tabBarW || my < tabBarY || my > tabBarY + tabBarH) return false;
|
| 972 | List<ClickGuiTabEntry> tabs = currentTabs();
|
| 973 | ensureActiveTab(tabs);
|
| 974 | for (int i = 0; i < tabs.size(); i++) {
|
| 975 | float x = tabX[i];
|
| 976 | float w = tabW[i];
|
| 977 | if (mx >= x && mx <= x + w && my >= tabBarY && my <= tabBarY + tabBarH) {
|
| 978 | ClickGuiTabEntry tab = tabs.get(i);
|
| 979 | if (!activeTabId.equals(tab.id())) {
|
| 980 | ClickGuiSection previous = getActiveSection();
|
| 981 | activeTabId = tab.id();
|
| 982 | previous.onDeselected();
|
| 983 | ClickGuiSearch.deactivate();
|
| 984 | clearInlineText();
|
| 985 | closeTextEditor(false);
|
| 986 | getActiveSection().onSelected();
|
| 987 | }
|
| 988 | return true;
|
| 989 | }
|
| 990 | }
|
| 991 | return false;
|
| 992 | }
|
| 993 |
|
| 994 | private static ClickGuiSection getActiveSection() {
|
| 995 | List<ClickGuiTabEntry> tabs = currentTabs();
|
| 996 | ensureActiveTab(tabs);
|
| 997 | for (ClickGuiTabEntry tab : tabs) {
|
| 998 | if (tab.id().equals(activeTabId)) {
|
| 999 | return tab.section();
|
| 1000 | }
|
| 1001 | }
|
| 1002 | return tabs.isEmpty() ? null : tabs.get(0).section();
|
| 1003 | }
|
| 1004 |
|
| 1005 | private static boolean isSettingsTabActive() {
|
| 1006 | return SETTINGS_TAB_ID.equals(activeTabId);
|
| 1007 | }
|
| 1008 |
|
| 1009 | private static List<ClickGuiTabEntry> currentTabs() {
|
| 1010 | List<ClickGuiSectionManager.Entry> sections = ClickGuiSectionManager.sections();
|
| 1011 | ArrayList<ClickGuiTabEntry> out = new ArrayList<>(sections.size());
|
| 1012 | for (ClickGuiSectionManager.Entry entry : sections) {
|
| 1013 | out.add(new ClickGuiTabEntry(entry.id(), entry.label(), entry.section()));
|
| 1014 | }
|
| 1015 | return out;
|
| 1016 | }
|
| 1017 |
|
| 1018 | private static ClickGuiSection sectionById(String id) {
|
| 1019 | for (ClickGuiTabEntry tab : currentTabs()) {
|
| 1020 | if (tab.id().equals(id)) {
|
| 1021 | return tab.section();
|
| 1022 | }
|
| 1023 | }
|
| 1024 | return null;
|
| 1025 | }
|
| 1026 |
|
| 1027 | private static void ensureActiveTab(List<ClickGuiTabEntry> tabs) {
|
| 1028 | for (ClickGuiTabEntry tab : tabs) {
|
| 1029 | if (tab.id().equals(activeTabId)) {
|
| 1030 | return;
|
| 1031 | }
|
| 1032 | }
|
| 1033 | activeTabId = MODULES_TAB_ID;
|
| 1034 | }
|
| 1035 |
|
| 1036 | public static ClickGuiIslandState islandState() {
|
| 1037 | List<ClickGuiTabEntry> tabs = currentTabs();
|
| 1038 | ensureActiveTab(tabs);
|
| 1039 | String activeLabel = tabs.isEmpty() ? "" : tabs.get(0).label();
|
| 1040 | for (ClickGuiTabEntry tab : tabs) {
|
| 1041 | if (tab.id().equals(activeTabId)) {
|
| 1042 | activeLabel = tab.label();
|
| 1043 | break;
|
| 1044 | }
|
| 1045 | }
|
| 1046 | boolean geometryReady = tabX.length >= tabs.size() && tabW.length >= tabs.size();
|
| 1047 | if (!geometryReady) {
|
| 1048 | return new ClickGuiIslandState(
|
| 1049 | tabBarX, tabBarY, tabBarW, tabBarH,
|
| 1050 | tabAnimX, tabAnimW, lifecycleAnim,
|
| 1051 | activeLabel, 0,
|
| 1052 | picker != null || protocolHeuristicsEditor != null,
|
| 1053 | List.of()
|
| 1054 | );
|
| 1055 | }
|
| 1056 | ArrayList<ClickGuiIslandTab> islandTabs = new ArrayList<>(tabs.size());
|
| 1057 | for (int i = 0; i < tabs.size(); i++) {
|
| 1058 | ClickGuiTabEntry tab = tabs.get(i);
|
| 1059 | boolean active = tab.id().equals(activeTabId);
|
| 1060 | boolean hovered = !closingForExit
|
| 1061 | && mouseX >= tabX[i] && mouseX <= tabX[i] + tabW[i]
|
| 1062 | && mouseY >= tabBarY && mouseY <= tabBarY + tabBarH;
|
| 1063 | islandTabs.add(new ClickGuiIslandTab(
|
| 1064 | tab.label(),
|
| 1065 | tabX[i] - tabBarX,
|
| 1066 | tabW[i],
|
| 1067 | active,
|
| 1068 | hovered
|
| 1069 | ));
|
| 1070 | }
|
| 1071 | return new ClickGuiIslandState(
|
| 1072 | tabBarX,
|
| 1073 | tabBarY,
|
| 1074 | tabBarW,
|
| 1075 | tabBarH,
|
| 1076 | tabAnimX,
|
| 1077 | tabAnimW,
|
| 1078 | lifecycleAnim,
|
| 1079 | activeLabel,
|
| 1080 | tabs.size(),
|
| 1081 | picker != null || protocolHeuristicsEditor != null,
|
| 1082 | List.copyOf(islandTabs)
|
| 1083 | );
|
| 1084 | }
|
| 1085 |
|
| 1086 | private static void ensureTabCapacity(int size) {
|
| 1087 | if (tabX.length >= size && tabW.length >= size) return;
|
| 1088 | tabX = Arrays.copyOf(tabX, size);
|
| 1089 | tabW = Arrays.copyOf(tabW, size);
|
| 1090 | }
|
| 1091 |
|
| 1092 | private static float easeOutCubic(float t) {
|
| 1093 | t = Math.max(0.0f, Math.min(1.0f, t));
|
| 1094 | float inv = 1.0f - t;
|
| 1095 | return 1.0f - inv * inv * inv;
|
| 1096 | }
|
| 1097 |
|
| 1098 | public static TextRenderer getInterRegular() {
|
| 1099 | ensureFontBindingsCurrent();
|
| 1100 | if (interRegular == null) {
|
| 1101 | interRegular = BuiltinFontCatalog.INTER_REGULAR.renderer(TextRenderer.get());
|
| 1102 | }
|
| 1103 | return interRegular;
|
| 1104 | }
|
| 1105 |
|
| 1106 | public static Renderer2D currentRenderer() {
|
| 1107 | return renderer;
|
| 1108 | }
|
| 1109 |
|
| 1110 | public static TextRenderer getInterMedium() {
|
| 1111 | ensureFontBindingsCurrent();
|
| 1112 | if (interMedium == null) {
|
| 1113 | interMedium = BuiltinFontCatalog.INTER_MEDIUM.renderer(getInterRegular());
|
| 1114 | }
|
| 1115 | return interMedium;
|
| 1116 | }
|
| 1117 |
|
| 1118 | public static TextRenderer getIosevkaRegular() {
|
| 1119 | return getSfMedium();
|
| 1120 | }
|
| 1121 |
|
| 1122 | public static TextRenderer getSfMedium() {
|
| 1123 | ensureFontBindingsCurrent();
|
| 1124 | if (onestMedium == null) {
|
| 1125 | onestMedium = BuiltinFontCatalog.ONEST_MEDIUM.renderer(TextRenderer.get());
|
| 1126 | }
|
| 1127 | return onestMedium;
|
| 1128 | }
|
| 1129 |
|
| 1130 | public static TextRenderer getOnestMedium() {
|
| 1131 | return getSfMedium();
|
| 1132 | }
|
| 1133 |
|
| 1134 | public static TextRenderer getSfProDisplaySemibold() {
|
| 1135 | ensureFontBindingsCurrent();
|
| 1136 | if (onestBold == null) {
|
| 1137 | onestBold = BuiltinFontCatalog.ONEST_BOLD.renderer(getInterMedium());
|
| 1138 | }
|
| 1139 | return onestBold;
|
| 1140 | }
|
| 1141 |
|
| 1142 | public static TextRenderer getOnestBold() {
|
| 1143 | return getSfProDisplaySemibold();
|
| 1144 | }
|
| 1145 |
|
| 1146 | public static TextRenderer getMonsterratRegular() {
|
| 1147 | ensureFontBindingsCurrent();
|
| 1148 | if (monsterratRegular == null) {
|
| 1149 | monsterratRegular = BuiltinFontCatalog.MONSTERRAT.renderer(TextRenderer.get());
|
| 1150 | }
|
| 1151 | return monsterratRegular;
|
| 1152 | }
|
| 1153 |
|
| 1154 | private static void ensureFontBindingsCurrent() {
|
| 1155 | long generation = Fonts.generation();
|
| 1156 | if (boundFontGeneration == generation) return;
|
| 1157 | invalidateFontBindings();
|
| 1158 | boundFontGeneration = generation;
|
| 1159 | }
|
| 1160 |
|
| 1161 | /** Drop cached renderer identities after a font/resource generation is replaced. */
|
| 1162 | public static void invalidateFontBindings() {
|
| 1163 | interRegular = null;
|
| 1164 | interMedium = null;
|
| 1165 | onestMedium = null;
|
| 1166 | onestBold = null;
|
| 1167 | monsterratRegular = null;
|
| 1168 | boundFontGeneration = Long.MIN_VALUE;
|
| 1169 | TEXT_WIDTH_CACHE.clear();
|
| 1170 | TEXT_HEIGHT_CACHE.clear();
|
| 1171 | }
|
| 1172 |
|
| 1173 | public static int framebufferWidth() {
|
| 1174 | return fbWidth;
|
| 1175 | }
|
| 1176 |
|
| 1177 | public static int framebufferHeight() {
|
| 1178 | return fbHeight;
|
| 1179 | }
|
| 1180 |
|
| 1181 | public static float getAnimAlpha() {
|
| 1182 | return 1f;
|
| 1183 | }
|
| 1184 |
|
| 1185 | public static float getMouseX() {
|
| 1186 | return mouseX;
|
| 1187 | }
|
| 1188 |
|
| 1189 | public static float getMouseY() {
|
| 1190 | return mouseY;
|
| 1191 | }
|
| 1192 |
|
| 1193 | public static int mixColor(int from, int to, float t) {
|
| 1194 | t = Math.max(0f, Math.min(1f, t));
|
| 1195 | int a = (int) (((from >>> 24) & 0xFF) * (1 - t) + ((to >>> 24) & 0xFF) * t);
|
| 1196 | int r = (int) (((from >>> 16) & 0xFF) * (1 - t) + ((to >>> 16) & 0xFF) * t);
|
| 1197 | int g = (int) (((from >>> 8) & 0xFF) * (1 - t) + ((to >>> 8) & 0xFF) * t);
|
| 1198 | int b = (int) (((from) & 0xFF) * (1 - t) + ((to) & 0xFF) * t);
|
| 1199 | return (a << 24) | (r << 16) | (g << 8) | b;
|
| 1200 | }
|
| 1201 |
|
| 1202 | public static int scaleAlpha(int color, float factor) {
|
| 1203 | int a = (color >>> 24) & 0xFF;
|
| 1204 | int na = (int) (a * Math.max(0f, Math.min(1f, factor)));
|
| 1205 | return (color & 0x00FFFFFF) | (na << 24);
|
| 1206 | }
|
| 1207 |
|
| 1208 | public static int withAlpha(int color, int alpha) {
|
| 1209 | int a = Math.max(0, Math.min(255, alpha));
|
| 1210 | return (color & 0x00FFFFFF) | (a << 24);
|
| 1211 | }
|
| 1212 |
|
| 1213 | public static float setRenderAlphaMultiplier(float alpha) {
|
| 1214 | float previous = renderAlphaMultiplier;
|
| 1215 | renderAlphaMultiplier = Math.max(0.0f, Math.min(1.0f, alpha));
|
| 1216 | return previous;
|
| 1217 | }
|
| 1218 |
|
| 1219 | public static float getRenderAlphaMultiplier() {
|
| 1220 | return renderAlphaMultiplier;
|
| 1221 | }
|
| 1222 |
|
| 1223 | public static void restoreRenderAlphaMultiplier(float previous) {
|
| 1224 | renderAlphaMultiplier = Math.max(0.0f, Math.min(1.0f, previous));
|
| 1225 | }
|
| 1226 |
|
| 1227 | /**
|
| 1228 | * Applies a real vertex/glyph alpha ramp to ClickGUI content. Geometry remains hard-clipped
|
| 1229 | * separately at {@code endY}; this scope owns only the smooth part of the bottom edge.
|
| 1230 | */
|
| 1231 | public static VerticalAlphaFadeScope pushBottomAlphaFade(float startY, float endY) {
|
| 1232 | VerticalAlphaFadeScope scope = new VerticalAlphaFadeScope(
|
| 1233 | verticalAlphaFadeEnabled,
|
| 1234 | verticalAlphaFadeStart,
|
| 1235 | verticalAlphaFadeEnd
|
| 1236 | );
|
| 1237 | verticalAlphaFadeEnabled = endY > startY;
|
| 1238 | verticalAlphaFadeStart = startY;
|
| 1239 | verticalAlphaFadeEnd = Math.max(startY, endY);
|
| 1240 | return scope;
|
| 1241 | }
|
| 1242 |
|
| 1243 | private static int applyAlpha(int argb) {
|
| 1244 | if (renderAlphaMultiplier >= 0.999f) return argb;
|
| 1245 | int a = (argb >>> 24) & 0xFF;
|
| 1246 | int na = Math.round(a * renderAlphaMultiplier);
|
| 1247 | return (argb & 0x00FFFFFF) | ((na & 0xFF) << 24);
|
| 1248 | }
|
| 1249 |
|
| 1250 | private static float verticalAlphaAt(float y) {
|
| 1251 | return verticalAlphaAt(y, verticalAlphaFadeEnabled, verticalAlphaFadeStart, verticalAlphaFadeEnd);
|
| 1252 | }
|
| 1253 |
|
| 1254 | private static float verticalAlphaAt(float y, boolean enabled, float start, float end) {
|
| 1255 | if (!enabled) return 1.0f;
|
| 1256 | if (y <= start) return 1.0f;
|
| 1257 | if (y >= end) return 0.0f;
|
| 1258 | return 1.0f - (y - start) / Math.max(0.0001f, end - start);
|
| 1259 | }
|
| 1260 |
|
| 1261 | private static int multiplyAlpha(int argb, float factor) {
|
| 1262 | int a = (argb >>> 24) & 0xFF;
|
| 1263 | int na = Math.round(a * Math.max(0.0f, Math.min(1.0f, factor)));
|
| 1264 | return (argb & 0x00FFFFFF) | ((na & 0xFF) << 24);
|
| 1265 | }
|
| 1266 |
|
| 1267 | public static float scaleForSize(float size) {
|
| 1268 | return TextSizing.scaleForSize(size);
|
| 1269 | }
|
| 1270 |
|
| 1271 | public static float textWidth(TextRenderer tr, String text, float size) {
|
| 1272 | if (tr == null || text == null || text.isEmpty()) return 0f;
|
| 1273 | TextMeasureKey key = new TextMeasureKey(tr, Float.floatToIntBits(size), text);
|
| 1274 | Float cached = TEXT_WIDTH_CACHE.get(key);
|
| 1275 | if (cached != null) return cached;
|
| 1276 | float scale = scaleForSize(size);
|
| 1277 | tr.begin(scale, true, false);
|
| 1278 | try {
|
| 1279 | float width = (float) tr.getWidth(text, false);
|
| 1280 | TEXT_WIDTH_CACHE.put(key, width);
|
| 1281 | return width;
|
| 1282 | } finally {
|
| 1283 | tr.end();
|
| 1284 | }
|
| 1285 | }
|
| 1286 |
|
| 1287 | public static float textHeight(TextRenderer tr, float size) {
|
| 1288 | if (tr == null) return 0f;
|
| 1289 | TextHeightKey key = new TextHeightKey(tr, Float.floatToIntBits(size));
|
| 1290 | Float cached = TEXT_HEIGHT_CACHE.get(key);
|
| 1291 | if (cached != null) return cached;
|
| 1292 | float scale = scaleForSize(size);
|
| 1293 | tr.begin(scale, true, false);
|
| 1294 | try {
|
| 1295 | float height = (float) tr.getHeight(false);
|
| 1296 | TEXT_HEIGHT_CACHE.put(key, height);
|
| 1297 | return height;
|
| 1298 | } finally {
|
| 1299 | tr.end();
|
| 1300 | }
|
| 1301 | }
|
| 1302 |
|
| 1303 | public static void beginTextBatch() {
|
| 1304 | if (textBatchActive) return;
|
| 1305 | textBatchActive = true;
|
| 1306 | TEXT_BATCH.clear();
|
| 1307 | }
|
| 1308 |
|
| 1309 | public static void endTextBatch() {
|
| 1310 | if (!textBatchActive) return;
|
| 1311 | textBatchActive = false;
|
| 1312 | if (TEXT_BATCH.isEmpty()) return;
|
| 1313 |
|
| 1314 | java.util.LinkedHashMap<TextBatchKey, java.util.ArrayList<TextBatchItem>> groups = new java.util.LinkedHashMap<>();
|
| 1315 | for (TextBatchItem item : TEXT_BATCH) {
|
| 1316 | TextBatchKey key = new TextBatchKey(item.renderer, Float.floatToIntBits(item.size), item.shadow);
|
| 1317 | java.util.ArrayList<TextBatchItem> list = groups.get(key);
|
| 1318 | if (list == null) {
|
| 1319 | list = new java.util.ArrayList<>();
|
| 1320 | groups.put(key, list);
|
| 1321 | }
|
| 1322 | list.add(item);
|
| 1323 | }
|
| 1324 |
|
| 1325 | for (var entry : groups.entrySet()) {
|
| 1326 | TextBatchKey key = entry.getKey();
|
| 1327 | TextRenderer tr = key.renderer;
|
| 1328 | if (tr == null) continue;
|
| 1329 | float size = Float.intBitsToFloat(key.sizeBits);
|
| 1330 | float scale = scaleForSize(size);
|
| 1331 | tr.begin(scale, false, false);
|
| 1332 | for (TextBatchItem item : entry.getValue()) {
|
| 1333 | renderTextItem(tr, item);
|
| 1334 | }
|
| 1335 | tr.end();
|
| 1336 | }
|
| 1337 |
|
| 1338 | TEXT_BATCH.clear();
|
| 1339 | }
|
| 1340 |
|
| 1341 | public static void drawText(TextRenderer tr, String text, float x, float y, float size, int argb, boolean shadow) {
|
| 1342 | if (tr == null || text == null || text.isEmpty()) return;
|
| 1343 | argb = applyAlpha(argb);
|
| 1344 | if (((argb >>> 24) & 0xFF) <= 0) return;
|
| 1345 | if (textBatchActive) {
|
| 1346 | TEXT_BATCH.add(new TextBatchItem(
|
| 1347 | tr, text, x, y, size, argb, shadow,
|
| 1348 | verticalAlphaFadeEnabled, verticalAlphaFadeStart, verticalAlphaFadeEnd
|
| 1349 | ));
|
| 1350 | return;
|
| 1351 | }
|
| 1352 | float scale = scaleForSize(size);
|
| 1353 | tr.begin(scale, false, false);
|
| 1354 | renderTextItem(tr, new TextBatchItem(
|
| 1355 | tr, text, x, y, size, argb, shadow,
|
| 1356 | verticalAlphaFadeEnabled, verticalAlphaFadeStart, verticalAlphaFadeEnd
|
| 1357 | ));
|
| 1358 | tr.end();
|
| 1359 | }
|
| 1360 |
|
| 1361 | private static void renderTextItem(TextRenderer tr, TextBatchItem item) {
|
| 1362 | if (!item.fadeEnabled) {
|
| 1363 | tr.render(item.text, item.x, item.y, new RenderColor(item.argb), item.shadow);
|
| 1364 | return;
|
| 1365 | }
|
| 1366 | tr.renderQuadGradient(item.text, item.x, item.y, (index, codePoint, x0, y0, x1, y1, out) -> {
|
| 1367 | int top = multiplyAlpha(item.argb, verticalAlphaAt((float) y0, true, item.fadeStart, item.fadeEnd));
|
| 1368 | int bottom = multiplyAlpha(item.argb, verticalAlphaAt((float) y1, true, item.fadeStart, item.fadeEnd));
|
| 1369 | out[0] = top;
|
| 1370 | out[1] = bottom;
|
| 1371 | out[2] = bottom;
|
| 1372 | out[3] = top;
|
| 1373 | }, item.shadow);
|
| 1374 | }
|
| 1375 |
|
| 1376 | public static String fitText(TextRenderer tr, String text, float size, float maxWidth) {
|
| 1377 | if (text == null) return "";
|
| 1378 | if (maxWidth <= 0f) return text;
|
| 1379 | String trimmed = text;
|
| 1380 | float w = textWidth(tr, trimmed, size);
|
| 1381 | if (w <= maxWidth) return trimmed;
|
| 1382 | while (trimmed.length() > 1 && textWidth(tr, trimmed + "...", size) > maxWidth) {
|
| 1383 | trimmed = trimmed.substring(0, trimmed.length() - 1);
|
| 1384 | }
|
| 1385 | return trimmed + "...";
|
| 1386 | }
|
| 1387 |
|
| 1388 | public static List<String> wrapText(TextRenderer tr, String text, float size, float maxWidth, int maxLines) {
|
| 1389 | ArrayList<String> lines = new ArrayList<>();
|
| 1390 | if (text == null || text.isBlank()) {
|
| 1391 | lines.add("");
|
| 1392 | return lines;
|
| 1393 | }
|
| 1394 | if (maxLines <= 1 || maxWidth <= 0f) {
|
| 1395 | lines.add(fitText(tr, text, size, maxWidth));
|
| 1396 | return lines;
|
| 1397 | }
|
| 1398 |
|
| 1399 | String remaining = normalizeSpaces(text);
|
| 1400 | while (!remaining.isEmpty() && lines.size() < maxLines) {
|
| 1401 | if (lines.size() == maxLines - 1) {
|
| 1402 | lines.add(fitText(tr, remaining, size, maxWidth));
|
| 1403 | break;
|
| 1404 | }
|
| 1405 | if (textWidth(tr, remaining, size) <= maxWidth) {
|
| 1406 | lines.add(remaining);
|
| 1407 | break;
|
| 1408 | }
|
| 1409 |
|
| 1410 | int split = bestWrapIndex(tr, remaining, size, maxWidth);
|
| 1411 | String line = remaining.substring(0, split).trim();
|
| 1412 | if (line.isEmpty()) {
|
| 1413 | lines.add(fitText(tr, remaining, size, maxWidth));
|
| 1414 | break;
|
| 1415 | }
|
| 1416 | lines.add(line);
|
| 1417 | remaining = remaining.substring(split).trim();
|
| 1418 | }
|
| 1419 |
|
| 1420 | if (lines.isEmpty()) {
|
| 1421 | lines.add(fitText(tr, text, size, maxWidth));
|
| 1422 | }
|
| 1423 | return lines;
|
| 1424 | }
|
| 1425 |
|
| 1426 | private static int bestWrapIndex(TextRenderer tr, String text, float size, float maxWidth) {
|
| 1427 | int bestSpace = -1;
|
| 1428 | for (int i = 0; i < text.length(); i++) {
|
| 1429 | if (!Character.isWhitespace(text.charAt(i))) continue;
|
| 1430 | String candidate = text.substring(0, i).trim();
|
| 1431 | if (!candidate.isEmpty() && textWidth(tr, candidate, size) <= maxWidth) {
|
| 1432 | bestSpace = i;
|
| 1433 | continue;
|
| 1434 | }
|
| 1435 | if (bestSpace >= 0) break;
|
| 1436 | }
|
| 1437 | if (bestSpace >= 0) return bestSpace;
|
| 1438 |
|
| 1439 | String fitted = fitText(tr, text, size, maxWidth);
|
| 1440 | if (fitted.endsWith("...")) {
|
| 1441 | fitted = fitted.substring(0, Math.max(1, fitted.length() - 3));
|
| 1442 | }
|
| 1443 | return Math.max(1, Math.min(text.length(), fitted.length()));
|
| 1444 | }
|
| 1445 |
|
| 1446 | private static String normalizeSpaces(String text) {
|
| 1447 | if (text == null) return "";
|
| 1448 | String trimmed = text.trim();
|
| 1449 | if (trimmed.isEmpty()) return "";
|
| 1450 |
|
| 1451 | StringBuilder sb = new StringBuilder(trimmed.length());
|
| 1452 | boolean lastSpace = false;
|
| 1453 | for (int i = 0; i < trimmed.length(); i++) {
|
| 1454 | char c = trimmed.charAt(i);
|
| 1455 | if (Character.isWhitespace(c)) {
|
| 1456 | if (!lastSpace) {
|
| 1457 | sb.append(' ');
|
| 1458 | lastSpace = true;
|
| 1459 | }
|
| 1460 | } else {
|
| 1461 | sb.append(c);
|
| 1462 | lastSpace = false;
|
| 1463 | }
|
| 1464 | }
|
| 1465 | return sb.toString();
|
| 1466 | }
|
| 1467 |
|
| 1468 | private static String normalizeInlineText(String text) {
|
| 1469 | if (text == null) return "";
|
| 1470 | String normalized = text.replace("\r\n", "\n").replace('\r', '\n');
|
| 1471 | return normalized.replace('\n', ' ');
|
| 1472 | }
|
| 1473 |
|
| 1474 | public static void drawRoundedRect(float x, float y, float w, float h, float radius, int argb) {
|
| 1475 | if (renderer == null) return;
|
| 1476 | argb = applyAlpha(argb);
|
| 1477 | if (((argb >>> 24) & 0xFF) <= 0) return;
|
| 1478 | if (verticalAlphaFadeEnabled) {
|
| 1479 | int top = multiplyAlpha(argb, verticalAlphaAt(y));
|
| 1480 | int bottom = multiplyAlpha(argb, verticalAlphaAt(y + h));
|
| 1481 | renderer.roundedRectGradientQuad(x, y, w, h, radius, 1.1f, top, top, bottom, bottom);
|
| 1482 | } else {
|
| 1483 | renderer.roundedRect(x, y, w, h, radius, 1.1f, argb);
|
| 1484 | }
|
| 1485 | }
|
| 1486 |
|
| 1487 | public static void drawRoundedRectStroke(float x, float y, float w, float h, float radius, float thickness, int argb) {
|
| 1488 | if (renderer == null) return;
|
| 1489 | argb = applyAlpha(argb);
|
| 1490 | if (((argb >>> 24) & 0xFF) <= 0) return;
|
| 1491 | if (verticalAlphaFadeEnabled) {
|
| 1492 | int top = multiplyAlpha(argb, verticalAlphaAt(y));
|
| 1493 | int bottom = multiplyAlpha(argb, verticalAlphaAt(y + h));
|
| 1494 | renderer.roundedRectStrokeGradientQuad(x, y, w, h, radius, 1.1f, thickness,
|
| 1495 | top, top, bottom, bottom);
|
| 1496 | } else {
|
| 1497 | renderer.roundedRectStroke(x, y, w, h, radius, 1.1f, thickness, argb);
|
| 1498 | }
|
| 1499 | }
|
| 1500 |
|
| 1501 | public static void drawRoundedRectGlow(float x, float y, float w, float h,
|
| 1502 | float radius, float glow, int argb) {
|
| 1503 | if (renderer == null) return;
|
| 1504 | argb = applyAlpha(argb);
|
| 1505 | if (((argb >>> 24) & 0xFF) <= 0) return;
|
| 1506 | renderer.roundedRectGlow(x, y, w, h, radius, 1.1f, glow, argb);
|
| 1507 | }
|
| 1508 |
|
| 1509 | public static void drawRoundedRectShadow(float x, float y, float w, float h,
|
| 1510 | float radius, float softness, float spread, int argb) {
|
| 1511 | if (renderer == null) return;
|
| 1512 | argb = applyAlpha(argb);
|
| 1513 | if (((argb >>> 24) & 0xFF) <= 0) return;
|
| 1514 | renderer.roundedRectShadow(x, y, w, h, radius, softness, spread, argb);
|
| 1515 | }
|
| 1516 |
|
| 1517 | public static void drawRoundedRectGradient(float x, float y, float w, float h, float radius,
|
| 1518 | int startArgb, int endArgb, float angleDeg) {
|
| 1519 | if (renderer == null) return;
|
| 1520 | startArgb = applyAlpha(startArgb);
|
| 1521 | endArgb = applyAlpha(endArgb);
|
| 1522 | if (((startArgb >>> 24) & 0xFF) <= 0 && ((endArgb >>> 24) & 0xFF) <= 0) return;
|
| 1523 | if (verticalAlphaFadeEnabled) {
|
| 1524 | int[] colors = new int[4];
|
| 1525 | UiMeshGeometry.computeLinearGradientColors(w, h, startArgb, endArgb, angleDeg, 0.0f, colors);
|
| 1526 | float topAlpha = verticalAlphaAt(y);
|
| 1527 | float bottomAlpha = verticalAlphaAt(y + h);
|
| 1528 | renderer.roundedRectGradientQuad(x, y, w, h, radius, 1.1f,
|
| 1529 | multiplyAlpha(colors[0], topAlpha), multiplyAlpha(colors[1], topAlpha),
|
| 1530 | multiplyAlpha(colors[2], bottomAlpha), multiplyAlpha(colors[3], bottomAlpha));
|
| 1531 | } else {
|
| 1532 | renderer.roundedRectGradient(x, y, w, h, radius, 1.1f, startArgb, endArgb, angleDeg);
|
| 1533 | }
|
| 1534 | }
|
| 1535 |
|
| 1536 | public static void drawRoundedRectStrokeGradient(float x, float y, float w, float h, float radius, float thickness,
|
| 1537 | int startArgb, int endArgb, float angleDeg) {
|
| 1538 | if (renderer == null) return;
|
| 1539 | startArgb = applyAlpha(startArgb);
|
| 1540 | endArgb = applyAlpha(endArgb);
|
| 1541 | if (((startArgb >>> 24) & 0xFF) <= 0 && ((endArgb >>> 24) & 0xFF) <= 0) return;
|
| 1542 | if (verticalAlphaFadeEnabled) {
|
| 1543 | int[] colors = new int[4];
|
| 1544 | UiMeshGeometry.computeLinearGradientColors(w, h, startArgb, endArgb, angleDeg, 0.0f, colors);
|
| 1545 | float topAlpha = verticalAlphaAt(y);
|
| 1546 | float bottomAlpha = verticalAlphaAt(y + h);
|
| 1547 | renderer.roundedRectStrokeGradientQuad(x, y, w, h, radius, 1.1f, thickness,
|
| 1548 | multiplyAlpha(colors[0], topAlpha), multiplyAlpha(colors[1], topAlpha),
|
| 1549 | multiplyAlpha(colors[2], bottomAlpha), multiplyAlpha(colors[3], bottomAlpha));
|
| 1550 | } else {
|
| 1551 | renderer.roundedRectStrokeGradient(x, y, w, h, radius, 1.1f, thickness, startArgb, endArgb, angleDeg);
|
| 1552 | }
|
| 1553 | }
|
| 1554 |
|
| 1555 | public static void drawRoundedRectCorners(float x, float y, float w, float h,
|
| 1556 | float radiusTL, float radiusTR, float radiusBR, float radiusBL,
|
| 1557 | int argb) {
|
| 1558 | if (renderer == null) return;
|
| 1559 | argb = applyAlpha(argb);
|
| 1560 | if (((argb >>> 24) & 0xFF) <= 0) return;
|
| 1561 | if (verticalAlphaFadeEnabled) {
|
| 1562 | int top = multiplyAlpha(argb, verticalAlphaAt(y));
|
| 1563 | int bottom = multiplyAlpha(argb, verticalAlphaAt(y + h));
|
| 1564 | renderer.roundedRectCornersQuad(x, y, w, h, radiusTL, radiusTR, radiusBR, radiusBL, 1.1f,
|
| 1565 | top, top, bottom, bottom);
|
| 1566 | } else {
|
| 1567 | renderer.roundedRectCorners(x, y, w, h, radiusTL, radiusTR, radiusBR, radiusBL, 1.1f, argb);
|
| 1568 | }
|
| 1569 | }
|
| 1570 |
|
| 1571 | public static void drawRect(float x, float y, float w, float h, int argb) {
|
| 1572 | if (renderer == null) return;
|
| 1573 | argb = applyAlpha(argb);
|
| 1574 | if (((argb >>> 24) & 0xFF) <= 0) return;
|
| 1575 | if (verticalAlphaFadeEnabled) {
|
| 1576 | int top = multiplyAlpha(argb, verticalAlphaAt(y));
|
| 1577 | int bottom = multiplyAlpha(argb, verticalAlphaAt(y + h));
|
| 1578 | renderer.quadGradient(x, y, w, h, top, top, bottom, bottom);
|
| 1579 | } else {
|
| 1580 | renderer.quad(x, y, w, h, argb);
|
| 1581 | }
|
| 1582 | }
|
| 1583 |
|
| 1584 | public static void flushRenderer() {
|
| 1585 | if (renderer == null) return;
|
| 1586 | if (Renderer2D.isBatching()) {
|
| 1587 | Renderer2D.flushBatch();
|
| 1588 | } else {
|
| 1589 | renderer.begin();
|
| 1590 | }
|
| 1591 | }
|
| 1592 |
|
| 1593 | public static void drawGradientRect(float x, float y, float w, float h,
|
| 1594 | int cTopLeft, int cTopRight, int cBottomRight, int cBottomLeft) {
|
| 1595 | if (renderer == null) return;
|
| 1596 | cTopLeft = multiplyAlpha(applyAlpha(cTopLeft), verticalAlphaAt(y));
|
| 1597 | cTopRight = multiplyAlpha(applyAlpha(cTopRight), verticalAlphaAt(y));
|
| 1598 | cBottomRight = multiplyAlpha(applyAlpha(cBottomRight), verticalAlphaAt(y + h));
|
| 1599 | cBottomLeft = multiplyAlpha(applyAlpha(cBottomLeft), verticalAlphaAt(y + h));
|
| 1600 | renderer.quadGradient(x, y, w, h, cTopLeft, cTopRight, cBottomRight, cBottomLeft);
|
| 1601 | }
|
| 1602 |
|
| 1603 | public static void drawCircle(float cx, float cy, float r, int argb) {
|
| 1604 | if (renderer == null) return;
|
| 1605 | argb = applyAlpha(argb);
|
| 1606 | if (((argb >>> 24) & 0xFF) <= 0) return;
|
| 1607 | if (verticalAlphaFadeEnabled) {
|
| 1608 | int top = multiplyAlpha(argb, verticalAlphaAt(cy - r));
|
| 1609 | int bottom = multiplyAlpha(argb, verticalAlphaAt(cy + r));
|
| 1610 | renderer.roundedRectGradientQuad(cx - r, cy - r, r * 2f, r * 2f, r, 1.1f,
|
| 1611 | top, top, bottom, bottom);
|
| 1612 | } else {
|
| 1613 | renderer.circle(cx, cy, r, argb);
|
| 1614 | }
|
| 1615 | }
|
| 1616 |
|
| 1617 | public static void drawLine(float x1, float y1, float x2, float y2, int argb) {
|
| 1618 | if (renderer == null) return;
|
| 1619 | argb = applyAlpha(argb);
|
| 1620 | if (((argb >>> 24) & 0xFF) <= 0) return;
|
| 1621 | renderer.line(x1, y1, x2, y2, argb);
|
| 1622 | }
|
| 1623 |
|
| 1624 | public static void drawBlur(float x, float y, float w, float h, float radius, int argb, float alpha) {
|
| 1625 | alpha *= renderAlphaMultiplier;
|
| 1626 | alpha = AnimationUtility.clamp(alpha * clickGuiBlurDensityScale(), 0.0f, 1.0f);
|
| 1627 | if (alpha <= 0.01f) return;
|
| 1628 | float quality = clickGuiBlurQuality();
|
| 1629 | float brightness = 1.0f;
|
| 1630 | Renderer2D.COLOR.blurRect(x, y, w, h, radius, quality, brightness, alpha, 0xFFFFFF);
|
| 1631 | }
|
| 1632 |
|
| 1633 | public static void drawGlass(float x, float y, float w, float h, float radius, float alpha) {
|
| 1634 | if (renderer == null) return;
|
| 1635 | alpha *= renderAlphaMultiplier;
|
| 1636 | if (alpha <= 0.01f) return;
|
| 1637 |
|
| 1638 | float pad = 5f;
|
| 1639 | float gx = x - pad;
|
| 1640 | float gy = y - pad;
|
| 1641 | float gw = w + pad * 2f;
|
| 1642 | float gh = h + pad * 2f;
|
| 1643 | float gr = Math.max(0f, radius + pad);
|
| 1644 | float blurAlpha = AnimationUtility.clamp(alpha * clickGuiGlassBlurScale(), 0.0f, 1.0f);
|
| 1645 | float scale = Math.max(0.75f, gr / 10.0f);
|
| 1646 |
|
| 1647 | Renderer2D.COLOR.blurRect(gx, gy, gw, gh, gr, clickGuiBlurQuality(), 1.0f, blurAlpha, 0xFFFFFF);
|
| 1648 |
|
| 1649 | renderer.liquidGlassRect(
|
| 1650 | gx, gy, gw, gh, gr,
|
| 1651 | 15.0f * scale,
|
| 1652 | 0xFFFFFFFF,
|
| 1653 | alpha,
|
| 1654 | blurAlpha,
|
| 1655 | -18.0f,
|
| 1656 | 1.0f,
|
| 1657 | 0.78f,
|
| 1658 | 0.52f,
|
| 1659 | 0.190f * alpha,
|
| 1660 | 0.0f
|
| 1661 | );
|
| 1662 | }
|
| 1663 |
|
| 1664 | public static float clickGuiBlurQuality() {
|
| 1665 | return 27.35f;
|
| 1666 | }
|
| 1667 |
|
| 1668 | public static float clickGuiBlurDensityScale() {
|
| 1669 | return 1.16f;
|
| 1670 | }
|
| 1671 |
|
| 1672 | public static float clickGuiGlassBlurScale() {
|
| 1673 | return 1.28f;
|
| 1674 | }
|
| 1675 |
|
| 1676 | public static int getColorClipboard() {
|
| 1677 | return colorClipboard;
|
| 1678 | }
|
| 1679 |
|
| 1680 | public static void setColorClipboard(int argb) {
|
| 1681 | colorClipboard = argb;
|
| 1682 | }
|
| 1683 |
|
| 1684 | public static void beginKeyBind(Object owner) {
|
| 1685 | clearInlineText();
|
| 1686 | waitingForKey = true;
|
| 1687 | keyBindOwner = owner;
|
| 1688 | pendingBindKeys.clear();
|
| 1689 | ClickGuiSearch.deactivate();
|
| 1690 | GuiSound.BINDING_START.feedback();
|
| 1691 | }
|
| 1692 |
|
| 1693 | public static void finishKeyBind() {
|
| 1694 | waitingForKey = false;
|
| 1695 | keyBindOwner = null;
|
| 1696 | pendingBindKeys.clear();
|
| 1697 | }
|
| 1698 |
|
| 1699 | private static void addPendingKey(int keyCode, int scancode) {
|
| 1700 | int code = KeyUtil.fromKeyInput(keyCode, scancode);
|
| 1701 | if (code == KeyUtil.NONE) return;
|
| 1702 | pendingBindKeys.add(code);
|
| 1703 | }
|
| 1704 |
|
| 1705 | private static void addPendingMouseButton(int button) {
|
| 1706 | if (button < GLFW.GLFW_MOUSE_BUTTON_1 || button > GLFW.GLFW_MOUSE_BUTTON_LAST) return;
|
| 1707 | pendingBindKeys.add(KeyUtil.mouseButtonToCode(button));
|
| 1708 | }
|
| 1709 |
|
| 1710 | private static void submitKeySelection(Set<Integer> keys) {
|
| 1711 | if (keys == null || keys.isEmpty()) {
|
| 1712 | submitKeySelection((String) null);
|
| 1713 | return;
|
| 1714 | }
|
| 1715 | submitKeySelection(KeyUtil.comboToString(keys));
|
| 1716 | }
|
| 1717 |
|
| 1718 | private static void submitKeySelection(String combo) {
|
| 1719 | if (keyBindOwner instanceof KeyBindSetting ks) {
|
| 1720 | ks.onKeySelected(combo);
|
| 1721 | } else if (keyBindOwner instanceof FunctionBindSetting fs) {
|
| 1722 | fs.onKeySelected(combo);
|
| 1723 | }
|
| 1724 | }
|
| 1725 |
|
| 1726 | public static String getPendingBindDisplay() {
|
| 1727 | if (!waitingForKey) return null;
|
| 1728 | return pendingBindKeys.isEmpty() ? "..." : KeyUtil.comboToString(pendingBindKeys);
|
| 1729 | }
|
| 1730 |
|
| 1731 | public static void openTextEditor(TextEditorOwner owner, String title, String seedText, float anchorX, float anchorY, float anchorW) {
|
| 1732 | if (owner == null) return;
|
| 1733 | clearInlineText();
|
| 1734 | if (seedText == null) seedText = "";
|
| 1735 | ClickGuiSearch.deactivate();
|
| 1736 | textEditor = new ClickGuiTextEditorState(owner, title, seedText, anchorX, anchorY, anchorW);
|
| 1737 | }
|
| 1738 |
|
| 1739 | public static void closeTextEditor(boolean save) {
|
| 1740 | if (textEditor == null) return;
|
| 1741 | if (save) textEditor.save();
|
| 1742 | textEditor = null;
|
| 1743 | }
|
| 1744 |
|
| 1745 | public static void renderTextEditor(int fbw, int fbh) {
|
| 1746 | if (textEditor == null) return;
|
| 1747 | textEditor.render(fbw, fbh);
|
| 1748 | }
|
| 1749 |
|
| 1750 | private static void renderPicker(int fbw, int fbh) {
|
| 1751 | if (picker == null) return;
|
| 1752 | picker.render(fbw, fbh);
|
| 1753 | }
|
| 1754 |
|
| 1755 | public static void toggleInlineText(TextSetting owner) {
|
| 1756 | if (owner == null) return;
|
| 1757 | if (inlineTextOwner == owner) {
|
| 1758 | clearInlineText();
|
| 1759 | return;
|
| 1760 | }
|
| 1761 | inlineTextOwner = owner;
|
| 1762 | inlineTextBuffer = new StringBuilder(owner.getEditorText());
|
| 1763 | ClickGuiSearch.deactivate();
|
| 1764 | }
|
| 1765 |
|
| 1766 | public static boolean isInlineTextActive() {
|
| 1767 | return inlineTextOwner != null;
|
| 1768 | }
|
| 1769 |
|
| 1770 | public static boolean isInlineTextOwner(TextSetting owner) {
|
| 1771 | return inlineTextOwner == owner;
|
| 1772 | }
|
| 1773 |
|
| 1774 | public static String getInlineText(TextSetting owner) {
|
| 1775 | if (owner == null) return "";
|
| 1776 | if (inlineTextOwner == owner && inlineTextBuffer != null) {
|
| 1777 | return inlineTextBuffer.toString();
|
| 1778 | }
|
| 1779 | return owner.getEditorText();
|
| 1780 | }
|
| 1781 |
|
| 1782 | public static void updateInlineTextBounds(TextSetting owner, float x, float y, float w, float h) {
|
| 1783 | if (inlineTextOwner != owner) return;
|
| 1784 | inlineTextX = x;
|
| 1785 | inlineTextY = y;
|
| 1786 | inlineTextW = w;
|
| 1787 | inlineTextH = h;
|
| 1788 | }
|
| 1789 |
|
| 1790 | private static void finishInlineText(boolean save) {
|
| 1791 | if (inlineTextOwner == null || inlineTextBuffer == null) {
|
| 1792 | clearInlineText();
|
| 1793 | return;
|
| 1794 | }
|
| 1795 | if (save) {
|
| 1796 | inlineTextOwner.applyEditorText(inlineTextBuffer.toString());
|
| 1797 | }
|
| 1798 | clearInlineText();
|
| 1799 | }
|
| 1800 |
|
| 1801 | private static void clearInlineText() {
|
| 1802 | inlineTextOwner = null;
|
| 1803 | inlineTextBuffer = null;
|
| 1804 | inlineTextX = inlineTextY = inlineTextW = inlineTextH = 0f;
|
| 1805 | }
|
| 1806 |
|
| 1807 | private static void inlineBackspace() {
|
| 1808 | if (inlineTextBuffer == null) return;
|
| 1809 | int len = inlineTextBuffer.length();
|
| 1810 | if (len <= 0) return;
|
| 1811 | inlineTextBuffer.deleteCharAt(len - 1);
|
| 1812 | }
|
| 1813 |
|
| 1814 | private static void inlinePaste() {
|
| 1815 | if (inlineTextBuffer == null) return;
|
| 1816 | String clip = ClipboardUtil.get();
|
| 1817 | if (clip == null || clip.isEmpty()) return;
|
| 1818 | inlineTextBuffer.append(normalizeInlineText(clip));
|
| 1819 | }
|
| 1820 |
|
| 1821 | public static boolean isTextEditorActive() {
|
| 1822 | return textEditor != null;
|
| 1823 | }
|
| 1824 |
|
| 1825 | public static boolean isPickerActive() {
|
| 1826 | return picker != null || protocolHeuristicsEditor != null;
|
| 1827 | }
|
| 1828 |
|
| 1829 | public static boolean isBlockingModuleKeybinds() {
|
| 1830 | if (!ModuleManager.isEnabled("clickgui")) return false;
|
| 1831 | if (waitingForKey) return true;
|
| 1832 | if (textEditor != null) return true;
|
| 1833 | if (inlineTextOwner != null) return true;
|
| 1834 | if (protocolHeuristicsEditor != null) return true;
|
| 1835 | if (picker != null && picker.isListening()) return true;
|
| 1836 | return ClickGuiSearch.isActive();
|
| 1837 | }
|
| 1838 |
|
| 1839 | public static void processPickerIcons(GuiGraphicsExtractor ctx) {
|
| 1840 | if (pickerIcons.isEmpty()) {
|
| 1841 | pickerIconScissorActive = false;
|
| 1842 | return;
|
| 1843 | }
|
| 1844 | if (ctx == null) {
|
| 1845 | pickerIcons.clear();
|
| 1846 | pickerIconScissorActive = false;
|
| 1847 | return;
|
| 1848 | }
|
| 1849 | if (!(ctx instanceof IGuiGraphics accessor)) {
|
| 1850 | pickerIcons.clear();
|
| 1851 | pickerIconScissorActive = false;
|
| 1852 | return;
|
| 1853 | }
|
| 1854 | Minecraft mc = MC;
|
| 1855 | if (mc == null) {
|
| 1856 | pickerIcons.clear();
|
| 1857 | pickerIconScissorActive = false;
|
| 1858 | return;
|
| 1859 | }
|
| 1860 | int seed = 0;
|
| 1861 | for (PickerIcon icon : pickerIcons) {
|
| 1862 | ItemStack stack = icon.stack();
|
| 1863 | if (stack == null || stack.isEmpty()) continue;
|
| 1864 | boolean clippedGlobal = false;
|
| 1865 | boolean clippedLocal = false;
|
| 1866 | if (icon.hasGlobalClip()) {
|
| 1867 | clippedGlobal = ScissorFunction.pushRaw(
|
| 1868 | icon.globalClipX(),
|
| 1869 | icon.globalClipY(),
|
| 1870 | icon.globalClipW(),
|
| 1871 | icon.globalClipH()
|
| 1872 | );
|
| 1873 | }
|
| 1874 | if (icon.hasClip()) {
|
| 1875 | clippedLocal = ScissorFunction.pushRaw(
|
| 1876 | icon.clipX(),
|
| 1877 | icon.clipY(),
|
| 1878 | icon.clipW(),
|
| 1879 | icon.clipH()
|
| 1880 | );
|
| 1881 | }
|
| 1882 | Renderer2D.COLOR.begin();
|
| 1883 | // Picker screen uses beginUnscaledLogical(), so queued icon coordinates are already logical.
|
| 1884 | Renderer2D.COLOR.item(
|
| 1885 | stack,
|
| 1886 | icon.x(),
|
| 1887 | icon.y(),
|
| 1888 | icon.scale(),
|
| 1889 | seed++,
|
| 1890 | Renderer2D.ITEM_OVERLAY_ALL,
|
| 1891 | null
|
| 1892 | );
|
| 1893 | Renderer2D.COLOR.render();
|
| 1894 | if (clippedLocal) ScissorFunction.pop();
|
| 1895 | if (clippedGlobal) ScissorFunction.pop();
|
| 1896 | }
|
| 1897 | pickerIcons.clear();
|
| 1898 | pickerIconScissorActive = false;
|
| 1899 | }
|
| 1900 |
|
| 1901 | public static void beginPickerIconScissor(float x, float y, float w, float h) {
|
| 1902 | pickerIconScissorActive = true;
|
| 1903 | pickerIconScissorX = x;
|
| 1904 | pickerIconScissorY = y;
|
| 1905 | pickerIconScissorW = w;
|
| 1906 | pickerIconScissorH = h;
|
| 1907 | }
|
| 1908 |
|
| 1909 | public static void endPickerIconScissor() {
|
| 1910 | pickerIconScissorActive = false;
|
| 1911 | }
|
| 1912 |
|
| 1913 | public static void queuePickerIcon(ItemStack stack, float x, float y, float scale) {
|
| 1914 | if (stack == null || stack.isEmpty()) return;
|
| 1915 | pickerIcons.add(new PickerIcon(
|
| 1916 | stack,
|
| 1917 | x,
|
| 1918 | y,
|
| 1919 | scale,
|
| 1920 | currentPickerIconScissorActive(),
|
| 1921 | pickerIconScissorX,
|
| 1922 | pickerIconScissorY,
|
| 1923 | pickerIconScissorW,
|
| 1924 | pickerIconScissorH,
|
| 1925 | false,
|
| 1926 | 0f,
|
| 1927 | 0f,
|
| 1928 | 0f,
|
| 1929 | 0f
|
| 1930 | ));
|
| 1931 | }
|
| 1932 |
|
| 1933 | public static void queuePickerIcon(ItemStack stack,
|
| 1934 | float x,
|
| 1935 | float y,
|
| 1936 | float scale,
|
| 1937 | float clipX,
|
| 1938 | float clipY,
|
| 1939 | float clipW,
|
| 1940 | float clipH) {
|
| 1941 | if (stack == null || stack.isEmpty()) return;
|
| 1942 | boolean hasClip = clipW > 0f && clipH > 0f;
|
| 1943 | pickerIcons.add(new PickerIcon(
|
| 1944 | stack,
|
| 1945 | x,
|
| 1946 | y,
|
| 1947 | scale,
|
| 1948 | currentPickerIconScissorActive(),
|
| 1949 | pickerIconScissorX,
|
| 1950 | pickerIconScissorY,
|
| 1951 | pickerIconScissorW,
|
| 1952 | pickerIconScissorH,
|
| 1953 | hasClip,
|
| 1954 | clipX,
|
| 1955 | clipY,
|
| 1956 | clipW,
|
| 1957 | clipH
|
| 1958 | ));
|
| 1959 | }
|
| 1960 |
|
| 1961 | private static boolean currentPickerIconScissorActive() {
|
| 1962 | return pickerIconScissorActive && pickerIconScissorW > 0f && pickerIconScissorH > 0f;
|
| 1963 | }
|
| 1964 |
|
| 1965 | /**
|
| 1966 | * Materialize cheap ClickGUI screen wrappers and bind already-prewarmed font renderers before
|
| 1967 | * the first user-triggered open. Section discovery itself is owned by ClickGuiSectionManager.
|
| 1968 | */
|
| 1969 | public static void prewarmUiObjects() {
|
| 1970 | ensureFontBindingsCurrent();
|
| 1971 | if (mainScreen == null) mainScreen = new ClickGuiScreen();
|
| 1972 | if (pickerScreen == null) pickerScreen = new ClickGuiPickerScreen();
|
| 1973 | getInterRegular();
|
| 1974 | getInterMedium();
|
| 1975 | getSfMedium();
|
| 1976 | getOnestBold();
|
| 1977 | getMonsterratRegular();
|
| 1978 | }
|
| 1979 | public static void openClickGuiScreen() {
|
| 1980 | if (MC == null) return;
|
| 1981 | if (ClientScreen.current() != null) return;
|
| 1982 | if (mainScreen == null) {
|
| 1983 | mainScreen = new ClickGuiScreen();
|
| 1984 | }
|
| 1985 | GuiSound.OPEN.feedback();
|
| 1986 | ClientScreen.show(MC, mainScreen);
|
| 1987 | }
|
| 1988 |
|
| 1989 | public static void captureMainScreen() {
|
| 1990 | if (MC != null && ClientScreen.current() instanceof ClickGuiScreen cs) {
|
| 1991 | mainScreen = cs;
|
| 1992 | }
|
| 1993 | }
|
| 1994 |
|
| 1995 | public static ClickGuiScreen ensureMainScreen() {
|
| 1996 | if (mainScreen == null) {
|
| 1997 | mainScreen = new ClickGuiScreen();
|
| 1998 | }
|
| 1999 | return mainScreen;
|
| 2000 | }
|
| 2001 |
|
| 2002 | private static void openPickerScreen() {
|
| 2003 | if (MC == null) return;
|
| 2004 | if (ClientScreen.current() instanceof ClickGuiScreen cs) {
|
| 2005 | mainScreen = cs;
|
| 2006 | }
|
| 2007 | if (pickerScreen == null) {
|
| 2008 | pickerScreen = new ClickGuiPickerScreen();
|
| 2009 | }
|
| 2010 | ClientScreen.show(MC, pickerScreen);
|
| 2011 | }
|
| 2012 |
|
| 2013 | public static void clearScreens() {
|
| 2014 | mainScreen = null;
|
| 2015 | pickerScreen = null;
|
| 2016 | SettingsTabRuntime.clearScreens();
|
| 2017 | }
|
| 2018 |
|
| 2019 | public static void shutdownForRuntime() {
|
| 2020 | finishCloseImmediately();
|
| 2021 | clearInlineText();
|
| 2022 | clearPicker();
|
| 2023 | textEditor = null;
|
| 2024 | pickerIcons.clear();
|
| 2025 | pendingBindKeys.clear();
|
| 2026 | waitingForKey = false;
|
| 2027 | keyBindOwner = null;
|
| 2028 | renderer = null;
|
| 2029 | init = false;
|
| 2030 | }
|
| 2031 |
|
| 2032 | public static void openPicker(TextListSetting owner, String title, TextListSetting.PickerMode mode) {
|
| 2033 | if (owner == null) return;
|
| 2034 | clearInlineText();
|
| 2035 | ClickGuiSearch.deactivate();
|
| 2036 | protocolHeuristicsEditor = null;
|
| 2037 | picker = new ClickGuiPickerState(owner, title, mode);
|
| 2038 | openPickerScreen();
|
| 2039 | }
|
| 2040 |
|
| 2041 | public static void openProtocolHeuristicsEditor(ProtocolHeuristicsSetting owner, String title) {
|
| 2042 | if (owner == null) return;
|
| 2043 | clearInlineText();
|
| 2044 | ClickGuiSearch.deactivate();
|
| 2045 | picker = null;
|
| 2046 | protocolHeuristicsEditor = new CombatProtocolHeuristicsEditorState(owner, title);
|
| 2047 | openPickerScreen();
|
| 2048 | }
|
| 2049 |
|
| 2050 | public static void closeProtocolHeuristicsEditor() {
|
| 2051 | closePicker();
|
| 2052 | }
|
| 2053 |
|
| 2054 | public static void closePickerScreen() {
|
| 2055 | closePicker();
|
| 2056 | }
|
| 2057 |
|
| 2058 | private static void closePicker() {
|
| 2059 | picker = null;
|
| 2060 | protocolHeuristicsEditor = null;
|
| 2061 | textEditor = null;
|
| 2062 | if (MC != null && ClientScreen.current() instanceof ClickGuiPickerScreen) {
|
| 2063 | if (mainScreen == null) {
|
| 2064 | mainScreen = new ClickGuiScreen();
|
| 2065 | }
|
| 2066 | ClientScreen.show(MC, mainScreen);
|
| 2067 | }
|
| 2068 | }
|
| 2069 |
|
| 2070 | private static void clearPicker() {
|
| 2071 | picker = null;
|
| 2072 | protocolHeuristicsEditor = null;
|
| 2073 | }
|
| 2074 |
|
| 2075 | private static synchronized void requestConfigSave() {
|
| 2076 | Runnable task = () -> {
|
| 2077 | try {
|
| 2078 | ConfigSerializer.saveAll();
|
| 2079 | } catch (Throwable ignored) {
|
| 2080 | }
|
| 2081 | };
|
| 2082 |
|
| 2083 | if (pendingSaveTask == null || pendingSaveTask.isDone()) {
|
| 2084 | pendingSaveTask = CompletableFuture.runAsync(task);
|
| 2085 | } else {
|
| 2086 | pendingSaveTask = pendingSaveTask.thenRunAsync(task);
|
| 2087 | }
|
| 2088 | }
|
| 2089 |
|
| 2090 | private record ClickGuiTabEntry(String id, String label, ClickGuiSection section) {
|
| 2091 | }
|
| 2092 |
|
| 2093 | public record ClickGuiIslandState(float tabBarX,
|
| 2094 | float tabBarY,
|
| 2095 | float tabBarW,
|
| 2096 | float tabBarH,
|
| 2097 | float activeX,
|
| 2098 | float activeW,
|
| 2099 | float lifecycle,
|
| 2100 | String activeLabel,
|
| 2101 | int tabCount,
|
| 2102 | boolean pickerActive,
|
| 2103 | List<ClickGuiIslandTab> tabs) {
|
| 2104 | }
|
| 2105 |
|
| 2106 | public record ClickGuiIslandTab(String label,
|
| 2107 | float relativeX,
|
| 2108 | float width,
|
| 2109 | boolean active,
|
| 2110 | boolean hovered) {
|
| 2111 | }
|
| 2112 |
|
| 2113 | public static final class VerticalAlphaFadeScope implements AutoCloseable {
|
| 2114 | private final boolean previousEnabled;
|
| 2115 | private final float previousStart;
|
| 2116 | private final float previousEnd;
|
| 2117 | private boolean closed;
|
| 2118 |
|
| 2119 | private VerticalAlphaFadeScope(boolean previousEnabled, float previousStart, float previousEnd) {
|
| 2120 | this.previousEnabled = previousEnabled;
|
| 2121 | this.previousStart = previousStart;
|
| 2122 | this.previousEnd = previousEnd;
|
| 2123 | }
|
| 2124 |
|
| 2125 | @Override
|
| 2126 | public void close() {
|
| 2127 | if (closed) return;
|
| 2128 | closed = true;
|
| 2129 | verticalAlphaFadeEnabled = previousEnabled;
|
| 2130 | verticalAlphaFadeStart = previousStart;
|
| 2131 | verticalAlphaFadeEnd = previousEnd;
|
| 2132 | }
|
| 2133 | }
|
| 2134 |
|
| 2135 | private record TextBatchItem(TextRenderer renderer, String text, float x, float y, float size, int argb,
|
| 2136 | boolean shadow, boolean fadeEnabled, float fadeStart, float fadeEnd) {
|
| 2137 | }
|
| 2138 |
|
| 2139 | private record TextBatchKey(TextRenderer renderer, int sizeBits, boolean shadow) {
|
| 2140 | }
|
| 2141 |
|
| 2142 | private record TextMeasureKey(TextRenderer renderer, int sizeBits, String text) {
|
| 2143 | }
|
| 2144 |
|
| 2145 | private record TextHeightKey(TextRenderer renderer, int sizeBits) {
|
| 2146 | }
|
| 2147 |
|
| 2148 | private record PickerIcon(ItemStack stack,
|
| 2149 | float x,
|
| 2150 | float y,
|
| 2151 | float scale,
|
| 2152 | boolean hasGlobalClip,
|
| 2153 | float globalClipX,
|
| 2154 | float globalClipY,
|
| 2155 | float globalClipW,
|
| 2156 | float globalClipH,
|
| 2157 | boolean hasClip,
|
| 2158 | float clipX,
|
| 2159 | float clipY,
|
| 2160 | float clipW,
|
| 2161 | float clipH) {
|
| 2162 | }
|
| 2163 |
|
| 2164 | }
|
| 2165 |
|