✨Added theme-based region colors
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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
|
||||
@@ -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