✨Added minigame label for each region
This commit is contained in:
@@ -25,12 +25,12 @@ public partial class FightMinigameHandler : Node
|
||||
if(currentDetail is not MinigameActionDetail minigameDetail) return;
|
||||
|
||||
_minigameController.Run(new MinigameController.Builder<int>()
|
||||
.AddRegion(4)
|
||||
.AddRegion(0).RegionWithProportion(1.5f)
|
||||
.AddRegion(8).RegionWithProportion(0.5f)
|
||||
.AddRegion(0).RegionWithProportion(1.5f)
|
||||
.AddRegion(3)
|
||||
.AddRegion(5)
|
||||
.AddRegion(4).RegionWithText("4")
|
||||
.AddRegion(0).RegionWithProportion(1.5f).RegionWithText("0")
|
||||
.AddRegion(8).RegionWithProportion(0.5f).RegionWithText("8")
|
||||
.AddRegion(0).RegionWithProportion(1.5f).RegionWithText("0")
|
||||
.AddRegion(3).RegionWithText("3")
|
||||
.AddRegion(5).RegionWithText("5")
|
||||
.WithHitCount(3)
|
||||
).ContinueWith(task =>
|
||||
{
|
||||
|
||||
@@ -16,6 +16,7 @@ public partial class MinigameController : Node2D
|
||||
{
|
||||
public required T value;
|
||||
public float proportion = 1f;
|
||||
public string text = "";
|
||||
}
|
||||
|
||||
public enum DoubleHitHandling
|
||||
@@ -45,6 +46,15 @@ public partial class MinigameController : Node2D
|
||||
regions.Last().proportion = proportion;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<T> RegionWithText(string text)
|
||||
{
|
||||
if (regions.Count == 0)
|
||||
throw new InvalidOperationException("No region to set text for");
|
||||
|
||||
regions.Last().text = text;
|
||||
return this;
|
||||
}
|
||||
|
||||
// general settings
|
||||
public Builder<T> WithDoubleHitHandling(DoubleHitHandling handling)
|
||||
@@ -151,7 +161,7 @@ public partial class MinigameController : Node2D
|
||||
var normalisedAngleEnd = (regionSum + region.proportion) / totalRegionProportion;
|
||||
var normalAngles = new Vector2(normalisedAngleStart, normalisedAngleEnd);
|
||||
|
||||
regionVisual.Setup(normalAngles, _baseRegionColor.RandomHue());
|
||||
regionVisual.Setup(normalAngles, _baseRegionColor.RandomHue(),region.text);
|
||||
|
||||
regionSum += region.proportion;
|
||||
|
||||
|
||||
@@ -4,16 +4,25 @@ using System;
|
||||
public partial class RegionVisual : Node
|
||||
{
|
||||
[Export] private Sprite2D _sliceSprite;
|
||||
[Export] private Label _textLabel;
|
||||
[Export] private Node2D _labelPivot;
|
||||
|
||||
|
||||
public override void _EnterTree()
|
||||
{
|
||||
//_sliceSprite.Material = new Material()
|
||||
}
|
||||
|
||||
public void Setup(Vector2 normalAngles, Color color)
|
||||
public void Setup(Vector2 normalAngles, Color color, string regionText)
|
||||
{
|
||||
var mat = (_sliceSprite.Material as ShaderMaterial)!;
|
||||
mat.SetShaderParameter("angles", normalAngles);
|
||||
mat.SetShaderParameter("fillColor", color);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user