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.
47 lines
1.6 KiB
47 lines
1.6 KiB
using System;
|
|
using Godot;
|
|
using Godot.Collections;
|
|
|
|
namespace Babushka.scripts.CSharp.Common.Minigame;
|
|
|
|
public partial class RegionVisual : Node
|
|
{
|
|
[Export] private Sprite2D _sliceSprite = null!;
|
|
[Export] private Label _textLabel = null!;
|
|
[Export] private Node2D _labelPivot = null!;
|
|
|
|
[Export(PropertyHint.DictionaryType)] private Dictionary<MinigameController.RegionTheme, Color> _fillColors = new();
|
|
|
|
private int _index;
|
|
|
|
public void Setup(Vector2 normalAngles, string regionText, MinigameController.RegionTheme regionTheme, int index)
|
|
{
|
|
var mat = (_sliceSprite.Material as ShaderMaterial)!;
|
|
mat.SetShaderParameter("angles", normalAngles);
|
|
mat.SetShaderParameter("fillColor", GetFillColor(regionTheme));
|
|
|
|
// '/ 2' from the average and '* 2' from the radians cancel out
|
|
var averageAngleRadians = (normalAngles.X + normalAngles.Y) * float.Pi;
|
|
_labelPivot.Rotation = averageAngleRadians;
|
|
_textLabel.Rotation = -averageAngleRadians;
|
|
|
|
_textLabel.Text = regionText;
|
|
|
|
_index = index;
|
|
}
|
|
|
|
public void HitAnimation(int regionIndex)
|
|
{
|
|
if(regionIndex != _index) return;
|
|
|
|
var tween = GetTree().CreateTween();
|
|
tween.TweenProperty(_sliceSprite, "scale", new Vector2(1.5f, 1.5f), 0.1f);
|
|
tween.TweenProperty(_sliceSprite, "scale", new Vector2(1f, 1f), 0.2f);
|
|
}
|
|
|
|
private Color GetFillColor(MinigameController.RegionTheme theme)
|
|
{
|
|
if (_fillColors.TryGetValue(theme, out var color)) return color;
|
|
throw new InvalidOperationException($"No fill color for theme {theme}");
|
|
}
|
|
} |