Skip to content

Commit

Permalink
Minor tweak
Browse files Browse the repository at this point in the history
- Added a warning view to display whenever the game is outdated or the system isn't connected to internet
- Other things, I dunno
  • Loading branch information
developer9998 committed Sep 14, 2023
1 parent 20bec34 commit e5d1a11
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 5 deletions.
46 changes: 42 additions & 4 deletions ComputerInterface/CustomComputer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class CustomComputer : MonoBehaviour, IInitializable
private ComputerViewPlaceholderFactory _viewFactory;

private MainMenuView _mainMenuView;
private WarnView _warningView;

private readonly List<CustomScreenInfo> _customScreenInfos = new List<CustomScreenInfo>();
private readonly Dictionary<MonitorLocation, CustomScreenInfo> _customScreenDict = new Dictionary<MonitorLocation, CustomScreenInfo>();
Expand All @@ -54,14 +55,18 @@ public IMonitor Monitor
MonitorScale = Tuple.Create(_monitor.Width, _monitor.Height);
}
}
public MonitorType MonitorType;
public static Tuple<int, int> MonitorScale = Tuple.Create(0, 0);

public Dictionary<MonitorType, IMonitor> _monitorDict = new Dictionary<MonitorType, IMonitor>();
private List<IMonitor> _monitors = new List<IMonitor>();
private IMonitor _monitor;
private List<IMonitor> _monitors = new List<IMonitor>();

public MonitorType MonitorType;
public Dictionary<MonitorType, IMonitor> _monitorDict = new Dictionary<MonitorType, IMonitor>();

private bool _internetConnected => Application.internetReachability != NetworkReachability.NotReachable;
private bool _connectionError;

enum MonitorLocation
enum MonitorLocation
{
Stump,
Igloo,
Expand All @@ -80,6 +85,7 @@ internal async void Construct(
CIConfig config,
AssetsLoader assetsLoader,
MainMenuView mainMenuView,
WarnView warningView,
ComputerViewPlaceholderFactory viewFactory,
List<IComputerModEntry> computerModEntries,
List<IQueueInfo> queues,
Expand All @@ -94,6 +100,7 @@ internal async void Construct(
_assetsLoader = assetsLoader;

_mainMenuView = mainMenuView;
_warningView = warningView;
_cachedViews.Add(typeof(MainMenuView), _mainMenuView);

_viewFactory = viewFactory;
Expand Down Expand Up @@ -134,6 +141,14 @@ private void ShowInitialView(MainMenuView view, List<IComputerModEntry> 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);
}
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions ComputerInterface/MainInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public override void InstallBindings()
Container.Bind<CommandHandler>().AsSingle();

Container.Bind<MainMenuView>().AsSingle();
Container.Bind<WarnView>().AsSingle();

Container.Bind<IComputerModEntry>().To<GameSettingsEntry>().AsSingle();
Container.Bind<IComputerModEntry>().To<ComputerSettingsEntry>().AsSingle();
Container.Bind<IComputerModEntry>().To<CommandLineEntry>().AsSingle();
Expand Down
2 changes: 1 addition & 1 deletion ComputerInterface/Views/CommandLineHelpView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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("<size=40>Nativate with the left/right arrow keys</size>").AppendLines(2);
str.Append("<size=40>Nativate using the Left/Right arrow keys</size>").AppendLines(2);
}

public void DrawCommands(StringBuilder str)
Expand Down
71 changes: 71 additions & 0 deletions ComputerInterface/Views/WarnView.cs
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit e5d1a11

Please sign in to comment.