Skip to content

Commit

Permalink
Update with Hero rank support
Browse files Browse the repository at this point in the history
  • Loading branch information
dend committed Oct 1, 2024
1 parent 0c2ac82 commit f1eb040
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/OpenSpartan.Workshop/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
<converters:CsrToProgressConverter x:Key="CsrToProgressConverter"/>
<converters:CsrToTooltipValueConverter x:Key="CsrToTooltipValueConverter"/>
<converters:StringAvailabilityToParameterSource x:Key="StringAvailabilityToParameterSource"/>
<converters:RankToProgressColorConverter x:Key="RankToProgressColorConverter"/>
</ResourceDictionary>
</Application.Resources>
</Application>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Microsoft.UI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Media;
using System;

namespace OpenSpartan.Workshop.Converters
{
class RankToProgressColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value is int rank)
{
if (rank == 272)
{
return new SolidColorBrush(Windows.UI.Color.FromArgb(255, 241, 225, 75));
}
else
{
return (SolidColorBrush)Application.Current.Resources["ProgressRingForegroundThemeBrush"];
};
}

// Return a default SolidColorBrush (e.g., Black) if the input value is null or not of expected type
return new SolidColorBrush(Colors.Black);
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
}
12 changes: 8 additions & 4 deletions src/OpenSpartan.Workshop/Core/UserContextManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,16 +310,16 @@ await DispatcherWindow.DispatcherQueue.EnqueueAsync(async () =>
if (currentCareerStage.Rank != 272)
{
HomeViewModel.Instance.Title = $"{currentCareerStage.TierType} {currentCareerStage.RankTitle.Value} {currentCareerStage.RankTier.Value}";
HomeViewModel.Instance.CurrentRankExperience = careerTrackResult.Result.RewardTracks[0].Result.CurrentProgress.PartialProgress;
HomeViewModel.Instance.RequiredRankExperience = currentCareerStage.XpRequiredForRank;
}
else
{
// Hero rank is just "Hero" - no need to interpolate with other strings.
HomeViewModel.Instance.Title = currentCareerStage.RankTitle.Value;
HomeViewModel.Instance.CurrentRankExperience = HomeViewModel.Instance.RequiredRankExperience = currentCareerStage.XpRequiredForRank;
}

HomeViewModel.Instance.CurrentRankExperience = careerTrackResult.Result.RewardTracks[0].Result.CurrentProgress.PartialProgress;
HomeViewModel.Instance.RequiredRankExperience = currentCareerStage.XpRequiredForRank;

HomeViewModel.Instance.ExperienceTotalRequired = careerTrackContainerResult.Result.Ranks.Sum(item => item.XpRequiredForRank);

var relevantRanks = careerTrackContainerResult.Result.Ranks.TakeWhile(c => c.Rank < currentRank);
Expand Down Expand Up @@ -1952,7 +1952,7 @@ await DispatcherWindow.DispatcherQueue.EnqueueAsync(() =>
return await HaloClient.GameCmsGetItem(item.ItemPath, HaloClient.ClearanceToken);
});

if (itemMetadata != null)
if (itemMetadata != null && itemMetadata.Result != null)
{
string folderPath = !string.IsNullOrWhiteSpace(itemMetadata.Result.CommonData.DisplayPath.FolderPath) ? itemMetadata.Result.CommonData.DisplayPath.FolderPath : itemMetadata.Result.CommonData.DisplayPath.Media.FolderPath;
string fileName = !string.IsNullOrWhiteSpace(itemMetadata.Result.CommonData.DisplayPath.FileName) ? itemMetadata.Result.CommonData.DisplayPath.FileName : itemMetadata.Result.CommonData.DisplayPath.Media.FileName;
Expand Down Expand Up @@ -2014,6 +2014,10 @@ await DispatcherWindow.DispatcherQueue.EnqueueAsync(() =>

LogEngine.Log($"Got item for Exchange listing: {item.ItemPath}");
}
else
{
LogEngine.Log($"Failed to obtain exchange item: {item.ItemPath}", LogSeverity.Error);
}
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/OpenSpartan.Workshop/ViewModels/HomeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,14 @@ public double? RankProgress
{
if (CurrentRankExperience != null && RequiredRankExperience != null)
{
return Convert.ToDouble(CurrentRankExperience, CultureInfo.CurrentCulture) / Convert.ToDouble(RequiredRankExperience, CultureInfo.CurrentCulture);
if (CurrentRankExperience <= RequiredRankExperience)
{
return Convert.ToDouble(CurrentRankExperience, CultureInfo.CurrentCulture) / Convert.ToDouble(RequiredRankExperience, CultureInfo.CurrentCulture);
}
else
{
return 0;
}
}
else
{
Expand Down Expand Up @@ -267,6 +274,7 @@ public int? ExperienceEarnedToDate
NotifyPropertyChanged();
NotifyPropertyChanged(nameof(ExperienceRemaining));
NotifyPropertyChanged(nameof(ExperienceProgress));
NotifyPropertyChanged(nameof(RankProgress));
}
}
}
Expand All @@ -282,6 +290,7 @@ public int? ExperienceTotalRequired
NotifyPropertyChanged();
NotifyPropertyChanged(nameof(ExperienceRemaining));
NotifyPropertyChanged(nameof(ExperienceProgress));
NotifyPropertyChanged(nameof(RankProgress));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSpartan.Workshop/Views/HomeView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<VariableSizedWrapGrid Orientation="Horizontal" ItemWidth="250" Margin="24,0,24,0">
<StackPanel Background="#404040" Orientation="Vertical" BorderThickness="2" Padding="12" CornerRadius="4">
<Grid>
<ProgressRing Background="#2F2F2F" Height="160" Width="160" IsIndeterminate="False" Value="{Binding RankProgress}" Maximum="1" Minimum="0" HorizontalAlignment="Center" VerticalAlignment="Center"></ProgressRing>
<ProgressRing Background="#2F2F2F" Height="160" Width="160" IsIndeterminate="False" Value="{Binding RankProgress}" Maximum="1" Minimum="0" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="{Binding CareerSnapshot.RewardTracks[0].Result.CurrentProgress.Rank, Converter={StaticResource RankToProgressColorConverter}}"></ProgressRing>
<Image VerticalAlignment="Center" HorizontalAlignment="Center" Height="100" Source="{Binding RankImage}"></Image>
</Grid>
</StackPanel>
Expand Down

0 comments on commit f1eb040

Please sign in to comment.