✨Added minigame label for each region
This commit is contained in:
@@ -16,10 +16,27 @@ shader_parameter/smoothWidth = 0.0052
|
||||
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_0navw"]
|
||||
size = Vector2(400, 400)
|
||||
|
||||
[node name="RegionVisual" type="Node2D" node_paths=PackedStringArray("_sliceSprite")]
|
||||
[node name="RegionVisual" type="Node2D" node_paths=PackedStringArray("_sliceSprite", "_textLabel", "_labelPivot")]
|
||||
script = ExtResource("1_4ymj8")
|
||||
_sliceSprite = NodePath("Sprite2D")
|
||||
_textLabel = NodePath("LabelPivot/Label")
|
||||
_labelPivot = NodePath("LabelPivot")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
material = SubResource("ShaderMaterial_86pvs")
|
||||
texture = SubResource("PlaceholderTexture2D_0navw")
|
||||
|
||||
[node name="LabelPivot" type="Node2D" parent="."]
|
||||
|
||||
[node name="Label" type="Label" parent="LabelPivot"]
|
||||
custom_minimum_size = Vector2(100, 40)
|
||||
offset_left = -50.0
|
||||
offset_top = -240.0
|
||||
offset_right = 50.0
|
||||
offset_bottom = -200.0
|
||||
pivot_offset = Vector2(50, 20)
|
||||
size_flags_horizontal = 0
|
||||
theme_override_font_sizes/font_size = 21
|
||||
text = "test"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
@@ -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
|
||||
@@ -46,6 +47,15 @@ public partial class MinigameController : Node2D
|
||||
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