Added theme-based region colors

This commit is contained in:
jonathan
2025-10-03 20:02:25 +02:00
parent 7d35c991f3
commit 224863f891
4 changed files with 52 additions and 10 deletions
+12 -2
View File
@@ -1,5 +1,7 @@
using Godot;
using System;
using Babushka.scripts.CSharp.Common.Minigame;
using Godot.Collections;
public partial class RegionVisual : Node
{
@@ -7,17 +9,19 @@ public partial class RegionVisual : Node
[Export] private Label _textLabel;
[Export] private Node2D _labelPivot;
[Export(PropertyHint.DictionaryType)] private Dictionary<MinigameController.RegionTheme, Color> _fillColors = new();
public override void _EnterTree()
{
//_sliceSprite.Material = new Material()
}
public void Setup(Vector2 normalAngles, Color color, string regionText)
public void Setup(Vector2 normalAngles, Color color, string regionText, MinigameController.RegionTheme regionTheme)
{
var mat = (_sliceSprite.Material as ShaderMaterial)!;
mat.SetShaderParameter("angles", normalAngles);
mat.SetShaderParameter("fillColor", color);
mat.SetShaderParameter("fillColor", GetFillColor(regionTheme));
var averageAngleRadians = (normalAngles.X + normalAngles.Y) * float.Pi; // '/ 2' from the average and '* 2' from the radians cancel out
_labelPivot.Rotation = averageAngleRadians;
@@ -25,4 +29,10 @@ public partial class RegionVisual : Node
_textLabel.Text = regionText;
}
private Color GetFillColor(MinigameController.RegionTheme theme)
{
if (_fillColors.TryGetValue(theme, out var color)) return color;
throw new InvalidOperationException($"No fill color for theme {theme}");
}
}