public void RegisterGUIItem(EngineThrustControllerGUIItem item)
        {
            if(m_guiItems.Count == 0)
                AddGUI();

            if(m_guiItems.Contains(item)) return;
            m_guiItems.Add(item);
        }
        public void WindowFunc(int id)
        {
            bool isButtonClicked = false;

            if (isMinimized)
            {
                GUILayout.BeginVertical(GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true), GUILayout.MinWidth(Screen.width / 4), GUILayout.MaxWidth(Screen.width / 3));
            }
            else
            {
                GUILayout.BeginVertical(GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true), GUILayout.MinWidth(Screen.width / 4), GUILayout.MaxWidth(Screen.width / 3), GUILayout.MinHeight(Screen.height / 2));
            }
            {
                GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true), GUILayout.MinWidth(Screen.width / 4));
                {
                    isButtonClicked = GUILayout.Button((isMinimized ? "Restore" : "Minimize"), GUILayout.ExpandWidth(true));
                }
                GUILayout.EndHorizontal();

                for (int i = 0; i < m_guiItems.Count; ++i)
                {
                    EngineThrustControllerGUIItem item = m_guiItems[i];
                    if (item.CheckValid() == false)
                    {
                        item.UnregisterGUI(this);
                        --i;
                    }
                }

                if (isMinimized == false)
                {
                    verticalScroll = GUILayout.BeginScrollView(verticalScroll, GUILayout.ExpandWidth(true), GUILayout.MinWidth(Screen.width / 4), GUILayout.ExpandHeight(true), GUILayout.MinHeight(Screen.height / 8), GUILayout.MaxHeight(Screen.height / 2));
                    {
                        foreach (EngineThrustControllerGUIItem item in m_guiItems)
                        {
                            if (item.CheckAttached())
                            {
                                item.RenderGUI();
                            }
                        }
                    }
                    GUILayout.EndScrollView();
                }
            }
            GUILayout.EndVertical();

            GUI.DragWindow(new Rect(0, 0, 2000, 30));

            if (isButtonClicked)
            {
                isMinimized   = !isMinimized;
                windowUpdated = true;
            }
        }
        public void UnregisterGUIItem(EngineThrustControllerGUIItem item)
        {
            if (m_guiItems.Contains(item))
            {
                m_guiItems.Remove(item);
            }

            if (m_guiItems.Count == 0)
            {
                DeleteGUI();
            }
        }
        public void RegisterGUIItem(EngineThrustControllerGUIItem item)
        {
            if (m_guiItems.Count == 0)
            {
                AddGUI();
            }

            if (m_guiItems.Contains(item))
            {
                return;
            }
            m_guiItems.Add(item);
        }
        public override void OnStart(StartState state)
        {
            Debug.Log("ModuleEngineThrustController OnStart(" + state.ToString() + ")");
            m_state = state;

            if (state == StartState.None) return;

            BindEngine();

            if (minimumThrustPercent < 0.0f) minimumThrustPercent = 0.0f;
            if (minimumThrustPercent > 1.0f) minimumThrustPercent = 1.0f;

            if (maximumThrustPercent < 0.0f) maximumThrustPercent = 0.0f;
            if (maximumThrustPercent > 1.0f) maximumThrustPercent = 1.0f;

            if (minimumThrustPercent > maximumThrustPercent) minimumThrustPercent = maximumThrustPercent;

            if (initialThrust < minimumThrustPercent) initialThrust = minimumThrustPercent;
            if (initialThrust > maximumThrustPercent) initialThrust = maximumThrustPercent;

            // Save original engine data.
            if (engine != null)
            {
                originalMaxThrust = engine.maxThrust;
                originalHeatProduction = engine.heatProduction;
                if (((int)state & (int)StartState.PreLaunch) > 0)
                    thrustPercent = initialThrust;
                else if (state == StartState.Editor)
                    thrustPercent = initialThrust;

                engine.maxThrust = originalMaxThrust * thrustPercent;
                engine.heatProduction = originalHeatProduction * thrustPercent;
            }
            else if (engineFX != null)
            {
                originalMaxThrust = engineFX.maxThrust;
                originalHeatProduction = engineFX.heatProduction;
                if (((int)state & (int)StartState.PreLaunch) > 0)
                    thrustPercent = initialThrust;
                else if (state == StartState.Editor)
                    thrustPercent = initialThrust;

                engineFX.maxThrust = originalMaxThrust * thrustPercent;
                engineFX.heatProduction = originalHeatProduction * thrustPercent;
            }
            Debug.Log("Data saved:" + originalMaxThrust.ToString() + " " + thrustPercent.ToString("0%"));

            if (state == StartState.Editor)
            {
                EngineThrustControllerGUI.GetInstance().CheckClear();
                if (showItemInList == true)
                {
                    EngineThrustControllerGUIItem item = new EngineThrustControllerGUIItem(EngineThrustControllerGUI.GetInstance(), this);
                }
                return;
            }
            else
            {
                EngineThrustControllerGUI.GetInstance().ClearGUIItem();
            }

            if (canAdjustAtAnytime == true)
            {
                Events["ContextMenuIncreaseThrust"].guiName = "Increase Thrust by " + percentAdjustmentStep.ToString("0%");
                Events["ContextMenuDecreaseThrust"].guiName = "Decrease Thrust by " + percentAdjustmentStep.ToString("0%");
            }
            else
            {
                Events["ContextMenuIncreaseThrust"].guiActive = false;
                Events["ContextMenuIncreaseThrust"].active = false;
                Events["ContextMenuDecreaseThrust"].guiActive = false;
                Events["ContextMenuDecreaseThrust"].active = false;
            }
            Events["Group1"].guiName = "Set Group 1";
            Events["Group2"].guiName = "Set Group 2";
            Events["Group1"].guiActive = false;
            Events["Group2"].guiActive = false;
            base.OnStart(state);
        }
        public void UnregisterGUIItem(EngineThrustControllerGUIItem item)
        {
            if(m_guiItems.Contains(item))
                m_guiItems.Remove(item);

            if(m_guiItems.Count == 0) DeleteGUI();
        }
