Skip to content

Commit

Permalink
Merge pull request #15 from Meivyn/fix/navigation
Browse files Browse the repository at this point in the history
Fix navigation issues
  • Loading branch information
Sirspam authored Sep 2, 2023
2 parents e52cc1b + d4e3c6b commit dabb957
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 78 deletions.
12 changes: 6 additions & 6 deletions LeaderboardCore/Managers/CustomLeaderboardManager.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using LeaderboardCore.Interfaces;
using LeaderboardCore.Models;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Reflection;

namespace LeaderboardCore.Managers
{
/// <summary>
/// Class for the Leaderboard Manager. Use it to register and unregister yourself. Requires Zenject to recieve the instance (installed in menu scene).
/// Class for the Leaderboard Manager. Use it to register and unregister yourself. Requires Zenject to receive the instance (installed in menu scene).
/// </summary>
public class CustomLeaderboardManager
{
Expand All @@ -31,7 +29,7 @@ public void Register(CustomLeaderboard customLeaderboard)
{
customLeaderboard.pluginId = Assembly.GetCallingAssembly().GetName().Name;
}

if (!customLeaderboardsById.ContainsKey(customLeaderboard.LeaderboardId))
{
customLeaderboardsById[customLeaderboard.LeaderboardId] = customLeaderboard;
Expand All @@ -45,8 +43,10 @@ public void Register(CustomLeaderboard customLeaderboard)
/// </summary>
public void Unregister(CustomLeaderboard customLeaderboard)
{
customLeaderboardsById.Remove(customLeaderboard.LeaderboardId);
OnLeaderboardsChanged();
if (customLeaderboardsById.Remove(customLeaderboard.LeaderboardId))
{
OnLeaderboardsChanged();
}
}

private void OnLeaderboardsChanged()
Expand Down
10 changes: 5 additions & 5 deletions LeaderboardCore/Managers/MultiplayerLeaderboardManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@ private void ShowLeaderboard(IDifficultyBeatmap difficultyBeatmap)
}

_platformLeaderboardViewController.SetData(_levelSelectionNavigationController.selectedDifficultyBeatmap);

_mainFlowCoordinator.YoungestChildFlowCoordinatorOrSelf().InvokeMethod<object, FlowCoordinator>("SetRightScreenViewController", _platformLeaderboardViewController, ViewController.AnimationType.In);
_serverPlayerListViewController.gameObject.SetActive(false);
_serverPlayerListViewController.DeactivateGameObject();
}

private void HideLeaderboard()
{
_mainFlowCoordinator.YoungestChildFlowCoordinatorOrSelf().InvokeMethod<object, FlowCoordinator>("SetRightScreenViewController", null, ViewController.AnimationType.Out);
}

private void LevelSelectionNavigationControllerOndidChangeLevelDetailContentEvent(LevelSelectionNavigationController levelSelectionNavigationController, StandardLevelDetailViewController.ContentType contentType)
{
if (contentType == StandardLevelDetailViewController.ContentType.OwnedAndReady)
{
ShowLeaderboard(levelSelectionNavigationController.selectedDifficultyBeatmap);
return;
}

ShowLeaderboard(null);
}

Expand All @@ -65,7 +65,7 @@ public void Initialize()
_levelSelectionNavigationController.didChangeDifficultyBeatmapEvent += LevelSelectionNavigationControllerOndidChangeDifficultyBeatmapEvent;
_levelSelectionNavigationController.didChangeLevelDetailContentEvent += LevelSelectionNavigationControllerOndidChangeLevelDetailContentEvent;
}

