Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Myinah on Mon 20/05/2013 21:33:53

Title: ALARCOST - Looking for GUI help
Post by: Myinah on Mon 20/05/2013 21:33:53
Hi Guys

Working on our first training game and really struggling with the left click, right click interface. We have combed the old posts but found all the links to a template from 2004 to be broken. No other posts contained code we could get to work for us. We basically want to be able to walk and interact with hotspots using the left mouse button, and look at hotspots with the right.

This is the code we are using:

function on_mouse_click(MouseButton button) {
  if (button == eMouseLeft) ProcessClick(mouse.x, mouse.y, eModeWalkto);
 
  else if (button == eMouseRight) ProcessClick(mouse.x, mouse.y, eModeLookat);
  }

Any suggestions on how we can make this work? Or a working link to the original template?

Thanks for your help

Myinah
Title: Re: ALARCOST - Looking for GUI help
Post by: Crimson Wizard on Mon 20/05/2013 22:29:10
I have my own template here, you may use it as an example (it may have some parts you won't want to have or have differently):
https://www.box.com/shared/13f5pq38x7
Title: Re: ALARCOST - Looking for GUI help
Post by: Khris on Mon 20/05/2013 22:36:13
A really quick fix, disregarding inventory items:

Code (ags) Select
function on_mouse_click(MouseButton button) {

  int mode = eModeWalkto;  // default

  int lt = GetLocationType(mouse.x, mouse.y);

  if (button == eMouseLeft) {
    if (lt != eLocationNothing) {
      if (lt == eLocationCharacter) mode = eModeTalkto;
      else mode = eModeInteract;
    }
  }
  else if (button == eMouseRight) {
    if (lt != eLocationNothing) mode = eModeLookat;
  }

  ProcessClick(mouse.x, mouse.y, mode);
}
Title: Re: ALARCOST - Looking for GUI help
Post by: Phemar on Tue 21/05/2013 07:46:56
Personally I would disregard the 'Talk to' mouse mode, and not even bother setting mouse modes. Just write your talk to interactions under the 'interact' node.

Then I would use a boolean variable to set/check whether the player has selected an inventory item to use. (Disregarding the cursor mode again.)
You'll need to make sure you're handling inventory click in script for this to work.

Code (ags) Select
bool invMode = false;

function on_mouse_click (MouseButton button) {

  int mX = mouse.x,  mY =  mouse.y;

  if (button == eMouseLeft) {
   
    if (invMode) {  // if in inventory mode
      ProcessClick (mX, mY, 4); // Run "Use Inventory on" action.
      invMode = false; // Turn off inventory mode
    }
   
    else if (GetLocationType(mX, mY) == eLocationNothing) // No hotspot, so walk
      player.Walk (GetViewportX () + mX, GetViewportY () + mY);
   
    else // Hotspot, so process click as "Interact"
      ProcessClick (mX, mY, 2);

  }
 
  else if (button == eMouseRight) {
   
    if (invMode) // If "Use Inventory on", switch it off
      invMode = false;
   
    else {
     
      if (GetLocationType(mX, mY) == eLocationNothing) // No hotspot, so walk
        player.Walk(GetViewportX () + mX, GetViewportY () + mY);
     
      else // Process click as "Look at"
        ProcessClick(mX, mY, 1);
       
    }
  }
 
  // Inventory click handling:
 
  else if (button == eMouseLeftInv) {
   
    if (!invMode) {  // If not in "Use inventory mode"
      // Set the active inventory and switch inventory mode on
      player.ActiveInventory = inventory[game.inv_activated];
      invMode = true;
    }
   
    else { // The player is inventory mode, run "Use inventory on" interaction
      inventory[game.inv_activated].RunInteraction(4);
      invMode = false;
    }
  }
 
  else if (button == eMouseRightInv) // Else, look at the inventory item
    inventory[game.inv_activated].RunInteraction(1);

}
Title: Re: ALARCOST - Looking for GUI help
Post by: Myinah on Thu 23/05/2013 01:50:20
That was very helpful! Thank you all. Much appreciated!