|
| 1 | +package com.classictrashcode.suxaddons.client.hunting; |
| 2 | + |
| 3 | + |
| 4 | +import com.classictrashcode.suxaddons.client.config.Config; |
| 5 | +import com.classictrashcode.suxaddons.client.config.ConfigManager; |
| 6 | +import net.minecraft.client.Minecraft; |
| 7 | +import net.minecraft.client.gui.GuiGraphics; |
| 8 | +import net.minecraft.network.chat.Component; |
| 9 | + |
| 10 | +public class AutoFusionOverlay { |
| 11 | + private static final int OVERLAY_WIDTH = 200; |
| 12 | + private static final int OVERLAY_HEIGHT = 140; |
| 13 | + private static final int PADDING = 10; |
| 14 | + private static final int LINE_HEIGHT = 12; |
| 15 | + |
| 16 | + // Button dimensions |
| 17 | + private static final int BUTTON_WIDTH = 80; |
| 18 | + private static final int BUTTON_HEIGHT = 24; |
| 19 | + |
| 20 | + // State for button hover detection |
| 21 | + private static int buttonX; |
| 22 | + private static int buttonY; |
| 23 | + |
| 24 | + public static void renderOverlay(GuiGraphics context, int screenWidth, int screenHeight, int mouseX, int mouseY) { |
| 25 | + if (!AutoFusion.isFusionMenu || !ConfigManager.getConfig().hunting.autoFusion.enabled) { |
| 26 | + return; |
| 27 | + } |
| 28 | + |
| 29 | + // Get theme colors from config |
| 30 | + var theme = ConfigManager.getConfig().guiTheme; |
| 31 | + int backgroundColor = theme.parseColor(theme.surfaceColor); |
| 32 | + int borderColor = theme.parseColor(theme.dividerColor); |
| 33 | + int textColor = theme.parseColor(theme.textPrimaryColor); |
| 34 | + int textSecondaryColor = theme.parseColor(theme.textSecondaryColor); |
| 35 | + |
| 36 | + int overlayX = PADDING; |
| 37 | + int overlayY = PADDING + 20; // Add extra padding from top |
| 38 | + |
| 39 | + // Draw background with slight transparency |
| 40 | + int bgColorWithAlpha = (backgroundColor & 0x00FFFFFF) | 0xE6000000; // 90% opacity |
| 41 | + context.fill(overlayX, overlayY, overlayX + OVERLAY_WIDTH, overlayY + OVERLAY_HEIGHT, bgColorWithAlpha); |
| 42 | + |
| 43 | + // Draw colored title bar |
| 44 | + int titleBarHeight = 22; |
| 45 | + int titleBarColor = theme.parseColor(theme.primaryColor); |
| 46 | + context.fill(overlayX, overlayY, overlayX + OVERLAY_WIDTH, overlayY + titleBarHeight, titleBarColor); |
| 47 | + |
| 48 | + // Draw border |
| 49 | + drawBorder(context, overlayX, overlayY, OVERLAY_WIDTH, OVERLAY_HEIGHT, borderColor); |
| 50 | + |
| 51 | + // Draw title in white on colored bar |
| 52 | + context.drawString( |
| 53 | + Minecraft.getInstance().font, |
| 54 | + Component.literal("Auto Fusion"), |
| 55 | + overlayX + PADDING, |
| 56 | + overlayY + (titleBarHeight - 8) / 2, // Center vertically in title bar |
| 57 | + 0xFFFFFFFF, // White text |
| 58 | + false |
| 59 | + ); |
| 60 | + |
| 61 | + // Content starts below title bar |
| 62 | + int currentY = overlayY + titleBarHeight + 8; |
| 63 | + |
| 64 | + // Draw status |
| 65 | + int statusColor = AutoFusion.running ? theme.parseColor(theme.successColor) : textSecondaryColor; |
| 66 | + context.drawString( |
| 67 | + Minecraft.getInstance().font, |
| 68 | + Component.literal("Status: "), |
| 69 | + overlayX + PADDING, |
| 70 | + currentY, |
| 71 | + textColor, |
| 72 | + false |
| 73 | + ); |
| 74 | + context.drawString( |
| 75 | + Minecraft.getInstance().font, |
| 76 | + Component.literal(AutoFusion.running ? "Running" : "Stopped"), |
| 77 | + overlayX + PADDING + Minecraft.getInstance().font.width("Status: "), |
| 78 | + currentY, |
| 79 | + statusColor, |
| 80 | + false |
| 81 | + ); |
| 82 | + |
| 83 | + // Draw completed cycles |
| 84 | + currentY += LINE_HEIGHT + 2; |
| 85 | + context.drawString( |
| 86 | + Minecraft.getInstance().font, |
| 87 | + Component.literal("Cycles: " + AutoFusion.completedCycles), |
| 88 | + overlayX + PADDING, |
| 89 | + currentY, |
| 90 | + textColor, |
| 91 | + false |
| 92 | + ); |
| 93 | + |
| 94 | + // Draw current step |
| 95 | + currentY += LINE_HEIGHT + 2; |
| 96 | + int actionStep = AutoFusion.actionStep; |
| 97 | + context.drawString( |
| 98 | + Minecraft.getInstance().font, |
| 99 | + Component.literal("Step: " + actionStep + "/2"), |
| 100 | + overlayX + PADDING, |
| 101 | + currentY, |
| 102 | + textColor, |
| 103 | + false |
| 104 | + ); |
| 105 | + |
| 106 | + // Draw delay settings |
| 107 | + currentY += LINE_HEIGHT + 4; |
| 108 | + int actionDelay = ConfigManager.getConfig().hunting.autoFusion.actionDelayTicks; |
| 109 | + int longDelay = ConfigManager.getConfig().hunting.autoFusion.longDelayTicks; |
| 110 | + context.drawString( |
| 111 | + Minecraft.getInstance().font, |
| 112 | + Component.literal("Action Delay: " + actionDelay + "t"), |
| 113 | + overlayX + PADDING, |
| 114 | + currentY, |
| 115 | + textSecondaryColor, |
| 116 | + false |
| 117 | + ); |
| 118 | + currentY += LINE_HEIGHT; |
| 119 | + context.drawString( |
| 120 | + Minecraft.getInstance().font, |
| 121 | + Component.literal("Long Delay: " + longDelay + "t"), |
| 122 | + overlayX + PADDING, |
| 123 | + currentY, |
| 124 | + textSecondaryColor, |
| 125 | + false |
| 126 | + ); |
| 127 | + |
| 128 | + // Draw toggle button |
| 129 | + currentY += LINE_HEIGHT + 6; |
| 130 | + buttonX = overlayX + (OVERLAY_WIDTH - BUTTON_WIDTH) / 2; |
| 131 | + buttonY = currentY; |
| 132 | + |
| 133 | + boolean hovered = isMouseOver(mouseX, mouseY, buttonX, buttonY, BUTTON_WIDTH, BUTTON_HEIGHT); |
| 134 | + drawToggleButton(context, buttonX, buttonY, hovered); |
| 135 | + } |
| 136 | + |
| 137 | + private static void drawBorder(GuiGraphics context, int x, int y, int width, int height, int color) { |
| 138 | + // Top |
| 139 | + context.fill(x, y, x + width, y + 1, color); |
| 140 | + // Bottom |
| 141 | + context.fill(x, y + height - 1, x + width, y + height, color); |
| 142 | + // Left |
| 143 | + context.fill(x, y, x + 1, y + height, color); |
| 144 | + // Right |
| 145 | + context.fill(x + width - 1, y, x + width, y + height, color); |
| 146 | + } |
| 147 | + private static void drawToggleButton(GuiGraphics context, int x, int y, boolean hovered) { |
| 148 | + var theme = ConfigManager.getConfig().guiTheme; |
| 149 | + |
| 150 | + int buttonColor; |
| 151 | + if (AutoFusion.running) { |
| 152 | + // Stop button - use error color |
| 153 | + buttonColor = hovered ? |
| 154 | + theme.parseColor(theme.errorColor) : |
| 155 | + darken(theme.parseColor(theme.errorColor), 0.8f); |
| 156 | + } else { |
| 157 | + // Start button - use success color |
| 158 | + buttonColor = hovered ? |
| 159 | + theme.parseColor(theme.buttonHoverColor) : |
| 160 | + theme.parseColor(theme.buttonNormalColor); |
| 161 | + } |
| 162 | + |
| 163 | + // Draw button background |
| 164 | + context.fill(x, y, x + BUTTON_WIDTH, y + BUTTON_HEIGHT, buttonColor); |
| 165 | + |
| 166 | + // Draw button border |
| 167 | + int borderColor = theme.parseColor(theme.dividerColor); |
| 168 | + drawBorder(context, x, y, BUTTON_WIDTH, BUTTON_HEIGHT, borderColor); |
| 169 | + |
| 170 | + // Draw button text |
| 171 | + String buttonText = AutoFusion.running ? "Stop" : "Start"; |
| 172 | + int textWidth = Minecraft.getInstance().font.width(buttonText); |
| 173 | + int textX = x + (BUTTON_WIDTH - textWidth) / 2; |
| 174 | + int textY = y + (BUTTON_HEIGHT - 8) / 2; |
| 175 | + |
| 176 | + context.drawString( |
| 177 | + Minecraft.getInstance().font, |
| 178 | + Component.literal(buttonText), |
| 179 | + textX, |
| 180 | + textY, |
| 181 | + 0xFFFFFFFF, |
| 182 | + false |
| 183 | + ); |
| 184 | + } |
| 185 | + |
| 186 | + private static boolean isMouseOver(int mouseX, int mouseY, int x, int y, int width, int height) { |
| 187 | + return mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height; |
| 188 | + } |
| 189 | + |
| 190 | + public static boolean handleClick(int mouseX, int mouseY) { |
| 191 | + if (!AutoFusion.isFusionMenu) { |
| 192 | + return false; |
| 193 | + } |
| 194 | + |
| 195 | + if (isMouseOver(mouseX, mouseY, buttonX, buttonY, BUTTON_WIDTH, BUTTON_HEIGHT)) { |
| 196 | + if (!ConfigManager.getConfig().hunting.autoFusion.enabled) { |
| 197 | + return true; // Consume click but don't toggle |
| 198 | + } |
| 199 | + |
| 200 | + AutoFusion.running = !AutoFusion.running; |
| 201 | + if (!AutoFusion.running){ |
| 202 | + AutoFusion.reset(); |
| 203 | + } |
| 204 | + return true; |
| 205 | + } |
| 206 | + |
| 207 | + return false; |
| 208 | + } |
| 209 | + |
| 210 | + private static int darken(int color, float factor) { |
| 211 | + int alpha = (color >> 24) & 0xFF; |
| 212 | + int red = (int) (((color >> 16) & 0xFF) * factor); |
| 213 | + int green = (int) (((color >> 8) & 0xFF) * factor); |
| 214 | + int blue = (int) ((color & 0xFF) * factor); |
| 215 | + |
| 216 | + return (alpha << 24) | (red << 16) | (green << 8) | blue; |
| 217 | + } |
| 218 | +} |
0 commit comments