public override OverlayTooltip TooltipContent(double latitude, double longitude, CelestialBody body) { var height = ScanSatWrapper.GetElevation(body, longitude, latitude); var list = new List <double> { ScanSatWrapper.GetElevation(body, longitude, latitude + _accuracy), ScanSatWrapper.GetElevation(body, longitude, latitude - _accuracy), ScanSatWrapper.GetElevation(body, longitude - _accuracy, latitude), ScanSatWrapper.GetElevation(body, longitude + _accuracy, latitude) }; var slope = list.Select(x => height - x).Max(); ////TODO: switch over //this.Log("lat: " + latitude + " lon: " + longitude + " lat index: " + ArrayLatitudeIndex(latitude) + " long index: " + ArrayLongitudeIndex(longitude)); //var height = _arr[ArrayLatitudeIndex(latitude), ArrayLongitudeIndex(longitude)]; //this.Log("height: " + height); //var list = new List<double> //{ // _arr[ArrayLatitudeIndex(latitude),ArrayLongitudeIndex(longitude+_accuracy)], // _arr[ArrayLatitudeIndex(latitude),ArrayLongitudeIndex(longitude-_accuracy)], // _arr[ArrayLatitudeIndex(latitude+_accuracy),ArrayLongitudeIndex(longitude )], // _arr[ArrayLatitudeIndex(latitude-_accuracy),ArrayLongitudeIndex(longitude)], // _arr[ArrayLatitudeIndex(latitude+0.5*Math.PI*_accuracy),ArrayLongitudeIndex(longitude+0.5*Math.PI*_accuracy)], // _arr[ArrayLatitudeIndex(latitude-0.5*Math.PI*_accuracy),ArrayLongitudeIndex(longitude-0.5*Math.PI*_accuracy)], // _arr[ArrayLatitudeIndex(latitude+0.5*Math.PI*_accuracy),ArrayLongitudeIndex(longitude-0.5*Math.PI*_accuracy)], // _arr[ArrayLatitudeIndex(latitude-0.5*Math.PI*_accuracy),ArrayLongitudeIndex(longitude+0.5*Math.PI*_accuracy)] //}; //var slope = list.Select(x => height - x).Max(); //this.Log("index: " + ArrayIndex(latitude, longitude) +" slope: "+slope+ "height :" + height + " others: " + list.Aggregate("", (x, y) => x + "\n height: " + y)); return(new OverlayTooltip("", new GUIContent(slope.ToString()))); }
public override Color32 CalculateColor32(double latitude, double longitude, CelestialBody body, bool useScansat, bool bright) { var height = ScanSatWrapper.GetElevation(body, longitude, latitude); var list = new List <double> { ScanSatWrapper.GetElevation(body, longitude, latitude + _accuracy), ScanSatWrapper.GetElevation(body, longitude, latitude - _accuracy), ScanSatWrapper.GetElevation(body, longitude - _accuracy, latitude), ScanSatWrapper.GetElevation(body, longitude + _accuracy, latitude) }; var slope = list.Select(x => height - x).Max(); ////TODO: switch over //var height = _arr[ArrayLatitudeIndex(latitude), ArrayLongitudeIndex(longitude)]; //var list = new List<double> //{ // _arr[ArrayLatitudeIndex(latitude),ArrayLongitudeIndex(longitude+_accuracy)], // _arr[ArrayLatitudeIndex(latitude),ArrayLongitudeIndex(longitude-_accuracy)], // _arr[ArrayLatitudeIndex(latitude+_accuracy),ArrayLongitudeIndex(longitude )], // _arr[ArrayLatitudeIndex(latitude-_accuracy),ArrayLongitudeIndex(longitude)], // _arr[ArrayLatitudeIndex(latitude+0.5*Math.PI*_accuracy),ArrayLongitudeIndex(longitude+0.5*Math.PI*_accuracy)], // _arr[ArrayLatitudeIndex(latitude-0.5*Math.PI*_accuracy),ArrayLongitudeIndex(longitude-0.5*Math.PI*_accuracy)], // _arr[ArrayLatitudeIndex(latitude+0.5*Math.PI*_accuracy),ArrayLongitudeIndex(longitude-0.5*Math.PI*_accuracy)], // _arr[ArrayLatitudeIndex(latitude-0.5*Math.PI*_accuracy),ArrayLongitudeIndex(longitude+0.5*Math.PI*_accuracy)] //}; //var slope = list.Select(x => height -x ).Max(); var byteColor = Convert.ToByte(Mathf.Clamp((float)slope * 255 / (float)_max, 0, 255)); return(new Color32(byteColor, byteColor, byteColor, 255)); }
public override void OnAwake() { this.Log("Awaking"); _origTransform = gameObject.transform.parent; var filter = gameObject.AddComponent <MeshFilter>(); if (filter != null) { _mesh = filter.mesh; } else { _mesh = gameObject.GetComponent <MeshFilter>().mesh; } gameObject.AddComponent <MeshRenderer>(); _scanSat = ScanSatWrapper.Instance; base.OnAwake(); if (ToolbarManager.ToolbarAvailable) { _mapOverlayButton = ToolbarManager.Instance.add("MapResourceOverlay", "ResourceOverlay"); _mapOverlayButton.TexturePath = "MapResourceOverlay/Assets/MapOverlayIcon.small"; _mapOverlayButton.ToolTip = "Map Resource Overlay"; _mapOverlayButton.Visibility = new GameScenesVisibility(GameScenes.FLIGHT); _mapOverlayButton.OnClick += e => ToggleGui(); } else { _texture = new Texture2D(38, 38); _texture.LoadImage( System.IO.File.ReadAllBytes(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "/Assets/MapOverlayIcon.enabled.png")); ApplicationLauncher.Instance.AddModApplication(ToggleGui, ToggleGui, null, null, null, null, ApplicationLauncher.AppScenes.FLIGHT | ApplicationLauncher.AppScenes.MAPVIEW, _texture); } _toolTipId = new System.Random().Next(65536) + Assembly.GetExecutingAssembly().GetName().Name.GetHashCode() + "tooltip".GetHashCode(); GameEvents.onHideUI.Add(MakeInvisible); GameEvents.onShowUI.Add(MakeVisible); _overlayProviders = new List <IOverlayProvider>(); _targetBody = MapView.MapCamera.target.GetTargetBody(); }
public override OverlayTooltip TooltipContent(double latitude, double longitude, CelestialBody body) { return(new OverlayTooltip("", new GUIContent("Height: " + ScanSatWrapper.GetElevation(body, longitude, latitude) + "m"))); }
public override Color32 CalculateColor32(double latitude, double longitude, CelestialBody body, bool useScansat, bool bright) { var scanSat = ScanSatWrapper.Instance; if (useScansat && scanSat.Active() && !scanSat.IsCovered(longitude, latitude, body, ActiveResource.Resource)) { return(new Color32(0, 0, 0, 0)); } var avail = _getResourceAvailabilityByRealResourceName(body.flightGlobalsIndex, ActiveResource.Resource.ResourceName, latitude, longitude); var amount = (double)_getAmount(avail) * 1000000; if (amount > ActiveResource.Cutoff) { if (Exponential) { amount = ((Math.Pow(amount, 2) - (Math.Pow(ActiveResource.Cutoff, 2))) * 255) / ((Math.Pow(_displayMax, 2) - (Math.Pow(ActiveResource.Cutoff, 2)))); if (ColoredScale) { var color = ScanSatWrapper.heightToColor((float)amount, 0, 255); color.a = ActiveResource.HighColor.a; return(color); } } else if (Logaritmic) { if (ActiveResource.Cutoff < 1) { ActiveResource.Cutoff = 1; } amount = ((Math.Log(amount, 2) - (Math.Log(ActiveResource.Cutoff, 2))) * 255) / ((Math.Log(_displayMax, 2) - (Math.Log(ActiveResource.Cutoff, 2)))); if (ColoredScale) { var color = ScanSatWrapper.heightToColor((float)amount * 255, 0, 255f); color.a = ActiveResource.HighColor.a; return(color); } } else { if (ColoredScale) { var color = ScanSatWrapper.heightToColor((float)amount, ActiveResource.Cutoff, (float)_displayMax); color.a = ActiveResource.HighColor.a; return(color); } amount = ((amount - ActiveResource.Cutoff) * 255) / (_displayMax - ActiveResource.Cutoff); } amount = Mathf.Clamp((float)amount, 0f, 255f); if (!bright) { var r = amount * (ActiveResource.HighColor.r / 255.0); var g = amount * (ActiveResource.HighColor.g / 255.0); var b = amount * (ActiveResource.HighColor.b / 255.0); return(new Color32(Convert.ToByte(r), Convert.ToByte(g), Convert.ToByte(b), ActiveResource.HighColor.a)); } else { return(new Color32(155, Convert.ToByte(amount), Convert.ToByte(amount), 150)); } } return(ActiveResource.LowColor); }