Skip to content

Commit

Permalink
Fixed string allocations for shader parameter sets, fixed various fon…
Browse files Browse the repository at this point in the history
…t colours not applying (#5002)

* Switched common shader parameter sets to use StringName

that is stored

* Fixed entity label colours not applying

* Improved icon alignment with text

* Fixed chemical equation display

* Partially fixed modifier info label colour

* Removed some default values from a tscn

* Mostly fixed the modifier info values in editor tooltips

* Tweaked toxin cloud visuals to be a lot closer than earlier
  • Loading branch information
hhyyrylainen committed Apr 5, 2024
1 parent e22da85 commit 29ae0ca
Show file tree
Hide file tree
Showing 34 changed files with 382 additions and 173 deletions.
14 changes: 13 additions & 1 deletion src/engine/ChromaticFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
/// </summary>
public partial class ChromaticFilter : TextureRect
{
private readonly StringName amountParameterName = new("MAX_DIST_PX");

#pragma warning disable CA2213
private ShaderMaterial? material;
#pragma warning restore CA2213
Expand All @@ -30,6 +32,16 @@ public override void _ExitTree()
Settings.Instance.ChromaticEnabled.OnChanged -= OnChanged;
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
amountParameterName.Dispose();
}

base.Dispose(disposing);
}

private void OnChanged(bool enabled)
{
if (enabled)
Expand All @@ -44,6 +56,6 @@ private void OnChanged(bool enabled)

private void SetAmount(float amount)
{
material!.SetShaderParameter("MAX_DIST_PX", amount);
material!.SetShaderParameter(amountParameterName, amount);
}
}
16 changes: 14 additions & 2 deletions src/engine/ColourblindScreenFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public partial class ColourblindScreenFilter : TextureRect
{
private static ColourblindScreenFilter? instance;

private readonly StringName modeParameterName = new("mode");

#pragma warning disable CA2213
private ShaderMaterial screenFilterMaterial = null!;
#pragma warning restore CA2213
Expand Down Expand Up @@ -44,6 +46,16 @@ public void SetColourblindSetting(int index)
}
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
modeParameterName.Dispose();
}

base.Dispose(disposing);
}

private void SetNormal()
{
Material = null;
Expand All @@ -53,14 +65,14 @@ private void SetNormal()
private void SetRedGreen()
{
Material = screenFilterMaterial;
screenFilterMaterial.SetShaderParameter("mode", 1);
screenFilterMaterial.SetShaderParameter(modeParameterName, 1);
Show();
}

private void SetBlueYellow()
{
Material = screenFilterMaterial;
screenFilterMaterial.SetShaderParameter("mode", 2);
screenFilterMaterial.SetShaderParameter(modeParameterName, 2);
Show();
}
}
32 changes: 25 additions & 7 deletions src/engine/DebugOverlays.EntityLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,24 @@ public partial class DebugOverlays
private readonly HashSet<Entity> seenEntities = new();

#pragma warning disable CA2213
private LabelSettings smallerFont = null!;
[Export]
private LabelSettings entityLabelSmallFont = null!;

[Export]
private LabelSettings entityLabelDefaultFont = null!;

[Export]
private LabelSettings entityDeadFont = null!;

[Export]
private LabelSettings entityBindingFont = null!;

[Export]
private LabelSettings entityEngulfingFont = null!;

[Export]
private LabelSettings entityUnbindingFont = null!;

private Camera3D? activeCamera;
#pragma warning restore CA2213

