diff --git a/ComputerInterface/CustomComputer.cs b/ComputerInterface/CustomComputer.cs index c5c552d..5721fbb 100644 --- a/ComputerInterface/CustomComputer.cs +++ b/ComputerInterface/CustomComputer.cs @@ -29,6 +29,7 @@ public class CustomComputer : MonoBehaviour, IInitializable private ComputerViewPlaceholderFactory _viewFactory; private MainMenuView _mainMenuView; + private WarnView _warningView; private readonly List _customScreenInfos = new List(); private readonly Dictionary _customScreenDict = new Dictionary(); @@ -54,14 +55,18 @@ public IMonitor Monitor MonitorScale = Tuple.Create(_monitor.Width, _monitor.Height); } } - public MonitorType MonitorType; public static Tuple MonitorScale = Tuple.Create(0, 0); - public Dictionary _monitorDict = new Dictionary(); - private List _monitors = new List(); private IMonitor _monitor; + private List _monitors = new List(); + + public MonitorType MonitorType; + public Dictionary _monitorDict = new Dictionary(); + + private bool _internetConnected => Application.internetReachability != NetworkReachability.NotReachable; + private bool _connectionError; - enum MonitorLocation + enum MonitorLocation { Stump, Igloo, @@ -80,6 +85,7 @@ internal async void Construct( CIConfig config, AssetsLoader assetsLoader, MainMenuView mainMenuView, + WarnView warningView, ComputerViewPlaceholderFactory viewFactory, List computerModEntries, List queues, @@ -94,6 +100,7 @@ internal async void Construct( _assetsLoader = assetsLoader; _mainMenuView = mainMenuView; + _warningView = warningView; _cachedViews.Add(typeof(MainMenuView), _mainMenuView); _viewFactory = viewFactory; @@ -134,6 +141,14 @@ private void ShowInitialView(MainMenuView view, List computer pluginInfo.Instance.enabled = false; } + if (PhotonNetworkController.Instance.wrongVersion) + { + _computerViewController.SetView(_warningView, new object[] {new WarnInfo() + { + _warnType = WarnType.Outdated + }}); + return; + } _computerViewController.SetView(view, null); view.ShowEntries(computerModEntries); } @@ -150,6 +165,29 @@ private void Update() key.Fetch(); } } + + // Make sure the computer is ready + if (_computerViewController.CurrentComputerView != null) + { + // Check to see if our connection is off + if (!_internetConnected && !_connectionError) + { + _connectionError = true; + _computerViewController.SetView(_warningView, new object[] {new WarnInfo() + { + _warnType = WarnType.NoInternet + }}); + _gorillaComputer.UpdateFailureText("NO WIFI OR LAN CONNECTION DETECTED."); + } + + // Check to see if we're back online + if (_internetConnected && _connectionError) + { + _connectionError = false; + _computerViewController.SetView(_computerViewController.CurrentComputerView == _warningView ? _mainMenuView : _computerViewController.CurrentComputerView, null); + _gorillaComputer.InvokeMethod("RestoreFromFailureState", null); + } + } } public void SetText(string text) diff --git a/ComputerInterface/MainInstaller.cs b/ComputerInterface/MainInstaller.cs index e52961c..bca6b2c 100644 --- a/ComputerInterface/MainInstaller.cs +++ b/ComputerInterface/MainInstaller.cs @@ -25,6 +25,8 @@ public override void InstallBindings() Container.Bind().AsSingle(); Container.Bind().AsSingle(); + Container.Bind().AsSingle(); + Container.Bind().To().AsSingle(); Container.Bind().To().AsSingle(); Container.Bind().To().AsSingle(); diff --git a/ComputerInterface/Views/CommandLineHelpView.cs b/ComputerInterface/Views/CommandLineHelpView.cs index 1ed4bc6..96264df 100644 --- a/ComputerInterface/Views/CommandLineHelpView.cs +++ b/ComputerInterface/Views/CommandLineHelpView.cs @@ -66,7 +66,7 @@ public void DrawHeader(StringBuilder str) { str.BeginColor("ffffff50").Append("== ").EndColor(); str.Append("Command Line Info").BeginColor("ffffff50").Append(" ==").EndColor().AppendLine(); - str.Append("Nativate with the left/right arrow keys").AppendLines(2); + str.Append("Nativate using the Left/Right arrow keys").AppendLines(2); } public void DrawCommands(StringBuilder str) diff --git a/ComputerInterface/Views/WarnView.cs b/ComputerInterface/Views/WarnView.cs new file mode 100644 index 0000000..fe953d8 --- /dev/null +++ b/ComputerInterface/Views/WarnView.cs @@ -0,0 +1,71 @@ +using System.Text; +using ComputerInterface.ViewLib; + +namespace ComputerInterface.Views +{ + internal class WarnView : ComputerView + { + internal static WarnInfo _currentWarn; + + public override void OnShow(object[] args) + { + base.OnShow(args); + + _currentWarn = (WarnInfo)args[0]; // No way I'm actually using these arguments + Redraw(); + } + + public void Redraw() + { + StringBuilder str = new StringBuilder(); + str.BeginColor("ffffff50").Append("== ").EndColor(); + str.Append("Warning").BeginColor("ffffff50").Append(" ==").EndColor().AppendLines(2); + + switch (_currentWarn._warnType) + { + case WarnType.General: + str.AppendLine("Gorilla Tag has thrown a warning:").AppendLine(); + str.Append(_currentWarn._warnParams[0]); + break; + case WarnType.Outdated: + str.AppendLine("You aren't on the latest version of Gorilla Tag, please update your game to continue playing with others."); + break; + case WarnType.NoInternet: + str.AppendLine("You aren't connected to an internet connection, please connect to a valid connection to continue playing with others."); + break; + case WarnType.TemporaryBan: + str.AppendLine($"You have been temporarily banned. You will not be able to play with others until the ban expires."); + str.Append("Reason: ").Append(_currentWarn._warnParams[0]).AppendLine(); + str.Append("Hours remaining: ").Append(_currentWarn._warnParams[1]); + break; + case WarnType.PermanentBan: + str.AppendLine($"You have been permanently banned."); + str.Append("Reason: ").Append(_currentWarn._warnParams[0]); + break; + } + + Text = str.ToString(); + } + + public override void OnKeyPressed(EKeyboardKey key) + { + if (key != EKeyboardKey.Back) return; + ReturnToMainMenu(); + } + } + + internal struct WarnInfo + { + public WarnType _warnType; + public object[] _warnParams; + } + + internal enum WarnType + { + General, + Outdated, + NoInternet, + TemporaryBan, + PermanentBan + } +}