Author Topic: Cursor Changes when Mouseovers a Button  (Read 418 times)  Share 

KodiakBehr

  • Is FINALLY casting Conspirocracy
Cursor Changes when Mouseovers a Button
« on: 28 Jul 2012, 16:35 »
I could really use a hand here.

First Question:

GUI is constantly on, has a button that is clicked to load the Sierra-style inventory.
When the mouse is over the button, I want it to become a pointer.  When the mouse leaves the button, I want it to go back to the last cursor icon.

So far, so good.  I wrote this to repeatedly execute:

Code: Adventure Game Studio
  1. GUIControl*gc = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
  2. if (gc == btnInventory) {mouse.SaveCursorUntilItLeaves();mouse.UseModeGraphic(eModePointer);}
  3.  

Problem is, when you select the inventory item, thus changing the cursor to reflect that inventory item, and then close the inventory window, it will naturally want to change back to its last cursor instead of holding the cursor of the inventory item.  How do I code my way around this?

And second question:

Is it possible to check for a cursor's graphical property, rather than it's mode?  My game generates an overlay just above the cursor that displays the name of an object on a mouseover, but I find it's a little distracting and gets in the way while dialog is occurring.  I'd like to disable that feature when the wait cursor is displayed, but checking cursor.Mode==eModeWait has no effect, so I'm assuming that the cursor is just using the wait graphic, while retaining the original mode?  Does that make sense?  If so, I can't seem to find any command that checks for a cursor's graphic so I can set this overlay to disable.
« Last Edit: 28 Jul 2012, 17:23 by KodiakBehr »

Khris

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: Cursor Changes when Mouseovers a Button
« Reply #1 on: 28 Jul 2012, 17:20 »
According to the manual, mouse.SaveCursorUntilItLeaves() won't work for buttons, only for hotspots, objects and characters. Also, the command doesn't really do anything here, or at least not what you expect, because you aren't changing mouse.Mode, only the current mode's sprite.

Try this:
Code: Adventure Game Studio
  1. // above repeatedly_execute
  2. int old_mode;
  3. bool was_over_button;
  4.  
  5. // inside rep_ex
  6.   GUIControl*gc = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
  7.   if (gc == btnInventory && !was_over_button) { // mouse just went over the button
  8.     was_over_button = true;
  9.     old_mode = mouse.Mode;
  10.     mouse.Mode = eModePointer;
  11.   }
  12.   if (gc != btnInventory && was_over_button) { // mouse just went away from button
  13.     was_over_button = false;
  14.     if (mouse.Mode != eModeUseinv) mouse.Mode = old_mode;
  15.   }
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

KodiakBehr

  • Is FINALLY casting Conspirocracy
Re: Cursor Changes when Mouseovers a Button
« Reply #2 on: 28 Jul 2012, 17:48 »
Ah, very clever.  That did the trick.  Thank you!  Downside is that it always goes back to the Interact cursor (the mouse.Mode of the inventory) after leaving the inventory.

I did discover a bug that that I can't seem to consistently recreate whereby the original cursor is retained into the inventory, rather than the pointer.  I guess there's not a lot I can do about that if I can't recreate the problem consistently.

I also added a second, similar question about cursor graphics.  I'd appreciate any guidance you could offer.
« Last Edit: 28 Jul 2012, 17:57 by KodiakBehr »

Khris

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: Cursor Changes when Mouseovers a Button
« Reply #3 on: 28 Jul 2012, 18:02 »
Re your second question:
mouse.GetModeGraphic(mouse.Mode) should return the current sprite.
The reason why your check isn't working is another one though: the cursor is the wait cursor, but while the interface is disabled, rep_ex isn't run.
Move the code to repeatedly_execute_always instead.

Btw, I find it much more convenient to use a GUI for cursor texts.
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

KodiakBehr

  • Is FINALLY casting Conspirocracy
Re: Cursor Changes when Mouseovers a Button
« Reply #4 on: 28 Jul 2012, 18:36 »
The code is present in rep_exec_always under a specific Floating Hotspot script that Calin was good enough to help with last year.  I just wanted to change the display to null when the wait cursor is showing.  Assuming everything in the else condition is fine, is there an obvious reason why this will not work?  Other conditions when thrown in the place of GetModeGraphic seem to accomplish their effects.

Code: Adventure Game Studio
  1.     if (gInventory.Visible==true){}
  2.     else {
  3.       if (mouse.GetModeGraphic(mouse.Mode)==eModeWait){}
  4.       else {oLabel = Overlay.CreateGraphical(FloatToInt(x, eRoundNearest), FloatToInt(y, eRoundNearest) + Offset, sprite.Graphic,  true);
  5.     }
  6.     }
  7.  

« Last Edit: 28 Jul 2012, 18:37 by KodiakBehr »

Khris

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: Cursor Changes when Mouseovers a Button
« Reply #5 on: 28 Jul 2012, 18:55 »
Edit: Just saw this: mouse.GetModeGraphic() returns the sprite slot, not the cursor mode.
So it should be if (mouse.GetModeGraphic(mouse.Mode) != 2001) (didn't look up the slot number)
---

I see, you could try IsInterfaceEnabled instead.

Btw, there's no need to use empty {}s and else, you can use ! which will inverse the condition:
Code: Adventure Game Studio
  1.   if (!gInventory.Visible && IsInterfaceEnabled()) {
  2.     oLabel = Overlay.CreateGraphical(FloatToInt(x, eRoundNearest), FloatToInt(y, eRoundNearest) + Offset, sprite.Graphic,  true);
  3.   }
Also, it's sorta bad practice to continuously recreate the overlay, but it'll work of course.
« Last Edit: 28 Jul 2012, 18:57 by Khris »
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

KodiakBehr

  • Is FINALLY casting Conspirocracy
Re: Cursor Changes when Mouseovers a Button
« Reply #6 on: 28 Jul 2012, 22:19 »
That's perfect!  Thanks a lot.  I also appreciate the guidance on inversing conditions...that will make life much easier for me :)

KodiakBehr

  • Is FINALLY casting Conspirocracy
Re: Cursor Changes when Mouseovers a Button
« Reply #7 on: 06 Aug 2012, 23:16 »
I hate to re-open this question, but I feel like I'm close to the answer.

Khris' code worked fine if there is a single button that you want to be a pointer only during a mouseover.  But now there is a second button in the GUI for which I want the same effect.  So what I tried was this:

Code: Adventure Game Studio
  1. GUIControl*gc = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
  2.   if (gc == btnInventory|| gc == btnControlPanel && !was_over_button) { // mouse just went over the button
  3.     was_over_button = true;
  4.     old_mode = mouse.Mode;
  5.     mouse.Mode = eModePointer;
  6.   }
  7.  
  8.  
  9.   if (gc != btnInventory&& gc != btnControlPanel && was_over_button) { // mouse just went away from button
  10.     was_over_button = false;
  11.     if (mouse.Mode != eModeUseinv) mouse.Mode = old_mode;
  12.   }
  13.  

But what ends up happening is the cursor only changes back after mouseovering the control panel, but the Inventory, it stays a pointer.  Do you have any idea why this is and what I can do about it?

Khris

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: Cursor Changes when Mouseovers a Button
« Reply #8 on: 07 Aug 2012, 00:09 »
Each button needs their own was_over_button variable.
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

KodiakBehr

  • Is FINALLY casting Conspirocracy
Re: Cursor Changes when Mouseovers a Button
« Reply #9 on: 07 Aug 2012, 00:25 »
Shoot.  Thanks again, Khris.  I really appreciate it.