Skip to content

Commit

Permalink
Merge pull request #668 from GitEiko/development
Browse files Browse the repository at this point in the history
Loadin Screen Controls
  • Loading branch information
garrettluskey authored Dec 15, 2023
2 parents 88a061b + 16d566c commit 9b0e4e8
Show file tree
Hide file tree
Showing 4 changed files with 470 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System.Collections.Generic;
using Common.Messaging;
using GameInterface.Services.LoadingScreen.Interfaces;
using GameInterface.Services.LoadingScreen.Messages;
using TaleWorlds.Library;

namespace GameInterface.Services.LoadingScreen.Handlers;

/// <summary>
/// Handler for the CoopLoadingScreen
/// </summary>
/// <remarks>
/// To show the loading screen, just use
/// MessageBroker.Instance.Publish(this, new ShowLoadingScreen());
/// To hide it, use
/// MessageBroker.Instance.Publish(this, new HideLoadingScreen());
/// </remarks>
public class CoopLoadingScreenHandler : IHandler
{
private readonly CoopLoadingScreen loadingScreen = CoopLoadingScreen.Instance;
private readonly IMessageBroker messageBroker;

public CoopLoadingScreenHandler(IMessageBroker messageBroker)
{
this.messageBroker = messageBroker;

messageBroker.Subscribe<ShowLoadingScreen>(Handle);
messageBroker.Subscribe<HideLoadingScreen>(Handle);
}

private void Handle(MessagePayload<ShowLoadingScreen> payload)
{
loadingScreen.Initialize();
loadingScreen.EnableLoadingWindow();
}

private void Handle(MessagePayload<HideLoadingScreen> payload)
{
loadingScreen.DisableLoadingWindow();
}

public void Dispose()
{
messageBroker.Unsubscribe<ShowLoadingScreen>(Handle);
messageBroker.Unsubscribe<HideLoadingScreen>(Handle);
}

/*The part below is to test the show and hide mechanics in console, can be used as follows in console:
* tutorial.testShow
* tutorial.testHide */

[CommandLineFunctionality.CommandLineArgumentFunction("ShowLoadingScreen", "Coop.Debug")]
public static string testShow(List<string> strings)
{
MessageBroker.Instance.Publish(null, new ShowLoadingScreen());
return "Command Executed!";
}

[CommandLineFunctionality.CommandLineArgumentFunction("HideLoadingScreen", "Coop.Debug")]
public static string testHide(List<string> strings)
{
MessageBroker.Instance.Publish(null, new HideLoadingScreen());
return "Command Executed!";
}
}
Loading

0 comments on commit 9b0e4e8

Please sign in to comment.