envenger
(envenger)
March 17, 2015, 11:03am
1
Hello every one…
I first initialize a overlay slot and later add items to it with some thing like this.
MainInventoryUI.Get()->InventoryOverlay.Get()->AddSlot()
.VAlign(VAlign_Center)
.HAlign(HAlign_Right)
.Padding(FMargin(0, 0, 3, 0))
SAssignNew(QuickSlotUI, SQuickSlotFrameWidget)
.PlayerStorage(PlayerStoragePtr)
];
To remove the slot, I use something like this
if (MainInventoryUIContainer.IsValid())
{
MainInventoryUI.Get()->InventoryOverlay.Get()->RemoveSlot();
}
But, it only removes the top most slot only. Is it possible to assign the slots to a variable and remove only a particular slot?
//////////////////////////////// Edit
Solved
The addslot takes an index which gives the height where the slot is created
->AddSlot(1)
When you remove the slot, you need to provide the index and all slots with that height are deleted.
->RemoveSlot(1)
While you can use the ZOrder to distinguish between different slots, note that most multislot panels have a RemoveSlot overload that accepts a widget ref. For SOverlay:
void SOverlay::RemoveSlot( TSharedRef<SWidget> Widget )
The general idea is that if you’re dynamically adding and removing a widget, then most likely you’ll want to keep a reference to said widget in order to interact with it. Having a reference, you can use the widget overload.
Also, note that for complex use cases, you can also interact with the FChildren array directly. For instance, here’s how I iterate over the items in an inventory grid:
TPanelChildren<SGridPanel::FSlot>& GridSlots = *(TPanelChildren<SGridPanel::FSlot>*)InventoryGrid->GetChildren();
for( int32 s = GridSlots.Num()-1; s >= 0 && GridSlots[s].LayerParam > LAYER_BACKGROUND.TheLayer; --s )
{
...
}
envenger
(envenger)
March 17, 2015, 2:39pm
3
Thanks for the reply…
How do I assign a slot while adding the slot?
Will something like this work?
NewSlot = MainInventoryUI.Get()->InventoryOverlay.Get()->AddSlot()
You shouldn’t need to – despite its name, the overload takes a SWidget, not a slot. So keep the SAssignNew you already have:
MainInventoryUI.Get()->InventoryOverlay.Get()->AddSlot()
.VAlign(VAlign_Center)
.HAlign(HAlign_Right)
.Padding(FMargin(0, 0, 3, 0))
SAssignNew(**QuickSlotUI**, SQuickSlotFrameWidget)
.PlayerStorage(PlayerStoragePtr)
];
QuickSlotUI is the reference you would want to pass to RemoveSlot:
if (MainInventoryUIContainer.IsValid())
{
MainInventoryUI.Get()->InventoryOverlay.Get()->RemoveSlot(**QuickSlotUI**.ToSharedRef());
}
envenger
(envenger)
March 17, 2015, 3:54pm
5
Okay… So it basically checks the hierarchy up-to the slot and removes it?
Exactly. It just iterates over the slot array until it finds the widget you gave it, then removes that slot from the array.