I have an inventory with 2 buttons on the side, up and down arrows, which allow you to move through the inventory. When you are at the 'top' or 'bottom' of the inventory (and hence can move no further by clicking the appropriate button), the buttons are still there and still the same graphic.
Is there a way I can I can change the arrow graphic in this situation, to represent it being turned 'off', or make the button invisible?
Of course you can. :)
Your inventory can hold so many items. Don't know how many, so I'll say 5 just as an example.
Now place code the buttons to only be active/visible when you have 6 or more. You can even code it so only the correct direction is shown (as only up arrow is visible/active and when you click the up, then only the down arrow shows).
I coded that on my game, I used if (inventoryWindow.TopItem < (inventoryWindow.ItemCount - inventoryWindow.ItemsPerRow)) btnName.Visible=true;
make the condition for each button and if it's not true, turn the button off. I placed it on rep_exe as it's an always visible inventory window, otherwise you can just put the code where you turn the gui visible.
Hope it helps (there's probably other ways to do this, I just did it like that. (not all the code, but hopefully enough to get you get there. (nod) )
I did this in a similar way, also visually disabling the arrow's pushed graphic:
EDIT: Now with proper indentation and comments:
// in rep-exe:
// up-arrow is enabled
if (InventoryWindow.TopItem > 0)
{
Inv_Arrow_Up.NormalGraphic = 145;
Inv_Arrow_Up.PushedGraphic = 146;
}
// up-arrow is disabled
else
{
Inv_Arrow_Up.NormalGraphic = 144;
Inv_Arrow_Up.PushedGraphic = 144;
}
// down-arrow is enabled
if (InventoryWindow.ItemCount > InventoryWindow.TopItem + 6)
{
Inv_Arrow_Down.NormalGraphic = 148;
Inv_Arrow_Down.PushedGraphic = 149;
}
// down-arrow is disabled
else
{
Inv_Arrow_Down.NormalGraphic = 147;
Inv_Arrow_Down.PushedGraphic = 147;
}
+ 6 is equivalent to + InventoryWindow.ItemsPerRow.
What do you mean InventoryWindow.TopItem? My window is called gInventory, it doesn't have a property called TopItem.
(nor is there InventoryWindow, just InventoryItem, InvWindow, inventory, and INVENTORY).
invCustomInv?
The GUI is called gInventory; the actual InventoryWindow GUI control is called something else. Open the GUI in the editor, then check the dropdown above the GUI's properties or select the window by clicking it to see its name.
Got it.
The working code, for anybody interested:
if (gInventory.Visible) {
// up-arrow is enabled
if (invCustomInv.TopItem > 0)
{
btnInvUp.NormalGraphic = 4; //on
btnInvUp.PushedGraphic = 5333; //disabled
}
// up-arrow is disabled
else
{
btnInvUp.NormalGraphic = 5333; //disabled
btnInvUp.PushedGraphic = 5333; //disabled
}
// down-arrow is enabled
if (invCustomInv.ItemCount > invCustomInv.TopItem + 12)
{
btnInvDown.NormalGraphic = 1; //on
btnInvDown.PushedGraphic = 5334; //disabled
}
// down-arrow is disabled
else
{
btnInvDown.NormalGraphic = 5334; //disabled
btnInvDown.PushedGraphic = 5334; //disabled
}
}
My inventory box is 12 items: 3 rows of 4 items each.