Author Topic: One mouse cursor control method  (Read 314 times)  Share 

Helixeagle

  • "I'm selling these fine leather jackets..."
One mouse cursor control method
« on: 31 Jul 2012, 16:03 »
Most of what I currently have is by trial and error, I'm new to AGS and stubbornly have started from scratch learning along the way. I have looked over the internet and forums over the week and have finally decided to post as I have found bits and pieces of what I need/want but am failing to understand how I am going to work around specific issues I am discovering along the way.

What I essentially want is a method of left clicking for eModeInteract + eModeWalkto and right click as eModeLookat, which I have done simple enough by editing the on_mouse_click and Process Click coding, I have also recently created a custom Inv GUI which is always available (not sure if this ties into my issues) on screen and used a player.ActiveInventory = inventory[game.inv_activated] command to help me select inventory items with my new mouse (if that makes sense) so a bit like Brokensword or The Dig.

But say I wanted to do the following on a door hotspot:

function door_UseInv()
{
  if (player.ActiveInventory == IKey) {
  cChar.Say ("Hello!");
  }
else
{
  cChar.Say ("Goodbye!");
}



This will work fine but because interact, useinv, talk etc are all mashed into left click, it executes the actions one after another (which I guess is pretty obvious), so it will run the hotspot interact script and then the use inv script etc etc, the issue is that I stubbornly refuse to accept defeat on my single cursor idea, my coding is pretty messy since I'm using trial and error most of the time.

Is there a way to possible avert the interact and walkto clicks when I have an active inventory item? I'm not entirely sure on what's possible, I've tried a couple of things to no avail, I may have to ditch the idea completely since it's starting to drive me mad, here's the mess of code regardless:

function on_mouse_click(MouseButton button)
{
  if (IsGamePaused() == 1)
{
 }
  else if (button == eMouseLeft)
  {
    ProcessClick(mouse.x,mouse.y, eModeInteract);
    ProcessClick(mouse.x,mouse.y, eModeWalkto);
    ProcessClick(mouse.x,mouse.y, eModeUseinv);
  }
      else if (button == eMouseRight)// right-click, so Lookat
  {   
    ProcessClick(mouse.x,mouse.y, eModeLookat);
    mouse.Mode = eModeWalkto; 
  }
 
 if (button == eMouseLeftInv)
  {
   player.ActiveInventory = inventory[game.inv_activated];
  }
  else if (button == eMouseRightInv)
  {
    inventory[game.inv_activated].RunInteraction(eModeLookat);
  }
 
 
 
 
   

Crimson Wizard

  • AGS Project Admins
  • not et suppotreD
    • I can help with translating
    •  
Re: One mouse cursor control method
« Reply #1 on: 31 Jul 2012, 17:56 »
You should not do anything like that:
Code: Adventure Game Studio
  1. ProcessClick(mouse.x,mouse.y, eModeInteract);
  2. ProcessClick(mouse.x,mouse.y, eModeWalkto);
  3. ProcessClick(mouse.x,mouse.y, eModeUseinv);
  4.  

Instead make a check, find what lies under the mouse and process appropriate command.
For example:
Code: Adventure Game Studio
  1. // 1. Find any usable object under the cursor:
  2. Hotspot *h = Hotspot.GetAtScreenXY(mouse.x,mouse.y);
  3. Object *o = Object.GetAtScreenXY(mouse.x,mouse.y);
  4. Character *c = Character.GetAtScreenXY(mouse.x,mouse.y);
  5. // 2. If there's an object, then...
  6. if (h != null || o != null || c != null)
  7. {
  8.   // 2.1. If player is holding an inventory item, then use it on object
  9.   if (player.ActiveInventory != null)
  10.   {
  11.      ProcessClick(mouse.x,mouse.y, eModeUseinv);
  12.   }
  13.   // 2.2 else interact with object
  14.   else
  15.   {
  16.      ProcessClick(mouse.x,mouse.y, eModeInteract);
  17.   }
  18. }
  19. // 3. If no object found, then simply walk
  20. else
  21. {
  22.   ProcessClick(mouse.x,mouse.y, eModeWalk);
  23. }
  24.  
« Last Edit: 31 Jul 2012, 18:00 by Crimson Wizard »

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: One mouse cursor control method
« Reply #2 on: 31 Jul 2012, 21:31 »
Just use GetLocationType. Here's the entire click handling:

Code: Adventure Game Studio
  1.   int lt = GetLocationType(mouse.x, mouse.y);
  2.   InventoryItem*ai = player.ActiveInventory, ia = inventory[game.inv_activated];
  3.  
  4.   if (button == eMouseLeft) {
  5.     if (lt == eLocationNothing) ProcessClick(mouse.x, mouse.y, eModeWalkto);
  6.     else if (ai) ProcessClick(mouse.x, mouse.y, eModeUseinv);
  7.     else ProcessClick(mouse.x, mouse.y, eModeInteract);
  8.   }
  9.   else if (button == eMouseRight) {
  10.     if (ai) player.ActiveInventory = null;
  11.     else ProcessClick(mouse.x, mouse.y, eModeLookat);
  12.   }
  13.   else if (button == eMouseLeftInv) {
  14.     if (ai) ia.RunInteraction(eModeUseinv);
  15.     else player.ActiveInventory = ia;
  16.   }
  17.   else if (button == eMouseRightInv) {
  18.     if (ai) player.ActiveInventory = null;
  19.     else ia.RunInteraction(eModeLookat);
  20.   }
Not tested!
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"

Helixeagle

  • "I'm selling these fine leather jackets..."
Re: One mouse cursor control method
« Reply #3 on: 01 Aug 2012, 08:32 »
Well I clearly have a lot to learn, thank you so much! this worked perfectly, maybe I can actually advance my game now :)