protected virtual void DoSaveFamily(GUIButton sender, object value) { if (!string.IsNullOrEmpty(value.ToString()) && KLVCore.FamilyAvailable(value.ToString())) { if (editingFamily == null) { //Adding new family KLVCore.AddVehicleFamily(value.ToString()); } else { //Editing existing family editingFamily.SetName(value.ToString()); editingFamily = null; } KLVCore.Save(); KLVCore.UpdateAllVehicleNameSchemes(); UpdateFamilies(); textEditFamily.SetText(""); textEditFamily.SetEditing(false); SetFamilyEditState(false); } }
protected void DoUpdateLists(GUIButton sender = null, object value = null) { listSuggestions = GUIListNode.CreateListNode2Lvl(KLVCore.GetVehicleSuggestions(payloadMass, ignoreMass), null, DoShowSuggestionInfo); listSuggestions.SetCollapsedAll(false); listSuggestions.SetLevelStyle(2, klvGUIStyles.PanelLabel); editVehicleList = GUIListNode.CreateListNode3Lvl(KLVCore.GetFullVehicleSummary(), null, DoEditVehicle); UpdateFamilies(true); }
protected void DoShowSuggestionInfo(GUIButton sender, object value) { if (value != null && !string.IsNullOrEmpty(value.ToString())) { suggestedVehicle = KLVCore.GetVehicle(value.ToString()); } else { suggestedVehicle = null; } }
//Destinations private void DoRemoveDestination(GUIButton sender, object value) { if (!string.IsNullOrEmpty(value.ToString())) { KLVCore.RemoveDestination(value.ToString()); KLVCore.Save(); KLVCore.UpdateAllVehicleNameSchemes(); comboDestination.SetItems(KLVCore.GetAllDestinationName()); comboDestination.Deselect(); } }
protected void UpdateFamilies(bool forceNoEdit = false) { if (!forceNoEdit && GlobalSettings.AllowFamilyEdit) { familyList = GUIListNode.CreateListNode3Lvl(KLVCore.GetFullVehicleSummary(), null, null, DoBeginFamilyEdit); } else { familyList = GUIListNode.CreateListNode3Lvl(KLVCore.GetFullVehicleSummary()); } }
public virtual void Start() { KLVCore.Load(); var App = ApplicationLauncher.Instance; KLVButtonImage = GameDatabase.Instance.GetTexture("KerbalLaunchVehicles/Assets/launcherIcon", false); LauncherButton = App.AddModApplication(OnLauncherButtonPress, OnLauncherButtonPress, null, null, null, null, visibleInScenes, KLVButtonImage); GUIUtilities.Log("[MOD] KLV window start"); ActiveCombos = new HashSet <DropDown>(); MarkedCombos = new Dictionary <klvGUI.DropDown, bool>(); CreateControls(); }
private void DoAddDestination(GUIButton sender, object value) { if (!string.IsNullOrEmpty(value.ToString()) && KLVCore.DestinationAvailable(value.ToString())) { textAddDestination.SetEditing(false); textAddDestination.SetText(""); KLVCore.AddDestination(value.ToString()); KLVCore.Save(); KLVCore.UpdateAllVehicleNameSchemes(); comboDestination.SetItems(KLVCore.GetAllDestinationName()); //Open combo to view new addition MarkComboToExpand(true, comboDestination); } }
protected virtual void DoBeginFamilyEdit(GUIButton sender, object value) { if (value != null && GlobalSettings.AllowFamilyEdit) { var family = KLVCore.GetVehicleFamily(value.ToString().Trim()); if (family != null) { editingFamily = family; SetFamilyEditState(true); textEditFamily.SetText(editingFamily.Name); textEditFamily.SetEditing(true); } } }
private void DoEditVehicle(GUIButton sender, object value) { if (value != null && EditorLogic.RootPart == null) { if (!string.IsNullOrEmpty(value.ToString())) { var vehicle = KLVCore.GetVehicle(value.ToString()); if (vehicle != null) { StageManager.Instance.DeleteEmptyStages(); //Debug.Log(vehicle.SubassemblyName); failedSubassembly = ""; if (DoLoadSubassembly(sender, vehicle.SubassemblyName)) { DoAddSubassembly(sender, vehicle.SubassemblyName); textVehicleName.SetText(vehicle.Name); textVehicleName.SetEditing(true); outputVehicleName = vehicle.Name; textVehicleNote.SetText(String.IsNullOrEmpty(vehicle.Note) ? "Note..." : vehicle.Note); textVehicleNote.SetEditing(true); outputVehicleNote = vehicle.Note; comboFamily.SetSelection(vehicle.Parent.Name); comboFamily.SetExpanded(false); for (int i = 0; i < vehicle.AllLaunchConfigs.Count; i++) { AddConfig(vehicle.AllLaunchConfigs[i]); comboAllDestinations[i].SetExpanded(false); } editingVehicle = vehicle; } else { failedSubassembly = vehicle.SubassemblyName; } } } } }
protected override void CreateControls() { base.CreateControls(); // Destinations Tab textAddDestination = new GUITextBox("Add Destination: ", "", "", 180, 300, DoAddDestination); buttonAddDest = new GUIButton("Add", DoAddDestination, new GUILayoutOption[] { GUILayout.Width(120) }); buttonRemoveDest = new GUIButton("Remove", DoRemoveDestination, new GUILayoutOption[] { GUILayout.Width(100) }); comboDestination = new DropDown(new Vector2(260, 170), KLVCore.GetAllDestinationName()); RegisterCombos(comboDestination); // Settings Tab textFolderPath = new GUITextBox("Config path:", SaveManager.vehiclesPath, "", 300, 400); buttonSave = new GUIButton("Save Configurations", DoSave, null); buttonLoad = new GUIButton("Load Configurations", DoLoad, null); buttonUnload = new GUIButton("Unload All Configurations", DoUnload, null); buttonIncreaseFont = new GUIButton("▲", DoIncreaseFont, GUILayout.Width(30)); buttonDecreaseFont = new GUIButton("▼", DoDecreaseFont, GUILayout.Width(30)); }
protected void AddConfig(LaunchConfig config) { comboFamily.SetExpanded(false); if (maxNewConfigs <= newConfigs.Count()) { return; } isAddingConfig = true; // Add config and all editing controls var newRemoveButton = new GUIButton("Remove", DoRemoveLaunchConfig, new GUILayoutOption[] { GUILayout.Width(80) }); var newTextPayload = new GUITextBox("Max payload: ", "", "t to ", 50, 180); var newDestCombo = new klvGUI.DropDown(new Vector2(200, 130), KLVCore.GetAllDestinationName(), newRemoveButton); if (config != null) { newDestCombo.SetSelection(config.Target.Name); } newDestCombo.SetExpandAction(DoExpandCombo); RegisterCombos(newDestCombo); if (config != null) { newTextPayload.SetText(config.PayloadMass.ToString("0.###")); newDestCombo.SetSelection(config.Target == null ? "" : config.Target.Name); newConfigs.Add(config); } else { newConfigs.Add(new LaunchConfig()); } newTextPayload.SetEditing(true); buttonAllRemoveConfigs.Add(newRemoveButton); comboAllDestinations.Add(newDestCombo); textAllPayloads.Add(newTextPayload); }
private void EndVehicleEdit(GUIButton sender = null, object value = null) { textVehicleName.SetEditing(false); textVehicleNote.SetEditing(false); textVehicleName.SetText(""); textVehicleNote.SetText(""); comboFamily.Deselect(); isAddingConfig = false; newConfigs = new List <LaunchConfig>(); textAllPayloads = new List <GUITextBox>(); comboAllDestinations = new List <DropDown>(); buttonAllRemoveConfigs = new List <GUIButton>(); selectedRootPart = null; editingVehicle = null; KLVCore.UpdateAllVehicleNameSchemes(); DoUpdateLists(); }
protected void DoSaveVehicle(GUIButton sender, object value) { if (value != null) { if (!string.IsNullOrEmpty(comboFamily.selectedItemName)) { Vehicle newVehicle = null; if (editingVehicle == null) { newVehicle = KLVCore.AddVehicle(comboFamily.selectedItemName, outputVehicleName.ToString(), vehicleWetMass, outputVehicleNote.ToString()); } else { newVehicle = editingVehicle; newVehicle.SetName(outputVehicleName.ToString()); newVehicle.SetNote(outputVehicleNote.ToString()); } newVehicle.SetLaunchConfigs(newConfigs); KLVCore.Save(); if (SubassemblyDropZone.Instance != null && SubassemblyDropZone.Instance.enabled) { try { EditorPartList.Instance.subassemblyButtonTransform.enabled = true; SaveManager.SaveSubassembly(SubassemblyDropZone.Instance, selectedRootPart, newVehicle.GetFullName(), newVehicle.Note); } catch (NullReferenceException) { //GUIUtilities.Log("Saving subassembly button error"); } } EndVehicleEdit(); } } }
private bool LayoutLaunchConfigEdit(int index) { bool correct = true; GUILayout.BeginHorizontal(); outputPayload = textAllPayloads[index].GetText(); // Display any invalid data warnings if (outputPayload == null || !double.TryParse(outputPayload.ToString(), out payload)) { //GUILayout.Label("Invalid payload!", klvGUIStyles.WarningLabel); configErrorReason = String.IsNullOrEmpty(configErrorReason) ? "Invalid payload!" : configErrorReason; correct = false; } else if (!comboAllDestinations[index].isItemSelected) { //GUILayout.Label("Destination missing!", klvGUIStyles.WarningLabel); configErrorReason = String.IsNullOrEmpty(configErrorReason) ? "Destination missing!" : configErrorReason; correct = false; } else { newConfigs[index].SetPayload(payload); newConfigs[index].SetTarget(KLVCore.GetDestination(comboAllDestinations[index].selectedItemName)); } textAllPayloads[index].DoLayout(correct ? klvGUIStyles.StandardLabel : klvGUIStyles.WarningLabel); comboAllDestinations[index].DoLayout(null); buttonAllRemoveConfigs[index].DoLayout(klvGUIStyles.StandardButton, "Remove", true); GUILayout.EndHorizontal(); payload = 0; return(correct); }
protected override void CreateControls() { base.CreateControls(); //Tabs buttonTabSubassemblies = new GUIButton("Get Vehicle", DoChangeTab, new GUILayoutOption[] { GUILayout.ExpandWidth(true) }); //Edit Vehicle textVehicleName = new GUITextBox("Name :", "", "", 150, 210); textVehicleNote = new GUIFreeText("Notes...", 475, 60); buttonSaveVehicle = new GUIButton("Save Vehicle", DoSaveVehicle, new GUILayoutOption[] { GUILayout.Width(165) }); buttonCancelVehicleEdit = new GUIButton("Cancel", EndVehicleEdit, new GUILayoutOption[] { GUILayout.Width(85) }); comboFamily = new DropDown(new Vector2(180, 108), KLVCore.GetAllFamilyNames(), null, "Select Family"); RegisterCombos(comboFamily); editVehicleList = GUIListNode.CreateListNode3Lvl(KLVCore.GetFullVehicleSummary(), null, DoEditVehicle); dropZone = new GUIButton("ADD VESSEL AS LAUNCH VEHICLE", DoAddSubassembly, new GUILayoutOption[] { GUILayout.Height(60) }); buttonAddLaunchConfig = new GUIButton("Add Launch Config", DoAddLaunchConfig, new GUILayoutOption[] { GUILayout.Width(175) }); //Suggestions buttonUpdateSuggestions = new GUIButton("Update Suggestions", DoUpdateLists, new GUILayoutOption[] { GUILayout.Width(180) }); buttonGetSuggestion = new GUIButton("Load", DoLoadSuggestion, new GUILayoutOption[] { GUILayout.Width(80) }); DoUpdateLists(); }
//Settings private void DoSave(GUIButton sender, object value) { KLVCore.Save(); }
private void DoLoad(GUIButton sender, object value) { KLVCore.Load(); UpdateFamilies(); comboDestination.SetItems(KLVCore.GetAllDestinationName()); }
private void DoUnload(GUIButton sender, object value) { KLVCore.RefreshAllConfigurations(); UpdateFamilies(); comboDestination.SetItems(KLVCore.GetAllDestinationName()); }
//Displays private void DisplayVehicles() { if (selectedRootPart == null) { GUILayout.Space(10); if (EditorLogic.RootPart == null) { // If building is empty, allow select vehicle to edit GUILayout.BeginHorizontal(); GUILayout.Label("Edit existing Launch Vehicle", klvGUIStyles.HeaderLabel); GUILayout.EndHorizontal(); GUILayout.Label(String.IsNullOrEmpty(failedSubassembly) ? "" : "Could not find " + failedSubassembly, klvGUIStyles.WarningLabel); LayoutGUIList(editVehicleList, 340, 350); } else { // If building occupied only allow add new vehicle // If we allow dropping parts, display here dropZone.DoLayout(klvGUIStyles.HighlightBox, GlobalSettings.AllowVehicleDrop && EditorLogic.SelectedPart != null ? "DROP PART AS LAUNCH VEHICLE" : "ADD VESSEL AS LAUNCH VEHICLE"); GUILayout.Space(5); isRootPartDecoupler = (GlobalSettings.AllowVehicleDrop && EditorLogic.SelectedPart != null ? EditorLogic.SelectedPart : EditorLogic.RootPart).partInfo == null; //Coupling not available in ksp1.1 so we won't warn on this #if !VERSION1_1 isRootPartDecoupler = isRootPartDecoupler || (GlobalSettings.AllowVehicleDrop && EditorLogic.SelectedPart != null ? EditorLogic.SelectedPart : EditorLogic.RootPart).partInfo.category == PartCategories.Coupling; #else isRootPartDecoupler = true; #endif GUILayout.Label(isRootPartDecoupler ? "" : "It is recommended to use a decoupler as the root part to detach the payload", klvGUIStyles.WarningLabel); GUILayout.Space(10); GUILayout.Label("To edit an existing vehicle, clear the building", klvGUIStyles.HeaderLabel); } } else { GUILayout.Label(editingVehicle == null ? "Add New Launch Vehicle" : "Edit Launch Vehicle", klvGUIStyles.HeaderLabel); GUILayout.Space(5); GUILayout.BeginHorizontal(); outputVehicleName = textVehicleName.DoLayout(); comboFamily.DoLayout(editingVehicle == null ? null : klvGUIStyles.DisabledButton, editingVehicle == null ? true : false); GUILayout.EndHorizontal(); outputVehicleNote = textVehicleNote.DoLayout(); GUILayout.Label("Vehicle dry mass: " + vehicleDryMass.ToString("0.###") + "t", klvGUIStyles.StandardLabel); GUILayout.Label("Vehicle wet mass: " + vehicleWetMass.ToString("0.###") + "t", klvGUIStyles.StandardLabel); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false)); buttonCancelVehicleEdit.DoLayout(klvGUIStyles.StandardButton); if (!string.IsNullOrEmpty(outputVehicleName.ToString())) { if (string.IsNullOrEmpty(comboFamily.selectedItemName)) { buttonSaveVehicle.DoLayout(klvGUIStyles.WarningButton, "Family missing!", null); } else if (!KLVCore.VehicleAvailable(comboFamily.selectedItemName, outputVehicleName.ToString(), editingVehicle)) { buttonSaveVehicle.DoLayout(klvGUIStyles.WarningButton, "Vehicle exists!", null); } else if (isAddingConfig && !launchConfigsGood) { buttonSaveVehicle.DoLayout(klvGUIStyles.WarningButton, configErrorReason, null); } else { buttonSaveVehicle.DoLayout(klvGUIStyles.CorrectButton, "Save Vehicle", outputVehicleName.ToString()); } if (maxNewConfigs > newConfigs.Count()) { buttonAddLaunchConfig.DoLayout(klvGUIStyles.StandardButton, "Add Launch Config", true); } else { buttonAddLaunchConfig.DoLayout(klvGUIStyles.WarningButton, "Max new Configs", null); } } GUILayout.EndHorizontal(); launchConfigsGood = true; configErrorReason = ""; for (int i = 0; i < newConfigs.Count(); i++) { launchConfigsGood = LayoutLaunchConfigEdit(i) && launchConfigsGood; } } }