public void AddAvatarButtonList(List <AvatarMetadata> metadataList) { avatarButtonList.Clear(); const int offsetX = 108; const int offsetY = 86; for (int i = 0; i < 25 && i < metadataList.Count(); i++) { AvatarButton button = new AvatarButton( new Vector2(-95, -175) + new Vector2(offsetX * (i % 5), offsetY * (i / 5)), metadataList[i], AvatarButtonAction, DepthParameter.InterfaceButton); button.HideEquippedIndicator(); if (searchFilter.IsRenderingInventory) { if (inventoryRiderPreview.GetEquippedAvatarID(metadataList[i].AvatarCategory) == metadataList[i].ID) { button.ShowEquippedIndicator(); } } else { if (shopRiderPreview.GetEquippedAvatarID(metadataList[i].AvatarCategory) == metadataList[i].ID) { button.ShowEquippedIndicator(); } } avatarButtonList.Add(button); } }
/// <summary> /// This action is meant for avatar inventory and shop buttons. /// </summary> private void AvatarButtonAction(object sender) { AvatarButton avatarButton = (AvatarButton)sender; selectedAvatarMetadata = avatarButton.AvatarMetadata; // If it is a inventory button if (searchFilter.IsRenderingInventory) { // Equip player.EquipAvatar(selectedAvatarMetadata.AvatarCategory, selectedAvatarMetadata.ID); // Update Equipped avatarButtonList.ForEach((x) => x.HideEquippedIndicator()); avatarButton.ShowEquippedIndicator(); inventoryRiderPreview.ReplaceAvatar(selectedAvatarMetadata); inventoryInGamePreview.ReplaceAvatar(selectedAvatarMetadata); tryButton.Disable(true); buyButton.Disable(true); return; } // If it isn't an inventory button avatarButtonList.ForEach((x) => { x.Disable(); x.Enable(); }); avatarButton.ChangeButtonState(ButtonAnimationState.Activated, true); if (shopRiderPreview.GetEquippedAvatarID(selectedAvatarMetadata.AvatarCategory) != selectedAvatarMetadata.ID) { tryButton.Enable(); } else { tryButton.Disable(true); } if (player.Gold >= selectedAvatarMetadata.GoldPrice || player.Cash >= selectedAvatarMetadata.CashPrice) { if (!player.OwnedAvatar[selectedAvatarMetadata.AvatarCategory].Contains(selectedAvatarMetadata.ID)) { buyButton.Enable(); } else { buyButton.Disable(true); } } }