mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-18 19:59:00 +00:00
add quest progress
- hp bar and rage bar for boss - item list for collection quest
This commit is contained in:
parent
2f09ab00b3
commit
7880bb6a13
10 changed files with 266 additions and 2 deletions
3
Habitica/assets/migrations/Habitica/13.sql
Normal file
3
Habitica/assets/migrations/Habitica/13.sql
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
DELETE FROM QuestContent;
|
||||
ALTER TABLE QuestProgress ADD COLUMN hp float;
|
||||
ALTER TABLE QuestProgress ADD COLUMN rage float;
|
||||
|
|
@ -114,6 +114,40 @@
|
|||
bind:questImageName='@{"quest_"+ quest.key}'
|
||||
/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:visibility="@{group.quest.active? View.VISIBLE : View.GONE}">
|
||||
|
||||
<include
|
||||
android:id="@+id/bossHpBar"
|
||||
layout="@layout/value_bar"
|
||||
bind:barForegroundColor="@{@color/hpColor}"
|
||||
bind:description='@{String.format("%.0f",Math.ceil(group.quest.getProgress().hp))+" / "+String.format("%.0f",Math.ceil(quest.boss.hp))}'
|
||||
bind:icon="@drawable/ic_header_heart"
|
||||
bind:partyMembers="@{true}"
|
||||
bind:text='@{"Boss Health"}'
|
||||
bind:weightToShow="@{(float)(group.quest.getProgress().hp / quest.boss.hp)}" />
|
||||
|
||||
<include
|
||||
android:id="@+id/bossRageBar"
|
||||
layout="@layout/value_bar"
|
||||
bind:barForegroundColor="@{@color/mpColor}"
|
||||
bind:description='@{String.format("%.0f",Math.ceil(group.quest.getProgress().rage))+" / "+String.format("%.0f",Math.ceil(quest.boss.rage_value))}'
|
||||
bind:icon="@drawable/ic_header_magic"
|
||||
bind:partyMembers="@{true}"
|
||||
bind:text='@{"Rage"}'
|
||||
bind:weightToShow="@{(float)(group.quest.getProgress().rage / quest.boss.rage_value)}" />
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/collectionStats"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
|||
27
Habitica/res/layout/fragment_quest_collect.xml
Normal file
27
Habitica/res/layout/fragment_quest_collect.xml
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="8dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="item to collect" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/count"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="100 / 100" />
|
||||
</LinearLayout>
|
||||
|
|
@ -10,5 +10,5 @@ public class HabitDatabase {
|
|||
|
||||
public static final String NAME = "Habitica";
|
||||
|
||||
public static final int VERSION = 12;
|
||||
public static final int VERSION = 13;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,83 @@
|
|||
package com.habitrpg.android.habitica.ui.adapter.social;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.QuestContent;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.QuestProgress;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class QuestCollectRecyclerViewAdapter extends RecyclerView.Adapter<QuestCollectRecyclerViewAdapter.QuestCollectViewHolder> {
|
||||
|
||||
private ArrayList<String> collect = new ArrayList<>();
|
||||
|
||||
private QuestProgress progress;
|
||||
private QuestContent quest;
|
||||
|
||||
public void setQuestProgress(QuestProgress progress) {
|
||||
this.progress = progress;
|
||||
collect.clear();
|
||||
collect.addAll(progress.collect.keySet());
|
||||
this.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void setQuestContent(QuestContent quest){
|
||||
this.quest = quest;
|
||||
this.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public QuestCollectViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
|
||||
View view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.fragment_quest_collect, parent, false);
|
||||
|
||||
return new QuestCollectViewHolder(view);
|
||||
}
|
||||
@Override
|
||||
public void onBindViewHolder(QuestCollectViewHolder holder, int position) {
|
||||
holder.bind(collect.get(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return collect == null ? 0 : collect.size();
|
||||
}
|
||||
|
||||
class QuestCollectViewHolder extends RecyclerView.ViewHolder {
|
||||
@Bind(R.id.image)
|
||||
ImageView image;
|
||||
|
||||
@Bind(R.id.name)
|
||||
TextView name;
|
||||
|
||||
@Bind(R.id.count)
|
||||
TextView count;
|
||||
|
||||
View view;
|
||||
|
||||
public QuestCollectViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
ButterKnife.bind(this, itemView);
|
||||
this.view = itemView;
|
||||
}
|
||||
|
||||
public void bind(String key) {
|
||||
Picasso.with(view.getContext())
|
||||
.load("https://habitica-assets.s3.amazonaws.com/mobileApp/images/" + "quest_" + quest.key + "_" + key + ".png")
|
||||
.into(image);
|
||||
name.setText(quest.getCollect().get(key).text);
|
||||
count.setText(progress.collect.get(key) + " / " + quest.getCollect().get(key).count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,8 @@ import android.graphics.Color;
|
|||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
|
@ -17,6 +19,8 @@ import android.widget.TextView;
|
|||
import com.habitrpg.android.habitica.APIHelper;
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.databinding.FragmentGroupInfoBinding;
|
||||
import com.habitrpg.android.habitica.databinding.ValueBarBinding;
|
||||
import com.habitrpg.android.habitica.ui.adapter.social.QuestCollectRecyclerViewAdapter;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Group;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.QuestContent;
|
||||
|
|
@ -41,8 +45,16 @@ public class GroupInformationFragment extends Fragment {
|
|||
APIHelper mAPIHelper;
|
||||
@Bind(R.id.questMemberView)
|
||||
LinearLayout questMemberView;
|
||||
@Bind(R.id.collectionStats)
|
||||
RecyclerView collectionStats;
|
||||
private Group group;
|
||||
private HabitRPGUser user;
|
||||
private QuestContent quest;
|
||||
private ValueBarBinding bossHpBar;
|
||||
private ValueBarBinding bossRageBar;
|
||||
|
||||
private QuestCollectRecyclerViewAdapter questCollectViewAdapter;
|
||||
|
||||
|
||||
|
||||
public static GroupInformationFragment newInstance(Group group, HabitRPGUser user, APIHelper mAPIHelper) {
|
||||
|
|
@ -78,6 +90,12 @@ public class GroupInformationFragment extends Fragment {
|
|||
|
||||
ButterKnife.bind(this, view);
|
||||
|
||||
collectionStats.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
questCollectViewAdapter = new QuestCollectRecyclerViewAdapter();
|
||||
collectionStats.setAdapter(questCollectViewAdapter);
|
||||
bossHpBar = DataBindingUtil.bind(view.findViewById(R.id.bossHpBar));
|
||||
bossRageBar = DataBindingUtil.bind(view.findViewById(R.id.bossRageBar));
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
|
|
@ -95,6 +113,8 @@ public class GroupInformationFragment extends Fragment {
|
|||
updateQuestMember(group);
|
||||
}
|
||||
|
||||
updateQuestProgress(group, quest);
|
||||
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
|
|
@ -102,6 +122,20 @@ public class GroupInformationFragment extends Fragment {
|
|||
if (viewBinding != null) {
|
||||
viewBinding.setQuest(quest);
|
||||
}
|
||||
|
||||
updateQuestProgress(group, quest);
|
||||
|
||||
this.quest = quest;
|
||||
}
|
||||
|
||||
private void updateQuestProgress(Group group, QuestContent quest) {
|
||||
if (group == null || quest == null) {
|
||||
return;
|
||||
}
|
||||
questCollectViewAdapter.setQuestContent(quest);
|
||||
questCollectViewAdapter.setQuestProgress(group.quest.getProgress());
|
||||
bossHpBar.valueBarLayout.setVisibility((quest.boss != null && quest.boss.hp > 0) ? View.VISIBLE : View.GONE);
|
||||
bossRageBar.valueBarLayout.setVisibility((quest.boss != null && quest.boss.rage_value > 0) ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
private void updateQuestMember(Group group) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
package com.magicmicky.habitrpgwrapper.lib.models;
|
||||
|
||||
import com.habitrpg.android.habitica.HabitDatabase;
|
||||
import com.raizlabs.android.dbflow.annotation.Column;
|
||||
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
|
||||
import com.raizlabs.android.dbflow.annotation.Table;
|
||||
import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||
|
||||
@Table(databaseName = HabitDatabase.NAME)
|
||||
public class QuestCollect extends BaseModel {
|
||||
@Column
|
||||
public String key;
|
||||
|
||||
@Column
|
||||
public String quest_key;
|
||||
|
||||
@Column
|
||||
@PrimaryKey(autoincrement = true)
|
||||
long id;
|
||||
|
||||
@Column
|
||||
public String text;
|
||||
|
||||
@Column
|
||||
public int count;
|
||||
}
|
||||
|
|
@ -2,10 +2,18 @@ package com.magicmicky.habitrpgwrapper.lib.models;
|
|||
|
||||
import com.habitrpg.android.habitica.HabitDatabase;
|
||||
import com.raizlabs.android.dbflow.annotation.Column;
|
||||
import com.raizlabs.android.dbflow.annotation.OneToMany;
|
||||
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
|
||||
import com.raizlabs.android.dbflow.annotation.Table;
|
||||
import com.raizlabs.android.dbflow.sql.builder.Condition;
|
||||
import com.raizlabs.android.dbflow.sql.language.Select;
|
||||
import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by Negue on 29.09.2015.
|
||||
*/
|
||||
|
|
@ -38,6 +46,41 @@ public class QuestContent extends BaseModel {
|
|||
|
||||
public QuestBoss boss;
|
||||
|
||||
HashMap<String, QuestCollect> collect;
|
||||
|
||||
@OneToMany(methods = {OneToMany.Method.SAVE, OneToMany.Method.DELETE}, variableName = "collect")
|
||||
public Collection<QuestCollect> getCollectCollection() {
|
||||
return getCollect().values();
|
||||
}
|
||||
|
||||
public HashMap<String, QuestCollect> getCollect() {
|
||||
if (collect == null) {
|
||||
List<QuestCollect> collectList = new Select()
|
||||
.from(QuestCollect.class)
|
||||
.where(Condition.column("quest_key").eq(this.key))
|
||||
.queryList();
|
||||
collect = new HashMap<>();
|
||||
for (QuestCollect c : collectList) {
|
||||
collect.put(c.key, c);
|
||||
}
|
||||
}
|
||||
return collect;
|
||||
}
|
||||
|
||||
public void setCollect(HashMap<String, QuestCollect> collect) {
|
||||
this.collect = collect;
|
||||
}
|
||||
|
||||
public void save() {
|
||||
if (collect != null) {
|
||||
for (Map.Entry<String, QuestCollect> kv : collect.entrySet()) {
|
||||
kv.getValue().quest_key = key;
|
||||
kv.getValue().key = kv.getKey();
|
||||
}
|
||||
}
|
||||
super.save();
|
||||
}
|
||||
|
||||
// todo drops
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import com.raizlabs.android.dbflow.annotation.PrimaryKey;
|
|||
import com.raizlabs.android.dbflow.annotation.Table;
|
||||
import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Created by viirus on 06/07/15.
|
||||
*/
|
||||
|
|
@ -19,6 +21,11 @@ public class QuestProgress extends BaseModel {
|
|||
@Column
|
||||
private float down, up;
|
||||
|
||||
@Column
|
||||
public double hp, rage;
|
||||
|
||||
public HashMap<String, Integer> collect;
|
||||
|
||||
private QuestProgress(float down, float up) {
|
||||
this.down = down;
|
||||
this.up = up;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import com.google.gson.reflect.TypeToken;
|
|||
import com.magicmicky.habitrpgwrapper.lib.models.ChatMessage;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Group;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Quest;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
|
|
@ -20,7 +21,9 @@ public class GroupDeserializer implements JsonDeserializer<Group> {
|
|||
JsonObject obj = json.getAsJsonObject();
|
||||
group.id = obj.get("_id").getAsString();
|
||||
group.name = obj.get("name").getAsString();
|
||||
group.description = obj.get("description").getAsString();
|
||||
if (obj.has("description")) {
|
||||
group.description = obj.get("description").getAsString();
|
||||
}
|
||||
|
||||
if (obj.has("memberCount")) {
|
||||
group.memberCount = obj.get("memberCount").getAsInt();
|
||||
|
|
@ -48,6 +51,10 @@ public class GroupDeserializer implements JsonDeserializer<Group> {
|
|||
group.leaderID = obj.get("leader").getAsJsonObject().get("_id").getAsString();
|
||||
}
|
||||
}
|
||||
if (obj.has("quest")) {
|
||||
group.quest = context.deserialize(obj.get("quest"), new TypeToken<Quest>() {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
return group;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue