public override List <DialogGUIBase> getContentComponents() { List <DialogGUIBase> layout = new List <DialogGUIBase>(); DialogGUILabel msgLbl = new DialogGUILabel(Localizer.Format("#CNC_getContentCompon_msgLabel4"), 100, 32);//"Set up the master frequency in one go. All antennas will be assigned to this frequency, and Comm powers of those deployed antennas will be combined." layout.Add(new DialogGUIHorizontalLayout(true, false, 0, new RectOffset(), TextAnchor.MiddleLeft, new DialogGUIBase[] { msgLbl })); DialogGUILabel freqLabel = new DialogGUILabel("<b>" + Localizer.Format("#CNC_Generic_FrequencyLabel") + "</b>", 52, 12);//Frequency frequencyInput = new DialogGUITextInput(CNCSettings.Instance.PublicRadioFrequency + "", false, CNCSettings.MaxDigits, setConstellFreq, 45, 25); DialogGUIToggle membershipToggle = new DialogGUIToggle(false, "", membershipFlagToggle); DialogGUILabel membershipLabel = new DialogGUILabel("<b>" + Localizer.Format("#CNC_getContentCompon_membershipLabel") + "</b>", 200, 12);//Talk to constellation members only DialogGUIHorizontalLayout constellationGroup = new DialogGUIHorizontalLayout(true, false, 4, new RectOffset(), TextAnchor.MiddleCenter, new DialogGUIBase[] { freqLabel, frequencyInput, new DialogGUISpace(20), membershipToggle, membershipLabel }); layout.Add(constellationGroup); constellationColorImage = new DialogGUIImage(new Vector2(32, 32), Vector2.one, Color.white, colorTexture); DialogGUILabel constNameLabel = new DialogGUILabel(getConstellationName, 200, 12); layout.Add(new DialogGUIHorizontalLayout(false, false, 0, new RectOffset(), TextAnchor.MiddleLeft, new DialogGUIBase[] { constNameLabel, constellationColorImage })); DialogGUIButton updateButton = new DialogGUIButton(Localizer.Format("#CNC_Generic_UpdateButton"), updateClick, false); //"Update" DialogGUIButton publicButton = new DialogGUIButton(Localizer.Format("#CNC_Generic_PublicButton"), defaultClick, false); //"Revert to public" DialogGUIHorizontalLayout actionGroup = new DialogGUIHorizontalLayout(true, false, 4, new RectOffset(), TextAnchor.MiddleCenter, new DialogGUIBase[] { new DialogGUIFlexibleSpace(), updateButton, publicButton, new DialogGUIFlexibleSpace() }); layout.Add(actionGroup); return(layout); }
public static DialogGUIToggle GUIToggle(Boolean set, String lbel, Callback <Boolean> selected, Single w = -1f, Single h = -1f, Modifier <DialogGUIToggle> modifier = null) { DialogGUIToggle element = new DialogGUIToggle(set, lbel, selected, w, h); if (modifier != null) { element = modifier(element); } _elements.Add(element); return(element); }
public static DialogGUIToggle GUIToggle(Func <Boolean> set, Func <Sprite> checkSet, Callback <Boolean> selected, Sprite overImage, Single w = -1f, Single h = -1f, Modifier <DialogGUIToggle> modifier = null) { DialogGUIToggle element = new DialogGUIToggle(set, checkSet, selected, overImage, w, h); if (modifier != null) { element = modifier(element); } _elements.Add(element); return(element); }
public void Show(Part part) { Hide(); DialogGUIToggle toggleSurfaceAttach = new DialogGUIToggle(delegate { return(GetSurfaceAttach(part)); }, "Allow surface attachment to other parts", delegate { ToggleSurfaceAttach(part); }, -1, LINE_HEIGHT); DialogGUIToggle toggleAllowSurfaceAttach = new DialogGUIToggle(delegate { return(GetAllowSurfaceAttach(part)); }, "Allow other parts to be surface attached to this part", delegate { ToggleAllowSurfaceAttach(part); }, -1, LINE_HEIGHT); string title = FormatLabel("Precise Editor - ") + "Attachment Rules"; List <DialogGUIBase> dialogGUIBaseList = new List <DialogGUIBase> { toggleSurfaceAttach, toggleAllowSurfaceAttach }; dialog = new MultiOptionDialog("attachmentWindowDialog", "", title, HighLogic.UISkin, dialogRect, new DialogGUIVerticalLayout(dialogGUIBaseList.ToArray())); popupDialog = PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), dialog, false, HighLogic.UISkin, false); popupDialog.onDestroy.AddListener(SaveWindowPosition); }
private PopupDialog GenerateDialog() { List <DialogGUIBase> guiItems = new List <DialogGUIBase>(); if (EditorLogic.fetch == null || EditorLogic.fetch.ship == null) { guiItems.Add(new DialogGUILabel("No Vessel Detected")); } else { guiItems.Add(new DialogGUILabel(_utilities.SystemNotes, _utilities.CreateNoteStyle())); guiItems.Add(new DialogGUILabel(_utilities.Warnings, _utilities.CreateNoteStyle())); DialogGUIBase[] vertical = new DialogGUIBase[_utilities.Planets.Count]; DialogGUIBase[] horizontal = new DialogGUIBase[2]; horizontal[0] = new DialogGUIToggle(() => _returnTrip, "Return Trip?", delegate { SetReturnTrip(); }); horizontal[1] = new DialogGUIToggle(() => payloadOnly, "Payload Only", delegate { SetPayoadOnly(); }); guiItems.Add(new DialogGUIHorizontalLayout(horizontal)); for (int i = 0; i < _utilities.Planets.Count; i++) { PlanetDeltaV p = _utilities.Planets.ElementAt(i); horizontal = new DialogGUIBase[4]; horizontal[0] = new DialogGUILabel(p.GetName(), _utilities.GenerateStyle(-1, false)); horizontal[1] = GetDeltaVString(p, "Flyby: "); horizontal[2] = GetDeltaVString(p, "Orbiting: "); if (p.IsHomeWorld && p.SynchronousDv != -1) { horizontal[3] = GetDeltaVString(p, "Synchronous Orbit: "); } else { horizontal[3] = GetDeltaVString(p, "Landing: "); } vertical[i] = new DialogGUIHorizontalLayout(horizontal); } DialogGUIVerticalLayout layout = new DialogGUIVerticalLayout(vertical); guiItems.Add(new DialogGUIScrollList(-Vector2.one, false, true, layout)); } guiItems.Add(new DialogGUILabel("*Assuming craft has enough chutes")); guiItems.Add(new DialogGUIButton("Close", () => _utilities.CloseDialog(_uiDialog), false)); return(PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new MultiOptionDialog("WhereCanIGoDialog", "", "Where Can I Go", UISkinManager.defaultSkin, _geometry, guiItems.ToArray()), false, UISkinManager.defaultSkin)); }
/// <summary> /// Compares the return of a dialog button with the cache /// </summary> public static Boolean CompareDialog(DialogGUIBase text, String cache) { // Replace text if (text is DialogGUIButton) { DialogGUIButton gui = ((DialogGUIButton)text); return(gui.GetString?.Invoke() == cache); } if (text is DialogGUIToggle) { DialogGUIToggle gui = ((DialogGUIToggle)text); return(gui.setLabel?.Invoke() == cache); } if (text is DialogGUILabel) { DialogGUILabel gui = ((DialogGUILabel)text); return(gui.GetString?.Invoke() == cache); } return(false); }
public override List <DialogGUIBase> getContentComponents() { List <DialogGUIBase> layout = new List <DialogGUIBase>(); DialogGUILabel msgLbl = new DialogGUILabel("Decide how the vessel's frequency list should be updated whenever one antenna is changed (eg extended/retracted or frequency change).", 100, 32); layout.Add(new DialogGUIHorizontalLayout(true, false, 0, new RectOffset(), TextAnchor.MiddleLeft, new DialogGUIBase[] { msgLbl })); DialogGUIToggleGroup toggleGrp = new DialogGUIToggleGroup(); DialogGUIVerticalLayout nameColumn = new DialogGUIVerticalLayout(false, false, 0, new RectOffset(), TextAnchor.MiddleLeft); DialogGUIVerticalLayout descriptionColumn = new DialogGUIVerticalLayout(false, false, 0, new RectOffset(), TextAnchor.MiddleLeft); DialogGUIToggle toggleBtn1 = new DialogGUIToggle((cncVessel.FreqListOperation == FrequencyListOperation.AutoBuild) ? true : false, "", delegate(bool b) { ListOperationSelected(b, FrequencyListOperation.AutoBuild); }, 20, 32); DialogGUILabel nameLabel1 = new DialogGUILabel("Auto Build", style); nameLabel1.size = new Vector2(80, 32); DialogGUILabel descriptionLabel1 = new DialogGUILabel("Rebuild the list from all antennas automatically", style); descriptionLabel1.size = new Vector2(350, 32); toggleGrp.AddChild(toggleBtn1); nameColumn.AddChild(nameLabel1); descriptionColumn.AddChild(descriptionLabel1); DialogGUIToggle toggleBtn2 = new DialogGUIToggle((cncVessel.FreqListOperation == FrequencyListOperation.LockList) ? true : false, "", delegate(bool b) { ListOperationSelected(b, FrequencyListOperation.LockList); }, 20, 32); DialogGUILabel nameLabel2 = new DialogGUILabel("Lock List", style); nameLabel2.size = new Vector2(80, 32); DialogGUILabel descriptionLabel2 = new DialogGUILabel("Disallow any change in the current list (except for staging)", style); descriptionLabel2.size = new Vector2(350, 32); toggleGrp.AddChild(toggleBtn2); nameColumn.AddChild(nameLabel2); descriptionColumn.AddChild(descriptionLabel2); /* * DialogGUIToggle toggleBtn3 = new DialogGUIToggle((cncVessel.FreqListOperation == FrequencyListOperation.UpdateOnly) ? true : false, "", delegate (bool b) { ListOperationSelected(b, FrequencyListOperation.UpdateOnly); }, 20, 32); * DialogGUILabel nameLabel3 = new DialogGUILabel("Freq Only", style); nameLabel3.size = new Vector2(80, 32); * DialogGUILabel descriptionLabel3 = new DialogGUILabel("Update the affected frequency in the list only (not yet)", style); descriptionLabel3.size = new Vector2(350, 32); * toggleGrp.AddChild(toggleBtn3); * nameColumn.AddChild(nameLabel3); * descriptionColumn.AddChild(descriptionLabel3); */ layout.Add(new DialogGUIHorizontalLayout(true, false, 0, new RectOffset(), TextAnchor.MiddleLeft, new DialogGUIBase[] { new DialogGUIVerticalLayout(false, false, 0, new RectOffset(), TextAnchor.MiddleLeft, toggleGrp), nameColumn, descriptionColumn })); return(layout); }
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); }
public override List <DialogGUIBase> getContentComponents() { List <DialogGUIBase> layout = new List <DialogGUIBase>(); DialogGUILabel msgLbl = new DialogGUILabel("Select one or more antennas to manually build the frequency list instead of the default list. Only deployed antennas can be chosen.", 100, 32); layout.Add(new DialogGUIHorizontalLayout(true, false, 0, new RectOffset(), TextAnchor.MiddleLeft, new DialogGUIBase[] { msgLbl })); toggleAntennaColumn = new DialogGUIVerticalLayout(false, false, 0, new RectOffset(), TextAnchor.MiddleLeft); DialogGUIVerticalLayout nameColumn = new DialogGUIVerticalLayout(false, false, 0, new RectOffset(), TextAnchor.MiddleLeft); DialogGUIVerticalLayout comPowerColumn = new DialogGUIVerticalLayout(false, false, 0, new RectOffset(), TextAnchor.MiddleLeft); DialogGUIVerticalLayout frequencyColumn = new DialogGUIVerticalLayout(false, false, 0, new RectOffset(), TextAnchor.MiddleLeft); DialogGUIVerticalLayout combinableColumn = new DialogGUIVerticalLayout(false, false, 0, new RectOffset(), TextAnchor.MiddleLeft); for (int i = 0; i < antennas.Count; i++) { CNCAntennaPartInfo antennaInfo = antennas[i]; DialogGUIToggle toggleBtn = new DialogGUIToggle(antennaInfo.inUse && antennaInfo.canComm, "", delegate(bool b) { vesselAntennaSelected(b, antennaInfo); actionCallbacks[0](); }, 20, 32); DialogGUILabel nameLabel = new DialogGUILabel(antennaInfo.name, style); nameLabel.size = new Vector2(150, 32); DialogGUILabel comPowerLabel = new DialogGUILabel(string.Format("Com power: {0}", UIUtils.RoundToNearestMetricFactor(antennaInfo.antennaPower * (double)HighLogic.CurrentGame.Parameters.CustomParams <CommNetParams>().rangeModifier, 2)), style); comPowerLabel.size = new Vector2(130, 32); DialogGUILabel frequencyLabel = new DialogGUILabel(string.Format("(<color={0}>{1}</color>)", UIUtils.colorToHex(Constellation.getColor(antennaInfo.frequency)), antennaInfo.frequency), style); frequencyLabel.size = new Vector2(60, 32); DialogGUILabel combinableLabel = new DialogGUILabel("Combinable: " + (antennaInfo.antennaCombinable ? "<color=green>Yes</color>" : "<color=red>No</color>") + "\nBroadcast: " + (antennaInfo.canComm ? "<color=green>Yes</color>" : "<color=red>No</color>"), style); combinableLabel.size = new Vector2(90, 32); toggleAntennaColumn.AddChild(toggleBtn); nameColumn.AddChild(nameLabel); frequencyColumn.AddChild(frequencyLabel); comPowerColumn.AddChild(comPowerLabel); combinableColumn.AddChild(combinableLabel); } layout.Add(new DialogGUIHorizontalLayout(true, false, 0, new RectOffset(), TextAnchor.MiddleLeft, new DialogGUIBase[] { toggleAntennaColumn, nameColumn, frequencyColumn, comPowerColumn, combinableColumn })); DialogGUIButton deselectButton = new DialogGUIButton("Deselect all", delegate { toggleAllAntennas(false); actionCallbacks[0](); }, false); DialogGUIButton selectButton = new DialogGUIButton("Select all", delegate { toggleAllAntennas(true); actionCallbacks[0](); }, false); layout.Add(new DialogGUIHorizontalLayout(true, false, 0, new RectOffset(), TextAnchor.MiddleLeft, new DialogGUIBase[] { selectButton, deselectButton })); return(layout); }
private PopupDialog RandomKerbalDialog() { List <DialogGUIBase> dialogElements = new List <DialogGUIBase>(); int numberOfRandomKerbals = 4; dialogElements.Add(new DialogGUIToggle(() => randomKerbals, "Generate Random Kerbals", b => { SwitchMode(); })); DialogGUIBase[] verticalArray = new DialogGUIBase[3]; verticalArray[0] = new DialogGUILabel(() => "Number of Kerbals: " + numberOfRandomKerbals); verticalArray[1] = new DialogGUISpace(30.0f); verticalArray[2] = new DialogGUISlider(() => numberOfRandomKerbals, 1, 10, true, 90.0f, 30.0f, newValue => { numberOfRandomKerbals = (int)newValue; }); dialogElements.Add(new DialogGUIHorizontalLayout(verticalArray)); verticalArray = new DialogGUIBase[2]; DialogGUIBase[] splitBox = new DialogGUIBase[2]; verticalArray[0] = new DialogGUIToggle(allowFemales, "Allow Female Kerbals", b => allowFemales = b); verticalArray[1] = new DialogGUIToggle(allowMales, "Allow Male Kerbals", b => allowMales = b); splitBox[0] = new DialogGUIVerticalLayout(verticalArray); splitBox[1] = new DialogGUIVerticalLayout(TraitDialogOptions()); dialogElements.Add(new DialogGUIHorizontalLayout(splitBox)); dialogElements.Add(new DialogGUISpace(5.0f)); dialogElements.Add(new DialogGUIButton("I'm Done", () => GenerateRandomKerbals(numberOfRandomKerbals), true)); return(PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new MultiOptionDialog("FirstKerbaliserRandomKerbals", "", "Earn Your Stripes", UISkinManager.defaultSkin, new Rect(0.5f, 0.5f, 280.0f, 210), dialogElements.ToArray()), false, UISkinManager.defaultSkin)); }
/// <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); }
/// <summary> /// Updates the Popup Dialoges /// </summary> public void PopupDialogUpdate() { if (HighLogic.LoadedScene == GameScenes.LOADING) { return; } // Patch all PopupDialogs foreach (PopupDialog dialog in Resources.FindObjectsOfTypeAll <PopupDialog>()) { // Dialog is null if (dialog?.dialogToDisplay == null) { continue; } // Translate the texts dialog.dialogToDisplay.title = translations[dialog.dialogToDisplay.title]; dialog.dialogToDisplay.message = translations[dialog.dialogToDisplay.message]; // Patch the Dialog Options foreach (DialogGUIBase guiBase in dialog.dialogToDisplay.Options) { Utility.DoRecursive(guiBase, childBase => childBase.children, text => { if (patched.Contains <DialogGUIBase, String>(text) && (!patched.Contains <DialogGUIBase, String>(text) || patched.Get <DialogGUIBase, String>(text) == text.OptionText || Utility.CompareDialog(text, patched.Get <DialogGUIBase, String>(text)))) { return; } // Log if (debug) { Logger.Active.Log("[PUD]" + text.OptionText); } // Replace text if (text is DialogGUIButton) { DialogGUIButton gui = ((DialogGUIButton)text); if (gui.GetString != null) { Func <String> value = (Func <String>)Delegate.CreateDelegate(typeof(Func <String>), gui.GetString.Target, gui.GetString.Method); gui.GetString = () => translations[value()]; } else { gui.OptionText = translations[gui.OptionText]; } } else if (text is DialogGUIToggle) { DialogGUIToggle gui = ((DialogGUIToggle)text); if (gui.setLabel != null) { Func <String> value = (Func <String>)Delegate.CreateDelegate(typeof(Func <String>), gui.setLabel.Target, gui.setLabel.Method); gui.setLabel = () => translations[value()]; } else { gui.label = gui.OptionText = translations[gui.OptionText]; } } else if (text is DialogGUILabel) { DialogGUILabel gui = ((DialogGUILabel)text); if (gui.GetString != null) { Func <String> value = (Func <String>)Delegate.CreateDelegate(typeof(Func <String>), gui.GetString.Target, gui.GetString.Method); gui.GetString = () => translations[value()]; } else { gui.OptionText = translations[gui.OptionText]; } } else if (!String.IsNullOrEmpty(text.OptionText)) { text.OptionText = translations[text.OptionText]; } if (patched.Contains <DialogGUIBase, String>(text)) { patched.Set(text, text.OptionText); } else { patched.Add(text, text.OptionText); } }); } } }
private void ButtonOnTrue() { // Store labels in separate data structure for easy access when updating labelMap.Clear(); List <LifeSupportReportable> modules = FlightGlobals.ActiveVessel.FindPartModulesImplementing <LifeSupportReportable>(); // Calculate once on window generation, instead of each frame bool buttonEnable = !FlightGlobals.ActiveVessel.isEVA && FlightGlobals.ActiveVessel.HasModule <Cons2LSModule>(); // Cell padding RectOffset offset = new RectOffset(20, 0, 10, 0); DialogGUIVerticalLayout vert = new DialogGUIVerticalLayout( false, false, 1f, new RectOffset(), TextAnchor.UpperLeft); DialogGUIBase[] vertHeader; if (compress) { vertHeader = new DialogGUIBase[2] { new DialogGUILabel("<b>Kerbal</b>", true, true), new DialogGUILabel("<b>Life Support</b>", true, true) }; } else { vertHeader = new DialogGUIBase[4] { new DialogGUILabel("<b>Kerbal</b>", true, true), new DialogGUILabel("<b>Ship Life Support</b>", true, true), new DialogGUILabel("<b>Suit Life Support</b>", true, true), new DialogGUILabel("", true, true) }; } vert.AddChild( new DialogGUIGridLayout(new RectOffset(), new Vector2(cellWidth, 20), Vector2.zero, UnityEngine.UI.GridLayoutGroup.Corner.UpperLeft, UnityEngine.UI.GridLayoutGroup.Axis.Horizontal, TextAnchor.MiddleLeft, UnityEngine.UI.GridLayoutGroup.Constraint.FixedColumnCount, compress ? 2 : 4, vertHeader )); emptyPartLabels.Clear(); DialogGUILabel emptyLabel = new DialogGUILabel("", true, true); foreach (LifeSupportReportable module in modules) { if (module.part.protoModuleCrew.Count == 0) { emptyPartLabels.Add(module.part, new DialogGUILabel("EE", true, true)); continue; } List <ProtoCrewMember> crew = new List <ProtoCrewMember>(module.part.protoModuleCrew); List <DialogGUIBase> kerbalCells = new List <DialogGUIBase>(); crew.Sort(CompareCrewNames); vert.AddChild(new DialogGUILabel($"{ORANGE}<b>{module.part.partInfo.title}</b></color>")); foreach (ProtoCrewMember kerbal in crew) { GUIElements elems = new GUIElements(kerbal, buttonEnable); labelMap.Add(kerbal.name, elems); kerbalCells.Add(elems.nameLabel); kerbalCells.Add(elems.shipLS); if (!compress) { elems.nameLabel.SetOptionText(kerbal.name); kerbalCells.Add(elems.evaLS); kerbalCells.Add(elems.fillEVAButton); } // Add raw EVA tracking values if (Config.DEBUG_SHOW_EVA) { kerbalCells.Add(emptyLabel); kerbalCells.Add(elems.evaLS_Value); kerbalCells.Add(elems.evaProp); kerbalCells.Add(emptyLabel); } } vert.AddChild( new DialogGUIGridLayout(new RectOffset(), new Vector2(cellWidth, 20), Vector2.zero, UnityEngine.UI.GridLayoutGroup.Corner.UpperLeft, UnityEngine.UI.GridLayoutGroup.Axis.Horizontal, TextAnchor.MiddleLeft, UnityEngine.UI.GridLayoutGroup.Constraint.FixedColumnCount, compress ? 2 : 4, kerbalCells.ToArray())); } if (emptyPartLabels.Count > 0 && !compress) { vert.AddChild(new DialogGUISpace(20)); foreach (Part part in emptyPartLabels.Keys) { vert.AddChild( new DialogGUIGridLayout(new RectOffset(), new Vector2(cellWidth * 2, 20), Vector2.zero, UnityEngine.UI.GridLayoutGroup.Corner.UpperLeft, UnityEngine.UI.GridLayoutGroup.Axis.Horizontal, TextAnchor.MiddleLeft, UnityEngine.UI.GridLayoutGroup.Constraint.FixedColumnCount, 2, new DialogGUILabel($"{ORANGE}{part.partInfo.title}</color>"), emptyPartLabels[part] )); } } // How can the SizeUp() -> RefreshGUI() -> OnButtonTrue() dependency // be altered to make these fields static, so that they don't have // to be re-initialized each time? sizeUpButton = new DialogGUIButton("+", SizeUp, CanSizeUp, buttonHeight, buttonHeight, false); sizeDownButton = new DialogGUIButton("-", SizeDown, CanSizeDown, buttonHeight, buttonHeight, false); DialogGUIToggleButton compressButton = new DialogGUIToggleButton( compress, "Minimize", ToggleCompressGUI, w: 70, h: buttonHeight); DialogGUIHorizontalLayout compressLayout = new DialogGUIHorizontalLayout( false, true, 0f, noOffset, TextAnchor.MiddleLeft, compressButton, sizeDownButton, sizeUpButton); riskToggle = new DialogGUIToggle( EVALifeSupportTracker.AllowUnsafeActivity, "Allow unsafe crew transfer", RiskButtonSelected); riskLayout = new DialogGUIHorizontalLayout( 0f, 0f, 0f, noOffset, TextAnchor.MiddleLeft, riskToggle); // Define the header which contains additional info // (status, Consumables) DialogGUIGridLayout statusGrid = new DialogGUIGridLayout(noOffset, new Vector2(cellWidth * (compress ? 1 : 2), 25), Vector2.zero, UnityEngine.UI.GridLayoutGroup.Corner.UpperLeft, UnityEngine.UI.GridLayoutGroup.Axis.Horizontal, TextAnchor.MiddleLeft, UnityEngine.UI.GridLayoutGroup.Constraint.FixedColumnCount, 2, statusLabel, compressLayout); // Contains the statusGrid and the "unsafe" toggle DialogGUIGridLayout masterGrid = new DialogGUIGridLayout(statusOffset, new Vector2(cellWidth * (compress ? 2 : 4), 25), new Vector2(0f, 5f), UnityEngine.UI.GridLayoutGroup.Corner.UpperLeft, UnityEngine.UI.GridLayoutGroup.Axis.Horizontal, TextAnchor.MiddleLeft, UnityEngine.UI.GridLayoutGroup.Constraint.FixedColumnCount, 1, statusGrid, riskLayout); // Set up the pop window size.x = compress ? 270 : 470; MultiOptionDialog multi = new MultiOptionDialog( "lifesupport_readout", "", "LifeSupport Readout", UISkinManager.defaultSkin, new Rect(position, size), masterGrid, new DialogGUIScrollList(Vector2.zero, false, true, new DialogGUIVerticalLayout(false, false, 1f, offset, TextAnchor.UpperLeft, new DialogGUIContentSizer( UnityEngine.UI.ContentSizeFitter.FitMode.Unconstrained, UnityEngine.UI.ContentSizeFitter.FitMode.PreferredSize, true), vert))); gui = PopupDialog.SpawnPopupDialog( multi, false, UISkinManager.defaultSkin, false, ""); showgui = true; drewgui = false; }