void GUIDisplay(int windowID)
        {
            GUILayout.BeginHorizontal();
            foreach (var category in TextureTools.categories)
            {
                if (TextureTools.textures.ContainsKey(category))
                {
                    filters[category] = GUILayout.Toggle(filters[category], TextureTools.textures[category], HighLogic.Skin.button, GUILayout.Height(iconSize.y), GUILayout.Width(iconSize.x));
                }
            }
            GUILayout.EndHorizontal();
            if (GUILayout.Button($"Sort Mode: {sourceSortMode}"))
            {
                sourceSortMode = (SortMode)(((int)(sourceSortMode + 1)) % System.Enum.GetNames(typeof(SortMode)).Length);
                SortList(sourceVessels, sourceSortMode);
            }
            scrollSourcePos = GUILayout.BeginScrollView(scrollSourcePos, GUILayout.ExpandWidth(true));
            foreach (var ra in from Vessel v in sourceVessels
                     from RealAntenna ra in (v.Connection?.Comm as RACommNode)?.RAAntennaList
                     where filters[TextureTools.GetKeyFromVesselType(v.vesselType)]
                     select ra)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label($"{ra.ParentNode?.displayName}: {ra.ToStringShort()}", GUILayout.ExpandWidth(true));
                if (ra.CanTarget && GUILayout.Button("Target", GUILayout.ExpandWidth(false)))
                {
                    Targeting.AntennaTargetManager.AcquireGUI(ra);
                }
                if (GUILayout.Button("Debug", GUILayout.ExpandWidth(false)))
                {
                    var dbg = new GameObject($"Antenna Debugger: {ra.Name}").AddComponent <Network.ConnectionDebugger>();
                    dbg.antenna = ra;
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndScrollView();

            if (GUILayout.Button("Close"))
            {
                Destroy(this);
                gameObject.DestroyGameObject();
            }
            GUI.DragWindow();
        }
Exemplo n.º 2
0
        void GUIDisplay(int windowID)
        {
            Vessel parentVessel = (antenna?.ParentNode as RACommNode)?.ParentVessel;

            GUILayout.BeginVertical(HighLogic.Skin.box);
            GUILayout.Label($"Vessel: {parentVessel?.name ?? "None"}");
            GUILayout.Label($"Antenna: {antenna.Name}");
            GUILayout.Label($"Band: {antenna.RFBand.name}       Power: {antenna.TxPower}dBm");
            GUILayout.Label($"Target: {antenna.Target}");
            GUILayout.EndVertical();
            GUILayout.Space(7);

            GUILayout.BeginVertical(HighLogic.Skin.box);
            GUILayout.BeginHorizontal();
            if (GUILayout.Button($"Target Mode: {targetMode.displayName}"))
            {
                targetMode = GetNextTargetMode();
            }
            showTargetModeInfo = GUILayout.Toggle(showTargetModeInfo, "ⓘ", HighLogic.Skin.button, GUILayout.ExpandWidth(false), GUILayout.Height(20));
            GUILayout.EndHorizontal();
            if (showTargetModeInfo)
            {
                GUILayout.Label(targetMode.hint, GUILayout.ExpandWidth(true));
                if (GameDatabase.Instance.GetTexture(targetMode.texture, false) is Texture2D tex)
                {
                    GUILayout.Box(tex, GUILayout.Height(200), GUILayout.Width(200));
                }
            }
            GUILayout.EndVertical();
            GUILayout.Space(7);

            GUILayout.BeginVertical(HighLogic.Skin.box);
            var sortIcon = GetSortIcon(sortMode);

            if (targetMode.mode == TargetMode.Vessel)
            {
                GUILayout.BeginHorizontal();
                foreach (var category in TextureTools.categories)
                {
                    if (TextureTools.textures.ContainsKey(category))
                    {
                        filters[category] = GUILayout.Toggle(filters[category], TextureTools.textures[category], HighLogic.Skin.button, GUILayout.Height(iconSize.y), GUILayout.Width(iconSize.x));
                    }
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label(targetMode.text, GUILayout.ExpandWidth(true));
                HandleSortMode(sortIcon, parentVessel);
                GUILayout.EndHorizontal();

                scrollVesselPos = GUILayout.BeginScrollView(scrollVesselPos, GUILayout.Height(200), GUILayout.ExpandWidth(true));
                foreach (Vessel v in vessels)
                {
                    if (filters.TryGetValue(TextureTools.GetKeyFromVesselType(v.vesselType), out bool show) &&
                        show && GUILayout.Button(v.name))
                    {
                        var x = new ConfigNode(AntennaTarget.nodeName);
                        x.AddValue("name", $"{TargetMode.Vessel}");
                        x.AddValue("vesselId", v.id);
                        antenna.Target = AntennaTarget.LoadFromConfig(x, antenna);
                    }
                }
                GUILayout.EndScrollView();
            }
            if (targetMode.mode == TargetMode.BodyCenter)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(targetMode.text, GUILayout.ExpandWidth(true));
                HandleSortMode(sortIcon);
                GUILayout.EndHorizontal();
                scrollBodyPos = GUILayout.BeginScrollView(scrollBodyPos, GUILayout.Height(200), GUILayout.ExpandWidth(true));
                foreach (CelestialBody body in FlightGlobals.Bodies)
                {
                    if (GUILayout.Button(body.name))
                    {
                        var x = new ConfigNode(AntennaTarget.nodeName);
                        x.AddValue("name", $"{AntennaTarget.TargetMode.BodyLatLonAlt}");
                        x.AddValue("bodyName", body.name);
                        x.AddValue("latLonAlt", new Vector3(0, 0, (float)-body.Radius));
                        antenna.Target = AntennaTarget.LoadFromConfig(x, antenna);
                    }
                }
                GUILayout.EndScrollView();
            }
            if (targetMode.mode == TargetMode.BodyLatLonAlt)
            {
                GUILayout.BeginVertical();
                GUILayout.BeginHorizontal();
                GUILayout.Label("Lat");
                sLat = GUILayout.TextField(sLat, 4);
                GUILayout.Label("Lon");
                sLon = GUILayout.TextField(sLon, 4);
                GUILayout.Label("Alt");
                sAlt = GUILayout.TextField(sAlt, 15);
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                GUILayout.Label(targetMode.text, GUILayout.ExpandWidth(true));
                HandleSortMode(sortIcon);
                GUILayout.EndHorizontal();
                scrollBodyPos = GUILayout.BeginScrollView(scrollBodyPos, GUILayout.Height(200), GUILayout.ExpandWidth(true));
                foreach (CelestialBody body in FlightGlobals.Bodies)
                {
                    if (GUILayout.Button(body.name))
                    {
                        var x = new ConfigNode(AntennaTarget.nodeName);
                        if (float.TryParse(sLat, out float flat) &&
                            float.TryParse(sLon, out float flon) &&
                            float.TryParse(sAlt, out float falt))
                        {
                            x.AddValue("name", $"{AntennaTarget.TargetMode.BodyLatLonAlt}");
                            x.AddValue("bodyName", body.name);
                            x.AddValue("latLonAlt", new Vector3(flat, flon, falt));
                            antenna.Target = AntennaTarget.LoadFromConfig(x, antenna);
                        }
                    }
                }
                GUILayout.EndScrollView();
                GUILayout.EndVertical();
            }
            if (targetMode.mode == TargetMode.AzEl)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Azimuth");
                sAzimuth = GUILayout.TextField(sAzimuth, 4);
                GUILayout.Label("Elevation");
                sElevation = GUILayout.TextField(sElevation, 4);
                GUILayout.EndHorizontal();
                if (GUILayout.Button("Apply"))
                {
                    var x = new ConfigNode(AntennaTarget.nodeName);
                    if (float.TryParse(sAzimuth, out float azimuth) &&
                        float.TryParse(sElevation, out float elevation))
                    {
                        azimuth   = Mathf.Clamp(azimuth, 0, 360);
                        elevation = Mathf.Clamp(elevation, -90, 90);
                        x.AddValue("name", $"{AntennaTarget.TargetMode.AzEl}");
                        x.AddValue("vesselId", parentVessel?.id);
                        x.AddValue("azimuth", azimuth);
                        x.AddValue("elevation", elevation);
                        antenna.Target = AntennaTarget.LoadFromConfig(x, antenna);
                    }
                }
            }
            if (targetMode.mode == TargetMode.OrbitRelative)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Deflection");
                sForward = GUILayout.TextField($"{deflection}", 5);
                GUILayout.Label("Elevation");
                sElevation = GUILayout.TextField(sElevation, 4);
                GUILayout.EndHorizontal();
                float.TryParse(sForward, out deflection);
                deflection = GUILayout.HorizontalSlider(deflection, -180, 180);
                if (GUILayout.Button("Apply"))
                {
                    var x = new ConfigNode(AntennaTarget.nodeName);
                    if (float.TryParse(sElevation, out float elevation))
                    {
                        deflection = Mathf.Clamp(deflection, -360, 360);
                        elevation  = Mathf.Clamp(elevation, -90, 90);
                        x.AddValue("name", $"{AntennaTarget.TargetMode.OrbitRelative}");
                        x.AddValue("vesselId", parentVessel?.id);
                        x.AddValue("forward", deflection);
                        x.AddValue("elevation", elevation);
                        antenna.Target = AntennaTarget.LoadFromConfig(x, antenna);
                    }
                }
            }
            GUILayout.EndVertical();
            GUILayout.Space(15);
            if (GUILayout.Button("Close"))
            {
                Destroy(this);
            }
            GUI.DragWindow();
        }
 public void Start()
 {
     sourceVessels.Clear();
     sourceVessels.AddRange(FlightGlobals.Vessels.Where(v => v.Connection is RACommNetVessel && v.Connection.Comm is RACommNode));
     TextureTools.Setup(filters, true);
 }
Exemplo n.º 4
0
 public void Start()
 {
     vessels.Clear();
     vessels.AddRange(FlightGlobals.Vessels);
     TextureTools.Setup(filters, true);
 }