Esempio n. 1
0
        /// <summary>
        /// Attempts to find a TreeNode in the save file or data files
        /// </summary>
        /// <param name="treeNode"></param>
        /// <returns></returns>
        public Json_File FindOwningFile(Base_TN treeNode)
        {
            if (treeNode == null)
            {
                return(null);
            }

            // Check the Save File first.
            Debug.Print("Searching " + SaveFile.File.FullName);
            if (SaveFile.RootNode.AllNodes.Contains(treeNode))
            {
                return(SaveFile);
            }

            foreach (Json_File_UI file in StaticData.DataDictionary.Values)
            {
                Debug.Print("Searching " + file.File.FullName);
                if (file.RootNode.AllNodes.Contains(treeNode))
                {
                    return(file);
                }
            }

            foreach (Json_File_UI file in StationsData.DataDictionary.Values)
            {
                Debug.Print("Searching " + file.File.FullName);
                if (file.RootNode.AllNodes.Contains(treeNode))
                {
                    return(file);
                }
            }

            foreach (Json_File_UI file in CollisionData.DataDictionary.Values)
            {
                Debug.Print("Searching " + file.File.FullName);
                if (file.RootNode.AllNodes.Contains(treeNode))
                {
                    return(file);
                }
            }



            // Unable to find a match.
            return(null);     //FindOwningFile(token);
        }
        /// <summary>
        /// Constructor that takes a DirectoryInfo and if valid, triggers the load
        /// </summary>
        /// <param name="passedDirectoryInfo"></param>
        /// <param name="autoPopulateTree"></param>
        public Json_FileCollection(IParent_Json_File passedParent, DirectoryInfo passedDirectoryInfo, int populateDepth = 0)
        {
            // Set up the data dictionary
            DataDictionary = new Dictionary <string, Json_File_UI>();

            // Check validity - if good load the data set
            OwnerObject       = passedParent ?? throw new InvalidOperationException("passedParent was null.");
            DataDirectoryInfo = passedDirectoryInfo ?? throw new NullReferenceException("passedDirectoryInfo was null.");
            if (!DataDirectoryInfo.Exists)
            {
                throw new DirectoryNotFoundException("DataDirectoryInfo reports the passed folder doesn't exist.");
            }

            RootNode = new Base_TN(ownerObject: this, nodeType: Base_TN_NodeType.DataFolder,
                                   nodeName: DataDirectoryInfo.Name);

            Load(populateDepth: populateDepth);
        }
