-
-
Notifications
You must be signed in to change notification settings - Fork 566
Add dots indicating player population on patch map #5880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
cb4ceec
608718f
4268a2c
5d8212c
86c2910
1e9ddfa
4efda91
797aea9
e67f36a
03603a3
fa9f846
20de572
d55eb81
63ccc78
194cc1b
98a1bec
c168bc5
d1752e5
a8fd79c
80a7e8c
330293e
fcf8f69
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,7 @@ public partial class PatchMapDrawer : Control | |
|
|
||
| #pragma warning disable CA2213 | ||
| private PackedScene nodeScene = null!; | ||
| private PackedScene populationIndicatorScene = null!; | ||
| private Control patchNodeContainer = null!; | ||
| private Control lineContainer = null!; | ||
| #pragma warning restore CA2213 | ||
|
|
@@ -141,6 +142,11 @@ public Patch? SelectedPatch | |
| /// </summary> | ||
| public Action<PatchMapDrawer>? OnSelectedPatchChanged { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Player species ID for player population indicator (dots on patch map) | ||
| /// </summary> | ||
| public uint PlayerSpeciesID { get; set; } | ||
|
|
||
| public override void _Ready() | ||
| { | ||
| base._Ready(); | ||
|
|
@@ -149,6 +155,8 @@ public override void _Ready() | |
| lineContainer = GetNode<Control>(LineContainerPath); | ||
|
|
||
| nodeScene = GD.Load<PackedScene>("res://src/microbe_stage/editor/PatchMapNode.tscn"); | ||
| populationIndicatorScene = GD.Load<PackedScene>( | ||
|
||
| "res://src/microbe_stage/editor/PatchMapPopulationIndicator.tscn"); | ||
|
|
||
| if (DrawDefaultMapIfEmpty && Map == null) | ||
| { | ||
|
|
@@ -1109,6 +1117,24 @@ private void AddPatchNode(Patch patch, Vector2 position) | |
|
|
||
| patch.ApplyPatchEventVisuals(node); | ||
|
|
||
| var playerSpecies = patch.FindSpeciesByID(PlayerSpeciesID); | ||
| if (playerSpecies != null) | ||
| { | ||
| var playerPopulation = patch.GetSpeciesSimulationPopulation(playerSpecies); | ||
|
|
||
| for (var i = 0; i < playerPopulation * 0.001; ++i) | ||
| { | ||
| var indicator = populationIndicatorScene.Instantiate<PatchMapPopulationIndicator>(); | ||
|
||
| indicator.IndicatorPositionModifier = i; | ||
| indicator.Position = position; | ||
| indicator.MouseFilter = MouseFilterEnum.Ignore; | ||
| indicator.UpdateIndicator(node); | ||
| node.AddChild(indicator); | ||
|
|
||
| indicator.ShowBehindParent = true; | ||
| } | ||
| } | ||
|
|
||
| patchNodeContainer.AddChild(node); | ||
| nodes.Add(node.Patch, node); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| using Godot; | ||
|
|
||
| /// <summary> | ||
| /// Dots scattered around patch map nodes, indication population of player species | ||
| /// </summary> | ||
| public partial class PatchMapPopulationIndicator : Control | ||
|
||
| { | ||
| private int positionModifier; | ||
|
|
||
| #pragma warning disable CA2213 | ||
| [Export] | ||
| private TextureRect indicator = null!; | ||
| #pragma warning restore CA2213 | ||
|
|
||
| public int IndicatorPositionModifier | ||
| { | ||
| get | ||
| { | ||
| return positionModifier; | ||
| } | ||
| set | ||
| { | ||
| positionModifier = value; | ||
| } | ||
| } | ||
|
|
||
| public void UpdateIndicator(Control parent) | ||
| { | ||
| var nodeModifier = parent.Position.LengthSquared(); | ||
| var modifierSinus = Mathf.Sin(IndicatorPositionModifier); | ||
|
|
||
| indicator.Position = Size * 0.5f + new Vector2(0, 40).Rotated(nodeModifier * 20) + new Vector2( | ||
| 0, modifierSinus * 50).Rotated(IndicatorPositionModifier * 6 * modifierSinus + nodeModifier); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| [gd_scene load_steps=3 format=3 uid="uid://d368temjpdpxv"] | ||
|
|
||
| [ext_resource type="Script" path="res://src/microbe_stage/editor/PatchMapPopulationIndicator.cs" id="1_8o4yl"] | ||
| [ext_resource type="Texture2D" uid="uid://cs4ewaw3baruk" path="res://assets/textures/gui/bevel/GrabClick.svg" id="1_r6jqg"] | ||
|
|
||
| [node name="PatchMapPopulationIndicator" type="Control" node_paths=PackedStringArray("indicator")] | ||
| layout_mode = 3 | ||
| anchors_preset = 0 | ||
| offset_right = 64.0 | ||
| offset_bottom = 64.0 | ||
| script = ExtResource("1_8o4yl") | ||
| indicator = NodePath("TextureRect") | ||
|
|
||
| [node name="TextureRect" type="TextureRect" parent="."] | ||
| layout_mode = 0 | ||
| offset_right = 10.0 | ||
| offset_bottom = 10.0 | ||
| texture = ExtResource("1_r6jqg") | ||
| expand_mode = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could default to -1 (or uint.MaxValue if C# complains) so that this doesn't accidentally match anything if there's a bug elsewhere in the code that causes a species with ID = 0 to be created.