Jump to content
mad_cheese

returning onMapSingleClick codeBlock?

Recommended Posts

Before taking this to the feedback tracker I figured I'd consult the oracle.

 

Is it possible to return the codeblock that was set through onMapSingleClick?

 

My concrete problem is that I need to temporarily disable the default mapclick functions for _shift and _alt, the good old issue. In my case it's for an addon - it would be cool if I could disable the _shift and _alt control layers, but only  while a map overlay is open.

 

I can not disable the engine level mapclick functions via my own added UI-eventhandlers. 

 

_mouseHandler = (findDisplay 12) displayAddEventHandler
[
    "MouseButtonDown",
    {                    
        if (_this select 4) then {true} else {false};        
    }
];

The above will not work. I'm not sure if this is related but generally I find that you can override engine functions by returning TRUE in the end of your codeblock ONLY FOR KEYBINDS. not for mousebinds.

 

The only working thing is:

onMapSingleClick {if (_shift) then {true}};

But this is not a feasible solution for an addon it seems, since it will override anything a mission designer had in mind for this command. There can only ever be one onMapSingleClick. I found a script that is called 'multiple onmapsingleclicks' but it's just a management script that still creates one onMapSingleClick command and a script that manages the rest on it's own behalf.

 

Does anyone know a way to return the code that is currently assigned to onMapSingleClick? This way I could just add to the code, but I do not think it's possible... If that does not exist, I think I should write a feature request for either this or custom mousebinds being unable to prevent default engine functions of those binds.

 

Thank you!

 

 

  • Like 1

Share this post


Link to post
Share on other sites

I have half a solution for you. You need to "play" with the map control, not the display. And use set not add EH to override the click (working with a string, not code).

 

(findDisplay 12 displayCtrl 51) ctrlSetEventHandler [ "MouseButtonClick",

  "  if ((_this select 4) or (_this select 6)) then {                 
        hint str _this ; true}    
  "
];

 

The ALT (player teleport) is overridden but, I don't know why, the SHIFT is just adding code and the waypoint is created. Sorry for that.

 

  • Like 2

Share this post


Link to post
Share on other sites
On 1.9.2017 at 1:45 AM, pierremgi said:

I have half a solution for you. You need to "play" with the map control, not the display. And use set not add EH to override the click (working with a string, not code).

 

(findDisplay 12 displayCtrl 51) ctrlSetEventHandler [ "MouseButtonClick",

  "  if ((_this select 4) or (_this select 6)) then {                 
        hint str _this ; true}    
  "
];

 

The ALT (player teleport) is overridden but, I don't know why, the SHIFT is just adding code and the waypoint is created. Sorry for that.

 

 

Thank you for this! That was really interesting, although I realized that I was looking at my problem from the wrong angle.

 

What really needs to happen, is preventing the driver of a player commanded vehicle to just go to the position of any mapclick (would only be prevented under some conditions)...

 

I tried with ctrlSetEventhandler but can not override this func, but the Teleport - that's also good to know :D

 

Would you have an idea? @pierremgi ?

Share this post


Link to post
Share on other sites

sorry to bump this thread. I have made an error with my original question, apologies for that.

 

The real issue is this: I have a map overlay, while this is open I would like to disable the engine level mapclick commands, if the overlay is not open I would like them to work as normal.

 

This is the only thing I can get to work

//-- after overlay is opened
onMapSingleClick {true};
//-- after overlay is closed
onMapSingleClick {};

It works well of course, but there is only the one onMapSingleClick EH and since I am using this for an addon, I am worried to break missions. I can not use the new stackable option because I need to prevent the engine commands, and I suspect that a lot of mission designers will not use that option so I could end up breaking a crucial mission function. In rare cases admittedly, but it could happen.

 

Using the method described  above by @pierremgi , I am able to execute code, but returning 'true' does not have the effects I desire as was also mentioned. The shift waypoint can still be set, but more importantly for my case the player character will issue a movement order on every mapclick if he is commanding an AI-driven vehicle. I can not avoid that bevahiour other than with onmapSingleClick.

 

I tried this to see if I could get a hint somewhere, but no dice... 

disableserialization;
{
    _display = _x;
    _allCtrls = [];
    {
        _ctrl = ((str _x) splitString "Control#");
        {
            
            if (_x == "Control#") then {
                _ctrl = _ctrl - [_x];
            };
            
        } foreach _ctrl;
        _ctrl = _ctrl joinString "";
        _ctrl = parseNumber _ctrl;
        
        if (_ctrl > 0) then {
            {
                (_display displayCtrl _ctrl) ctrlSetEventHandler [_x,(format ["systemchat 'control %1'; true",_ctrl])];
                //~~ rumour: if EH returns number, default will be overriden. Could not confirm
            } foreach ["MouseButtonClick","MouseButtonDown","OnMouseButtonDown"];
        };
        _allCtrls pushback _ctrl;        
    } foreach (allControls _display);
} foreach (allDisplays);

{
    _display = _x;
    {
        _display displaySetEventHandler [_x,(format ["player commandchat 'control %1'; true",_display])];
    } foreach ["MouseButtonClick","MouseButtonDown"];
} foreach (allDisplays);

I do get the chat messages, but the engine events are still firing. Who knows, maybe this gives someone an idea :D

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×