Skip to content

Commit

Permalink
Added restart button for when mods are installed after an update
Browse files Browse the repository at this point in the history
  • Loading branch information
nike4613 committed Apr 23, 2019
1 parent 1882f5d commit b79f3c6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
15 changes: 8 additions & 7 deletions BSIPA-ModList/DownloadController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private IEnumerator StartUpdateCheck()

private enum States
{
Start, Checking, UpdatesFound, Downloading, Done
Start, Checking, UpdatesFound, Downloading, Done, DoneWithNoUpdates
}

private States _state = States.Start;
Expand All @@ -78,12 +78,13 @@ private States State
}
}

public bool CanCheck => State == States.Start || State == States.Done;
public bool CanCheck => State == States.Start || IsDone;
public bool CanDownload => State == States.UpdatesFound;
public bool CanReset => State == States.UpdatesFound;
public bool IsChecking => State == States.Checking;
public bool IsDownloading => State == States.Downloading;
public bool IsDone => State == States.Done;
public bool IsDone => State == States.Done || State == States.DoneWithNoUpdates;
public bool HadUpdates => State == States.Done;

public void Awake() => DontDestroyOnLoad(this);

Expand Down Expand Up @@ -147,7 +148,7 @@ private void UpdateCheckComplete(List<DependencyObject> found)
OnDownloaderListChanged?.Invoke();

if (downloads.Count == 0)
OnAllDownloadsCompleted();
OnAllDownloadsCompleted(false);
else if (SelfConfig.SelfConfigRef.Value.Updates.AutoUpdate)
StartDownloads();
}
Expand Down Expand Up @@ -204,12 +205,12 @@ private IEnumerator RemoveModFromList(DependencyObject obj)
Remove(obj);

if (downloads.Count == 0)
OnAllDownloadsCompleted();
OnAllDownloadsCompleted(true);
}

private void OnAllDownloadsCompleted()
private void OnAllDownloadsCompleted(bool hadUpdates)
{
State = States.Done;
State = hadUpdates ? States.Done : States.DoneWithNoUpdates;
}
}
}
28 changes: 23 additions & 5 deletions BSIPA-ModList/UI/ViewControllers/DownloadProgressViewController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using CustomUI.BeatSaber;
using CustomUI.Utilities;
Expand All @@ -19,11 +21,16 @@ internal class DownloadProgressViewController : VRUIViewController, TableView.ID

private Button _checkForUpdates;
private Button _downloadUpdates;
private Button _restartGame;
private TableView _currentlyUpdatingTableView;
private LevelListTableCell _songListTableCellInstance;
private Button _pageUpButton;
private Button _pageDownButton;

private const float TableXOffset = -20f;
private const float ButtonXOffset = 36f;
private static readonly Vector2 ButtonSize = new Vector2(40f, 10f);

