Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: KiraHaraReturns on Sun 04/08/2013 17:50:54

Title: Inventor window: disappering scroll up and down buttons when not needed [solved]
Post by: KiraHaraReturns on Sun 04/08/2013 17:50:54
how can I simply let the scrolling down button disappear  if it's not needful?


edit:
this is my attempt and it seem's to work, feel free to propose improvements:


int initem = (invMain.ItemCount/invMain.ItemsPerRow)*invMain.ItemsPerRow;
  int finitem;
  if(initem == invMain.ItemCount){
   
    finitem = initem - invMain.ItemsPerRow;
    }
    else if(initem != invMain.ItemCount){
     
      finitem = initem;
      }

if (invMain.ItemCount > (invMain.ItemsPerRow * invMain.RowCount)) {
 
    if (invMain.TopItem == 0){
 
      btnInvUpMain.Visible = false;
      btnInvDownMain.Visible = true;
      }
 
      else if (invMain.TopItem == finitem){
   
        btnInvUpMain.Visible = true;
        btnInvDownMain.Visible = false;
        }
 
    else{
      btnInvUpMain.Visible = true;
      btnInvDownMain.Visible = true;
     
      }
}


else{
  btnInvUpMain.Visible = false;
  btnInvDownMain.Visible = false;
 
  }

Title: Re: Inventory window scrolling buttons
Post by: Khris on Sun 04/08/2013 22:33:50
Try this:

Code (ags) Select
  if (invMain.ItemAtIndex[0] != null)
  {
    if (invMain.TopItem != 0)
    {
      // if inventory can scroll up
      int visible_items = (invMain.Width / invMain.ItemWidth) * (invMain.Height / invMain.ItemHeight);
      if (invMain.ItemCount > visible_items) btnInvUpMain.Visible = true;
     
      // auto-scroll up if losing an item decreases row count
      InventoryItem *invItem = InventoryItem.GetAtScreenXY(180, 190);  // <- coordinates inside first item of last row
      if (invItem == null)
        invMain.ScrollUp();
    }
    else btnInvUpMain.Visible = false;
  }
  else btnInvUpMain.Visible = false;

  if ((invMain.TopItem + (invMain.ItemsPerRow * invMain.RowCount)) < invMain.ItemCount)
    btnInvDownMain.Visible = true;
  else
    btnInvDownMain.Visible = false;


I quickly adapted code from a ManiacMansionMania template. It should work as is, you just need to change the coordinates to fit your inventory.
Title: Re: Inventor window: disappering scroll up and down buttons when not needed [solved]
Post by: KiraHaraReturns on Mon 05/08/2013 00:10:24
thanks Khris, your code seems more compact and I didn't consider changes after losing items from inventory