Beispiel #7
0
        public override void OnStart(StartState state)
        {
            Debug.Log("ModuleEngineThrustController OnStart(" + state.ToString() + ")");
            m_state = state;

            if (state == StartState.None)
            {
                return;
            }

            BindEngine();

            if (minimumThrustPercent < 0.0f)
            {
                minimumThrustPercent = 0.0f;
            }
            if (minimumThrustPercent > 1.0f)
            {
                minimumThrustPercent = 1.0f;
            }

            if (maximumThrustPercent < 0.0f)
            {
                maximumThrustPercent = 0.0f;
            }
            if (maximumThrustPercent > 1.0f)
            {
                maximumThrustPercent = 1.0f;
            }

            if (minimumThrustPercent > maximumThrustPercent)
            {
                minimumThrustPercent = maximumThrustPercent;
            }

            if (initialThrust < minimumThrustPercent)
            {
                initialThrust = minimumThrustPercent;
            }
            if (initialThrust > maximumThrustPercent)
            {
                initialThrust = maximumThrustPercent;
            }

            // Save original engine data.
            if (engine != null)
            {
                originalMaxThrust      = engine.maxThrust;
                originalHeatProduction = engine.heatProduction;
                if (((int)state & (int)StartState.PreLaunch) > 0)
                {
                    thrustPercent = initialThrust;
                }
                else if (state == StartState.Editor)
                {
                    thrustPercent = initialThrust;
                }

                engine.maxThrust      = originalMaxThrust * thrustPercent;
                engine.heatProduction = originalHeatProduction * thrustPercent;
            }
            else if (engineFX != null)
            {
                originalMaxThrust      = engineFX.maxThrust;
                originalHeatProduction = engineFX.heatProduction;
                if (((int)state & (int)StartState.PreLaunch) > 0)
                {
                    thrustPercent = initialThrust;
                }
                else if (state == StartState.Editor)
                {
                    thrustPercent = initialThrust;
                }

                engineFX.maxThrust      = originalMaxThrust * thrustPercent;
                engineFX.heatProduction = originalHeatProduction * thrustPercent;
            }
            Debug.Log("Data saved:" + originalMaxThrust.ToString() + " " + thrustPercent.ToString("0%"));

            if (state == StartState.Editor)
            {
                EngineThrustControllerGUI.GetInstance().CheckClear();
                if (showItemInList == true)
                {
                    EngineThrustControllerGUIItem item = new EngineThrustControllerGUIItem(EngineThrustControllerGUI.GetInstance(), this);
                }
                return;
            }
            else
            {
                EngineThrustControllerGUI.GetInstance().ClearGUIItem();
            }

            if (canAdjustAtAnytime == true)
            {
                Events["ContextMenuIncreaseThrust"].guiName = "Increase Thrust by " + percentAdjustmentStep.ToString("0%");
                Events["ContextMenuDecreaseThrust"].guiName = "Decrease Thrust by " + percentAdjustmentStep.ToString("0%");
            }
            else
            {
                Events["ContextMenuIncreaseThrust"].guiActive = false;
                Events["ContextMenuIncreaseThrust"].active    = false;
                Events["ContextMenuDecreaseThrust"].guiActive = false;
                Events["ContextMenuDecreaseThrust"].active    = false;
            }
            Events["Group1"].guiName   = "Set Group 1";
            Events["Group2"].guiName   = "Set Group 2";
            Events["Group1"].guiActive = false;
            Events["Group2"].guiActive = false;
            base.OnStart(state);
        }