Skip to content

Commit bb1c616

Browse files
authored
Merge pull request #152 from EnderdracheLP/1.16.3
Added Download Progress Bar and warning dialog for Quickplay customs
2 parents 3b6420a + 8017437 commit bb1c616

File tree

7 files changed

+100
-22
lines changed

7 files changed

+100
-22
lines changed

MultiplayerExtensions/Downloader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static bool TryGetDownload(string levelId, out Task<IPreviewBeatmapLevel?
4949
byte[]? beatmapBytes = await bm.Versions.ToList().Find(version => {
5050
Plugin.Log?.Info($"Version: '{version.Key}' '{version.Hash}'");
5151
return version.Hash.ToUpper() == hash;
52-
}).DownloadZIP();
52+
}).DownloadZIP(progress: UI.CenterScreenLoadingPanel.self);
5353
#if DEBUG
5454
TimeSpan delay = TimeSpan.FromSeconds(Plugin.Config.DebugConfig?.MinDownloadTime ?? 0) - TimeSpan.FromMilliseconds(sw.ElapsedMilliseconds);
5555
if (delay > TimeSpan.Zero)

MultiplayerExtensions/Extensions/ExtendedGameStateController.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ public async override void HandleMultiplayerLevelLoaderCountdownFinished(IPrevie
115115
_levelLoadSyncCts = null;
116116

117117
Plugin.Log?.Debug("All players ready, starting game.");
118+
119+
Plugin.Log?.Debug($"Null Checking previewBeatmapLevel: '{(previewBeatmapLevel == null ? "null" : "not null")}'");
120+
Plugin.Log?.Debug($"Null Checking beatmapDifficulty: '{beatmapDifficulty}'");
121+
Plugin.Log?.Debug($"Null Checking beatmapCharacteristic: '{(beatmapCharacteristic == null ? "null" : "not null")}'");
122+
Plugin.Log?.Debug($"Null Checking difficultyBeatmap: '{(difficultyBeatmap == null ? "null" : "not null")}'");
123+
Plugin.Log?.Debug($"Null Checking gameplayModifiers: '{(gameplayModifiers == null ? "null" : "not null")}'");
124+
118125
base.HandleMultiplayerLevelLoaderCountdownFinished(previewBeatmapLevel, beatmapDifficulty, beatmapCharacteristic, difficultyBeatmap, gameplayModifiers);
119126
}
120127
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using HarmonyLib;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using IPA.Utilities;
8+
using HMUI;
9+
10+
namespace MultiplayerExtensions.HarmonyPatches
11+
{
12+
[HarmonyPatch(typeof(MultiplayerModeSelectionFlowCoordinator), nameof(MultiplayerModeSelectionFlowCoordinator.HandleJoinQuickPlayViewControllerDidFinish), MethodType.Normal)]
13+
internal class MultiplayerModeSelectionFlowCoordinatorPatch
14+
{
15+
static bool Prefix(MultiplayerModeSelectionFlowCoordinator __instance, bool success, JoinQuickPlayViewController ____joinQuickPlayViewController, SimpleDialogPromptViewController ____simpleDialogPromptViewController, SongPackMaskModelSO ____songPackMaskModel)
16+
{
17+
string levelPackName = ____joinQuickPlayViewController.multiplayerModeSettings.quickPlaySongPackMaskSerializedName;
18+
Plugin.Log?.Debug(levelPackName);
19+
if (success && ____songPackMaskModel.ToSongPackMask(levelPackName).Contains("custom_levelpack_CustomLevels"))
20+
{
21+
____simpleDialogPromptViewController.Init(
22+
"Custom Song Quickplay",
23+
"<color=#EB4949>This category includes songs of varying difficulty.\nIt may be more enjoyable to play in a private lobby with friends.",
24+
"Continue",
25+
"Cancel",
26+
delegate (int btnId)
27+
{
28+
switch (btnId)
29+
{
30+
default:
31+
case 0: // Continue
32+
__instance.HandleJoinQuickPlayViewControllerDidFinish(true);
33+
break;
34+
case 1: // Cancel
35+
__instance.InvokeMethod<object, MultiplayerModeSelectionFlowCoordinator>("ReplaceTopViewController", new object[] {
36+
____joinQuickPlayViewController, null, ViewController.AnimationType.In, ViewController.AnimationDirection.Vertical
37+
});
38+
break;
39+
}
40+
}
41+
);
42+
__instance.InvokeMethod<object, MultiplayerModeSelectionFlowCoordinator>("ReplaceTopViewController", new object[] {
43+
____simpleDialogPromptViewController, null, ViewController.AnimationType.In, ViewController.AnimationDirection.Vertical
44+
});
45+
return false;
46+
}
47+
return true;
48+
}
49+
}
50+
}

