示例#1
0
        protected void LateUpdate()
        {
            if (simulator != null && !(HighLogic.LoadedSceneIsFlight && MapView.MapIsEnabled))
            {
                if (simulator.HeatLoops == null || simulator.HeatLoops.Count == 0)
                {
                    Utils.Log(String.Format("[SystemHeatOverlay]: No loops, destroying overlay"), LogType.Overlay);
                    DestroyOverlay();
                }
                // Update each loop, build a new loop when needed
                foreach (HeatLoop loop in simulator.HeatLoops)
                {
                    // if we have an overlay for this loop, update it
                    OverlayLoop curOverlay = overlayLoops.FirstOrDefault(x => x.heatLoop.ID == loop.ID);
                    if (curOverlay != null)
                    {
                        // if no modules, hide the loop
                        if (loop.LoopModules.Count <= 1 && curOverlay.Drawn)
                        {
                            Utils.Log(String.Format("[SystemHeatOverlay]: Loop has < 2 members, hiding"), LogType.Overlay);
                            curOverlay.SetVisible(false);
                        }
                        else
                        {
                            curOverlay.SetVisible((SystemHeatUI.Instance.OverlayMasterState && SystemHeatUI.Instance.OverlayLoopState(loop.ID)));
                            if (curOverlay.Drawn)
                            {
                                curOverlay.Update(loop);
                            }
                        }
                    }
                    // else build a new loop
                    else
                    {
                        Utils.Log(String.Format("[SystemHeatOverlay]: Building a new overlay for loop {0}", loop.ID), LogType.Overlay);
                        overlayLoops.Add(new OverlayLoop(loop, overlayRoot, (SystemHeatUI.Instance.OverlayMasterState && SystemHeatUI.Instance.OverlayLoopState(loop.ID))));
                    }

                    foreach (ModuleSystemHeat system in loop.LoopModules)
                    {
                        int index = overlayPanels.FindIndex(f => f.heatModule == system);
                        if (index == -1)
                        {
                            Utils.Log($"[SystemHeatOverlay]: Building new OverlayPanel for system {system.moduleID}", LogType.Overlay);
                            // new panel instance
                            GameObject newUIPanel = (GameObject)Instantiate(SystemHeatUILoader.OverlayPanelPrefab, Vector3.zero, Quaternion.identity);
                            newUIPanel.transform.SetParent(UIMasterController.Instance.actionCanvas.transform);
                            newUIPanel.transform.localPosition = Vector3.zero;
                            OverlayPanel panel = newUIPanel.AddComponent <OverlayPanel>();
                            panel.parentCanvas = UIMasterController.Instance.appCanvas;
                            panel.SetupLoop(loop, system, (SystemHeatUI.Instance.OverlayMasterState && SystemHeatUI.Instance.OverlayLoopState(loop.ID)));
                            overlayPanels.Add(panel);
                        }
                        else
                        {
                            // Update the panel
                            overlayPanels[index].UpdateLoop(loop, system, (SystemHeatUI.Instance.OverlayMasterState && SystemHeatUI.Instance.OverlayLoopState(loop.ID)));
                        }
                    }
                }


                for (int i = overlayPanels.Count - 1; i >= 0; i--)
                {
                    if (overlayPanels[i].heatModule == null)
                    {
                        Utils.Log(String.Format("[SystemHeatOverlay]: Destroying unusued overlay panel"), LogType.Overlay);

                        Destroy(overlayPanels[i].gameObject);
                        overlayPanels.RemoveAt(i);
                    }
                }
                foreach (OverlayLoop l in overlayLoops)
                {
                    if (!simulator.HasLoop(l.heatLoop.ID))
                    {
                        l.SetVisible(false);
                    }
                }
            }
            else
            {
                DestroyOverlay();
                foreach (OverlayPanel panel in overlayPanels)
                {
                    panel.SetVisibility(false);
                }
            }
        }
