Inventor window: disappering scroll up and down buttons when not needed [solved]

Started by KiraHaraReturns, Sun 04/08/2013 17:50:54

Previous topic - Next topic

KiraHaraReturns

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:

Code: ags

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;
  
  }


Khris

Try this:

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

KiraHaraReturns

thanks Khris, your code seems more compact and I didn't consider changes after losing items from inventory

SMF spam blocked by CleanTalk