Beispiel #1
0
 /// <summary>
 ///     Draws an action list for the supplied sections.
 /// </summary>
 private void DrawSections(IEnumerable <SectionModule> sections)
 {
     try
     {
         foreach (var section in sections)
         {
             GUILayout.BeginHorizontal();
             section.IsVisible       = GUILayout.Toggle(section.IsVisible, section.Name.ToUpper(), this.buttonStyle);
             section.IsEditorVisible = GUILayout.Toggle(section.IsEditorVisible, "EDIT", this.buttonStyle, GUILayout.Width(50.0f));
             GUILayout.EndHorizontal();
         }
     }
     catch (Exception ex)
     {
         MyLogger.Exception(ex);
     }
 }
Beispiel #2
0
        protected void OnGUI()
        {
            try
            {
                if (!Visible || Hidden || selectedPart == null)
                {
                    return;
                }

                position = GUILayout.Window(GetInstanceID(), position, Window, string.Empty, BuildOverlay.WindowStyle);
            }
            catch (Exception ex)

            {
                MyLogger.Exception(ex);
            }
        }
 /// <summary>
 /// Loads config
 /// </summary>
 private static void LoadReadoutConfig()
 {
     try {
         SettingHandler handler = SettingHandler.Load("ReadoutsConfig.xml", new Type[] { typeof(ReadoutModuleConfigNode) });
         foreach (ReadoutModule readout in readouts)
         {
             ReadoutModuleConfigNode r = handler.Get <ReadoutModuleConfigNode>(readout.Name, null);
             if (r != null)
             {
                 readout.ValueStyle.normal.textColor = r.Color;
             }
         }
         handler.Save("ReadoutsConfig.xml");
     } catch (Exception ex) {
         MyLogger.Exception(ex);
     }
 }
 /// <summary>
 ///     Sets the instance to this object.
 /// </summary>
 protected void Awake()
 {
     try {
         if (Instance == null)
         {
             Instance = this;
             GuiDisplaySize.OnSizeChanged += this.OnSizeChanged;
             Debug.Log("DisplayStackTS->Awake");
         }
         else
         {
             Destroy(this);
         }
     } catch (Exception ex) {
         MyLogger.Exception(ex);
     }
 }
Beispiel #5
0
        /// <summary>
        ///     Update all required Flight Engineer objects.
        /// </summary>
        private void Update()
        {
            if (FlightGlobals.ActiveVessel == null)
            {
                return;
            }

            try
            {
                SectionLibrary.Update();
                this.UpdateModules();
            }
            catch (Exception ex)
            {
                MyLogger.Exception(ex);
            }
        }
Beispiel #6
0
 /// <summary>
 ///     Creates a section window, adds it to the FlightEngineerCore and returns a reference to it.
 /// </summary>
 public SectionWindow AddSectionWindow(SectionModule section)
 {
     try {
         if (this.gameObject == null)
         {
             return(null);
         }
         var window = this.gameObject.AddComponent <SectionWindow>();
         window.ParentSection  = section;
         window.WindowPosition = new Rect(section.FloatingPositionX, section.FloatingPositionY, 0, 0);
         this.SectionWindows.Add(window);
         return(window);
     } catch (Exception ex) {
         MyLogger.Exception(ex);
         return(null);
     }
 }
        protected void Update()
        {
            try
            {
                if (!Visible)
                {
                    return;
                }

                SetResources();
                SetSlidePosition();
            }
            catch (Exception ex)
            {
                MyLogger.Exception(ex);
            }
        }
 /// <summary>
 ///     Creates a section editor, adds it to the FlightEngineerCore and returns a reference to it.
 /// </summary>
 public SectionEditor AddSectionEditor(SectionModule section)
 {
     try
     {
         var editor = this.gameObject.AddComponent <SectionEditor>();
         editor.ParentSection = section;
         editor.Position      = new Rect(section.EditorPositionX, section.EditorPositionY, SectionEditor.Width, SectionEditor.Height);
         this.SectionEditors.Add(editor);
         ReadoutCategory.Selected = ReadoutCategory.GetCategory("Orbital");
         return(editor);
     }
     catch (Exception ex)
     {
         MyLogger.Exception(ex);
         return(null);
     }
 }
Beispiel #9
0
 /// <summary>
 ///     Draws and performs the control bar button action.
 /// </summary>
 private void DrawControlBarButton()
 {
     try
     {
         GUILayout.BeginHorizontal();
         DisplayStack.Instance.Hidden = !GUILayout.Toggle(!DisplayStack.Instance.Hidden, "SHOW ENGINEER", this.buttonStyle);
         if (GUILayout.Toggle(DisplayStack.Instance.ShowControlBar, "CONTROL BAR", this.buttonStyle) != DisplayStack.Instance.ShowControlBar)
         {
             DisplayStack.Instance.ShowControlBar = !DisplayStack.Instance.ShowControlBar;
             DisplayStack.Instance.RequestResize();
         }
         GUILayout.EndHorizontal();
     }
     catch (Exception ex)
     {
         MyLogger.Exception(ex);
     }
 }
