Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 115 additions & 6 deletions Assets/Scripts/SS3D/Data/PaletteColors.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,125 @@
using System.Collections.Generic;
using UnityEngine;

namespace SS3D.Data
{
public enum PaletteColor
{
White,
TextPrimary,
TextDisabled,
UiOverlay,
UiOverlayHighlighted,
UiOverlayDisabled,
LightGreen,
NormalGreen,
LightBlue,
LightRed,
LogBlue,
LogGreen,
LogRed,
LogServer,
LogExternal,
LogClient,
LogPhysics
}

public struct PaletteColorDefinition
{
public PaletteColorDefinition(PaletteColor key, string displayName, Color color)
{
Key = key;
DisplayName = displayName;
Color = color;
}

public PaletteColor Key { get; }

public string DisplayName { get; }

public Color Color { get; }

public string Hex => "#" + ColorUtility.ToHtmlStringRGBA(Color);
}

public static class PaletteColors
{
public static Color White = Color.white;
public static Color LightGreen = new Color(42, 193, 50);
public static Color NormalGreen = new Color(35, 155, 42);
public static readonly Color White = Color.white;
public static readonly Color TextPrimary = White;
public static readonly Color TextDisabled = new Color(1f, 1f, 1f, 0.23137255f);

public static readonly Color UiOverlay = new Color(0f, 0f, 0f, 0.34901962f);
public static readonly Color UiOverlayHighlighted = new Color(0f, 0f, 0f, 0.7490196f);
public static readonly Color UiOverlayDisabled = new Color(0f, 0f, 0f, 0.6f);

public static readonly Color LightGreen = new Color32(42, 193, 50, 255);
public static readonly Color NormalGreen = new Color32(35, 155, 42, 255);
public static readonly Color LightBlue = new Color32(80, 115, 216, 255);
public static readonly Color LightRed = new Color32(155, 31, 31, 255);

public static readonly Color LogBlue = FromHex("#90C4FE");
public static readonly Color LogGreen = FromHex("#88B36B");
public static readonly Color LogRed = FromHex("#8D3131");
public static readonly Color LogServer = FromHex("#A645A6");
public static readonly Color LogExternal = FromHex("#E6DC33");
public static readonly Color LogClient = FromHex("#B94949");
public static readonly Color LogPhysics = FromHex("#678DB8");

private static readonly PaletteColorDefinition[] _colors =
{
new PaletteColorDefinition(PaletteColor.White, "White", White),
new PaletteColorDefinition(PaletteColor.TextPrimary, "Text Primary", TextPrimary),
new PaletteColorDefinition(PaletteColor.TextDisabled, "Text Disabled", TextDisabled),
new PaletteColorDefinition(PaletteColor.UiOverlay, "UI Overlay", UiOverlay),
new PaletteColorDefinition(PaletteColor.UiOverlayHighlighted, "UI Overlay Highlighted", UiOverlayHighlighted),
new PaletteColorDefinition(PaletteColor.UiOverlayDisabled, "UI Overlay Disabled", UiOverlayDisabled),
new PaletteColorDefinition(PaletteColor.LightGreen, "Light Green", LightGreen),
new PaletteColorDefinition(PaletteColor.NormalGreen, "Normal Green", NormalGreen),
new PaletteColorDefinition(PaletteColor.LightBlue, "Light Blue", LightBlue),
new PaletteColorDefinition(PaletteColor.LightRed, "Light Red", LightRed),
new PaletteColorDefinition(PaletteColor.LogBlue, "Log Blue", LogBlue),
new PaletteColorDefinition(PaletteColor.LogGreen, "Log Green", LogGreen),
new PaletteColorDefinition(PaletteColor.LogRed, "Log Red", LogRed),
new PaletteColorDefinition(PaletteColor.LogServer, "Log Server", LogServer),
new PaletteColorDefinition(PaletteColor.LogExternal, "Log External", LogExternal),
new PaletteColorDefinition(PaletteColor.LogClient, "Log Client", LogClient),
new PaletteColorDefinition(PaletteColor.LogPhysics, "Log Physics", LogPhysics)
};

private static readonly Dictionary<PaletteColor, Color> _colorLookup = BuildLookup();

public static IReadOnlyList<PaletteColorDefinition> All => _colors;

public static Color Get(PaletteColor color)
{
return _colorLookup.TryGetValue(color, out Color value) ? value : White;
}

public static bool TryGet(PaletteColor color, out Color value)
{
return _colorLookup.TryGetValue(color, out value);
}

public static string GetHex(PaletteColor color)
{
return "#" + ColorUtility.ToHtmlStringRGBA(Get(color));
}

private static Dictionary<PaletteColor, Color> BuildLookup()
{
var lookup = new Dictionary<PaletteColor, Color>();

public static Color LightBlue = new Color(80, 115, 216);
foreach (PaletteColorDefinition color in _colors)
{
lookup[color.Key] = color.Color;
}

public static Color LightRed = new Color(155, 31, 31);
return lookup;
}

private static Color FromHex(string hex)
{
return ColorUtility.TryParseHtmlString(hex, out Color color) ? color : White;
}
}
}
}
45 changes: 45 additions & 0 deletions Documents/UI_COLOR_PALETTE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# UI Color Palette

SS3D keeps shared UI colors in `Assets/Scripts/SS3D/Data/PaletteColors.cs`.
Use this palette instead of hard-coded color literals when a color is shared by more than one UI component.

## Code usage

```csharp
using SS3D.Data;
using UnityEngine.UI;

public sealed class ReadyStateView : MonoBehaviour
{
[SerializeField] private Image _background;

public void SetReady(bool ready)
{
_background.color = ready
? PaletteColors.Get(PaletteColor.LightBlue)
: PaletteColors.Get(PaletteColor.UiOverlay);
}
}
```

Existing direct static colors still work:

```csharp
_label.color = PaletteColors.TextPrimary;
_button.image.color = PaletteColors.UiOverlayHighlighted;
```

## Choosing colors

- `TextPrimary` and `TextDisabled` are for text states.
- `UiOverlay`, `UiOverlayHighlighted`, and `UiOverlayDisabled` match the existing generic button asset.
- `LightGreen`, `NormalGreen`, `LightBlue`, and `LightRed` are gameplay/UI accent colors.
- `Log*` colors mirror the existing log color set so UI and logs can share the same semantic colors when needed.

## Adding colors

1. Add a new key to the `PaletteColor` enum.
2. Add a static `Color` value in `PaletteColors`.
3. Add it to the `_colors` array so editor/debug tools can enumerate it.

Prefer `Color32` for byte-based RGB values, for example `new Color32(80, 115, 216, 255)`. Unity's `Color` constructor expects normalized `0f..1f` channel values.
Loading