From a6b94e1be7c7a324213db293f109857e6c374b20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20G=C3=B3mez?= <72423267+Haruki1707@users.noreply.github.com> Date: Mon, 10 Jan 2022 21:56:38 -0600 Subject: [PATCH] dev Phase 4.5 --- ValorantCC/MainWindow.xaml.cs | 2 +- ValorantCC/SubWindow/ProfilesWindow.xaml | 2 +- ValorantCC/SubWindow/ProfilesWindow.xaml.cs | 40 ++++--- ValorantCC/src/Crosshair_Parser.cs | 110 +++++++++++++++++++- 4 files changed, 139 insertions(+), 15 deletions(-) diff --git a/ValorantCC/MainWindow.xaml.cs b/ValorantCC/MainWindow.xaml.cs index c3017bd..e4a8d21 100644 --- a/ValorantCC/MainWindow.xaml.cs +++ b/ValorantCC/MainWindow.xaml.cs @@ -124,7 +124,7 @@ private void profiles_SelectionChanged(object sender, SelectionChangedEventArgs sniper_dot_color.SelectedColor = Color.FromRgb(SelectedProfile.Sniper.CenterDotColor.R, SelectedProfile.Sniper.CenterDotColor.G, SelectedProfile.Sniper.CenterDotColor.B); if (ValCCAPI != null) ValCCAPI.profile = SelectedProfile; - if (ValCCAPI != null && chkbxShareable.IsChecked) ValCCAPI.Set(); + if (ValCCAPI != null && (chkbxShareable.IsChecked ?? false)) ValCCAPI.Set(); Crosshair_load(); } private void StackPanel_MouseDown(object sender, MouseButtonEventArgs e) diff --git a/ValorantCC/SubWindow/ProfilesWindow.xaml b/ValorantCC/SubWindow/ProfilesWindow.xaml index 3b036e3..b0881b3 100644 --- a/ValorantCC/SubWindow/ProfilesWindow.xaml +++ b/ValorantCC/SubWindow/ProfilesWindow.xaml @@ -6,7 +6,7 @@ xmlns:local="clr-namespace:ValorantCC" mc:Ignorable="d" Title="ProfilesWindow" Height="Auto" Width="Auto" ResizeMode="NoResize" SizeToContent="WidthAndHeight"> - + diff --git a/ValorantCC/SubWindow/ProfilesWindow.xaml.cs b/ValorantCC/SubWindow/ProfilesWindow.xaml.cs index 960e3d0..b1eca3c 100644 --- a/ValorantCC/SubWindow/ProfilesWindow.xaml.cs +++ b/ValorantCC/SubWindow/ProfilesWindow.xaml.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Text.RegularExpressions; +using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; @@ -14,6 +15,8 @@ using System.Windows.Media.Imaging; using System.Windows.Shapes; using Newtonsoft.Json; +using ValorantCC.src; + namespace ValorantCC { /// @@ -39,15 +42,19 @@ public ProfilesWindow(CrosshairProfile current, API ValCCAPI) main = (MainWindow) Application.Current.MainWindow; ValCCApi = ValCCAPI; bc = new BrushConverter(); - InitialFetch(); - RenderProfiles(); + } + + private async void Border_Loaded(object sender, RoutedEventArgs e) + { + await InitialFetch(); + await RenderProfiles(); } /// /// Returns the searched sharecode or the list of shareables depending if sharecode is provided or not. /// /// Nullable. Searched Code - private static void InitialFetch(String sharecode = null) + private static async Task InitialFetch(String sharecode = null) { List Shareables; if (sharecode != null) @@ -57,7 +64,7 @@ private static void InitialFetch(String sharecode = null) } else Shareables = ValCCApi.Fetch().data; - if (Shareables.Count == 0) return; + if (Shareables.Count == 0) return true; for (int i = 0; i < Shareables.Count; i++) { ShareableProfile currentShareable = Shareables[i]; @@ -72,31 +79,36 @@ private static void InitialFetch(String sharecode = null) } PublicProfiles.Add(new PublicProfile() { owner = currentShareable.displayName, settings = profile }); } + + //Change this delay for the async backend + await Task.Delay(1); + return true; } /// /// Render the PublicProfiles var into frontend. /// - private void RenderProfiles() + private async Task RenderProfiles() { UIElementCollection shareablesElement = ShareablesContainer.Children; - if (PublicProfiles.Count == 0) return; + if (PublicProfiles.Count == 0) return true; for (int i = 0; i < PublicProfiles.Count; i++) { PublicProfile profile = PublicProfiles[i]; - shareablesElement.Add(CreateRender(profile)); + shareablesElement.Add(await CreateRender(profile)); } - + await Task.Delay(1); + return true; } - private void btnSearchCode_Click(object sender, RoutedEventArgs e) + private async void btnSearchCode_Click(object sender, RoutedEventArgs e) { if (SearchCode.Text == null || SearchCode.Text == "") return; - InitialFetch(SearchCode.Text); - RenderProfiles(); + await InitialFetch(SearchCode.Text); + await RenderProfiles(); } - private UIElement CreateRender(PublicProfile profile) + private async Task CreateRender(PublicProfile profile) { // This will be changed and will be replaced with more efficient method of rendering multiple settings. @@ -194,7 +206,11 @@ private UIElement CreateRender(PublicProfile profile) Grid0.Children.Add(shareButton); Grid0.Children.Add(detailsButton); Grid0.Children.Add(applyButton); + + Crosshair_Parser.Generate(0, Grid0, profile.settings.Primary); + template.Child = Grid0; + await Task.Delay(1); return template; } } diff --git a/ValorantCC/src/Crosshair_Parser.cs b/ValorantCC/src/Crosshair_Parser.cs index 1ca249c..53f9bfb 100644 --- a/ValorantCC/src/Crosshair_Parser.cs +++ b/ValorantCC/src/Crosshair_Parser.cs @@ -1,4 +1,7 @@ -using System.Windows; +using System.Diagnostics; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media; using System.Windows.Shapes; namespace ValorantCC.src @@ -13,6 +16,111 @@ public enum Position East = 3, } + public static void Generate(int column, Grid grid, ProfileSettings settings) + { + Rectangle[] rectangles = new Rectangle[16]; + int recindex = 0; + /*for (int i = 1; i <= 4; i++) + { + string name = $"prime{}"; + switch (i) + { + case 0: + name += "X"; + break; + case 1: + name += "Y"; + break; + case 2: + name += "OLX"; + break; + case 3: + name += "OLY"; + break; + } + + for (int j = 1; j <= 4; j++) + { + string subname = name; + if (j % 2 != 0) + subname += "OT"; + + Rectangle rectangle = new Rectangle() + { + Name = subname, + Width = 3, + Height = 3 + }; + rectangles[recindex] = rectangle; + recindex++; + } + }*/ + + for (int i = 0; i < rectangles.Length; i++) + { + Rectangle rectangle = new Rectangle() + { + Width = 3, + Height = 3 + }; + rectangles[recindex] = rectangle; + recindex++; + } + + recindex = 1; + for (int i = 0; i < rectangles.Length; i+=2) + { + var pos = Position.East; + switch (recindex % 4) + { + case 1: + pos = Position.East; + break; + case 2: + pos = Position.West; + break; + case 3: + pos = Position.North; + break; + case 0: + pos = Position.South; + break; + } + recindex++; + if(recindex == 4) + recindex = 0; + + rectangle_redraw(rectangles[i], rectangles[i + 1], pos, settings); + rectangles[i].Fill = new SolidColorBrush(Color.FromRgb(settings.Color.R, settings.Color.G, settings.Color.B)); + rectangles[i + 1].Stroke = new SolidColorBrush(Color.FromRgb(settings.OutlineColor.R, settings.OutlineColor.G, settings.OutlineColor.B)); + Grid.SetColumn(rectangles[i], column); + Grid.SetRow(rectangles[i], 0); + Grid.SetColumn(rectangles[i + 1], column); + Grid.SetRow(rectangles[i + 1], 0); + + grid.Children.Add(rectangles[i]); + grid.Children.Add(rectangles[i + 1]); + } + + Rectangle dot = new Rectangle() + { + Margin = new Thickness(0, 0, 0, 0) + }; + Rectangle dotOT = new Rectangle() + { + Margin = new Thickness(0, 0, 0, 0) + }; + + dot_redraw(dot, dotOT, settings); + Grid.SetColumn(dot, column); + Grid.SetRow(dot, 0); + Grid.SetColumn(dotOT, column); + Grid.SetColumn(dotOT, 0); + + grid.Children.Add(dot); + grid.Children.Add(dotOT); + } + public static void dot_redraw(Rectangle Rect, Rectangle RectOT, ProfileSettings settings) { Rect.Width = Rect.Height = settings.CenterDotSize;