Skip to content
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

Remove 3 variables trying to access another scene's nodes #4954

Merged
merged 5 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 9 additions & 42 deletions src/general/base_stage/CreatureStageHUDBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,6 @@ public partial class CreatureStageHUDBase<TStage> : HUDWithPausing, ICreatureSta
[Export]
public NodePath HealthBarPath = null!;

[Export]
public NodePath AmmoniaReproductionBarPath = null!;

[Export]
public NodePath PhosphateReproductionBarPath = null!;

[Export]
public NodePath EditorButtonFlashPath = null!;

[Export]
public NodePath ProcessPanelPath = null!;

Expand Down Expand Up @@ -164,9 +155,6 @@ public partial class CreatureStageHUDBase<TStage> : HUDWithPausing, ICreatureSta

protected TextureProgressBar atpBar = null!;
protected TextureProgressBar healthBar = null!;
protected TextureProgressBar ammoniaReproductionBar = null!;
protected TextureProgressBar phosphateReproductionBar = null!;
protected PointLight2D editorButtonFlash = null!;
protected Label atpLabel = null!;
protected Label hpLabel = null!;
protected Label populationLabel = null!;
Expand Down Expand Up @@ -229,6 +217,12 @@ protected CreatureStageHUDBase()
[Signal]
public delegate void OnOpenMenuToHelpEventHandler();

[Signal]
public delegate void OnSetEditorButtonFlashEffectEventHandler();
hhyyrylainen marked this conversation as resolved.
Show resolved Hide resolved

[Signal]
public delegate void OnUpdateReproductionProgressBarsEventHandler();

/// <summary>
/// Gets and sets the text that appears at the upper HUD.
/// </summary>
Expand Down Expand Up @@ -262,9 +256,6 @@ public override void _Ready()

atpBar = GetNode<TextureProgressBar>(AtpBarPath);
healthBar = GetNode<TextureProgressBar>(HealthBarPath);
ammoniaReproductionBar = GetNode<TextureProgressBar>(AmmoniaReproductionBarPath);
phosphateReproductionBar = GetNode<TextureProgressBar>(PhosphateReproductionBarPath);
editorButtonFlash = GetNode<PointLight2D>(EditorButtonFlashPath);

atpLabel = GetNode<Label>(AtpLabelPath);
hpLabel = GetNode<Label>(HpLabelPath);
Expand Down Expand Up @@ -684,7 +675,7 @@ protected virtual void ReadPlayerHitpoints(out float hp, out float maxHP)

protected void SetEditorButtonFlashEffect(bool enabled)
{
editorButtonFlash.Visible = enabled;
EmitSignal(SignalName.OnSetEditorButtonFlashEffect, enabled);
}

protected void UpdatePopulation()
Expand Down Expand Up @@ -817,11 +808,8 @@ protected void UpdateReproductionProgress()
GD.PrintErr("can't get reproduction phosphates progress: ", e);
}

ammoniaReproductionBar.Value = fractionOfAmmonia * ammoniaReproductionBar.MaxValue;
phosphateReproductionBar.Value = fractionOfPhosphates * phosphateReproductionBar.MaxValue;

CheckAmmoniaProgressHighlight(fractionOfAmmonia);
CheckPhosphateProgressHighlight(fractionOfPhosphates);
EmitSignal(SignalName.OnUpdateReproductionProgressBars, fractionOfAmmonia, fractionOfPhosphates,
AmmoniaBW, PhosphatesBW);
}

protected virtual void CalculatePlayerReproductionProgress(Dictionary<Compound, float> gatheredCompounds,
Expand Down Expand Up @@ -949,9 +937,6 @@ protected override void Dispose(bool disposing)
EditorButtonPath.Dispose();
AtpBarPath.Dispose();
HealthBarPath.Dispose();
AmmoniaReproductionBarPath.Dispose();
PhosphateReproductionBarPath.Dispose();
EditorButtonFlashPath.Dispose();
ProcessPanelPath.Dispose();
HintTextPath.Dispose();
HotBarPath.Dispose();
Expand Down Expand Up @@ -1013,24 +998,6 @@ private void UpdateBarVisibility(Func<Compound, bool> isUseful)
}
}

