Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Lewis on Tue 27/03/2012 14:56:24

Title: Mouse flickering over inventory in 2-button UI, presumably a rep_ex problem
Post by: Lewis on Tue 27/03/2012 14:56:24
Hi. Yeah, another problem. Sorry.

I'm trying to incorporate a two-button interface, which I've botched together via various examples of how to do it that have been posted on the AGS boards over the year.

Left-click interacts, right-click examines. Moving the mouse over a hotspot, object or character changes the cursor to 'interact'.

That's all working fine, but I'm struggling to get it working with the always-on inventory bar I have down the right of the screen. I'm pretty sure it's a problem with the repeatedly_execute function, I'm just not quite sure what I'm doing with it.

At the moment, when you hover over any part of the inventory (which exists past x=610), the mouse cursor flickers 'interact' mode on and off at about a billion frames per second. You can only select the inventory item if you click during one of the frames when it's in interact mode, so it doubles up as both a graphical bug and an interaction one.

I'm pretty sure this is my problem:


    // Mouse flickers between interact and pointer when over anywhere on the far right of the screen.
   
      if (mouse.x > 610)
  {
  if (!gInventory.Visible) mouse.Mode = eModePointer; }
 
    // End of problematic code


because it's specifying that it should turn the mouse to 'interact' whenever the mouse is over the inventory portion of the screen, not over individual inventory items. I've tried searching for what would be a better code, but to no avail.

But I'm not quite sure as to why it's flickering on and off in the way it does. Any help would be really appreciated.

Full rep_ex code below:

function repeatedly_execute() {

 if (IsGamePaused()) return;

 int mm = mouse.Mode;
 int nm;     // new mode
 Hotspot*h;
 Object*o;
 int lt = GetLocationType(mouse.x, mouse.y);   // what's under the cursor?

 if (mm != eModeUseinv) {
   if (lt == eLocationNothing) nm = eModeWalkto;
   if (lt == eLocationHotspot) {
     h = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
     nm = h.GetProperty("def_curs");
   }
   if (lt == eLocationObject) {
     o = Object.GetAtScreenXY(mouse.x, mouse.y);
     nm = o.GetProperty("def_curs");
   }
   if (lt == eLocationCharacter) {
     nm = eModeInteract;
     
   }
   
   // The offending code is presumably in here.
   
     if (mouse.x > 610)
 {
 if (!gInventory.Visible) mouse.Mode = eModeInteract; }
 
   // End of problematic code

   if (nm != mm) mouse.Mode = nm;  // only change if necessary to not disturb animated cursors
 }
}
Title: Re: Mouse flickering over inventory in 2-button UI, presumably a rep_ex problem
Post by: geork on Tue 27/03/2012 15:40:05
Quote
  if (!gInventory.Visible) mouse.Mode = eModeInteract; }

I don't fully understand why it should flicker, as the inventory screen should be visible, but a useful catch is just to check whether the mouse mode is already at interact:

  if (!gInventory.Visible && mouse.Mode != eModeInteract) mouse.Mode = eModeInteract; }

I don't know much about how you plan to continue the code, but you could combine three lines into one:

if(mouse.x > 610 && !gInventory.Visible && mouse.Mode != eModeInteract) mouse.Mode = eModeInteract;

Hope that helped!
Title: Re: Mouse flickering over inventory in 2-button UI, presumably a rep_ex problem
Post by: Lewis on Tue 27/03/2012 15:51:40
Thanks for your help - unfortunately, that hasn't fixed it. :-(
Title: Re: Mouse flickering over inventory in 2-button UI, presumably a rep_ex problem
Post by: Khris on Tue 27/03/2012 16:02:36
I recognize my code :)

What I did, precisely to prevent unnecessarily changing the mouse mode, is use the nm variable to store the new mouse mode determined by the position and location, then only change it if it differs from the current mode.

This should fix it:

    // The offending code is presumably in here.
   
    if (GUI.GetAtScreenXY(mouse.x, mouse.y) == gInventory) nm = eModePointer;
 
    // End of problematic code
Title: Re: Mouse flickering over inventory in 2-button UI, presumably a rep_ex problem
Post by: Lewis on Tue 27/03/2012 16:04:32
Thanks Kris - for your relentlessly brilliant contributions to this forum, and for the code I pinched and then promptly fucked up. ;-)