✨Added theme-based region colors
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).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")
|
||||
.AddRegion(4).RegionWithText("4").RegionWithTheme(MinigameController.RegionTheme.Normal)
|
||||
.AddRegion(0).RegionWithProportion(1.5f).RegionWithText("0").RegionWithTheme(MinigameController.RegionTheme.Bad)
|
||||
.AddRegion(8).RegionWithProportion(0.5f).RegionWithText("8").RegionWithTheme(MinigameController.RegionTheme.VeryGood)
|
||||
.AddRegion(0).RegionWithProportion(1.5f).RegionWithText("0").RegionWithTheme(MinigameController.RegionTheme.Bad)
|
||||
.AddRegion(3).RegionWithText("3").RegionWithTheme(MinigameController.RegionTheme.NormalAlt1)
|
||||
.AddRegion(5).RegionWithText("5").RegionWithTheme(MinigameController.RegionTheme.NormalAlt2)
|
||||
.WithHitCount(3)
|
||||
).ContinueWith(task =>
|
||||
{
|
||||
|
||||
@@ -10,6 +10,18 @@ namespace Babushka.scripts.CSharp.Common.Minigame;
|
||||
|
||||
public partial class MinigameController : Node2D
|
||||
{
|
||||
public enum RegionTheme
|
||||
{
|
||||
Disabled,
|
||||
VeryBad,
|
||||
Bad,
|
||||
Normal,
|
||||
NormalAlt1,
|
||||
NormalAlt2,
|
||||
God,
|
||||
VeryGood
|
||||
}
|
||||
|
||||
public class Builder<T>
|
||||
{
|
||||
internal class Region
|
||||
@@ -17,6 +29,7 @@ public partial class MinigameController : Node2D
|
||||
public required T value;
|
||||
public float proportion = 1f;
|
||||
public string text = "";
|
||||
public RegionTheme theme = RegionTheme.Normal;
|
||||
}
|
||||
|
||||
public enum DoubleHitHandling
|
||||
@@ -46,7 +59,7 @@ public partial class MinigameController : Node2D
|
||||
regions.Last().proportion = proportion;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Builder<T> RegionWithText(string text)
|
||||
{
|
||||
if (regions.Count == 0)
|
||||
@@ -56,6 +69,15 @@ public partial class MinigameController : Node2D
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<T> RegionWithTheme(RegionTheme theme)
|
||||
{
|
||||
if (regions.Count == 0)
|
||||
throw new InvalidOperationException("No region to set theme for");
|
||||
|
||||
regions.Last().theme = theme;
|
||||
return this;
|
||||
}
|
||||
|
||||
// general settings
|
||||
public Builder<T> WithDoubleHitHandling(DoubleHitHandling handling)
|
||||
{
|
||||
@@ -161,7 +183,7 @@ public partial class MinigameController : Node2D
|
||||
var normalisedAngleEnd = (regionSum + region.proportion) / totalRegionProportion;
|
||||
var normalAngles = new Vector2(normalisedAngleStart, normalisedAngleEnd);
|
||||
|
||||
regionVisual.Setup(normalAngles, _baseRegionColor.RandomHue(),region.text);
|
||||
regionVisual.Setup(normalAngles, _baseRegionColor.RandomHue(), region.text, region.theme);
|
||||
|
||||
regionSum += region.proportion;
|
||||
|
||||
|
||||
@@ -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}");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user