Skip to content
This repository has been archived by the owner on Aug 24, 2023. It is now read-only.

Commit

Permalink
New mode of pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
Haruki1707 committed Mar 11, 2022
1 parent e08ad71 commit 6a33bcb
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 55 deletions.
6 changes: 1 addition & 5 deletions ValorantCC/SubWindow/ProfilesWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@
<Button Style="{DynamicResource MahApps.Styles.Button}" Name="btnSearchCode" Content="Search Code" MinWidth="85" Background="#FF393B44" Margin="0,5,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>
<DockPanel x:Name="Pagination">
<Label Content="Previous" FontWeight="Normal" FontStyle="Italic" Cursor="Hand" x:Name="btnPreviousOffset" MouseUp="btnPreviousOffset_MouseUp"/>
<Label Content="Next" HorizontalAlignment="Right" FontStyle="Italic" Cursor="Hand" x:Name="btnNextOffset" MouseUp="btnNextOffset_MouseUp"/>
</DockPanel>
<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="405" Width="338">
<ScrollViewer Name="ScrollContainer" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" Margin="0,5,0,0" Height="405" Width="338" ScrollChanged="ScrollViewer_ScrollChanged">

<StackPanel Name="ShareablesContainer" HorizontalAlignment="Center" Loaded="ShareablesContainer_Loaded">
</StackPanel>
Expand Down
106 changes: 58 additions & 48 deletions ValorantCC/SubWindow/ProfilesWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
Expand All @@ -26,9 +27,11 @@ public struct PublicProfile
public partial class ProfilesWindow : MetroWindow
{
public CrosshairProfile selected;
private static bool SearchButtonPressed = false;
private static API ValCCApi;
private static MainWindow main;
private static List<PublicProfile> PublicProfiles = new List<PublicProfile>();
private bool AlreadyFetching = false;
private int _offset = 0;
public ProfilesWindow(CrosshairProfile current, API ValCCAPI)
{
Expand All @@ -42,14 +45,14 @@ public ProfilesWindow(CrosshairProfile current, API ValCCAPI)
private async void ShareablesContainer_Loaded(object sender, RoutedEventArgs e)
{
LoadingPlaceHolder.Visibility = Visibility.Visible;
Pagination.Visibility = Visibility.Collapsed;
fetchErrorTxt.Visibility = Visibility.Collapsed;
try
{
bool fetchSucc = await InitialFetch();
if (!fetchSucc) fetchErrorTxt.Visibility = Visibility.Visible;
else
{
LoadingPlaceHolder.Visibility = Visibility.Collapsed;
await RenderProfiles();
}
}
Expand All @@ -58,20 +61,21 @@ private async void ShareablesContainer_Loaded(object sender, RoutedEventArgs e)
Utilities.Utils.Log(ex.StackTrace.ToString());
}
LoadingPlaceHolder.Visibility = Visibility.Collapsed;
Pagination.Visibility = Visibility.Visible;
}

/// <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 async Task<bool> InitialFetch(String sharecode = null)
private async Task<bool> InitialFetch(String sharecode = null, bool ClearArrays = true)
{
Utilities.Utils.Log("Disabling Search button.");
btnSearchCode.IsEnabled = false;
Utilities.Utils.Log("Clearing arrays.");
PublicProfiles.Clear();
ShareablesContainer.Children.Clear();
if (ClearArrays)
{
Utilities.Utils.Log("Clearing arrays.");
PublicProfiles.Clear();
}
List<ShareableProfile> Shareables;
if (!string.IsNullOrWhiteSpace(sharecode))
{
Expand All @@ -92,10 +96,13 @@ private async Task<bool> InitialFetch(String sharecode = null)
FetchResponse fetchResponse = await ValCCApi.Fetch(Offset: _offset);
if (!fetchResponse.success) return false;
Shareables = fetchResponse.data;
Pagination.Visibility = Visibility.Visible;
}

if (Shareables.Count == 0) return true;
if (Shareables == null || Shareables.Count == 0)
{
btnSearchCode.IsEnabled = true;
return true;
}

for (int i = 0; i < Shareables.Count; i++)
{
Expand All @@ -111,29 +118,40 @@ private async Task<bool> InitialFetch(String sharecode = null)
/// <summary>
/// Render the PublicProfiles var into frontend.
/// </summary>
private async Task<bool> RenderProfiles()
private async Task<bool> RenderProfiles(bool clearChildren = true)
{
UIElementCollection shareablesElement = ShareablesContainer.Children;
if (PublicProfiles.Count == 0) return true;

for (int i = 0; i < PublicProfiles.Count; i++)
int positionToRender = _offset;
if (clearChildren)
{
positionToRender = 0;
shareablesElement.Clear();
}
for (int i = positionToRender; i < PublicProfiles.Count; i++)
{
if (SearchButtonPressed)
return true;
PublicProfile profile = PublicProfiles[i];
shareablesElement.Add(await this.GenerateRender(profile));
}
return true;
}
private async void btnSearchCode_Click(object sender, RoutedEventArgs e)
{
SearchButtonPressed = true;
LoadingPlaceHolder.Visibility = Visibility.Visible;
Pagination.Visibility = Visibility.Collapsed;
fetchErrorTxt.Visibility = Visibility.Collapsed;
try
{
bool fetchSucc = await InitialFetch(SearchCode.Text);
if (!fetchSucc) fetchErrorTxt.Visibility = Visibility.Visible;
else
{
SearchButtonPressed = false;
await RenderProfiles();
}
}
catch (Exception ex)
{
Expand Down Expand Up @@ -212,50 +230,42 @@ private void LoadingPlaceHolder_IsVisibleChanged(object sender, DependencyProper
WpfAnimatedGif.ImageBehavior.GetAnimationController(LoadingPlaceHolder)?.Pause();
}

private async void btnNextOffset_MouseUp(object sender, MouseButtonEventArgs e)
private async void ScrollViewer_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
LoadingPlaceHolder.Visibility = Visibility.Visible;
Pagination.Visibility = Visibility.Collapsed;
fetchErrorTxt.Visibility = Visibility.Collapsed;
_offset += 20;
try
var MaxHeight = ScrollContainer.ScrollableHeight;
var ScrollPercentage = ((MaxHeight - ScrollContainer.VerticalOffset) / MaxHeight) *100;
var MaxScrollPercentage = 12 - .025*_offset;
if(MaxScrollPercentage <= 0) MaxScrollPercentage = .5;
System.Diagnostics.Trace.WriteLine(ScrollPercentage);
if (ScrollPercentage < MaxScrollPercentage && !AlreadyFetching)
{
bool fetchSucc = await InitialFetch();
if (!fetchSucc) fetchErrorTxt.Visibility = Visibility.Visible;
else
AlreadyFetching = true;
mouse_event(MOUSEEVENTF_LEFTUP, (uint)Mouse.GetPosition(this).X, (uint)Mouse.GetPosition(this).Y, 0, 0);
fetchErrorTxt.Visibility = Visibility.Collapsed;
_offset += 20;
try
{
await RenderProfiles();
bool fetchSucc = await InitialFetch(null, false);
if (!fetchSucc) fetchErrorTxt.Visibility = Visibility.Visible;
else
{
await RenderProfiles(false);
}
}
}
catch (Exception ex)
{
Utilities.Utils.Log(ex.StackTrace.ToString());
}
LoadingPlaceHolder.Visibility = Visibility.Collapsed;
Pagination.Visibility = Visibility.Visible;
}

private async void btnPreviousOffset_MouseUp(object sender, MouseButtonEventArgs e)
{
LoadingPlaceHolder.Visibility = Visibility.Visible;
Pagination.Visibility = Visibility.Collapsed;
fetchErrorTxt.Visibility = Visibility.Collapsed;
if (_offset >= 20) _offset -= 20;
try
{
bool fetchSucc = await InitialFetch();
if (!fetchSucc) fetchErrorTxt.Visibility = Visibility.Visible;
else
catch (Exception ex)
{
await RenderProfiles();
Utilities.Utils.Log(ex.StackTrace.ToString());
}
AlreadyFetching = false;
}
catch (Exception ex)
{
Utilities.Utils.Log(ex.StackTrace.ToString());
}
LoadingPlaceHolder.Visibility = Visibility.Collapsed;
Pagination.Visibility = Visibility.Visible;
}

//For making left click up, so it doesnt make trouble with auto-fetching
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);
private const int MOUSEEVENTF_LEFTDOWN = 0x02;
private const int MOUSEEVENTF_LEFTUP = 0x04;
private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
private const int MOUSEEVENTF_RIGHTUP = 0x10;
}
}
2 changes: 1 addition & 1 deletion ValorantCC/ValorantCC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<AssemblyVersion></AssemblyVersion>
<FileVersion></FileVersion>
<Version>3.1.7</Version>
<Version>3.1.8</Version>
<SignAssembly>true</SignAssembly>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion ValorantCC/src/Crosshair_Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public static void rectangle_redraw(Rectangle Rect, Rectangle RectOT, Position p
if (Rect.Name.Contains("OL"))
line = settings.OuterLines;

if (line.bShowShootingError)
if ((bool)(line?.bShowShootingError))
Margin += 8;

switch (pos)
Expand Down

0 comments on commit 6a33bcb

Please sign in to comment.