Esempio n. 3
0
        private void TreeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            // Update the object path + name + Tag in the object identifier bar
            HellionExplorerProgram.RefreshSelectedOjectPathBarText(e.Node);
            HellionExplorerProgram.RefreshListView(e.Node);
            HellionExplorerProgram.RefreshSelectedObjectSummaryText(e.Node);
            HellionExplorerProgram.RefreshStatusStrip(e.Node);

            // Show menu only if the right mouse button is clicked.
            if (e.Button == MouseButtons.Right)
            {
                Base_TN node = (Base_TN)e.Node;
                // Get the node that the user has clicked.
                if (node == null)
                {
                    return;
                }

                // Select in the TreeView the node the user has clicked.
                treeView1.SelectedNode = node;

                // Determine node type and activate appropriate jump to menu items.
                Type t = node.GetType();
                // Handles Json_TN nodes for the Game Data representation.
                if (t.Equals(typeof(Json_TN)))
                {
                    // We're working with a GAME DATA node

                    // Enable the Json Data View
                    //jsonDataViewToolStripMenuItem.Enabled = true;

                    // Editing of Json is now handled by the Edit menu item on the
                    // context menu. At this point only Objects seem
                    // suitable for use in the Json editor - otherwise de-serialisation
                    // fails and changes can't be applied to the main document.

                    switch (node.NodeType)
                    {
                    case Base_TN_NodeType.SaveFile:
                    case Base_TN_NodeType.DataFile:
                    case Base_TN_NodeType.StationBlueprintFile:
                    case Base_TN_NodeType.JsonObject:
                        //case Base_TN_NodeType.JsonArray:
                        // Show the Edit menu item.
                        editToolStripMenuItem1.Enabled = true;
                        break;

                    default:
                        // Disable the Edit menu item.
                        editToolStripMenuItem1.Enabled = false;
                        break;
                    }



                    // Enable the Jump to sub-menu
                    jumpToToolStripMenuItem.Enabled = true;

                    // GD nodes always have load items visible, even if enabled
                    loadNextLevelToolStripMenuItem.Enabled = true;
                    loadAllLevelsToolStripMenuItem.Enabled = true;

                    // We're in the Game Data already, so disable selection of it
                    thisObjectInGameDataViewToolStripMenuItem.Enabled = false;
                    thisObjectInGameDataViewToolStripMenuItem.Checked = true;

                    // Disable these two as they're Solar System related
                    rootOfDockingTreeToolStripMenuItem.Enabled   = false;
                    parentCelestialBodyToolStripMenuItem.Enabled = false;

                    // Cast the node to an Json_TN type
                    Json_TN gDnode = (Json_TN)treeView1.SelectedNode;

                    // Disable the LoadNextLevel item if it's already been loaded.
                    if (gDnode.ChildNodesLoaded)
                    {
                        loadNextLevelToolStripMenuItem.Enabled = false;
                    }
                    else
                    {
                        loadNextLevelToolStripMenuItem.Enabled = true;
                    }

                    if (gDnode.LinkedSolarSystemNode != null)
                    {
                        // It's a Game Data node that has a linked Solar System node
                        // Enable the Jump to menu item
                        thisObjectInSolarSystemViewToolStripMenuItem.Enabled = true;
                        thisObjectInSolarSystemViewToolStripMenuItem.Checked = false;
                    }
                    else
                    {
                        thisObjectInSolarSystemViewToolStripMenuItem.Enabled = false;
                        thisObjectInSolarSystemViewToolStripMenuItem.Checked = false;
                    }
                }

                else if (t.Equals(typeof(Base_TN)) && node.NodeType == Base_TN_NodeType.StationBlueprintFile)
                {
                    // Enable the Edit menu item.
                    editToolStripMenuItem1.Enabled = true;

                    // Disable the Jump to sub-menu
                    jumpToToolStripMenuItem.Enabled = false;

                    // Disable Jump to sub-items.
                    thisObjectInGameDataViewToolStripMenuItem.Enabled    = false;
                    thisObjectInGameDataViewToolStripMenuItem.Checked    = false;
                    thisObjectInSolarSystemViewToolStripMenuItem.Enabled = false;
                    thisObjectInSolarSystemViewToolStripMenuItem.Checked = false;
                    rootOfDockingTreeToolStripMenuItem.Enabled           = false;
                    parentCelestialBodyToolStripMenuItem.Enabled         = false;

                    // Disable load items.
                    loadNextLevelToolStripMenuItem.Enabled = false;
                    loadAllLevelsToolStripMenuItem.Enabled = false;
                }


                // Handles SolarSystem_TN Nodes for the Solar System representation.
                else if (t.Equals(typeof(SolarSystem_TN)))
                {
                    // We're working with a SOLAR SYSTEM node

                    // Hide the Edit menu item.
                    editToolStripMenuItem1.Enabled = false;

                    // Disable the Json Data View option.
                    //jsonDataViewToolStripMenuItem.Enabled = false;

                    // Solar System nodes never have load options
                    loadNextLevelToolStripMenuItem.Enabled = false;
                    loadAllLevelsToolStripMenuItem.Enabled = false;

                    // We're in the Solar System already, so disable selection of it
                    thisObjectInSolarSystemViewToolStripMenuItem.Enabled = false;
                    thisObjectInSolarSystemViewToolStripMenuItem.Checked = true;

                    // Cast the node as an SolarSystem_TN type
                    SolarSystem_TN sSnode = (SolarSystem_TN)treeView1.SelectedNode;

                    if (sSnode.GUID == -1 || sSnode.NodeType == Base_TN_NodeType.SolarSystemView ||
                        sSnode.NodeType == Base_TN_NodeType.BlueprintHierarchyView)
                    {
                        // We're dealing with the Solar System Root Node or a Blueprint Hierarchy
                        // View node, special cases.

                        jumpToToolStripMenuItem.Enabled = false;
                        thisObjectInGameDataViewToolStripMenuItem.Enabled = false;
                        thisObjectInGameDataViewToolStripMenuItem.Checked = false;
                    }
                    else
                    {
                        if (sSnode.LinkedGameDataNode == null) // throw new NullReferenceException("sNode.LinkedGameDataNode was null.");
                        {
                            thisObjectInGameDataViewToolStripMenuItem.Enabled = false;
                            thisObjectInGameDataViewToolStripMenuItem.Checked = false;
                        }
                        else
                        {
                            thisObjectInGameDataViewToolStripMenuItem.Enabled = true;
                            thisObjectInGameDataViewToolStripMenuItem.Checked = false;
                        }
                        // Enable the Jump to sub-menu unless it's the Solar System root node
                        if (sSnode.GUID != -1)
                        {
                            jumpToToolStripMenuItem.Enabled = true;
                        }
                        else
                        {
                            jumpToToolStripMenuItem.Enabled = false;
                        }

                        // Enable the Root of Docking Tree option only if the node's parent type
                        // is a ship, indicating it is docked to something (rather than something
                        // being docked *to* this node i.e. child nodes).
                        rootOfDockingTreeToolStripMenuItem.Enabled = sSnode.IsDockedToParent;
                    }
                }

                // Handles Blueprint_TN for blueprint files.
                else if (t.Equals(typeof(Blueprint_TN)))
                {
                    // Some decision making logic needed here

                    if (node.NodeType == Base_TN_NodeType.StationBlueprintFile)
                    {
                        // Show the Edit menu item.
                        editToolStripMenuItem1.Enabled = true;
                    }
                    else
                    {
                        editToolStripMenuItem1.Enabled = false;
                    }



                    // Disable the Json Data View
                    //jsonDataViewToolStripMenuItem.Enabled = false;

                    // Disable the Jump to sub-menu
                    jumpToToolStripMenuItem.Enabled = false;

                    // Disable the Solar System Jump to option
                    thisObjectInSolarSystemViewToolStripMenuItem.Enabled = false;
                    thisObjectInSolarSystemViewToolStripMenuItem.Checked = false;

                    // Disable the Game Data Jump to option
                    thisObjectInGameDataViewToolStripMenuItem.Enabled = false;
                    thisObjectInGameDataViewToolStripMenuItem.Checked = false;

                    // Disable these two as they're Solar System related
                    rootOfDockingTreeToolStripMenuItem.Enabled   = false;
                    parentCelestialBodyToolStripMenuItem.Enabled = false;

                    // Disable the load options
                    loadNextLevelToolStripMenuItem.Enabled = false;
                    loadAllLevelsToolStripMenuItem.Enabled = false;
                }

                // Default behaviour - handles other node types.
                else
                {
                    // Hide the Edit menu item.
                    editToolStripMenuItem1.Enabled = false;

                    // Disable the Json Data View
                    //jsonDataViewToolStripMenuItem.Enabled = false;

                    // Disable the Jump to sub-menu
                    jumpToToolStripMenuItem.Enabled = false;

                    // Disable the Solar System Jump to option
                    thisObjectInSolarSystemViewToolStripMenuItem.Enabled = false;
                    thisObjectInSolarSystemViewToolStripMenuItem.Checked = false;

                    // Disable the Game Data Jump to option
                    thisObjectInGameDataViewToolStripMenuItem.Enabled = false;
                    thisObjectInGameDataViewToolStripMenuItem.Checked = false;

                    // Disable these two as they're Solar System related
                    rootOfDockingTreeToolStripMenuItem.Enabled   = false;
                    parentCelestialBodyToolStripMenuItem.Enabled = false;

                    // Disable the load options
                    loadNextLevelToolStripMenuItem.Enabled = false;
                    loadAllLevelsToolStripMenuItem.Enabled = false;
                }

                // Show the ContextMenuStrip.
                contextMenuStrip1.Show(treeView1, e.Location);
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Handles closing of the Solar System object. Sets RootNode to null.
 /// </summary>
 public void Close()
 {
     RootNode = null;
 }
Esempio n. 5
0
        /// <summary>
        /// Constructor that takes a FileInfo and a DirectoryInfo representing the save file
        /// and the Data folder.
        /// </summary>
        /// <param name="SaveFileInfo">The FileInfo representing the save file.</param>
        /// <param name="StaticDataFolderInfo">The DirectoryInfo representing the Data folder.</param>
        public GameData(FileInfo SaveFileInfo, DirectoryInfo StaticDataFolderInfo)
        {
            RootNode = new Base_TN(ownerObject: this, nodeType: Base_TN_NodeType.LocalServer, nodeName: "Game Data");
            if (SaveFileInfo != null && SaveFileInfo.Exists)
            {
                // Create new save file object.
                SaveFile = new GameSave_Json_File(this, SaveFileInfo, populateDepth: Def_SaveFileNodeDepth);

                // Pre-load in several levels of node.
                //((Json_TN)SaveFile.RootNode).CreateChildNodesFromjData(3);

                if (SaveFile.RootNode == null)
                {
                    throw new Exception("SaveFile rootNode was null");
                }
                else
                {
                    RootNode.Nodes.Insert(0, SaveFile.RootNode);
                }
            }

            if (StaticDataFolderInfo != null && StaticDataFolderInfo.Exists)
            {
                StaticData = new Json_FileCollection(this, StaticDataFolderInfo, populateDepth: Def_DataFileNodeDepth);
                if (StaticData.RootNode == null)
                {
                    throw new Exception("StaticData rootNode was null");
                }
                else
                {
                    RootNode.Nodes.Insert(0, StaticData.RootNode);
                }

                // Create the Station Blueprint sub-folder
                DirectoryInfo stationsInfo = new DirectoryInfo(StaticDataFolderInfo.FullName + @"\Stations");
                StationsData = new Json_FileCollection(this, stationsInfo, populateDepth: Def_DataFileNodeDepth);
                if (StationsData.RootNode == null)
                {
                    throw new Exception("StationsData rootNode was null");
                }
                else
                {
                    // Set this level's type (overriding the default for a file collection)
                    StationsData.RootNode.NodeType = Base_TN_NodeType.BlueprintCollection;

                    // Override each of the blueprint file types also.
                    foreach (Base_TN node in StationsData.RootNode.Nodes)
                    {
                        node.NodeType = Base_TN_NodeType.StationBlueprintFile;
                    }
                    StaticData.RootNode.Nodes.Add(StationsData.RootNode);
                }

                // Create the Collisions sub-folder.
                DirectoryInfo collsionInfo = new DirectoryInfo(StaticDataFolderInfo.FullName + @"\Collision");
                CollisionData = new Json_FileCollection(this, collsionInfo, populateDepth: Def_DataFileNodeDepth);
                if (CollisionData.RootNode == null)
                {
                    throw new Exception("CollisionData rootNode was null");
                }
                else
                {
                    CollisionData.RootNode.NodeType = Base_TN_NodeType.CollisionDataFolder;
                    StaticData.RootNode.Nodes.Add(CollisionData.RootNode);
                }
            }
        }