Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue40 item compare #12

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions AndorsTrail/res/layout/iteminfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,118 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>

<LinearLayout
android:id="@+id/compareinfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/dialog_margin"
>
<TextView
android:id="@+id/compareinfo_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/inventory_info"
style="@style/titleWithIcon"
android:drawableLeft="@drawable/equip_weapon"
/>

<TextView
android:id="@+id/compareinfo_description"
android:textStyle="italic"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/section_margin"
/>

<TextView
android:id="@+id/compareinfo_displaytype"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:layout_marginBottom="@dimen/section_margin"
>
<TextView
android:text="@string/iteminfo_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/compareinfo_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>

<com.gpl.rpg.AndorsTrail.view.ItemEffectsView
android:id="@+id/compareinfo_effects"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>

<LinearLayout
android:id="@+id/compare2info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/dialog_margin"
>
<TextView
android:id="@+id/compare2info_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/inventory_info"
style="@style/titleWithIcon"
android:drawableLeft="@drawable/equip_weapon"
/>

<TextView
android:id="@+id/compare2info_description"
android:textStyle="italic"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/section_margin"
/>

<TextView
android:id="@+id/compare2info_displaytype"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:layout_marginBottom="@dimen/section_margin"
>
<TextView
android:text="@string/iteminfo_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/compare2info_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>

<com.gpl.rpg.AndorsTrail.view.ItemEffectsView
android:id="@+id/compare2info_effects"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>

Expand Down
1 change: 1 addition & 0 deletions AndorsTrail/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@

<!-- <string name="key_required">A specific key is required to pass.</string> -->

<string name="iteminfo_title_equipped">(Equipped)</string>
<string name="iteminfo_category">Category: </string>
<string name="iteminfo_action_use">Use</string>
<string name="iteminfo_action_equip">Equip</string>
Expand Down
102 changes: 80 additions & 22 deletions AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/ItemInfoActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail.R;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.model.item.Inventory;
import com.gpl.rpg.AndorsTrail.model.item.ItemType;
import com.gpl.rpg.AndorsTrail.view.ItemEffectsView;

