示例#1
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);
            }
        }
        public string ToSharingString()
        {
            string windowSharingString = "--- MechJeb Custom Window ---\n";

            windowSharingString += "Name: " + GetName() + "\n";
            windowSharingString += "Show in:" + (ShowInEditor ? " editor" : "") + (ShowInFlight ? " flight" : "") + "\n";
            for (int i = 0; i < items.Count; i++)
            {
                InfoItem item = items[i];
                windowSharingString += item.id + "\n";
            }
            windowSharingString += "-----------------------------\n";
            windowSharingString  = windowSharingString.Replace("\n", Environment.NewLine);
            return(windowSharingString);
        }
        protected override void WindowGUI(int windowID)
        {
            GUI.skin         = isCompact ? GuiUtils.compactSkin : GuiUtils.skin;
            GUI.contentColor = text;

            GUILayout.BeginVertical();
            for (int i = 0; i < items.Count; i++)
            {
                InfoItem item = items[i];
                if (HighLogic.LoadedSceneIsEditor ? item.showInEditor : item.showInFlight)
                {
                    item.DrawItem();
                }
                else
                {
                    GUILayout.Label(Localizer.Format(item.name));//
                }
            }
            if (items.Count == 0)
            {
                GUILayout.Label(Localizer.Format("#MechJeb_WindowEd_CustomInfoWindow_Label1"));                  //Add items to this window with the custom window editor.
            }
            GUILayout.EndVertical();

            if (!IsOverlay && GUI.Button(new Rect(10, 0, 13, 20), "E", GuiUtils.yellowOnHover))
            {
                MechJebModuleCustomWindowEditor editor = core.GetComputerModule <MechJebModuleCustomWindowEditor>();
                if (editor != null)
                {
                    editor.enabled      = true;
                    editor.editedWindow = this;
                }
            }

            if (!IsOverlay && GUI.Button(new Rect(25, 0, 13, 20), "C", GuiUtils.yellowOnHover))
            {
                MuUtils.SystemClipboard = ToSharingString();
                ScreenMessages.PostScreenMessage(Localizer.Format("#MechJeb_WindowEd_CustomInfoWindow_Scrmsg1", GetName()), 3.0f, ScreenMessageStyle.UPPER_RIGHT);//Configuration of <<1>> window copied to clipboard.
            }

            base.WindowGUI(windowID);
        }
        public void FromSharingString(string[] lines, List <InfoItem> registry)
        {
            if (lines.Length > 1 && lines[1].StartsWith("Name: "))
            {
                title = lines[1].Trim().Substring("Name: ".Length);
            }
            if (lines.Length > 2 && lines[2].StartsWith("Show in:"))
            {
                ShowInEditor = lines[2].Contains("editor");
                ShowInFlight = lines[2].Contains("flight");
            }

            for (int i = 3; i < lines.Length; i++)
            {
                string   id    = lines[i].Trim();
                InfoItem match = registry.FirstOrDefault(item => item.id == id);
                if (match != null)
                {
                    items.Add(match);
                }
            }
        }
示例#5
0
        protected override void WindowGUI(int windowID)
        {
            GUILayout.BeginVertical();
            for (int i = 0; i < items.Count; i++)
            {
                InfoItem item = items[i];
                if (HighLogic.LoadedSceneIsEditor ? item.showInEditor : item.showInFlight)
                {
                    item.DrawItem();
                }
                else
                {
                    GUILayout.Label(item.name);
                }
            }
            if (items.Count == 0)
            {
                GUILayout.Label("Add items to this window with the custom window editor.");
            }
            GUILayout.EndVertical();

            if (GUI.Button(new Rect(10, 0, 13, 20), "E", GuiUtils.yellowOnHover))
            {
                MechJebModuleCustomWindowEditor editor = core.GetComputerModule <MechJebModuleCustomWindowEditor>();
                if (editor != null)
                {
                    editor.enabled      = true;
                    editor.editedWindow = this;
                }
            }

            if (GUI.Button(new Rect(25, 0, 13, 20), "C", GuiUtils.yellowOnHover))
            {
                MuUtils.SystemClipboard = ToSharingString();
                ScreenMessages.PostScreenMessage("Configuration of \"" + GetName() + "\" window copied to clipboard.", 3.0f, ScreenMessageStyle.UPPER_RIGHT);
            }

            base.WindowGUI(windowID);
        }
        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 ToggleInfoItemAttribute(string name, InfoItem.Category category)
     : base(name, category)
 {
 }
 public ActionInfoItemAttribute(string name, InfoItem.Category category)
     : base(name, category)
 {
 }
 public InfoItemAttribute(string name, InfoItem.Category category)
 {
     this.name = name;
     this.category = category;
     description = name; //description defaults to name, but can be set to be something different
 }
 public GeneralInfoItemAttribute(string name, InfoItem.Category category)
     : base(name, category)
 {
 }
示例#11
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);
        }