Updated to Interface Event

Changed SendConsoleEvent to SendInterfaceEvent to make functionality clearer. Added InterfaceProcess virtual to EventHandlers. Added CCMD for sending interface events.
This commit is contained in:
Boondorl 2022-11-11 13:44:26 -05:00 committed by Christoph Oelckers
commit 7517b64aee
4 changed files with 69 additions and 26 deletions

View file

@ -516,12 +516,12 @@ bool EventManager::Responder(const event_t* ev)
return false;
}
void EventManager::Console(int player, FString name, int arg1, int arg2, int arg3, bool manual)
void EventManager::Console(int player, FString name, int arg1, int arg2, int arg3, bool manual, bool ui)
{
if (ShouldCallStatic(false)) staticEventManager.Console(player, name, arg1, arg2, arg3, manual);
if (ShouldCallStatic(false)) staticEventManager.Console(player, name, arg1, arg2, arg3, manual, ui);
for (DStaticEventHandler* handler = FirstEventHandler; handler; handler = handler->next)
handler->ConsoleProcess(player, name, arg1, arg2, arg3, manual);
handler->ConsoleProcess(player, name, arg1, arg2, arg3, manual, ui);
}
void EventManager::RenderOverlay(EHudState state)
@ -686,7 +686,7 @@ DEFINE_ACTION_FUNCTION(DEventHandler, SendNetworkEvent)
ACTION_RETURN_BOOL(currentVMLevel->localEventManager->SendNetworkEvent(name, arg1, arg2, arg3, false));
}
DEFINE_ACTION_FUNCTION(DEventHandler, SendConsoleEvent)
DEFINE_ACTION_FUNCTION(DEventHandler, SendInterfaceEvent)
{
PARAM_PROLOGUE;
PARAM_INT(playerNum);
@ -696,7 +696,7 @@ DEFINE_ACTION_FUNCTION(DEventHandler, SendConsoleEvent)
PARAM_INT(arg3);
if (playerNum == consoleplayer)
primaryLevel->localEventManager->Console(-1, name, arg1, arg2, arg3, false);
primaryLevel->localEventManager->Console(-1, name, arg1, arg2, arg3, false, true);
return 0;
}
@ -1158,26 +1158,49 @@ void DStaticEventHandler::PostUiTick()
}
}
void DStaticEventHandler::ConsoleProcess(int player, FString name, int arg1, int arg2, int arg3, bool manual)
void DStaticEventHandler::ConsoleProcess(int player, FString name, int arg1, int arg2, int arg3, bool manual, bool ui)
{
if (player < 0)
{
IFVIRTUAL(DStaticEventHandler, ConsoleProcess)
if (ui)
{
// don't create excessive DObjects if not going to be processed anyway
if (isEmpty(func)) return;
FConsoleEvent e;
IFVIRTUAL(DStaticEventHandler, InterfaceProcess)
{
// don't create excessive DObjects if not going to be processed anyway
if (isEmpty(func)) return;
FConsoleEvent e;
//
e.Player = player;
e.Name = name;
e.Args[0] = arg1;
e.Args[1] = arg2;
e.Args[2] = arg3;
e.IsManual = manual;
//
e.Player = player;
e.Name = name;
e.Args[0] = arg1;
e.Args[1] = arg2;
e.Args[2] = arg3;
e.IsManual = manual;
VMValue params[2] = { (DStaticEventHandler*)this, &e };
VMCall(func, params, 2, nullptr, 0);
VMValue params[2] = { (DStaticEventHandler*)this, &e };
VMCall(func, params, 2, nullptr, 0);
}
}
else
{
IFVIRTUAL(DStaticEventHandler, ConsoleProcess)
{
// don't create excessive DObjects if not going to be processed anyway
if (isEmpty(func)) return;
FConsoleEvent e;
//
e.Player = player;
e.Name = name;
e.Args[0] = arg1;
e.Args[1] = arg2;
e.Args[2] = arg3;
e.IsManual = manual;
VMValue params[2] = { (DStaticEventHandler*)this, &e };
VMCall(func, params, 2, nullptr, 0);
}
}
}
else
@ -1253,6 +1276,25 @@ void DStaticEventHandler::OnDestroy()
// console stuff
// this is kinda like puke, except it distinguishes between local events and playsim events.
CCMD(interfaceevent)
{
int argc = argv.argc();
if (argc < 2 || argc > 5)
{
Printf("Usage: interfaceevent <name> [arg1] [arg2] [arg3]\n");
}
else
{
int arg[3] = { 0, 0, 0 };
int argn = min<int>(argc - 2, countof(arg));
for (int i = 0; i < argn; i++)
arg[i] = atoi(argv[2 + i]);
// call locally
primaryLevel->localEventManager->Console(-1, argv[1], arg[0], arg[1], arg[2], true, true);
}
}
CCMD(event)
{
int argc = argv.argc();
@ -1268,7 +1310,7 @@ CCMD(event)
for (int i = 0; i < argn; i++)
arg[i] = atoi(argv[2 + i]);
// call locally
primaryLevel->localEventManager->Console(-1, argv[1], arg[0], arg[1], arg[2], true);
primaryLevel->localEventManager->Console(-1, argv[1], arg[0], arg[1], arg[2], true, false);
}
}