Expand All @@ -35,35 +36,59 @@ public void onCreate(Bundle savedInstanceState) {
Bundle params = intent.getExtras();
String itemTypeID = params.getString("itemTypeID");
final ItemType itemType = world.itemTypes.getItemType(itemTypeID);
final ItemType equippedType;
final ItemType secondaryEquippedType;

if (itemType.isEquippable()) {
equippedType = world.model.player.inventory.getItemTypeInWearSlot(itemType.category.inventorySlot);
if (itemType.category.inventorySlot == Inventory.WearSlot.leftring)
{
secondaryEquippedType = world.model.player.inventory.getItemTypeInWearSlot(Inventory.WearSlot.rightring);
} else if (itemType.category.inventorySlot == Inventory.WearSlot.weapon) {
secondaryEquippedType = world.model.player.inventory.getItemTypeInWearSlot(Inventory.WearSlot.shield);
} else {
secondaryEquippedType = null;
}
} else {
equippedType = null;
secondaryEquippedType = null;
}



final String buttonText = params.getString("buttonText");
boolean buttonEnabled = params.getBoolean("buttonEnabled");
final Resources resources = getResources();

setContentView(R.layout.iteminfo);

TextView tv = (TextView) findViewById(R.id.iteminfo_title);
tv.setText(itemType.getName(world.model.player));
world.tileManager.setImageViewTileForSingleItemType(getResources(), tv, itemType);

tv = (TextView) findViewById(R.id.iteminfo_description);
String description = itemType.getDescription();
if (description != null) {
tv.setText(description);
tv.setVisibility(View.VISIBLE);
fillTitle(world, resources, (TextView) findViewById(R.id.iteminfo_title), itemType, (itemType == equippedType || itemType == secondaryEquippedType));
fillDescription((TextView) findViewById(R.id.iteminfo_description), itemType);
fillCategory((TextView) findViewById(R.id.iteminfo_category), itemType);
fillItemEffects((ItemEffectsView) findViewById(R.id.iteminfo_effects), itemType);
fillDisplayType(resources, (TextView) findViewById(R.id.iteminfo_displaytype), itemType);

if (equippedType != null && equippedType != itemType){
findViewById(R.id.compareinfo).setVisibility(View.VISIBLE);
fillTitle(world, resources, (TextView) findViewById(R.id.compareinfo_title), equippedType, true);
fillDescription((TextView) findViewById(R.id.compareinfo_description), equippedType);
fillCategory((TextView) findViewById(R.id.compareinfo_category), equippedType);
fillItemEffects((ItemEffectsView) findViewById(R.id.compareinfo_effects), equippedType);
fillDisplayType(resources, (TextView) findViewById(R.id.compareinfo_displaytype), equippedType);
} else {
tv.setVisibility(View.GONE);
findViewById(R.id.compareinfo).setVisibility(View.GONE);
}

tv = (TextView) findViewById(R.id.iteminfo_category);
tv.setText(itemType.category.displayName);

((ItemEffectsView) findViewById(R.id.iteminfo_effects)).update(
itemType.effects_equip,
itemType.effects_use == null ? null : Collections.singletonList(itemType.effects_use),
itemType.effects_hit == null ? null : Collections.singletonList(itemType.effects_hit),
itemType.effects_kill == null ? null : Collections.singletonList(itemType.effects_kill),
itemType.isWeapon()
);
if (secondaryEquippedType != null && itemType != secondaryEquippedType && equippedType != secondaryEquippedType) {
findViewById(R.id.compare2info).setVisibility(View.VISIBLE);
fillTitle(world, resources, (TextView) findViewById(R.id.compare2info_title), secondaryEquippedType, true);
fillDescription((TextView) findViewById(R.id.compare2info_description), secondaryEquippedType);
fillCategory((TextView) findViewById(R.id.compare2info_category), secondaryEquippedType);
fillItemEffects((ItemEffectsView) findViewById(R.id.compare2info_effects), secondaryEquippedType);
fillDisplayType(resources, (TextView) findViewById(R.id.compare2info_displaytype), secondaryEquippedType);
} else {
findViewById(R.id.compare2info).setVisibility(View.GONE);
}

Button b = (Button) findViewById(R.id.iteminfo_close);
b.setOnClickListener(new OnClickListener() {
Expand Down Expand Up @@ -93,16 +118,49 @@ public void onClick(View arg0) {
}
});

tv = (TextView) findViewById(R.id.iteminfo_displaytype);
}

private static void fillTitle(WorldContext world, Resources resources, TextView tv, ItemType itemType, boolean equipped) {
tv.setText(itemType.getName(world.model.player) + (equipped ? " " + resources.getString(R.string.iteminfo_title_equipped) : ""));
world.tileManager.setImageViewTileForSingleItemType(resources, tv, itemType);

}

private static void fillCategory(TextView tv, ItemType itemType) {
tv.setText(itemType.category.displayName);
}

private static void fillDisplayType(Resources resources, TextView tv, ItemType itemType) {
if (itemType.isOrdinaryItem()) {
tv.setVisibility(View.GONE);
} else {
tv.setVisibility(View.VISIBLE);
final String diplayType = getDisplayTypeString(getResources(), itemType);
final String diplayType = getDisplayTypeString(resources, itemType);
tv.setText(diplayType);
}
}

private static void fillItemEffects(ItemEffectsView iev, ItemType itemType) {
iev.update(
itemType.effects_equip,
itemType.effects_use == null ? null : Collections.singletonList(itemType.effects_use),
itemType.effects_hit == null ? null : Collections.singletonList(itemType.effects_hit),
itemType.effects_kill == null ? null : Collections.singletonList(itemType.effects_kill),
itemType.isWeapon()
);
}

private static void fillDescription(TextView tv, ItemType itemType) {
String description = itemType.getDescription();
if (description != null) {
tv.setText(description);
tv.setVisibility(View.VISIBLE);
} else {
tv.setVisibility(View.GONE);
}
}


public static String getDisplayTypeString(Resources res, ItemType itemType) {
switch (itemType.displayType) {
case rare: return res.getString(R.string.iteminfo_displaytypes_rare);
Expand Down