Created an Inventory GUI, Nothing Works

Started by Georgeqgreg, Sun 05/01/2014 20:02:14

Previous topic - Next topic

Georgeqgreg

I created a simple GUI with an inventory window, my inventory item shows up, but nothing happens when clicking it. I've been really wracking my head over it. :-X

I played with the inventory item's different events, general settings' "override built in inventory click" option, all kinds of different things in the globalscript, (can't remember) and probably other things I can't recall at the moment. My brain hurts. I also have looking through piles of documentation, but most of it was written for AGS 2.x where inventory seems to have worked waaaay different. Also on the first time and only the first time putting my mouse over it I can see part of the inventory label from SSH's description module underneath the inventory window. Weird.

What I'm trying to do is make the inventory item become the mouse cursor by left clicking and I want to be able to look at it by right clicking.

So how do I make the window respond to mouse clicks? Can we start there? :confused:

Slasher

Hi,

if you mess around too much without knowing what you are doing you can mess things up big time.

Usually if you can't click on an inventory item(s) try adjusting the Inventory window ItemHeight and ItemWidth in the inv window properties.

This usually cures the issue (eventually).

In your case I don't know....





Adeel

Hi Georgeqgreq.

I assume that you're using the empty template. If that is the case, then I think you should post your global script's code here, so that your problem would be identified immediately, especially post the (on_mouse_click) part of your global script.

E: Use this option if slasher's advice doesn't solve your problem.

Georgeqgreg

Screw things up? Hah! I'm using the blank template anyway, I'm kinda forced to make my own everything. (The default interfaces AGS comes with don't satisfy me. Sorry guys.)

In any case, it works! The label still doesn't come up, but that's probably something to ask SSH about. Thanks slasher! +1

(Adeel posted while I was typing the above, yes, I am using the blank template. My globalscript is maybe the topic of another thread anyway. :grin:)

Adeel

I see. Please post only (on_mouse_click) part of your global script then.

Georgeqgreg

#5
Ok. It's a bit of a mess.

Code: AGS
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 (ie. don't allow mouse click)
  {
  }
  else if (button == eMouseLeft) 
  {
    if (IsInteractionAvailable(mouse.x,mouse.y, eModeInteract) == 1) //if you click an object
    {ProcessClick(mouse.x,mouse.y, eModeInteract);}
    else if (IsInteractionAvailable(mouse.x,mouse.y, eModeTalkto) == 1) //if you click an object
    {ProcessClick(mouse.x,mouse.y, eModeTalkto);}
    else {ProcessClick(mouse.x,mouse.y, eModeWalkto);} //if you click the ground
  }
  else if (button == eMouseRight) // right click look
  {   
 
    if (IsInteractionAvailable(mouse.x,mouse.y, eModeLookat) == 1) //if you click an object
    {ProcessClick(mouse.x,mouse.y, eModeLookat);}
    else {ProcessClick(mouse.x,mouse.y, eModeWalkto);} //if you click the ground
   
  }
  else if (button == eMouseWheelSouth) // scroll wheel down
  {   
 if (gInventWindow.Visible == false)
{    gInventWindow.Visible = true;
player.StopMoving();
    gInventWindow.Y = -450;
    Wait(1);
    gInventWindow.Y = -400;
    Wait(1);
    gInventWindow.Y = -350;
    Wait(1);
    gInventWindow.Y = -300;
    Wait(1);
    gInventWindow.Y = -250;
    Wait(1);
    gInventWindow.Y = -200;
    Wait(1);
    gInventWindow.Y = -150;
    Wait(1);
    gInventWindow.Y = -100;
    Wait(1);
    gInventWindow.Y = -50;
    Wait(1);
    gInventWindow.Y = 0;
}  
  }
  else if (button == eMouseWheelNorth)
  if (gInventWindow.Visible == true) {
    gInventWindow.Y = -50;
    Wait(1);
    gInventWindow.Y = -100;
    Wait(1);
    gInventWindow.Y = -150;
    Wait(1);
    gInventWindow.Y = -200;
    Wait(1);
    gInventWindow.Y = -250;
    Wait(1);
    gInventWindow.Y = -300;
    Wait(1);
    gInventWindow.Y = -350;
    Wait(1);
    gInventWindow.Y = -400;
    Wait(1);
    gInventWindow.Y = -450;
    Wait(1);
    gInventWindow.Visible = false;}
} 


I don't know why code tags aren't working. (Because you have to add =AGS to the opening tag. -Snarky)

Adeel

#6
Code: AGS

     InventoryItem*ia = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);  //put this line at the start of on_mouse_click function
     
    if (player.ActiveInventory == null){            //start of code - you can put it anywhere as long as you put it inside the on_mouse click function.
        if (button == eMouseLeftInv) player.ActiveInventory = ia;
        else if (button == eMouseRightInv) ia.RunInteraction(eModeLookat);
        }
     else if (player.ActiveInventory != null && button == eMouseRightInv) player.ActiveInventory == null; // end of code
      


What this code does:
Spoiler

This code should do the basic work, i.e, once the inventory is open and you left click on Inventory item - make that inventory item as your active inventory and if you right click on an inventory item (provided your active inventory is empty), it'll perform the inventory item's look function. Otherwise if you already have an item set as your active inventory before, it'll cancel or free your active inventory.
[close]

Two terms worth noting are "eMouseLeftInv" and "eMouseRightInv" because these modes are especially designed for the inventory items and have no apparent purpose other than the handling of Inventory Items.

I hope this helps and pardon me if I did some misspelling while writing the above code. It was done in haste and without using the editor.

E: Shit, I didn't use right operator in the end. Corrected now.

Georgeqgreg

Actually I know about eMouseRightInv. (and such) It was in the script before but inventory clicks seem to respond to eMouseRight just fine. (Haven't wired a left click action up yet.)

Adeel

A million dollar question.....does my code work?

Georgeqgreg

Uhh... isn't a lot of it a bit redundant? :-[

Adeel

Of course it can be shrunk depending on your need. Well, this code works for me. I don't know why it should work for you. :sealed:

Georgeqgreg

Sorry, but I do think it gives me ideas. Thanks.

SMF spam blocked by CleanTalk