I'm trying to retrieve the UI coordinates of X and Y from a clicked dialog button. Every time I click the button, it returns (0, 0). I tried moving the button around the screen as well and it still returns (0,0). I need this button to find out the X and Y coordinates of the button so I can find what resolution the user has it set to and then adjust the map's custom UI accordingly. If I cannot use a button and have to use a image instead, how will I know that the user has clicked on the image?
Yes, button clicks don't get registered by the UI Click event. And thus the X/Y coordinates return 0.
I think the closest you can get it grabbing the x/y positions of the clicked button.
Or if you really want that button and the exact x/y position then you can place a dialog image above the button and make it transparent. You will then click on the dialog image (because the button is stuck underneath it) and this returns valid X/Y coordinates and triggers the UI click event (which you have to use then).
How do you get the x/y positions of the button or any dialog item for that matter? The only thing I can find are size and offset, which only return the values assigned in the editor.
I tried putting an image over the button and setting it to have a higher priority but I couldn't get it to work. How do you know if the user has clicked on the dialog image? I had it set up like this:
ButtonClickedEventsDialog-AnyDialogItemisusedbyPlayerAnyPlayerwitheventtypeClickedLocalVariablesButtonX=0<Integer>ButtonY=0<Integer>Conditions(Useddialogitem)==Dialog[Welcome]::DialogItem[InvisibleImage]Actions------- Retreive X and Y coordinates of 'clicked' image.Variable-SetButtonX=(MouseXpositionclickedintheUI)Variable-SetButtonY=(MouseYpositionclickedintheUI)
The trigger never initiates because images cannot be interacted with, I'm assuming. If I swap the conditions to point to the button, I simply get (0,0) returned.
You can set the button to have the image you specify. Or you can write a trigger that returns the x,y of the mouse click relative to the dialog box. (MouseXInBox = AbsoluteMouseX - DialogBoxX; y found in similar manner)
Hm, I'm not sure I understand. When you say AbsoluteMouseX, are you referring to the Absolute Value of Mouse X?
Here is how I have my 'if button is clicked' trigger set up. Just testing 'x' for now.
They are adding the ability to track mouse even when not clicking it, I'm just saying I don't know if they add the possibility to always get the mouse position using triggers or not. Currently it's only possible to get mouse X/Y position with the Mouse Clicked event.
I read the patch notes and there wasn't anything regarding them removing the 'Mouse Click' trigger. I found the part you are talking about:
"New trigger event: Mouse Moved, sent in response to the mouse being moved in the game world."
The only part about that is how they say "...in the game world." This leads me to believe the trigger is intended for retrieving World coordinates and not UI coordinates. But, I hope I'm wrong, mouse tracking for the UI and World would be amazing.
When I say AbsoluteMouseX, I am talking about the x position of the mouse relative to the game world. Even if they do remove compatibility for getting mouse coordinates in a UI, using the method would fix the problem.
Uh, the world coordinates are 3D points, they aren't related to the GUI in any way. But no one said anything about anything being removed. I only said I don't know what they will add.
I think the closest you can get it grabbing the x/y positions of the clicked button.
Or if you really want that button and the exact x/y position then you can place a dialog image above the button and make it transparent. You will then click on the dialog image (because the button is stuck underneath it) and this returns valid X/Y coordinates and triggers the UI click event (which you have to use then).
Sorry to re-bump this thread but I tried this and it doesn't return any values unless I'm doing something wrong.
Set up Dialog, button, image
EventsGame-MapinitializationLocalVariablesConditionsActions------- DialogDialog-CreateaModaldialogofsize(256,256)at(0,0)relativetoCenterofscreenVariable-Setdialog=(Lastcreateddialog)------- ButtonDialog-Createabuttonfordialogdialogwiththedimensions(128,128)anchoredtoCenterwithanoffsetof(0,0)settingthetooltipto""withbuttontext"Button"andthehoverimagesetto""Variable-Setbutton=(Lastcreateddialogitem)Dialog-Set(Lastcreateddialogitem)RenderPriorityto0for(Allplayers)------- ImageDialog-Createanimagefordialog(Lastcreateddialog)withthedimensions(128,128)anchoredtoCenterwithanoffsetof(0,0)settingthetooltipto""usingtheimageAssets\Textures\white32.ddsasaNormaltypewithtiledsettotruetintcolorWhiteandblendmodeAlphaVariable-Setimage=(Lastcreateddialogitem)Dialog-Set(Lastcreateddialogitem)RenderPriorityto512for(Allplayers)------- Show allDialog-Showdialogfor(Allplayers)Dialog-Showbuttonfor(Allplayers)Dialog-Showimagefor(Allplayers)
You're creating an image which looks like a button, instead of a button itself. There was also a way of have a real button underneath but when I just tested it it didn't exactly want to work.
Anyway, you also should use "Mouse Clicked UI Pos X/Y" instead of world.
There is problem with that though. How do you know if they user has clicked on the image compared to just clicking randomly on the screen? There are no events/conditions to use for this scenario to fire a trigger except "If user clicks mouse". You cannot use a dialog image with a "dialog item is used" event or "used dialog item" condition. I thank you for helping me though. I think I'm just going to wait until patch 1.2 and see how the real-time mouse tracking goes. If that mouse tracking does record GUI-coordinates then what I'll do is create an array of size 10 that records the coordinates every .1 seconds and when the user clicks on the button and it returns (0,0), the 'fired' trigger will just cycle through the array for last known greater than 0 coordinates and use that. That would work.
This reminds me of a problem I had long ago, where the position reported by clicking on the UI was different than the one used by dialogs and depended on resolution.
No, you need the UI coordinates, not the world coordinates.
World coordinates give you the point on the map you're just clicking at, which is heavily influenced by your camera perspective.
UI coordinates give you a point that doesn't care about camera and stuff.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
Hello,
I'm trying to retrieve the UI coordinates of X and Y from a clicked dialog button. Every time I click the button, it returns (0, 0). I tried moving the button around the screen as well and it still returns (0,0). I need this button to find out the X and Y coordinates of the button so I can find what resolution the user has it set to and then adjust the map's custom UI accordingly. If I cannot use a button and have to use a image instead, how will I know that the user has clicked on the image?
Thanks.
@desiderius1: Go
could you screen shot the code your using the get the mouse X,Y
Im not sure this will even work the way you think it does. Screen shot would help people help you though. (of the line of code your using )
Yes, button clicks don't get registered by the UI Click event. And thus the X/Y coordinates return 0.
I think the closest you can get it grabbing the x/y positions of the clicked button.
Or if you really want that button and the exact x/y position then you can place a dialog image above the button and make it transparent. You will then click on the dialog image (because the button is stuck underneath it) and this returns valid X/Y coordinates and triggers the UI click event (which you have to use then).
@s3rius: Go
How do you get the x/y positions of the button or any dialog item for that matter? The only thing I can find are size and offset, which only return the values assigned in the editor.
I tried putting an image over the button and setting it to have a higher priority but I couldn't get it to work. How do you know if the user has clicked on the dialog image? I had it set up like this:
The trigger never initiates because images cannot be interacted with, I'm assuming. If I swap the conditions to point to the button, I simply get (0,0) returned.
@desiderius1: Go
You can set the button to have the image you specify. Or you can write a trigger that returns the x,y of the mouse click relative to the dialog box. (MouseXInBox = AbsoluteMouseX - DialogBoxX; y found in similar manner)
@Abion47: Go
Hm, I'm not sure I understand. When you say AbsoluteMouseX, are you referring to the Absolute Value of Mouse X? Here is how I have my 'if button is clicked' trigger set up. Just testing 'x' for now.
Thanks for helping
You can only get the mouse coordinates on the "Mouse Clicked" event until 1.2 patch (not sure how well we can get them even after that, though).
@A1win: Go
What do you mean? They are removing the ability to get UI coordinates via mouse click? If so, why would they do that?
They are adding the ability to track mouse even when not clicking it, I'm just saying I don't know if they add the possibility to always get the mouse position using triggers or not. Currently it's only possible to get mouse X/Y position with the Mouse Clicked event.
@A1win: Go
I read the patch notes and there wasn't anything regarding them removing the 'Mouse Click' trigger. I found the part you are talking about:
"New trigger event: Mouse Moved, sent in response to the mouse being moved in the game world."
The only part about that is how they say "...in the game world." This leads me to believe the trigger is intended for retrieving World coordinates and not UI coordinates. But, I hope I'm wrong, mouse tracking for the UI and World would be amazing.
@desiderius1: Go
When I say AbsoluteMouseX, I am talking about the x position of the mouse relative to the game world. Even if they do remove compatibility for getting mouse coordinates in a UI, using the method would fix the problem.
Here's a coded version of it:
Uh, the world coordinates are 3D points, they aren't related to the GUI in any way. But no one said anything about anything being removed. I only said I don't know what they will add.
Use my way and you're done with it.
@s3rius: Go
Sorry to re-bump this thread but I tried this and it doesn't return any values unless I'm doing something wrong.
Set up Dialog, button, image
If player clicks mouse
Ah sorry, this is better:
You're creating an image which looks like a button, instead of a button itself. There was also a way of have a real button underneath but when I just tested it it didn't exactly want to work.
Anyway, you also should use "Mouse Clicked UI Pos X/Y" instead of world.
@s3rius: Go
There is problem with that though. How do you know if they user has clicked on the image compared to just clicking randomly on the screen? There are no events/conditions to use for this scenario to fire a trigger except "If user clicks mouse". You cannot use a dialog image with a "dialog item is used" event or "used dialog item" condition. I thank you for helping me though. I think I'm just going to wait until patch 1.2 and see how the real-time mouse tracking goes. If that mouse tracking does record GUI-coordinates then what I'll do is create an array of size 10 that records the coordinates every .1 seconds and when the user clicks on the button and it returns (0,0), the 'fired' trigger will just cycle through the array for last known greater than 0 coordinates and use that. That would work.
Real-time mouse tracking will track the game world and not the UI. And I forsee that it has a lot of lag.
And when a user clicks with his mouse you can check whether he actually clicked the button by seeing if the mouse position is inside the image bounds.
@s3rius: Go
To check to see if the mouse position is in the image bounds, I have to get the world coordinates of the mouse click relative to the dialog box?
@desiderius1: Go
This reminds me of a problem I had long ago, where the position reported by clicking on the UI was different than the one used by dialogs and depended on resolution.
My solution to it looked similar to the following MouseUIGameUI.SC2Map
@desiderius1: Go
No, you need the UI coordinates, not the world coordinates.
World coordinates give you the point on the map you're just clicking at, which is heavily influenced by your camera perspective.
UI coordinates give you a point that doesn't care about camera and stuff.