Browse Source

Added restart button for when mods are installed after an update

pull/11/head 3.12.14
Anairkoen Schno 5 years ago
parent
commit
b79f3c6afa
2 changed files with 31 additions and 12 deletions
  1. +8
    -7
      BSIPA-ModList/DownloadController.cs
  2. +23
    -5
      BSIPA-ModList/UI/ViewControllers/DownloadProgressViewController.cs

+ 8
- 7
BSIPA-ModList/DownloadController.cs View File

@ -64,7 +64,7 @@ namespace BSIPA_ModList
private enum States
{
Start, Checking, UpdatesFound, Downloading, Done
Start, Checking, UpdatesFound, Downloading, Done, DoneWithNoUpdates
}
private States _state = States.Start;
@ -78,12 +78,13 @@ namespace BSIPA_ModList
}
}
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);
@ -147,7 +148,7 @@ namespace BSIPA_ModList
OnDownloaderListChanged?.Invoke();
if (downloads.Count == 0)
OnAllDownloadsCompleted();
OnAllDownloadsCompleted(false);
else if (SelfConfig.SelfConfigRef.Value.Updates.AutoUpdate)
StartDownloads();
}
@ -204,12 +205,12 @@ namespace BSIPA_ModList
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;
}
}
}

+ 23
- 5
BSIPA-ModList/UI/ViewControllers/DownloadProgressViewController.cs View File

@ -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;
@ -19,11 +21,16 @@ namespace BSIPA_ModList.UI.ViewControllers
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)
@ -40,7 +47,7 @@ namespace BSIPA_ModList.UI.ViewControllers
_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 ()
@ -51,7 +58,7 @@ namespace BSIPA_ModList.UI.ViewControllers
_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 ()
@ -75,7 +82,7 @@ namespace BSIPA_ModList.UI.ViewControllers
(_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);
@ -84,19 +91,29 @@ namespace BSIPA_ModList.UI.ViewControllers
_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)
@ -116,6 +133,7 @@ namespace BSIPA_ModList.UI.ViewControllers
{
_checkForUpdates.interactable = DownloadController.Instance.CanCheck || DownloadController.Instance.CanReset;
_downloadUpdates.interactable = DownloadController.Instance.CanDownload;
_restartGame.interactable = DownloadController.Instance.HadUpdates;
}
protected override void DidDeactivate(DeactivationType type)


Loading…
Cancel
Save