private void CheckAmmoniaProgressHighlight(float fractionOfAmmonia)
{
if (fractionOfAmmonia < 1.0f)
return;

ammoniaReproductionBar.TintProgress = new Color(1, 1, 1, 1);
editorButton.GetNode<TextureRect>("ReproductionBar/AmmoniaIcon").Texture = AmmoniaBW;
}

private void CheckPhosphateProgressHighlight(float fractionOfPhosphates)
{
if (fractionOfPhosphates < 1.0f)
return;

phosphateReproductionBar.TintProgress = new Color(1, 1, 1, 1);
editorButton.GetNode<TextureRect>("ReproductionBar/PhosphateIcon").Texture = PhosphatesBW;
}

private void ProcessPanelButtonPressed()
{
if (processPanel.Visible)
Expand Down
5 changes: 2 additions & 3 deletions src/late_multicellular_stage/MulticellularHUD.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ PatchOverlayPath = NodePath("PatchNameOverlay")
EditorButtonPath = NodePath("BottomRight/EditorButton")
AtpBarPath = NodePath("BottomRight/ATPBar")
HealthBarPath = NodePath("BottomRight/HealthBar")
AmmoniaReproductionBarPath = NodePath("")
PhosphateReproductionBarPath = NodePath("")
EditorButtonFlashPath = NodePath("")
ProcessPanelPath = NodePath("ProcessPanel")
HintTextPath = NodePath("HintText")
HotBarPath = NodePath("ScrollContainer/HotBar")
Expand Down Expand Up @@ -541,6 +538,8 @@ custom_minimum_size = Vector2(450, 0)
DialogText = "MOVING_TO_AWAKENING_PROTOTYPE"
WindowTitle = "MOVING_TO_AWAKENING_PROTOTYPE_TITLE"

[connection signal="OnSetEditorButtonFlashEffect" from="." to="BottomRight/EditorButton" method="SetEditorButtonFlashEffect"]
[connection signal="OnUpdateReproductionProgressBars" from="." to="BottomRight/EditorButton" method="UpdateReproductionProgressBars"]
[connection signal="OnCompoundsToggled" from="BottomLeft/HUDBottomBar" to="." method="CompoundButtonPressed"]
[connection signal="OnEnvironmentToggled" from="BottomLeft/HUDBottomBar" to="." method="EnvironmentButtonPressed"]
[connection signal="OnHelpPressed" from="BottomLeft/HUDBottomBar" to="." method="OpenHelp"]
Expand Down
5 changes: 2 additions & 3 deletions src/microbe_stage/MicrobeHUD.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,6 @@ PatchOverlayPath = NodePath("../PatchNameOverlay")
EditorButtonPath = NodePath("BottomRight/EditorButton")
AtpBarPath = NodePath("BottomRight/ATPBar")
HealthBarPath = NodePath("BottomRight/HealthBar")
AmmoniaReproductionBarPath = NodePath("BottomRight/EditorButton/ReproductionBar/AmmoniaReproductionBar")
PhosphateReproductionBarPath = NodePath("BottomRight/EditorButton/ReproductionBar/PhosphateReproductionBar")
EditorButtonFlashPath = NodePath("BottomRight/EditorButton/Highlight/PointLight2D")
ProcessPanelPath = NodePath("ProcessPanel")
HintTextPath = NodePath("HintText")
HotBarPath = NodePath("ScrollContainer/HotBar")
Expand Down Expand Up @@ -700,6 +697,8 @@ custom_minimum_size = Vector2(450, 0)
offset_right = 300.0
offset_bottom = 97.0

[connection signal="OnSetEditorButtonFlashEffect" from="." to="BottomRight/EditorButton" method="SetEditorButtonFlashEffect"]
[connection signal="OnUpdateReproductionProgressBars" from="." to="BottomRight/EditorButton" method="UpdateReproductionProgressBars"]
[connection signal="OnCompoundsToggled" from="BottomLeft/HUDBottomBar" to="." method="CompoundButtonPressed"]
[connection signal="OnEnvironmentToggled" from="BottomLeft/HUDBottomBar" to="." method="EnvironmentButtonPressed"]
[connection signal="OnHelpPressed" from="BottomLeft/HUDBottomBar" to="." method="OpenHelp"]
Expand Down
44 changes: 44 additions & 0 deletions src/microbe_stage/gui/EditorEntryButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,51 @@ public partial class EditorEntryButton : TextureButton

[Export]
private AnimationPlayer buttonAnimationPlayer = null!;

[Export]
private TextureRect ammoniaIcon = null!;

[Export]
private TextureProgressBar ammoniaReproductionBar = null!;

[Export]
private TextureRect phosphateIcon = null!;

[Export]
private TextureProgressBar phosphateReproductionBar = null!;

[Export]
private PointLight2D editorButtonFlash = null!;
#pragma warning restore CA2213
private void SetEditorButtonFlashEffect(bool enabled)
{
editorButtonFlash.Visible = enabled;
}

private void UpdateReproductionProgressBars(float fractionOfAmmonia, float fractionOfPhosphates,
Texture2D ammoniaBW, Texture2D phosphatesBW)
{
ammoniaReproductionBar.Value = fractionOfAmmonia * ammoniaReproductionBar.MaxValue;
phosphateReproductionBar.Value = fractionOfPhosphates * phosphateReproductionBar.MaxValue;

if (fractionOfAmmonia >= 1.0f)
{
ammoniaReproductionBar.TintProgress = new Color(1, 1, 1, 1);
ammoniaIcon.Texture = ammoniaBW;
}

if (fractionOfPhosphates >= 1.0f)
{
phosphateReproductionBar.TintProgress = new Color(1, 1, 1, 1);
phosphateIcon.Texture = phosphatesBW;
}
}

private void UpdateReproductionProgress(float newAmmoniaValue, float newPhosphateValue)
{
ammoniaReproductionBar.Value = newAmmoniaValue;
phosphateReproductionBar.Value = newPhosphateValue;
}

private void OnEditorButtonMouseEnter()
{
Expand Down
11 changes: 8 additions & 3 deletions src/microbe_stage/gui/EditorEntryButton.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ _data = {
"EditorButtonFlash": SubResource("30")
}

[node name="EditorButton" type="TextureButton" node_paths=PackedStringArray("Highlight", "ButtonAnimationPlayer")]
[node name="EditorButton" type="TextureButton" node_paths=PackedStringArray("highlight", "buttonAnimationPlayer", "ammoniaIcon", "ammoniaReproductionBar", "phosphateIcon", "phosphateReproductionBar", "editorButtonFlash")]
custom_minimum_size = Vector2(160, 160)
anchors_preset = 3
anchor_left = 1.0
Expand All @@ -66,8 +66,13 @@ texture_disabled = ExtResource("4_4niqg")
ignore_texture_size = true
stretch_mode = 5
script = ExtResource("5_kxl0r")
Highlight = NodePath("Highlight")
ButtonAnimationPlayer = NodePath("AnimationPlayer")
highlight = NodePath("Highlight")
buttonAnimationPlayer = NodePath("AnimationPlayer")
ammoniaIcon = NodePath("ReproductionBar/AmmoniaIcon")
ammoniaReproductionBar = NodePath("ReproductionBar/AmmoniaReproductionBar")
phosphateIcon = NodePath("ReproductionBar/PhosphateIcon")
phosphateReproductionBar = NodePath("ReproductionBar/PhosphateReproductionBar")
editorButtonFlash = NodePath("Highlight/PointLight2D")

[node name="Highlight" type="TextureRect" parent="."]
visible = false
Expand Down