Beispiel #10
0
 protected void OnDestroy()
 {
     try
     {
         GameEvents.onGUIApplicationLauncherReady.Remove(this.OnGuiAppLauncherReady);
         GameEvents.onHideUI.Remove(this.OnHide);
         GameEvents.onShowUI.Remove(this.OnShow);
         if (button != null)
         {
             ApplicationLauncher.Instance.RemoveModApplication(this.button);
         }
     }
     catch (Exception ex)
     {
         MyLogger.Exception(ex);
     }
     MyLogger.Log("ActionMenu was destroyed.");
 }
Beispiel #11
0
        protected void Awake()
        {
            try
            {
                Instance   = this;
                bodiesList = gameObject.AddComponent <DropDown>();
                bodiesList.DrawCallback = DrawBodiesList;
                Load();

                SimManager.UpdateModSettings();
                SimManager.OnReady -= GetStageInfo;
                SimManager.OnReady += GetStageInfo;
            }
            catch (Exception ex)
            {
                MyLogger.Exception(ex, "BuildAdvanced.Awake()");
            }
        }
Beispiel #12
0
        public static void RemoveReadoutConfig(ReadoutModule readout)
        {
            try {
                SettingHandler handler = SettingHandler.Load("ReadoutsConfig.xml", new Type[] { typeof(ReadoutModuleConfigNode) });
                var            r       = handler.Get <ReadoutModuleConfigNode>(readout.Name, null);

                if (r == null)
                {
                    return;
                }

                handler.Items.Remove(handler.Items.Find(i => i.Name == readout.Name));

                handler.Save("ReadoutsConfig.xml");
            } catch (Exception ex) {
                MyLogger.Exception(ex);
            }
        }
        private void OnGUI()
        {
            try
            {
                if (this.Resize)
                {
                    this.position.height = 0;
                    this.Resize          = false;
                }

                GUI.skin      = null;
                this.position = GUILayout.Window(this.GetInstanceID(), this.position, this.Window, string.Empty, this.windowStyle);
            }
            catch (Exception ex)
            {
                MyLogger.Exception(ex);
            }
        }
Beispiel #14
0
 protected void Awake()
 {
     try
     {
         if (instance == null)
         {
             DontDestroyOnLoad(this);
             instance     = this;
             this.enabled = false;
             return;
         }
         Destroy(this);
     }
     catch (Exception ex)
     {
         MyLogger.Exception(ex);
     }
 }
        protected void Update()
        {
            try
            {
                if (!FlightEngineerCore.IsDisplayable)
                {
                    return;
                }

                if (Input.GetKeyDown(KeyBinder.FlightShowHide))
                {
                    this.Hidden = !this.Hidden;
                }
            }
            catch (Exception ex)
            {
                MyLogger.Exception(ex);
            }
        }
        /// <summary>
        ///     Create base Flight Engineer child objects.
        /// </summary>
        private void Awake()
        {
            try
            {
                Instance = this;

                this.SectionWindows   = new List <SectionWindow>();
                this.SectionEditors   = new List <SectionEditor>();
                this.UpdatableModules = new List <IUpdatable>();

                SimManager.UpdateModSettings();

                MyLogger.Log("FlightEngineerCore->Awake");
            }
            catch (Exception ex)
            {
                MyLogger.Exception(ex);
            }
        }
        /// <summary>
        ///     Draws and performs the new section button action.
        /// </summary>
        private void DrawNewButton()
        {
            try {
                GUILayout.BeginHorizontal();

                if (GUILayout.Button("NEW CUSTOM SECTION", this.buttonStyle))
                {
                    SectionLibrary.CustomSections.Add(new SectionModule {
                        Name            = "Custom " + (SectionLibrary.CustomSections.Count + 1),
                        Abbreviation    = "CUST " + (SectionLibrary.CustomSections.Count + 1),
                        IsVisible       = true,
                        IsEditorVisible = true
                    });
                }
                GUILayout.EndHorizontal();
            } catch (Exception ex) {
                MyLogger.Exception(ex);
            }
        }
