/** * ModernLayout * * Coordinates and hit-testing for the modern resizable layout. * Pure Java: no java.awt or android.* imports, allowing 100% shared code * between Desktop and Android. */ public final class ModernLayout { public static final int TARGET_DEFAULT = 0; public static final int TARGET_VIEWPORT = 1; public static final int TARGET_TAB = 2; public static final int TARGET_CHAT = 3; public static final int TARGET_MINIMAP = 4; public static int windowWidth = 765; public static int windowHeight = 503; public static boolean inGame = false; private ModernLayout() {} public static void updateWindowSize(int w, int h) { if (w < 765) w = 765; if (h < 503) h = 503; windowWidth = w; windowHeight = h; } public static int hit(int x, int y) { if (!ClientSettings.isModernLayout() || !inGame) { return TARGET_DEFAULT; } int w = windowWidth; int h = windowHeight; // Minimap: top right (from w - 249 to w, y from 0 to 168) if (x >= w - 249 && y <= 168) { int localX = x - (w - 249); int localY = y; if (isInsideMinimap(localX, localY)) { return TARGET_MINIMAP; } } // Tab block: bottom right (from w - 249 to w, y from h - 343 to h) if (x >= w - 249 && y >= h - 343) { int localX = x - (w - 249); int localY = y - (h - 343); if (isInsideTabArea(localX, localY)) { return TARGET_TAB; } } // Chatbox: bottom left (from 0 to 519, y from h - 165 to h) if (x <= 519 && y >= h - 165) { return TARGET_CHAT; } return TARGET_VIEWPORT; } // Symmetrical corner inset profile for dy = 0..33 from top (sy=0) or bottom (sy=334) of the 234x335 stone ring private static final int[] TAB_CORNER_DX = { 234, // dy = 0 (outermost 1px row is transparent) 28, 26, 24, 22, 20, 19, 17, 14, 13, 11, 10, 9, 8, 8, 7, 7, 7, 7, 6, 6, 6, 5, 5, 5, 5, 4, 4, 3, 3, 3, 3, 2, 2 }; public static boolean isInsideTabArea(int localX, int localY) { int sx = localX - 15; int sy = localY - 8; if (sx <= 0 || sx >= 233 || sy <= 0 || sy >= 334) { return false; } int dy = Math.min(sy, 334 - sy); int dx = (dy < TAB_CORNER_DX.length) ? TAB_CORNER_DX[dy] : 1; return sx >= dx && sx <= (233 - dx); } public static boolean isInsideMinimap(int localX, int localY) { // 1. Compass circular area (centered at (16, 16), radius 16) int cDx = localX - 16; int cDy = localY - 16; if (cDx * cDx + cDy * cDy <= 16 * 16) { return true; } // 2. Minimap elliptical walking area (centered at (132, 84), Rx=76, Ry=78) float mDx = (localX - 132) / 76f; float mDy = (localY - 84) / 78f; return (mDx * mDx + mDy * mDy) <= 1.0f; } /** * Computes aspect-ratio-preserved scaled bounds { originX, originY, scaledW, scaledH } * for a 765x503 canvas (login/title screen or welcome screen) inside window (w, h), * matching the Android client's welcomeScale behavior. */ public static int[] getScaledScreenBounds(int w, int h) { float scale = Math.min((float) w / 765f, (float) h / 503f); int scaledW = Math.round(765 * scale); int scaledH = Math.round(503 * scale); int originX = Math.max(0, (w - scaledW) / 2); int originY = Math.max(0, (h - scaledH) / 2); return new int[] { originX, originY, scaledW, scaledH }; } /** * Maps window coordinates (x, y) to fixed-layout game coordinates (used by input processing). */ public static int[] toGameCoords(int area, int x, int y) { if (!ClientSettings.isModernLayout()) { return new int[] { x, y }; } int w = windowWidth; int h = windowHeight; if (!inGame) { int[] b = getScaledScreenBounds(w, h); int gx = ((x - b[0]) * 765) / Math.max(1, b[2]); int gy = ((y - b[1]) * 503) / Math.max(1, b[3]); return new int[] { gx, gy }; } switch (area) { case TARGET_MINIMAP: return new int[] { x - (w - 765), y }; case TARGET_TAB: return new int[] { x - (w - 765), y - (h - 503) }; case TARGET_CHAT: return new int[] { x, y - (h - 503) }; case TARGET_VIEWPORT: default: return new int[] { x, y }; } } /** * Maps classic fixed coordinates (fixedX, fixedY) of a UI element/producer to window coordinates. * Returns null if the element should be hidden/skipped in modern layout (e.g. fixed outer border frames). */ public static int[] toWindow(int fixedX, int fixedY, int width, int height) { if (!ClientSettings.isModernLayout()) { return new int[] { fixedX, fixedY }; } int w = windowWidth; int h = windowHeight; if (!inGame || (width == 765 && height == 503 && fixedX == 0 && fixedY == 0)) { int[] b = getScaledScreenBounds(w, h); int x0 = b[0] + (fixedX * b[2]) / 765; int y0 = b[1] + (fixedY * b[3]) / 503; int x1 = b[0] + ((fixedX + width) * b[2]) / 765; int y1 = b[1] + ((fixedY + height) * b[3]) / 503; return new int[] { x0, y0, x1 - x0, y1 - y0 }; } // 3D Viewport: (4, 4) in fixed mode -> (0, 0) edge-to-edge in modern mode if (fixedX == 4 && fixedY == 4) { return new int[] { 0, 0 }; } // Minimap and top-right stone border pieces: // Handled cleanly via modern minimap composite in desktop overlays; suppress raw legacy pieces if (fixedX >= 516 && fixedY < 160) { return null; } // Chatbox outer stone borders and raw producers: // backVmidIP2_2 top border (fixedX = 0, fixedY = 338) // backLeftIP2 left border (fixedX = 0, fixedY = 357) // backVmidIP3 right border (fixedX = 496, fixedY = 357) // Parchment 1166 (fixedX = 17, fixedY = 357) // Buttons 1123 (fixedX = 0, fixedY = 453) // All handled cleanly via modern chat composite in DesktopHooks.drawModernChat if (fixedX == 0 && fixedY == 338) { return null; } if ((fixedX == 0 || fixedX == 496 || fixedX == 17) && fixedY == 357) { return null; } if (fixedX == 0 && fixedY == 453) { return null; } // Tab block elements: // top bar 1125 (516, 160), left pillar backVmidIP2 (516, 205), // tab body 1163 (553, 205), right pillar backRightIP2 (743, 205), // bottom bar 1124 (496, 466) // All handled cleanly via unified modern tab composite in DesktopHooks.drawModernTab if (fixedX >= 496 && fixedY >= 160) { return null; } // Fixed outer frame borders that should not be drawn in modern layout return null; } }