Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b7d1f9d8d5 | |||
| 12bf632932 | |||
| aa4f1c55b5 |
@@ -21,7 +21,7 @@ public partial class MinigameController : Node2D
|
||||
God,
|
||||
VeryGood
|
||||
}
|
||||
|
||||
|
||||
public class Builder<T>
|
||||
{
|
||||
internal class Region
|
||||
@@ -108,6 +108,8 @@ public partial class MinigameController : Node2D
|
||||
|
||||
[Signal] public delegate void ArmMovedEventHandler(float newPos);
|
||||
|
||||
[Signal] public delegate void RegionHitEventHandler(int regionIndex);
|
||||
|
||||
public override void _EnterTree()
|
||||
{
|
||||
HideMinigame();
|
||||
@@ -125,6 +127,7 @@ public partial class MinigameController : Node2D
|
||||
ShowMinigame();
|
||||
Setup(builder);
|
||||
await _minigameComplete!.Task;
|
||||
await ToSignal(GetTree().CreateTimer(.3), "timeout");
|
||||
var returnValue = _hits!.Select(h => builder.regions[h].value).ToList();
|
||||
Reset();
|
||||
HideMinigame();
|
||||
@@ -145,6 +148,7 @@ public partial class MinigameController : Node2D
|
||||
}
|
||||
|
||||
_hits.Add(i);
|
||||
EmitSignalRegionHit(i);
|
||||
|
||||
_armSpeed = -_armSpeed;
|
||||
|
||||
@@ -174,16 +178,18 @@ public partial class MinigameController : Node2D
|
||||
|
||||
// spawn regions
|
||||
var regionSum = 0f;
|
||||
foreach (var region in builder.regions)
|
||||
foreach (var (region, i) in builder.regions.Select((region, i) => (region, i)))
|
||||
{
|
||||
var regionVisual = _regionVisualPrefab.Instantiate<RegionVisual>();
|
||||
_regionsParent.AddChild(regionVisual);
|
||||
|
||||
RegionHit += regionVisual.HitAnimation;
|
||||
|
||||
var normalisedAngleStart = regionSum / totalRegionProportion;
|
||||
var normalisedAngleEnd = (regionSum + region.proportion) / totalRegionProportion;
|
||||
var normalAngles = new Vector2(normalisedAngleStart, normalisedAngleEnd);
|
||||
|
||||
regionVisual.Setup(normalAngles, _baseRegionColor.RandomHue(), region.text, region.theme);
|
||||
regionVisual.Setup(normalAngles, region.text, region.theme, i);
|
||||
|
||||
regionSum += region.proportion;
|
||||
|
||||
@@ -207,6 +213,13 @@ public partial class MinigameController : Node2D
|
||||
{
|
||||
_minigameComplete = null;
|
||||
_hits = null;
|
||||
_regionsParent.GetChildren().ForEach(c => c.QueueFree());
|
||||
_regionsParent.GetChildren().ForEach(c =>
|
||||
{
|
||||
if (c is RegionVisual rv)
|
||||
{
|
||||
RegionHit -= rv.HitAnimation;
|
||||
}
|
||||
c.QueueFree();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,27 +1,42 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using Babushka.scripts.CSharp.Common.Minigame;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Minigame;
|
||||
|
||||
public partial class RegionVisual : Node
|
||||
{
|
||||
[Export] private Sprite2D _sliceSprite;
|
||||
[Export] private Label _textLabel;
|
||||
[Export] private Node2D _labelPivot;
|
||||
[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();
|
||||
|
||||
public void Setup(Vector2 normalAngles, Color color, string regionText, MinigameController.RegionTheme regionTheme)
|
||||
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));
|
||||
|
||||
var averageAngleRadians = (normalAngles.X + normalAngles.Y) * float.Pi; // '/ 2' from the average and '* 2' from the radians cancel out
|
||||
// '/ 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)
|
||||
|
||||
Reference in New Issue
Block a user