Expand Down Expand Up @@ -78,7 +95,7 @@ private bool UpdateLabelColour(Entity entity, Label label)
{
if (!entity.IsAlive)
{
label.AddThemeColorOverride("font_color", new Color(1.0f, 0.3f, 0.3f));
label.LabelSettings = entityDeadFont;
return false;
}

Expand All @@ -90,25 +107,25 @@ private bool UpdateLabelColour(Entity entity, Label label)
{
case MicrobeState.Binding:
{
label.AddThemeColorOverride("font_color", new Color(0.2f, 0.5f, 0.0f));
label.LabelSettings = entityBindingFont;
break;
}

case MicrobeState.Engulf:
{
label.AddThemeColorOverride("font_color", new Color(0.2f, 0.5f, 1.0f));
label.LabelSettings = entityEngulfingFont;
break;
}

case MicrobeState.Unbinding:
{
label.AddThemeColorOverride("font_color", new Color(1.0f, 0.5f, 0.2f));
label.LabelSettings = entityUnbindingFont;
break;
}

default:
{
label.AddThemeColorOverride("font_color", new Color(1.0f, 1.0f, 1.0f));
label.LabelSettings = entityLabelDefaultFont;
break;
}
}
Expand Down Expand Up @@ -187,12 +204,13 @@ private void OnEntityAdded(Entity entity)
if (entity.Has<ToxinDamageSource>() || entity.Has<CompoundVenter>() || entity.Has<DamageOnTouch>())
{
// To reduce the labels overlapping each other
label.LabelSettings = smallerFont;
label.LabelSettings = entityLabelSmallFont;
}
}

