/// <summary> /// Instantiates a new MainWindow prefab GameObject, sets its parent to the MainCanvas and saves a reference to the MainWindow component. /// Sets IsVisible to true, Updates the IVesselElements list, initializes the window. /// </summary> private void OpenWindow() { if (PTGUI_Loader.MainWindowPrefab == null) { return; } window = Instantiate(PTGUI_Loader.MainWindowPrefab).GetComponent <MainWindow>(); if (window == null) { return; } window.transform.SetParent(MainCanvasUtil.MainCanvas.transform); IsVisible = true; // Update the vessel list by clearing it and forcing an Update. IvesselElements.Clear(); Update(); // Pass the instance to the MainWindow class as an interface to initialize the window. window.SetInitialState(Instance); }
/// <summary> /// Checks if a vessel is valid. If it is, creates a new PTGUI_Vessel Monobehaviour and adds its interface to the IVesselElements list. /// Otherwise, it removes it from the vessel list. /// </summary> /// <param name="v"> Vessel that is being examined. </param> private void AddVesselToIVesselList(Vessel v) { // Check if vessel is valid, in a valid situation, and if it has any persistent engine bool remove; if (IvesselElements.ContainsKey(v.id)) { remove = !v.IsVesselValid(); } else { remove = !v.IsVesselValid() || !v.HasPersistentEngineModules(); } // If not in the dictionary and valid, add it if (!IvesselElements.ContainsKey(v.id) && !remove) { var veInterface = PTGUI_Vessel.Create(v); // Add new vessel to the list and instantiate IvesselElements[v.id] = veInterface; veInterface.HasPersistentThrustActive = veInterface.PersistentThrustEnabled(v).Contains(true); } // Fails filter, so remove the vessel if (remove && IvesselElements.ContainsKey(v.id)) { window.RemoveVessel(IvesselElements[v.id]); IvesselElements.Remove(v.id); } }