mirror of
https://mirror.ghproxy.com/https://github.com/dexyfex/CodeWalker
synced 2024-11-23 07:22:52 +08:00
881 lines
31 KiB
C#
881 lines
31 KiB
C#
using CodeWalker.GameFiles;
|
|
using CodeWalker.World;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using WeifenLuo.WinFormsUI.Docking;
|
|
|
|
namespace CodeWalker.Project.Panels
|
|
{
|
|
public partial class ProjectExplorerPanel : ProjectPanel
|
|
{
|
|
public ProjectForm ProjectForm { get; set; }
|
|
public ProjectFile CurrentProjectFile { get; set; }
|
|
|
|
private bool inDoubleClick = false; //used in disabling double-click to expand tree nodes
|
|
|
|
public ProjectExplorerPanel(ProjectForm projectForm)
|
|
{
|
|
ProjectForm = projectForm;
|
|
InitializeComponent();
|
|
}
|
|
|
|
public override void SetTheme(ThemeBase theme)
|
|
{
|
|
base.SetTheme(theme);
|
|
if (theme is VS2015DarkTheme)
|
|
{
|
|
ProjectTreeView.BackColor = theme.ColorPalette.MainWindowActive.Background;
|
|
ProjectTreeView.ForeColor = Color.White;
|
|
ProjectTreeView.LineColor = Color.White;
|
|
}
|
|
else
|
|
{
|
|
ProjectTreeView.BackColor = SystemColors.Window;
|
|
ProjectTreeView.ForeColor = SystemColors.WindowText;
|
|
ProjectTreeView.LineColor = Color.Black;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void LoadProjectTree(ProjectFile projectFile)
|
|
{
|
|
ProjectTreeView.Nodes.Clear();
|
|
|
|
CurrentProjectFile = projectFile;
|
|
if (CurrentProjectFile == null) return;
|
|
|
|
var pcstr = CurrentProjectFile.HasChanged ? "*" : "";
|
|
|
|
var projnode = ProjectTreeView.Nodes.Add(pcstr + CurrentProjectFile.Name);
|
|
projnode.Tag = CurrentProjectFile;
|
|
|
|
|
|
if (CurrentProjectFile.YmapFiles.Count > 0)
|
|
{
|
|
var ymapsnode = projnode.Nodes.Add("Ymap Files");
|
|
ymapsnode.Name = "Ymap";
|
|
|
|
foreach (var ymapfile in CurrentProjectFile.YmapFiles)
|
|
{
|
|
var ycstr = ymapfile.HasChanged ? "*" : "";
|
|
string name = ymapfile.Name;
|
|
if (ymapfile.RpfFileEntry != null)
|
|
{
|
|
name = ymapfile.RpfFileEntry.Name;
|
|
}
|
|
var ymapnode = ymapsnode.Nodes.Add(ycstr + name);
|
|
ymapnode.Tag = ymapfile;
|
|
|
|
LoadYmapTreeNodes(ymapfile, ymapnode);
|
|
|
|
JenkIndex.Ensure(name);
|
|
JenkIndex.Ensure(Path.GetFileNameWithoutExtension(name));
|
|
}
|
|
ymapsnode.Expand();
|
|
}
|
|
|
|
if (CurrentProjectFile.YtypFiles.Count > 0)
|
|
{
|
|
var ytypsnode = projnode.Nodes.Add("Ytyp Files");
|
|
ytypsnode.Name = "Ytyp";
|
|
|
|
foreach (var ytypfile in CurrentProjectFile.YtypFiles)
|
|
{
|
|
var ycstr = ytypfile.HasChanged ? "*" : "";
|
|
string name = ytypfile.Name;
|
|
if (ytypfile.RpfFileEntry != null)
|
|
{
|
|
name = ytypfile.RpfFileEntry.Name;
|
|
}
|
|
var ytypnode = ytypsnode.Nodes.Add(ycstr + name);
|
|
ytypnode.Tag = ytypfile;
|
|
|
|
LoadYtypTreeNodes(ytypfile, ytypnode);
|
|
|
|
JenkIndex.Ensure(name);
|
|
JenkIndex.Ensure(Path.GetFileNameWithoutExtension(name));
|
|
}
|
|
ytypsnode.Expand();
|
|
}
|
|
|
|
if (CurrentProjectFile.YndFiles.Count > 0)
|
|
{
|
|
var yndsnode = projnode.Nodes.Add("Ynd Files");
|
|
yndsnode.Name = "Ynd";
|
|
|
|
foreach (var yndfile in CurrentProjectFile.YndFiles)
|
|
{
|
|
var ycstr = yndfile.HasChanged ? "*" : "";
|
|
string name = yndfile.Name;
|
|
if (yndfile.RpfFileEntry != null)
|
|
{
|
|
name = yndfile.RpfFileEntry.Name;
|
|
}
|
|
var yndnode = yndsnode.Nodes.Add(ycstr + name);
|
|
yndnode.Tag = yndfile;
|
|
|
|
LoadYndTreeNodes(yndfile, yndnode);
|
|
}
|
|
yndsnode.Expand();
|
|
}
|
|
|
|
if (CurrentProjectFile.YnvFiles.Count > 0)
|
|
{
|
|
var ynvsnode = projnode.Nodes.Add("Ynv Files");
|
|
ynvsnode.Name = "Ynv";
|
|
|
|
foreach (var ynvfile in CurrentProjectFile.YnvFiles)
|
|
{
|
|
var ycstr = ynvfile.HasChanged ? "*" : "";
|
|
string name = ynvfile.Name;
|
|
if (ynvfile.RpfFileEntry != null)
|
|
{
|
|
name = ynvfile.RpfFileEntry.Name;
|
|
}
|
|
var ynvnode = ynvsnode.Nodes.Add(ycstr + name);
|
|
ynvnode.Tag = ynvfile;
|
|
|
|
LoadYnvTreeNodes(ynvfile, ynvnode);
|
|
}
|
|
ynvsnode.Expand();
|
|
}
|
|
|
|
if (CurrentProjectFile.TrainsFiles.Count > 0)
|
|
{
|
|
var trainsnode = projnode.Nodes.Add("Trains Files");
|
|
trainsnode.Name = "Trains";
|
|
|
|
foreach (var trainfile in CurrentProjectFile.TrainsFiles)
|
|
{
|
|
var tcstr = trainfile.HasChanged ? "*" : "";
|
|
string name = trainfile.Name;
|
|
if (trainfile.RpfFileEntry != null)
|
|
{
|
|
name = trainfile.RpfFileEntry.Name;
|
|
}
|
|
var trainnode = trainsnode.Nodes.Add(tcstr + name);
|
|
trainnode.Tag = trainfile;
|
|
|
|
LoadTrainTrackTreeNodes(trainfile, trainnode);
|
|
}
|
|
trainsnode.Expand();
|
|
}
|
|
|
|
if (CurrentProjectFile.ScenarioFiles.Count > 0)
|
|
{
|
|
var scenariosnode = projnode.Nodes.Add("Scenario Files");
|
|
scenariosnode.Name = "Scenarios";
|
|
|
|
foreach (var scenariofile in CurrentProjectFile.ScenarioFiles)
|
|
{
|
|
var scstr = scenariofile.HasChanged ? "*" : "";
|
|
string name = scenariofile.Name;
|
|
if (scenariofile.RpfFileEntry != null)
|
|
{
|
|
name = scenariofile.RpfFileEntry.Name;
|
|
}
|
|
var scenarionode = scenariosnode.Nodes.Add(scstr + name);
|
|
scenarionode.Tag = scenariofile;
|
|
|
|
LoadScenarioTreeNodes(scenariofile, scenarionode);
|
|
}
|
|
scenariosnode.Expand();
|
|
}
|
|
|
|
projnode.Expand();
|
|
|
|
}
|
|
|
|
private void LoadYmapTreeNodes(YmapFile ymap, TreeNode node)
|
|
{
|
|
if (ymap == null) return;
|
|
|
|
if (!string.IsNullOrEmpty(node.Name)) return; //named nodes are eg Entities and CarGens
|
|
|
|
node.Nodes.Clear();
|
|
|
|
if ((ymap.AllEntities != null) && (ymap.AllEntities.Length > 0))
|
|
{
|
|
var entsnode = node.Nodes.Add("Entities (" + ymap.AllEntities.Length.ToString() + ")");
|
|
entsnode.Name = "Entities";
|
|
entsnode.Tag = ymap;
|
|
var ents = ymap.AllEntities;
|
|
for (int i = 0; i < ents.Length; i++)
|
|
{
|
|
var ent = ents[i];
|
|
var edef = ent.CEntityDef;
|
|
var enode = entsnode.Nodes.Add(edef.archetypeName.ToString());
|
|
enode.Tag = ent;
|
|
}
|
|
}
|
|
if ((ymap.CarGenerators != null) && (ymap.CarGenerators.Length > 0))
|
|
{
|
|
var cargensnode = node.Nodes.Add("Car Generators (" + ymap.CarGenerators.Length.ToString() + ")");
|
|
cargensnode.Name = "CarGens";
|
|
cargensnode.Tag = ymap;
|
|
var cargens = ymap.CarGenerators;
|
|
for (int i = 0; i < cargens.Length; i++)
|
|
{
|
|
var cargen = cargens[i];
|
|
var ccgnode = cargensnode.Nodes.Add(cargen.ToString());
|
|
ccgnode.Tag = cargen;
|
|
}
|
|
}
|
|
if ((ymap.GrassInstanceBatches != null) && (ymap.GrassInstanceBatches.Length > 0))
|
|
{
|
|
var grassbatchesnodes = node.Nodes.Add("Grass Batches (" + ymap.GrassInstanceBatches.Length.ToString() + ")");
|
|
grassbatchesnodes.Name = "GrassBatches";
|
|
grassbatchesnodes.Tag = ymap;
|
|
var grassbatches = ymap.GrassInstanceBatches;
|
|
for (int i = 0; i < grassbatches.Length; i++)
|
|
{
|
|
var batch = grassbatches[i];
|
|
var gbnode = grassbatchesnodes.Nodes.Add(batch.ToString());
|
|
gbnode.Tag = batch;
|
|
}
|
|
}
|
|
|
|
}
|
|
private void LoadYtypTreeNodes(YtypFile ytyp, TreeNode node)//TODO!
|
|
{
|
|
}
|
|
private void LoadYndTreeNodes(YndFile ynd, TreeNode node)
|
|
{
|
|
if (ynd == null) return;
|
|
|
|
if (!string.IsNullOrEmpty(node.Name)) return; //named nodes are eg Nodes
|
|
|
|
node.Nodes.Clear();
|
|
|
|
|
|
|
|
if ((ynd.Nodes != null) && (ynd.Nodes.Length > 0))
|
|
{
|
|
var nodesnode = node.Nodes.Add("Nodes (" + ynd.Nodes.Length.ToString() + ")");
|
|
nodesnode.Name = "Nodes";
|
|
nodesnode.Tag = ynd;
|
|
var nodes = ynd.Nodes;
|
|
for (int i = 0; i < nodes.Length; i++)
|
|
{
|
|
var ynode = nodes[i];
|
|
var nnode = ynode.RawData;
|
|
var tnode = nodesnode.Nodes.Add(nnode.ToString());
|
|
tnode.Tag = ynode;
|
|
}
|
|
}
|
|
|
|
}
|
|
private void LoadYnvTreeNodes(YnvFile ynv, TreeNode node)//TODO!
|
|
{
|
|
}
|
|
private void LoadTrainTrackTreeNodes(TrainTrack track, TreeNode node)
|
|
{
|
|
if (track == null) return;
|
|
|
|
if (!string.IsNullOrEmpty(node.Name)) return; //named nodes are eg Nodes
|
|
|
|
node.Nodes.Clear();
|
|
|
|
|
|
|
|
if ((track.Nodes != null) && (track.Nodes.Count > 0))
|
|
{
|
|
var nodesnode = node.Nodes.Add("Nodes (" + track.Nodes.Count.ToString() + ")");
|
|
nodesnode.Name = "Nodes";
|
|
nodesnode.Tag = track;
|
|
var nodes = track.Nodes;
|
|
for (int i = 0; i < nodes.Count; i++)
|
|
{
|
|
var ynode = nodes[i];
|
|
var tnode = nodesnode.Nodes.Add(ynode.ToString());
|
|
tnode.Tag = ynode;
|
|
}
|
|
}
|
|
|
|
}
|
|
private void LoadScenarioTreeNodes(YmtFile ymt, TreeNode node)
|
|
{
|
|
if (!string.IsNullOrEmpty(node.Name)) return; //named nodes are eg Points
|
|
|
|
node.Nodes.Clear();
|
|
|
|
var region = ymt?.ScenarioRegion;
|
|
|
|
if (region == null) return;
|
|
|
|
var nodes = region.Nodes;
|
|
if ((nodes == null) || (nodes.Count == 0)) return;
|
|
|
|
var pointsnode = node.Nodes.Add("Points (" + nodes.Count.ToString() + ")");
|
|
pointsnode.Name = "Points";
|
|
pointsnode.Tag = ymt;
|
|
for (int i = 0; i < nodes.Count; i++)
|
|
{
|
|
var snode = nodes[i];
|
|
var tnode = pointsnode.Nodes.Add(snode.MedTypeName + ": " + snode.StringText);
|
|
tnode.Tag = snode;
|
|
}
|
|
|
|
//var sr = region.Region;
|
|
//if (sr == null) return;
|
|
//int pointCount = (sr.Points?.LoadSavePoints?.Length ?? 0) + (sr.Points?.MyPoints?.Length ?? 0);
|
|
//int entityOverrideCount = (sr.EntityOverrides?.Length ?? 0);
|
|
//int chainCount = (sr.Paths?.Chains?.Length ?? 0);
|
|
//int clusterCount = (sr.Clusters?.Length ?? 0);
|
|
//TreeNode pointsNode = null;
|
|
//TreeNode entityOverridesNode = null;
|
|
//TreeNode chainsNode = null;
|
|
//TreeNode clustersNode = null;
|
|
//if (pointCount > 0)
|
|
//{
|
|
// pointsNode = node.Nodes.Add("Points (" + pointCount.ToString() + ")");
|
|
//}
|
|
//if (entityOverrideCount > 0)
|
|
//{
|
|
// entityOverridesNode = node.Nodes.Add("Entity Overrides (" + entityOverrideCount.ToString() + ")");
|
|
//}
|
|
//if (chainCount > 0)
|
|
//{
|
|
// chainsNode = node.Nodes.Add("Chains (" + chainsNode.ToString() + ")");
|
|
//}
|
|
//if (clusterCount > 0)
|
|
//{
|
|
// clustersNode = node.Nodes.Add("Clusters (" + clusterCount.ToString() + ")");
|
|
//}
|
|
//for (int i = 0; i < nodes.Count; i++)
|
|
//{
|
|
// var snode = nodes[i];
|
|
// if (snode == null) continue;
|
|
// if ((pointsNode != null) && ((snode.LoadSavePoint != null) || (snode.MyPoint != null)))
|
|
// {
|
|
// pointsNode.Nodes.Add(snode.ToString()).Tag = snode;
|
|
// }
|
|
// if ((entityOverridesNode != null) && ((snode.EntityOverride != null) || (snode.EntityPoint != null)))
|
|
// {
|
|
// entityOverridesNode.Nodes.Add(snode.ToString()).Tag = snode;
|
|
// }
|
|
// if ((chainsNode != null) && (snode.ChainingNode != null))
|
|
// {
|
|
// chainsNode.Nodes.Add(snode.ToString()).Tag = snode;
|
|
// }
|
|
// if ((clustersNode != null) && ((snode.Cluster != null) || (snode.ClusterLoadSavePoint != null) || (snode.ClusterMyPoint != null)))
|
|
// {
|
|
// clustersNode.Nodes.Add(snode.ToString()).Tag = snode;
|
|
// }
|
|
//}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetProjectHasChanged(bool changed)
|
|
{
|
|
if ((ProjectTreeView.Nodes.Count > 0) && (CurrentProjectFile != null))
|
|
{
|
|
//first node is the project...
|
|
string changestr = changed ? "*" : "";
|
|
ProjectTreeView.Nodes[0].Text = changestr + CurrentProjectFile.Name;
|
|
}
|
|
}
|
|
public void SetYmapHasChanged(YmapFile ymap, bool changed)
|
|
{
|
|
if (ProjectTreeView.Nodes.Count > 0)
|
|
{
|
|
var pnode = ProjectTreeView.Nodes[0];
|
|
var ymnode = GetChildTreeNode(pnode, "Ymap");
|
|
if (ymnode == null) return;
|
|
string changestr = changed ? "*" : "";
|
|
for (int i = 0; i < ymnode.Nodes.Count; i++)
|
|
{
|
|
var ynode = ymnode.Nodes[i];
|
|
if (ynode.Tag == ymap)
|
|
{
|
|
string name = ymap.Name;
|
|
if (ymap.RpfFileEntry != null)
|
|
{
|
|
name = ymap.RpfFileEntry.Name;
|
|
}
|
|
ynode.Text = changestr + name;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
public void SetYtypHasChanged(YtypFile ytyp, bool changed)
|
|
{
|
|
if (ProjectTreeView.Nodes.Count > 0)
|
|
{
|
|
var pnode = ProjectTreeView.Nodes[0];
|
|
var ytnode = GetChildTreeNode(pnode, "Ytyp");
|
|
if (ytnode == null) return;
|
|
string changestr = changed ? "*" : "";
|
|
for (int i = 0; i < ytnode.Nodes.Count; i++)
|
|
{
|
|
var ynode = ytnode.Nodes[i];
|
|
if (ynode.Tag == ytyp)
|
|
{
|
|
string name = ytyp.Name;
|
|
if (ytyp.RpfFileEntry != null)
|
|
{
|
|
name = ytyp.RpfFileEntry.Name;
|
|
}
|
|
ynode.Text = changestr + name;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
public void SetYndHasChanged(YndFile ynd, bool changed)
|
|
{
|
|
if (ProjectTreeView.Nodes.Count > 0)
|
|
{
|
|
var pnode = ProjectTreeView.Nodes[0];
|
|
var ynnode = GetChildTreeNode(pnode, "Ynd");
|
|
if (ynnode == null) return;
|
|
string changestr = changed ? "*" : "";
|
|
for (int i = 0; i < ynnode.Nodes.Count; i++)
|
|
{
|
|
var ynode = ynnode.Nodes[i];
|
|
if (ynode.Tag == ynd)
|
|
{
|
|
string name = ynd.Name;
|
|
if (ynd.RpfFileEntry != null)
|
|
{
|
|
name = ynd.RpfFileEntry.Name;
|
|
}
|
|
ynode.Text = changestr + name;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
public void SetYnvHasChanged(YnvFile ynv, bool changed)//TODO!
|
|
{
|
|
}
|
|
public void SetTrainTrackHasChanged(TrainTrack track, bool changed)
|
|
{
|
|
if (ProjectTreeView.Nodes.Count > 0)
|
|
{
|
|
var pnode = ProjectTreeView.Nodes[0];
|
|
var trnode = GetChildTreeNode(pnode, "Trains");
|
|
if (trnode == null) return;
|
|
string changestr = changed ? "*" : "";
|
|
for (int i = 0; i < trnode.Nodes.Count; i++)
|
|
{
|
|
var tnode = trnode.Nodes[i];
|
|
if (tnode.Tag == track)
|
|
{
|
|
string name = track.Name;
|
|
if (track.RpfFileEntry != null)
|
|
{
|
|
name = track.RpfFileEntry.Name;
|
|
}
|
|
tnode.Text = changestr + name;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
public void SetScenarioHasChanged(YmtFile scenario, bool changed)
|
|
{
|
|
if (ProjectTreeView.Nodes.Count > 0)
|
|
{
|
|
var pnode = ProjectTreeView.Nodes[0];
|
|
var scnode = GetChildTreeNode(pnode, "Scenarios");
|
|
if (scnode == null) return;
|
|
string changestr = changed ? "*" : "";
|
|
for (int i = 0; i < scnode.Nodes.Count; i++)
|
|
{
|
|
var snode = scnode.Nodes[i];
|
|
if (snode.Tag == scenario)
|
|
{
|
|
string name = scenario.Name;
|
|
if (scenario.RpfFileEntry != null)
|
|
{
|
|
name = scenario.RpfFileEntry.Name;
|
|
}
|
|
snode.Text = changestr + name;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private TreeNode GetChildTreeNode(TreeNode node, string name)
|
|
{
|
|
if (node == null) return null;
|
|
var nodes = node.Nodes.Find(name, false);
|
|
if ((nodes == null) || (nodes.Length != 1)) return null;
|
|
return nodes[0];
|
|
}
|
|
public TreeNode FindYmapTreeNode(YmapFile ymap)
|
|
{
|
|
if (ProjectTreeView.Nodes.Count <= 0) return null;
|
|
var projnode = ProjectTreeView.Nodes[0];
|
|
var ymapsnode = GetChildTreeNode(projnode, "Ymap");
|
|
if (ymapsnode == null) return null;
|
|
for (int i = 0; i < ymapsnode.Nodes.Count; i++)
|
|
{
|
|
var ymapnode = ymapsnode.Nodes[i];
|
|
if (ymapnode.Tag == ymap) return ymapnode;
|
|
}
|
|
return null;
|
|
}
|
|
public TreeNode FindEntityTreeNode(YmapEntityDef ent)
|
|
{
|
|
if (ent == null) return null;
|
|
TreeNode ymapnode = FindYmapTreeNode(ent.Ymap);
|
|
if (ymapnode == null) return null;
|
|
var entsnode = GetChildTreeNode(ymapnode, "Entities");
|
|
if (entsnode == null) return null;
|
|
for (int i = 0; i < entsnode.Nodes.Count; i++)
|
|
{
|
|
TreeNode entnode = entsnode.Nodes[i];
|
|
if (entnode.Tag == ent) return entnode;
|
|
}
|
|
return null;
|
|
}
|
|
public TreeNode FindCarGenTreeNode(YmapCarGen cargen)
|
|
{
|
|
if (cargen == null) return null;
|
|
TreeNode ymapnode = FindYmapTreeNode(cargen.Ymap);
|
|
if (ymapnode == null) return null;
|
|
var cargensnode = GetChildTreeNode(ymapnode, "CarGens");
|
|
if (cargensnode == null) return null;
|
|
for (int i = 0; i < cargensnode.Nodes.Count; i++)
|
|
{
|
|
TreeNode cargennode = cargensnode.Nodes[i];
|
|
if (cargennode.Tag == cargen) return cargennode;
|
|
}
|
|
return null;
|
|
}
|
|
public TreeNode FindYndTreeNode(YndFile ynd)
|
|
{
|
|
if (ProjectTreeView.Nodes.Count <= 0) return null;
|
|
var projnode = ProjectTreeView.Nodes[0];
|
|
var yndsnode = GetChildTreeNode(projnode, "Ynd");
|
|
if (yndsnode == null) return null;
|
|
for (int i = 0; i < yndsnode.Nodes.Count; i++)
|
|
{
|
|
var yndnode = yndsnode.Nodes[i];
|
|
if (yndnode.Tag == ynd) return yndnode;
|
|
}
|
|
return null;
|
|
}
|
|
public TreeNode FindPathNodeTreeNode(YndNode n)
|
|
{
|
|
if (n == null) return null;
|
|
TreeNode yndnode = FindYndTreeNode(n.Ynd);
|
|
var nodesnode = GetChildTreeNode(yndnode, "Nodes");
|
|
if (nodesnode == null) return null;
|
|
for (int i = 0; i < nodesnode.Nodes.Count; i++)
|
|
{
|
|
TreeNode nnode = nodesnode.Nodes[i];
|
|
if (nnode.Tag == n) return nnode;
|
|
}
|
|
return null;
|
|
}
|
|
public TreeNode FindYnvTreeNode(YnvFile ynv)
|
|
{
|
|
if (ProjectTreeView.Nodes.Count <= 0) return null;
|
|
var projnode = ProjectTreeView.Nodes[0];
|
|
var ynvsnode = GetChildTreeNode(projnode, "Ynv");
|
|
if (ynvsnode == null) return null;
|
|
for (int i = 0; i < ynvsnode.Nodes.Count; i++)
|
|
{
|
|
var yndnode = ynvsnode.Nodes[i];
|
|
if (yndnode.Tag == ynv) return yndnode;
|
|
}
|
|
return null;
|
|
}
|
|
public TreeNode FindNavPolyTreeNode(YnvPoly p)
|
|
{
|
|
if (p == null) return null;
|
|
TreeNode ynvnode = FindYnvTreeNode(p.Ynv);
|
|
var polysnode = GetChildTreeNode(ynvnode, "Polygons");
|
|
if (polysnode == null) return null;
|
|
for (int i = 0; i < polysnode.Nodes.Count; i++)
|
|
{
|
|
TreeNode pnode = polysnode.Nodes[i];
|
|
if (pnode.Tag == p) return pnode;
|
|
}
|
|
return null;
|
|
}
|
|
public TreeNode FindTrainTrackTreeNode(TrainTrack track)
|
|
{
|
|
if (ProjectTreeView.Nodes.Count <= 0) return null;
|
|
var projnode = ProjectTreeView.Nodes[0];
|
|
var trainsnode = GetChildTreeNode(projnode, "Trains");
|
|
if (trainsnode == null) return null;
|
|
for (int i = 0; i < trainsnode.Nodes.Count; i++)
|
|
{
|
|
var trainnode = trainsnode.Nodes[i];
|
|
if (trainnode.Tag == track) return trainnode;
|
|
}
|
|
return null;
|
|
}
|
|
public TreeNode FindTrainNodeTreeNode(TrainTrackNode n)
|
|
{
|
|
if (n == null) return null;
|
|
TreeNode tracknode = FindTrainTrackTreeNode(n.Track);
|
|
var nodesnode = GetChildTreeNode(tracknode, "Nodes");
|
|
if (nodesnode == null) return null;
|
|
for (int i = 0; i < nodesnode.Nodes.Count; i++)
|
|
{
|
|
TreeNode nnode = nodesnode.Nodes[i];
|
|
if (nnode.Tag == n) return nnode;
|
|
}
|
|
return null;
|
|
}
|
|
public TreeNode FindScenarioTreeNode(YmtFile ymt)
|
|
{
|
|
if (ProjectTreeView.Nodes.Count <= 0) return null;
|
|
var projnode = ProjectTreeView.Nodes[0];
|
|
var scenariosnode = GetChildTreeNode(projnode, "Scenarios");
|
|
if (scenariosnode == null) return null;
|
|
for (int i = 0; i < scenariosnode.Nodes.Count; i++)
|
|
{
|
|
var ymtnode = scenariosnode.Nodes[i];
|
|
if (ymtnode.Tag == ymt) return ymtnode;
|
|
}
|
|
return null;
|
|
}
|
|
public TreeNode FindScenarioNodeTreeNode(ScenarioNode p)
|
|
{
|
|
if (p == null) return null;
|
|
TreeNode ymtnode = FindScenarioTreeNode(p.Ymt);
|
|
var pointsnode = GetChildTreeNode(ymtnode, "Points");
|
|
if (pointsnode == null) return null;
|
|
for (int i = 0; i < pointsnode.Nodes.Count; i++)
|
|
{
|
|
TreeNode pnode = pointsnode.Nodes[i];
|
|
if (pnode.Tag == p) return pnode;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void DeselectNode()
|
|
{
|
|
ProjectTreeView.SelectedNode = null;
|
|
}
|
|
public void TrySelectEntityTreeNode(YmapEntityDef ent)
|
|
{
|
|
TreeNode entnode = FindEntityTreeNode(ent);
|
|
if (entnode != null)
|
|
{
|
|
ProjectTreeView.SelectedNode = entnode;
|
|
}
|
|
}
|
|
public void TrySelectCarGenTreeNode(YmapCarGen cargen)
|
|
{
|
|
TreeNode cargennode = FindCarGenTreeNode(cargen);
|
|
if (cargennode != null)
|
|
{
|
|
ProjectTreeView.SelectedNode = cargennode;
|
|
}
|
|
}
|
|
public void TrySelectPathNodeTreeNode(YndNode node)
|
|
{
|
|
TreeNode tnode = FindPathNodeTreeNode(node);
|
|
if (tnode == null)
|
|
{
|
|
tnode = FindYndTreeNode(node?.Ynd);
|
|
}
|
|
if (tnode != null)
|
|
{
|
|
ProjectTreeView.SelectedNode = tnode;
|
|
}
|
|
}
|
|
public void TrySelectNavPolyTreeNode(YnvPoly poly)
|
|
{
|
|
TreeNode tnode = FindNavPolyTreeNode(poly);
|
|
if (tnode == null)
|
|
{
|
|
tnode = FindYnvTreeNode(poly?.Ynv);
|
|
}
|
|
if (tnode != null)
|
|
{
|
|
ProjectTreeView.SelectedNode = tnode;
|
|
}
|
|
}
|
|
public void TrySelectTrainNodeTreeNode(TrainTrackNode node)
|
|
{
|
|
TreeNode tnode = FindTrainNodeTreeNode(node);
|
|
if (tnode == null)
|
|
{
|
|
tnode = FindTrainTrackTreeNode(node?.Track);
|
|
}
|
|
if (tnode != null)
|
|
{
|
|
ProjectTreeView.SelectedNode = tnode;
|
|
}
|
|
}
|
|
public void TrySelectScenarioTreeNode(YmtFile scenario)
|
|
{
|
|
TreeNode tnode = FindScenarioTreeNode(scenario);
|
|
if (tnode != null)
|
|
{
|
|
ProjectTreeView.SelectedNode = tnode;
|
|
}
|
|
}
|
|
public void TrySelectScenarioNodeTreeNode(ScenarioNode node)
|
|
{
|
|
TreeNode tnode = FindScenarioNodeTreeNode(node);
|
|
if (tnode == null)
|
|
{
|
|
tnode = FindScenarioTreeNode(node?.Ymt);
|
|
}
|
|
if (tnode != null)
|
|
{
|
|
ProjectTreeView.SelectedNode = tnode;
|
|
}
|
|
}
|
|
|
|
public void UpdateCarGenTreeNode(YmapCarGen cargen)
|
|
{
|
|
var tn = FindCarGenTreeNode(cargen);
|
|
if (tn != null)
|
|
{
|
|
tn.Text = cargen.ToString();
|
|
}
|
|
}
|
|
public void UpdatePathNodeTreeNode(YndNode node)
|
|
{
|
|
var tn = FindPathNodeTreeNode(node);
|
|
if (tn != null)
|
|
{
|
|
tn.Text = node._RawData.ToString();
|
|
}
|
|
}
|
|
public void UpdateNavPolyTreeNode(YnvPoly poly)
|
|
{
|
|
var tn = FindNavPolyTreeNode(poly);
|
|
if (tn != null)
|
|
{
|
|
tn.Text = poly._RawData.ToString();
|
|
}
|
|
}
|
|
public void UpdateTrainNodeTreeNode(TrainTrackNode node)
|
|
{
|
|
var tn = FindTrainNodeTreeNode(node);
|
|
if (tn != null)
|
|
{
|
|
tn.Text = node.ToString();
|
|
}
|
|
}
|
|
public void UpdateScenarioNodeTreeNode(ScenarioNode node)
|
|
{
|
|
var tn = FindScenarioNodeTreeNode(node);
|
|
if (tn != null)
|
|
{
|
|
tn.Text = node.MedTypeName + ": " + node.StringText;
|
|
}
|
|
}
|
|
|
|
public void RemoveEntityTreeNode(YmapEntityDef ent)
|
|
{
|
|
var tn = FindEntityTreeNode(ent);
|
|
if ((tn != null) && (tn.Parent != null))
|
|
{
|
|
tn.Parent.Text = "Entities (" + ent.Ymap.AllEntities.Length.ToString() + ")";
|
|
tn.Parent.Nodes.Remove(tn);
|
|
}
|
|
}
|
|
public void RemoveCarGenTreeNode(YmapCarGen cargen)
|
|
{
|
|
var tn = FindCarGenTreeNode(cargen);
|
|
if ((tn != null) && (tn.Parent != null))
|
|
{
|
|
tn.Parent.Text = "Car Generators (" + cargen.Ymap.CarGenerators.Length.ToString() + ")";
|
|
tn.Parent.Nodes.Remove(tn);
|
|
}
|
|
}
|
|
public void RemovePathNodeTreeNode(YndNode node)
|
|
{
|
|
var tn = FindPathNodeTreeNode(node);
|
|
if ((tn != null) && (tn.Parent != null))
|
|
{
|
|
tn.Parent.Text = "Nodes (" + node.Ynd.Nodes.Length.ToString() + ")";
|
|
tn.Parent.Nodes.Remove(tn);
|
|
}
|
|
}
|
|
public void RemoveTrainNodeTreeNode(TrainTrackNode node)
|
|
{
|
|
var tn = FindTrainNodeTreeNode(node);
|
|
if ((tn != null) && (tn.Parent != null))
|
|
{
|
|
tn.Parent.Text = "Nodes (" + node.Track.Nodes.Count.ToString() + ")";
|
|
tn.Parent.Nodes.Remove(tn);
|
|
}
|
|
}
|
|
public void RemoveScenarioNodeTreeNode(ScenarioNode node)
|
|
{
|
|
var tn = FindScenarioNodeTreeNode(node);
|
|
if ((tn != null) && (tn.Parent != null))
|
|
{
|
|
tn.Parent.Text = "Points (" + (node.Ymt?.ScenarioRegion?.Nodes?.Count ?? 0).ToString() + ")";
|
|
tn.Parent.Nodes.Remove(tn);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public event ProjectExplorerItemSelectHandler OnItemSelected;
|
|
public event ProjectExplorerItemActivateHandler OnItemActivated;
|
|
|
|
|
|
|
|
private void ProjectTreeView_AfterSelect(object sender, TreeViewEventArgs e)
|
|
{
|
|
OnItemSelected?.Invoke(ProjectTreeView.SelectedNode?.Tag);
|
|
}
|
|
private void ProjectTreeView_DoubleClick(object sender, EventArgs e)
|
|
{
|
|
if (ProjectTreeView.SelectedNode != null)
|
|
{
|
|
OnItemActivated?.Invoke(ProjectTreeView.SelectedNode.Tag);
|
|
}
|
|
}
|
|
|
|
private void ProjectTreeView_BeforeCollapse(object sender, TreeViewCancelEventArgs e)
|
|
{
|
|
//if (e.Node.Tag != CurrentProjectFile) return; //disabling doubleclick expand/collapse only for project node
|
|
if (inDoubleClick == true && e.Action == TreeViewAction.Collapse) e.Cancel = true;
|
|
}
|
|
private void ProjectTreeView_BeforeExpand(object sender, TreeViewCancelEventArgs e)
|
|
{
|
|
//if (e.Node.Tag != CurrentProjectFile) return; //disabling doubleclick expand/collapse only for project node
|
|
if (inDoubleClick == true && e.Action == TreeViewAction.Expand) e.Cancel = true;
|
|
}
|
|
private void ProjectTreeView_MouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
inDoubleClick = (e.Clicks > 1); //disabling doubleclick expand/collapse
|
|
}
|
|
}
|
|
public delegate void ProjectExplorerItemSelectHandler(object item);
|
|
public delegate void ProjectExplorerItemActivateHandler(object item);
|
|
}
|