You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
1.2 KiB
32 lines
1.2 KiB
using Godot;
|
|
using System;
|
|
using Babushka.scripts.CSharp.Common.Minigame;
|
|
using Godot.Collections;
|
|
|
|
public partial class RegionVisual : Node
|
|
{
|
|
[Export] private Sprite2D _sliceSprite;
|
|
[Export] private Label _textLabel;
|
|
[Export] private Node2D _labelPivot;
|
|
|
|
[Export(PropertyHint.DictionaryType)] private Dictionary<MinigameController.RegionTheme, Color> _fillColors = new();
|
|
|
|
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", GetFillColor(regionTheme));
|
|
|
|
var averageAngleRadians = (normalAngles.X + normalAngles.Y) * float.Pi; // '/ 2' from the average and '* 2' from the radians cancel out
|
|
_labelPivot.Rotation = averageAngleRadians;
|
|
_textLabel.Rotation = -averageAngleRadians;
|
|
|
|
_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}");
|
|
}
|
|
} |