Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Dhelayan on Mon 04/03/2013 22:34:43

Title: [SOLVED!] combining multiple cursor modes?
Post by: Dhelayan on Mon 04/03/2013 22:34:43
Hey there!

Is it possible to give the "interact" cursormode another mode in addition to interacting?
Think "Mixed-Up Fairy Tales" by Sierra. You had one "interact" cursor, and also whereever you clicked, your character would move.
Title: Re: combining multiple cursor modes?
Post by: Khris on Tue 05/03/2013 00:59:40
Look for the on_mouse_click function in GlobalScript.asc.
In there is the eMouseLeft section that calls ProcessClick(mouse.x, mouse.y, mouse.Mode);

Replace that line with this:
Code (ags) Select
    if (mouse.Mode == eModeInteract && GetLocationType(mouse.x, mouse.y) == eLocationNothing) ProcessClick(mouse.x, mouse.y, eModeWalkto);
    else ProcessClick(mouse.x, mouse.y, mouse.Mode);


That should do it.
Title: Re: combining multiple cursor modes?
Post by: KBlaney on Tue 05/03/2013 03:51:55
Paying this one forward because I asked a similar question recently.

Code (ags) Select

else if (button == eMouseLeft)  // Left click
  {
    if(GetLocationType(mouse.x, mouse.y) == eLocationNothing) // If not over anything clickable, walk
    {
      ProcessClick(mouse.x, mouse.y, eModeWalkto);
    }
    else
    {
      if(mouse.Mode == eModeUseinv)
      {
        ProcessClick(mouse.x, mouse.y, eModeUseinv);  // Use inventory item
      }
      else
      {
        ProcessClick(mouse.x,mouse.y, eModeInteract); // Interact with object/char/hotspot
      }
    }
  }
  else if (button == eMouseRight) // right-click, so look or cancel inv. item
  {
    if(mouse.Mode == eModeUseinv)
    {
      mouse.Mode = eModeInteract;
    }
    else
    {
      ProcessClick(mouse.x,mouse.y, eModeLookat);
    }
  }


The key to this whole thing (and Khris's as well) is GetLocationType(mouse.x, mouse.y) which gets called when you click. It looks at the coordinate provided and returns one of these: eLocationCharacter, eLocationHotspot, eLocationObject, eLocationNothing. The code above (provided to me by Snarky originally) also includes item usage, another feature you probably want with your UI.
Title: Re: combining multiple cursor modes?
Post by: Khris on Tue 05/03/2013 10:09:42
KBlaney:
That code is for a kinda-sorta two-button interface, not multiple cursor modes. If that's what Dhelayan wants, then fine, but you should've mentioned that you aren't really answering his question but suggesting an entirely different UI.
Title: Re: combining multiple cursor modes?
Post by: Dhelayan on Tue 05/03/2013 13:27:38
Quote from: Khris on Tue 05/03/2013 00:59:40
Look for the on_mouse_click function in GlobalScript.asc.
In there is the eMouseLeft section that calls ProcessClick(mouse.x, mouse.y, mouse.Mode);

Replace that line with this:
Code (ags) Select
    if (mouse.Mode == eModeInteract && GetLocationType(mouse.x, mouse.y) == eLocationNothing) ProcessClick(mouse.x, mouse.y, eModeWalkto);
    else ProcessClick(mouse.x, mouse.y, mouse.Mode);


That should do it.

Wooohoo! That did it :D thankies so much! Slowly getting the hang of it all XD
Title: Re: combining multiple cursor modes?
Post by: Snarky on Tue 05/03/2013 14:46:39
Quote from: Khris on Tue 05/03/2013 10:09:42
That code is for a kinda-sorta two-button interface

"Kinda-sorta" how? It's exactly a two-button interface, n'est-ce pas?
Title: Re: combining multiple cursor modes?
Post by: Khris on Tue 05/03/2013 15:22:20
Yes, but using that code in combination with the default interface currently used by Dhelayan will give awkward results.
Example: if eModeLookat is the active mode and I click on something, the player will interact with it. Thus I wanted to discourage Dhelayan from trying the code as-is.

If somebody is looking to build a two-button interface and has already disabled all cursor modes except eModeInteract and eModeUseinv, that code will work fine of course.
Title: Re: combining multiple cursor modes?
Post by: KBlaney on Tue 05/03/2013 16:18:11
I was looking to provide an example of how GetLocationType can be used in conjunction with cursor modes to set up conditionals. Maybe a bad assumption on my part, but I didn't expect  him to copy and paste code into his project without modifying it or understanding it at all.

But yes, in that example code left click does all the walking and interacting but right click does all the looking.