Help with Verbcoin interface for inventory. (Solved)

Started by Wade, Thu 18/03/2010 21:26:09

Previous topic - Next topic

Wade

I've done a lot of searching and I did find similar questions to mine so forgive me if this sounds a bit familiar.  The reason I'm posting is because nothing I read really helped me, or I couldn't understand it.

I'm trying to make a verbcoin interface I'm not using any templates so the code is all from scratch.  my verbcoin works perfectly, but I'm having trouble making it work in the inventory.  I'll try and explain how my verbcoin works so you'll have a better idea of how to help me.

I made the mouse context sensitive like this:

Code: ags

else if ((GetLocationType(mouse.x, mouse.y) == eLocationObject) ||
            (GetLocationType(mouse.x, mouse.y) == eLocationCharacter))
    {
      mouse.Mode = eModeUsermode1;
    }


Usermode1 is what I use to identify the verbcoin, which is scripted like this:

Code: ags

if ((mouse.Mode == eModeUsermode1) && 
        (mouse.IsButtonDown(eMouseLeft) == true))
    {
      mousex = mouse.x;
      mousey = mouse.y;
      gVerbcoin.SetPosition(mouse.x - 25, mouse.y - 25);
      if (gVerbcoin.X < 0) 
          gVerbcoin.X = 0;
      if (gVerbcoin.X > 589)
          gVerbcoin.X = 589;
      if (gVerbcoin.Y < 0)
          gVerbcoin.Y = 0;
      if (gVerbcoin.Y > 349)
          gVerbcoin.Y = 349;
      gVerbcoin.Visible = true;
    }


The inventory is giving me problems because there doesn't seem to be a way to find out if the mouse is over an inventory item, except for eLocationNothing, which isn't specific enough to work.  I've tried various methods, while admittedly only half understanding them, to no success.

If anyone could help me I'd be super grateful.

Khris

Try:
  if (InventoryItem.GetAtScreenXY(mouse.x, mouse.y) != null)

Wade

Thanks for your quick response.  Your method works quite well, now I'm just having trouble making the verbcoin appear on my click. 

Khris

Yeah, it can be a pain to integrate inv items because they're handled so differently.
Does it appear at all? Or just flash and disappear again?


Wade

#5
I discovered something interesting.  If I clicked on an inventory item, the verbcoin does not display, but if I then close the inventory window I can see the verbcoin which appears to have been hidden behind the inventory in the area where it should have shown up.  I tried using a gInventory.ZOrder = 0, and even a gVerbcoin.ZOrder = 1000, but neither of them seemed to affect this behaviour.

EDIT:  I fixed this by moving the gInventory.ZOrder and gVerbcoin.ZOrder to the repeatedly_execute rather than the on_mouse_click that displays the verbcoin.  The verb coin now displays when clicking an inventory item, but the buttons do not work.

DOUBLE EDIT:  The inventory verb coin doesn't work because processed clicks ignore interfaces.  Now to find a way around this.  :-\

Khris

Setting the verbcoin GUI's ZOrder to 1 in the GUI editor should do the trick. I believe all GUIs have 0 by default, so should the inv GUI.

The usual way to implement a verbcoin is thusly:

On a click, store the coordinates/inv item, then display the verb coin.
Upon clicking a button, call ProcessClick(stored coords, button's mouse.Mode) / invitem.RunInteraction(button's mouse.Mode)
(This won't work for moving characters/objects though.)

Not sure why the button's don't work, it shouldn't have anything to do with ProcessClick ignoring GUIs though.

Wade

Thanks Khris again for your help, though I actually solved this moments before your post.  I was missing the "RunInteraction(inventory)" part, I've implemented this a bit differently to how I think you mentioned.  The code for my verb coin buttons now read:

Code: ags

function Button1_OnClick(GUIControl *control, MouseButton button)
{
  if (gInventory.Visible == false)
  {
    ProcessClick (mousex, mousey, eModeTalkto);
    gVerbcoin.Visible = false;
  }
  
  else if (gInventory.Visible == true)
  {
    inventory[game.inv_activated].RunInteraction(eModeTalkto);
    gVerbcoin.Visible = false;
  }
}

SMF spam blocked by CleanTalk