Searching the forum gave me this code:
if (GUIControl.GetAtScreenXY(mouse.x,mouse.y) == buttonname) {
mouse.Mode = eModePointer;
}
This works but I like to change the cursor on any guibutton, not a specific one.
How do I check the coordinates to find if there's any button or not?
Also this way the cursor doesn't change back when the pointer is no longer over the button. I tried mouse.SaveCursorUntilItLeaves() but that doesn't work. I assume that is because it's in repeatedly_execute(). Any ideas on this?
thanks
Hello!
if(GUIControl.GetAtScreenXY(mouse.x, mouse.y) != null){ //Checks whether the mouse is on ANY button
Mouse.Mode = eModePointer;
}
else{
Mouse.Mode = eModeInteract; //Or whatever
}
Should work in repeatedly_exececute(). If you want it to go back to the specific mouse mode you were in, try:
//Declare these at the top of the script
int m;
bool Switch = false;
//Then in repeatedly execute:
if(GUIControl.GetAtScreenXY(mouse.x, mouse.y) != null){
if(Switch == false){
m = Mouse.Mode;
Switch = true;
}
Mouse.Mode = eModePointer;
}
else{
if(Switch == true){
Mouse.Mode = m;
Switch = false;
}
}
Maybe there's a more concise way of doing this, but for now this should work just fine.
To only change over an actual button and not any GUIControl, use:
GUIControl*gc = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
if (gc != null && gc.AsButton != null) {
Edit: corrected code
I get an null pointer referenced on the line with if (gc.AsButton != null)
(and I did change GUControl*gc to GUIControl*gc :))
Sorry, long day :)
I fixed the code.
Cool! Geork's code was good for the gui buttons but the inventory didn't work anymore. Now with Khris' addition everything's ok.
thanks