Tile highlight texture system with cursor + hover glow

Server / DB:
- New HighlightConfig entity (catalog.highlight_configs): one row per
  highlight type (Movement/Attack/Ability/Terramorpha/Selector). Supports
  static texture URL or animated (base folder + frame count + FPS) with a
  FallbackHex RGBA colour for when no texture is configured.
- EF migration AddHighlightConfig.
- CosmeticType.HighlightPack added; AssetCdnUrl stores serialised JSON with
  per-type texture config so players can buy full highlight packs in the Bazaar.
- content.get_highlight_config handler in SOR.Content; response DTOs added to
  ContentMessages.cs; handler registered in ServiceRegistration.

Admin:
- /content/highlights page: inline editor for all five highlight types
  (CDN path, animated toggle, frame count, FPS, fallback hex with swatch).
  Upserts rows — no delete needed since there is always exactly one row per type.
- Highlights nav link added to Content section in NavMenu.
- CosmeticEditor: HighlightPack type renders a per-type table (Movement/
  Attack/Ability/Terramorpha/Selector), serialising to JSON in AssetCdnUrl.

Client (Godot):
- HighlightConfig autoload: fetches content.get_highlight_config on startup,
  caches to user://highlight_config.json. Provides get_texture(type) and
  get_color(type). Supports set_override/clear_override/apply_cosmetic_pack
  for cosmetic and settings overrides.
- Settings autoload: highlight_overrides Dictionary persisted in settings.cfg.
  set_highlight_override/clear_highlight_override push into HighlightConfig.
- settings_screen.gd: programmatic "Highlight Texture Overrides" section added
  with a LineEdit + Reset button per type; appended to Sections VBoxContainer.
- game_screen.gd:
  • _add_highlight() rewritten to use flat PlaneMesh quads with textured
    StandardMaterial3D. Accepts a string type key ("movement", "attack",
    "ability", "terramorpha", "selector") instead of a Color constant.
  • _cursor_highlight + _hover_team_overlay: two permanently-allocated quads
    that are never freed. The selector highlights the tile under the mouse at
    all times; the team overlay shows a coloured tint when hovering an occupied
    tile. Both are preserved across _clear_highlights() and _build_board().
  • _update_hover(): called on every InputEventMouseMotion event. Moves the
    selector quad, shows the team-colour overlay when hovering an occupied tile,
    and boosts MeshInstance3D emission on the hovered unit via
    set_surface_override_material (reset when hover leaves).
  • All existing _highlight_tiles() / _add_highlight() callers updated from
    HI_* Color constants to type key strings.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
