| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- using UnityEngine;
- using UnityEngine.UI;
- namespace DevilLink2.Presentation
- {
- /// <summary>Inset surface details stay inside the board's existing padding and never intercept input.</summary>
- [DisallowMultipleComponent]
- public sealed class BoardSurface : BaseMeshEffect
- {
- private BoardLayout layout;
- private int columns, rows;
- public void SetGrid(BoardLayout value, int columnCount, int rowCount)
- {
- if (columns == columnCount && rows == rowCount && layout.Size == value.Size && layout.TileSize == value.TileSize) return;
- layout = value; columns = columnCount; rows = rowCount; graphic.SetVerticesDirty();
- }
- public override void ModifyMesh(VertexHelper mesh)
- {
- if (!IsActive()) return;
- var rect = ((RectTransform)transform).rect;
- mesh.Clear();
- // Gameplay uses the one shared outer stage. The matrix surface contributes
- // only per-cell slots; no matrix-sized rectangle, fill or inner frame remains.
- if (columns <= 0 || rows <= 0) {
- // Preserve the standalone legacy surface, which has no configured grid/stage.
- Quad(mesh, rect, new Color32(18,20,37,255), new Color32(11,14,27,255));
- Frame(mesh, rect, new Color32(110,94,62,255));
- var inner = new Rect(rect.x + 4, rect.y + 4, rect.width - 8, rect.height - 8);
- if (inner.width > 2 && inner.height > 2) Frame(mesh, inner, new Color32(37,40,62,255));
- return;
- }
- if (columns > 0 && rows > 0) {
- for (int r = 0; r < rows; r++) for (int c = 0; c < columns; c++) {
- var p = layout.TilePosition(r, c);
- var cell = new Rect(rect.xMin + p.x, rect.yMax + p.y - layout.TileSize, layout.TileSize, layout.TileSize);
- Quad(mesh, cell, new Color32(32, 25, 46, 255), new Color32(23, 19, 35, 255));
- Frame(mesh, cell, new Color32(48, 39, 59, 255));
- }
- }
- }
- private static void Frame(VertexHelper mesh, Rect rect, Color32 color)
- {
- if (rect.width < 2 || rect.height < 2) return;
- Quad(mesh, new Rect(rect.x, rect.y, rect.width, 1), color, color);
- Quad(mesh, new Rect(rect.x, rect.yMax - 1, rect.width, 1), color, color);
- Quad(mesh, new Rect(rect.x, rect.y + 1, 1, rect.height - 2), color, color);
- Quad(mesh, new Rect(rect.xMax - 1, rect.y + 1, 1, rect.height - 2), color, color);
- }
- private static void Quad(VertexHelper mesh, Rect rect, Color32 top, Color32 bottom)
- {
- int start = mesh.currentVertCount;
- mesh.AddVert(new Vector3(rect.xMin, rect.yMin), bottom, Vector2.zero);
- mesh.AddVert(new Vector3(rect.xMin, rect.yMax), top, Vector2.zero);
- mesh.AddVert(new Vector3(rect.xMax, rect.yMax), top, Vector2.zero);
- mesh.AddVert(new Vector3(rect.xMax, rect.yMin), bottom, Vector2.zero);
- mesh.AddTriangle(start, start + 1, start + 2);
- mesh.AddTriangle(start + 2, start + 3, start);
- }
- }
- }
|