void RemoveCurrentWindow()
        {
            if (editedWindow == null)
            {
                return;
            }

            core.RemoveComputerModule(editedWindow);
            editedWindow = core.GetComputerModule <MechJebModuleCustomInfoWindow>();
        }
示例#2
0
        public override void OnLoad(ConfigNode local, ConfigNode type, ConfigNode global)
        {
            base.OnLoad(local, type, global);

            registry.Clear();
            editedWindow = null;

            RegisterInfoItems(vesselState);
            foreach (ComputerModule m in core.GetComputerModules <ComputerModule>())
            {
                RegisterInfoItems(m);
            }

            if (global == null)
            {
                return;
            }

            //Load custom info windows, which are stored in our ConfigNode:
            ConfigNode[] windowNodes = global.GetNodes(typeof(MechJebModuleCustomInfoWindow).Name);
            foreach (ConfigNode windowNode in windowNodes)
            {
                MechJebModuleCustomInfoWindow window = new MechJebModuleCustomInfoWindow(core);

                ConfigNode.LoadObjectFromConfig(window, windowNode);

                if (windowNode.HasValue("enabled"))
                {
                    bool loadedEnabled;
                    if (bool.TryParse(windowNode.GetValue("enabled"), out loadedEnabled))
                    {
                        window.enabled = loadedEnabled;
                    }
                }

                window.items = new List <InfoItem>();

                if (windowNode.HasNode("items"))
                {
                    ConfigNode   itemCollection = windowNode.GetNode("items");
                    ConfigNode[] itemNodes      = itemCollection.GetNodes("InfoItem");
                    foreach (ConfigNode itemNode in itemNodes)
                    {
                        string   id    = itemNode.GetValue("id");
                        InfoItem match = registry.FirstOrDefault(item => item.id == id);
                        if (match != null)
                        {
                            window.items.Add(match);
                        }
                    }
                }

                core.AddComputerModuleLater(window);
            }
        }