dingo
2026-03-23 06:50:00 -04:00
co-authored by Claude Happy
parent 9c44657deb
commit fe293f6bee
17 changed files with 1655 additions and 67 deletions
@@ -127,6 +127,11 @@
<i class="bi bi-cloud-sun me-2"></i>Skyboxes
</NavLink>
</li>
<li class="nav-item">
<NavLink class="nav-link text-white-50 py-1" href="/content/highlights">
<i class="bi bi-grid-fill me-2"></i>Highlights
</NavLink>
</li>
</ul>
</li>
<li class="nav-item">
@@ -5,6 +5,7 @@
@using SOR.Database.Contexts
@using SOR.Database.Entities.Bazaar
@using SOR.Database.Enums
@using System.Text.Json.Nodes
@inject BazaarDbContext Db
@inject CatalogDbContext CatalogDb
@inject SOR.Cdn.ICdnClient Cdn
@@ -110,23 +111,84 @@ else
</div>
</div>
<!-- Asset -->
<div class="card shadow-sm">
<div class="card-header fw-medium">Asset URL (art / model)</div>
<div class="card-body">
<input @bind="_cosmetic.AssetCdnUrl"
class="form-control form-control-sm mb-2"
placeholder="https://cdn.sor.gg/…" />
<label class="btn btn-sm btn-outline-primary @(_uploadingAsset ? "disabled" : "")">
@if (_uploadingAsset) { <span class="spinner-border spinner-border-sm"></span> }
else { <i class="bi bi-upload"></i> }
<span class="ms-1">Upload</span>
<InputFile style="display:none"
accept="image/*,.glb,.gltf,.fbx"
OnChange="UploadAssetAsync" />
</label>
<!-- Asset — normal types -->
@if (_cosmetic.CosmeticType != CosmeticType.HighlightPack)
{
<div class="card shadow-sm">
<div class="card-header fw-medium">Asset URL (art / model)</div>
<div class="card-body">
<input @bind="_cosmetic.AssetCdnUrl"
class="form-control form-control-sm mb-2"
placeholder="https://cdn.sor.gg/…" />
<label class="btn btn-sm btn-outline-primary @(_uploadingAsset ? "disabled" : "")">
@if (_uploadingAsset) { <span class="spinner-border spinner-border-sm"></span> }
else { <i class="bi bi-upload"></i> }
<span class="ms-1">Upload</span>
<InputFile style="display:none"
accept="image/*,.glb,.gltf,.fbx"
OnChange="UploadAssetAsync" />
</label>
</div>
</div>
</div>
}
else
{
<!-- HighlightPack — per-type texture editor -->
<div class="card shadow-sm">
<div class="card-header fw-medium">Highlight Pack Textures</div>
<div class="card-body p-0">
<table class="table table-sm mb-0 align-middle">
<thead>
<tr>
<th style="width:110px">Type</th>
<th>CDN Path</th>
<th style="width:80px" class="text-center">Animated</th>
<th style="width:65px">Frames</th>
<th style="width:55px">FPS</th>
<th style="width:105px">Fallback Hex</th>
</tr>
</thead>
<tbody>
@foreach (var key in _packKeys)
{
var k = key;
var p = _highlightPack[k];
<tr>
<td class="fw-medium">@k</td>
<td>
<input value="@p.CdnPath"
@onchange='e => p.CdnPath = e.Value?.ToString() ?? ""'
class="form-control form-control-sm font-monospace"
placeholder="https://cdn.sor.gg/…" />
</td>
<td class="text-center">
<input type="checkbox" class="form-check-input"
checked="@p.IsAnimated"
@onchange='e => p.IsAnimated = (bool)(e.Value ?? false)' />
</td>
<td>
<input value="@p.FrameCount" type="number" min="1" max="256"
@onchange='e => p.FrameCount = int.TryParse(e.Value?.ToString(), out var n) ? n : 1'
class="form-control form-control-sm" />
</td>
<td>
<input value="@p.Fps" type="number" min="1" max="60" step="0.5"
@onchange='e => p.Fps = float.TryParse(e.Value?.ToString(), out var f) ? f : 12f'
class="form-control form-control-sm" />
</td>
<td>
<input value="@p.FallbackHex"
@onchange='e => p.FallbackHex = e.Value?.ToString() ?? "#FFFFFF66"'
class="form-control form-control-sm font-monospace"
placeholder="#RRGGBBAA" />
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
}
</div>
</div>
@@ -152,6 +214,25 @@ else
@code {
[Parameter] public Guid? Id { get; set; }
private sealed class PackEntry
{
public string CdnPath { get; set; } = string.Empty;
public bool IsAnimated { get; set; }
public int FrameCount { get; set; } = 1;
public float Fps { get; set; } = 12f;
public string FallbackHex{ get; set; } = "#FFFFFF66";
}
private static readonly string[] _packKeys = ["Movement", "Attack", "Ability", "Terramorpha", "Selector"];
private static readonly Dictionary<string, string> _packDefaultHex = new()
{
["Movement"] = "#33FF3366",
["Attack"] = "#FF404080",
["Ability"] = "#3380FF66",
["Terramorpha"] = "#FF990073",
["Selector"] = "#FFFFFF40",
};
private bool IsNew => !Id.HasValue;
private Cosmetic? _cosmetic;
private string _cosmeticTypeStr = nameof(CosmeticType.CardBack);
@@ -159,6 +240,11 @@ else
private bool _saving, _uploadingPreview, _uploadingAsset;
private string? _error;
// HighlightPack state — one entry per type.
private Dictionary<string, PackEntry> _highlightPack = _packKeys.ToDictionary(
k => k,
k => new PackEntry { FallbackHex = _packDefaultHex.GetValueOrDefault(k, "#FFFFFF66") });
protected override async Task OnInitializedAsync()
{
if (IsNew)
@@ -171,6 +257,8 @@ else
if (_cosmetic is null) { Nav.NavigateTo("/bazaar/cosmetics"); return; }
_cosmeticTypeStr = _cosmetic.CosmeticType.ToString();
_cardDefinitionIdStr = _cosmetic.CardDefinitionId?.ToString() ?? string.Empty;
if (_cosmetic.CosmeticType == CosmeticType.HighlightPack)
_ParseHighlightPack(_cosmetic.AssetCdnUrl);
}
}
@@ -202,18 +290,69 @@ else
finally { _uploadingAsset = false; }
}
private void _ParseHighlightPack(string json)
{
_highlightPack = _packKeys.ToDictionary(
k => k,
k => new PackEntry { FallbackHex = _packDefaultHex.GetValueOrDefault(k, "#FFFFFF66") });
try
{
var root = JsonNode.Parse(json) as JsonObject;
if (root is null) return;
foreach (var key in _packKeys)
{
var lk = key.ToLowerInvariant();
if (root[lk] is JsonObject o)
{
_highlightPack[key] = new PackEntry
{
CdnPath = o["cdnPath"]?.GetValue<string>() ?? "",
IsAnimated = o["isAnimated"]?.GetValue<bool>() ?? false,
FrameCount = o["frameCount"]?.GetValue<int>() ?? 1,
Fps = (float)(o["fps"]?.GetValue<double>() ?? 12.0),
FallbackHex = o["fallbackHex"]?.GetValue<string>() ?? _packDefaultHex.GetValueOrDefault(key, "#FFFFFF66"),
};
}
}
}
catch { /* malformed JSON — keep defaults */ }
}
private string _SerializeHighlightPack()
{
var root = new JsonObject();
foreach (var key in _packKeys)
{
var p = _highlightPack[key];
root[key.ToLowerInvariant()] = new JsonObject
{
["cdnPath"] = p.CdnPath,
["isAnimated"] = p.IsAnimated,
["frameCount"] = p.FrameCount,
["fps"] = p.Fps,
["fallbackHex"] = p.FallbackHex,
};
}
return root.ToJsonString();
}
private async Task SaveAsync()
{
_error = null;
if (string.IsNullOrWhiteSpace(_cosmetic!.Name))
{ _error = "Name is required."; return; }
if (string.IsNullOrWhiteSpace(_cosmetic.AssetCdnUrl))
{ _error = "Asset URL is required."; return; }
if (!Enum.TryParse<CosmeticType>(_cosmeticTypeStr, out var t))
{ _error = "Invalid cosmetic type."; return; }
_cosmetic.CosmeticType = t;
// For HighlightPack, AssetCdnUrl holds the serialized JSON pack.
if (t == CosmeticType.HighlightPack)
_cosmetic.AssetCdnUrl = _SerializeHighlightPack();
if (string.IsNullOrWhiteSpace(_cosmetic.AssetCdnUrl))
{ _error = "Asset URL is required."; return; }
_cosmetic.CardDefinitionId = string.IsNullOrWhiteSpace(_cardDefinitionIdStr) ? null
: Guid.TryParse(_cardDefinitionIdStr, out var g) ? g : null;
@@ -0,0 +1,194 @@
@page "/content/highlights"
@attribute [Authorize(Roles = "Admin,SuperAdmin")]
@using Microsoft.EntityFrameworkCore
@using SOR.Database.Contexts
@using SOR.Database.Entities.Catalog
@inject CatalogDbContext Db
<PageTitle>Highlight Textures – SOR Admin</PageTitle>
<div class="d-flex justify-content-between align-items-center mb-4">
<div>
<h1 class="mb-0">Tile Highlight Textures</h1>
<div class="text-muted small">
Configure textures for each battlefield tile highlight type. The client applies these
as flat quads on top of tiles. Leave CdnPath empty to use the fallback colour only.
</div>
</div>
<button class="btn btn-outline-secondary btn-sm" @onclick="LoadAsync" disabled="@_loading">
<i class="bi bi-arrow-clockwise me-1"></i>Refresh
</button>
</div>
@if (_message is not null)
{
<div class="alert @(_isError ? "alert-danger" : "alert-success") alert-dismissible">
@_message
<button type="button" class="btn-close" @onclick='() => _message = null'></button>
</div>
}
@if (_loading)
{
<p class="text-muted">Loading…</p>
}
else
{
<div class="row g-3">
@foreach (var row in _rows)
{
var r = row;
<div class="col-12">
<div class="card shadow-sm">
<div class="card-header d-flex align-items-center gap-2">
<span class="fw-medium">@r.Config.HighlightType</span>
@{
var swatch = r.Config.FallbackHex;
if (swatch.Length == 9) swatch = swatch[..7]; // strip alpha for CSS
}
<span class="rounded-2 border"
style="display:inline-block;width:18px;height:18px;background:@swatch;"></span>
<span class="text-muted small fst-italic">@r.Config.FallbackHex</span>
</div>
<div class="card-body">
<div class="row g-3 align-items-end">
<div class="col-md-5">
<label class="form-label small">CDN Path / URL</label>
<input @bind='r.Config.CdnPath'
class="form-control form-control-sm font-monospace"
placeholder="https://cdn.sor.gg/highlights/… (leave empty for colour only)" />
</div>
<div class="col-md-2">
<label class="form-label small">Fallback Hex</label>
<input @bind='r.Config.FallbackHex'
class="form-control form-control-sm font-monospace"
placeholder="#RRGGBBAA" />
</div>
<div class="col-auto d-flex align-items-end gap-3 pb-1">
<div class="form-check mb-0">
<input @bind='r.Config.IsAnimated' type="checkbox"
class="form-check-input" id="@("anim_" + r.Config.HighlightType)" />
<label class="form-check-label small"
for="@("anim_" + r.Config.HighlightType)">Animated</label>
</div>
</div>
@if (r.Config.IsAnimated)
{
<div class="col-md-1">
<label class="form-label small">Frames</label>
<input @bind='r.Config.FrameCount' type="number"
class="form-control form-control-sm" min="1" max="256" />
</div>
<div class="col-md-1">
<label class="form-label small">FPS</label>
<input @bind='r.Config.Fps' type="number"
class="form-control form-control-sm" min="1" max="60" step="0.5" />
</div>
}
<div class="col-auto ms-auto d-flex align-items-end pb-0">
<button class="btn btn-sm btn-outline-primary"
@onclick='() => SaveRowAsync(r)'>
<i class="bi bi-floppy me-1"></i>Save
</button>
</div>
</div>
@if (r.Config.IsAnimated && !string.IsNullOrEmpty(r.Config.CdnPath))
{
<div class="mt-2 text-muted small">
Frames served at: <code>@r.Config.CdnPath/0.png</code> …
<code>@r.Config.CdnPath/@(r.Config.FrameCount - 1).png</code>
</div>
}
else if (!string.IsNullOrEmpty(r.Config.CdnPath))
{
<div class="mt-2">
<img src="@r.Config.CdnPath" alt="preview"
style="max-height:48px;max-width:200px;border-radius:4px;border:1px solid #444" />
</div>
}
</div>
</div>
</div>
}
</div>
}
@code {
private sealed class HighlightRow { public HighlightConfig Config { get; set; } = null!; }
private static readonly string[] Types = ["Movement", "Attack", "Ability", "Terramorpha", "Selector"];
private static readonly Dictionary<string, string> DefaultHex = new()
{
["Movement"] = "#33FF3366",
["Attack"] = "#FF404080",
["Ability"] = "#3380FF66",
["Terramorpha"]= "#FF990073",
["Selector"] = "#FFFFFF40",
};
private List<HighlightRow> _rows = new();
private bool _loading = true;
private string? _message;
private bool _isError;
protected override async Task OnInitializedAsync() => await LoadAsync();
private async Task LoadAsync()
{
_loading = true;
var existing = await Db.HighlightConfigs
.AsNoTracking()
.ToListAsync();
_rows = Types.Select(t =>
{
var cfg = existing.FirstOrDefault(e => string.Equals(e.HighlightType, t, StringComparison.OrdinalIgnoreCase))
?? new HighlightConfig
{
HighlightType = t,
FallbackHex = DefaultHex.GetValueOrDefault(t, "#FFFFFF66"),
};
return new HighlightRow { Config = cfg };
}).ToList();
_loading = false;
}
private async Task SaveRowAsync(HighlightRow row)
{
_message = null;
try
{
var tracked = await Db.HighlightConfigs
.FirstOrDefaultAsync(h => string.Equals(h.HighlightType, row.Config.HighlightType, StringComparison.OrdinalIgnoreCase));
if (tracked is null)
{
row.Config.Id = row.Config.Id == Guid.Empty ? Guid.NewGuid() : row.Config.Id;
Db.HighlightConfigs.Add(row.Config);
}
else
{
tracked.CdnPath = row.Config.CdnPath;
tracked.FallbackHex = row.Config.FallbackHex;
tracked.IsAnimated = row.Config.IsAnimated;
tracked.FrameCount = row.Config.FrameCount;
tracked.Fps = row.Config.Fps;
}
await Db.SaveChangesAsync();
_message = $"{row.Config.HighlightType} highlight saved.";
_isError = false;
// Re-attach the tracked entity to the row so future saves go through the tracked path.
if (!Db.HighlightConfigs.Local.Any(h => h.HighlightType == row.Config.HighlightType))
Db.Entry(row.Config).State = Microsoft.EntityFrameworkCore.EntityState.Detached;
}
catch (Exception ex)
{
_message = $"Save failed: {ex.Message}";
_isError = true;
}
}
}