public static Dictionary <string, Dictionary <string, string> > GetShipList(bool editorShip, bool flyingShip, bool applyMod = false) { Debug.Log("GetShipList, editorShip: " + editorShip + ", flyingShip: " + flyingShip + ", applyMod: " + applyMod); Dictionary <string, Dictionary <string, string> > returnList = new Dictionary <string, Dictionary <string, string> >(); if (editorShip) { foreach (KeyValuePair <string, Dictionary <string, string> > kvp in listEditorVessel) { returnList.Add(kvp.Key, kvp.Value); if (applyMod) { returnList[kvp.Key]["powerTotal"] = AHUtil.TruePower(Double.Parse(returnList[kvp.Key]["powerTotal"])).ToString("N0"); returnList[kvp.Key]["powerRelay"] = AHUtil.TruePower(Double.Parse(returnList[kvp.Key]["powerRelay"])).ToString("N0"); } } } if (flyingShip) { foreach (KeyValuePair <string, Dictionary <string, string> > kvp in listFlyingVessel) { returnList.Add(kvp.Key, kvp.Value); } } return(returnList); }
public static void TargetWindowShipFlight(int id) { GUIStyle guiStyleLabel; GUIStyle guiStyleLabelNorm = new GUIStyle(GUI.skin.GetStyle("Label")); GUIStyle guiStyleLabelBold = new GUIStyle(GUI.skin.GetStyle("Label")); guiStyleLabelBold.fontStyle = FontStyle.Bold; // Close Button if (GUI.Button(new Rect(AHEditor.rectTargetShipFlightWindow.size.x - 20, 2, 18, 18), "X")) { AHEditor.CloseTargetShipFlightWindow(); } GUILayout.BeginVertical(); scrollVectorFlight = GUILayout.BeginScrollView(scrollVectorFlight); foreach (Dictionary <string, string> vesselInfo in AHEditor.guiExternListShipFlight) { if (vesselInfo ["type"] != "Relay") { continue; } GUILayout.BeginHorizontal(); if (GUILayout.Button(/*Select*/ Localizer.Format("#autoLOC_AH_0022"), GUILayout.Width(60f))) { AHEditor.SetTarget(vesselInfo ["pid"]); } if (AHEditor.targetPid == vesselInfo ["pid"]) { guiStyleLabel = guiStyleLabelBold; } else { guiStyleLabel = guiStyleLabelNorm; } GUILayout.Label( "(" + AHUtil.TruePower(Double.Parse(vesselInfo ["powerRelay"])).ToString("N0") + ") " + vesselInfo ["name"], guiStyleLabel); GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); GUILayout.EndVertical(); }
public static void UpdateTargetPartPower() { List <ModuleDataTransmitter> antennas = new List <ModuleDataTransmitter> (); double bestAntenna = 0; foreach (ModuleDataTransmitter antenna in AHShipList.listAntennaPart) { if (!listAntennaPart.ContainsKey(antenna)) { continue; } if (listAntennaPart [antenna] <= 0) { listAntennaPart [antenna] = 0; continue; } if (antenna.antennaPower > bestAntenna) { bestAntenna = antenna.antennaPower; } for (int i = 0; i < listAntennaPart [antenna]; i++) { antennas.Add(antenna); } } double combPower = AHUtil.GetVesselPower(antennas, true); bestAntenna = AHUtil.TruePower(bestAntenna); if (combPower > bestAntenna) { targetPartPower = combPower; } else { targetPartPower = bestAntenna; } SetTargetAsPart(); }
public static void SetTarget(string pid) { Dictionary <string, string> targetDict; if (externListShipEditor.ContainsKey(pid)) { targetDict = externListShipEditor [pid]; targetType = AHEditorTargetType.EDITOR; } else { targetDict = externListShipFlight [pid]; targetType = AHEditorTargetType.FLIGHT; } targetPower = AHUtil.TruePower(Double.Parse(targetDict ["powerRelay"])); targetName = Localizer.Format("#autoLOC_AH_0039") + " : " + targetDict ["name"]; targetPid = pid; instance.DoTheMath(); }
private void EditorShipListWindow(int id) { GUIStyle guiStyleLabel; GUIStyle guiStyleLabelNorm = new GUIStyle(GUI.skin.GetStyle("Label")); GUIStyle guiStyleLabelBold = new GUIStyle(GUI.skin.GetStyle("Label")); guiStyleLabelBold.fontStyle = FontStyle.Bold; GUIStyle guiStyleButton; GUIStyle guiStyleButtonNorm = new GUIStyle(GUI.skin.GetStyle("Button")); GUIStyle guiStyleButtonBold = new GUIStyle(GUI.skin.GetStyle("Button")); guiStyleButtonBold.fontStyle = FontStyle.Bold; // Close Button if (GUI.Button(new Rect(rectEditorShipWindow.size.x - 22, 2, 20, 20), "X")) { editorShipWindowOn = false; } GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); if (editorShipVab) { guiStyleButton = guiStyleButtonBold; } else { guiStyleButton = guiStyleButtonNorm; } if (GUILayout.Button(Localizer.Format("#autoLOC_AH_0019"), guiStyleButton)) { editorShipVab = true; } if (editorShipVab) { guiStyleButton = guiStyleButtonNorm; } else { guiStyleButton = guiStyleButtonBold; } if (GUILayout.Button(Localizer.Format("#autoLOC_AH_0020"), guiStyleButton)) { editorShipVab = false; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(35f); if (editorShipRelay) { guiStyleButton = guiStyleButtonNorm; } else { guiStyleButton = guiStyleButtonBold; } if (GUILayout.Button(Localizer.Format("#autoLOC_AH_0021"), guiStyleButton)) { editorShipRelay = false; } if (editorShipRelay) { guiStyleButton = guiStyleButtonBold; } else { guiStyleButton = guiStyleButtonNorm; } if (GUILayout.Button(Localizer.Format("#autoLOC_AH_0003"), guiStyleButton)) { editorShipRelay = true; } GUILayout.Space(35f); GUILayout.EndHorizontal(); if (editorShipVab) { if (editorShipRelay) { guiListEditorShipDisplay = guiListEditorShipVabRelay; } else { guiListEditorShipDisplay = guiListEditorShipVabAll; } } else { if (editorShipRelay) { guiListEditorShipDisplay = guiListEditorShipSphRelay; } else { guiListEditorShipDisplay = guiListEditorShipSphAll; } } scrollerEditorShipWindow = GUILayout.BeginScrollView(scrollerEditorShipWindow); foreach (Dictionary <string, string> vesselInfo in guiListEditorShipDisplay) { GUILayout.BeginHorizontal(); if (GUILayout.Button(Localizer.Format("#autoLOC_AH_0022"), GUILayout.Width(60f))) { targetPid = vesselInfo ["pid"]; ShowCircles(); } if (targetPid == vesselInfo ["pid"]) { guiStyleLabel = guiStyleLabelBold; } else { guiStyleLabel = guiStyleLabelNorm; } string power; if (editorShipRelay) { power = AHUtil.TruePower(Double.Parse(vesselInfo ["powerRelay"])).ToString(); } else { power = AHUtil.TruePower(Double.Parse(vesselInfo ["powerTotal"])).ToString(); } GUILayout.Label("(" + power + ") " + vesselInfo ["name"], guiStyleLabel); GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); GUILayout.EndVertical(); GUI.DragWindow(); }
private void CreateMarkers() { listMarkers = new Dictionary <string, Dictionary <string, List <GameObject> > > (); foreach (KeyValuePair <string, Dictionary <string, string> > vesselPairInfo in listShipTransmitter) { // Debug.Log ("[AH] creating marker for vessel : " + vesselPairInfo.Value ["name"]); listMarkers.Add(vesselPairInfo.Key, new Dictionary <string, List <GameObject> > ()); double vesselPower, maxRange, realSignal; Vessel transmiter; bool editorShip; bool isHome; Transform relay; AHMapMarker marker; vesselPower = AHUtil.TruePower(Double.Parse(vesselPairInfo.Value ["powerTotal"])); if ((vesselPairInfo.Value ["type"] == "VAB") || (vesselPairInfo.Value ["type"] == "SPH")) { transmiter = null; editorShip = true; } else { transmiter = FlightGlobals.Vessels.Find(v => v.id.ToString() == vesselPairInfo.Key); editorShip = false; } // Debug.Log ("[AH] vessel power computed"); // Active Connection : if (vesselPairInfo.Value ["connectedTo"] == "") { // the active connection is to the DSN or isn't set maxRange = AHUtil.GetRange(vesselPower, dsnPower); realSignal = 1d; isHome = true; relay = Planetarium.fetch.Home.MapObject.trf; } else { // active connection going trough a relay maxRange = AHUtil.GetRange(vesselPower, AHUtil.TruePower(Double.Parse(listShipRelay [vesselPairInfo.Value ["connectedTo"]] ["powerRelay"]))); realSignal = Double.Parse(listShipRelay [vesselPairInfo.Value ["connectedTo"]] ["realSignal"]); isHome = false; relay = FlightGlobals.Vessels.Find(v => v.id.ToString() == vesselPairInfo.Value ["connectedTo"]).mapObject.trf; } maxRange = AHUtil.GetDistanceAt0(maxRange); listMarkers [vesselPairInfo.Key].Add("ACTIVE", new List <GameObject> ()); listMarkers [vesselPairInfo.Key] ["ACTIVE"].Add(new GameObject()); marker = listMarkers [vesselPairInfo.Key] ["ACTIVE"] [0].AddComponent <AHMapMarker> (); marker.SetUp(maxRange, transmiter, relay, isHome, realSignal, editorShip); // Debug.Log ("[AH] active connection done"); // DSN Connection : maxRange = AHUtil.GetRange(vesselPower, dsnPower); maxRange = AHUtil.GetDistanceAt0(maxRange); realSignal = 1d; isHome = true; relay = Planetarium.fetch.Home.MapObject.trf; listMarkers [vesselPairInfo.Key].Add("DSN", new List <GameObject> ()); listMarkers [vesselPairInfo.Key] ["DSN"].Add(new GameObject()); marker = listMarkers [vesselPairInfo.Key] ["DSN"] [0].AddComponent <AHMapMarker> (); marker.SetUp(maxRange, transmiter, relay, isHome, realSignal, editorShip); // Debug.Log ("[AH] dsn connection done"); // Relay(s) Connection : List <GameObject> listRelayMarkers = new List <GameObject> (); foreach (KeyValuePair <string, Dictionary <string, string> > relayPairInfo in listShipRelay) { if (relayPairInfo.Key == vesselPairInfo.Key) { continue; } maxRange = AHUtil.GetRange(vesselPower, AHUtil.TruePower(Double.Parse(relayPairInfo.Value ["powerRelay"]))); maxRange = AHUtil.GetDistanceAt0(maxRange); realSignal = Double.Parse(relayPairInfo.Value ["realSignal"]); isHome = false; relay = FlightGlobals.Vessels.Find(v => v.id.ToString() == relayPairInfo.Key).mapObject.trf; listRelayMarkers.Add(new GameObject()); marker = listRelayMarkers [listRelayMarkers.Count - 1].AddComponent <AHMapMarker> (); marker.SetUp(maxRange, transmiter, relay, isHome, realSignal, editorShip); } listMarkers [vesselPairInfo.Key].Add("RELAY", listRelayMarkers); // Debug.Log ("[AH] relays connections done"); } }
public void DoTheMath() { // Direct antenna (not-relay) nbDirectAntenna = directAntennaList.Count; nbDirectCombAntenna = directCombAntennaList.Count; // Direct combinable : if (nbDirectCombAntenna > 0) { rawDirectCombPower = AHUtil.GetVesselPower(directCombAntennaList, false); directCombPower = AHUtil.TruePower(rawDirectCombPower); //AHUtil.GetVesselPower (directCombAntennaList); directCombRange = AHUtil.GetRange(directCombPower, targetPower); } else { rawDirectCombPower = 0; directCombPower = 0; directCombRange = 0; } // Direct straight : if (nbDirectAntenna > 0) { ModuleDataTransmitter bigDirect = null; foreach (ModuleDataTransmitter antenna in directAntennaList) { if (bigDirect == null || bigDirect.antennaPower < antenna.antennaPower) { bigDirect = antenna; } } rawDirectPower = bigDirect.antennaPower; directPower = AHUtil.TruePower(rawDirectPower); //AHUtil.TruePower (bigDirect.antennaPower); directRange = AHUtil.GetRange(directPower, targetPower); directAntennaName = bigDirect.part.partInfo.title; } else { rawDirectPower = 0; directPower = 0; directRange = 0; directAntennaName = "No Antenna"; } // Relay antenna : nbRelayAntenna = relayAntennaList.Count; nbRelayCombAntenna = relayCombAntennaList.Count; // Relay combinable : if (nbRelayCombAntenna > 0) { rawRelayCombPower = AHUtil.GetVesselPower(relayCombAntennaList, false); relayCombPower = AHUtil.TruePower(rawRelayCombPower); //AHUtil.GetVesselPower (relayCombAntennaList); relayCombRange = AHUtil.GetRange(relayCombPower, targetPower); } else { rawRelayCombPower = 0; relayCombPower = 0; relayCombRange = 0; } // Relay straight : if (nbRelayAntenna > 0) { ModuleDataTransmitter bigRelay = null; foreach (ModuleDataTransmitter antenna in relayAntennaList) { if (bigRelay == null || bigRelay.antennaPower < antenna.antennaPower) { bigRelay = antenna; } } rawRelayPower = bigRelay.antennaPower; relayPower = AHUtil.TruePower(rawRelayPower); //AHUtil.TruePower (bigRelay.antennaPower); relayRange = AHUtil.GetRange(relayPower, targetPower); relayAntennaName = bigRelay.part.partInfo.title; } else { rawRelayPower = 0; relayPower = 0; relayRange = 0; relayAntennaName = "No Antenna"; } FetchBetterAntennas(); FetchAntennaStatus(); SetPerPlanetList(); directDistanceAt100 = AHUtil.GetDistanceAt100(directBetterRange); directDistanceAt75 = AHUtil.GetDistanceAt75(directBetterRange); directDistanceAt50 = AHUtil.GetDistanceAt50(directBetterRange); directDistanceAt25 = AHUtil.GetDistanceAt25(directBetterRange); relayDistanceAt100 = AHUtil.GetDistanceAt100(relayBetterRange); relayDistanceAt75 = AHUtil.GetDistanceAt75(relayBetterRange); relayDistanceAt50 = AHUtil.GetDistanceAt50(relayBetterRange); relayDistanceAt25 = AHUtil.GetDistanceAt25(relayBetterRange); }
public static void TargetWindowPart(int id) { GUIStyle guiStyleLabel; GUIStyle guiStyleLabelNorm = new GUIStyle(GUI.skin.GetStyle("Label")); GUIStyle guiStyleLabelBold = new GUIStyle(GUI.skin.GetStyle("Label")); guiStyleLabelBold.fontStyle = FontStyle.Bold; GUIStyle guiStyleButtonBold = new GUIStyle(GUI.skin.GetStyle("Button")); guiStyleButtonBold.fontStyle = FontStyle.Bold; // Close Button if (GUI.Button(new Rect(AHEditor.rectTargetPartWindow.size.x - 20, 2, 18, 18), "X")) { AHEditor.CloseTargetPartWindow(); } GUILayout.BeginVertical(); scrollVectorPart = GUILayout.BeginScrollView(scrollVectorPart); foreach (ModuleDataTransmitter antenna in AHShipList.listAntennaPart) { if (antenna.antennaType != AntennaType.RELAY) { continue; } if (AHEditor.listAntennaPart [antenna] > 0) { guiStyleLabel = guiStyleLabelBold; } else { guiStyleLabel = guiStyleLabelNorm; } GUILayout.BeginHorizontal(); GUILayout.Label(AHEditor.listAntennaPart [antenna].ToString(), guiStyleLabel, GUILayout.Width(15f)); if (GUILayout.Button("+", guiStyleButtonBold, GUILayout.Width(20f))) { AHEditor.listAntennaPart [antenna]++; AHEditor.UpdateTargetPartPower(); } if (GUILayout.Button("-", guiStyleButtonBold, GUILayout.Width(20f))) { AHEditor.listAntennaPart [antenna]--; AHEditor.UpdateTargetPartPower(); } GUILayout.Label( "(" + AHUtil.TruePower(antenna.antennaPower).ToString("N0") + ") " + antenna.part.partInfo.title, guiStyleLabel); GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); GUILayout.Space(10f); GUILayout.BeginHorizontal(); GUILayout.Label(/*Power*/ Localizer.Format("#autoLOC_AH_0009") + " : " + AHEditor.targetPartPower.ToString("N0")); if (GUILayout.Button(/*Set As Target*/ Localizer.Format("#autoLOC_AH_0023"))) { AHEditor.SetTargetAsPart(); } GUILayout.EndHorizontal(); GUILayout.EndVertical(); }
public static void TargetWindowShipEditor(int id) { GUIStyle guiStyleLabel; GUIStyle guiStyleLabelNorm = new GUIStyle(GUI.skin.GetStyle("Label")); GUIStyle guiStyleLabelBold = new GUIStyle(GUI.skin.GetStyle("Label")); guiStyleLabelBold.fontStyle = FontStyle.Bold; GUIStyle guiStyleButton; GUIStyle guiStyleButtonNorm = new GUIStyle(GUI.skin.GetStyle("Button")); GUIStyle guiStyleButtonBold = new GUIStyle(GUI.skin.GetStyle("Button")); guiStyleButtonBold.fontStyle = FontStyle.Bold; GUIStyle guiStyleButtonRed = new GUIStyle(GUI.skin.GetStyle("Button")); guiStyleButtonRed.fontStyle = FontStyle.Bold; guiStyleButtonRed.normal.textColor = Color.red; guiStyleButtonRed.hover.textColor = Color.red; // Close Button if (GUI.Button(new Rect(AHEditor.rectTargetShipEditorWindow.size.x - 20, 2, 18, 18), "X")) { AHEditor.CloseTargetShipEditorWindow(); } GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); if (vab) { guiStyleButton = guiStyleButtonBold; } else { guiStyleButton = guiStyleButtonNorm; } if (GUILayout.Button(/*VAB*/ Localizer.Format("#autoLOC_AH_0019"), guiStyleButton)) { vab = true; } if (vab) { guiStyleButton = guiStyleButtonNorm; } else { guiStyleButton = guiStyleButtonBold; } if (GUILayout.Button(/*SPH*/ Localizer.Format("#autoLOC_AH_0020"), guiStyleButton)) { vab = false; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(35f); if (relay) { guiStyleButton = guiStyleButtonNorm; } else { guiStyleButton = guiStyleButtonBold; } if (GUILayout.Button(/*All*/ Localizer.Format("#autoLOC_AH_0021"), guiStyleButton)) { relay = false; } if (relay) { guiStyleButton = guiStyleButtonBold; } else { guiStyleButton = guiStyleButtonNorm; } if (GUILayout.Button(/*Relay*/ Localizer.Format("#autoLOC_AH_0003"), guiStyleButton)) { relay = true; } GUILayout.Space(35f); GUILayout.EndHorizontal(); scrollVectorEditor = GUILayout.BeginScrollView(scrollVectorEditor); if (vab) { if (relay) { displayList = AHEditor.guiExternListShipEditorVabRelay; } else { displayList = AHEditor.guiExternListShipEditorVabAll; } } else { if (relay) { displayList = AHEditor.guiExternListShipEditorSphRelay; } else { displayList = AHEditor.guiExternListShipEditorSphAll; } } foreach (Dictionary <string, string> vesselInfo in displayList) { if ((vab && (vesselInfo ["type"] != "VAB")) || (!vab && (vesselInfo ["type"] != "SPH"))) { continue; } GUILayout.BeginHorizontal(); if (GUILayout.Button(Localizer.Format("#autoLOC_AH_0022"), GUILayout.Width(60f))) { AHEditor.SetTarget(vesselInfo ["pid"]); } if (AHEditor.targetPid == vesselInfo ["pid"]) { guiStyleLabel = guiStyleLabelBold; } else { guiStyleLabel = guiStyleLabelNorm; } GUILayout.Label( "(" + AHUtil.TruePower(Double.Parse(vesselInfo ["powerRelay"])).ToString("N0") + ") " + vesselInfo ["name"], guiStyleLabel); if (GUILayout.Button("X", guiStyleButtonRed, GUILayout.Width(22f))) { AHEditor.RemoveShipFromShipList(vesselInfo ["pid"]); } GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); GUILayout.EndVertical(); }