Skip to content

Commit 2b562dd

Browse files
committed
visibility moved down to non renderable components
so now lights can turn on/off via their visibility and component visibility is persistent relative to the owner actor
1 parent 397984a commit 2b562dd

15 files changed

Lines changed: 120 additions & 113 deletions

File tree

CUE4Parse

Submodule CUE4Parse updated 163 files

Editor/Widgets/InspectorWidget.cs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ private void DrawFlatNode(ActorComponent component, bool warn, bool isSearching)
165165
if (!hasChildren) flags |= ImGuiTreeNodeFlags.Leaf | ImGuiTreeNodeFlags.NoTreePushOnOpen;
166166
else ImGui.SetNextItemOpen(component.IsNodeOpen, ImGuiCond.Always);
167167

168-
if (warn) ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(1f, 0.75f, 0f, 1f));
168+
if (warn) ImGui.PushStyleColor(ImGuiCol.Text, Settings.OrangeColor);
169169
var nodeOpen = ImGui.TreeNodeEx("##Component", flags, $"{(warn ? $"{WarnIcon} " : "")}{component.Icon} {component.Name}");
170170
component.IsNodeOpen = nodeOpen;
171171
if (warn) ImGui.PopStyleColor();
@@ -188,7 +188,11 @@ private void DrawFlatNode(ActorComponent component, bool warn, bool isSearching)
188188
if (ImGui.MenuItem("\uf185 Make Sun Light")) lightSystem!.DirectionalLight = dirLight;
189189
ImGui.EndDisabled();
190190
}
191-
if (ImGui.MenuItem("\uf124 Teleport To") && component is SpatialComponent spatial) spatial.TeleportTo();
191+
if (component is SpatialComponent spatial)
192+
{
193+
if (ImGui.MenuItem($"{Settings.EyeIcon} Toggle Visibility")) spatial.SetVisibility(!spatial.IsVisible, ImGui.GetIO().KeyShift);
194+
if (ImGui.MenuItem("\uf124 Teleport To")) spatial.TeleportTo();
195+
}
192196
if (ImGui.MenuItem("\uf1c9 Open JSON"))
193197
{
194198
if (component.Actor?.ActorManager is EditorManager manager)
@@ -230,7 +234,7 @@ private void DrawFlatNode(ActorComponent component, bool warn, bool isSearching)
230234
{
231235
if (warn)
232236
{
233-
ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(1f, 0.75f, 0f, 1f));
237+
ImGui.PushStyleColor(ImGuiCol.Text, Settings.OrangeColor);
234238
ImGui.TextUnformatted($"{WarnIcon} Orphaned component not attached to the tree.");
235239
ImGui.PopStyleColor();
236240
ImGui.Separator();
@@ -276,17 +280,31 @@ private void DrawFlatNode(ActorComponent component, bool warn, bool isSearching)
276280
if (nodeOpen) ImGui.TreePop();
277281
}
278282

279-
var btnW = ImGui.CalcTextSize(FileIcon).X + style.FramePadding.X * 2;
280-
ImGui.SameLine(rightEdge - btnW);
281-
ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, style.ItemSpacing with { X = 0 });
282-
ImGui.PushStyleColor(ImGuiCol.Button, Vector4.Zero);
283-
if (ImGui.Button(FileIcon))
284283
{
285-
if (component.Actor?.ActorManager is EditorManager manager)
286-
manager._jsonViewer.Open(component);
284+
ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, style.ItemSpacing with { X = 0 });
285+
ImGui.PushStyleColor(ImGuiCol.Button, Vector4.Zero);
286+
if (component is SpatialComponent spatial)
287+
{
288+
var btnW = ImGui.CalcTextSize(spatial.VisibilityIcon).X + style.FramePadding.X * 2;
289+
ImGui.SameLine(rightEdge - btnW);
290+
var textColor = spatial.VisibilityColor;
291+
if (textColor != null) ImGui.PushStyleColor(ImGuiCol.Text, textColor.Value);
292+
if (ImGui.Button(spatial.VisibilityIcon)) spatial.SetVisibility(!spatial.IsVisible, ImGui.GetIO().KeyShift);
293+
if (textColor != null) ImGui.PopStyleColor();
294+
}
295+
else
296+
{
297+
var btnW = ImGui.CalcTextSize(FileIcon).X + style.FramePadding.X * 2;
298+
ImGui.SameLine(rightEdge - btnW);
299+
if (ImGui.Button(FileIcon))
300+
{
301+
if (component.Actor?.ActorManager is EditorManager manager)
302+
manager._jsonViewer.Open(component);
303+
}
304+
}
305+
ImGui.PopStyleColor();
306+
ImGui.PopStyleVar();
287307
}
288-
ImGui.PopStyleColor();
289-
ImGui.PopStyleVar();
290308

