|
public void InitializeOtherInventory() |
|
{ |
|
// InventoryPage is a variable assigned through the Stride GameStudion of type UIPage |
|
var inventoryStack = InventoryPage.Page.RootElement.FindVisualChildOfType<ScrollViewer>("OtherItems") |
|
.FindVisualChildOfType<StackPanel>(); |
|
|
|
// Clear the current list of buttons |
|
inventoryStack.Children.Clear(); |
|
|
|
// Run GetInventoryButton and add it to the list of reach item |
|
foreach (var item in OtherInventory.Items) |
|
{ |
|
string name = $"{item.Name} ({item.Quantity})"; |
|
var button = GetInventoryButton(item.ItemPrefab, name, item.Quantity); |
|
inventoryStack.Children.Add(button); |
|
} |
|
|
|
_transferButton.IsEnabled = true; |
|
_transferButton.Visibility = Visibility.Visible; |
|
} |
|
|
|
// Creates a new button that is cloned from CustomButtons which is a unique UIElement from a UILibrary |
|
private Button GetInventoryButton(Prefab prefab, string text, int quantity, string description = "No description", ISpriteProvider image = null) |
|
{ |
|
var element = CustomButtons.InstantiateElement<Button>("ImageTextButton"); |
|
|
|
element.FindVisualChildOfType<Grid>().FindVisualChildOfType<TextBlock>().Text = text; |
|
|
|
if(image != null) |
|
{ |
|
element.FindVisualChildOfType<Grid>().FindVisualChildOfType<ImageElement>().Source = image; |
|
} |
|
|
|
element.Height = 80; |
|
element.VerticalAlignment = VerticalAlignment.Top; |
|
|
|
// add the inventory item to a dictionary and conatin the dictionary key in the button |
|
element.Name = Guid.NewGuid().ToString(); |
|
itemsAttachedToButtons.TryAdd(element.Name, prefab); |
|
|
|
element.Click += (s, e) => { OnButtonPress(text, description, quantity, image); }; |
|
element.Click += ItemButton_Click; |
|
|
|
return element; |
|
} |