protected override void draw_gui() { LockControls(); WindowPos = GUILayout.Window(GetInstanceID(), WindowPos, DrawMainWindow, Title, GUILayout.Width(width), GUILayout.Height(height)).clampToScreen(); if (warning.doShow) { var facility = EditorLogic.fetch.ship.shipFacility; warning.Draw("Are you sure you want to save current ship configuration as default for " + facility + "?"); if (warning.Result == SimpleDialog.Answer.Yes) { TCAScenario.UpdateDefaultConfig(facility, CFG); } } PartsEditor.Draw(); if (show_imbalance && ActiveEngines.Count > 0) { Markers.DrawWorldMarker(WetCoM, Color.yellow, "Center of Mass", CoM_Icon); Markers.DrawWorldMarker(DryCoM, Color.red, "Center of Dry Mass", CoM_Icon); } }
bool GetCFG() { var ship = EditorLogic.fetch.ship; var TCA_Modules = ModuleTCA.AllTCA(ship); if (TCA_Modules.Count == 0) { Reset(); return(false); } CFG = null; foreach (var tca in TCA_Modules) { if (tca.CFG == null) { continue; } CFG = NamedConfig.FromVesselConfig(ship.shipName, tca.CFG); break; } if (CFG == null) { CFG = NamedConfig.FromVesselConfig(ship.shipName, TCAScenario.GetDefaultConfig(ship.shipFacility)); if (CFG.EnginesProfiles.Empty) { CFG.EnginesProfiles.AddProfile(Engines); } } else { CFG.ActiveProfile.Apply(Engines); } UpdateCFG(TCA_Modules); return(true); }
public override void Awake() { base.Awake(); width = 600; height = 400; GameEvents.onEditorShipModified.Add(OnShipModified); GameEvents.onEditorLoad.Add(OnShipLoad); GameEvents.onEditorRestart.Add(Reset); Available = false; //module availability HasMacroProcessor = TCAModulesDatabase.ModuleAvailable(typeof(MacroProcessor)); HasVTOLAssist = TCAModulesDatabase.ModuleAvailable(typeof(VTOLAssist)); HasVTOLControls = TCAModulesDatabase.ModuleAvailable(typeof(VTOLControl)); HasFlightStabilizer = TCAModulesDatabase.ModuleAvailable(typeof(FlightStabilizer)); HasAltitudeControl = TCAModulesDatabase.ModuleAvailable(typeof(AltitudeControl)); //update TCA part infos foreach (var ap in PartLoader.LoadedPartsList) { foreach (var mi in ap.moduleInfos) { if (mi.moduleName != ModuleTCA.TCA_NAME) { continue; } mi.info = TCAScenario.ModuleStatusString(); mi.primaryInfo = "<b>TCA:</b> " + mi.info; } } }
void SelectConfig() { if (TCAScenario.NamedConfigs.Count == 0) { GUILayout.Label("", Styles.white, GUILayout.ExpandWidth(true)); } else { named_configs.DrawButton(); var new_config = TCAScenario.GetConfig(named_configs.SelectedIndex); if (new_config != selected_config) { selected_config = new_config; config_name = selected_config != null? selected_config.Name : string.Empty; } } }
static void UpdatePartsInfo() { //update TCA part infos var info = TCAScenario.ModuleStatusString(); foreach (var ap in PartLoader.LoadedPartsList) { foreach (var mi in ap.moduleInfos) { if (mi.moduleName != ModuleTCA.TCA_NAME) { continue; } mi.primaryInfo = "<b>TCA:</b> " + info; mi.info = info; } } }
void ConfigsGUI() { GUILayout.BeginVertical(); GUILayout.Label("Manage named configurations", Styles.label, GUILayout.ExpandWidth(true)); GUILayout.BeginHorizontal(); GUILayout.Label("Name:", GUILayout.ExpandWidth(false)); config_name = GUILayout.TextField(config_name, GUILayout.ExpandWidth(true), GUILayout.MinWidth(50)); if (TCAScenario.NamedConfigs.ContainsKey(config_name)) { if (GUILayout.Button(new GUIContent("Overwrite", "Overwrite selected configuration with the current one"), Styles.danger_button, GUILayout.ExpandWidth(false))) { TCAScenario.SaveNamedConfig(config_name, CFG, true); } } else if (GUILayout.Button(new GUIContent("Add", "Save current configuration"), Styles.add_button, GUILayout.ExpandWidth(false)) && config_name != string.Empty) { TCAScenario.SaveNamedConfig(config_name, CFG); UpdateNamedConfigs(); named_configs.SelectItem(TCAScenario.NamedConfigs.IndexOfKey(config_name)); } SelectConfig(); if (GUILayout.Button(new GUIContent("Load", "Load selected configuration"), Styles.active_button, GUILayout.ExpandWidth(false)) && selected_config != null) { CFG.CopyFrom(selected_config); } if (GUILayout.Button(new GUIContent("Delete", "Delete selected configuration"), Styles.danger_button, GUILayout.ExpandWidth(false)) && selected_config != null) { TCAScenario.NamedConfigs.Remove(selected_config.Name); named_configs.SelectItem(named_configs.SelectedIndex - 1); UpdateNamedConfigs(); selected_config = null; } GUILayout.EndHorizontal(); GUILayout.EndVertical(); }
void updateCFG() { //get all ModuleTCA instances in the vessel var TCA_Modules = AllTCA(vessel); //try to get saved CFG from other modules, if needed if (CFG == null) { foreach (var tca in TCA_Modules) { if (tca.CFG == null) { continue; } CFG = tca.CFG; break; } } //if it is found in one of the modules, use it //else, get it from common database or create a new one if (CFG != null) { if (CFG.VesselID == Guid.Empty) { CFG.VesselID = vessel.id; } else if (CFG.VesselID != vessel.id) { CFG = VesselConfig.FromVesselConfig(vessel, CFG); } TCAScenario.Configs[CFG.VesselID] = CFG; } else { CFG = TCAScenario.GetConfig(vessel); } //finally, update references in other modules TCA_Modules.ForEach(m => m.CFG = CFG); }
void DrawMainWindow(int windowID) { //help button if (GUI.Button(new Rect(WindowPos.width - 23f, 2f, 20f, 18f), new GUIContent("?", "Help"))) { TCAManual.ToggleInstance(); } GUILayout.BeginVertical(); { GUILayout.BeginHorizontal(); { if (GUILayout.Button(new GUIContent("Select Modules", "Select which TCA Modules should be installed on this ship"), Styles.active_button, GUILayout.ExpandWidth(true))) { PartsEditor.Toggle(); } if (Modules[typeof(MacroProcessor)]) { if (TCAMacroEditor.Editing) { GUILayout.Label("Edit Macros", Styles.inactive_button, GUILayout.ExpandWidth(true)); } else if (GUILayout.Button("Edit Macros", Styles.active_button, GUILayout.ExpandWidth(true))) { TCAMacroEditor.Edit(CFG); } } if (GUILayout.Button(new GUIContent("Save As Default", "Save current configuration as default for new ships in this facility (VAB/SPH)"), Styles.active_button, GUILayout.ExpandWidth(true))) { var facility = EditorLogic.fetch.ship.shipFacility; warning.Message = string.Format("Are you sure you want to save current ship configuration as default for {0}?", facility); warning.yesCallback = () => TCAScenario.UpdateDefaultConfig(facility, CFG); warning.Show(true); } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.BeginVertical(); { GUILayout.BeginHorizontal(); { if (Utils.ButtonSwitch("Enable TCA", ref CFG.Enabled, "", GUILayout.ExpandWidth(true))) { if (!CFG.Enabled) { Engines.ForEach(e => e.forceThrustPercentage(100)); } CFG.GUIVisible = CFG.Enabled; } if (Modules[typeof(AltitudeControl)]) { if (Utils.ButtonSwitch("Hover", CFG.VF[VFlight.AltitudeControl], "Enable Altitude Control", GUILayout.ExpandWidth(false))) { CFG.VF.Toggle(VFlight.AltitudeControl); } Utils.ButtonSwitch("Follow Terrain", ref CFG.AltitudeAboveTerrain, "Enable follow terrain mode", GUILayout.ExpandWidth(false)); } if (Modules[typeof(VTOLControl)]) { if (Utils.ButtonSwitch("VTOL Mode", CFG.CTRL[ControlMode.VTOL], "Keyboard controls thrust direction instead of torque", GUILayout.ExpandWidth(false))) { CFG.CTRL.XToggle(ControlMode.VTOL); } } if (Modules[typeof(VTOLAssist)]) { Utils.ButtonSwitch("VTOL Assist", ref CFG.VTOLAssistON, "Automatic assistance with vertical takeof or landing", GUILayout.ExpandWidth(false)); } if (Modules[typeof(FlightStabilizer)]) { Utils.ButtonSwitch("Flight Stabilizer", ref CFG.StabilizeFlight, "Automatic flight stabilization when vessel is out of control", GUILayout.ExpandWidth(false)); } if (Modules[typeof(CollisionPreventionSystem)]) { Utils.ButtonSwitch("CPS", ref CFG.UseCPS, "Enable Collistion Prevention System", GUILayout.ExpandWidth(false)); } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { Utils.ButtonSwitch("AutoThrottle", ref CFG.BlockThrottle, "Change altitude/vertical velocity using main throttle control", GUILayout.ExpandWidth(true)); if (Utils.ButtonSwitch("SmartEngines", ref CFG.UseSmartEngines, "Group engines by thrust direction and automatically use appropriate group for a meneuver", GUILayout.ExpandWidth(true))) { if (CFG.UseSmartEngines) { CFG.SmartEngines.OnIfNot(SmartEnginesMode.Best); } } Utils.ButtonSwitch("AutoGear", ref CFG.AutoGear, "Automatically deploy/retract landing gear when needed", GUILayout.ExpandWidth(true)); Utils.ButtonSwitch("AutoBrakes", ref CFG.AutoBrakes, "Automatically ebable/disable brakes when needed", GUILayout.ExpandWidth(true)); Utils.ButtonSwitch("AutoStage", ref CFG.AutoStage, "Automatically activate next stage when previous falmeouted", GUILayout.ExpandWidth(true)); Utils.ButtonSwitch("AutoChute", ref CFG.AutoParachutes, "Automatically activate parachutes when needed", GUILayout.ExpandWidth(true)); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (Modules[typeof(HorizontalSpeedControl)]) { Utils.ButtonSwitch("RCS Translation", ref CFG.CorrectWithTranslation, "Use RCS to correct horizontal velocity", GUILayout.ExpandWidth(true)); } Utils.ButtonSwitch("RCS Rotation", ref CFG.RotateWithRCS, "Use RCS for attitude control", GUILayout.ExpandWidth(true)); GUILayout.EndHorizontal(); } GUILayout.EndVertical(); } GUILayout.EndHorizontal(); if (Engines.Count > 0) { if (GUILayout.Button(new GUIContent("Autoconfigure Active Profile", "This will overwrite any existing groups and roles"), Styles.danger_button, GUILayout.ExpandWidth(true))) { autoconfigure_profile = true; } CFG.EnginesProfiles.Draw(height); if (CFG.ActiveProfile.Changed) { CFG.ActiveProfile.Apply(Engines); update_engines = true; } } GUILayout.BeginHorizontal(Styles.white); { GUILayout.Label("Ship Info:"); GUILayout.FlexibleSpace(); GUILayout.Label("Mass:", Styles.boxed_label); if (Utils.ButtonSwitch(Utils.formatMass(Mass), use_wet_mass, "Balance engines using Wet Mass")) { use_wet_mass = true; update_stats = true; } GUILayout.Label("►"); if (Utils.ButtonSwitch(Utils.formatMass(DryMass), !use_wet_mass, "Balance engines using Dry Mass")) { use_wet_mass = false; update_stats = true; } if (CFG.Enabled) { if (ActiveEngines.Count > 0) { GUILayout.Label(new GUIContent(string.Format("TMR: {0:F2} ► {1:F2}", MinTWR, MaxTWR), "Thrust ot Mass Ratio"), Styles.fracStyle(Utils.Clamp(MinTWR - 1, 0, 1))); GUILayout.Label(new GUIContent(string.Format("Balanced: {0:P1}", MinLimit), "The efficacy of the least efficient of balanced engines"), Styles.fracStyle(MinLimit)); Utils.ButtonSwitch("HL", ref show_imbalance, "Highlight engines with low efficacy deu to balancing"); } else { GUILayout.Label("No active engines", Styles.boxed_label); } } else { GUILayout.Label("TCA is disabled", Styles.boxed_label); } } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); TooltipsAndDragWindow(); }
void DrawMainWindow(int windowID) { if (Macro == null) { return; } GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); LoadMacro |= GUILayout.Button("Load", Styles.active_button, GUILayout.ExpandWidth(false)); if (GUILayout.Button("New", Styles.open_button, GUILayout.ExpandWidth(false))) { EditMacro(null); } GUILayout.Space(20); if (GUILayout.Button(CFG.SelectedMacro != null && CFG.SelectedMacro.Name == Macro.Name? "Apply" : "Use", Styles.active_button, GUILayout.ExpandWidth(false))) { CFG.SelectedMacro = (TCAMacro)Macro.GetCopy(); } if (GUILayout.Button("Save to Vessel DB", Styles.active_button, GUILayout.ExpandWidth(false))) { CFG.Macros.SaveMacro(Macro, true); } if (GUILayout.Button("Save to Global DB", Styles.active_button, GUILayout.ExpandWidth(false))) { TCAScenario.SaveMacro(Macro); } GUILayout.FlexibleSpace(); exit |= GUILayout.Button("Exit", Styles.close_button, GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); scroll = GUILayout.BeginScrollView(scroll, GUILayout.ExpandHeight(false)); Macro.Draw(); GUILayout.EndScrollView(); if (SelectingAction) { GUILayout.FlexibleSpace(); GUILayout.BeginVertical(Styles.white); GUILayout.Label("Select Action", Styles.enabled, GUILayout.ExpandWidth(true)); MacroNode action = null; GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); GUILayout.Label("Builtin", Styles.active, GUILayout.ExpandWidth(true)); if (Components.ActionSelector(out action)) { select_action(action); } GUILayout.EndVertical(); GUILayout.BeginVertical(); GUILayout.Label("Current Vessel", Styles.active, GUILayout.ExpandWidth(true)); if (CFG.Macros.Selector(out action)) { select_action(action); } GUILayout.EndVertical(); GUILayout.BeginVertical(); GUILayout.Label("Global Database", Styles.active, GUILayout.ExpandWidth(true)); if (TCAScenario.Macros.Selector(out action)) { select_action(action); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); if (GUILayout.Button("Cancel", Styles.close_button, GUILayout.ExpandWidth(true))) { SelectAction(null); } GUILayout.EndVertical(); } if (SelectingCondition) { GUILayout.FlexibleSpace(); GUILayout.BeginVertical(Styles.white); GUILayout.Label("Select Condition", Styles.enabled, GUILayout.ExpandWidth(true)); Condition cnd = null; if (Components.ConditionSelector(out cnd)) { if (cnd != null && condition_selected != null) { condition_selected(cnd); } SelectCondition(null); } if (GUILayout.Button("Cancel", Styles.close_button, GUILayout.ExpandWidth(true))) { SelectCondition(null); } GUILayout.EndVertical(); } if (LoadMacro) { GUILayout.FlexibleSpace(); TCAMacro macro; if (DrawMacroSelector(CFG, out macro)) { load_macro(macro); } } GUILayout.EndVertical(); TooltipsAndDragWindow(); }
public string GetPrimaryField() { return("<b>TCA:</b> " + TCAScenario.ModuleStatusString()); }
public string GetPrimaryField() => "<b>TCA:</b> " + TCAScenario.ModuleStatusString();