291309
ImGui.PopID();
292310
}

Snooper/Core/Managers/ActorManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ public virtual void DrawControls()
265265
EditorUI.TogglableTreeNode("Lighting", light?.IsEnabled ?? false, () => light?.DrawControls(), toggle =>
266266
{
267267
light?.IsEnabled = toggle;
268-
light?.DirectionalLight?.IsEnabled = !toggle;
268+
light?.DirectionalLight?.SetVisibility(!toggle);
269269
// TODO: auto disable shadows
270270
});
271271
ImGui.EndDisabled();

Snooper/Rendering/Actors/Actor.cs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,12 @@ public bool IsVisible
112112
if (field == value) return;
113113

114114
field = value;
115-
116-
foreach (var component in Components.OfType<IPrimitiveComponent>())
117-
component.IsVisible = field;
118-
foreach (var child in Children)
119-
child.IsVisible = field;
115+
OnHierarchyChanged();
120116
}
121117
} = true;
122118

119+
public bool IsVisibleRecursive { get; private set; } = true;
120+
123121
public void ToggleVisibility()
124122
{
125123
IsVisible = !IsVisible;
@@ -207,7 +205,7 @@ private void MoveUnder(Actor newParent)
207205
newParent.Children.AddQuiet(this);
208206

209207
_parent = newParent;
210-
UpdateHierarchyDepth();
208+
OnHierarchyChanged();
211209

212210
manager.IncrementRevision();
213211
}
@@ -232,7 +230,7 @@ internal void OnChildAdded(Actor actor)
232230

233231
actor._parent = this;
234232
actor.RootComponent?.Relation = RootComponent;
235-
actor.UpdateHierarchyDepth();
233+
actor.OnHierarchyChanged();
236234

237235
actor.SetScene(ActorManager, EEndPlayReason.Destroyed);
238236
}
@@ -248,7 +246,7 @@ internal void OnChildRemoved(Actor actor)
248246

249247
actor._parent = null;
250248
actor.RootComponent?.Relation = null;
251-
actor.UpdateHierarchyDepth();
249+
actor.OnHierarchyChanged();
252250
}
253251

254252
internal void OnComponentAdded(ActorComponent component)
@@ -290,6 +288,17 @@ internal void OnComponentRemoved(ActorComponent component)
290288
}
291289
}
292290

291+
private void OnHierarchyChanged()
292+
{
293+
NodeDepth = (_parent?.NodeDepth ?? -1) + 1;
294+
IsVisibleRecursive = IsVisible && (_parent?.IsVisibleRecursive ?? true);
295+
296+
foreach (var component in Components)
297+
component.OnActorVisibilityChanged();
298+
foreach (var child in Children)
299+
child.OnHierarchyChanged();
300+
}
301+
293302
public override void SetOutlined(bool state)
294303
{
295304
foreach (var c in Components)
@@ -309,12 +318,7 @@ public override bool ShouldScrollHere
309318
if (field) IsNodeOpen = true;
310319
}
311320
}
312-
private void UpdateHierarchyDepth()
313-
{
314-
NodeDepth = (_parent?.NodeDepth ?? -1) + 1;
315-
foreach (var child in Children)
316-
child.UpdateHierarchyDepth();
317-
}
321+
318322
public override void DrawControls()
319323
{
320324

Snooper/Rendering/Components/ActorComponent.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ protected ActorComponent(FFastGeoComponent component) : base($"Component{compone
3535

3636
}
3737

38+
internal virtual void OnActorVisibilityChanged()
39+
{
40+
// the owning actor, or one above it, was shown or hidden
41+
}
42+
3843
private DebugComponent? _visualization;
3944
protected virtual DebugComponent? CreateDebugVisualization() => null;
4045

@@ -56,7 +61,7 @@ public void SetDebugVisualizationVisibility(bool visible)
5661
Actor.Components.Add(_visualization);
5762
}
5863

