From 83c9dfc9455ce5daee0ded1d0b1c1ab292c25bb6 Mon Sep 17 00:00:00 2001 From: jonathan Date: Fri, 3 Oct 2025 20:02:25 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8Added=20theme-based=20region=20colors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- prefabs/minigame/region_visual.tscn | 10 +++++++ .../Common/Fight/FightMinigameHandler.cs | 12 ++++----- .../Common/Minigame/MinigameController.cs | 26 +++++++++++++++++-- .../CSharp/Common/Minigame/RegionVisual.cs | 14 ++++++++-- 4 files changed, 52 insertions(+), 10 deletions(-) diff --git a/prefabs/minigame/region_visual.tscn b/prefabs/minigame/region_visual.tscn index 1133017..e2c36b8 100644 --- a/prefabs/minigame/region_visual.tscn +++ b/prefabs/minigame/region_visual.tscn @@ -21,6 +21,16 @@ script = ExtResource("1_4ymj8") _sliceSprite = NodePath("Sprite2D") _textLabel = NodePath("LabelPivot/Label") _labelPivot = NodePath("LabelPivot") +_fillColors = Dictionary[int, Color]({ +0: Color(0.427493, 0.427493, 0.427493, 1), +1: Color(0.675735, 0.105671, 0.0799616, 1), +2: Color(0.645128, 0.346481, 0.215967, 1), +3: Color(0.754619, 0.665655, 0.384568, 1), +4: Color(0.365769, 0.400285, 0.598083, 1), +5: Color(0.222174, 0.457454, 0.45483, 1), +6: Color(0.316126, 0.448834, 0.312852, 1), +7: Color(0.244391, 0.640687, 0.283315, 1) +}) [node name="Sprite2D" type="Sprite2D" parent="."] material = SubResource("ShaderMaterial_86pvs") diff --git a/scripts/CSharp/Common/Fight/FightMinigameHandler.cs b/scripts/CSharp/Common/Fight/FightMinigameHandler.cs index fe4a71a..1a01888 100644 --- a/scripts/CSharp/Common/Fight/FightMinigameHandler.cs +++ b/scripts/CSharp/Common/Fight/FightMinigameHandler.cs @@ -25,12 +25,12 @@ public partial class FightMinigameHandler : Node if(currentDetail is not MinigameActionDetail minigameDetail) return; _minigameController.Run(new MinigameController.Builder() - .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 => { diff --git a/scripts/CSharp/Common/Minigame/MinigameController.cs b/scripts/CSharp/Common/Minigame/MinigameController.cs index a33b463..9fb4bc1 100644 --- a/scripts/CSharp/Common/Minigame/MinigameController.cs +++ b/scripts/CSharp/Common/Minigame/MinigameController.cs @@ -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 { 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 RegionWithText(string text) { if (regions.Count == 0) @@ -56,6 +69,15 @@ public partial class MinigameController : Node2D return this; } + public Builder 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 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; diff --git a/scripts/CSharp/Common/Minigame/RegionVisual.cs b/scripts/CSharp/Common/Minigame/RegionVisual.cs index 5e2d1cd..9e6efa2 100644 --- a/scripts/CSharp/Common/Minigame/RegionVisual.cs +++ b/scripts/CSharp/Common/Minigame/RegionVisual.cs @@ -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 _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}"); + } } \ No newline at end of file