From aeac52ef887571c09a087006192493a20b270a11 Mon Sep 17 00:00:00 2001 From: Phillip Thelen Date: Tue, 13 Feb 2018 13:43:48 +0100 Subject: [PATCH] Update world boss dialogs --- Habitica/res/layout/dialog_habitica_base.xml | 8 +-- Habitica/res/layout/npc_banner.xml | 17 +++++ Habitica/res/layout/shop_header.xml | 11 ++-- .../layout/world_boss_description_view.xml | 4 +- Habitica/res/values/strings.xml | 2 +- .../adapter/inventory/ShopRecyclerAdapter.kt | 26 ++------ .../fragments/social/TavernDetailFragment.kt | 18 +---- .../habitica/ui/views/HabiticaAlertDialog.kt | 28 ++++---- .../habitica/ui/views/NPCBannerView.kt | 65 +++++++++++++++++++ .../ui/views/social/QuestProgressView.kt | 6 ++ 10 files changed, 116 insertions(+), 69 deletions(-) create mode 100644 Habitica/res/layout/npc_banner.xml create mode 100644 Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/NPCBannerView.kt diff --git a/Habitica/res/layout/dialog_habitica_base.xml b/Habitica/res/layout/dialog_habitica_base.xml index d07f8a7be..d33b4ea8e 100644 --- a/Habitica/res/layout/dialog_habitica_base.xml +++ b/Habitica/res/layout/dialog_habitica_base.xml @@ -13,13 +13,13 @@ android:paddingTop="@dimen/spacing_large" android:paddingBottom="@dimen/spacing_large" android:textSize="18sp" - android:layout_marginBottom="@dimen/spacing_large" android:paddingLeft="@dimen/spacing_large" android:paddingRight="@dimen/spacing_large" tools:text="This is the title!" tools:background="@color/brand_300" /> - \ No newline at end of file diff --git a/Habitica/res/layout/npc_banner.xml b/Habitica/res/layout/npc_banner.xml new file mode 100644 index 000000000..3d767bba3 --- /dev/null +++ b/Habitica/res/layout/npc_banner.xml @@ -0,0 +1,17 @@ + + + + + + + \ No newline at end of file diff --git a/Habitica/res/layout/shop_header.xml b/Habitica/res/layout/shop_header.xml index 524855a71..bb21ae5bf 100644 --- a/Habitica/res/layout/shop_header.xml +++ b/Habitica/res/layout/shop_header.xml @@ -6,14 +6,11 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> - - + android:layout_height="@dimen/shop_scene_height"/> + + android:layout_height="match_parent" + android:paddingLeft="@dimen/spacing_large" + android:paddingRight="@dimen/spacing_large"> You have bought all the Gems you can this month. More become available within the first three days of each month. Thanks for subscribing! Monthly Gem Cap Reached Chat Message - The DysHeartener attacks! + What’s a World Boss? A World Boss is a special event where the whole community works together to take down a powerful monster with their tasks!\nComplete tasks to damage the Boss\nThe Boss won’t damage you for missed tasks, but its Rage meter will go up. If the bar fills up, the Boss will attack one of the shopkeepers!\nYou can continue with normal Quest Bosses, damage will apply to both\nCheck the Tavern to see Boss progress and Rage attacks A World Boss is a special event where the whole community works together to take down a powerful monster with their tasks! Complete tasks to damage the Boss diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/inventory/ShopRecyclerAdapter.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/inventory/ShopRecyclerAdapter.kt index dd919d70b..6e24d4b93 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/inventory/ShopRecyclerAdapter.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/inventory/ShopRecyclerAdapter.kt @@ -27,6 +27,7 @@ import com.habitrpg.android.habitica.models.user.User import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils import com.habitrpg.android.habitica.ui.viewHolders.SectionViewHolder import com.habitrpg.android.habitica.ui.viewHolders.ShopItemViewHolder +import com.habitrpg.android.habitica.ui.views.NPCBannerView import org.greenrobot.eventbus.EventBus import rx.Observable import rx.android.schedulers.AndroidSchedulers @@ -40,7 +41,7 @@ class ShopRecyclerAdapter : RecyclerView.Adapter() { private var ownedItems: Map = HashMap() - var shopSpriteSuffix: String? = null + var shopSpriteSuffix: String = "" set(value) { field = value notifyItemChanged(0) @@ -229,31 +230,16 @@ class ShopRecyclerAdapter : RecyclerView.Adapter() { internal class ShopHeaderViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { private val descriptionView: TextView by bindView(itemView, R.id.descriptionView) - private val sceneView: SimpleDraweeView by bindView(itemView, R.id.sceneView) - private val backgroundView: ImageView by bindView(itemView, R.id.backgroundView) + private val npcBannerView: NPCBannerView by bindView(itemView, R.id.npcBannerView) private val namePlate: TextView by bindView(itemView, R.id.namePlate) init { descriptionView.movementMethod = LinkMovementMethod.getInstance() } - fun bind(shop: Shop, shopSpriteSuffix: String?) { - DataBindingUtils.loadImage(sceneView, shop.identifier + "_scene" + shopSpriteSuffix) - - backgroundView.scaleType = ImageView.ScaleType.FIT_START - - DataBindingUtils.loadImage(shop.identifier + "_background" + shopSpriteSuffix, { - val aspectRatio = it.width / it.height.toFloat() - val height = itemView.context.resources.getDimension(R.dimen.shop_height).toInt() - val width = Math.round(height * aspectRatio) - val drawable = BitmapDrawable(itemView.context.resources, Bitmap.createScaledBitmap(it, width, height, false)) - drawable.tileModeX = Shader.TileMode.REPEAT - Observable.just(drawable) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(Action1 { - backgroundView.backgroundCompat = it - }, RxErrorHandler.handleEmptyError()) - }) + fun bind(shop: Shop, shopSpriteSuffix: String) { + npcBannerView.shopSpriteSuffix = shopSpriteSuffix + npcBannerView.identifier = shop.identifier descriptionView.text = Html.fromHtml(shop.notes) namePlate.setText(shop.npcNameResource) diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/social/TavernDetailFragment.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/social/TavernDetailFragment.kt index 299ad0728..920df9573 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/social/TavernDetailFragment.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/social/TavernDetailFragment.kt @@ -95,22 +95,8 @@ class TavernDetailFragment : BaseFragment() { descriptionView.setText(R.string.tavern_description) namePlate.setText(R.string.tavern_owner) - DataBindingUtils.loadImage(sceneView, "tavern_scene" + configManager.shopSpriteSuffix()) - - backgroundView.scaleType = ImageView.ScaleType.FIT_START - - DataBindingUtils.loadImage("tavern_background" + configManager.shopSpriteSuffix(), {bitmap -> - val aspectRatio = bitmap.width / bitmap.height.toFloat() - val height = context?.resources?.getDimension(R.dimen.shop_height)?.toInt() ?: 0 - val width = Math.round(height * aspectRatio) - val drawable = BitmapDrawable(context?.resources, Bitmap.createScaledBitmap(bitmap, width, height, false)) - drawable.tileModeX = Shader.TileMode.REPEAT - Observable.just(drawable) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(Action1 { - backgroundView.backgroundCompat = it - }, RxErrorHandler.handleEmptyError()) - }) + npcBannerView.shopSpriteSuffix = configManager.shopSpriteSuffix() + npcBannerView.identifier = "tavern" addPlayerTiers() bindButtons() diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/HabiticaAlertDialog.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/HabiticaAlertDialog.kt index d8637a172..04ea7e33d 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/HabiticaAlertDialog.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/HabiticaAlertDialog.kt @@ -5,7 +5,6 @@ import android.support.v4.content.ContextCompat import android.support.v7.app.AlertDialog import android.view.LayoutInflater import android.view.View -import android.view.ViewGroup import android.widget.LinearLayout import android.widget.TextView import com.habitrpg.android.habitica.R @@ -18,7 +17,8 @@ open class HabiticaAlertDialog(context: Context) : AlertDialog(context) { private val titleTextView: TextView by bindView(view, R.id.titleTextView) private val subtitleTextView: TextView by bindView(view, R.id.subtitleTextView) private val messageTextView: TextView by bindView(view, R.id.messageTextView) - private val contentViewContainer: ViewGroup by bindView(view, R.id.contentViewContainer) + + private var additionalContentView: View? = null init { setView(view) @@ -66,26 +66,20 @@ open class HabiticaAlertDialog(context: Context) : AlertDialog(context) { setMessage(context.getString(messageId)) } - fun setAdditionalContentView(layoutResID: Int) { + fun setAdditionalContentView(layoutResID: Int, index: Int = -1) { val inflater = context.layoutInflater - setAdditionalContentView(inflater.inflate(layoutResID, contentViewContainer, false)) + setAdditionalContentView(inflater.inflate(layoutResID, view, false)) } - fun setAdditionalContentView(view: View?) { - contentViewContainer.removeAllViewsInLayout() - if (view != null) { - contentViewContainer.visibility = View.VISIBLE + fun setAdditionalContentView(view: View?, index: Int = -1) { + this.view.removeView(additionalContentView) + additionalContentView = view + if (index >= 0) { + this.view.addView(view, index) } else { - contentViewContainer.visibility = View.GONE + this.view.addView(view) } - contentViewContainer.addView(view) } - fun getContentView(): View? { - return if (contentViewContainer.childCount > 0) { - contentViewContainer.getChildAt(0) - } else { - null - } - } + fun getContentView(): View? = additionalContentView } \ No newline at end of file diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/NPCBannerView.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/NPCBannerView.kt new file mode 100644 index 000000000..abf46f993 --- /dev/null +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/NPCBannerView.kt @@ -0,0 +1,65 @@ +package com.habitrpg.android.habitica.ui.views + +import android.content.Context +import android.graphics.Bitmap +import android.graphics.Shader +import android.graphics.drawable.BitmapDrawable +import android.util.AttributeSet +import android.widget.FrameLayout +import android.widget.ImageView +import com.facebook.drawee.view.SimpleDraweeView +import com.habitrpg.android.habitica.R +import com.habitrpg.android.habitica.extensions.backgroundCompat +import com.habitrpg.android.habitica.extensions.bindView +import com.habitrpg.android.habitica.extensions.layoutInflater +import com.habitrpg.android.habitica.helpers.RxErrorHandler +import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils +import rx.Observable +import rx.android.schedulers.AndroidSchedulers +import rx.functions.Action1 + +class NPCBannerView(context: Context?, attrs: AttributeSet?) : FrameLayout(context, attrs) { + + private val backgroundView: ImageView by bindView(R.id.backgroundView) + private val sceneView: SimpleDraweeView by bindView(R.id.sceneView) + + var shopSpriteSuffix: String = "" + set(value) { + field = if (value.isEmpty() || value.startsWith("_")) { + value + } else { + "_"+value + } + if (identifier.isNotEmpty()) { + setImage() + } + } + var identifier: String = "" + set(value) { + field = value + setImage() + } + + init { + context?.layoutInflater?.inflate(R.layout.npc_banner, this) + } + + private fun setImage() { + DataBindingUtils.loadImage(sceneView, identifier + "_scene" + shopSpriteSuffix) + + backgroundView.scaleType = ImageView.ScaleType.FIT_START + + DataBindingUtils.loadImage(identifier + "_background" + shopSpriteSuffix, { + val aspectRatio = it.width / it.height.toFloat() + val height = context.resources.getDimension(R.dimen.shop_height).toInt() + val width = Math.round(height * aspectRatio) + val drawable = BitmapDrawable(context.resources, Bitmap.createScaledBitmap(it, width, height, false)) + drawable.tileModeX = Shader.TileMode.REPEAT + Observable.just(drawable) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(Action1 { + backgroundView.backgroundCompat = it + }, RxErrorHandler.handleEmptyError()) + }) + } +} \ No newline at end of file diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/social/QuestProgressView.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/social/QuestProgressView.kt index f32e77de4..956c9eb16 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/social/QuestProgressView.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/social/QuestProgressView.kt @@ -210,6 +210,12 @@ class QuestProgressView : LinearLayout { alert.setTitleBackground(R.color.orange_10) alert.setSubtitle(context.getString(R.string.strike_active_subtitle, getNpcName(key))) alert.setMessage(context.getString(R.string.strike_active_description, getLongNPCName(key), quest?.boss?.name ?: "", getLocationName(key))) + + val npcBannerView = NPCBannerView(context, null) + npcBannerView.shopSpriteSuffix = quest?.key ?: "" + npcBannerView.identifier = key + alert.setAdditionalContentView(npcBannerView, 1) + alert.setButton(AlertDialog.BUTTON_POSITIVE, context.getString(R.string.close), { dialog, _ -> dialog.dismiss() })