Skip to content

Commit

Permalink
Dev phase 3
Browse files Browse the repository at this point in the history
  • Loading branch information
weedeej committed Jan 5, 2022
1 parent 4265b86 commit e4b5492
Show file tree
Hide file tree
Showing 4 changed files with 33 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 @@ -102,7 +102,6 @@ private void profiles_SelectionChanged(object sender, SelectionChangedEventArgs

SelectedIndex = profiles.SelectedIndex;
SelectedProfile = DataProcessor.ProfileFromIndex(SelectedIndex);
ValCCAPI.profile = SelectedProfile;

primary_color.SelectedColor = Color.FromRgb(SelectedProfile.Primary.Color.R, SelectedProfile.Primary.Color.G, SelectedProfile.Primary.Color.B);
if (!DataProcessor.ProfileListed)
Expand All @@ -120,6 +119,7 @@ private void profiles_SelectionChanged(object sender, SelectionChangedEventArgs
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);

if (ValCCAPI != null) ValCCAPI.profile = SelectedProfile;
Crosshair_load();
}
private void StackPanel_MouseDown(object sender, MouseButtonEventArgs e)
Expand Down
3 changes: 1 addition & 2 deletions ValorantCC/SubWindow/ProfilesWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>

<Image Source="../Resources/CrosshairBG1.png" Grid.ColumnSpan="3" Grid.Row="0" Stretch="Fill" Margin="2,0,2,2"/>
<Label Grid.Column="2" Grid.Row="0" Content="Haruki's Profile" Foreground="White" VerticalAlignment="Bottom" HorizontalAlignment="Right"/>

Expand All @@ -56,7 +56,6 @@
</Grid>
</Border>
<Border Background="#FF393B44" MinHeight="95" MaxHeight="95" MinWidth="330" MaxWidth="330" Margin="0,5"/>
<Border Background="#FF393B44" MinHeight="95" MaxHeight="95" MinWidth="330" MaxWidth="330" Margin="0,5"/>
</StackPanel>
</StackPanel>
</Border>
Expand Down
23 changes: 20 additions & 3 deletions ValorantCC/SubWindow/ProfilesWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
Expand All @@ -28,6 +29,7 @@ public struct PublicProfile
public partial class ProfilesWindow : Window
{
public CrosshairProfile selected;
private BrushConverter bc;
private static API ValCCApi;
private static MainWindow main;
private static List<PublicProfile> PublicProfiles = new List<PublicProfile>();
Expand All @@ -36,6 +38,7 @@ public ProfilesWindow(CrosshairProfile current, API ValCCAPI)
InitializeComponent();
main = (MainWindow) Application.Current.MainWindow;
ValCCApi = ValCCAPI;
bc = new BrushConverter();
InitialFetch();
RenderProfiles();
}
Expand All @@ -61,7 +64,7 @@ private static void InitialFetch(String sharecode = null)
CrosshairProfile profile;
try
{
profile = JsonConvert.DeserializeObject<CrosshairProfile>(currentShareable.settings);
profile = JsonConvert.DeserializeObject<CrosshairProfile>(Regex.Unescape(currentShareable.settings));
}
catch
{
Expand All @@ -74,9 +77,23 @@ private static void InitialFetch(String sharecode = null)
/// <summary>
/// Render the PublicProfiles var into frontend.
/// </summary>
private static void RenderProfiles()
private void RenderProfiles()
{

UIElementCollection shareablesElement = ShareablesContainer.Children;
Border template = new Border()
{
Background = (Brush)bc.ConvertFromString("#FF393B44"),
MinHeight = 95,
MaxHeight = 95,
MinWidth = 330,
MaxWidth = 330,
Margin = new Thickness() { Bottom = 5, Top = 5, Left = 0, Right = 0 }
};
for (int i = 0; i < PublicProfiles.Count; i++)
{
PublicProfile profile = PublicProfiles[i];
shareablesElement.Add(template);
}
}
private void btnSearchCode_Click(object sender, RoutedEventArgs e)
{
Expand Down
20 changes: 11 additions & 9 deletions ValorantCC/src/API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.Threading.Tasks;
using RestSharp;
using Newtonsoft.Json;
using System.Text.RegularExpressions;
using System.Diagnostics;

namespace ValorantCC
{
Expand All @@ -17,15 +19,15 @@ public struct VoidCallResponse
public struct FetchResponse
{
public bool success { get; set; }
public List<ShareableProfile> data {get; set; }
public List<ShareableProfile> data { get; set; }
}

public struct ShareableProfile
{
public String shareCode { get; }
public String settings { get; }
public bool shareable { get; }
public String displayName { get; }
public String shareCode { get; set; }
public String settings { get; set; }
public bool shareable { get; set; }
public String displayName { get; set; }
}

public partial class PostPayload
Expand Down Expand Up @@ -67,10 +69,10 @@ public FetchResponse Fetch(String sharecode = null)
payload.action = Action;
}
RestRequest request = new RestRequest() { Method = Method.POST};
request.AddParameter("application/json", payload, ParameterType.RequestBody);
request.AddJsonBody(payload);
RestResponse response = (RestResponse)client.Execute(request);
if (response.StatusCode != System.Net.HttpStatusCode.OK) return new FetchResponse() { success = false };
return JsonConvert.DeserializeObject<FetchResponse>(response.Content);
return JsonConvert.DeserializeObject<FetchResponse>(Regex.Unescape(response.Content));
}

public VoidCallResponse Set()
Expand All @@ -83,11 +85,11 @@ public VoidCallResponse Set()
action = Action
};
RestRequest request = new RestRequest() { Method = Method.POST };
request.AddParameter("application/json", payload, ParameterType.RequestBody);
request.AddJsonBody(payload);
request.AddHeader("Authorization", $"Bearer {AuthTokens.AccessToken}"); // Pass to server so nobody can set somebody's saved profile.
RestResponse response = (RestResponse)client.Execute(request);
if (response.StatusCode != System.Net.HttpStatusCode.OK) return new VoidCallResponse() { success = false };
return JsonConvert.DeserializeObject<VoidCallResponse>(response.Content);
return JsonConvert.DeserializeObject<VoidCallResponse>(Regex.Unescape(response.Content));
}

}
Expand Down

0 comments on commit e4b5492

Please # to comment.