protected override void DidActivate(bool firstActivation, ActivationType type)
{
if (firstActivation && type == ActivationType.AddedToHierarchy)
Expand All @@ -40,7 +47,7 @@ protected override void DidActivate(bool firstActivation, ActivationType type)
_pageUpButton = Instantiate(Resources.FindObjectsOfTypeAll<Button>().Last(x => (x.name == "PageUpButton")), rectTransform, false);
(_pageUpButton.transform as RectTransform).anchorMin = new Vector2(0.5f, 1f);
(_pageUpButton.transform as RectTransform).anchorMax = new Vector2(0.5f, 1f);
(_pageUpButton.transform as RectTransform).anchoredPosition = new Vector2(0f, -14f);
(_pageUpButton.transform as RectTransform).anchoredPosition = new Vector2(TableXOffset, -14f);
(_pageUpButton.transform as RectTransform).sizeDelta = new Vector2(40f, 10f);
_pageUpButton.interactable = true;
_pageUpButton.onClick.AddListener(delegate ()
Expand All @@ -51,7 +58,7 @@ protected override void DidActivate(bool firstActivation, ActivationType type)
_pageDownButton = Instantiate(Resources.FindObjectsOfTypeAll<Button>().First(x => (x.name == "PageDownButton")), rectTransform, false);
(_pageDownButton.transform as RectTransform).anchorMin = new Vector2(0.5f, 0f);
(_pageDownButton.transform as RectTransform).anchorMax = new Vector2(0.5f, 0f);
(_pageDownButton.transform as RectTransform).anchoredPosition = new Vector2(0f, 8f);
(_pageDownButton.transform as RectTransform).anchoredPosition = new Vector2(TableXOffset, 8f);
(_pageDownButton.transform as RectTransform).sizeDelta = new Vector2(40f, 10f);
_pageDownButton.interactable = true;
_pageDownButton.onClick.AddListener(delegate ()
Expand All @@ -75,7 +82,7 @@ protected override void DidActivate(bool firstActivation, ActivationType type)
(_currentlyUpdatingTableView.transform as RectTransform).anchorMin = new Vector2(0.3f, 0.5f);
(_currentlyUpdatingTableView.transform as RectTransform).anchorMax = new Vector2(0.7f, 0.5f);
(_currentlyUpdatingTableView.transform as RectTransform).sizeDelta = new Vector2(0f, 60f);
(_currentlyUpdatingTableView.transform as RectTransform).anchoredPosition = new Vector3(0f, -3f);
(_currentlyUpdatingTableView.transform as RectTransform).anchoredPosition = new Vector3(TableXOffset, -3f);

ReflectionUtil.SetPrivateField(_currentlyUpdatingTableView, "_pageUpButton", _pageUpButton);
ReflectionUtil.SetPrivateField(_currentlyUpdatingTableView, "_pageDownButton", _pageDownButton);
Expand All @@ -84,19 +91,29 @@ protected override void DidActivate(bool firstActivation, ActivationType type)
_currentlyUpdatingTableView.dataSource = this;
gobj.SetActive(true);

_checkForUpdates = BeatSaberUI.CreateUIButton(rectTransform, "CreditsButton", new Vector2(36f, -30f), new Vector2(20f, 10f), CheckUpdates, "Check for updates");
_checkForUpdates = BeatSaberUI.CreateUIButton(rectTransform, "CreditsButton", new Vector2(ButtonXOffset, -30f), ButtonSize, CheckUpdates, "Check for updates");
_checkForUpdates.interactable = DownloadController.Instance.CanCheck || DownloadController.Instance.CanReset;
_checkForUpdates.ToggleWordWrapping(false);

_downloadUpdates = BeatSaberUI.CreateUIButton(rectTransform, "CreditsButton", new Vector2(36f, -15f), new Vector2(20f, 10f), DownloadUpdates, "Download Updates");
_downloadUpdates = BeatSaberUI.CreateUIButton(rectTransform, "CreditsButton", new Vector2(ButtonXOffset, -19f), ButtonSize, DownloadUpdates, "Download Updates");
_downloadUpdates.interactable = DownloadController.Instance.CanDownload;
_downloadUpdates.ToggleWordWrapping(false);

_restartGame = BeatSaberUI.CreateUIButton(rectTransform, "CreditsButton", new Vector2(ButtonXOffset, -8f), ButtonSize, Restart, "Restart Game");
_restartGame.interactable = DownloadController.Instance.HadUpdates;
_restartGame.ToggleWordWrapping(false);

DownloadController.Instance.OnDownloaderListChanged += Refresh;
DownloadController.Instance.OnDownloadStateChanged += DownloaderStateChanged;
}
}

private void Restart()
{
Process.Start(Path.Combine(Environment.CurrentDirectory, Process.GetCurrentProcess().MainModule.FileName), Environment.CommandLine);
Application.Quit();
}

private void DownloadUpdates()
{
if (DownloadController.Instance.CanDownload)
Expand All @@ -116,6 +133,7 @@ private void DownloaderStateChanged()
{
_checkForUpdates.interactable = DownloadController.Instance.CanCheck || DownloadController.Instance.CanReset;
_downloadUpdates.interactable = DownloadController.Instance.CanDownload;
_restartGame.interactable = DownloadController.Instance.HadUpdates;
}

protected override void DidDeactivate(DeactivationType type)
Expand Down

0 comments on commit b79f3c6

Please sign in to comment.