Beispiel #18
0
        /// <summary>
        ///     Saves an object to disk.
        /// </summary>
        public static void SaveObject <T>(string path, T obj)
        {
            if (obj == null || string.IsNullOrEmpty(path))
            {
                return;
            }

            try
            {
                using (StreamWriter stream = new StreamWriter(path, false, Encoding.UTF8))
                {
                    new XmlSerializer(typeof(T)).Serialize(stream, obj);
                }
            }
            catch (Exception ex)
            {
                MyLogger.Exception(ex);
            }
        }
        /// <summary>
        ///     Updates the details by recalculating if requested.
        /// </summary>
        public void Update()
        {
            try
            {
                if (!this.hasCheckedAeroMods)
                {
                    this.CheckAeroMods();
                }

                if (FlightGlobals.ActiveVessel.atmDensity < double.Epsilon || NearInstalled)
                {
                    ShowDetails = false;
                    return;
                }

                ShowDetails = true;

                if (FarInstalled)
                {
                    TerminalVelocity = (double)this.farTerminalVelocity.Invoke(null, null);
                }
                else
                {
                    var m = FlightGlobals.ActiveVessel.parts.Sum(part => PartExtensions.GetWetMass(part)) * 1000.0;
                    var g = FlightGlobals.getGeeForceAtPosition(FlightGlobals.ship_position).magnitude;
                    var a = FlightGlobals.ActiveVessel.parts.Sum(part => part.DragCubes.AreaDrag) * PhysicsGlobals.DragCubeMultiplier;
                    var p = FlightGlobals.ActiveVessel.atmDensity;
                    var c = PhysicsGlobals.DragMultiplier;

                    TerminalVelocity = Math.Sqrt((2.0 * m * g) / (p * a * c));

                    StaticPressure  = FlightGlobals.ActiveVessel.staticPressurekPa;
                    DynamicPressure = FlightGlobals.ActiveVessel.dynamicPressurekPa;
                }

                Efficiency = FlightGlobals.ship_srfSpeed / TerminalVelocity;
            }
            catch (Exception ex)
            {
                MyLogger.Exception(ex, "AtmosphericProcessor->Update");
            }
        }
        protected void OnGUI()
        {
            try
            {
                if (!Visible || EditorLogic.RootPart == null || EditorLogic.fetch.editorScreen != EditorScreen.Parts)
                {
                    return;
                }

                open = GUI.Toggle(tabPosition, open, tabContent, BuildOverlay.TabStyle);
                if (openPercent > 0.0)
                {
                    windowPosition = GUILayout.Window(GetInstanceID(), windowPosition, VesselWindow, string.Empty, BuildOverlay.WindowStyle);
                }
            }
            catch (Exception ex)
            {
                MyLogger.Exception(ex);
            }
        }
Beispiel #21
0
 protected void Awake()
 {
     try
     {
         if (instance != null)
         {
             Destroy(this);
             return;
         }
         instance              = this;
         buildOverlayPartInfo  = this.gameObject.AddComponent <BuildOverlayPartInfo>();
         buildOverlayVessel    = this.gameObject.AddComponent <BuildOverlayVessel>();
         buildOverlayResources = this.gameObject.AddComponent <BuildOverlayResources>();
         Load();
     }
     catch (Exception ex)
     {
         MyLogger.Exception(ex);
     }
 }
 private void InitialiseStyles()
 {
     try
     {
         this.windowStyle = new GUIStyle
         {
             normal =
             {
                 background = GameDatabase.Instance.GetTexture("KerbalEngineer/Textures/DropDownBackground", false)
             },
             border  = new RectOffset(8, 8, 1, 8),
             margin  = new RectOffset(),
             padding = new RectOffset(5, 5, 5, 5)
         };
     }
     catch (Exception ex)
     {
         MyLogger.Exception(ex);
     }
 }
Beispiel #23
0
        public static void SaveReadoutConfig(ReadoutModule readout)
        {
            try {
                SettingHandler handler = SettingHandler.Load("ReadoutsConfig.xml", new Type[] { typeof(ReadoutModuleConfigNode) });
                var            r       = handler.Get <ReadoutModuleConfigNode>(readout.Name, null);

                if (r == null)
                {
                    r = new ReadoutModuleConfigNode();
                }

                r.Name  = readout.Name;
                r.Color = readout.ValueStyle.normal.textColor;

                handler.Set(r.Name, r);
                handler.Save("ReadoutsConfig.xml");
            } catch (Exception ex) {
                MyLogger.Exception(ex);
            }
        }
