TechbloxModdingAPI/GamecraftModdingAPI/Events/MenuActivatedPatch.cs

41 lines
1.3 KiB
C#
Raw Normal View History

2019-12-14 04:42:55 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2019-12-14 04:42:55 +00:00
using Harmony;
using RobocraftX;
using Svelto.ECS;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Events
{
2019-12-14 18:52:24 +00:00
/// <summary>
/// Patch of RobocraftX.FullGameCompositionRoot.ActivateMenu()
/// </summary>
2019-12-14 04:42:55 +00:00
[HarmonyPatch(typeof(FullGameCompositionRoot), "ActivateMenu")]
2019-12-14 18:52:24 +00:00
class MenuActivatedPatch
2019-12-14 04:42:55 +00:00
{
private static bool firstLoad = true;
public static void Postfix(ref EnginesRoot ____frontEndEnginesRoot)
{
// register custom menu engines
MenuEngineManager.RegisterEngines(____frontEndEnginesRoot);
2019-12-14 04:42:55 +00:00
// A new EnginesRoot is always created when ActivateMenu is called
// so all event emitters and handlers must be re-registered.
2019-12-15 07:20:20 +00:00
EventManager.RegisterEngines(____frontEndEnginesRoot);
2019-12-14 04:42:55 +00:00
if (firstLoad)
{
firstLoad = false;
Logging.Log("Dispatching App Init event");
2019-12-15 07:20:20 +00:00
EventManager.GetEventEmitter("GamecraftModdingAPIApplicationInitializedEventEmitter").Emit();
2019-12-14 04:42:55 +00:00
}
Logging.Log("Dispatching Menu Activated event");
2019-12-15 07:20:20 +00:00
EventManager.GetEventEmitter("GamecraftModdingAPIMenuActivatedEventEmitter").Emit();
2019-12-14 04:42:55 +00:00
}
}
}