I'm trying to script my mouse cursor to animate over GUI buttons and Inventory items like it does over Hotspots.
I understand the Pointers are used somehow but I'm completely new to scripting and have no idea how to get my Cursor to animate in the GUI.
I would create a global int variable called MouseOverButton which is 0 by default.
Then, in the global script, under repeatedly_execute, put something like this:
if (GUIcontrol.GetAtScreenXY(mouse.x, mouse.y) != null){
MouseOverButton += 1;
// if you want it to animate only over certain buttons you'll need to add more conditions to the above if statement
}
if (Guicontrol.GetAtScreenXY(mouse.x,mouse.y == null){
MouseOverButton= 0;
//If mouse animation is repeating, add a line to stop it here
}
if (MouseOverButton == 1){
//Animate mouse cursor here, non-blocking
}
There might be simpler ways to do this but I'm not at my computer right now. Didn't test it.
Put this somewhere above the repeatedly_execute function in the global script:
int mouseAnimFrame;
function HandleMouseAnim() {
GUIControl* gc = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
InventoryItem* ii = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
if (gc != null && gc.AsButton != null || ii != null) mouseAnimFrame++; // hovering
else mouseAnimFrame = 0;
int view = MOUSE_ANIMATION; // view name here
int frame = (mouseAnimFrame / 5) % Game.GetFrameCountForLoop(view, 0); // speed: 5
ViewFrame* vf = Game.GetViewFrame(view, 0, frame);
Mouse.ChangeModeGraphic(Mouse.Mode, vf.Graphic);
}
Now add this line inside the repeatedly_execute function:
HandleMouseAnim();
Quote from: RootBound on Wed 13/09/2023 20:57:39I would create a global int variable called MouseOverButton which is 0 by default.
Then, in the global script, under repeatedly_execute, put something like this:
if (GUIcontrol.GetAtScreenXY(mouse.x, mouse.y) != null){
MouseOverButton += 1;
// if you want it to animate only over certain buttons you'll need to add more conditions to the above if statement
}
if (Guicontrol.GetAtScreenXY(mouse.x,mouse.y == null){
MouseOverButton= 0;
//If mouse animation is repeating, add a line to stop it here
}
if (MouseOverButton == 1){
//Animate mouse cursor here, non-blocking
}
There might be simpler ways to do this but I'm not at my computer right now. Didn't test it.
I attempted this but didn't get any results.
Quote from: Khris on Wed 13/09/2023 21:37:54Put this somewhere above the repeatedly_execute function in the global script:
int mouseAnimFrame;
function HandleMouseAnim() {
GUIControl* gc = GUIControl.GetAtScreenXY(Mouse.x, Mouse.y);
InventoryItem* ii = InventoryItem.GetAtScreenXY(Mouse.x, Mouse.y);
if (gc.AsButton != null || ii != null) mouseAnimFrame++; // hovering
else mouseAnimFrame = 0;
int view = MOUSE_ANIMATION; // view name here
int frame = (mouseAnimFrame / 5) % Game.GetFrameCountForLoop(view, 0); // speed: 5
ViewFrame* vf = Game.GetViewFrame(view, 0, frame);
Mouse.ChangeModeGraphic(Mouse.Mode, vf.Graphic);
}
Now add this line inside the repeatedly_execute function:
HandleMouseAnim();
Used this on got a message at the "GUI control* gc = GUIcontrol.GetAtScreenXY(Mouse.x, mouse.y);" line
"Must have an instance of the struct to access a non-static member."
Yeah, I should've listened to my gut and not changed these. :P
Replace the offending lines with
GUIControl* gc = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
InventoryItem* ii = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
(lower case mouse.x and mouse.y)
Also note that you have to use your own view's name (or number) where it says MOUSE_ANIMATION in my code.
Also please go easy on the quotes, this is really messy to read ;)
Fixed the mouse letter casing.
Now it's telling me "Nested functions not supported (you may have forgotten a closing brace) on the repeatedly_execute() line
I realized after I posted that the if statements might be in the wrong order. It may also be increasing the variable multiple times per loop, so that it is above 1 before the next line runs. Apologies for overestimating my own coding skills.
Could be fixable but I am still away from my computer unfortunately.
Khris's code looks like it will give you more precise control over everything anyway.
Quote from: VENOMDRINKER on Wed 13/09/2023 22:53:53Fixed the mouse letter casing.
Now it's telling me "Nested functions not supported (you may have forgotten a closing brace) on the repeatedly_execute() line
Nevermind, forgot to end the function with a }
But now when the game starts it crashes saying
"error running function 'repeatedly_execute':
Error (line 107): null pointer referenced"
Line 107 being
If (gc.AsButton != null || ii != null) mouseAnimFrame++; // hovering
Bah, it was really late :P
if (gc != null && gc.AsButton != null || ii != null) mouseAnimFrame++; // hovering
I should have been thinking about time zones before posting :-D
Changed the line and now my cursor animates over GUI buttons and items!
Something else, now when I select an item and which to the Use Inv cursor it no longer switches to the CursorImage with it's custom hotspot marker but instead stays on the default cursor while the item is selected.