Skip to content

Commit

Permalink
Render code improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
Haruki1707 committed Feb 4, 2022
1 parent b95e751 commit 5d3023c
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 118 deletions.
11 changes: 5 additions & 6 deletions ValorantCC/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
Background="Transparent"
RenderOptions.BitmapScalingMode="Fant">
<Window.Resources>
<BitmapImage x:Key="crosshairBG0" UriSource="Resources/CrosshairBG0.png"/>
<BitmapImage x:Key="crosshairBG1" UriSource="Resources/CrosshairBG1.png"/>
<BitmapImage x:Key="crosshairBG2" UriSource="Resources/CrosshairBG2.png"/>
<BitmapImage x:Key="crosshairBG3" UriSource="Resources/CrosshairBG3.png"/>
<BitmapImage x:Key="crosshairBG4" UriSource="Resources/CrosshairBG4.png"/>
<BitmapImage x:Key="crosshairBG5" UriSource="Resources/CrosshairBG5.png"/>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/BGdictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Border Background="#232429"
CornerRadius="7">
Expand Down
14 changes: 6 additions & 8 deletions ValorantCC/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Linq;
using System.Windows.Shapes;
using Utilities;
using ValorantCC.src;
using System.Threading;
using System.Threading.Tasks;

namespace ValorantCC
{
Expand Down Expand Up @@ -102,7 +99,7 @@ private void profiles_SelectionChanged(object sender, SelectionChangedEventArgs
}
prim_outline_color.SelectedColor = Color.FromRgb(SelectedProfile.Primary.OutlineColor.R, SelectedProfile.Primary.OutlineColor.G, SelectedProfile.Primary.OutlineColor.B);
if (SelectedProfile.aDS == null) SelectedProfile.aDS = SelectedProfile.Primary;
if(SelectedProfile.bUsePrimaryCrosshairForADS) SelectedProfile.aDS.Color = SelectedProfile.Primary.Color;
if (SelectedProfile.bUsePrimaryCrosshairForADS) SelectedProfile.aDS.Color = SelectedProfile.Primary.Color;
ads_color.SelectedColor = Color.FromRgb(SelectedProfile.aDS.Color.R, SelectedProfile.aDS.Color.G, SelectedProfile.aDS.Color.B);
ads_outline_color.SelectedColor = Color.FromRgb(SelectedProfile.aDS.OutlineColor.R, SelectedProfile.aDS.OutlineColor.G, SelectedProfile.aDS.OutlineColor.B);
sniper_dot_color.SelectedColor = Color.FromRgb(SelectedProfile.Sniper.CenterDotColor.R, SelectedProfile.Sniper.CenterDotColor.G, SelectedProfile.Sniper.CenterDotColor.B);
Expand Down Expand Up @@ -285,10 +282,10 @@ private ImageSource Get_CrosshairBG(bool next = true)
{
int number = int.Parse(System.IO.Path.GetFileNameWithoutExtension(CrosshairBG.Source.ToString()).Replace("CrosshairBG", "")) + (next ? 1 : -1);

if (next && number > Resources.Count - 1)
if (next && number > Resources.MergedDictionaries[0].Count - 1)
number = 0;
else if (number < 0)
number = Resources.Count - 1;
number = Resources.MergedDictionaries[0].Count - 1;

return (ImageSource)FindResource("crosshairBG" + number);
}
Expand All @@ -304,7 +301,8 @@ private void btnCommunityProfiles_Click(object sender, RoutedEventArgs e)
{
Window publicProfiles = Application.Current.Windows.Cast<Window>().Single(window => window.GetType().ToString() == "ValorantCC.ProfilesWindow");
publicProfiles.Activate();
}catch(Exception ex)
}
catch (Exception ex)
{
ProfilesWindow publicProfiles = new ProfilesWindow(SelectedProfile, ValCCAPI);
publicProfiles.Owner = this;
Expand Down
9 changes: 9 additions & 0 deletions ValorantCC/Resources/BGdictionary.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<BitmapImage x:Key="crosshairBG0" UriSource="/Resources/CrosshairBG0.png"/>
<BitmapImage x:Key="crosshairBG1" UriSource="/Resources/CrosshairBG1.png"/>
<BitmapImage x:Key="crosshairBG2" UriSource="/Resources/CrosshairBG2.png"/>
<BitmapImage x:Key="crosshairBG3" UriSource="/Resources/CrosshairBG3.png"/>
<BitmapImage x:Key="crosshairBG4" UriSource="/Resources/CrosshairBG4.png"/>
<BitmapImage x:Key="crosshairBG5" UriSource="/Resources/CrosshairBG5.png"/>
</ResourceDictionary>
23 changes: 7 additions & 16 deletions ValorantCC/SubWindow/ProfilesWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
using System;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Newtonsoft.Json;
using ValorantCC.src;

namespace ValorantCC
{
/// <summary>
/// Interaction logic for ProfilesWindow.xaml
/// </summary>

public struct PublicProfile
{
public String owner { get; set; }
Expand All @@ -41,7 +32,7 @@ public partial class ProfilesWindow : Window
public ProfilesWindow(CrosshairProfile current, API ValCCAPI)
{
InitializeComponent();
main = (MainWindow) Application.Current.MainWindow;
main = (MainWindow)Application.Current.MainWindow;
selected = current;
ValCCApi = ValCCAPI;
bc = new BrushConverter();
Expand Down Expand Up @@ -103,11 +94,11 @@ private async Task<bool> RenderProfiles()
{
UIElementCollection shareablesElement = ShareablesContainer.Children;
if (PublicProfiles.Count == 0) return true;

for (int i = 0; i < PublicProfiles.Count; i++)
{
PublicProfile profile = PublicProfiles[i];
shareablesElement.Add(await CreateRender.GenerateRender(profile, this));
shareablesElement.Add(await this.GenerateRender(profile));
}
await Task.Delay(1);
return true;
Expand Down Expand Up @@ -157,7 +148,7 @@ public void applyBtnClicked(object sender, RoutedEventArgs e)

private void ExitClick(object sender, RoutedEventArgs e)
{
Close();
Close();
}
private void MinimizeClick(object sender, RoutedEventArgs e)
{
Expand Down
125 changes: 59 additions & 66 deletions ValorantCC/SubWindow/src/CreateRender.cs
Original file line number Diff line number Diff line change
@@ -1,47 +1,45 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ValorantCC.src;

namespace ValorantCC
{
public class CreateRender
public static class CreateRender
{
public static async Task<UIElement> GenerateRender(PublicProfile profile, ProfilesWindow profilesWindow)
enum ButtonType
{
Share,
Details,
Apply
}

static Style style;
static Random rand = new Random();
static BrushConverter bc = new BrushConverter();
static List<ImageBrush> imageSources = new List<ImageBrush>();
static ImageBrush RandomBG => imageSources[rand.Next(0, imageSources.Count - 1)];

static CreateRender()
{
ResourceDictionary res = (ResourceDictionary)Application.LoadComponent(new Uri("Resources/BGdictionary.xaml", UriKind.Relative));
for (int i = 0; i < res.Count; i++)
imageSources.Add(new ImageBrush((ImageSource)res["crosshairBG" + i]));
}

public static async Task<UIElement> GenerateRender(this ProfilesWindow profilesWindow, PublicProfile profile)
{
// This will be changed and will be replaced with more efficient method of rendering multiple settings.

// These first 2 vars can be put somewhere else but I didn't because lazy.
List<ImageSource> imageSources = new List<ImageSource>()
{
new BitmapImage(new Uri("pack://application:,,,/ValorantCC;component/Resources/CrosshairBG0.png")),
new BitmapImage(new Uri("pack://application:,,,/ValorantCC;component/Resources/CrosshairBG1.png")),
new BitmapImage(new Uri("pack://application:,,,/ValorantCC;component/Resources/CrosshairBG2.png")),
new BitmapImage(new Uri("pack://application:,,,/ValorantCC;component/Resources/CrosshairBG3.png")),
new BitmapImage(new Uri("pack://application:,,,/ValorantCC;component/Resources/CrosshairBG4.png")),
new BitmapImage(new Uri("pack://application:,,,/ValorantCC;component/Resources/CrosshairBG5.png"))
};
Random rand = new Random();
// Main border
ImageBrush image = new ImageBrush();
image.ImageSource = imageSources[rand.Next(0, 5)];
BrushConverter bc = new BrushConverter();
Border template = new Border()
{
Background = image,
Background = RandomBG,
CornerRadius = new CornerRadius(7, 7, 25, 25),
MinHeight = 95,
MaxHeight = 95,
Expand Down Expand Up @@ -84,53 +82,16 @@ public static async Task<UIElement> GenerateRender(PublicProfile profile, Profil
};
Grid.SetColumn(ownerName, 2);
Grid.SetRow(ownerName, 0);


int buttonFont = 11;
int buttonHeight = 22;
string buttonColor = "#4648BF";
style = (Style)profilesWindow.FindResource("RoundButton");

Button shareButton = new Button()
{
Style = (Style)profilesWindow.FindResource("RoundButton"),
Background = (Brush)bc.ConvertFromString(buttonColor),
Margin = new Thickness() { Bottom = 0, Top = 0, Left = 5, Right = 5 },
Height = buttonHeight,
FontSize = buttonFont,
FontWeight = FontWeights.Bold,
Content = "Share",
Cursor = Cursors.Hand,
Name = "A_"+profile.sharecode+"_shareBtn",
};
Button shareButton = ButtonType.Share.Generate(profile.sharecode);
shareButton.Click += profilesWindow.shareBtnClicked;

Button detailsButton = new Button()
{
Style = (Style)profilesWindow.FindResource("RoundButton"),
Background = (Brush)bc.ConvertFromString(buttonColor),
Margin = new Thickness() { Bottom = 0, Top = 0, Left = 5, Right = 5 },
FontSize = buttonFont,
Height = buttonHeight,
FontWeight = FontWeights.Bold,
Content = "Details",
Cursor = Cursors.Hand,
Name = "A_" + profile.ID.ToString() + "_detailsBtn"

};
Button detailsButton = ButtonType.Details.Generate(profile.ID.ToString());
detailsButton.Click += profilesWindow.detailsBtnClicked;

Button applyButton = new Button()
{
Style = (Style)profilesWindow.FindResource("RoundButton"),
Background = (Brush)bc.ConvertFromString(buttonColor),
Margin = new Thickness() { Bottom = 0, Top = 0, Left = 5, Right = 5 },
FontSize = buttonFont,
Height = buttonHeight,
FontWeight = FontWeights.Bold,
Content = "Apply",
Cursor = Cursors.Hand,
Name = "A_" + profile.ID.ToString() + "_applyBtn"
};
Button applyButton = ButtonType.Apply.Generate(profile.ID.ToString());
applyButton.Click += profilesWindow.applyBtnClicked;

Grid.SetColumn(shareButton, 0);
Expand All @@ -155,5 +116,37 @@ public static async Task<UIElement> GenerateRender(PublicProfile profile, Profil
await Task.Delay(1);
return template;
}

private static Button Generate(this ButtonType btntype, string namedata)
{
Button button = new Button()
{
Style = style,
Background = (Brush)bc.ConvertFromString("#4648BF"),
Margin = new Thickness() { Bottom = 0, Top = 2, Left = 5, Right = 5 },
FontSize = 11,
Height = 22,
FontWeight = FontWeights.Bold,
Cursor = Cursors.Hand,
};

switch (btntype)
{
case ButtonType.Share:
button.Content = "Share";
button.Name = $"A_{namedata}_shareBtn";
break;
case ButtonType.Details:
button.Content = "Details";
button.Name = $"A_{namedata}_detailsBtn";
break;
case ButtonType.Apply:
button.Content = "Apply";
button.Name = $"A_{namedata}_applyBtn";
break;
}

return button;
}
}
}
15 changes: 5 additions & 10 deletions ValorantCC/src/API.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
using System;
using Newtonsoft.Json;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RestSharp;
using Newtonsoft.Json;
using System.Text.RegularExpressions;
using System.Diagnostics;
using RestSharp.Authenticators;

namespace ValorantCC
{
Expand Down Expand Up @@ -47,7 +42,7 @@ public class API
public CrosshairProfile profile;
public int Action;
public bool Shareable;
public API(AuthTokens Tokens, CrosshairProfile TargetProfile ,int ActionInt, bool isShareable)
public API(AuthTokens Tokens, CrosshairProfile TargetProfile, int ActionInt, bool isShareable)
{
AuthTokens = Tokens;
profile = TargetProfile;
Expand All @@ -69,7 +64,7 @@ public async Task<FetchResponse> Fetch(String sharecode = null)
payload.sharecode = sharecode;
payload.action = Action;
}
RestRequest request = new RestRequest() { Method = Method.POST};
RestRequest request = new RestRequest() { Method = Method.POST };
request.AddJsonBody(payload);
RestResponse response = (RestResponse)await client.ExecuteAsync(request);

Expand Down
3 changes: 1 addition & 2 deletions ValorantCC/src/Auth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.IO;
using System.Net;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using Utilities;
namespace ValorantCC
Expand Down Expand Up @@ -143,7 +142,7 @@ private async static Task<String> GetVersion()
asyncResult => request.EndGetResponse(asyncResult),
(object)null);
VersionResponse RespData = await taskResp.ContinueWith(r =>
{
{
WebResponse response = (WebResponse)r.Result;
StreamReader sr = new StreamReader(response.GetResponseStream());
return JsonConvert.DeserializeObject<VersionResponse>(sr.ReadToEnd());
Expand Down
7 changes: 2 additions & 5 deletions ValorantCC/src/BackgroundAuth.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.IO;
using System.Diagnostics;
using Utilities;

namespace ValorantCC
{
class BackgroundAuth
{
MainWindow main = (MainWindow) Application.Current.MainWindow;
MainWindow main = (MainWindow)Application.Current.MainWindow;
Processor processor;
public BackgroundAuth(Processor processor1)
{
Expand Down
Loading

0 comments on commit 5d3023c

Please # to comment.