Mouse flickering over inventory in 2-button UI, presumably a rep_ex problem

Started by Lewis, Tue 27/03/2012 14:56:24

Previous topic - Next topic

Lewis

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:

Code: ags

    // 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:

Code: ags
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
  }
}
Returning to AGS after a hiatus. Co-director of Richard & Alice and The Charnel House Trilogy.

geork

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:

Code: ags
  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:

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


Hope that helped!

Lewis

Thanks for your help - unfortunately, that hasn't fixed it. :-(
Returning to AGS after a hiatus. Co-director of Richard & Alice and The Charnel House Trilogy.

Khris

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:

Code: ags
    // The offending code is presumably in here.
    
    if (GUI.GetAtScreenXY(mouse.x, mouse.y) == gInventory) nm = eModePointer;
  
    // End of problematic code

Lewis

Thanks Kris - for your relentlessly brilliant contributions to this forum, and for the code I pinched and then promptly fucked up. ;-)
Returning to AGS after a hiatus. Co-director of Richard & Alice and The Charnel House Trilogy.

SMF spam blocked by CleanTalk