MultiplayerExtensions/MultiplayerExtensions.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
<DisableZipRelease>True</DisableZipRelease>
3636
</PropertyGroup>
3737
<ItemGroup>
38-
<None Remove="UI\CenterScreenLoading.bsml" />
3938
<None Remove="UI\LobbySetupPanel.bsml" />
4039
<None Remove="UI\settings.bsml" />
4140
</ItemGroup>
@@ -204,7 +203,6 @@
204203
</ItemGroup>
205204
<ItemGroup>
206205
<EmbeddedResource Include="manifest.json" />
207-
<EmbeddedResource Include="UI\CenterScreenLoading.bsml" />
208206
<EmbeddedResource Include="UI\LobbySetupPanel.bsml" />
209207
<EmbeddedResource Include="UI\settings.bsml" />
210208
<None Remove="Assets\IconSteam64.png" />

MultiplayerExtensions/UI/CenterScreenLoading.bsml

Lines changed: 0 additions & 4 deletions
This file was deleted.

MultiplayerExtensions/UI/CenterScreenLoadingPanel.cs

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,72 @@
11
using BeatSaberMarkupLanguage.Attributes;
22
using BeatSaberMarkupLanguage.ViewControllers;
3+
using System;
4+
using System.Linq;
35
using UnityEngine;
46
using UnityEngine.UI;
57
using Zenject;
68

79
namespace MultiplayerExtensions.UI
810
{
9-
class CenterScreenLoadingPanel : BSMLResourceViewController
11+
class CenterScreenLoadingPanel : MonoBehaviour, IProgress<double>
1012
{
11-
public override string ResourceName => "MultiplayerExtensions.UI.CenterScreenLoading.bsml";
1213
private IMultiplayerSessionManager sessionManager;
1314
private ILobbyGameStateController gameStateController;
1415
private CenterStageScreenController screenController;
16+
private LoadingControl? loadingControl;
17+
private bool isDownloading;
18+
public static CenterScreenLoadingPanel? self { get; private set; }
1519

1620
[Inject]
1721
internal void Inject(IMultiplayerSessionManager sessionManager, ILobbyGameStateController gameStateController, CenterStageScreenController screenController)
1822
{
23+
self = this;
1924
this.sessionManager = sessionManager;
2025
this.gameStateController = gameStateController;
2126
this.screenController = screenController;
22-
base.DidActivate(true, false, true);
2327

24-
loadIndicator.color = Color.white;
25-
}
26-
27-
[UIComponent("LoadingDisplay")]
28-
public RectTransform loadingDisplay;
28+
BeatSaberMarkupLanguage.Tags.VerticalLayoutTag verticalTag = new BeatSaberMarkupLanguage.Tags.VerticalLayoutTag();
29+
GameObject vertical = verticalTag.CreateObject(transform);
30+
(vertical.transform as RectTransform).sizeDelta = new Vector2(60, 60);
31+
(vertical.transform as RectTransform).anchoredPosition = new Vector2(0.0f, -30.0f);
32+
var layout = vertical.AddComponent<LayoutElement>().minWidth = 60;
2933

30-
[UIComponent("LoadIndicator")]
31-
public Image loadIndicator;
34+
GameObject existingLoadingControl = Resources.FindObjectsOfTypeAll<LoadingControl>().First().gameObject;
35+
GameObject loadingControlGameObject = GameObject.Instantiate(existingLoadingControl, vertical.transform);
36+
loadingControl = loadingControlGameObject.GetComponent<LoadingControl>();
37+
loadingControl.Hide();
38+
}
3239

3340
public void Update()
3441
{
35-
if (screenController.countdownShown && sessionManager.syncTime >= gameStateController.startTime && gameStateController.levelStartInitiated)
42+
if (isDownloading)
3643
{
37-
if (loadingDisplay != null)
38-
loadingDisplay.gameObject.SetActive(true);
44+
return;
45+
}
46+
else if (screenController.countdownShown && sessionManager.syncTime >= gameStateController.startTime && gameStateController.levelStartInitiated)
47+
{
48+
if (loadingControl != null)
49+
loadingControl.ShowLoading("Loading...");
3950
}
4051
else
4152
{
42-
if (loadingDisplay != null)
43-
loadingDisplay.gameObject.SetActive(false);
53+
if (loadingControl != null)
54+
loadingControl.Hide();
55+
}
56+
}
57+
58+
public void OnDisable()
59+
{
60+
if (loadingControl != null)
61+
loadingControl.Hide();
62+
}
63+
64+
public void Report(double value)
65+
{
66+
isDownloading = (value < 1.0);
67+
if (loadingControl != null)
68+
{
69+
loadingControl.ShowDownloadingProgress("Downloading...", (float)value);
4470
}
4571
}
4672
}

MultiplayerExtensions/Utilities/Harmony/HarmonyManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ static HarmonyManager()
4949
AddDefaultPatch<PacketErrorLoggingPatch>();
5050
//AddDefaultPatch<YeetPredictionsPatch>();
5151
AddDefaultPatch<DisableAvatarRestrictions>();
52+
AddDefaultPatch<MultiplayerModeSelectionFlowCoordinatorPatch>();
5253
}
5354

5455
private static void AddDefaultPatch<T>() where T : class

0 commit comments

Comments
 (0)