public static DialogGUIBox GUIBox(Action optionBuilder, Modifier <DialogGUIBox> modifier = null) { DialogGUIBox element = new DialogGUIBox("", -1, -1, null, Declare(optionBuilder)); if (modifier != null) { element = modifier(element); } _elements.Add(element); return(element); }
public static DialogGUIBox GUIBox(String message, Single w, Single h, Func <Boolean> EnabledCondition, Action optionBuilder, Modifier <DialogGUIBox> modifier = null) { DialogGUIBox element = new DialogGUIBox(message, w, h, EnabledCondition, Declare(optionBuilder)); if (modifier != null) { element = modifier(element); } _elements.Add(element); return(element); }
public DialogGuiVesselWidget(VesselPhysicsHold instance) { this.instance = instance; vesselTitle = new DialogGUILabel(() => GetVesselName(instance), 270f); DialogGUIVerticalLayout vesselInfo = new DialogGUIVerticalLayout( vesselTitle, new DialogGUILabel(() => GetVesselState(instance))); vesselInfo.padding = new RectOffset(5, 0, 0, 0); switchToButton = new DialogGUIButton(string.Empty, () => FlightGlobals.SetActiveVessel(instance.Vessel), 28f, 28f, false); switchToButton.OptionInteractableCondition += () => instance.Vessel.loaded && !instance.Vessel.isActiveVessel; DialogGUIHorizontalLayout boxTopSection = new DialogGUIHorizontalLayout(switchToButton, vesselInfo); boxTopSection.anchor = TextAnchor.MiddleLeft; holdToggle = new DialogGUIToggle(() => instance.physicsHold, "Physics hold", instance.OnToggleHold, 80f, 32f); holdToggle.OptionInteractableCondition += instance.CanTogglePhysicsHold; roboticsToggle = new DialogGUIToggle(() => instance.roboticsOverride, "Exclude robotics", instance.OnToggleRobotics, 80f, 32f); roboticsToggle.OptionInteractableCondition += instance.CanToggleRobotics; deformationButton = new DialogGUIButton("", () => instance.OnApplyDeformation(), false); deformationButton.OptionInteractableCondition += instance.CanApplyDeformation; deformationButton.size = new Vector2(32f, 32f); deformationButton.AddChild(new DialogGUIImage(new Vector2(32f, 32f), new Vector2(0f, 0f), Color.white, Lib.DeformTexture)); deformationButtonLabel = new DialogGUILabel("Apply deformation", 80f, 32f); deformationButtonLabel.OptionInteractableCondition += instance.CanApplyDeformation; DialogGUIHorizontalLayout buttonsSection = new DialogGUIHorizontalLayout(holdToggle, roboticsToggle, deformationButton, deformationButtonLabel); DialogGUIVerticalLayout boxContent = new DialogGUIVerticalLayout(boxTopSection, buttonsSection); boxContent.padding = new RectOffset(5, 5, 5, 0); widgetBox = new DialogGUIBox("", 280f, 80f, null, boxContent); }
/// <summary> /// This function gets called when the user clicks the "New Game" button in the main menu /// </summary> void OnNewGameBtnTap() { // Grab internal values FieldInfo createGameDialog = typeof(MainMenu).GetFields(BindingFlags.NonPublic | BindingFlags.Instance) .FirstOrDefault(f => f.FieldType == typeof(PopupDialog)); if (createGameDialog == null) { return; } FieldInfo newGameMode = typeof(MainMenu).GetFields(BindingFlags.NonPublic | BindingFlags.Static) .FirstOrDefault(f => f.FieldType == typeof(Game.Modes)); if (newGameMode == null) { return; } FieldInfo newGameParameters = typeof(MainMenu).GetFields(BindingFlags.NonPublic | BindingFlags.Static) .FirstOrDefault(f => f.FieldType == typeof(GameParameters)); if (newGameParameters == null) { return; } MethodInfo UpdatedGameParameters = typeof(MainMenu).GetMethod("UpdatedGameParameters", BindingFlags.NonPublic | BindingFlags.Instance); if (UpdatedGameParameters == null) { return; } // Descent into the popup dialog PopupDialog dialog = createGameDialog.GetValue(menu) as PopupDialog; if (dialog == null) { return; } if (dialog.dialogToDisplay == null) { return; } DialogGUIHorizontalLayout d1 = dialog.dialogToDisplay.Options[0] as DialogGUIHorizontalLayout; if (d1 == null) { return; } DialogGUIVerticalLayout d2 = d1.children[0] as DialogGUIVerticalLayout; if (d2 == null) { return; } DialogGUIHorizontalLayout d3 = d2.children[1] as DialogGUIHorizontalLayout; if (d3 == null) { return; } DialogGUIVerticalLayout d4 = d3.children[2] as DialogGUIVerticalLayout; if (d4 == null) { return; } DialogGUIToggleGroup d5 = d4.children[0] as DialogGUIToggleGroup; if (d5 == null) { return; } // Create the new layout DialogGUIToggle scienceboxButton = new DialogGUIToggle( (Game.Modes)newGameMode.GetValue(null) == Game.Modes.SCIENCE_SANDBOX && Sciencebox, Localizer.Format("#LOC_SCIENCEBOX_NAME"), b => { if ((Game.Modes)newGameMode.GetValue(null) != Game.Modes.SCIENCE_SANDBOX) { newGameMode.SetValue(null, Game.Modes.SCIENCE_SANDBOX); newGameParameters.SetValue(null, UpdatedGameParameters.Invoke(menu, new[] { newGameParameters.GetValue(null) })); } Sciencebox = true; }, 200f, 30f); DialogGUIToggle scienceButton = new DialogGUIToggle((Game.Modes)newGameMode.GetValue(null) == Game.Modes.SCIENCE_SANDBOX && !Sciencebox, Localizer.Format("#autoLOC_190714"), b => { if ((Game.Modes)newGameMode.GetValue(null) != Game.Modes.SCIENCE_SANDBOX) { newGameMode.SetValue(null, Game.Modes.SCIENCE_SANDBOX); newGameParameters.SetValue(null, UpdatedGameParameters.Invoke(menu, new[] { newGameParameters.GetValue(null) })); } Sciencebox = false; }, 200f, 30f); d5.children.Insert(2, scienceboxButton); d5.children[1] = scienceButton; d4.children[0] = d5; d3.children[2] = d4; d2.children[1] = d3; d1.children[0] = d2; dialog.dialogToDisplay.Options[0] = d1; DialogGUIBox scienceboxBox = new DialogGUIBox(string.Empty, -1f, 100f, () => (Game.Modes)newGameMode.GetValue(null) == Game.Modes.SCIENCE_SANDBOX && Sciencebox, new DialogGUIBase[] { new DialogGUIHorizontalLayout(false, false, 2f, new RectOffset(8, 8, 8, 8), TextAnchor.MiddleLeft, new DialogGUIBase[] { new DialogGUIImage(new Vector2(96f, 96f), Vector2.zero, Color.white, menu.scienceSandboxIcon), new DialogGUILabel( Localizer.Format("#LOC_SCIENCEBOX_TEXT1") + "\n\n" + Localizer.Format("#LOC_SCIENCEBOX_TEXT2"), menu.guiSkinDef.SkinDef.customStyles[6], true, true) }) }); DialogGUIBox scienceBox = new DialogGUIBox(string.Empty, -1f, 100f, () => (Game.Modes)newGameMode.GetValue(null) == Game.Modes.SCIENCE_SANDBOX && !Sciencebox, new DialogGUIBase[] { new DialogGUIHorizontalLayout(false, false, 2f, new RectOffset(8, 8, 8, 8), TextAnchor.MiddleLeft, new DialogGUIBase[] { new DialogGUIImage(new Vector2(96f, 96f), Vector2.zero, Color.white, menu.scienceSandboxIcon), new DialogGUILabel( Localizer.Format("#autoLOC_190750") + "\n\n" + Localizer.Format("#autoLOC_190751"), menu.guiSkinDef.SkinDef.customStyles[6], true, true) }) }); List <DialogGUIBase> elements = dialog.dialogToDisplay.Options.ToList(); elements[2] = scienceBox; elements.Insert(3, scienceboxBox); dialog.dialogToDisplay.Options = elements.ToArray(); PopupDialog newDialog = PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), dialog.dialogToDisplay, false, menu.guiSkinDef.SkinDef, true, ""); dialog.Dismiss(); createGameDialog.SetValue(menu, newDialog); }
public void Allocate() { //DialogGUILayoutBase layout = new DialogGUIVerticalLayout(true, true); uwind_label = new DialogGUILabel(() => { return(uwind_txt); }, 65); vwind_label = new DialogGUILabel(() => { return(vwind_txt); }, 65); wwind_label = new DialogGUILabel(() => { return(wwind_txt); }, 65); wspd_label = new DialogGUILabel(() => { return(wspd_txt); }, 65); wdir_label = new DialogGUILabel(() => { return(wdir_txt); }, 65); //Velocity velocity_ias_label = new DialogGUILabel(() => { return(velocity_ias_txt); }, 65); velocity_tas_label = new DialogGUILabel(() => { return(velocity_tas_txt); }, 65); velocity_ground_label = new DialogGUILabel(() => { return(velocity_ground_txt); }, 65); tailwind_label = new DialogGUILabel(() => { return(tailwind_txt); }, 65); crosswind_label = new DialogGUILabel(() => { return(crosswind_txt); }, 65); //Thermo pressure_label = new DialogGUILabel(() => { return(pressure_txt); }, 65); temperature_label = new DialogGUILabel(() => { return(temperature_txt); }, 65); humidity_label = new DialogGUILabel(() => { return(humidity_txt); }, 65); Debug.Log("[KerbalWxGUI]: Toggle Wx Enabled, " + wx_enabled.ToString()); // create pages info_page = new DialogGUIVerticalLayout(false, true, 0, new RectOffset(), TextAnchor.UpperCenter, new DialogGUIHorizontalLayout( new DialogGUIToggle(() => { return(wx_enabled); }, Localizer.Format("Toggle Weather"), OnButtonClick_ToggleWx)), //new DialogGUILabel("Wind Speed and Direction", Util.Style_Label_Normal_Center_White, true), new DialogGUILabel("<b><color=\"white\">" + Localizer.Format("Wind Speed and Direction") + "</color></b>", true), //Name new DialogGUIHorizontalLayout(TextAnchor.MiddleRight, new DialogGUILabel(Localizer.Format("Zonal Wind Speed (U)"), true), new DialogGUILabel(() => { return(uwind_txt); })), new DialogGUIHorizontalLayout(TextAnchor.MiddleRight, new DialogGUILabel(Localizer.Format("Meridional Wind Speed (V)"), true), new DialogGUILabel(() => { return(vwind_txt); })), new DialogGUIHorizontalLayout(TextAnchor.MiddleRight, new DialogGUILabel(Localizer.Format("Vertical Wind Speed (W): "), true), new DialogGUILabel(() => { return(wwind_txt); })), new DialogGUIHorizontalLayout(TextAnchor.MiddleRight, new DialogGUILabel(Localizer.Format("Horizontal Wind Speed"), true), new DialogGUILabel(() => { return(wspd_txt); })), new DialogGUIHorizontalLayout(TextAnchor.MiddleRight, new DialogGUILabel(Localizer.Format("Wind Direction"), true), new DialogGUILabel(() => { return(wdir_txt); })), //new DialogGUILabel("Vehicle Speed and Relative Wind", Util.Style_Label_Normal_Center_White, true), new DialogGUILabel("<b><color=\"white\">" + Localizer.Format("Vehicle Speed and Relative Wind") + "</color></b>", true), //Name new DialogGUIHorizontalLayout(TextAnchor.MiddleRight, new DialogGUILabel(Localizer.Format("Tailwind (+) | Headwind (-)"), true), new DialogGUILabel(() => { return(tailwind_txt); })), new DialogGUIHorizontalLayout(TextAnchor.MiddleRight, new DialogGUILabel(Localizer.Format("Crosswind"), true), new DialogGUILabel(() => { return(crosswind_txt); })), new DialogGUIHorizontalLayout(TextAnchor.MiddleRight, new DialogGUILabel(Localizer.Format("Indicated Airspeed"), true), new DialogGUILabel(() => { return(velocity_ias_txt); })), new DialogGUIHorizontalLayout(TextAnchor.MiddleRight, new DialogGUILabel(Localizer.Format("True Airspeed"), true), new DialogGUILabel(() => { return(velocity_tas_txt); })), new DialogGUIHorizontalLayout(TextAnchor.MiddleRight, new DialogGUILabel(Localizer.Format("Ground speed"), true), new DialogGUILabel(() => { return(velocity_ground_txt); })) ); thermo_page = new DialogGUIVerticalLayout(false, true, 0, new RectOffset(), TextAnchor.UpperCenter, new DialogGUIHorizontalLayout( new DialogGUIToggle(() => { return(wx_enabled); }, Localizer.Format("Toggle Weather"), OnButtonClick_ToggleWx)), new DialogGUIHorizontalLayout(TextAnchor.MiddleRight, new DialogGUILabel(Localizer.Format("Atmospheric Pressure"), true), new DialogGUILabel(() => { return(pressure_txt); })), new DialogGUIHorizontalLayout(TextAnchor.MiddleRight, new DialogGUILabel(Localizer.Format("Ambient Temperature"), true), new DialogGUILabel(() => { return(temperature_txt); })), new DialogGUIHorizontalLayout(TextAnchor.MiddleRight, new DialogGUILabel(Localizer.Format("Relative Humidity"), true), new DialogGUILabel(() => { return(humidity_txt); })) ); switch ((PageType)MainGUICurrentPage) { case PageType.THERMO: page_box = new DialogGUIBox(null, -1, -1, () => true, thermo_page); break; default: page_box = new DialogGUIBox(null, -1, -1, () => true, info_page); break; } //Debug.Log("[KerbalWxGUI] X: " + MainGUIWindowPos.x.ToString() + ", Y: " + MainGUIWindowPos.y.ToString()); // create base window for popup dialog multi_dialog = new MultiOptionDialog( "KWPMainGUI", "", Localizer.Format("Kerbal Weather Project") + " - 1.0", HighLogic.UISkin, // window origin is center of rect, position is offset from lower left corner of screen and normalized // i.e (0.5, 0.5 is screen center) new Rect(MainGUIWindowPos.x, MainGUIWindowPos.y, width, height), new DialogGUIBase[] { // create page select buttons new DialogGUIHorizontalLayout(true, false, 2, new RectOffset(), TextAnchor.MiddleCenter, new DialogGUIButton(Localizer.Format("Kinematics"), OnButtonClick_Info, ButtonEnabler_Info, button_width, button_height, false), new DialogGUIButton(Localizer.Format("Thermodynamics"), OnButtonClick_Thermo, ButtonEnabler_Thermo, button_width, button_height, false)), page_box } ); }
/// <summary> /// Generates and spawns the Upgrade Editor UI. /// </summary> public PopupDialog GenerateUpgradeEditorUI() { upgrade_editor.Clear(); upgrade_line.Clear(); upgrade_editor.Add(new DialogGUIHorizontalLayout(new DialogGUISpace(50), new DialogGUILabel("Upgrade"), new DialogGUISpace(150), new DialogGUILabel("Changes"), new DialogGUISpace(250), new DialogGUILabel("Description"))); upgrade_editor.Add(new DialogGUISpace(4)); // create one line with toggle upgrade button, all modules affected and description for every upgrade in the selected part for (int cns = 0; cns < allupgrades.Count; cns++) { var affected_modules = new List <string>(); foreach (PartModule yapm in part.Modules) { if (yapm.HasUpgrades()) { foreach (ConfigNode ymup in yapm.upgrades) { if (ymup.GetValue("name__") == allupgrades[cns].GetValue("name__")) { affected_modules.Add(yapm.GetModuleDisplayName() + " => " + ymup.GetValue("description__")); } } } } // Using PartUpgradeManager.Handler to access the Upgrade as located in the Tech Tree referred // in the PartModules and find out its in-game name and description. var nameforcurrentupgrade = allupgrades[cns].GetValue("name__"); var currentupgrade = PartUpgradeManager.Handler.GetUpgrade(nameforcurrentupgrade); if (affected_modules[0] == " => ") { affected_modules[0] = "See general description for details"; } var single_upgrade_button = new DialogGUIToggleButton(() => !ListOfTemporarilyDisabledUpgrades.Contains(currentupgrade.name), currentupgrade.title, OnButtonClick_Upgrade(currentupgrade), button_width, button_height); //PartUpgradeManager.Handler.IsEnabled(currentupgrade.name) var single_modules_button = new DialogGUIBox(string.Join("\n", affected_modules.ToArray()), 250, button_height); var single_desc_button = new DialogGUIBox(currentupgrade.description, 340, button_height); var h = new DialogGUIHorizontalLayout(true, false, 4, new RectOffset(), TextAnchor.MiddleCenter, new DialogGUIBase[] { single_upgrade_button, single_modules_button, single_desc_button }); upgrade_line.Add(h); } scrollList = null; scrollList = new DialogGUIBase[upgrade_line.Count + 1]; scrollList[0] = new DialogGUIContentSizer(ContentSizeFitter.FitMode.Unconstrained, ContentSizeFitter.FitMode.PreferredSize, true); for (int i = 0; i < upgrade_line.Count; i++) { scrollList[i + 1] = upgrade_line[i]; } upgrade_editor.Add(new DialogGUIScrollList(new Vector2(270, 200), false, true, new DialogGUIVerticalLayout(10, 100, 4, new RectOffset(6, 24, 10, 10), TextAnchor.UpperLeft, scrollList) )); upgrade_editor.Add(new DialogGUISpace(4)); upgrade_editor.Add(new DialogGUIHorizontalLayout(new DialogGUIBase[] { new DialogGUIFlexibleSpace(), new DialogGUIButton("Reset & Close", ResetUnlockedUpgrades), new DialogGUIFlexibleSpace(), new DialogGUIToggleButton(() => EnableAllUpgrades, "Toggle All", OnButtonClick_EnableAllUpgrades, -1, 30), new DialogGUIFlexibleSpace(), new DialogGUIToggleButton(() => PartUpgradeHandler.AllEnabled, "Always Enable", OnButtonClick_ToggleAllUpgrades, -1, 30), new DialogGUIFlexibleSpace(), new DialogGUIButton("Close", Dismiss) })); return(PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new MultiOptionDialog( "Upgrade Editor", "", "Upgrade Editor", HighLogic.UISkin, // window origin is center of rect, position is offset from lower left corner of screen and normalized i.e (0.5, 0.5 is screen center) new Rect(0.5f, 0.5f, width, height), upgrade_editor.ToArray()), false, HighLogic.UISkin)); }