Skip to content

Commit

Permalink
dev Phase 4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Haruki1707 committed Jan 11, 2022
1 parent c7c753f commit a6b94e1
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 15 deletions.
2 changes: 1 addition & 1 deletion ValorantCC/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion ValorantCC/SubWindow/ProfilesWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
xmlns:local="clr-namespace:ValorantCC"
mc:Ignorable="d"
Title="ProfilesWindow" Height="Auto" Width="Auto" ResizeMode="NoResize" SizeToContent="WidthAndHeight">
<Border Background="#232429" Height="450" Width="350">
<Border Background="#232429" Height="450" Width="350" Loaded="Border_Loaded">
<StackPanel Name="Container" HorizontalAlignment="Center" Margin="0,5">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<TextBox Name="SearchCode" MinWidth="165" MaxWidth="165" Background="#FF393B44" Margin="0,0,5,0" Foreground="White"/>
Expand Down
40 changes: 28 additions & 12 deletions ValorantCC/SubWindow/ProfilesWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,6 +15,8 @@
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Newtonsoft.Json;
using ValorantCC.src;

namespace ValorantCC
{
/// <summary>
Expand All @@ -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();
}

/// <summary>
/// Returns the searched sharecode or the list of shareables depending if sharecode is provided or not.
/// </summary>
/// <param name="sharecode">Nullable. Searched Code</param>
private static void InitialFetch(String sharecode = null)
private static async Task<bool> InitialFetch(String sharecode = null)
{
List<ShareableProfile> Shareables;
if (sharecode != null)
Expand All @@ -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];
Expand All @@ -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;
}

/// <summary>
/// Render the PublicProfiles var into frontend.
/// </summary>
private void RenderProfiles()
private async Task<bool> 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<UIElement> CreateRender(PublicProfile profile)
{
// This will be changed and will be replaced with more efficient method of rendering multiple settings.

Expand Down Expand Up @@ -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;
}
}
Expand Down
110 changes: 109 additions & 1 deletion ValorantCC/src/Crosshair_Parser.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand Down

0 comments on commit a6b94e1

Please # to comment.