59-
_visualization.IsVisible = visible;
64+
_visualization.SetVisibility(visible);
6065
}
6166

6267
public event Action<ActorComponent>? OnRequestSystemUpdate;

Snooper/Rendering/Components/Light/LightComponent.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ public abstract class LightComponent : BillboardComponent
2222

2323
internal BufferAllocation? _allocation;
2424

25-
public bool IsEnabled { get; internal set; }
26-
2725
public LightComponent(ULightComponent component, string sprite) : base(component, sprite)
2826
{
2927
Intensity = component.Intensity;
@@ -49,7 +47,7 @@ public LightComponent(float intensity, Vector3 color, string sprite, Transform?
4947
public LightData GetLightData()
5048
{
5149
var data = new LightData();
52-
SetLightData(ref data);
50+
if (IsVisible && IsActorVisibleRecursive) SetLightData(ref data);
5351
return data;
5452
}
5553

Snooper/Rendering/Components/Mesh/LandscapeMeshComponent.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,12 @@ public LandscapeMeshComponent(ULandscapeComponent component) : base(component)
102102
}
103103

104104
private const string HeaderLabel = "Landscape";
105-
private HeaderButtons HeaderButtons => field ??= new HeaderButtons(HeaderLabel)
106-
.Add(() => IsVisible ? Settings.EyeIcon : Settings.EyeSlashIcon, () => "Toggle Visibility",
107-
() => { IsVisible = !IsVisible; }, null,
108-
() => IsVisible ? null : Settings.RedColor);
109105

110106
public override void DrawControls()
111107
{
112108
base.DrawControls();
113109

114-
var open = ImGui.CollapsingHeader(HeaderLabel, ImGuiTreeNodeFlags.DefaultOpen | ImGuiTreeNodeFlags.AllowOverlap);
115-
HeaderButtons.Draw(ImGui.GetItemRectMin(), ImGui.GetItemRectSize());
116-
117-
if (!open) return;
110+
if (!ImGui.CollapsingHeader(HeaderLabel, ImGuiTreeNodeFlags.DefaultOpen)) return;
118111

119112
EditorUI.PropertyValueTable(HeaderLabel, () =>
120113
{

Snooper/Rendering/Components/Primitive/BillboardComponent.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,12 @@ protected BillboardComponent(USceneComponent component, string sprite) : base(co
4646
}
4747

4848
private const string HeaderLabel = "Billboard";
49-
private HeaderButtons HeaderButtons => field ??= new HeaderButtons(HeaderLabel)
50-
.Add(() => IsVisible ? Settings.EyeIcon : Settings.EyeSlashIcon, () => "Toggle Visibility",
51-
() => { IsVisible = !IsVisible; }, null,
52-
() => IsVisible ? null : Settings.RedColor);
5349

5450
public override void DrawControls()
5551
{
5652
base.DrawControls();
5753

58-
var open = ImGui.CollapsingHeader(HeaderLabel, ImGuiTreeNodeFlags.DefaultOpen | ImGuiTreeNodeFlags.AllowOverlap);
59-
HeaderButtons.Draw(ImGui.GetItemRectMin(), ImGui.GetItemRectSize());
60-
61-
if (!open) return;
54+
if (!ImGui.CollapsingHeader(HeaderLabel, ImGuiTreeNodeFlags.DefaultOpen)) return;
6255

6356
EditorUI.PropertyValueTable(HeaderLabel, () =>
6457
{

0 commit comments

Comments
 (0)