Skip to content

Commit

Permalink
MainWindow themes changed.
Browse files Browse the repository at this point in the history
  • Loading branch information
weedeej committed Feb 15, 2022
1 parent d6bb70e commit 85df620
Show file tree
Hide file tree
Showing 13 changed files with 339 additions and 650 deletions.
389 changes: 9 additions & 380 deletions ValorantCC/App.xaml

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions ValorantCC/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ private void AppEventHandler(object sender, StartupEventArgs e)

private void LogFirstChanceException(object sender, FirstChanceExceptionEventArgs e)
{
Utils.Log($"{e.Exception.Message}: {e.Exception.StackTrace}");
Utilities.Utils.Log($"{e.Exception.Message}: {e.Exception.StackTrace}");
}

private void LogDispatcherUnhandled(object sender, DispatcherUnhandledExceptionEventArgs e)
{
Utils.Log($"{e.Exception.Message}: {e.Exception.StackTrace}");
Utilities.Utils.Log($"{e.Exception.Message}: {e.Exception.StackTrace}");
e.Handled = false;
}

Expand All @@ -47,13 +47,13 @@ private void LogUnhandled(object sender, UnhandledExceptionEventArgs e)
var ex = e.ExceptionObject as Exception;
if (e.IsTerminating)
{
Utils.Log($"{ex.Message}: {ex.StackTrace}");
Utilities.Utils.Log($"{ex.Message}: {ex.StackTrace}");
}
}

private void LogUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
Utils.Log($"{e.Exception.Message}: {e.Exception.StackTrace}");
Utilities.Utils.Log($"{e.Exception.Message}: {e.Exception.StackTrace}");
e.SetObserved();
}
}
Expand Down
332 changes: 173 additions & 159 deletions ValorantCC/MainWindow.xaml

Large diffs are not rendered by default.

88 changes: 43 additions & 45 deletions ValorantCC/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using EZ_Updater;
using MahApps.Metro.Controls;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand All @@ -15,7 +16,7 @@

