Campaignmap click and double click handler

Users who are viewing this thread

Unterkatze

Recruit
I´m looking for the eventhandlers for clicking and doubleclicking on the campaign map in Bannerlord.
I want to alter the behavior of the time speed fast forward and normal speed.
At the moment a single click will set time to normal speed and a double click will set the time to fast forward. I want to make the single click not change the speed.
Cant find the code where the speed is set. Any suggestions?
 
Solution
When you say single click on the campaign map, are you clicking on anything in particular?

EDIT: Sorry I got confused. I understand what you're referring to now. The code is found in MapScreen.HandleLeftMouseButtonClick(), specifically this part:
C#:
                    if (flag && this._processCameraInput && MobileParty.MainParty.MapEvent == null)
                    {
                        this._mapState.ProcessTravel(intersectionPoint.AsVec2);
                        if (!this._leftButtonDoubleClickOnSceneWidget && Campaign.Current.TimeControlMode == CampaignTimeControlMode.StoppableFastForward)
                        {
                            this._waitForDoubleClickUntilTime = Time.ApplicationTime + 0.3f...
When you say single click on the campaign map, are you clicking on anything in particular?

EDIT: Sorry I got confused. I understand what you're referring to now. The code is found in MapScreen.HandleLeftMouseButtonClick(), specifically this part:
C#:
                    if (flag && this._processCameraInput && MobileParty.MainParty.MapEvent == null)
                    {
                        this._mapState.ProcessTravel(intersectionPoint.AsVec2);
                        if (!this._leftButtonDoubleClickOnSceneWidget && Campaign.Current.TimeControlMode == CampaignTimeControlMode.StoppableFastForward)
                        {
                            this._waitForDoubleClickUntilTime = Time.ApplicationTime + 0.3f;
                            Campaign.Current.TimeControlMode = CampaignTimeControlMode.StoppableFastForward;
                        }
                        else
                        {
                            Campaign.Current.TimeControlMode = (this._leftButtonDoubleClickOnSceneWidget ? CampaignTimeControlMode.StoppableFastForward : CampaignTimeControlMode.StoppablePlay);
                        }
                    }

You'll need to use a transpiler to change this line:
C#:
            Campaign.Current.TimeControlMode = (this._leftButtonDoubleClickOnSceneWidget ? CampaignTimeControlMode.StoppableFastForward : CampaignTimeControlMode.StoppablePlay);

To this line:
C#:
            Campaign.Current.TimeControlMode = (this._leftButtonDoubleClickOnSceneWidget ? CampaignTimeControlMode.StoppableFastForward : CampaignTimeControlMode.Stop);

EDIT 2: Doesn't work. It might be hard-coded in the engine. @MRay can you help?

EDIT 3: So I got it to work but with bugs. Double-clicking won't allow you to move on the map too:
C#:
    [HarmonyPatch(typeof(MapScreen))]
    public class TestSubModule : MBSubModuleBase
    {
        protected override void OnSubModuleLoad() => new Harmony("test").PatchAll();
        [HarmonyPatch(MethodType.Constructor, new Type[] { typeof(MapState) })]
        public static void Postfix(bool ____leftButtonDoubleClickOnSceneWidget) => _leftButtonDoubleClickOnSceneWidget = ____leftButtonDoubleClickOnSceneWidget;
        [HarmonyPatch("HandleLeftMouseButtonClick")]
        private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
        {
            List<CodeInstruction> codes = new List<CodeInstruction>(instructions);
            List<CodeInstruction> codesToInsert = new List<CodeInstruction>();
            int index = 0;
            for (int i = 0; i < codes.Count; i++)
            {
                if (codes[i].operand is MethodInfo method && method == AccessTools.Method(typeof(MapScreen), "OnTerrainClick"))
                {
                    index = i;
                    break;
                }
            }
            codesToInsert.Add(new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(TestSubModule), "Stop")));
            codes.InsertRange(index, codesToInsert);
            return codes;
        }
        private static void Stop()
        {
            if (!_leftButtonDoubleClickOnSceneWidget)
            {
                Campaign.Current.TimeControlMode = CampaignTimeControlMode.Stop;
            }
        }
        private static bool _leftButtonDoubleClickOnSceneWidget;
    }
 
Last edited:
Upvote 0
Solution
Back
Top Bottom