diff --git a/CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs b/CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs index a7fa2f2..a541802 100644 --- a/CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs +++ b/CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs @@ -1332,6 +1332,31 @@ namespace CodeWalker.GameFiles + public void SetName(string newname) + { + var newnamel = newname.ToLowerInvariant(); + var newnamex = newname + ".ymap"; + var newnamexl = newname.ToLowerInvariant(); + var newhash = JenkHash.GenHash(newnamel); + JenkIndex.Ensure(newnamel); + if (RpfFileEntry != null) + { + RpfFileEntry.Name = newnamex; + RpfFileEntry.NameLower = newnamexl; + RpfFileEntry.NameHash = JenkHash.GenHash(newnamexl); + RpfFileEntry.ShortNameHash = newhash; + } + Name = newnamex; + _CMapData.name = newhash; + } + public void SetFilePath(string filepath) + { + FilePath = filepath.ToLowerInvariant(); + var newname = Path.GetFileNameWithoutExtension(filepath); + SetName(newname); + } + + public bool CalcFlags() { uint flags = 0; diff --git a/CodeWalker/Project/Panels/EditYmapPanel.cs b/CodeWalker/Project/Panels/EditYmapPanel.cs index 7b177f9..d82fa9a 100644 --- a/CodeWalker/Project/Panels/EditYmapPanel.cs +++ b/CodeWalker/Project/Panels/EditYmapPanel.cs @@ -362,14 +362,13 @@ namespace CodeWalker.Project.Panels { lock (ProjectForm.ProjectSyncRoot) { - string ymname = name + ".ymap"; - if (Ymap.Name != ymname) + Ymap.SetName(name); + if (!File.Exists(Ymap.FilePath)) { - Ymap.Name = ymname; - Ymap._CMapData.name = new MetaHash(hash); - SetYmapHasChanged(true); - UpdateFormTitle(); + Ymap.FilePath = name; } + SetYmapHasChanged(true); + UpdateFormTitle(); } } } diff --git a/CodeWalker/Project/Panels/ProjectExplorerPanel.cs b/CodeWalker/Project/Panels/ProjectExplorerPanel.cs index b0e87ef..b800c36 100644 --- a/CodeWalker/Project/Panels/ProjectExplorerPanel.cs +++ b/CodeWalker/Project/Panels/ProjectExplorerPanel.cs @@ -755,10 +755,6 @@ namespace CodeWalker.Project.Panels } public void SetYmapHasChanged(YmapFile ymap, bool changed) { - if (ymap != null) - { - ymap.HasChanged = true; - } if (ProjectTreeView.Nodes.Count > 0) { var pnode = ProjectTreeView.Nodes[0]; @@ -783,10 +779,6 @@ namespace CodeWalker.Project.Panels } public void SetYtypHasChanged(YtypFile ytyp, bool changed) { - if (ytyp != null) - { - ytyp.HasChanged = true; - } if (ProjectTreeView.Nodes.Count > 0) { var pnode = ProjectTreeView.Nodes[0]; @@ -811,10 +803,6 @@ namespace CodeWalker.Project.Panels } public void SetYbnHasChanged(YbnFile ybn, bool changed) { - if (ybn != null) - { - ybn.HasChanged = true; - } if (ProjectTreeView.Nodes.Count > 0) { var pnode = ProjectTreeView.Nodes[0]; @@ -839,10 +827,6 @@ namespace CodeWalker.Project.Panels } public void SetYndHasChanged(YndFile ynd, bool changed) { - if (ynd != null) - { - ynd.HasChanged = true; - } if (ProjectTreeView.Nodes.Count > 0) { var pnode = ProjectTreeView.Nodes[0]; @@ -867,10 +851,6 @@ namespace CodeWalker.Project.Panels } public void SetYnvHasChanged(YnvFile ynv, bool changed) { - if (ynv != null) - { - ynv.HasChanged = true; - } if (ProjectTreeView.Nodes.Count > 0) { var pnode = ProjectTreeView.Nodes[0]; @@ -895,10 +875,6 @@ namespace CodeWalker.Project.Panels } public void SetTrainTrackHasChanged(TrainTrack track, bool changed) { - if (track != null) - { - track.HasChanged = true; - } if (ProjectTreeView.Nodes.Count > 0) { var pnode = ProjectTreeView.Nodes[0]; @@ -923,10 +899,6 @@ namespace CodeWalker.Project.Panels } public void SetScenarioHasChanged(YmtFile scenario, bool changed) { - if (scenario != null) - { - scenario.HasChanged = true; - } if (ProjectTreeView.Nodes.Count > 0) { var pnode = ProjectTreeView.Nodes[0]; @@ -951,10 +923,6 @@ namespace CodeWalker.Project.Panels } public void SetAudioRelHasChanged(RelFile rel, bool changed) { - if (rel != null) - { - rel.HasChanged = true; - } if (ProjectTreeView.Nodes.Count > 0) { var pnode = ProjectTreeView.Nodes[0]; @@ -979,10 +947,6 @@ namespace CodeWalker.Project.Panels } public void SetGrassBatchHasChanged(YmapGrassInstanceBatch batch, bool changed) { - if (batch?.Ymap != null) - { - batch.Ymap.HasChanged = true; - } if (ProjectTreeView.Nodes.Count > 0) { var gbnode = FindGrassTreeNode(batch); diff --git a/CodeWalker/Project/ProjectForm.cs b/CodeWalker/Project/ProjectForm.cs index 3d6a2e4..7d01d23 100644 --- a/CodeWalker/Project/ProjectForm.cs +++ b/CodeWalker/Project/ProjectForm.cs @@ -1781,13 +1781,7 @@ namespace CodeWalker.Project { return; } } - filepath = filepath.ToLowerInvariant(); - string newname = Path.GetFileNameWithoutExtension(filepath); - JenkIndex.Ensure(newname); - CurrentYmapFile.FilePath = filepath; - CurrentYmapFile.RpfFileEntry.Name = new FileInfo(filepath).Name; - CurrentYmapFile.Name = CurrentYmapFile.RpfFileEntry.Name; - CurrentYmapFile._CMapData.name = new MetaHash(JenkHash.GenHash(newname)); + CurrentYmapFile.SetFilePath(filepath); data = CurrentYmapFile.Save(); } @@ -8340,13 +8334,15 @@ namespace CodeWalker.Project { if (CurrentYmapFile == null) return; - bool changechange = changed != CurrentYmapFile.HasChanged; - if (!changechange) return; - CurrentYmapFile.HasChanged = changed; ProjectExplorer?.SetYmapHasChanged(CurrentYmapFile, changed); + RefreshUI(); + + bool changechange = changed != CurrentYmapFile.HasChanged; + if (!changechange) return; + PromoteIfPreviewPanelActive(); } public void SetYtypHasChanged(bool changed)