namespace ValorantCC
{
public partial class MainWindow : Window
public partial class MainWindow : MetroWindow
{
public Processor DataProcessor = new Processor();
BrushConverter bc = new BrushConverter();
Expand All @@ -29,47 +30,22 @@ public partial class MainWindow : Window
public MainWindow()
{
// Create logging dir
if (!Directory.Exists(Path.GetDirectoryName(Utils.LoggingFile))) Directory.CreateDirectory(Path.GetDirectoryName(Utils.LoggingFile));
if (!Directory.Exists(Path.GetDirectoryName(Utilities.Utils.LoggingFile))) Directory.CreateDirectory(Path.GetDirectoryName(Utilities.Utils.LoggingFile));
// Replace old logs
if (File.Exists(Utils.LoggingFile)) File.Move(Utils.LoggingFile, Utils.LoggingFile + ".old", true);
if (File.Exists(Utilities.Utils.LoggingFile)) File.Move(Utilities.Utils.LoggingFile, Utilities.Utils.LoggingFile + ".old", true);
Version ProgramFileVersion = new Version(FileVersionInfo.GetVersionInfo(Process.GetCurrentProcess().MainModule.FileName).ProductVersion);

InitializeComponent();
Utils.Log($"App Started | v{ProgramFileVersion}. Replaced old logfile.");
Txt_CurrVer.Content = $"ValorantCC3.0b - v{ProgramFileVersion}";
Utilities.Utils.Log($"App Started | v{ProgramFileVersion}. Replaced old logfile.");
this.Title = $"ValorantCC3.0b - v{ProgramFileVersion}";
BackgroundAuth auth = new BackgroundAuth(DataProcessor);
auth.LoopCheck();
}

private async void Grid_Loaded(object sender, RoutedEventArgs e)
{
Updater.CustomLogger = Utils.Log;
Updater.OriginalFileName = "ValorantCC";
Updater.LogInterfix = " | ";
if (await Updater.CheckUpdateAsync("weedeej", "ValorantCC"))
{
try
{
File.Create("./valccPermsTest.null").Close();
File.Delete("./valccPermsTest.null");
}
catch (UnauthorizedAccessException)
{
Utils.Log("User is not authorized to create a file on current valcc dir. Consider moving.");
MessageWindow.Show("There's an update available but you have no access to write on this folder.\nPlease consider moving the app to a folder created by you or running the app as administrator.");
this.Close();
}
var update = new UpdateWindow();
update.Owner = this;
update.ShowDialog();
}
}

private async void btnSave_Click(object sender, RoutedEventArgs e)
{
if (!LoggedIn)
{
Utils.MessageText("You are not logged in!", Brushes.Red);
Utilities.Utils.MessageText("You are not logged in!", Brushes.Red);
return;
}
if (DataProcessor.ProfileListed)
Expand All @@ -85,10 +61,10 @@ private async void btnSave_Click(object sender, RoutedEventArgs e)
await DataProcessor.Construct();
profiles.Items.Refresh();
profiles.SelectedIndex = DataProcessor.CurrentProfile;
Utils.MessageText("Saved! Restart Valorant.", Brushes.Lime);
Utilities.Utils.MessageText("Saved! Restart Valorant.", Brushes.Lime);
return;
}
Utils.MessageText("Your session expired! Please restart ValorantCC/Valorant", Brushes.Red);
Utilities.Utils.MessageText("Your session expired! Please restart ValorantCC/Valorant", Brushes.Red);

return;
}
Expand Down Expand Up @@ -126,12 +102,12 @@ private async void btnReload_Click(object sender, RoutedEventArgs e)
{
if (!LoggedIn)
{
Utils.MessageText("You are not logged in!", Brushes.Red);
Utilities.Utils.MessageText("You are not logged in!", Brushes.Red);
return;
}
Utils.Log("Reload Clicked > Reconstructing Processor.");
Utilities.Utils.Log("Reload Clicked > Reconstructing Processor.");
if (!(await DataProcessor.Construct()))
Utils.MessageText("Your session expired! Please restart ValorantCC/Valorant", Brushes.Red);
Utilities.Utils.MessageText("Your session expired! Please restart ValorantCC/Valorant", Brushes.Red);

profiles.ItemsSource = DataProcessor.ProfileNames;
profiles.Items.Refresh();
Expand Down Expand Up @@ -276,9 +252,9 @@ private void ClipboardButtonLeave(object sender, MouseEventArgs e)
private void btnOpenLogs_Click(object sender, RoutedEventArgs e)
{
Process p = new Process();
p.StartInfo = new ProcessStartInfo() { FileName = Path.GetDirectoryName(Utils.LoggingFile), UseShellExecute = true };
p.StartInfo = new ProcessStartInfo() { FileName = Path.GetDirectoryName(Utilities.Utils.LoggingFile), UseShellExecute = true };
p.Start();
Utils.MessageText("Log folder opened! Please include OLD files to your report if exists.", Brushes.Lime);
Utilities.Utils.MessageText("Log folder opened! Please include OLD files to your report if exists.", Brushes.Lime);
}

private void next_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -307,7 +283,7 @@ private void btnCommunityProfiles_Click(object sender, RoutedEventArgs e)
{
if (!LoggedIn)
{
Utils.MessageText("You are not logged in !", Brushes.Red);
Utilities.Utils.MessageText("You are not logged in !", Brushes.Red);
return;
}
try
Expand All @@ -327,7 +303,7 @@ private void chkbxShareable_Click(object sender, RoutedEventArgs e)
{
if (!LoggedIn)
{
Utils.MessageText("You are not logged in !", Brushes.Red);
Utilities.Utils.MessageText("You are not logged in !", Brushes.Red);
((CheckBox)sender).IsChecked = !((CheckBox)sender).IsChecked;
return;
}
Expand All @@ -337,11 +313,10 @@ private async void btnShare_Click(object sender, RoutedEventArgs e)
{
if (!LoggedIn)
{
Utils.MessageText("You are not logged in !", Brushes.Red);
Utilities.Utils.MessageText("You are not logged in !", Brushes.Red);
return;
}
exitButton.Visibility = Visibility.Collapsed;
Utils.MessageText("Your profile is being saved...", Brushes.Yellow);
Utilities.Utils.MessageText("Your profile is being saved...", Brushes.Yellow);

ValCCAPI.Shareable = (bool)chkbxShareable.IsChecked;
ValCCAPI.profile = SelectedProfile;
Expand All @@ -350,8 +325,31 @@ private async void btnShare_Click(object sender, RoutedEventArgs e)
Clipboard.SetText(sharecode);
MessageWindow.Show($"Your sharecode is: \"{sharecode}\" and is copied.\nIf you want this profile accessible across the community,\nPlease be sure that you have the 'shareable' checkbox checked.", "Profile shared!");

Utils.MessageText("Your profile has been saved. It can now be browsed if \"shareable\" checkbox is checked before saving.", Brushes.Lime);
exitButton.Visibility = Visibility.Visible;
Utilities.Utils.MessageText("Your profile has been saved. It can now be browsed if \"shareable\" checkbox is checked before saving.", Brushes.Lime);
}

private async void spinner_Loaded(object sender, RoutedEventArgs e)
{
Updater.CustomLogger = Utilities.Utils.Log;
Updater.OriginalFileName = "ValorantCC";
Updater.LogInterfix = " | ";
if (await Updater.CheckUpdateAsync("weedeej", "ValorantCC"))
{
try
{
File.Create("./valccPermsTest.null").Close();
File.Delete("./valccPermsTest.null");
}
catch (UnauthorizedAccessException)
{
Utilities.Utils.Log("User is not authorized to create a file on current valcc dir. Consider moving.");
MessageWindow.Show("There's an update available but you have no access to write on this folder.\nPlease consider moving the app to a folder created by you or running the app as administrator.");
this.Close();
}
var update = new UpdateWindow();
update.Owner = this;
update.ShowDialog();
}
}
}
}
6 changes: 4 additions & 2 deletions ValorantCC/SubWindow/ProfilesWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ValorantCC"
xmlns:mah="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:gif="http://wpfanimatedgif.codeplex.com"
mc:Ignorable="d"
Title="ProfilesWindow" RenderOptions.BitmapScalingMode="Fant" Background="Transparent" AllowsTransparency="True" Height="481" Width="339" ResizeMode="NoResize" SizeToContent="WidthAndHeight" ShowInTaskbar="False" WindowStartupLocation="CenterOwner" WindowStyle="None">
Expand All @@ -26,9 +27,10 @@
</Border>
<StackPanel Name="Container" HorizontalAlignment="Center" Margin="0,5">
<StackPanel Orientation="Horizontal" Width="350">
<TextBox Style="{StaticResource LineTextBox}" Name="SearchCode" MinWidth="128" MaxWidth="128" Background="#FF393B44" Margin="65,25,5,0" Foreground="White" Height="22"/>
<Button Style="{DynamicResource SearchCodeButtonStyle}" Name="btnSearchCode" Content="Search Code" MinWidth="85" Background="#FF393B44" Margin="0,25,5,0" Foreground="White" Cursor="Hand" Click="btnSearchCode_Click" BorderBrush="#FF393B44"/>
<TextBox Style="{DynamicResource MahApps.Styles.TextBox}" Name="SearchCode" MinWidth="128" MaxWidth="128" Background="#FF393B44" Margin="65,25,5,0" Foreground="White" Height="22"/>
<Button Style="{DynamicResource MahApps.Styles.Button}" Name="btnSearchCode" Content="Search Code" MinWidth="85" Background="#FF393B44" Margin="0,25,5,0" Foreground="White" Cursor="Hand" Click="btnSearchCode_Click" BorderBrush="#FF393B44"/>
</StackPanel>
<TextBlock Foreground="White" HorizontalAlignment="Center" Visibility="Collapsed" Name="fetchErrorTxt">An error has occured while fetching profiles.</TextBlock>
<Image gif:ImageBehavior.AnimatedSource="../Resources/vtspinner optimized.gif" Width="50" Height="52" Margin="0,155,0,0" x:Name="LoadingPlaceHolder" Visibility="Visible" IsVisibleChanged="LoadingPlaceHolder_IsVisibleChanged"/>
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" Margin="0,5,0,0" Height="388" Width="338">

Expand Down
59 changes: 44 additions & 15 deletions ValorantCC/SubWindow/ProfilesWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using ValorantCC.SubWindow;

using Utilities;
namespace ValorantCC
{
/// <summary>
Expand All @@ -35,14 +36,27 @@ public ProfilesWindow(CrosshairProfile current, API ValCCAPI)
main = (MainWindow)Application.Current.MainWindow;
selected = current;
ValCCApi = ValCCAPI;
Utilities.Utils.Log("Community Profiles Loading...");
}

private async void ShareablesContainer_Loaded(object sender, RoutedEventArgs e)
{
LoadingPlaceHolder.Visibility = Visibility.Visible;
await InitialFetch();
fetchErrorTxt.Visibility = Visibility.Collapsed;
try
{
bool fetchSucc = await InitialFetch();
if (!fetchSucc) fetchErrorTxt.Visibility = Visibility.Visible;
else
{
await RenderProfiles();
}
}
catch (Exception ex)
{
Utilities.Utils.Log(ex.StackTrace.ToString());
}
LoadingPlaceHolder.Visibility = Visibility.Collapsed;
await RenderProfiles();
}

/// <summary>
Expand All @@ -51,34 +65,36 @@ private async void ShareablesContainer_Loaded(object sender, RoutedEventArgs e)
/// <param name="sharecode">Nullable. Searched Code</param>
private async Task<bool> InitialFetch(String sharecode = null)
{
Utilities.Utils.Log("Disabling Search button.");
btnSearchCode.IsEnabled = false;
Utilities.Utils.Log("Clearing arrays.");
PublicProfiles.Clear();
ShareablesContainer.Children.Clear();
List<ShareableProfile> Shareables;
if (!string.IsNullOrWhiteSpace(sharecode))
{
Utilities.Utils.Log($"Fetching profile with code: {sharecode}");
ValCCApi.Action = 3;
Shareables = (await ValCCApi.Fetch(sharecode)).data;
FetchResponse fetchResponse = await ValCCApi.Fetch(sharecode);
if (!fetchResponse.success) return false;
Shareables = fetchResponse.data;
}
else
{
Utilities.Utils.Log($"Fetching profiles from server");
ValCCApi.Action = 2;
Shareables = (await ValCCApi.Fetch()).data;
FetchResponse fetchResponse = await ValCCApi.Fetch(sharecode);
if (!fetchResponse.success) return false;
Shareables = fetchResponse.data;
}

if (Shareables.Count == 0) return true;

for (int i = 0; i < Shareables.Count; i++)
{
ShareableProfile currentShareable = Shareables[i];
CrosshairProfile profile;
try
{
profile = JsonConvert.DeserializeObject<CrosshairProfile>(Regex.Unescape(currentShareable.settings));
}
catch
{
continue;
}
profile = JsonConvert.DeserializeObject<CrosshairProfile>(Regex.Unescape(currentShareable.settings));
PublicProfiles.Add(new PublicProfile() { owner = currentShareable.displayName, settings = profile, sharecode = currentShareable.shareCode, ID = i });
}
btnSearchCode.IsEnabled = true;
Expand All @@ -103,27 +119,40 @@ private async Task<bool> RenderProfiles()
private async void btnSearchCode_Click(object sender, RoutedEventArgs e)
{
LoadingPlaceHolder.Visibility = Visibility.Visible;
await InitialFetch(SearchCode.Text);
fetchErrorTxt.Visibility = Visibility.Collapsed;
try
{
bool fetchSucc = await InitialFetch(SearchCode.Text);
if (!fetchSucc) fetchErrorTxt.Visibility = Visibility.Visible;
else
await RenderProfiles();
}
catch (Exception ex)
{
Utilities.Utils.Log(ex.StackTrace.ToString());
}
LoadingPlaceHolder.Visibility = Visibility.Collapsed;
await RenderProfiles();
}

public void shareBtnClicked(object sender, RoutedEventArgs e)
{
String shareCode = ((Button)sender).Name.Split('_')[1];
Clipboard.SetText(shareCode);
MessageWindow.Show("\"" + shareCode + "\" has been copied to clipboard!");
Utilities.Utils.Log($"{shareCode} copied to clipboard.");
}

public void detailsBtnClicked(object sender, RoutedEventArgs e)
{
PublicProfile pressedPubProfile = PublicProfiles[Int32.Parse(((Button)sender).Name.Split('_')[1])];
CrosshairProfile pressedProfile = pressedPubProfile.settings;
MessageWindow.Show($"{pressedPubProfile.owner}'s Profile: {pressedProfile.ProfileName}\nPrimary:\n\tInner Lines: {pressedProfile.Primary.InnerLines.Opacity}, {pressedProfile.Primary.InnerLines.LineLength}, {pressedProfile.Primary.InnerLines.LineThickness}, {pressedProfile.Primary.InnerLines.LineOffset}\n\tOuter Lines: {pressedProfile.Primary.OuterLines.Opacity}, {pressedProfile.Primary.OuterLines.LineLength}, {pressedProfile.Primary.OuterLines.LineThickness}, {pressedProfile.Primary.OuterLines.LineOffset}\n\nADS:\n\tInner Lines: {pressedProfile.aDS.InnerLines.Opacity}, {pressedProfile.aDS.InnerLines.LineLength}, {pressedProfile.aDS.InnerLines.LineThickness}, {pressedProfile.aDS.InnerLines.LineOffset}\n\tOuter Lines: {pressedProfile.aDS.OuterLines.Opacity}, {pressedProfile.aDS.OuterLines.LineLength}, {pressedProfile.aDS.OuterLines.LineThickness}, {pressedProfile.aDS.OuterLines.LineOffset}");
Utilities.Utils.Log($"Details button clicked.");
}

public void applyBtnClicked(object sender, RoutedEventArgs e)
{
Utilities.Utils.Log("Apply button clicked.");
PublicProfile pressedPubProfile = PublicProfiles[Int32.Parse(((Button)sender).Name.Split('_')[1])];
CrosshairProfile pressedProfile = pressedPubProfile.settings;
selected.aDS = pressedProfile.aDS;
Expand Down
Loading

0 comments on commit 85df620

Please # to comment.