Skip to content

Commit

Permalink
Merge pull request #101 from snowystars1/master
Browse files Browse the repository at this point in the history
Clan Rankings
  • Loading branch information
NSGolova authored Jan 13, 2024
2 parents 62eab22 + b16b5ee commit 90a8857
Show file tree
Hide file tree
Showing 15 changed files with 248 additions and 14 deletions.
11 changes: 10 additions & 1 deletion Source/1_Config/ConfigDefaults.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BeatLeader.Models;
using BeatLeader.Models;
using UnityEngine;

namespace BeatLeader {
Expand Down Expand Up @@ -32,6 +32,15 @@ internal static class ConfigDefaults {

#endregion

#region LeaderboardDisplaySettings

public static LeaderboardDisplaySettings LeaderboardDisplaySettings = new()
{
ClanCaptureDisplay = true
};

#endregion

#region ReplayerSettings

public static readonly InternalReplayerCameraSettings InternalReplayerCameraSettings = new() {
Expand Down
8 changes: 7 additions & 1 deletion Source/1_Config/ConfigFileData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Runtime.CompilerServices;
using System.Runtime.CompilerServices;
using BeatLeader.Models;
using Hive.Versioning;
using IPA.Config.Stores;
Expand Down Expand Up @@ -54,6 +54,12 @@ internal class ConfigFileData {

#endregion

#region LeaderboardDisplaySettings

public LeaderboardDisplaySettings LeaderboardDisplaySettings = ConfigDefaults.LeaderboardDisplaySettings;

#endregion

#region ReplayerSettings

public InternalReplayerCameraSettings InternalReplayerCameraSettings { get; set; } = ConfigDefaults.InternalReplayerCameraSettings;
Expand Down
22 changes: 19 additions & 3 deletions Source/1_Config/PluginConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,28 @@ public static ScoreRowCellType LeaderboardTableMask {

public static ScoreRowCellType GetLeaderboardTableMask(bool includePP) {
return includePP ? LeaderboardTableMask : LeaderboardTableMask & ~ScoreRowCellType.PerformancePoints;
}

#endregion

#region LeaderboardDisplaySettings

public static event Action<LeaderboardDisplaySettings> LeaderboardDisplaySettingsChangedEvent;

public static LeaderboardDisplaySettings LeaderboardDisplaySettings
{
get => ConfigFileData.Instance.LeaderboardDisplaySettings;
set
{
ConfigFileData.Instance.LeaderboardDisplaySettings = value;
LeaderboardDisplaySettingsChangedEvent?.Invoke(value);
}
}


#endregion


#region ReplayerSettings


public static event Action<ReplayerSettings> ReplayerSettingsChangedEvent;

public static ReplayerSettings ReplayerSettings {
Expand Down
2 changes: 2 additions & 0 deletions Source/2_Core/API/Authentication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ private static IEnumerator DoLogin(Action onSuccess, Action<string> onFail) {
new MultipartFormDataSection("provider", provider),
new MultipartFormDataSection("returnUrl", "/")
};

var request = UnityWebRequest.Post(BLConstants.SIGNIN_WITH_TICKET, form);

yield return request.SendWebRequest();

switch (request.responseCode) {
Expand Down
18 changes: 16 additions & 2 deletions Source/2_Core/Managers/DataManager/LeaderboardInfoManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ private void UpdateLeaderboardsByHash(string hash) {

void OnSuccess(HashLeaderboardsInfoResponse result) {
foreach (var leaderboardInfo in result.leaderboards) {
LeaderboardsCache.PutLeaderboardInfo(result.song, leaderboardInfo.id, leaderboardInfo.difficulty, leaderboardInfo.qualification);
LeaderboardsCache.PutLeaderboardInfo(
result.song,
leaderboardInfo.id,
leaderboardInfo.difficulty,
leaderboardInfo.qualification,
leaderboardInfo.clan,
leaderboardInfo.clanRankingContested
);
}

LeaderboardsCache.NotifyCacheWasChanged();
Expand Down Expand Up @@ -64,7 +71,14 @@ private static IEnumerator FullCacheUpdateTask() {

void OnSuccess(Paged<MassLeaderboardsInfoResponse> result) {
foreach (var response in result.data) {
LeaderboardsCache.PutLeaderboardInfo(response.song, response.id, response.difficulty, response.qualification);
LeaderboardsCache.PutLeaderboardInfo(
response.song,
response.id,
response.difficulty,
response.qualification,
response.clan,
response.clanRankingContested
);
}

totalPages = Mathf.CeilToInt((float) result.metadata.total / result.metadata.itemsPerPage);
Expand Down
10 changes: 7 additions & 3 deletions Source/2_Core/Managers/DataManager/LeaderboardsCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,26 @@ public static bool TryGetLeaderboardInfo(LeaderboardKey key, out LeaderboardCach
return true;
}

public static void PutLeaderboardInfo(SongInfo songInfo, string leaderboardId, DiffInfo diffInfo, QualificationInfo qualificationInfo) {
public static void PutLeaderboardInfo(SongInfo songInfo, string leaderboardId, DiffInfo diffInfo, QualificationInfo qualificationInfo, Clan clan, bool clanRankingContested) {
var key = LeaderboardKey.FromSongDiff(songInfo, diffInfo);
LeaderboardInfoCache[key] = new LeaderboardCacheEntry(leaderboardId, songInfo, diffInfo, qualificationInfo);
LeaderboardInfoCache[key] = new LeaderboardCacheEntry(leaderboardId, songInfo, diffInfo, qualificationInfo, clan, clanRankingContested);
}

public readonly struct LeaderboardCacheEntry {
public readonly string LeaderboardId;
public readonly SongInfo SongInfo;
public readonly DiffInfo DifficultyInfo;
public readonly QualificationInfo QualificationInfo;
public readonly Clan Clan;
public readonly bool ClanRankingContested;

public LeaderboardCacheEntry(string leaderboardId, SongInfo songInfo, DiffInfo difficultyInfo, QualificationInfo qualificationInfo) {
public LeaderboardCacheEntry(string leaderboardId, SongInfo songInfo, DiffInfo difficultyInfo, QualificationInfo qualificationInfo, Clan clan, bool clanRankingContested) {
SongInfo = songInfo;
DifficultyInfo = difficultyInfo;
QualificationInfo = qualificationInfo;
LeaderboardId = leaderboardId;
Clan = clan;
ClanRankingContested = clanRankingContested;
}
}

Expand Down
10 changes: 10 additions & 0 deletions Source/2_Core/Models/LeaderboardDisplaySettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using BeatLeader.Utils;
using Newtonsoft.Json;

namespace BeatLeader.Models
{
public class LeaderboardDisplaySettings
{
public bool ClanCaptureDisplay { get; set; }
}
}
4 changes: 4 additions & 0 deletions Source/2_Core/Models/LeaderboardsInfoResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ internal struct MassLeaderboardsInfoResponse {
public SongInfo song;
public DiffInfo difficulty;
public QualificationInfo qualification;
public Clan clan;
public bool clanRankingContested;
}

[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
Expand All @@ -22,6 +24,8 @@ internal struct HashLeaderboardInfo {
public string id;
public DiffInfo difficulty;
public QualificationInfo qualification;
public Clan clan;
public bool clanRankingContested;
}

[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
Expand Down
2 changes: 1 addition & 1 deletion Source/8_UI/Leaderboard/Components/Basic/ClanTag.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BeatLeader.Models;
using BeatLeader.Models;
using BeatSaberMarkupLanguage.Attributes;
using JetBrains.Annotations;
using TMPro;
Expand Down
123 changes: 123 additions & 0 deletions Source/8_UI/Leaderboard/Components/Header/CaptorClan.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
using BeatLeader.DataManager;
using BeatSaberMarkupLanguage.Attributes;
using JetBrains.Annotations;

namespace BeatLeader.Components {
internal class CaptorClan : ReeUIComponentV2 {
#region Components

[UIValue("clan-tag"), UsedImplicitly]
private ClanTag _captorClanTag;

private bool _captorClanActive = false;

[UIValue("captor-clan-active"), UsedImplicitly]
private bool CaptorClanActive {
get => _captorClanActive;
set {
if (_captorClanActive.Equals(value)) return;
_captorClanActive = value;
NotifyPropertyChanged();
}
}

private bool _leaderboardCaptured = false;

[UIValue("leaderboard-captured"), UsedImplicitly]
private bool LeaderboardCaptured {
get => _leaderboardCaptured;
set {
if (_leaderboardCaptured.Equals(value)) return;
_leaderboardCaptured = value;
NotifyPropertyChanged();
}
}

private string _leaderboardCaptorClanStatusText = "";

[UIValue("captor-clan-text"), UsedImplicitly]
private string CaptorClanText {
get => _leaderboardCaptorClanStatusText;
set {
if (_leaderboardCaptorClanStatusText.Equals(value)) return;
_leaderboardCaptorClanStatusText = value;
NotifyPropertyChanged();
}
}

private string _captorClanHover = "";

[UIValue("captor-clan-hover"), UsedImplicitly]
private string CaptorClanHover {
get => _captorClanHover;
set {
if (_captorClanHover.Equals(value)) return;
_captorClanHover = value;
NotifyPropertyChanged();
}
}

private string _leaderboardCaptorClanStatusColor = "#FFFFFFDD";

[UIValue("captor-clan-text-color"), UsedImplicitly]
private string CaptorClanTextColor {
get => _leaderboardCaptorClanStatusColor;
set {
if (_leaderboardCaptorClanStatusColor.Equals(value)) return;
_leaderboardCaptorClanStatusColor = value;
NotifyPropertyChanged();
}
}

#endregion

#region Init/Dispose

private void Awake() {
_captorClanTag = Instantiate<ClanTag>(transform, false);
}

protected override void OnInitialize() {
_captorClanTag.CalculatePreferredWidth();
}

protected override void OnDispose() {
}

#endregion

#region Set

public void SetActive(bool value) {
CaptorClanActive = value;
}

public void SetValues(LeaderboardsCache.LeaderboardCacheEntry data) {
if (data.Clan != null) {
if (data.ClanRankingContested) {
// Clan Ranking was contested
_captorClanTag.Clear();
CaptorClanText = $"⚔ Contested";
CaptorClanTextColor = "#C0C0C0FF";
CaptorClanHover = "Set a score on this leaderboard to break the tie and capture it for your clan!";
} else if (data.Clan?.tag == null) {
// Map is not captured
_captorClanTag.Clear();
CaptorClanText = $"👑 Uncaptured";
CaptorClanTextColor = "#FFFFFFFF";
CaptorClanHover = "Set a score on this leaderboard to capture it for your clan!";
} else {
// Map is captured by a clan
CaptorClanText = $"👑 ";
CaptorClanTextColor = "#FFD700FF";
CaptorClanHover = "Clan with the highest weighted PP on this leaderboard!";
_captorClanTag.SetValue(data.Clan);
}
} else {
Plugin.Log.Error("Leaderboard Clan Captor missing!");
}
}
}

#endregion
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BeatLeader.DataManager;
using BeatLeader.DataManager;
using BeatLeader.Manager;
using BeatLeader.Models;
using BeatLeader.UIPatches;
Expand Down Expand Up @@ -29,13 +29,17 @@ internal class LeaderboardInfoPanel : ReeUIComponentV2 {
[UIValue("map-status"), UsedImplicitly]
private MapStatus _mapStatus = null!;

[UIValue("captor-clan"), UsedImplicitly]
private CaptorClan _captorClan;

private void Awake() {
_criteriaCheckbox = Instantiate<QualificationCheckbox>(transform, false);
_approvalCheckbox = Instantiate<QualificationCheckbox>(transform, false);
_menuButton = Instantiate<HeaderButton>(transform, false);
_websiteButton = Instantiate<HeaderButton>(transform, false);
_settingsButton = Instantiate<HeaderButton>(transform, false);
_mapStatus = Instantiate<MapStatus>(transform, false);
_captorClan = Instantiate<CaptorClan>(transform, false);
}

#endregion
Expand All @@ -51,6 +55,7 @@ protected override void OnInitialize() {
_websiteButton.OnClick += WebsiteButtonOnClick;
_settingsButton.OnClick += SettingsButtonOnClick;
LeaderboardsCache.CacheWasChangedEvent += OnCacheWasChanged;
PluginConfig.LeaderboardDisplaySettingsChangedEvent += OnLeaderboardDisplaySettingsChanged;
EnvironmentManagerPatch.EnvironmentTypeChangedEvent += OnMenuEnvironmentChanged;

LeaderboardState.AddSelectedBeatmapListener(OnSelectedBeatmapWasChanged);
Expand All @@ -63,12 +68,19 @@ protected override void OnDispose() {
LeaderboardsCache.CacheWasChangedEvent -= OnCacheWasChanged;
EnvironmentManagerPatch.EnvironmentTypeChangedEvent -= OnMenuEnvironmentChanged;
LeaderboardState.RemoveSelectedBeatmapListener(OnSelectedBeatmapWasChanged);
PluginConfig.LeaderboardDisplaySettingsChangedEvent -= OnLeaderboardDisplaySettingsChanged;
}

#endregion

#region Events

private void OnLeaderboardDisplaySettingsChanged(LeaderboardDisplaySettings settings)
{
_displayCaptorClan = settings.ClanCaptureDisplay;
UpdateVisuals();
}

private void OnMenuEnvironmentChanged(MenuEnvironmentManager.MenuEnvironmentType type) {
UpdateVisuals();
}
Expand All @@ -87,6 +99,7 @@ private void OnCacheWasChanged() {

private RankedStatus _rankedStatus;
private DiffInfo _difficultyInfo;
private bool _displayCaptorClan = PluginConfig.LeaderboardDisplaySettings.ClanCaptureDisplay;
private string? _websiteLink;

private void SetBeatmap(IDifficultyBeatmap? beatmap) {
Expand All @@ -108,6 +121,9 @@ private void SetBeatmap(IDifficultyBeatmap? beatmap) {
_difficultyInfo = data.DifficultyInfo;
_rankedStatus = FormatUtils.GetRankedStatus(data.DifficultyInfo);
_websiteLink = BLConstants.LeaderboardPage(data.LeaderboardId);
if (_rankedStatus is RankedStatus.Ranked) {
_captorClan.SetValues(data);
}

UpdateCheckboxes(data.QualificationInfo);
UpdateVisuals();
Expand Down Expand Up @@ -161,6 +177,7 @@ private void UpdateCheckboxes(QualificationInfo qualificationInfo) {
private void UpdateVisuals() {
_mapStatus.SetActive(_rankedStatus is not RankedStatus.Unknown);
_mapStatus.SetValues(_rankedStatus, _difficultyInfo);
_captorClan.SetActive(_displayCaptorClan && _rankedStatus is RankedStatus.Ranked);

QualificationActive = _rankedStatus is RankedStatus.Nominated or RankedStatus.Qualified or RankedStatus.Unrankable;
IsMenuButtonActive = EnvironmentManagerPatch.EnvironmentType is not MenuEnvironmentManager.MenuEnvironmentType.Lobby;
Expand Down
Loading

0 comments on commit 90a8857

Please sign in to comment.