示例#2
0
        protected void LateUpdate()
        {
            if (simulator != null && !(HighLogic.LoadedSceneIsFlight && MapView.MapIsEnabled))
            {
                if (simulator.HeatLoops == null || simulator.HeatLoops.Count == 0)
                {
                    foreach (KeyValuePair <int, OverlayLoop> kvp in overlayLoops)
                    {
                        kvp.Value.Destroy();
                    }
                    overlayLoops.Clear();
                    overlayLoopVisibility.Clear();
                }
                // Update each loop, build a new loop when needed
                foreach (KeyValuePair <int, HeatLoop> kvp in simulator.HeatLoops)
                {
                    bool loopDrawn = false;
                    overlayLoopVisibility.TryGetValue(kvp.Key, out loopDrawn);
                    if (kvp.Value.LoopModules.Count > 1)
                    {
                        // Check to see if the loops's panels are all built
                        foreach (ModuleSystemHeat system in kvp.Value.LoopModules)
                        {
                            int index = overlayPanels.FindIndex(f => f.heatModule == system);
                            if (index == -1)
                            {
                                Utils.Log($"[SystemHeatOverlay]: Building new OverlayPanel for system {system.moduleID}");
                                // new panel instance
                                GameObject newUIPanel = (GameObject)Instantiate(SystemHeatUILoader.OverlayPanelPrefab, Vector3.zero, Quaternion.identity);
                                newUIPanel.transform.SetParent(UIMasterController.Instance.actionCanvas.transform);
                                newUIPanel.transform.localPosition = Vector3.zero;
                                OverlayPanel panel = newUIPanel.AddComponent <OverlayPanel>();
                                panel.parentCanvas = UIMasterController.Instance.appCanvas;
                                panel.SetupLoop(kvp.Value, system, loopDrawn);
                                overlayPanels.Add(panel);
                            }
                            else
                            {
                                // Update the panel
                                overlayPanels[index].UpdateLoop(kvp.Value, system, loopDrawn);
                            }
                        }

                        // Update the overlay
                        if (overlayLoops.ContainsKey(kvp.Key))
                        {
                            overlayLoops[kvp.Key].Update(kvp.Value);
                            if (loopDrawn && !overlayLoops[kvp.Key].Drawn)
                            {
                                overlayLoops[kvp.Key].SetVisible(loopDrawn);
                            }
                        }
                        else
                        {
                            if (SystemHeatSettings.DebugOverlay)
                            {
                                Utils.Log(String.Format("[SystemHeatOverlay]: Building a new overlay for loop {0}", kvp.Key));
                            }
                            overlayLoops[kvp.Key]          = new OverlayLoop(kvp.Value, overlayRoot, loopDrawn);
                            overlayLoopVisibility[kvp.Key] = loopDrawn;
                        }
                    }
                    else
                    {
                        if (overlayLoops.ContainsKey(kvp.Key) && overlayLoops[kvp.Key].Drawn)
                        {
                            Utils.Log(String.Format("[SystemHeatOverlay]: Loop has < 2 members, hiding"));
                            overlayLoops[kvp.Key].SetVisible(false);
                        }
                    }
                }

                for (int i = overlayPanels.Count - 1; i >= 0; i--)
                {
                    if (overlayPanels[i].heatModule == null)
                    {
                        if (SystemHeatSettings.DebugOverlay)
                        {
                            Utils.Log(String.Format("[SystemHeatOverlay]: Destroying unusued overlay panel"));
                        }

                        Destroy(overlayPanels[i].gameObject);
                        overlayPanels.RemoveAt(i);
                    }
                }
            }
            else
            {
                if (simulator != null)
                {
                    foreach (KeyValuePair <int, OverlayLoop> kvp in overlayLoops)
                    {
                        kvp.Value.SetVisible(false);
                    }
                    foreach (OverlayPanel panel in overlayPanels)
                    {
                        panel.SetVisibility(false);
                    }
                }
                else
                {
                    foreach (KeyValuePair <int, OverlayLoop> kvp in overlayLoops)
                    {
                        kvp.Value.SetVisible(false);
                    }
                }
            }
        }