Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: DazJ on Sat 26/07/2008 01:15:54

Title: Custom Inventory GUI Problem (SOLVED)
Post by: DazJ on Sat 26/07/2008 01:15:54
I've modified the standard AGS Inventory GUI. It's activated by moving the mouse to the top of the screen where it appears in a long strip, much like Broken Sword.

When I click on an inventory item the GUI just vanishes and my cursor remains the same as it was. It doesn't seem to select the item at all.

I'm using AGS 3.0 and haven't changed any of the GUI code, I've simply rearranged it all.

Any ideas?
Title: Re: Custom Inventory GUI Problem
Post by: Makeout Patrol on Sat 26/07/2008 01:40:10
I had the same problem; the way to get around it is to change the visibility mode from MouseYPos to Normal, and put some code in the global repeatedly execute function so that it becomes visible when your mouse is above a certain position:

if(mouse.y <= 30){
  gMenu.Visible = true;
} else {
  gMenu.Visible = false;
}

You might also want to include a check of whether the game is paused so that it doesn't show up during cutscenes and the like.
Title: Re: Custom Inventory GUI Problem
Post by: DazJ on Sat 26/07/2008 01:46:06
Cheers Makeout, but that hasn't done a thing  :-\
Title: Re: Custom Inventory GUI Problem
Post by: DazJ on Sat 26/07/2008 02:11:50
Actually you were right, lol...it wasn't working because I had 'Run Script with inventory clicks' ticked.

How though do I make it so I can select an item directly without having to click SELECT first?
Title: Re: Custom Inventory GUI Problem
Post by: Makeout Patrol on Sat 26/07/2008 09:38:14
I'm kind of unclear on what you mean by that. If you're asking how you select an item just with a single click, you can put the player.activeinventory = iInventory; command in the appropriate inventory item interaction. If you want to do it with, say, a key press, you can put it in the OnKeyPress function in the global script with the appropriate key code.

Or maybe I'm misunderstanding what you're trying to do?
Title: Re: Custom Inventory GUI Problem
Post by: DazJ on Sat 26/07/2008 09:46:15
Well when I access the inventory, I have to click on SELECT first to change the cursor to the pointer, THEN I can click on my inventory item to perhaps use it on a hotspot.

I'm basically just wanting to bypass the whole 'having to click on SELECT first' scenerio as it's rather frustrating and sloppy looking.
Title: Re: Custom Inventory GUI Problem
Post by: Khris on Sat 26/07/2008 10:31:55
Recheck 'Run Script with inventory clicks', then add this to your on_mouse_click:
  if (button == eMouseLeftInv) player.ActiveInventory = InventoryItem.GetAtScreen(mouse.x, mouse.y);
Title: Re: Custom Inventory GUI Problem
Post by: DazJ on Sat 26/07/2008 11:17:04
That still doesn't work :(

I add that line in the globalscript right?
Title: Re: Custom Inventory GUI Problem
Post by: Khris on Sat 26/07/2008 12:54:51
Add it in the global script, inside the on_mouse_click function.
And make sure it gets called, so e.g. use "else if" instead of "else" before the check.
Title: Re: Custom Inventory GUI Problem
Post by: DazJ on Sat 26/07/2008 17:17:38
It still doesn't work so I deleted that line of code but now my player won't interact with hotspots or objects whatsoever! He won't walk to them, look at them or interact with them, which he did before.

Below is the code in on_mouse_click function from the GlobalScript.asc

I'm using SSH's Description module.

HELP!!!  ::)


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

  if (IsGamePaused() == 1){
    //Game is paused, so do nothing on any mouse click
  }else{
    if (button == eMouseLeft){
      //left mouse button     
     
      if (GetLocationType(mouse.x, mouse.y) == eLocationNothing){
        //not over hotspot so walk
        ProcessClick(mouse.x, mouse.y, eModeWalkto);
      }else{
        //over a hotspot/object etc
        if (mouse.Mode==eModeUseinv){
          //using inventory on hotspot
          ProcessClick(mouse.x, mouse.y, eModeUseinv);
        }
      } 
    }else if (button == eMouseRight){
      //right mouse button
      if (mouse.Mode==eModeUseinv){
        //inventory item out, so cancel it
        mouse.Mode=eModeInteract;
      }else{
        //no inventory item out, so look
        ProcessClick(mouse.x, mouse.y, eModeLookat);
      }
    }else if (button == eMouseWheelNorth){
      //mouse wheel up
    }else if (button == eMouseWheelSouth){
      //mouse wheel down
    }
  }

}
Title: Re: Custom Inventory GUI Problem
Post by: Makeout Patrol on Sat 26/07/2008 19:44:09
There are a couple of problems with this code, so I'll put changes in bold.

