diff --git a/EVEData/Character.cs b/EVEData/Character.cs index 05214e64..bd6d2cdc 100644 --- a/EVEData/Character.cs +++ b/EVEData/Character.cs @@ -1,6 +1,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; +using System.Collections.Generic; using System.IO; using System.Net; using System.Text; @@ -15,6 +16,10 @@ public class Character public string ID { get; set; } + public string CorporationID { get; set; } + + public string AllianceID { get; set; } + public string LocalChatFile { get; set; } public string Location { get; set; } @@ -32,11 +37,24 @@ public class Character public override string ToString() { - return Name; + string toStr = Name; + if(ESILinked) + { + toStr += " (ESI)"; + } + return toStr; } + [XmlIgnoreAttribute] + public Dictionary Standings; + + + public Character() { + Standings = new Dictionary(); + CorporationID = string.Empty; + AllianceID = string.Empty; } public void Update() @@ -45,6 +63,7 @@ public void Update() if (ts.Minutes < 0) { RefreshAccessToken(); + UpdateInfoFromESI(); } UpdatePositionFromESI(); @@ -157,6 +176,170 @@ private void UpdatePositionFromESI() catch { } } + public void UpdateInfoFromESI() + { + if (string.IsNullOrEmpty(ID) || !ESILinked) + { + return; + } + + try + { + if (string.IsNullOrEmpty(CorporationID)) + { + string url = @"https://esi.tech.ccp.is/latest/characters/" + ID + "/?datasource=tranquility"; + + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); + request.Method = WebRequestMethods.Http.Get; + request.Timeout = 20000; + request.Proxy = null; + + HttpWebResponse esiResult = (HttpWebResponse)request.GetResponse(); + + if (esiResult.StatusCode != HttpStatusCode.OK) + { + return; + } + + Stream responseStream = esiResult.GetResponseStream(); + using (StreamReader sr = new StreamReader(responseStream)) + { + // Need to return this response + string strContent = sr.ReadToEnd(); + + JsonTextReader jsr = new JsonTextReader(new StringReader(strContent)); + while (jsr.Read()) + { + if (jsr.TokenType == JsonToken.StartObject) + { + JObject obj = JObject.Load(jsr); + string corpID = obj["corporation_id"].ToString(); + CorporationID = corpID; + } + } + } + } + + if (string.IsNullOrEmpty(AllianceID) && !string.IsNullOrEmpty(CorporationID)) + { + string url = @"https://esi.tech.ccp.is/latest/corporations/" + CorporationID + "/?datasource=tranquility"; + + + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); + request.Method = WebRequestMethods.Http.Get; + request.Timeout = 20000; + request.Proxy = null; + + HttpWebResponse esiResult = (HttpWebResponse)request.GetResponse(); + + if (esiResult.StatusCode != HttpStatusCode.OK) + { + return; + } + + Stream responseStream = esiResult.GetResponseStream(); + using (StreamReader sr = new StreamReader(responseStream)) + { + // Need to return this response + string strContent = sr.ReadToEnd(); + + JsonTextReader jsr = new JsonTextReader(new StringReader(strContent)); + while (jsr.Read()) + { + if (jsr.TokenType == JsonToken.StartObject) + { + JObject obj = JObject.Load(jsr); + string allianceID = obj["alliance_id"].ToString(); + AllianceID = allianceID; + } + } + } + } + + + + if (!string.IsNullOrEmpty(AllianceID)) + { + int page = 0; + int maxPageCount = 1; + do + { + page++; + // + + //string url = @"https://esi.tech.ccp.is/latest/alliances/" + AllianceID + "/contacts/?datasource=tranquility&page=" + page; + + UriBuilder urlBuilder = new UriBuilder(@"https://esi.tech.ccp.is/latest/alliances/" + AllianceID + "/contacts/"); + var esiQuery = HttpUtility.ParseQueryString(urlBuilder.Query); + esiQuery["page"] = page.ToString(); + esiQuery["datasource"] = "tranquility"; + esiQuery["token"] = ESIAccessToken; + + + urlBuilder.Query = esiQuery.ToString(); + + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlBuilder.ToString()); + request.Method = WebRequestMethods.Http.Get; + request.ContentType = "application/json"; + request.Timeout = 20000; + request.Proxy = null; + + try + { + HttpWebResponse esiResult = (HttpWebResponse)request.GetResponse(); + maxPageCount = int.Parse(esiResult.Headers["X-Pages"].ToString()); + + + if (esiResult.StatusCode != HttpStatusCode.OK) + { + return; + } + + Stream responseStream = esiResult.GetResponseStream(); + using (StreamReader sr = new StreamReader(responseStream)) + { + // Need to return this response + string strContent = sr.ReadToEnd(); + + JsonTextReader jsr = new JsonTextReader(new StringReader(strContent)); + while (jsr.Read()) + { + if (jsr.TokenType == JsonToken.StartObject) + { + JObject obj = JObject.Load(jsr); + string contactID = obj["contact_id"].ToString(); + string contactType = obj["contact_type"].ToString(); + float standing = float.Parse(obj["standing"].ToString()); + + Standings[contactID] = standing; + } + } + } + } + catch (Exception ex) + { + + } + + + + } while (page < maxPageCount); + + + + + } + + if (!string.IsNullOrEmpty(AllianceID) && !string.IsNullOrEmpty(CorporationID)) + { + + } + } + catch (Exception ex) + { + + } + } public void AddDestination(string SystemID, bool Clear) { @@ -217,6 +400,8 @@ public Character(string name, string lcf, string location) ESIAuthCode = string.Empty; ESIAccessToken = string.Empty; ESIRefreshToken = string.Empty; + + Standings = new Dictionary(); } } } \ No newline at end of file diff --git a/EVEData/EveManager.cs b/EVEData/EveManager.cs index 2d573f03..e1f31928 100644 --- a/EVEData/EveManager.cs +++ b/EVEData/EveManager.cs @@ -1028,7 +1028,7 @@ public string GetESILogonURL() esiQuery["response_type"] = "code"; esiQuery["client_id"] = EveAppConfig.CLIENT_ID; esiQuery["redirect_uri"] = EveAppConfig.CALLBACK_URL; - esiQuery["scope"] = "publicData esi-location.read_location.v1 esi-ui.write_waypoint.v1 esi-characters.read_standings.v1 esi-location.read_online.v1"; + esiQuery["scope"] = "publicData esi-location.read_location.v1 esi-ui.write_waypoint.v1 esi-characters.read_standings.v1 esi-location.read_online.v1 esi-alliances.read_contacts.v1"; esiQuery["state"] = Process.GetCurrentProcess().Id.ToString(); @@ -1343,7 +1343,7 @@ public void StartUpdateCharacterThread() c.Update(); } } - Thread.Sleep(5000); + Thread.Sleep(8000); } }).Start(); } diff --git a/MainWindow.xaml b/MainWindow.xaml index af00c7e8..573bb708 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -72,7 +72,7 @@ - + diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index f51ec729..7a21d2e1 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -59,8 +59,6 @@ public MainWindow() DynamicMapElements = new List(); - - // load any custom map settings off disk string mapConfigFileName = AppDomain.CurrentDomain.BaseDirectory + @"\MapConfig.dat"; OutputLog.Info("Loading Map config from {0}", mapConfigFileName); @@ -516,6 +514,7 @@ private struct GateHelper private void AddSystemsToMap() { EVEData.MapRegion rd = RegionDropDown.SelectedItem as EVEData.MapRegion; + EVEData.Character c = CharacterDropDown.SelectedItem as EVEData.Character; if (MapConf.ShowJumpBridges || MapConf.ShowHostileJumpBridges) { @@ -576,16 +575,16 @@ private void AddSystemsToMap() path.StrokeDashArray = dashes; - // animate the jump bridges + // animate the jump bridges DoubleAnimation da = new DoubleAnimation(); - da.From = 0; - da.To = 200; - da.By = 2; - da.Duration = new Duration(TimeSpan.FromSeconds(40)); - da.RepeatBehavior = RepeatBehavior.Forever; - - path.StrokeDashArray = dashes; - path.BeginAnimation(Shape.StrokeDashOffsetProperty, da); + da.From = 0; + da.To = 200; + da.By = 2; + da.Duration = new Duration(TimeSpan.FromSeconds(40)); + da.RepeatBehavior = RepeatBehavior.Forever; + + path.StrokeDashArray = dashes; + path.BeginAnimation(Shape.StrokeDashOffsetProperty, da); @@ -610,7 +609,12 @@ private void AddSystemsToMap() Brush JumpInRange = new SolidColorBrush(MapConf.ActiveColourScheme.JumpRangeInColour); Brush JumpOutRange = new SolidColorBrush(MapConf.ActiveColourScheme.JumpRangeOutColour); - + + Brush StandingVBad = new SolidColorBrush(Color.FromRgb(148, 5, 5)); + Brush StandingBad = new SolidColorBrush(Color.FromRgb(196, 72, 6)); + Brush StandingNeut = new SolidColorBrush(Color.FromRgb(140, 140, 140)); + Brush StandingGood = new SolidColorBrush(Color.FromRgb(43, 101, 196)); + Brush StandingVGood = new SolidColorBrush(Color.FromRgb(5, 34, 120)); foreach (EVEData.MapSystem sys in rd.MapSystems.Values.ToList()) { @@ -653,6 +657,53 @@ private void AddSystemsToMap() } + /* + // override with sec status colours + if (MapConf.ShowSystemSovStanding && c!=null && c.ESILinked) + { + float Standing = 0.0f; + + if(c.AllianceID != null && c.AllianceID == sys.ActualSystem.SOVAlliance) + { + Standing = 10.0f; + } + + if(sys.ActualSystem.SOVCorp != null && c.Standings.Keys.Contains(sys.ActualSystem.SOVCorp)) + { + Standing = c.Standings[sys.ActualSystem.SOVCorp]; + } + + if (sys.ActualSystem.SOVAlliance != null && c.Standings.Keys.Contains(sys.ActualSystem.SOVAlliance)) + { + Standing = c.Standings[sys.ActualSystem.SOVAlliance]; + } + + systemShape.Fill = StandingNeut; + + if (Standing == -10.0) + { + systemShape.Fill = StandingVBad; + } + + if (Standing == -5.0) + { + systemShape.Fill = StandingBad; + } + + if (Standing == 5.0) + { + systemShape.Fill = StandingGood; + } + + if (Standing == 10.0) + { + systemShape.Fill = StandingVGood; + } + } + */ + + + systemShape.DataContext = sys; systemShape.MouseDown += ShapeMouseDownHandler; systemShape.MouseEnter += ShapeMouseOverHandler; @@ -867,8 +918,15 @@ private void AddSystemsToMap() private void AddDataToMap() { EVEData.MapRegion rd = RegionDropDown.SelectedItem as EVEData.MapRegion; + EVEData.Character c = CharacterDropDown.SelectedItem as EVEData.Character; + + + Brush StandingVBad = new SolidColorBrush(Color.FromArgb(100,148, 5, 5)); + Brush StandingBad = new SolidColorBrush(Color.FromArgb(100,196, 72, 6)); + Brush StandingNeut = new SolidColorBrush(Color.FromArgb(100, 140, 140, 140)); + Brush StandingGood = new SolidColorBrush(Color.FromArgb(100, 43, 101, 196)); + Brush StandingVGood = new SolidColorBrush(Color.FromArgb(100, 5, 34, 120)); - Dictionary> mergedOverlay = new Dictionary>(); foreach (EVEData.MapSystem sys in rd.MapSystems.Values.ToList()) { @@ -919,7 +977,7 @@ private void AddDataToMap() - if (MapConf.ColourBySov && sys.ActualSystem.SOVAlliance != null) + if ((MapConf.ColourBySov || MapConf.ShowSystemSovStanding) && sys.ActualSystem.SOVAlliance != null) { Polygon poly = new Polygon(); @@ -928,94 +986,82 @@ private void AddDataToMap() poly.Points.Add(p); } - Color c = stringToColour(sys.ActualSystem.SOVAlliance); - //c.A = 75; - poly.Fill = new SolidColorBrush(c); - poly.SnapsToDevicePixels = true; - poly.Stroke = poly.Fill; - poly.StrokeThickness = 0.5; - poly.StrokeDashCap = PenLineCap.Round; - poly.StrokeLineJoin = PenLineJoin.Round; - - - //MainCanvas.Children.Add(poly); + bool addToMap = true; + Brush br = new SolidColorBrush(stringToColour(sys.ActualSystem.SOVAlliance)); - // save the dynamic map elements - //DynamicMapElements.Add(poly); - - if (!mergedOverlay.Keys.Contains(sys.ActualSystem.SOVAlliance)) + if(MapConf.ShowSystemSovStanding) { - mergedOverlay[sys.ActualSystem.SOVAlliance] = new List(); - } - - mergedOverlay[sys.ActualSystem.SOVAlliance].Add(poly); + if(c != null && c.ESILinked) + { + float Standing = 0.0f; - } + if (c.AllianceID != null && c.AllianceID == sys.ActualSystem.SOVAlliance) + { + Standing = 10.0f; + } - } + if (sys.ActualSystem.SOVCorp != null && c.Standings.Keys.Contains(sys.ActualSystem.SOVCorp)) + { + Standing = c.Standings[sys.ActualSystem.SOVCorp]; + } + if (sys.ActualSystem.SOVAlliance != null && c.Standings.Keys.Contains(sys.ActualSystem.SOVAlliance)) + { + Standing = c.Standings[sys.ActualSystem.SOVAlliance]; + } - if(MapConf.ColourBySov) - { - List mergedGeom = new List(); - foreach (List pl in mergedOverlay.Values) - { - CombinedGeometry c = new CombinedGeometry(); - // quick and dirty recursive geometry combine + if (Standing == 0.0f) + { + addToMap = false; + } - if (pl.Count >= 2) - { - Rect r = new Rect(MainCanvas.RenderSize); - foreach (Polygon pg in pl) - { - pg.Measure(MainCanvas.RenderSize); - pg.Arrange(r); + br = StandingNeut; - if (c.Geometry1 == null) + if (Standing == -10.0) { - c.Geometry1 = pg.RenderedGeometry; + br = StandingVBad; + } - continue; + if (Standing == -5.0) + { + br = StandingBad; } - c.Geometry2 = pg.RenderedGeometry; - c.GeometryCombineMode = GeometryCombineMode.Union; + if (Standing == 5.0) + { + br = StandingGood; + } - CombinedGeometry temp = c; - c = new CombinedGeometry(); - c.Geometry1 = temp; + if (Standing == 10.0) + { + br = StandingVGood; + } + } + else + { + // enabled but not linked + addToMap = false; } - - System.Windows.Shapes.Path p = new System.Windows.Shapes.Path(); - p.Data = c; - p.Stroke = System.Windows.Media.Brushes.Black; - p.StrokeThickness = 1; - p.Fill = pl[0].Fill; - p.SnapsToDevicePixels = true; - mergedGeom.Add(p); - } - else - { - pl[0].Stroke = System.Windows.Media.Brushes.Black; - pl[0].StrokeThickness = 1; - - mergedGeom.Add(pl[0]); - } - } + poly.Fill = br; + poly.SnapsToDevicePixels = true; + poly.Stroke = poly.Fill; + poly.StrokeThickness = 0.5; + poly.StrokeDashCap = PenLineCap.Round; + poly.StrokeLineJoin = PenLineJoin.Round; - foreach(Shape poly in mergedGeom) - { - MainCanvas.Children.Add(poly); + if(addToMap) + { + MainCanvas.Children.Add(poly); - // save the dynamic map elements - DynamicMapElements.Add(poly); + // save the dynamic map elements + DynamicMapElements.Add(poly); + } } - } } @@ -1331,7 +1377,6 @@ public Color stringToColour(string str) { int hash = 0; - foreach (char c in str.ToCharArray()) { hash = c + ((hash << 5) - hash); @@ -1340,11 +1385,8 @@ public Color stringToColour(string str) double R = (((byte) (hash & 0xff) / 255.0) * 80.0 ) + 127.0 ; double G = (((byte) ((hash >> 8) & 0xff) / 255.0 ) * 80.0 ) + 127.0; double B = (((byte) ((hash >> 16) & 0xff) / 255.0)* 80.0) + 127.0; - - - - return Color.FromRgb((byte)R, (byte)G, (byte)B); - + + return Color.FromArgb(100,(byte)R, (byte)G, (byte)B); } private void RawIntelBox_MouseDoubleClick(object sender, MouseButtonEventArgs e) diff --git a/MapConfig.cs b/MapConfig.cs index 0bdc9402..9b8f1b67 100644 --- a/MapConfig.cs +++ b/MapConfig.cs @@ -31,6 +31,16 @@ protected void OnPropertyChanged(string name) } private bool m_ColourBySov; + + private bool m_ShowJumpBridges; + private bool m_ShowHostileJumpBridges; + + private bool m_ShowSystemSovTicker; + private bool m_ShowSystemSovName; + + private bool m_ShowSystemSecurity; + private bool m_ShowSystemSovStanding; + private bool m_ShowNPCKills; private bool m_ShowPodKills; private bool m_ShowShipKills; @@ -39,6 +49,8 @@ protected void OnPropertyChanged(string name) private string m_DefaultRegion; private double m_ESIOverlayScale; + + [Browsable(false)] public string DefaultRegion { @@ -64,11 +76,35 @@ public string DefaultRegion [Category("Jump Bridges")] [DisplayName("Friendly Bridges")] - public bool ShowJumpBridges { get; set; } + public bool ShowJumpBridges + { + get + { + return m_ShowJumpBridges; + } + set + { + m_ShowJumpBridges = value; + + OnPropertyChanged("ShowJumpBridges"); + } + } [Category("Jump Bridges")] [DisplayName("Hostile Bridges")] - public bool ShowHostileJumpBridges { get; set; } + public bool ShowHostileJumpBridges + { + get + { + return m_ShowHostileJumpBridges; + } + set + { + m_ShowHostileJumpBridges = value; + + OnPropertyChanged("ShowHostileJumpBridges"); + } + } [Category("General")] [DisplayName("System Popup")] @@ -76,17 +112,79 @@ public string DefaultRegion [Category("General")] [DisplayName("Show Security")] - public bool ShowSystemSecurity { get; set; } + public bool ShowSystemSecurity + { + get + { + return m_ShowSystemSecurity; + } + set + { + m_ShowSystemSecurity = value; + + if (m_ShowSystemSecurity) + { + ShowSystemSovStanding = false; + } + + OnPropertyChanged("ShowSystemSecurity"); + } + } [Category("General")] - [DisplayName("Show SOV Ticker")] + [DisplayName("Show SOV Standing")] + public bool ShowSystemSovStanding + { + get + { + return m_ShowSystemSovStanding; + } + set + { + m_ShowSystemSovStanding = value; + + if (m_ShowSystemSovStanding) + { + ShowSystemSecurity = false; + } + + OnPropertyChanged("ShowSystemSovStanding"); + } + } + - public bool ShowSystemSovTicker { get; set; } + + [Category("General")] + [DisplayName("Show SOV Ticker")] + public bool ShowSystemSovTicker + { + get + { + return m_ShowSystemSovTicker; + } + set + { + m_ShowSystemSovTicker = value; + OnPropertyChanged("ShowSystemSovTicker"); + } + } [Category("General")] [DisplayName("Show SOV Name")] + public bool ShowSystemSovName + { + get + { + return m_ShowSystemSovName; + } + set + { + m_ShowSystemSovName = value; + OnPropertyChanged("ShowSystemSovName"); + } + } + - public bool ShowSystemSovName { get; set; } [Category("Navigation")]