private void OnEntityRemoved(Entity entity)
{
// TODO: pooling for entity labels?
if (entityLabels.TryGetValue(entity, out var label))
{
label.DetachAndQueueFree();
Expand Down
1 change: 0 additions & 1 deletion src/engine/DebugOverlays.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public override void _Ready()
fpsCounter = GetNode<Control>(FPSCounterPath);
performanceMetrics = GetNode<CustomWindow>(PerformanceMetricsPath);
labelsLayer = GetNode<Control>(EntityLabelsPath);
smallerFont = GD.Load<LabelSettings>("res://src/gui_common/fonts/Body-Regular-Tiny.tres");
fpsLabel = GetNode<Label>(FPSLabelPath);
deltaLabel = GetNode<Label>(DeltaLabelPath);
metricsText = GetNode<Label>(MetricsTextPath);
Expand Down
13 changes: 12 additions & 1 deletion src/engine/DebugOverlays.tscn
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
[gd_scene load_steps=6 format=3 uid="uid://c4dyrcb6l1u3o"]
[gd_scene load_steps=11 format=3 uid="uid://c4dyrcb6l1u3o"]

[ext_resource type="PackedScene" path="res://src/gui_common/dialogs/CustomWindow.tscn" id="1"]
[ext_resource type="PackedScene" uid="uid://dtukmqrvwffbl" path="res://src/gui_common/CustomCheckBox.tscn" id="2"]
[ext_resource type="LabelSettings" uid="uid://c07qrffjvqfw" path="res://src/gui_common/fonts/Body-Regular-Tiny.tres" id="2_gkxar"]
[ext_resource type="Script" path="res://src/engine/DebugOverlays.cs" id="3"]
[ext_resource type="LabelSettings" uid="uid://dvqx73nhtr0y2" path="res://src/gui_common/fonts/Body-Regular-Small.tres" id="3_fussq"]
[ext_resource type="LabelSettings" uid="uid://bl7dig4lq5ko" path="res://src/gui_common/fonts/Body-Regular-Small-Red.tres" id="4_rmq2c"]
[ext_resource type="LabelSettings" uid="uid://cw40l6f6fo8ml" path="res://src/gui_common/fonts/Body-Regular-Small-Green.tres" id="5_jl51v"]
[ext_resource type="LabelSettings" uid="uid://u7fwx3p3shvk" path="res://src/gui_common/fonts/Body-Regular-Small-Shadow.tres" id="6_2giyi"]
[ext_resource type="LabelSettings" uid="uid://c7r7hod24qer8" path="res://src/gui_common/fonts/Body-Regular-Small-Blue.tres" id="6_05a1v"]
[ext_resource type="LabelSettings" uid="uid://dj8uej1eg2iuh" path="res://src/gui_common/fonts/Body-Regular-Small-Orange.tres" id="7_8xdu2"]

[node name="DebugOverlay" type="Control"]
layout_mode = 3
Expand All @@ -19,6 +24,12 @@ FPSCounterPath = NodePath("FPSCounter")
PerformanceMetricsPath = NodePath("PerformanceMetrics")
EntityLabelsPath = NodePath("EntityLabels")
InspectorDialogPath = NodePath("Inspector")
entityLabelSmallFont = ExtResource("2_gkxar")
entityLabelDefaultFont = ExtResource("3_fussq")
entityDeadFont = ExtResource("4_rmq2c")
entityBindingFont = ExtResource("5_jl51v")
entityEngulfingFont = ExtResource("6_05a1v")
entityUnbindingFont = ExtResource("7_8xdu2")
FPSDisplayLabelPath = NodePath("FPSCounter/FPSDisplayLabel")
FPSLabelPath = NodePath("PerformanceMetrics/ScrollContainer/VBoxContainer/HBoxContainer/FPS")
DeltaLabelPath = NodePath("PerformanceMetrics/ScrollContainer/VBoxContainer/HBoxContainer/Delta")
Expand Down
24 changes: 24 additions & 0 deletions src/general/utils/LabelSettingsUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Godot;

public static class LabelSettingsUtils
{
/// <summary>
/// Duplicates label settings but with a different colour
/// </summary>
/// <param name="settings">Settings to duplicate</param>
/// <param name="newColour">New colour for the font</param>
/// <returns>The duplicated font</returns>
public static LabelSettings CloneWithDifferentColour(this LabelSettings settings, Color newColour)
{
return new LabelSettings
{
Font = settings.Font,
FontSize = settings.FontSize,
FontColor = newColour,
OutlineSize = 0,
ShadowColor = settings.ShadowColor,
ShadowSize = settings.ShadowSize,
ShadowOffset = settings.ShadowOffset,
};
}
}
57 changes: 14 additions & 43 deletions src/gui_common/ChemicalEquation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@
/// </summary>
public partial class ChemicalEquation : VBoxContainer
{
#pragma warning disable CA2213
[Export]
public NodePath? TitlePath;
public LabelSettings DefaultTitleFont = null!;

[Export]
public NodePath SpinnerPath = null!;
private Label? title;

[Export]
public NodePath FirstLineContainerPath = null!;

#pragma warning disable CA2213
private Label? title;
private TextureRect? spinner;

[Export]
private HBoxContainer firstLineContainer = null!;

[Export]
private LabelSettings speedLimitedTitleFont = null!;

[Export]
private Texture2D equationArrowTexture = null!;

// Dynamically generated controls
Expand Down Expand Up @@ -86,33 +89,13 @@ public bool ShowSpinner

public float SpinnerBaseSpeed { get; set; } = Constants.DEFAULT_PROCESS_SPINNER_SPEED;

public Color DefaultTitleColour
{
get => defaultTitleColour;
set
{
if (defaultTitleColour == value)
return;

defaultTitleColour = value;
if (title != null)
UpdateHeader();
}
}

/// <summary>
/// If true the title color will be changed to red if EquationFromProcess has any limiting compounds.
/// </summary>
public bool MarkRedOnLimitingCompounds { get; set; }

public override void _Ready()
{
title = GetNode<Label>(TitlePath);
spinner = GetNode<TextureRect>(SpinnerPath);
firstLineContainer = GetNode<HBoxContainer>(FirstLineContainerPath);

equationArrowTexture = GD.Load<Texture2D>("res://assets/textures/gui/bevel/WhiteArrow.png");

UpdateEquation();
}

Expand Down Expand Up @@ -144,21 +127,6 @@ public override void _Notification(int what)
}
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
if (TitlePath != null)
{
TitlePath.Dispose();
SpinnerPath.Dispose();
FirstLineContainerPath.Dispose();
}
}

base.Dispose(disposing);
}