public void Dispose()
{
_levelSelectionNavigationController.didChangeDifficultyBeatmapEvent -= LevelSelectionNavigationControllerOndidChangeDifficultyBeatmapEvent;
Expand Down
26 changes: 14 additions & 12 deletions LeaderboardCore/Models/CustomLeaderboard.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections;
using BeatSaberMarkupLanguage.FloatingScreen;
using HMUI;
using LeaderboardCore.Utilities;
Expand All @@ -21,28 +20,31 @@ public abstract class CustomLeaderboard
/// The ViewController for the leaderboard itself.
/// </summary>
protected abstract ViewController leaderboardViewController { get; }

/// <summary>
/// The ID for the leaderboard.
/// Must be a unique string if the mod has multiple leaderboards.
/// </summary>
protected virtual string leaderboardId { get; } = "";

internal string pluginId;

internal string LeaderboardId => $"{pluginId}{leaderboardId}";

internal void Show(FloatingScreen panelScreen, Vector3 leaderboardPosition, PlatformLeaderboardViewController platformLeaderboardViewController)
{
panelScreen.gameObject.SetActive(true);

if (!panelScreen.gameObject.activeSelf)
{
panelScreen.gameObject.SetActive(true);
}

if (!panelScreen.isActiveAndEnabled)
{
SharedCoroutineStarter.Instance.StartCoroutine(WaitForScreen(panelScreen, leaderboardPosition,
SharedCoroutineStarter.instance.StartCoroutine(WaitForScreen(panelScreen, leaderboardPosition,
platformLeaderboardViewController));
return;
}

if (panelViewController != null)
{
panelScreen.SetRootViewController(panelViewController, ViewController.AnimationType.None);
Expand All @@ -69,7 +71,7 @@ internal void Show(FloatingScreen panelScreen, Vector3 leaderboardPosition, Plat
leaderboardViewController.transform.SetParent(platformLeaderboardViewController.transform);
}
}

private IEnumerator WaitForScreen(FloatingScreen panelScreen, Vector3 leaderboardPosition,
PlatformLeaderboardViewController platformLeaderboardViewController)
{
Expand All @@ -90,11 +92,11 @@ internal void Hide(FloatingScreen panelScreen)
}
else
{
panelViewController.gameObject.SetActive(false);
panelViewController.DeactivateGameObject();
}
}

if (leaderboardViewController != null && leaderboardViewController.isActivated)
if (leaderboardViewController != null)
{
leaderboardViewController.__Deactivate(false, true, false);
}
Expand Down
21 changes: 12 additions & 9 deletions LeaderboardCore/Models/ScoreSaberCustomLeaderboard.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using LeaderboardCore.Interfaces;
using LeaderboardCore.Interfaces;
using UnityEngine;
using Zenject;

Expand All @@ -15,9 +14,13 @@ internal class ScoreSaberCustomLeaderboard : INotifyScoreSaberActivate

private Transform ssPanelScreenTransform;
private Vector3 ssPanelScreenPosition;


private Vector3 hiddenPosition;

public void OnScoreSaberActivated()
{
hiddenPosition = new Vector3(-999, -999, -999);

if (ssLeaderboardElementsTransform == null)
{
ssLeaderboardElementsTransform = platformLeaderboardViewController.transform.Find("ScoreSaberLeaderboardElements");
Expand All @@ -30,23 +33,23 @@ public void OnScoreSaberActivated()
ssPanelScreenPosition = ssPanelScreenTransform.localPosition;
}
}

public void YeetSS()
{
if (ssLeaderboardElementsTransform != null && ssPanelScreenTransform != null)
if (ssLeaderboardElementsTransform != null && ssPanelScreenTransform != null && ssLeaderboardElementsTransform.localPosition != hiddenPosition)
{
ssLeaderboardElementsTransform.localPosition = new Vector3(-999, -999);
ssPanelScreenTransform.localPosition = new Vector3(-999, -999);
ssLeaderboardElementsTransform.localPosition = hiddenPosition;
ssPanelScreenTransform.localPosition = hiddenPosition;
}
}

public void UnYeetSS()
{
if (ssLeaderboardElementsTransform != null && ssPanelScreenTransform != null)
if (ssLeaderboardElementsTransform != null && ssPanelScreenTransform != null && ssLeaderboardElementsTransform.localPosition != ssLeaderboardElementsPosition)
{
ssLeaderboardElementsTransform.localPosition = ssLeaderboardElementsPosition;
ssPanelScreenTransform.localPosition = ssPanelScreenPosition;
}
}
}
}
}
Loading

0 comments on commit dabb957

Please sign in to comment.