Show background for purchase when selecting background item

This commit is contained in:
Hafiz 2022-05-14 21:39:45 -04:00
parent 73246fa354
commit f89847feea
3 changed files with 24 additions and 4 deletions

View file

@ -35,6 +35,7 @@ class AvatarView : FrameLayout {
private var showPet = true
private var showSleeping = true
private var hasBackground: Boolean = false
private var backgroundForPurchase: String? = null
private var hasMount: Boolean = false
private var hasPet: Boolean = false
private val imageViewHolder = mutableListOf<ImageView>()
@ -203,7 +204,10 @@ class AvatarView : FrameLayout {
}
var backgroundName = avatar.preferences?.background
if (showBackground && backgroundName?.isNotEmpty() == true) {
if (backgroundForPurchase != null) {
layerMap[LayerType.BACKGROUND] = backgroundForPurchase
if (resetHasAttributes) hasBackground = true
} else if (showBackground && backgroundName?.isNotEmpty() == true) {
backgroundName = substituteOrReturn(spriteSubstitutions["backgrounds"], backgroundName)
layerMap[LayerType.BACKGROUND] = "background_$backgroundName"
if (resetHasAttributes) hasBackground = true
@ -433,6 +437,22 @@ class AvatarView : FrameLayout {
}
}
fun setAvatarWithBackgroundForPurchase(avatar: Avatar, backgroundForPurchase: String?) {
val oldUser = this.avatar
this.avatar = avatar
this.backgroundForPurchase = backgroundForPurchase
var equals = false
if (oldUser != null) {
val newLayerMap = getLayerMap(avatar, false)
equals = currentLayers == newLayerMap
}
if (!equals) {
invalidate()
}
}
private fun initAvatarRectMatrix() {
if (avatarRectF == null) {
val srcRect = originalRect

View file

@ -288,7 +288,7 @@ class PurchaseDialog(context: Context, component: UserComponent?, val item: Shop
setLimitedTextView()
if (additionalContentView is PurchaseDialogBackgroundContent) {
(additionalContentView as PurchaseDialogBackgroundContent).setAvatar(userRepository.getUnmanagedCopy(user))
(additionalContentView as PurchaseDialogBackgroundContent).setAvatarWithBackgroundForPurchase(userRepository.getUnmanagedCopy(user), shopItem)
}
}

View file

@ -20,7 +20,7 @@ class PurchaseDialogBackgroundContent(context: Context) : PurchaseDialogContent(
binding.notesTextView.text = item.notes
}
fun setAvatar(avatar: Avatar) {
binding.avatarView.setAvatar(avatar)
fun setAvatarWithBackgroundForPurchase(avatar: Avatar, item: ShopItem) {
binding.avatarView.setAvatarWithBackgroundForPurchase(avatar, item.imageName)
}
}