Pazyryk
Deity
- Joined
- Jun 13, 2008
- Messages
- 3,584
To be specific, I need to run some Lua whenever a player opens the in-game menu (the one you get when you press esc or the MENU link in top panel). And I want to do it without modding GameMenu.lua itself.
Does anyone know how to do this? I think I'm supposed to be able to do this with ContextPtr, but I'm not very clear how to do that from outside a Lua state.
(I could do it by intercepting ESC and modding top panel, but I'd prefer a cleaner solution.)
Edit: well, I'm playing with LookUpControl but can't seem to get it for GameMenu. It's certainly loaded because I'm in Fire Tuner.
> print(ContextPtr:LookUpControl("/InGame/WorldView/MiniMapPanel"))
EaMain: LuaContext: 1A4849A0
> print(ContextPtr:LookUpControl("/InGame/Menus/GameMenu"))
EaMain: nil
Even if I get that working, I'm not sure what to do with it. I could SetShowHideHandler(MyFunction), but then I will have removed its own OnShowHide function.
Edit2: Darn, I thought the menu might be a kind of popup. But it isn't. Added this in Fire Tuner and it prints for other popups like social policies, but not the Game Menu:
Edit3: OK, I got a context pointer:
> ContextPtr:LookUpControl("/InGame/GameMenu")
LuaContext: 1A2F26A0
I'm not sure what to do with it though...
Edit4: I got it!
ContextPtr:LookUpControl("/InGame/GameMenu"):SetShowHideHandler(function(isHide, isInit) print(isHide, isInit) end)
Prints false nil whenever I enter the menu.
Does anyone know how to do this? I think I'm supposed to be able to do this with ContextPtr, but I'm not very clear how to do that from outside a Lua state.
(I could do it by intercepting ESC and modding top panel, but I'd prefer a cleaner solution.)
> print(ContextPtr:LookUpControl("/InGame/WorldView/MiniMapPanel"))
EaMain: LuaContext: 1A4849A0
> print(ContextPtr:LookUpControl("/InGame/Menus/GameMenu"))
EaMain: nil
Even if I get that working, I'm not sure what to do with it. I could SetShowHideHandler(MyFunction), but then I will have removed its own OnShowHide function.
Edit2: Darn, I thought the menu might be a kind of popup. But it isn't. Added this in Fire Tuner and it prints for other popups like social policies, but not the Game Menu:
Code:
Events.SerialEventGameMessagePopup.Add(function(popupInfo) print(popupInfo.Type) end)
Edit3: OK, I got a context pointer:
> ContextPtr:LookUpControl("/InGame/GameMenu")
LuaContext: 1A2F26A0
I'm not sure what to do with it though...
Edit4: I got it!
ContextPtr:LookUpControl("/InGame/GameMenu"):SetShowHideHandler(function(isHide, isInit) print(isHide, isInit) end)
Prints false nil whenever I enter the menu.