EDIT: Looks like bold doesn't work in code boxes, so I hope this is readable.


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

  if (IsGamePaused() == 1){
    //Game is paused, so do nothing on any mouse click
  }else{
    if (button == eMouseLeft){
      //left mouse button     
     
      if (GetLocationType(mouse.x, mouse.y) == eLocationNothing){
        //not over hotspot so walk
        ProcessClick(mouse.x, mouse.y, eModeWalkto);
      }else{
        //over a hotspot/object etc
        ProcessClick(mouse.x, mouse.y, mouse.mode);
      }
    }else if (button == eMouseRight){
      //right mouse button
      if (player.ActiveInventory != null){
        //inventory item out, so cancel it
        mouse.Mode=eModeInteract;
      }else{
        //no inventory item out, so look
        ProcessClick(mouse.x, mouse.y, eModeLookat);
      }
    }else if (button == eMouseWheelNorth){
      //mouse wheel up
    }else if (button == eMouseWheelSouth){
      //mouse wheel down
    }else if(button == eMouseLeftInv){
      //left-click on inventory
      player.ActiveInventory = InventoryItem.GetAtScreen(mouse.x, mouse.y);
    } else if(button == eMouseRightInv){
      //right-click on inventory
      ProcessClick(mouse.x, mouse.y, eModeLookAt);
    }

  }

}


Here is an explanation of the changes:

1) You only had logic for if the player was hitting the left mouse button while in Inventory mode. The mouse now just clicks where it is in whatever mode it's set to - depending on how your GUI works, you may want to change this.
2) Keep in mind that I'm typing this directly into the forum post box, so I don't have any way of testing it, but I think this should work better for dismissing inventory items. If the other way actually does work, don't worry about this one.
3) These are your inventory interactions - you'll need 'run script with inventory clicks' to be checked for this one. The way it's set up here, left-clicking will select an inventory item, and right-clicking will 'LOOK AT' it. No 'select' cursor is necessary. (There is probably a better way of doing the second one than the ProcessClick function - I seem to remember some sort of 'run interaction' function, but like I say, I'm typing into a text box in OS X and I can't remember what it is.)

So yeah, this isn't tested, and some of the capitalization could be completely wrong, but it should be pretty close to what you need?
Title: Re: Custom Inventory GUI Problem
Post by: Khris on Sun 27/07/2008 08:17:18
1) DazJ, you've removed the eModeInteract line. Look again at OneDollar's code (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=35159.msg460376#msg460376).

2) mouse.Mode == eModeUseinv and player.ActiveInventory != null are pretty much equivalent.

Here's the code, cleaned up:

function on_mouse_click(MouseButton button) {

  if (IsGamePaused()) return;

  if (button == eMouseLeft) {
    if (GetLocationType(mouse.x, mouse.y) == eLocationNothing) ProcessClick(mouse.x, mouse.y, eModeWalkto);
    else {
      if (mouse.Mode==eModeUseinv) ProcessClick(mouse.x, mouse.y, eModeUseinv);
      else ProcessClick(mouse.x, mouse.y, eModeInteract);
  }

  else if (button == eMouseRight) {
    if (mouse.Mode==eModeUseinv) mouse.Mode=eModeInteract;
    else ProcessClick(mouse.x, mouse.y, eModeLookat);
  }

  else if (button == eMouseLeftInv) player.ActiveInventory = InventoryItem.GetAtScreen(mouse.x, mouse.y);

  else if (button == eMouseRightInv) ProcessClick(mouse.x, mouse.y, eModeLookAt);

}
Title: Re: Custom Inventory GUI Problem
Post by: DazJ on Mon 28/07/2008 11:50:46
That's done it! Thanks guys.