示例#3
0
 void AddNewWindow()
 {
     editedWindow = new MechJebModuleCustomInfoWindow(core);
     if (HighLogic.LoadedSceneIsEditor)
     {
         editedWindow.showInEditor = true;
     }
     if (HighLogic.LoadedSceneIsFlight)
     {
         editedWindow.showInFlight = true;
     }
     core.AddComputerModule(editedWindow);
     editedWindow.enabled = true;
 }
        public MechJebModuleCustomInfoWindow CreateWindowFromSharingString(string sharingString)
        {
            string[] lines = sharingString.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            if (lines[0] != "--- MechJeb Custom Window ---")
            {
                ScreenMessages.PostScreenMessage(Localizer.Format("#MechJeb_WindowEd_CustomInfoWindow_Scrmsg2"), 3.0f, ScreenMessageStyle.UPPER_RIGHT);//"Pasted text wasn't a MechJeb custom window descriptor."
                return(null);
            }

            MechJebModuleCustomInfoWindow window = new MechJebModuleCustomInfoWindow(core);

            core.AddComputerModule(window);
            window.enabled = true;

            window.FromSharingString(lines, registry);

            return(window);
        }
        protected override void WindowGUI(int windowID)
        {
            GUILayout.BeginVertical();

            if (editedWindow == null)
            {
                editedWindow = core.GetComputerModule <MechJebModuleCustomInfoWindow>();
            }

            if (editedWindow == null)
            {
                if (GUILayout.Button(Localizer.Format("#MechJeb_WindowEd_button1")))
                {
                    AddNewWindow();                                                                 //New window
                }
            }
            else
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.Button(Localizer.Format("#MechJeb_WindowEd_button1")))
                {
                    AddNewWindow();                                                                 //New window
                }
                if (GUILayout.Button(Localizer.Format("#MechJeb_WindowEd_button2")))
                {
                    RemoveCurrentWindow();                                                                 //Delete window
                }
                GUILayout.EndHorizontal();
            }

            if (editedWindow != null)
            {
                List <ComputerModule> allWindows = core.GetComputerModules <MechJebModuleCustomInfoWindow>();

                GUILayout.BeginHorizontal();
                GUILayout.Label(Localizer.Format("#MechJeb_WindowEd_Edtitle"), GUILayout.ExpandWidth(false));//Title:
                int editedWindowIndex = allWindows.IndexOf(editedWindow);
                editedWindowIndex = GuiUtils.ArrowSelector(editedWindowIndex, allWindows.Count, () =>
                {
                    string newTitle = GUILayout.TextField(editedWindow.title, GUILayout.Width(120), GUILayout.ExpandWidth(false));

                    if (editedWindow.title != newTitle)
                    {
                        editedWindow.title = newTitle;
                        editedWindow.dirty = true;
                    }
                });
                editedWindow = (MechJebModuleCustomInfoWindow)allWindows[editedWindowIndex];
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label(Localizer.Format("#MechJeb_WindowEd_label1"));                                                                                 //Show in:
                editedWindow.ShowInFlight = GUILayout.Toggle(editedWindow.ShowInFlight, Localizer.Format("#MechJeb_WindowEd_checkbox1"), GUILayout.Width(60)); //Flight
                editedWindow.ShowInEditor = GUILayout.Toggle(editedWindow.ShowInEditor, Localizer.Format("#MechJeb_WindowEd_checkbox2"));                      //Editor
                GUILayout.EndHorizontal();


                GUILayout.BeginHorizontal();
                editedWindow.IsOverlay = GUILayout.Toggle(editedWindow.IsOverlay, Localizer.Format("#MechJeb_WindowEd_checkbox3")); //Overlay
                editedWindow.Locked    = GUILayout.Toggle(editedWindow.Locked, Localizer.Format("#MechJeb_WindowEd_checkbox4"));    //Locked
                editedWindow.IsCompact = GUILayout.Toggle(editedWindow.IsCompact, Localizer.Format("#MechJeb_WindowEd_checkbox5")); //Compact
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label(Localizer.Format("#MechJeb_WindowEd_label2"));//Color:
                bool previous = editingText;

                editingText = GUILayout.Toggle(editingText, Localizer.Format("#MechJeb_WindowEd_checkbox6"));//Text

                if (editingText && editingText != previous)
                {
                    editingBackground = false;
                }

                previous          = editingBackground;
                editingBackground = GUILayout.Toggle(editingBackground, Localizer.Format("#MechJeb_WindowEd_checkbox7"));//Background

                if (editingBackground && editingBackground != previous)
                {
                    editingText = false;
                }

                GUILayout.EndHorizontal();

                GUILayout.Label(Localizer.Format("#MechJeb_WindowEd_label3"));//Window contents (click to edit):

                GUILayout.BeginVertical(GUILayout.Height(100));
                scrollPos = GUILayout.BeginScrollView(scrollPos);
                for (int i = 0; i < editedWindow.items.Count; i++)
                {
                    GUIStyle s = new GUIStyle(GUI.skin.label);
                    if (i == selectedItemIndex)
                    {
                        s.normal.textColor = Color.yellow;
                    }

                    if (GUILayout.Button(Localizer.Format(editedWindow.items[i].description), s))
                    {
                        selectedItemIndex = i;                                                                          //
                    }
                }
                GUILayout.EndScrollView();
                GUILayout.EndVertical();

                GUILayout.BeginHorizontal();

                if (!(selectedItemIndex >= 0 && selectedItemIndex < editedWindow.items.Count))
                {
                    selectedItemIndex = -1;
                }

                if (GUILayout.Button(Localizer.Format("#MechJeb_WindowEd_button3")) && selectedItemIndex != -1)
                {
                    editedWindow.items.RemoveAt(selectedItemIndex);                                             //Remove
                }
                if (GUILayout.Button(Localizer.Format("#MechJeb_WindowEd_button4")) && selectedItemIndex != -1) //"Move up"
                {
                    if (selectedItemIndex > 0)
                    {
                        InfoItem item = editedWindow.items[selectedItemIndex];
                        editedWindow.items.RemoveAt(selectedItemIndex);
                        editedWindow.items.Insert(selectedItemIndex - 1, item);
                        selectedItemIndex -= 1;
                    }
                }
                if (GUILayout.Button(Localizer.Format("#MechJeb_WindowEd_button5")) && selectedItemIndex != -1)//Move down
                {
                    if (selectedItemIndex < editedWindow.items.Count)
                    {
                        InfoItem item = editedWindow.items[selectedItemIndex];
                        editedWindow.items.RemoveAt(selectedItemIndex);
                        editedWindow.items.Insert(selectedItemIndex + 1, item);
                        selectedItemIndex += 1;
                    }
                }

                GUILayout.EndHorizontal();

                GUILayout.Label(Localizer.Format("#MechJeb_WindowEd_label4"));//Click an item to add it to the info window:

                itemCategory = (InfoItem.Category)GuiUtils.ComboBox.Box((int)itemCategory, categories, this);

                scrollPos2 = GUILayout.BeginScrollView(scrollPos2);
                foreach (InfoItem item in registry.Where(it => it.category == itemCategory).OrderBy(it => it.description))
                {
                    if (GUILayout.Button(Localizer.Format(item.description), GuiUtils.yellowOnHover))//
                    {
                        editedWindow.items.Add(item);
                    }
                }
                GUILayout.EndScrollView();
            }

            GUILayout.Label(Localizer.Format("#MechJeb_WindowEd_label5"), new GUIStyle(GUI.skin.label)
            {
                alignment = TextAnchor.MiddleCenter
            });                                                                                                                                 //Window presets:

            presetIndex = GuiUtils.ArrowSelector(presetIndex, CustomWindowPresets.presets.Length, () =>
            {
                if (GUILayout.Button(CustomWindowPresets.presets[presetIndex].name))
                {
                    MechJebModuleCustomInfoWindow newWindow = CreateWindowFromSharingString(CustomWindowPresets.presets[presetIndex].sharingString);
                    if (newWindow != null)
                    {
                        editedWindow = newWindow;
                    }
                }
            });

            GUILayout.EndVertical();

            base.WindowGUI(windowID);
        }
 public override void OnStart(PartModule.StartState state)
 {
     editedWindow = core.GetComputerModule <MechJebModuleCustomInfoWindow>();
 }
        void RemoveCurrentWindow()
        {
            if (editedWindow == null) return;

            core.RemoveComputerModule(editedWindow);
            editedWindow = core.GetComputerModule<MechJebModuleCustomInfoWindow>();
        }
 void AddNewWindow()
 {
     editedWindow = new MechJebModuleCustomInfoWindow(core);
     if (HighLogic.LoadedSceneIsEditor) editedWindow.showInEditor = true;
     if (HighLogic.LoadedSceneIsFlight) editedWindow.showInFlight = true;
     core.AddComputerModule(editedWindow);
     editedWindow.enabled = true;
 }
        protected override void WindowGUI(int windowID)
        {
            GUILayout.BeginVertical();

            if (editedWindow == null) editedWindow = core.GetComputerModule<MechJebModuleCustomInfoWindow>();

            if (editedWindow == null)
            {
                if (GUILayout.Button("New window")) AddNewWindow();
            }
            else
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("New window")) AddNewWindow();
                if (GUILayout.Button("Delete window")) RemoveCurrentWindow();
                GUILayout.EndHorizontal();
            }

            if (editedWindow != null)
            {
                List<MechJebModuleCustomInfoWindow> allWindows = core.GetComputerModules<MechJebModuleCustomInfoWindow>();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Title:", GUILayout.ExpandWidth(false));
                int editedWindowIndex = allWindows.IndexOf(editedWindow);
                editedWindowIndex = GuiUtils.ArrowSelector(editedWindowIndex, allWindows.Count, () =>
                    {
                        editedWindow.title = GUILayout.TextField(editedWindow.title, GUILayout.Width(120), GUILayout.ExpandWidth(false));
                    });
                editedWindow = allWindows[editedWindowIndex];
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Show in:");
                editedWindow.showInFlight = GUILayout.Toggle(editedWindow.showInFlight, "Flight", GUILayout.Width(60));
                editedWindow.showInEditor = GUILayout.Toggle(editedWindow.showInEditor, "Editor");
                GUILayout.EndHorizontal();

                GUILayout.Label("Window contents (click to edit):");

                GUILayout.BeginVertical(GUILayout.Height(100));
                scrollPos = GUILayout.BeginScrollView(scrollPos);
                for (int i = 0; i < editedWindow.items.Count; i++)
                {
                    GUIStyle s = new GUIStyle(GUI.skin.label);
                    if (i == selectedItemIndex) s.normal.textColor = Color.yellow;

                    if (GUILayout.Button(editedWindow.items[i].description, s)) selectedItemIndex = i;
                }
                GUILayout.EndScrollView();
                GUILayout.EndVertical();

                GUILayout.BeginHorizontal();

                if (!(selectedItemIndex >= 0 && selectedItemIndex < editedWindow.items.Count)) selectedItemIndex = -1;

                if (GUILayout.Button("Remove") && selectedItemIndex != -1) editedWindow.items.RemoveAt(selectedItemIndex);
                if (GUILayout.Button("Move up") && selectedItemIndex != -1)
                {
                    if (selectedItemIndex > 0)
                    {
                        InfoItem item = editedWindow.items[selectedItemIndex];
                        editedWindow.items.RemoveAt(selectedItemIndex);
                        editedWindow.items.Insert(selectedItemIndex - 1, item);
                        selectedItemIndex -= 1;
                    }
                }
                if (GUILayout.Button("Move down") && selectedItemIndex != -1)
                {
                    if (selectedItemIndex < editedWindow.items.Count)
                    {
                        InfoItem item = editedWindow.items[selectedItemIndex];
                        editedWindow.items.RemoveAt(selectedItemIndex);
                        editedWindow.items.Insert(selectedItemIndex + 1, item);
                        selectedItemIndex += 1;
                    }
                }

                GUILayout.EndHorizontal();

                GUILayout.Label("Click an item to add it to the info window:");

                itemCategory = (InfoItem.Category)GuiUtils.ArrowSelector((int)itemCategory, numCategories, itemCategory.ToString());

                scrollPos2 = GUILayout.BeginScrollView(scrollPos2);
                foreach (InfoItem item in registry.Where(it => it.category == itemCategory).OrderBy(it => it.description))
                {
                    if (GUILayout.Button(item.description, GuiUtils.yellowOnHover))
                    {
                        editedWindow.items.Add(item);
                    }
                }
                GUILayout.EndScrollView();
            }

            GUILayout.Label("Window presets:", new GUIStyle(GUI.skin.label) { alignment = TextAnchor.MiddleCenter });

            presetIndex = GuiUtils.ArrowSelector(presetIndex, CustomWindowPresets.presets.Length, () =>
            {
                if (GUILayout.Button(CustomWindowPresets.presets[presetIndex].name))
                {
                    MechJebModuleCustomInfoWindow newWindow = CreateWindowFromSharingString(CustomWindowPresets.presets[presetIndex].sharingString);
                    if (newWindow != null) editedWindow = newWindow;
                }
            });

            GUILayout.EndVertical();

            base.WindowGUI(windowID);
        }
 public override void OnStart(PartModule.StartState state)
 {
     editedWindow = core.GetComputerModule<MechJebModuleCustomInfoWindow>();
 }
        public override void OnLoad(ConfigNode local, ConfigNode type, ConfigNode global)
        {
            base.OnLoad(local, type, global);

            registry.Clear();
            editedWindow = null;

            RegisterInfoItems(vesselState);
            foreach (ComputerModule m in core.GetComputerModules<ComputerModule>())
            {
                RegisterInfoItems(m);
            }

            if (global == null) return;

            //Load custom info windows, which are stored in our ConfigNode:
            ConfigNode[] windowNodes = global.GetNodes(typeof(MechJebModuleCustomInfoWindow).Name);
            foreach (ConfigNode windowNode in windowNodes)
            {
                MechJebModuleCustomInfoWindow window = new MechJebModuleCustomInfoWindow(core);

                ConfigNode.LoadObjectFromConfig(window, windowNode);

                if (windowNode.HasValue("enabled"))
                {
                    bool loadedEnabled;
                    if (bool.TryParse(windowNode.GetValue("enabled"), out loadedEnabled)) window.enabled = loadedEnabled;
                }

                window.items = new List<InfoItem>();

                if (windowNode.HasNode("items"))
                {
                    ConfigNode itemCollection = windowNode.GetNode("items");
                    ConfigNode[] itemNodes = itemCollection.GetNodes("InfoItem");
                    foreach (ConfigNode itemNode in itemNodes)
                    {
                        string id = itemNode.GetValue("id");
                        InfoItem match = registry.FirstOrDefault(item => item.id == id);
                        if (match != null) window.items.Add(match);
                    }
                }

                core.AddComputerModuleLater(window);
            }
        }
        public MechJebModuleCustomInfoWindow CreateWindowFromSharingString(string sharingString)
        {
            string[] lines = sharingString.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            if (lines[0] != "--- MechJeb Custom Window ---")
            {
                ScreenMessages.PostScreenMessage("Pasted text wasn't a MechJeb custom window descriptor.", 3.0f, ScreenMessageStyle.UPPER_RIGHT);
                return null;
            }

            MechJebModuleCustomInfoWindow window = new MechJebModuleCustomInfoWindow(core);
            core.AddComputerModule(window);
            window.enabled = true;

            window.FromSharingString(lines, registry);

            return window;
        }
