Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: steptoe on Thu 09/02/2012 10:14:13

Title: Show top row in inventory window whenever opened
Post by: steptoe on Thu 09/02/2012 10:14:13
Hi

It seems search is down at the moment.

I am trying to have invwindow show top row whenever it is opened. At the moment it shows lower row with nothing if inventory in that row has been used.

I have 7 items per row.

So far I have this at top of Global:


void on_event(EventType event, int data)
{

  if (event == eEventLoseInventory)
  {
  int ic = invCustomInv.ItemCount;
  if ((ic/7)*7 == ic && invCustomInv.TopItem == ic-7) invCustomInv.ScrollUp();
  }
}


No doubt it is slightly wrong.

Cheers if you could check/correct my code


Title: Re: Show top row in inventory window whenever opened
Post by: Snarky on Thu 09/02/2012 10:38:57
I'm not entirely clear on what you're trying to achieve, but you seem to go about it in an indirect way.

Do you always want the inventory to show the first row of your items whenever you open it? In that case I would do:


when_opening_inventory()
{
  while(invCustomInv.TopItem > 0)
    invCustomInv.ScrollUp();
}


Or do you just want to make sure that when you open the inventory, it doesn't display an empty row and you have to scroll up to see your items (because you've removed some inventory items since the last time it was opened)? In that case I would do:


when_opening_inventory()
{
  if(invCustomInv.ItemCount>0)
  {
    while(invCustomInv.TopItem >= invCustomInv.ItemCount)
      invCustomInv.ScrollUp();
  }
}
Title: Re: Show top row in inventory window whenever opened
Post by: steptoe on Thu 09/02/2012 10:50:07
Hi


they both sort of work. Option two, when selecting last item actually selects first item on cursor.

cheers anyhow
Title: Re: Show top row in inventory window whenever opened
Post by: monkey0506 on Thu 09/02/2012 17:59:03
I don't think that a while loop is actually necessary to ensure that an empty row won't be shown...you just need to do a bit of math:

if (invCustomInv.TopItem >= invCustomInv.ItemCount)
{
  if (invCustomInv.ItemCount <= invCustomInv.ItemsPerRow) invCustomInv.TopItem = 0; // fewer items than fit in one row
  else
  {
    int ti = (invCustomInv.ItemCount - (invCustomInv.ItemCount % invCustomInv.ItemsPerRow)); // first item of last row
    ti -= ((invCustomInv.RowCount - 1) * invCustomInv.ItemsPerRow); // offset for empty rows
    if (ti < 0) ti = 0; // fewer items than fill the entire InvWindow
    invCustomInv.TopItem = ti; // update top item
  }
}


I didn't actually test this 8), but I don't see why you should repeatedly be calling ScrollUp when you can just calculate the value once and get it over with.
Title: Re: Show top row in inventory window whenever opened
Post by: steptoe on Thu 09/02/2012 18:54:54
Hi Monkey

yours works as normal. The thing I am trying to achieve is to show top row whenever inventory is opened. At the moment it shows last item(S) added

I would add that all Items are added with ID

Items 8 and 19 are started with game.

sorry to be a pain  ;)
Title: Re: Show top row in inventory window whenever opened
Post by: monkey0506 on Thu 09/02/2012 21:47:42
If you just want the inventory window to always start from the very top, just do:

invCustomInv.TopItem = 0;

You really couldn't figure that out?
Title: Re: Show top row in inventory window whenever opened
Post by: Snarky on Fri 10/02/2012 00:12:56
Quote from: monkey_05_06 on Thu 09/02/2012 17:59:03
I didn't actually test this 8), but I don't see why you should repeatedly be calling ScrollUp when you can just calculate the value once and get it over with.

Well, in my case the reason was that I couldn't remember if TopItem was a writeable property.  :P
Title: Re: Show top row in inventory window whenever opened
Post by: steptoe on Fri 10/02/2012 04:19:54
Monkey,


invCustomInv.TopItem = 0;


was the first thing  I tried.

I will endeavor to try it again

cheers guys


Title: Re: Show top row in inventory window whenever opened
Post by: monkey0506 on Fri 10/02/2012 07:31:14
I can absolutely confirm that if you want the list to be scrolled all the way to the top, that setting the TopItem to 0 is the way to do it. If you have issues with that, post the code you're using so we can help from there.

@Snarky: Fair enough. If I'm allowed to not test my code, I suppose that you're allowed to not RTFM. :P
Title: Re: Show top row in inventory window whenever opened
Post by: Snarky on Fri 10/02/2012 10:22:49
I'm usually posting from my Mac (or as now, my smart phone), so I can't easily consult the manual. The online version is out of date and (as far as I can tell) incomplete.