From 958c6def5b933010a43e785d0865fb6b1c86baa9 Mon Sep 17 00:00:00 2001 From: dexy Date: Mon, 8 Nov 2021 23:43:47 +1100 Subject: [PATCH] Auto update room portal counts when adding/editing portals --- .../GameFiles/MetaTypes/Archetype.cs | 26 +++++++++++++++++++ .../Project/Panels/EditYtypMloPortalPanel.cs | 2 ++ 2 files changed, 28 insertions(+) diff --git a/CodeWalker.Core/GameFiles/MetaTypes/Archetype.cs b/CodeWalker.Core/GameFiles/MetaTypes/Archetype.cs index 1d8cd85..41a1e27 100644 --- a/CodeWalker.Core/GameFiles/MetaTypes/Archetype.cs +++ b/CodeWalker.Core/GameFiles/MetaTypes/Archetype.cs @@ -315,6 +315,8 @@ namespace CodeWalker.GameFiles { rooms[i].Index = i; } + + UpdatePortalCounts();//portal room indices probably would need to be updated anyway } public void AddPortal(MCMloPortalDef portal) @@ -327,6 +329,8 @@ namespace CodeWalker.GameFiles var newportals = portals?.ToList() ?? new List(); newportals.Add(portal); portals = newportals.ToArray(); + + UpdatePortalCounts(); } public void RemovePortal(MCMloPortalDef portal) { @@ -340,6 +344,8 @@ namespace CodeWalker.GameFiles { portals[i].Index = i; } + + UpdatePortalCounts(); } public void AddEntitySet(MCMloEntitySet set) @@ -432,6 +438,26 @@ namespace CodeWalker.GameFiles } } + public void UpdatePortalCounts() + { + if ((rooms == null) || (portals == null)) return; + + foreach (var room in rooms) + { + uint count = 0; + foreach (var portal in portals) + { + if ((portal._Data.roomFrom == room.Index) || (portal._Data.roomTo == room.Index)) + { + count++; + } + } + room._Data.portalCount = count; + } + + } + + public void LoadChildren(Meta meta) { var centities = MetaTypes.ConvertDataArray(meta, MetaName.CEntityDef, _MloArchetypeDefData.entities); diff --git a/CodeWalker/Project/Panels/EditYtypMloPortalPanel.cs b/CodeWalker/Project/Panels/EditYtypMloPortalPanel.cs index 83e61d6..97f79d0 100644 --- a/CodeWalker/Project/Panels/EditYtypMloPortalPanel.cs +++ b/CodeWalker/Project/Panels/EditYtypMloPortalPanel.cs @@ -103,6 +103,7 @@ namespace CodeWalker.Project.Panels if (CurrentPortal._Data.roomFrom != u) { CurrentPortal._Data.roomFrom = u; + CurrentPortal.OwnerMlo?.UpdatePortalCounts(); ProjectForm.SetYtypHasChanged(true); } } @@ -123,6 +124,7 @@ namespace CodeWalker.Project.Panels if (CurrentPortal._Data.roomTo != u) { CurrentPortal._Data.roomTo = u; + CurrentPortal.OwnerMlo?.UpdatePortalCounts(); ProjectForm.SetYtypHasChanged(true); } }