示例#13
0
        protected override void WindowGUI(int windowID)
        {
            GUILayout.BeginVertical();

            if (editedWindow == null)
            {
                editedWindow = core.GetComputerModule <MechJebModuleCustomInfoWindow>();
            }

            if (editedWindow == null)
            {
                if (GUILayout.Button("New window"))
                {
                    AddNewWindow();
                }
            }
            else
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("New window"))
                {
                    AddNewWindow();
                }
                if (GUILayout.Button("Delete window"))
                {
                    RemoveCurrentWindow();
                }
                GUILayout.EndHorizontal();
            }

            if (editedWindow != null)
            {
                List <MechJebModuleCustomInfoWindow> allWindows = core.GetComputerModules <MechJebModuleCustomInfoWindow>();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Title:", GUILayout.ExpandWidth(false));
                int editedWindowIndex = allWindows.IndexOf(editedWindow);
                editedWindowIndex = GuiUtils.ArrowSelector(editedWindowIndex, allWindows.Count, () =>
                {
                    editedWindow.title = GUILayout.TextField(editedWindow.title, GUILayout.Width(120), GUILayout.ExpandWidth(false));
                });
                editedWindow = allWindows[editedWindowIndex];
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Show in:");
                editedWindow.showInFlight = GUILayout.Toggle(editedWindow.showInFlight, "Flight", GUILayout.Width(60));
                editedWindow.showInEditor = GUILayout.Toggle(editedWindow.showInEditor, "Editor");
                GUILayout.EndHorizontal();

                GUILayout.Label("Window contents (click to edit):");

                GUILayout.BeginVertical(GUILayout.Height(100));
                scrollPos = GUILayout.BeginScrollView(scrollPos);
                for (int i = 0; i < editedWindow.items.Count; i++)
                {
                    GUIStyle s = new GUIStyle(GUI.skin.label);
                    if (i == selectedItemIndex)
                    {
                        s.normal.textColor = Color.yellow;
                    }

                    if (GUILayout.Button(editedWindow.items[i].description, s))
                    {
                        selectedItemIndex = i;
                    }
                }
                GUILayout.EndScrollView();
                GUILayout.EndVertical();

                GUILayout.BeginHorizontal();

                if (!(selectedItemIndex >= 0 && selectedItemIndex < editedWindow.items.Count))
                {
                    selectedItemIndex = -1;
                }

                if (GUILayout.Button("Remove") && selectedItemIndex != -1)
                {
                    editedWindow.items.RemoveAt(selectedItemIndex);
                }
                if (GUILayout.Button("Move up") && selectedItemIndex != -1)
                {
                    if (selectedItemIndex > 0)
                    {
                        InfoItem item = editedWindow.items[selectedItemIndex];
                        editedWindow.items.RemoveAt(selectedItemIndex);
                        editedWindow.items.Insert(selectedItemIndex - 1, item);
                        selectedItemIndex -= 1;
                    }
                }
                if (GUILayout.Button("Move down") && selectedItemIndex != -1)
                {
                    if (selectedItemIndex < editedWindow.items.Count)
                    {
                        InfoItem item = editedWindow.items[selectedItemIndex];
                        editedWindow.items.RemoveAt(selectedItemIndex);
                        editedWindow.items.Insert(selectedItemIndex + 1, item);
                        selectedItemIndex += 1;
                    }
                }

                GUILayout.EndHorizontal();

                GUILayout.Label("Click an item to add it to the info window:");

                itemCategory = (InfoItem.Category)GuiUtils.ArrowSelector((int)itemCategory, numCategories, itemCategory.ToString());

                scrollPos2 = GUILayout.BeginScrollView(scrollPos2);
                foreach (InfoItem item in registry.Where(it => it.category == itemCategory).OrderBy(it => it.description))
                {
                    if (GUILayout.Button(item.description, GuiUtils.yellowOnHover))
                    {
                        editedWindow.items.Add(item);
                    }
                }
                GUILayout.EndScrollView();
            }

            GUILayout.Label("Window presets:", new GUIStyle(GUI.skin.label)
            {
                alignment = TextAnchor.MiddleCenter
            });

            presetIndex = GuiUtils.ArrowSelector(presetIndex, CustomWindowPresets.presets.Length, () =>
            {
                if (GUILayout.Button(CustomWindowPresets.presets[presetIndex].name))
                {
                    MechJebModuleCustomInfoWindow newWindow = CreateWindowFromSharingString(CustomWindowPresets.presets[presetIndex].sharingString);
                    if (newWindow != null)
                    {
                        editedWindow = newWindow;
                    }
                }
            });

            GUILayout.EndVertical();

            base.WindowGUI(windowID);
        }