private void UpdateEquation()
{
if (title == null)
Expand Down Expand Up @@ -216,10 +184,11 @@ private void UpdateHeader()
if (MarkRedOnLimitingCompounds && EquationFromProcess.LimitingCompounds is { Count: > 0 })
{
title.AddThemeColorOverride("font_color", new Color(1.0f, 0.3f, 0.3f));
title.LabelSettings = speedLimitedTitleFont;
}
else
{
title.AddThemeColorOverride("font_color", DefaultTitleColour);
title.LabelSettings = DefaultTitleFont;
}
}

Expand Down Expand Up @@ -257,9 +226,11 @@ private void UpdateLeftSide(List<KeyValuePair<Compound, float>> normalInputs)
{
equationArrow = new TextureRect
{
ExpandMode = TextureRect.ExpandModeEnum.FitWidthProportional,
ExpandMode = TextureRect.ExpandModeEnum.IgnoreSize,
CustomMinimumSize = new Vector2(20, 20),
Texture = equationArrowTexture,
StretchMode = TextureRect.StretchModeEnum.KeepAspectCentered,
SizeFlagsVertical = SizeFlags.ShrinkBegin,
};
firstLineContainer.AddChild(equationArrow);
}
Expand Down
15 changes: 10 additions & 5 deletions src/gui_common/ChemicalEquation.tscn
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
[gd_scene load_steps=7 format=3 uid="uid://d3vq1x8lvthvt"]
[gd_scene load_steps=9 format=3 uid="uid://d3vq1x8lvthvt"]

[ext_resource type="Theme" uid="uid://b4cx0o110g4b6" path="res://src/gui_common/thrive_theme.tres" id="1"]
[ext_resource type="Script" path="res://src/gui_common/ChemicalEquation.cs" id="2"]
[ext_resource type="Texture2D" uid="uid://cyrha88k4ioqh" path="res://assets/textures/gui/bevel/ProcessProcessing.png" id="3"]
[ext_resource type="LabelSettings" uid="uid://b6c60ljn172wp" path="res://src/gui_common/fonts/Body-Bold-Smaller.tres" id="4_77wn0"]
[ext_resource type="LabelSettings" uid="uid://4teclbsvoawb" path="res://src/gui_common/fonts/Body-Bold-Smaller-Red.tres" id="4_vbkf3"]
[ext_resource type="Texture2D" uid="uid://bembxnxct020" path="res://assets/textures/gui/bevel/WhiteArrow.png" id="5_tr4hc"]
[ext_resource type="FontFile" uid="uid://b62thy1er4r08" path="res://assets/fonts/Lato-Bold.ttf" id="5_wdgi7"]

[sub_resource type="Theme" id="1"]
default_font = ExtResource("5_wdgi7")
default_font_size = 18

[node name="ChemicalEquation" type="VBoxContainer"]
[node name="ChemicalEquation" type="VBoxContainer" node_paths=PackedStringArray("title", "spinner", "firstLineContainer")]
process_priority = 7
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
size_flags_horizontal = 3
theme = ExtResource("1")
script = ExtResource("2")
TitlePath = NodePath("HBoxContainer/Label")
SpinnerPath = NodePath("HBoxContainer/Spinner")
FirstLineContainerPath = NodePath("FirstLine")
DefaultTitleFont = ExtResource("4_77wn0")
title = NodePath("HBoxContainer/Label")
spinner = NodePath("HBoxContainer/Spinner")
firstLineContainer = NodePath("FirstLine")
speedLimitedTitleFont = ExtResource("4_vbkf3")
equationArrowTexture = ExtResource("5_tr4hc")

[node name="HBoxContainer" type="HBoxContainer" parent="."]
layout_mode = 2
Expand Down

0 comments on commit 29ae0ca

Please sign in to comment.