public GeneralInfoItemAttribute(string name, InfoItem.Category category) : base(name, category)
 {
 }
 public ActionInfoItemAttribute(string name, InfoItem.Category category) : base(name, category)
 {
 }
 public ToggleInfoItemAttribute(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
 }
        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);
        }
        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 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
 }
Ejemplo n.º 8
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);
        }