Show top row in inventory window whenever opened

Started by steptoe, Thu 09/02/2012 10:14:13

Previous topic - Next topic

steptoe

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:

Code: ags

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



Snarky

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:

Code: ags

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:

Code: ags

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

steptoe

Hi


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

cheers anyhow

monkey0506

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:

Code: ags
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.

steptoe

#4
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  ;)

monkey0506

If you just want the inventory window to always start from the very top, just do:

Code: ags
invCustomInv.TopItem = 0;


You really couldn't figure that out?

Snarky

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

steptoe

Monkey,

Code: ags

invCustomInv.TopItem = 0; 


was the first thing  I tried.

I will endeavor to try it again

cheers guys



monkey0506

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

Snarky

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.

SMF spam blocked by CleanTalk