Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: steptoe on Fri 27/01/2012 08:04:14

Title: SOLVED: Open gui from inventory item click
Post by: steptoe on Fri 27/01/2012 08:04:14
Hi

EDIT.. I have opted to use inv compass on main player at the moment.

------------------

Is there a reason why inv click only works with Look/Select?

I am trying to select an inv object which opens up a gui. This works when I select Look, the gui appears. I would rather it happen when inv item is seleted.

inv=icompass
gui=gcompass

The gui compass has a close button.

Would this be acceptable if i had this and made inv  image transparant?:


function repeatedly_execute_always()
{
if (cjonesy.ActiveInventory==icompass)
{
gcompass.Visible=true;
}
}




cheers for any help


Title: Re: Open gui from inventory item click
Post by: Khris on Fri 27/01/2012 09:07:07
The default behavior is hard-coded into AGS, interacting with an inventory item is used to select it.

To change that, change the respective option in general settings (handle inv clicks in script), then check for button being eMouseLeft/RightInv in on_mouse_click and script the click handling yourself.

Regardless of how sensible it is to use it, your code is ok, it's better practice to do this though (only do something if it's necessary):

function repeatedly_execute_always()
{
  if (cjonesy.ActiveInventory == icompass && gcompass.Visible == false) gcompass.Visible = true;
}
Title: Re: Open gui from inventory item click
Post by: steptoe on Fri 27/01/2012 12:10:28
Hi Khris,

'Hardcoded' - I thought it was.

As mentioned in edit, I have used use inventory on player to get same results.

The help you provided will be useful to know for reference.

cheers

steptoe



Title: Re: SOLVED: Open gui from inventory item click
Post by: Miglioshin on Fri 27/01/2012 14:33:39
Hi Steptoe,
I faced the same problem in my game, but I solved with a little workaround (since I think that it's better to leave the 'hard coded parts' alone until you PERFECTLY know what you are doing EXACTLY).

I've written a function that checks which inventory item is currently under the cursor, and I used it for a double-purpose:
1.To print the name of the inventory item in a label in the inventory window
2.To work around the hard coded 'interact with inventory'.

in GlobalScript.asc:


function Inventory_Label_and_FakeInteract()
{
 if(gInventory.Visible==true)
   {
     
//I create an Inventory item token named 'item' that store the displayed object
//at the actual mouse position

       InventoryItem *item = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
       
//If the mouse is over that item I want to open the new gui (iNew_Gui) I change the mouse.Mode
//from eModeInteract to another custom mode "eModeFakeInteract" that has the
//same graphic that the interact cursor, viceversa I restore the 'true' eModeInteract

       if(item==iNew_Gui && mouse.Mode==eModeInteract)
         {mouse.Mode=eModeFakeInte;}
       if(item!=iNew_Gui && mouse.Mode==eModeFakeInte)
         {mouse.Mode=eModeInteract;}
         
//If mouse cursor isn't pointing an inventory item I 'empty' the label

       if(item==null){lblInventory.Text="";}
       
//if mouse cursor is pointing an inventory item I print the inventory name

       else{lblInventory.Text=item.Name;}
   }
}


Then, since you have coded that behaviour that works perfectly with eModeLookat, you'll just add this


function iNew_Gui_OtherClick()
{
 if(mouse.Mode==eModeFakeInte)
   {iNew_Gui.RunInteraction(eModeLookat);}
}


Then, in game repeatedly_execute, you just make a call to the function


Inventory_Label_and_FakeInteract();


Obviously you can use only the code that 'change' the mouse.Mode to give the player the illusion of 'interacting' with the item that will only open a new gui instead of change the mouse.Mode to eModeUseInv.

I hope I haven't forgot nothing and that this can be of help.

Let us know...

Cheers