Detecting mouse click on the map (LUA)

psparky

King
Joined
Feb 24, 2011
Messages
624
I'm building myself a simple UI mod to help with city planning. I've looked at a few existing mods but they are overkill for what I need and may have compatibility issues with other mods I use. I've got it mostly working, but would like to improve the interface. The code is in LUA and I'm just adding it to my tweaked version of EUI.

Currently, I'm using a hotkey to trigger the action and then detecting the current mouse location to determine which plot to act on (so you move the mouse where you want a city to be and then hit the hotkey). It would be more natural if I could use a middle mouse button click to trigger the action. I'm thinking the only way to do this would be to attach my handler to every plot. Would that be expensive in terms of CPU or memory or not a problem? Or is there a better way to do it?

Thanks for any help/thoughts.
 
Put a transparent control over the whole map, detect the click in the control, then use
local iMouseX, iMouseY = UI.GetMouseOverHex()
local pPlot = Map.GetPlot(iMouseX, iMouseY)
to covert the current mouse location to a plot.

You'll need to jump through a few hoops to avoid the mini-map, etc - see my "UI - Map Pins" mod for more details
 
Thank you for the information. I did try your map pins mod but I had a few issues, which I thought were probably due to other personal UI tweaks that I have made.

As suggested I've studied the code of map pins particularly with reference to the minimap workaround, but I'm curious, is your mod compatible with EUI? The civ/CS ribbon on the right and the city/unit ribbon on the left both have an action associated with left and right clicks on the instances. I don't understand why those wouldn't need special treatment like the minimap.
 
is your mod compatible with EUI?

Unlikely, as a) EUI makes so many UI changes it's basically a "total conversion" mod, and b) I've never used it.
 
OK, that probably explains the issues I had when I tried it.

Seems like there may be more complications if I try the transparent control technique, so I think I'll stick with my somewhat clunky interface for now and see if I get used to it. I guess it's only going to be useful once or twice a game anyway.

Thanks again for your help.
 
I use map pins + auto map pins with VP and it works. It's probably because of the older integrated version of EUI that VP uses.

I presume your comment implies you are using EUI and that clicking on the various ribbons fully works as expected - for example, left-click on a city in the city ribbon opens the city and right-click moves the camera to that city.

I did have a thought that maybe the map pins overlay is only active some of the time, like when you are in "map pins mode". If that's the case, I suppose I could try something similar.

BTW I am using VP with it's older version of EUI, but I have tweaked EUI quite a lot to my personal taste.
 
I presume your comment implies you are using EUI and that clicking on the various ribbons fully works as expected - for example, left-click on a city in the city ribbon opens the city and right-click moves the camera to that city.
I need to verify later, I don't think I've tried the city ribbon.
 
I've looked again at the description and code for map pins and I believe the transparent control is only active when in "pinboard mode", so EUI should work fine the rest of the time. I also see now why the minimap is treated specially as you would want that to work even in pinboard mode.

I now think I could use this technique to do what I want after all.

Thanks again.
 
Back
Top Bottom