Beispiel #24
0
 /// <summary>
 ///     Loads the settings when this object is created.
 /// </summary>
 private void Load()
 {
     try
     {
         SettingHandler handler = SettingHandler.Load("BuildAdvanced.xml");
         handler.Get("visible", ref visible);
         position.x = handler.Get("windowPositionX", position.x);
         position.y = handler.Get("windowPositionY", position.y);
         handler.Get("compactMode", ref compactMode);
         handler.Get("compactCollapseRight", ref compactCollapseRight);
         handler.Get("showAllStages", ref showAllStages);
         handler.Get("showAtmosphericDetails", ref showAtmosphericDetails);
         handler.Get("showSettings", ref showSettings);
         CelestialBodies.SetSelectedBody(handler.Get("selectedBodyName", CelestialBodies.SelectedBody.Name));
     }
     catch (Exception ex)
     {
         MyLogger.Exception(ex, "BuildAdvanced.Load()");
     }
 }
        protected void OnGUI()
        {
            try
            {
                if (!Visible || resources.Count == 0)
                {
                    return;
                }

                open = GUI.Toggle(tabPosition, open, tabContent, BuildOverlay.TabStyle);
                if (openPercent > 0.0)
                {
                    windowPosition = GUILayout.Window(GetInstanceID(), windowPosition, Window, String.Empty, BuildOverlay.WindowStyle);
                }
            }
            catch (Exception ex)
            {
                MyLogger.Exception(ex);
            }
        }
        /// <summary>
        ///     Draws the menu window.
        /// </summary>
        private void Window(int windowId)
        {
            try {
                GUILayout.BeginVertical();

                this.DrawControlBarButton();
                GUILayout.Space(5.0f);
                this.DrawSections(SectionLibrary.StockSections);
                this.DrawSections(SectionLibrary.CustomSections);
                GUILayout.Space(5.0f);
                if (HighLogic.LoadedSceneIsFlight)
                {
                    this.DrawNewButton();
                }

                GUILayout.EndVertical();
            } catch (Exception ex) {
                MyLogger.Exception(ex);
            }
        }
Beispiel #27
0
        protected void Update()
        {
            try
            {
                if (Input.GetKeyDown(KeyBinder.EditorShowHide))
                {
                    visible = !visible;
                    if (!visible)
                    {
                        EditorLock(false);
                    }
                }

                if (!visible || EditorLogic.fetch == null || EditorLogic.fetch.ship.parts.Count == 0)
                {
                    bodiesList.enabled = false;
                    return;
                }

                // Configure the simulation parameters based on the selected reference body.
                SimManager.Gravity = CelestialBodies.SelectedBody.Gravity;

                if (showAtmosphericDetails)
                {
                    SimManager.Atmosphere = CelestialBodies.SelectedBody.GetAtmospheres(Altitude);
                }
                else
                {
                    SimManager.Atmosphere = 0;
                }

                SimManager.Mach = atmosphericMach;

                SimManager.RequestSimulation();
                SimManager.TryStartSimulation();
            }
            catch (Exception ex)
            {
                MyLogger.Exception(ex, "BuildAdvanced.Update()");
            }
        }
Beispiel #28
0
        /// <summary>
        ///     Loads an object from disk.
        /// </summary>
        public static T LoadObject <T>(string path)
        {
            T obj = default(T);

            if (File.Exists(path))
            {
                try
                {
                    using (StreamReader stream = new StreamReader(path, Encoding.UTF8))
                    {
                        obj = (T) new XmlSerializer(typeof(T)).Deserialize(stream);
                    }
                }
                catch (Exception ex)
                {
                    MyLogger.Exception(ex);
                }
            }

            return(obj);
        }
        protected void Update()
        {
            try
            {
                if (!Visible || EditorLogic.RootPart == null)
                {
                    return;
                }

                if (openPercent > 0.0)
                {
                    SetVesselInfo();
                }

                SetSlidePosition();
            }
            catch (Exception ex)
            {
                MyLogger.Exception(ex);
            }
        }
Beispiel #30
0
        /// <summary>
        ///     Update all required Flight Engineer objects.
        /// </summary>
        private void Update()
        {
            if (switchVesselOnUpdate)
            {
                Vessel tempVessel = switchVesselTarget;
                switchVesselTarget   = null;
                switchVesselOnUpdate = false;

                //bool doRestore = (tempVessel != null) && tempVessel.loaded;

                if (switchVesselTargetTarget != null)
                { // you will switch or I will beat you.
                    tempVessel.protoVessel.targetInfo = new ProtoTargetInfo(switchVesselTargetTarget);
                    tempVessel.pTI          = tempVessel.protoVessel.targetInfo;
                    tempVessel.targetObject = switchVesselTargetTarget;
                }

                FlightGlobals.SetActiveVessel(tempVessel);

                //if (doRestore)
                //    FlightInputHandler.ResumeVesselCtrlState(tempVessel);
                //else
                //    FlightInputHandler.SetNeutralControls();
            }

            if (FlightGlobals.ActiveVessel == null)
            {
                return;
            }

            try
            {
                SectionLibrary.Update();
                this.UpdateModules();
            }
            catch (Exception ex)
            {
                MyLogger.Exception(ex);
            }
        }