GUI off on item pick

Started by BorisZ, Mon 06/09/2004 19:37:29

Previous topic - Next topic

BorisZ

How do I close custom GUI with inventory on inventory pick (when cursor changes to inventory object)? I tried to put the code under interact (on inventory object) but it didn't work. Oh, one more thing: is there better way of animating characters when they are not moving (i.e. bird moves it's wings even when it is not moving) then setting high idle animation rate?

Scorpiorus

#1
QuoteHow do I close custom GUI with inventory on inventory pick (when cursor changes to inventory object)? I tried to put the code under interact (on inventory object) but it didn't work.
It could be a little problem to make AGS turn the GUI off since, by default, all inventory clicks are handled internally by the engine. But here is an explanation on how to workaround this problem:

There is a handle inventory clicks in script option on the general settings panel. If the handle inventory clicks in script option is disabled (and it's disabled by default) thenÃ, the AGS engine handles inventory clicks by itself. That is why there is no relevant code in the global script that is responsible for clicking on inventory items. (the on_mouse_click() function is not even called!)

By default, AGS runs the look at interaction on a right click and other interactions on a left click unless the current mode is MODE_USE. In that case AGS selects the inventory item, so it becomes the active one.

The following example shows how to simulate AGS behaviour on clicking the inventory item:

Enable the handle inventory clicks in script option so that AGS won't process inventory clicks but will call the on_mouse_click() function instead with passing the RIGHTINV or LEFTINV value, so we can check it and decide what to do.

function on_mouse_click(int button)
{Ã,  // called when a mouse button is clicked. button is either LEFT or RIGHT

Ã,  Ã, if (IsGamePaused() == 1)
Ã,  Ã, {
Ã,  Ã,  Ã,  // Game is paused, so do nothing (ie. don't allow mouse click)
Ã,  Ã, }
Ã,  Ã, else if (button==LEFTINV) // left click on inventory item:
Ã,  Ã, {
Ã,  Ã,  Ã,  if (GetCursorMode()==MODE_USE)
Ã,  Ã,  Ã,  {Ã,  Ã, // select inventory on MODE_USE:
Ã,  Ã,  Ã,  Ã,  Ã, SetActiveInventory(game.inv_activated);
Ã,  Ã,  Ã,  Ã,  Ã, GUIOff(INVENTORY);
Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  else
Ã,  Ã,  Ã,  {Ã,  Ã, // run other interaction if the cursor mode isn't MODE_USE:
Ã,  Ã,  Ã,  Ã,  Ã, RunInventoryInteraction(game.inv_activated, GetCursorMode());
Ã,  Ã,  Ã,  }
Ã,  Ã, }
Ã,  Ã, else if (button==RIGHTINV) // right click on inventory item:
Ã,  Ã, {Ã,  Ã, // always run look interaction on MODE_LOOK:
Ã,  Ã,  Ã,  RunInventoryInteraction(game.inv_activated, MODE_LOOK);
Ã,  Ã, }
Ã,  Ã, else if (button==LEFT) {
Ã,  Ã,  Ã,  ProcessClick(mouse.x, mouse.y, GetCursorMode() );
Ã,  Ã, }
Ã,  Ã, else {Ã,  Ã, // right-click, so cycle cursor
Ã,  Ã,  Ã,  SetNextCursorMode();
Ã,  Ã, }
}

Notice where I put GUIOff(INVENTORY), as in that case it is the script that controls clicking on inventory items we can easily hook this event and put all the necessary code there.

QuoteOh, one more thing: is there better way of animating characters when they are not moving (i.e. bird moves it's wings even when it is not moving) then setting high idle animation rate?
Well, there is a Run animation loop action you can choose in the Interaction Editor or use an AnimateCharacter/AnimateCharacterEx script function. But if setting an idle view works fine then why not let it go that way. :)

BorisZ


Scorpiorus

You are welcome!

One thing though, I forgot to mention about. The mouse clicks won't work if the game is paused and it can be paused if a Popup modal GUI is on. So, to avoid any problems make sure your INVENTORY GUI has its visible property set to Normal.

Alternatively, you can adjust the script by removing the related part of the code:

...
/*
if (IsGamePaused() == 1)
{
Ã,  Ã,  Ã,  // Game is paused, so do nothing (ie. don't allow mouse click)
}
*/
...

SMF spam blocked by CleanTalk