Detecting When Entering Map View/Screen

Currently Viewing (Users: 0, Guests: 1)

icelty

Recruit
Best answers
0
Currently stuck at this. I'm trying to find which event I should subscribe to, in order to be notified with the player enters in map view. Is easy for mission loading but map view seams to trigger no event? Has anyone figure this out yet?
 

MitchPTI

Veteran
Best answers
0
This worked for me:

Code:
using SandBox.View.Map;
using TaleWorlds.Engine.Screens;
using TaleWorlds.MountAndBlade;

namespace ExampleMod
{
    public class ExampleSubModule : MBSubModuleBase
    {
        private bool _mapOpen = false;

        private void OnPushScreenEvent(ScreenBase screen)
        {
            if (!(screen is MapScreen))
            {
                this._mapOpen = false;
            }
        }

        protected override void OnSubModuleLoad()
        {
            ScreenManager.OnPushScreen += new ScreenManager.OnPushScreenEvent(this.OnPushScreenEvent);
        }

        protected override void OnApplicationTick(float dt)
        {
            if (!_mapOpen && ScreenManager.TopScreen is MapScreen)
            {
                this._mapOpen = true;
                // Do stuff here
            }
        }
    }
}
 

icelty

Recruit
Best answers
0
Man, you make it look so easy :grin:, I spent hours going through the source :sad: trying to find an example of something similar being done thank you so much!!! (I tried marking your post as Best Answer but there doesn't seam to be a way to do so.
 

Midnightknight

Regular
WBWF&SVC
Best answers
4
I necro things a bit, but doing checks on application tick is realllllllllly dirty ...

You can instead use
Code:
Game.Current.EventManager.RegisterEvent<TutorialContextChangedEvent>(new Action<TutorialContextChangedEvent>(Your_delegate));
To check when the screen state is changed, for once the tutorial being useful at something.
Then in your delegate do something like this
Code:
public void Your_delegate(TutorialContextChangedEvent eve)
        {
            if (eve.NewContext != TutorialContexts.MapWindow)
                return;
            //---Mycode here---//
        }
You can detect most of the game interface screen this way, except character screen that do not trigger the event correctly due to a bug.
 

MitchPTI

Veteran
Best answers
0
I necro things a bit, but doing checks on application tick is realllllllllly dirty ...

You can instead use
Code:
Game.Current.EventManager.RegisterEvent<TutorialContextChangedEvent>(new Action<TutorialContextChangedEvent>(Your_delegate));
To check when the screen state is changed, for once the tutorial being useful at something.
Then in your delegate do something like this
Code:
public void Your_delegate(TutorialContextChangedEvent eve)
        {
            if (eve.NewContext != TutorialContexts.MapWindow)
                return;
            //---Mycode here---//
        }
You can detect most of the game interface screen this way, except character screen that do not trigger the event correctly due to a bug.
That's definitely infinitely better than what I offered. Since you've already necro'd, I might hijack this thread a bit and ask if you happen to have any knowledge around detecting key presses in a similar manner? Right now I'm trying to detect when a certain key is pressed while the party screen is open and I'm struggling tbh.
 

Midnightknight

Regular
WBWF&SVC
Best answers
4
Lol i have not knowledge about this and to be honest i saw your answer a few weeks ago already but didn't posted cause i had not the knowledge to do it a better way. (Even if i'm never a fan of the every tick thing lol). Simply to say, we have many more to learn about how the engine works.

For detecting keys i haven't seen anything around those lines when browsing the partyVM or most of the VM files. But i remember i read something about key binding in the code, even if really don't remember where at all. (It wasn't something i was interested at all ...).
So if you can register an event on this key, or replace what it is bind too. I guess you can then check if the focus is set on the party screen with something like "GauntletLayer target = (GauntletLayer)ScreenManager.FocusedLayer;"
But as TW named all their layers the same way, you will have to be tricky checking on the properties.

It's only clues as i did not really looked in details for all this and it's only one week since i started investigating really how gauntlet is working and how to change it's logic without using harmony.