-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #668 from GitEiko/development
Loadin Screen Controls
- Loading branch information
Showing
4 changed files
with
470 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
source/GameInterface/Services/LoadingScreen/Handlers/CoopLoadingScreenHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"; | ||
} | ||
} |
Oops, something went wrong.