diff --git a/AndorsTrail/res/layout-land/heroinfo_inventory.xml b/AndorsTrail/res/layout-land/heroinfo_inventory.xml index c48730d39..19a00479b 100644 --- a/AndorsTrail/res/layout-land/heroinfo_inventory.xml +++ b/AndorsTrail/res/layout-land/heroinfo_inventory.xml @@ -41,6 +41,35 @@ android:orientation="vertical" android:gravity="left" > + + + + + - \ No newline at end of file + diff --git a/AndorsTrail/res/layout/heroinfo_inventory.xml b/AndorsTrail/res/layout/heroinfo_inventory.xml index 3ca4ba0f6..557b4b119 100644 --- a/AndorsTrail/res/layout/heroinfo_inventory.xml +++ b/AndorsTrail/res/layout/heroinfo_inventory.xml @@ -4,39 +4,85 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - android:gravity="left" > - - - + - + + + + + + + - + android:orientation="vertical" + android:gravity="left" + > + + - + + - \ No newline at end of file + + + + + + + diff --git a/AndorsTrail/res/layout/heroinfo_skill_list.xml b/AndorsTrail/res/layout/heroinfo_skill_list.xml index a764e30bd..b851d7d18 100644 --- a/AndorsTrail/res/layout/heroinfo_skill_list.xml +++ b/AndorsTrail/res/layout/heroinfo_skill_list.xml @@ -1,23 +1,65 @@ - + + + android:layout_marginBottom="5dp" + android:layout_marginTop="10dp" + android:gravity="right" + android:orientation="horizontal"> + + + + + + + + + + + + android:layout_width="match_parent" + android:layout_height="wrap_content" /> - + \ No newline at end of file diff --git a/AndorsTrail/res/layout/shoplist.xml b/AndorsTrail/res/layout/shoplist.xml index 2b871b54f..5f6e93784 100644 --- a/AndorsTrail/res/layout/shoplist.xml +++ b/AndorsTrail/res/layout/shoplist.xml @@ -1,21 +1,38 @@ - + android:orientation="vertical"> - + android:layout_marginBottom="5dp" + android:layout_marginTop="10dp" + android:gravity="right" + android:orientation="horizontal" + android:layout_alignParentRight="true"> + + + + + - + \ No newline at end of file diff --git a/AndorsTrail/res/values/arrays.xml b/AndorsTrail/res/values/arrays.xml index da1fd0406..6a7c65b3f 100644 --- a/AndorsTrail/res/values/arrays.xml +++ b/AndorsTrail/res/values/arrays.xml @@ -8,6 +8,56 @@ @string/questlog_includecompleted_onlycompleted + + + @string/inventory_category_all + @string/inventory_category_weapons + @string/inventory_category_armor + @string/inventory_category_usable + @string/inventory_category_quest + @string/inventory_category_other + + + + + @string/inventory_sort_custom + @string/inventory_sort_name + @string/inventory_sort_price + @string/inventory_sort_quantity + @string/inventory_sort_rarity + @string/inventory_sort_type + + + + + @string/skill_category_all + @string/skill_category_offense + @string/skill_category_defense + @string/skill_category_criticals + @string/skill_category_immunity + @string/skill_category_utility + @string/skill_category_speciality + @string/skill_category_proficiency + + + + + @string/skill_sort_unsorted + @string/skill_sort_name + @string/skill_sort_points + @string/skill_sort_unlocked + + + + + @string/shoplist_sort_custom + @string/shoplist_sort_name + @string/shoplist_sort_price + @string/shoplist_sort_quantity + @string/shoplist_sort_rarity + @string/shoplist_sort_type + + @string/preferences_display_loot_dialog @string/preferences_display_loot_dialog_on_items diff --git a/AndorsTrail/res/values/authors.xml b/AndorsTrail/res/values/authors.xml index 3078720ad..b736163ba 100644 --- a/AndorsTrail/res/values/authors.xml +++ b/AndorsTrail/res/values/authors.xml @@ -18,6 +18,7 @@ Additional programming by <a href="https://github.com/Zukero">Kevin Pochat</a><br /> Additional programming by Lucas Delvallet<br /> Additional programming by Florian Doublet<br /> + Additional programming by M.H. Alkotob<br /> Additional graphics by Karvis<br /> Russian translation by Dreamer..., e.solodookhin, shell.andor, konstmih, istasman, Aleksey Kabanov, Alexander Zubok, Paul Sulemenkov and dromoz<br /> Italian translation by k6blue, liogiu, Joker and Andrea Luciano Damico<br /> diff --git a/AndorsTrail/res/values/strings.xml b/AndorsTrail/res/values/strings.xml index b8a7f254a..850684e9b 100644 --- a/AndorsTrail/res/values/strings.xml +++ b/AndorsTrail/res/values/strings.xml @@ -33,11 +33,15 @@ Overview Items Skills + Category + Sort Level up Level Total experience Worn equipment Inventory + Category + Sort By Gold: %1$d Action points (AP): Quests @@ -142,6 +146,7 @@ Your gold: %1$d %1$s bought. %1$s sold. + Sort Level up Welcome to level %1$d! @@ -631,4 +636,39 @@ Every skill level increases the attack chance of weapons with %1$d %% of their o Use translation of interface and content, where available. (requires restart) Changing locale requires restart. Andor\'s Trail has been closed. + All + Favorites + Weapon + Armor + Consumable + Quest Item + Other + + Unsorted + Name + Price + Quantity + Rarity + Type + + Unsorted + Name + Price + Quantity + Rarity + Type + + All + Offense + Defense + Criticals + Immunity + Utility + Speciality + Proficiency + + Unsorted + Name + Points + Unlocked diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/fragment/HeroinfoActivity_Inventory.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/fragment/HeroinfoActivity_Inventory.java index 679bcaaed..d47d8040c 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/fragment/HeroinfoActivity_Inventory.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/fragment/HeroinfoActivity_Inventory.java @@ -10,9 +10,14 @@ import android.view.View.OnClickListener; import android.widget.AdapterView; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; +import android.widget.ArrayAdapter; +import android.widget.Button; import android.widget.ImageView; import android.widget.ListView; +import android.widget.Spinner; import android.widget.TextView; +import android.widget.Toast; + import com.gpl.rpg.AndorsTrail.AndorsTrailApplication; import com.gpl.rpg.AndorsTrail.Dialogs; import com.gpl.rpg.AndorsTrail.R; @@ -37,7 +42,16 @@ public final class HeroinfoActivity_Inventory extends Fragment { private TileCollection wornTiles; private Player player; + private ListView inventoryList; + private Spinner inventorylist_categories; + private Spinner inventorylist_sort; private ItemContainerAdapter inventoryListAdapter; + private ItemContainerAdapter inventoryWeaponsListAdapter; + private ItemContainerAdapter inventoryArmorListAdapter; + private ItemContainerAdapter inventoryUsableListAdapter; + private ItemContainerAdapter inventoryQuestListAdapter; + private ItemContainerAdapter inventoryOtherListAdapter; + private TextView heroinfo_stats_gold; private TextView heroinfo_stats_attack; @@ -60,17 +74,21 @@ public final class HeroinfoActivity_Inventory extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View v = inflater.inflate(R.layout.heroinfo_inventory, container, false); + final View v = inflater.inflate(R.layout.heroinfo_inventory, container, false); - ListView inventoryList = (ListView) v.findViewById(R.id.inventorylist_root); + initialiseInventorySpinners(v); + + inventoryList = (ListView) v.findViewById(R.id.inventorylist_root); registerForContextMenu(inventoryList); inventoryList.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View v, int position, long id) { - ItemType itemType = inventoryListAdapter.getItem(position).itemType; + // Move this code to separate function? -- Done + ItemType itemType = getSelectedItemType(position); showInventoryItemInfo(itemType.id); } }); + ItemContainer inv = player.inventory; wornTiles = world.tileManager.loadTilesFor(player.inventory, getResources()); inventoryListAdapter = new ItemContainerAdapter(getActivity(), world.tileManager, inv, player, wornTiles); @@ -93,6 +111,52 @@ public final class HeroinfoActivity_Inventory extends Fragment { return v; } + private void initialiseInventorySpinners(View v) { + inventorylist_categories = (Spinner) v.findViewById(R.id.inventorylist_category_filters); + ArrayAdapter categoryFilterAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.inventorylist_category_filters, android.R.layout.simple_spinner_item); + categoryFilterAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + inventorylist_categories.setAdapter(categoryFilterAdapter); + inventorylist_categories.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView arg0, View arg1, int arg2, long arg3) { + world.model.uiSelections.selectedInventoryCategory = inventorylist_categories.getSelectedItemPosition(); + reloadShownCategory(world.model.uiSelections.selectedInventoryCategory); + } + + @Override + public void onNothingSelected(AdapterView arg0) { + world.model.uiSelections.selectedInventoryCategory = 0; + } + }); + inventorylist_categories.setSelection(world.model.uiSelections.selectedInventoryCategory); + + + inventorylist_sort = (Spinner) v.findViewById(R.id.inventorylist_sort_filters); + ArrayAdapter sortFilterAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.inventorylist_sort_filters, android.R.layout.simple_spinner_item); + sortFilterAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + inventorylist_sort.setAdapter(sortFilterAdapter); + inventorylist_sort.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + world.model.uiSelections.selectedInventorySort = inventorylist_sort.getSelectedItemPosition(); + reloadShownSort(player.inventory); + } + + @Override + public void onNothingSelected(AdapterView parent) { + // Reset to "Custom" position + world.model.uiSelections.selectedInventorySort = 0; + } + }); + inventorylist_sort.setSelection(world.model.uiSelections.selectedInventorySort); + } + + private void setHeroStatsVisiblity(int visibility) { + heroinfo_stats_gold.setVisibility(visibility); + heroinfo_stats_attack.setVisibility(visibility); + heroinfo_stats_defense.setVisibility(visibility); + } + @Override public void onStart() { super.onStart(); @@ -201,7 +265,11 @@ public final class HeroinfoActivity_Inventory extends Fragment { } private void updateItemList() { - inventoryListAdapter.notifyDataSetChanged(); + int currentScreen = world.model.uiSelections.selectedInventoryCategory; + if (currentScreen == 0) + inventoryListAdapter.notifyDataSetChanged(); + else + reloadShownCategory(world.model.uiSelections.selectedInventoryCategory); } @Override @@ -226,6 +294,29 @@ public final class HeroinfoActivity_Inventory extends Fragment { lastSelectedItem = null; } + private ItemType getSelectedItemType(int position) { + int v = world.model.uiSelections.selectedInventoryCategory; + + if (v == 0) { //All items + return inventoryListAdapter.getItem(position).itemType; + }else if (v == 1) { //Weapon items + return inventoryWeaponsListAdapter.getItem(position).itemType; + } else if (v == 2) { //Armor items + return inventoryArmorListAdapter.getItem(position).itemType; + } else if (v == 3) { //Usable items + return inventoryUsableListAdapter.getItem(position).itemType; + } else if (v == 4) { //Quest items + return inventoryQuestListAdapter.getItem(position).itemType; + } else if (v == 5) { //Other items + return inventoryOtherListAdapter.getItem(position).itemType; + } + + // Better than crashing... + return inventoryListAdapter.getItem(position).itemType; + + } + + private ItemType getSelectedItemType(AdapterContextMenuInfo info) { return inventoryListAdapter.getItem(info.position).itemType; } @@ -340,4 +431,48 @@ public final class HeroinfoActivity_Inventory extends Fragment { Intent intent = Dialogs.getIntentForItemInfo(getActivity(), itemType.id, action, text, enabled, null); startActivityForResult(intent, INTENTREQUEST_ITEMINFO); } -} \ No newline at end of file + + private void reloadShownCategory(int v) { // Apologies about the code duplication, + // just didn't seem to make sense as an array, although I did create a nice array for skill category adapters. + + // Decide which category to show + if (v == 0) { //All items + inventoryList.setAdapter(inventoryListAdapter); + inventoryListAdapter.notifyDataSetChanged(); + } else if (v == 1) { //Weapon items + inventoryWeaponsListAdapter = new ItemContainerAdapter(getActivity(), world.tileManager, player.inventory.buildWeaponItems(), player, wornTiles); + inventoryList.setAdapter(inventoryWeaponsListAdapter); + inventoryWeaponsListAdapter.notifyDataSetChanged(); + } else if (v == 2) { //Armor items + inventoryArmorListAdapter = new ItemContainerAdapter(getActivity(), world.tileManager, player.inventory.buildArmorItems(), player, wornTiles); + inventoryList.setAdapter(inventoryArmorListAdapter); + inventoryArmorListAdapter.notifyDataSetChanged(); + } else if (v == 3) { //Usable items + inventoryUsableListAdapter = new ItemContainerAdapter(getActivity(), world.tileManager, player.inventory.buildUsableItems(), player, wornTiles); + inventoryList.setAdapter(inventoryUsableListAdapter); + inventoryUsableListAdapter.notifyDataSetChanged(); + } else if (v == 4) { //Quest items + inventoryQuestListAdapter = new ItemContainerAdapter(getActivity(), world.tileManager, player.inventory.buildQuestItems(), player, wornTiles); + inventoryList.setAdapter(inventoryQuestListAdapter); + inventoryQuestListAdapter.notifyDataSetChanged(); + } else if (v == 5) { //Other items + inventoryOtherListAdapter = new ItemContainerAdapter(getActivity(), world.tileManager, player.inventory.buildOtherItems(), player, wornTiles); + inventoryList.setAdapter(inventoryOtherListAdapter); + inventoryOtherListAdapter.notifyDataSetChanged(); + } + //updateItemList(); + } + + private void reloadShownSort(Inventory inv) { + int selected = world.model.uiSelections.selectedInventorySort; + + inventoryListAdapter.reloadShownSort(selected, world.model.uiSelections.oldSortSelection, player.inventory, player); + + // Currently not functional, perhaps because selection only updates when changed. + if (world.model.uiSelections.oldSortSelection == selected) + world.model.uiSelections.oldSortSelection = 0; + else world.model.uiSelections.oldSortSelection = selected; + updateItemList(); + } + +} diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/fragment/HeroinfoActivity_Skills.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/fragment/HeroinfoActivity_Skills.java index 6bd30e740..3be757014 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/fragment/HeroinfoActivity_Skills.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/fragment/HeroinfoActivity_Skills.java @@ -9,7 +9,9 @@ import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; +import android.widget.ArrayAdapter; import android.widget.ListView; +import android.widget.Spinner; import android.widget.TextView; import com.gpl.rpg.AndorsTrail.AndorsTrailApplication; import com.gpl.rpg.AndorsTrail.Dialogs; @@ -20,6 +22,7 @@ import com.gpl.rpg.AndorsTrail.model.ability.SkillCollection; import com.gpl.rpg.AndorsTrail.model.actor.Player; import com.gpl.rpg.AndorsTrail.view.SkillListAdapter; +import java.util.ArrayList; public final class HeroinfoActivity_Skills extends Fragment { private static final int INTENTREQUEST_SKILLINFO = 12; @@ -28,7 +31,10 @@ public final class HeroinfoActivity_Skills extends Fragment { private ControllerContext controllers; private Player player; - private SkillListAdapter skillListAdapter; + ListView skillList; + private ArrayList skillListCategoryViewsAdapters = new ArrayList(); + private Spinner skillList_categories; + private Spinner skillList_sort; private TextView listskills_number_of_increases; @Override @@ -46,13 +52,62 @@ public final class HeroinfoActivity_Skills extends Fragment { View v = inflater.inflate(R.layout.heroinfo_skill_list, container, false); final Activity ctx = getActivity(); - skillListAdapter = new SkillListAdapter(ctx, world.skills.getAllSkills(), player); - ListView skillList = (ListView) v.findViewById(R.id.heroinfo_listskills_list); - skillList.setAdapter(skillListAdapter); + + //Initiating drop-down list for category filters + skillList_categories = (Spinner) v.findViewById(R.id.skillList_category_filters); + ArrayAdapter skillCategoryFilterAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.skill_category_filters, android.R.layout.simple_spinner_item); + skillCategoryFilterAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + skillList_categories.setAdapter(skillCategoryFilterAdapter); + skillList_categories.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView arg0, View arg1, int arg2, long arg3) { + world.model.uiSelections.selectedSkillCategory = skillList_categories.getSelectedItemPosition(); + reloadShownCategory(); + } + + @Override + public void onNothingSelected(AdapterView arg0) { + world.model.uiSelections.selectedSkillCategory = 0; + } + }); + skillList_categories.setSelection(world.model.uiSelections.selectedSkillCategory); + + for(int i = 0; i< SkillCollection.SkillCategory.values().length; i++){ + // Creates a list of adapters for each category. + // The adapter at position 0 has all items. + // length + 1 in order to create an extra position for "all" + skillListCategoryViewsAdapters.add( + new SkillListAdapter(ctx, world.skills.getAllSkills(), player, i)); + } + + + //Initiating drop-down list for sort filters + skillList_sort = (Spinner) v.findViewById(R.id.skillList_sort_filters); + ArrayAdapter skillSortFilterAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.skill_sort_filters, android.R.layout.simple_spinner_item); + skillSortFilterAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + skillList_sort.setAdapter(skillSortFilterAdapter); + skillList_sort.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView arg0, View arg1, int arg2, long arg3) { + world.model.uiSelections.selectedSkillSort = skillList_sort.getSelectedItemPosition(); + reloadShownSort(); //Yet to be implemented + } + + @Override + public void onNothingSelected(AdapterView arg0) { + world.model.uiSelections.selectedSkillSort = 0; + } + }); + skillList_sort.setSelection(world.model.uiSelections.selectedSkillSort); + + + skillList = (ListView) v.findViewById(R.id.heroinfo_listskills_list); + skillList.setAdapter(getCurrentCategoryAdapter()); skillList.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View v, int position, long id) { - Intent intent = Dialogs.getIntentForSkillInfo(ctx, skillListAdapter.getItem(position).id); + Intent intent = Dialogs.getIntentForSkillInfo(ctx, + getCurrentCategoryAdapter().getItem(position).id); startActivityForResult(intent, INTENTREQUEST_SKILLINFO); } }); @@ -60,6 +115,25 @@ public final class HeroinfoActivity_Skills extends Fragment { return v; } + private void reloadShownSort() { + int v = world.model.uiSelections.selectedSkillSort; + if(v ==0); + if(v==1) getCurrentCategoryAdapter().sortByName(); + if(v==2) getCurrentCategoryAdapter().sortByPoints(); + if(v==3) getCurrentCategoryAdapter().sortByUnlocked(); + + updateSkillList(); + } + + private void reloadShownCategory() { + skillList.setAdapter(getCurrentCategoryAdapter()); + updateSkillList(); + } + private SkillListAdapter getCurrentCategoryAdapter(){ + return skillListCategoryViewsAdapters.get( + world.model.uiSelections.selectedSkillCategory); + } + @Override public void onStart() { super.onStart(); @@ -96,6 +170,6 @@ public final class HeroinfoActivity_Skills extends Fragment { } else { listskills_number_of_increases.setVisibility(View.GONE); } - skillListAdapter.notifyDataSetInvalidated(); + getCurrentCategoryAdapter().notifyDataSetInvalidated(); } -} \ No newline at end of file +} diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/fragment/ShopActivityFragment.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/fragment/ShopActivityFragment.java index 2cc0ba64e..1aa5476f3 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/fragment/ShopActivityFragment.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/fragment/ShopActivityFragment.java @@ -6,7 +6,10 @@ import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; import android.widget.ListView; +import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; import com.gpl.rpg.AndorsTrail.AndorsTrailApplication; @@ -17,6 +20,7 @@ import com.gpl.rpg.AndorsTrail.model.actor.Monster; import com.gpl.rpg.AndorsTrail.model.actor.Player; import com.gpl.rpg.AndorsTrail.model.item.ItemContainer; import com.gpl.rpg.AndorsTrail.resource.tiles.TileCollection; +import com.gpl.rpg.AndorsTrail.view.ItemContainerAdapter; import com.gpl.rpg.AndorsTrail.view.ShopItemContainerAdapter; import com.gpl.rpg.AndorsTrail.view.ShopItemContainerAdapter.OnContainerItemClickedListener; @@ -33,6 +37,7 @@ public abstract class ShopActivityFragment extends Fragment implements OnContain protected ItemContainer shopInventory; private TextView shop_gc; private ShopItemContainerAdapter listAdapter; + private Spinner shoplist_sort; protected abstract boolean isSellingInterface(); @@ -66,9 +71,34 @@ public abstract class ShopActivityFragment extends Fragment implements OnContain final boolean isSelling = isSellingInterface(); listAdapter = new ShopItemContainerAdapter(getActivity(), tiles, world.tileManager, player, isSelling ? player.inventory : shopInventory, this, isSelling); shoplist.setAdapter(listAdapter); + + //Initiating drop-down list for category filters + shoplist_sort = (Spinner) v.findViewById(R.id.shoplist_sort_filters); + ArrayAdapter sortFilterAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.shoplist_sort_filters, android.R.layout.simple_spinner_item); + sortFilterAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + shoplist_sort.setAdapter(sortFilterAdapter); + shoplist_sort.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView arg0, View arg1, int arg2, long arg3) { + world.model.uiSelections.selectedShopSort = shoplist_sort.getSelectedItemPosition(); + reloadShownSort(isSelling ? player.inventory : shopInventory); + } + + @Override + public void onNothingSelected(AdapterView arg0) { + world.model.uiSelections.selectedShopSort = 0; + } + }); + shoplist_sort.setSelection(world.model.uiSelections.selectedShopSort); + return v; } + private void reloadShownSort(ItemContainer itemContainer) { + listAdapter.reloadShownSort(world.model.uiSelections.selectedShopSort, itemContainer, player); + listAdapter.notifyDataSetChanged(); + } + @Override public void onStart() { super.onStart(); diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/InterfaceData.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/InterfaceData.java index 532544b39..3d368fc47 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/InterfaceData.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/InterfaceData.java @@ -1,6 +1,7 @@ package com.gpl.rpg.AndorsTrail.model; import com.gpl.rpg.AndorsTrail.model.actor.Monster; +import com.gpl.rpg.AndorsTrail.model.item.Inventory; import com.gpl.rpg.AndorsTrail.util.Coord; import java.io.DataInputStream; @@ -16,6 +17,13 @@ public final class InterfaceData { public String selectedTabHeroInfo = ""; public int selectedQuestFilter = 0; // Should not be parceled + public int selectedInventoryCategory = 0; //All + public int selectedInventorySort = 0; //Unsorted + public int oldSortSelection = 0; // Later will be used for reversing ascending/descending order + public int selectedSkillCategory = 0; //All + public int selectedSkillSort = 0; //Unsorted + public int selectedShopSort = 0; //Unsorted + public InterfaceData() { } diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/ability/SkillCollection.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/ability/SkillCollection.java index 7a3f75e1e..7fc01dc89 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/ability/SkillCollection.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/ability/SkillCollection.java @@ -54,6 +54,20 @@ public final class SkillCollection { ,specializationWeaponShield } + // should be in the same number &U order as in arrays.xml + public static enum SkillCategory { + all, // filler value -- don't use + offense, + defense, + criticals, + immunity, //fortitude? + utility, // efficiency? + specialty, + proficiency + } + + + public static final int PER_SKILLPOINT_INCREASE_WEAPON_CHANCE = 12; public static final int PER_SKILLPOINT_INCREASE_WEAPON_DAMAGE_MAX = 2; public static final int PER_SKILLPOINT_INCREASE_WEAPON_DAMAGE_MIN = 0; @@ -124,95 +138,95 @@ public final class SkillCollection { skills.put(skill.id.ordinal(), skill); } public void initialize() { - initializeSkill(new SkillInfo(SkillID.weaponChance, SkillInfo.MAXLEVEL_NONE, SkillInfo.LevelUpType.alwaysShown, null)); - initializeSkill(new SkillInfo(SkillID.weaponDmg, SkillInfo.MAXLEVEL_NONE, SkillInfo.LevelUpType.alwaysShown, null)); - initializeSkill(new SkillInfo(SkillID.barter, MAX_LEVEL_BARTER, SkillInfo.LevelUpType.alwaysShown, null)); - initializeSkill(new SkillInfo(SkillID.dodge, SkillInfo.MAXLEVEL_NONE, SkillInfo.LevelUpType.alwaysShown, null)); - initializeSkill(new SkillInfo(SkillID.barkSkin, MAX_LEVEL_BARKSKIN, SkillInfo.LevelUpType.alwaysShown, new SkillLevelRequirement[] { + initializeSkill(new SkillInfo(SkillID.weaponChance, SkillInfo.MAXLEVEL_NONE, SkillInfo.LevelUpType.alwaysShown, SkillCategory.offense, null)); + initializeSkill(new SkillInfo(SkillID.weaponDmg, SkillInfo.MAXLEVEL_NONE, SkillInfo.LevelUpType.alwaysShown, SkillCategory.offense, null)); + initializeSkill(new SkillInfo(SkillID.barter, MAX_LEVEL_BARTER, SkillInfo.LevelUpType.alwaysShown, SkillCategory.utility, null)); + initializeSkill(new SkillInfo(SkillID.dodge, SkillInfo.MAXLEVEL_NONE, SkillInfo.LevelUpType.alwaysShown, SkillCategory.defense, null)); + initializeSkill(new SkillInfo(SkillID.barkSkin, MAX_LEVEL_BARKSKIN, SkillInfo.LevelUpType.alwaysShown, SkillCategory.defense, new SkillLevelRequirement[] { SkillLevelRequirement.requireExperienceLevels(10, 0) ,SkillLevelRequirement.requirePlayerStats(Player.StatID.blockChance, 15, 0) })); - initializeSkill(new SkillInfo(SkillID.moreCriticals, SkillInfo.MAXLEVEL_NONE, SkillInfo.LevelUpType.alwaysShown, null)); - initializeSkill(new SkillInfo(SkillID.betterCriticals, SkillInfo.MAXLEVEL_NONE, SkillInfo.LevelUpType.alwaysShown, new SkillLevelRequirement[] { + initializeSkill(new SkillInfo(SkillID.moreCriticals, SkillInfo.MAXLEVEL_NONE, SkillInfo.LevelUpType.alwaysShown, SkillCategory.criticals, null)); + initializeSkill(new SkillInfo(SkillID.betterCriticals, SkillInfo.MAXLEVEL_NONE, SkillInfo.LevelUpType.alwaysShown, SkillCategory.criticals, new SkillLevelRequirement[] { SkillLevelRequirement.requireOtherSkill(SkillID.moreCriticals, 1) })); - initializeSkill(new SkillInfo(SkillID.speed, MAX_LEVEL_SPEED, SkillInfo.LevelUpType.alwaysShown, new SkillLevelRequirement[] { + initializeSkill(new SkillInfo(SkillID.speed, MAX_LEVEL_SPEED, SkillInfo.LevelUpType.alwaysShown, SkillCategory.offense, new SkillLevelRequirement[] { SkillLevelRequirement.requireExperienceLevels(15, 0) })); - initializeSkill(new SkillInfo(SkillID.coinfinder, SkillInfo.MAXLEVEL_NONE, SkillInfo.LevelUpType.alwaysShown, null)); - initializeSkill(new SkillInfo(SkillID.moreExp, SkillInfo.MAXLEVEL_NONE, SkillInfo.LevelUpType.alwaysShown, null)); - initializeSkill(new SkillInfo(SkillID.cleave, SkillInfo.MAXLEVEL_NONE, SkillInfo.LevelUpType.alwaysShown, new SkillLevelRequirement[] { + initializeSkill(new SkillInfo(SkillID.coinfinder, SkillInfo.MAXLEVEL_NONE, SkillInfo.LevelUpType.alwaysShown, SkillCategory.utility, null)); + initializeSkill(new SkillInfo(SkillID.moreExp, SkillInfo.MAXLEVEL_NONE, SkillInfo.LevelUpType.alwaysShown, SkillCategory.utility, null)); + initializeSkill(new SkillInfo(SkillID.cleave, SkillInfo.MAXLEVEL_NONE, SkillInfo.LevelUpType.alwaysShown, SkillCategory.offense, new SkillLevelRequirement[] { SkillLevelRequirement.requireOtherSkill(SkillID.weaponChance, 1) ,SkillLevelRequirement.requireOtherSkill(SkillID.weaponDmg, 1) })); - initializeSkill(new SkillInfo(SkillID.eater, SkillInfo.MAXLEVEL_NONE, SkillInfo.LevelUpType.alwaysShown, new SkillLevelRequirement[] { + initializeSkill(new SkillInfo(SkillID.eater, SkillInfo.MAXLEVEL_NONE, SkillInfo.LevelUpType.alwaysShown, SkillCategory.immunity, new SkillLevelRequirement[] { SkillLevelRequirement.requirePlayerStats(Player.StatID.maxHP, 20, 20) })); - initializeSkill(new SkillInfo(SkillID.fortitude, SkillInfo.MAXLEVEL_NONE, SkillInfo.LevelUpType.alwaysShown, new SkillLevelRequirement[] { + initializeSkill(new SkillInfo(SkillID.fortitude, SkillInfo.MAXLEVEL_NONE, SkillInfo.LevelUpType.alwaysShown, SkillCategory.immunity, new SkillLevelRequirement[] { SkillLevelRequirement.requireExperienceLevels(15, -10) })); - initializeSkill(new SkillInfo(SkillID.evasion, MAX_LEVEL_EVASION, SkillInfo.LevelUpType.alwaysShown, null)); - initializeSkill(new SkillInfo(SkillID.regeneration, SkillInfo.MAXLEVEL_NONE, SkillInfo.LevelUpType.alwaysShown, new SkillLevelRequirement[] { + initializeSkill(new SkillInfo(SkillID.evasion, MAX_LEVEL_EVASION, SkillInfo.LevelUpType.alwaysShown, SkillCategory.defense, null)); + initializeSkill(new SkillInfo(SkillID.regeneration, SkillInfo.MAXLEVEL_NONE, SkillInfo.LevelUpType.alwaysShown, SkillCategory.immunity, new SkillLevelRequirement[] { SkillLevelRequirement.requirePlayerStats(Player.StatID.maxHP, 30, 0) ,SkillLevelRequirement.requireOtherSkill(SkillID.fortitude, 1) })); - initializeSkill(new SkillInfo(SkillID.lowerExploss, MAX_LEVEL_LOWER_EXPLOSS, SkillInfo.LevelUpType.alwaysShown, null)); - initializeSkill(new SkillInfo(SkillID.magicfinder, SkillInfo.MAXLEVEL_NONE, SkillInfo.LevelUpType.alwaysShown, null)); - initializeSkill(new SkillInfo(SkillID.resistanceMental, MAX_LEVEL_RESISTANCE, SkillInfo.LevelUpType.alwaysShown, null)); - initializeSkill(new SkillInfo(SkillID.resistancePhysical, MAX_LEVEL_RESISTANCE, SkillInfo.LevelUpType.alwaysShown, null)); - initializeSkill(new SkillInfo(SkillID.resistanceBlood, MAX_LEVEL_RESISTANCE, SkillInfo.LevelUpType.alwaysShown, null)); - initializeSkill(new SkillInfo(SkillID.shadowBless, 1, SkillInfo.LevelUpType.onlyByQuests, null)); - initializeSkill(new SkillInfo(SkillID.crit1, 1, SkillInfo.LevelUpType.alwaysShown, new SkillLevelRequirement[] { + initializeSkill(new SkillInfo(SkillID.lowerExploss, MAX_LEVEL_LOWER_EXPLOSS, SkillInfo.LevelUpType.alwaysShown, SkillCategory.utility, null)); + initializeSkill(new SkillInfo(SkillID.magicfinder, SkillInfo.MAXLEVEL_NONE, SkillInfo.LevelUpType.alwaysShown, SkillCategory.utility, null)); + initializeSkill(new SkillInfo(SkillID.resistanceMental, MAX_LEVEL_RESISTANCE, SkillInfo.LevelUpType.alwaysShown, SkillCategory.immunity, null)); + initializeSkill(new SkillInfo(SkillID.resistancePhysical, MAX_LEVEL_RESISTANCE, SkillInfo.LevelUpType.alwaysShown, SkillCategory.immunity, null)); + initializeSkill(new SkillInfo(SkillID.resistanceBlood, MAX_LEVEL_RESISTANCE, SkillInfo.LevelUpType.alwaysShown, SkillCategory.immunity, null)); + initializeSkill(new SkillInfo(SkillID.shadowBless, 1, SkillInfo.LevelUpType.onlyByQuests, SkillCategory.immunity, null)); + initializeSkill(new SkillInfo(SkillID.crit1, 1, SkillInfo.LevelUpType.alwaysShown, SkillCategory.criticals, new SkillLevelRequirement[] { SkillLevelRequirement.requireOtherSkill(SkillID.moreCriticals, 3) ,SkillLevelRequirement.requireOtherSkill(SkillID.betterCriticals, 3) })); - initializeSkill(new SkillInfo(SkillID.crit2, 1, SkillInfo.LevelUpType.alwaysShown, new SkillLevelRequirement[] { + initializeSkill(new SkillInfo(SkillID.crit2, 1, SkillInfo.LevelUpType.alwaysShown, SkillCategory.criticals, new SkillLevelRequirement[] { SkillLevelRequirement.requireOtherSkill(SkillID.moreCriticals, 6) ,SkillLevelRequirement.requireOtherSkill(SkillID.betterCriticals, 6) ,SkillLevelRequirement.requireOtherSkill(SkillID.crit1, 1) })); - initializeSkill(new SkillInfo(SkillID.rejuvenation, 1, SkillInfo.LevelUpType.alwaysShown, new SkillLevelRequirement[] { + initializeSkill(new SkillInfo(SkillID.rejuvenation, 1, SkillInfo.LevelUpType.alwaysShown, SkillCategory.immunity, new SkillLevelRequirement[] { SkillLevelRequirement.requireOtherSkill(SkillID.resistanceBlood, 3) ,SkillLevelRequirement.requireOtherSkill(SkillID.resistanceMental, 3) ,SkillLevelRequirement.requireOtherSkill(SkillID.resistancePhysical, 3) })); - initializeSkill(new SkillInfo(SkillID.taunt, 1, SkillInfo.LevelUpType.alwaysShown, new SkillLevelRequirement[] { + initializeSkill(new SkillInfo(SkillID.taunt, 1, SkillInfo.LevelUpType.alwaysShown, SkillCategory.defense, new SkillLevelRequirement[] { SkillLevelRequirement.requireOtherSkill(SkillID.evasion, 2) ,SkillLevelRequirement.requireOtherSkill(SkillID.dodge, 4) })); - initializeSkill(new SkillInfo(SkillID.concussion, 1, SkillInfo.LevelUpType.alwaysShown, new SkillLevelRequirement[] { + initializeSkill(new SkillInfo(SkillID.concussion, 1, SkillInfo.LevelUpType.alwaysShown, SkillCategory.offense, new SkillLevelRequirement[] { SkillLevelRequirement.requireOtherSkill(SkillID.speed, 2) ,SkillLevelRequirement.requireOtherSkill(SkillID.weaponChance, 3) ,SkillLevelRequirement.requireOtherSkill(SkillID.weaponDmg, 5) })); - initializeSkill(new SkillInfo(SkillID.weaponProficiencyDagger, 3, SkillInfo.LevelUpType.firstLevelRequiresQuest, null)); - initializeSkill(new SkillInfo(SkillID.weaponProficiency1hsword, 3, SkillInfo.LevelUpType.firstLevelRequiresQuest, null)); - initializeSkill(new SkillInfo(SkillID.weaponProficiency2hsword, 3, SkillInfo.LevelUpType.firstLevelRequiresQuest, null)); - initializeSkill(new SkillInfo(SkillID.weaponProficiencyAxe, 3, SkillInfo.LevelUpType.firstLevelRequiresQuest, null)); - initializeSkill(new SkillInfo(SkillID.weaponProficiencyBlunt, 3, SkillInfo.LevelUpType.firstLevelRequiresQuest, null)); - initializeSkill(new SkillInfo(SkillID.weaponProficiencyUnarmed, 3, SkillInfo.LevelUpType.firstLevelRequiresQuest, null)); - initializeSkill(new SkillInfo(SkillID.armorProficiencyShield, 2, SkillInfo.LevelUpType.firstLevelRequiresQuest, null)); - initializeSkill(new SkillInfo(SkillID.armorProficiencyUnarmored, 3, SkillInfo.LevelUpType.firstLevelRequiresQuest, null)); - initializeSkill(new SkillInfo(SkillID.armorProficiencyLight, 3, SkillInfo.LevelUpType.firstLevelRequiresQuest, null)); - initializeSkill(new SkillInfo(SkillID.armorProficiencyHeavy, 4, SkillInfo.LevelUpType.firstLevelRequiresQuest, null)); - initializeSkill(new SkillInfo(SkillID.fightstyleDualWield, 2, SkillInfo.LevelUpType.alwaysShown, new SkillLevelRequirement[] { + initializeSkill(new SkillInfo(SkillID.weaponProficiencyDagger, 3, SkillInfo.LevelUpType.firstLevelRequiresQuest, SkillCategory.proficiency, null)); + initializeSkill(new SkillInfo(SkillID.weaponProficiency1hsword, 3, SkillInfo.LevelUpType.firstLevelRequiresQuest, SkillCategory.proficiency, null)); + initializeSkill(new SkillInfo(SkillID.weaponProficiency2hsword, 3, SkillInfo.LevelUpType.firstLevelRequiresQuest, SkillCategory.proficiency, null)); + initializeSkill(new SkillInfo(SkillID.weaponProficiencyAxe, 3, SkillInfo.LevelUpType.firstLevelRequiresQuest, SkillCategory.proficiency, null)); + initializeSkill(new SkillInfo(SkillID.weaponProficiencyBlunt, 3, SkillInfo.LevelUpType.firstLevelRequiresQuest, SkillCategory.proficiency, null)); + initializeSkill(new SkillInfo(SkillID.weaponProficiencyUnarmed, 3, SkillInfo.LevelUpType.firstLevelRequiresQuest, SkillCategory.proficiency, null)); + initializeSkill(new SkillInfo(SkillID.armorProficiencyShield, 2, SkillInfo.LevelUpType.firstLevelRequiresQuest, SkillCategory.proficiency, null)); + initializeSkill(new SkillInfo(SkillID.armorProficiencyUnarmored, 3, SkillInfo.LevelUpType.firstLevelRequiresQuest, SkillCategory.proficiency, null)); + initializeSkill(new SkillInfo(SkillID.armorProficiencyLight, 3, SkillInfo.LevelUpType.firstLevelRequiresQuest, SkillCategory.proficiency, null)); + initializeSkill(new SkillInfo(SkillID.armorProficiencyHeavy, 4, SkillInfo.LevelUpType.firstLevelRequiresQuest, SkillCategory.proficiency, null)); + initializeSkill(new SkillInfo(SkillID.fightstyleDualWield, 2, SkillInfo.LevelUpType.alwaysShown, SkillCategory.specialty, new SkillLevelRequirement[] { SkillLevelRequirement.requireExperienceLevels(15, 0) })); - initializeSkill(new SkillInfo(SkillID.fightstyle2hand, 2, SkillInfo.LevelUpType.alwaysShown, new SkillLevelRequirement[] { + initializeSkill(new SkillInfo(SkillID.fightstyle2hand, 2, SkillInfo.LevelUpType.alwaysShown, SkillCategory.specialty, new SkillLevelRequirement[] { SkillLevelRequirement.requireExperienceLevels(15, 0) })); - initializeSkill(new SkillInfo(SkillID.fightstyleWeaponShield, 2, SkillInfo.LevelUpType.alwaysShown, new SkillLevelRequirement[] { + initializeSkill(new SkillInfo(SkillID.fightstyleWeaponShield, 2, SkillInfo.LevelUpType.alwaysShown, SkillCategory.specialty, new SkillLevelRequirement[] { SkillLevelRequirement.requireExperienceLevels(15, 0) })); - initializeSkill(new SkillInfo(SkillID.specializationDualWield, 1, SkillInfo.LevelUpType.alwaysShown, new SkillLevelRequirement[] { + initializeSkill(new SkillInfo(SkillID.specializationDualWield, 1, SkillInfo.LevelUpType.alwaysShown, SkillCategory.specialty, new SkillLevelRequirement[] { SkillLevelRequirement.requireExperienceLevels(45, 0) ,SkillLevelRequirement.requireOtherSkill(SkillID.fightstyleDualWield, 2) })); - initializeSkill(new SkillInfo(SkillID.specialization2hand, 1, SkillInfo.LevelUpType.alwaysShown, new SkillLevelRequirement[] { + initializeSkill(new SkillInfo(SkillID.specialization2hand, 1, SkillInfo.LevelUpType.alwaysShown, SkillCategory.specialty, new SkillLevelRequirement[] { SkillLevelRequirement.requireExperienceLevels(45, 0) ,SkillLevelRequirement.requireOtherSkill(SkillID.fightstyle2hand, 2) })); - initializeSkill(new SkillInfo(SkillID.specializationWeaponShield, 1, SkillInfo.LevelUpType.alwaysShown, new SkillLevelRequirement[] { + initializeSkill(new SkillInfo(SkillID.specializationWeaponShield, 1, SkillInfo.LevelUpType.alwaysShown, SkillCategory.specialty, new SkillLevelRequirement[] { SkillLevelRequirement.requireExperienceLevels(45, 0) ,SkillLevelRequirement.requireOtherSkill(SkillID.fightstyleWeaponShield, 2) })); diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/ability/SkillInfo.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/ability/SkillInfo.java index 2df7e0cfd..430e1b859 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/ability/SkillInfo.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/ability/SkillInfo.java @@ -14,16 +14,19 @@ public final class SkillInfo { public final int maxLevel; public final LevelUpType levelupVisibility; public final SkillLevelRequirement[] levelupRequirements; + public final SkillCollection.SkillCategory categoryType; public SkillInfo( SkillCollection.SkillID id , int maxLevel , LevelUpType levelupVisibility + , SkillCollection.SkillCategory categoryType , SkillLevelRequirement[] levelupRequirements ) { this.id = id; this.maxLevel = maxLevel; this.levelupVisibility = levelupVisibility; this.levelupRequirements = levelupRequirements; + this.categoryType = categoryType; } public boolean hasMaxLevel() { diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/item/Inventory.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/item/Inventory.java index a901d750d..a5c29cd5d 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/item/Inventory.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/item/Inventory.java @@ -1,11 +1,18 @@ package com.gpl.rpg.AndorsTrail.model.item; import com.gpl.rpg.AndorsTrail.context.WorldContext; +import com.gpl.rpg.AndorsTrail.model.actor.Player; import com.gpl.rpg.AndorsTrail.savegames.LegacySavegameFormatReaderForItemContainer; +import com.gpl.rpg.AndorsTrail.savegames.Savegames; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.Map; public final class Inventory extends ItemContainer { @@ -87,6 +94,58 @@ public final class Inventory extends ItemContainer { } + // Move to item container? + public Inventory buildQuestItems() { + Inventory questItems = new Inventory(); + for (ItemEntry i : this.items) { + if (i == null) break; + if (i.itemType.isQuestItem()) + questItems.items.add(i); + } + return questItems; + } + // Move to item container? + public Inventory buildUsableItems() { + Inventory usableItems = new Inventory(); + for (ItemEntry i : this.items) { + if (i == null) break; + if (i.itemType.isUsable()) + usableItems.items.add(i); + } + return usableItems; + } + // Move to item container? + public Inventory buildWeaponItems() { + Inventory weaponItems = new Inventory(); + for (ItemEntry i : this.items) { + if (i == null) break; + if (i.itemType.isWeapon()) + weaponItems.items.add(i); + } + return weaponItems; + } + // Move to item container? + public Inventory buildArmorItems() { + Inventory armorItems = new Inventory(); + for (ItemEntry i : this.items) { + if (i == null) break; + if (i.itemType.isEquippable() && !i.itemType.isWeapon()) + armorItems.items.add(i); + } + return armorItems; + } + // Move to item container? + public Inventory buildOtherItems() { + Inventory otherItems = new Inventory(); + for (ItemEntry i : this.items) { + if (i == null) break; + if (i.itemType.isEquippable() || i.itemType.isUsable() || i.itemType.isQuestItem()) + continue; + otherItems.items.add(i); + } + return otherItems; + } + // ====== PARCELABLE =================================================================== public Inventory(DataInputStream src, WorldContext world, int fileversion) throws IOException { diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/item/ItemContainer.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/item/ItemContainer.java index 23c7a7955..9c203076f 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/item/ItemContainer.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/item/ItemContainer.java @@ -1,11 +1,14 @@ package com.gpl.rpg.AndorsTrail.model.item; import com.gpl.rpg.AndorsTrail.context.WorldContext; +import com.gpl.rpg.AndorsTrail.model.actor.Player; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; public class ItemContainer { public final ArrayList items = new ArrayList(); @@ -127,6 +130,117 @@ public class ItemContainer { } + public void sortByName(Player p) { + final Player q = p; + Comparator comparatorName = new Comparator() { + @Override + public int compare(ItemEntry item1, ItemEntry item2) { + return item1.itemType.getName(q).compareTo(item2.itemType.getName(q)); + } + }; + Collections.sort(this.items, comparatorName); + + } + + + public void sortByPrice(Player p) { + final Player q = p; + Comparator comparatorPrice = new Comparator() { + @Override + public int compare(ItemEntry item1, ItemEntry item2) { + // More expensive items go to top + if (item1.itemType.baseMarketCost < item2.itemType.baseMarketCost) { + return 1; + } else if (item1.itemType.baseMarketCost > item2.itemType.baseMarketCost) { + return -1; + } else { // compares the names if rarity is the same + return item1.itemType.getName(q).compareTo(item2.itemType.getName(q)); + } + } + }; + Collections.sort(this.items, comparatorPrice); + + } + + public void sortByQuantity(Player p) { + final Player q = p; + Comparator comparatorQuantity = new Comparator() { + @Override + public int compare(ItemEntry item1, ItemEntry item2) { + // Bigger quantity is put first + if (item1.quantity > item2.quantity) { + return -1; + } else if (item1.quantity < item2.quantity) { + return 1; + } else { // compares the names if quantity is the same + return item1.itemType.getName(q).compareTo(item2.itemType.getName(q)); + } + } + }; + Collections.sort(this.items, comparatorQuantity); + + } + + + public void sortByRarity(Player p) { + final Player q = p; + Comparator comparatorRarity = new Comparator() { + @Override + public int compare(ItemEntry item1, ItemEntry item2) { + // More rare items go to top + if (item1.itemType.displayType.compareTo(item2.itemType.displayType) != 0 ) { + return (-1) * item1.itemType.displayType.compareTo(item2.itemType.displayType); + // ^ More rare goes on top + } else { // compares the names if rarity is the same + return item1.itemType.getName(q).compareTo(item2.itemType.getName(q)); + } + } + }; + Collections.sort(this.items, comparatorRarity); + + } + + + public void sortByType(Player p) { + final Player q = p; + Comparator comparatorType = new Comparator() { + @Override + public int compare(ItemEntry item1, ItemEntry item2) { + if (determineType(item1) > determineType(item2)) { + return 1; + } else if (determineType(item1) < determineType(item2)) { + return -666; + } else { // compares the names if type is the same + return item1.itemType.getName(q).compareTo(item2.itemType.getName(q)); + } + } + }; + Collections.sort(this.items, comparatorType); + + } + + public int determineType(ItemEntry item) { + if (item.itemType.isWeapon()) { + if(item.itemType.isTwohandWeapon()) + return 1; + if(false)//item.itemType.isRangedWeapon()) + return 2; + return 3; + } // Weapons + else if (item.itemType.isShield()) { return 4; } // Shields + else if (item.itemType.isArmor()) { return 5; } // Armor, gloves, hats, boots + else if (item.itemType.isEquippable()) { return 6; } // Jewelry + else if (item.itemType.isUsable()) { return 7; } // Items with use, for example food + else if (item.itemType.isQuestItem()) { return 8; } // Quest items + else { return 9; } // others + } + + public void sortByReverse() { + Collections.reverse(this.items); + } + + + // ====== PARCELABLE =================================================================== public static ItemContainer newFromParcel(DataInputStream src, WorldContext world, int fileversion) throws IOException { diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/view/ItemContainerAdapter.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/view/ItemContainerAdapter.java index 750717237..e6dd5d639 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/view/ItemContainerAdapter.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/view/ItemContainerAdapter.java @@ -47,4 +47,49 @@ public class ItemContainerAdapter extends ArrayAdapter { public long getItemId(int position) { return getItem(position).itemType.id.hashCode(); } + + /*public void reloadShownCategory(int category){ // Overwrites player.inventory instead of cloning it + this.clear(); + ArrayList< + for(ItemEntry i: (ItemEntry) this.player.inventory.items.clone()){ + if(category == 0) + this.add(i); + else if(i.itemType.isWeapon()) + if(category ==1) + this.add(i); + else if(i.itemType.isEquippable() && ! i.itemType.isWeapon()) + if(category==2) + this.add(i); + else if(i.itemType.isUsable()) + if(category ==3) + this.add(i); + else if(i.itemType.isQuestItem()) + if(category ==4) + this.add(i); + else if(category == 5) //other items + this.add(i); + } + }*/ + + public static void reloadShownSort(int selected, int oldSortSelection, ItemContainer container, Player p) { + //Not sure which is worse, hardcoding the names or the position. + + if(selected == oldSortSelection); + //inv.sortByReverse(); + else if (selected ==1) + container.sortByName(p); + else if (selected == 2) + container.sortByPrice(p); + else if (selected == 3) + container.sortByQuantity(p); + else if (selected == 4) + container.sortByRarity(p); + else if (selected == 5) + container.sortByType(p); + else if (selected == 0); //Unsorted + } + + public static void reloadShownSort(int selected, ItemContainer container, Player p){ + reloadShownSort(selected, -1, container, p); + } } diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/view/ShopItemContainerAdapter.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/view/ShopItemContainerAdapter.java index a99212911..0d2c7f36a 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/view/ShopItemContainerAdapter.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/view/ShopItemContainerAdapter.java @@ -82,4 +82,8 @@ public final class ShopItemContainerAdapter extends ArrayAdapter { void onItemActionClicked(int position, ItemType itemType); void onItemInfoClicked(int position, ItemType itemType); } + + public void reloadShownSort(int selection, ItemContainer container, Player p){ + ItemContainerAdapter.reloadShownSort(selection, container, player); + } } diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/view/SkillListAdapter.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/view/SkillListAdapter.java index 7c30bf2a8..0412f7ca3 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/view/SkillListAdapter.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/view/SkillListAdapter.java @@ -26,6 +26,12 @@ public final class SkillListAdapter extends ArrayAdapter { this.player = player; } + public SkillListAdapter(Context context, Collection skills, Player player, int category) { + super(context, 0, filterNondisplayedSkills(skills, player, category-1)); + this.r = context.getResources(); + this.player = player; + } + private static List filterNondisplayedSkills(Collection skills, Player player) { final ArrayList result = new ArrayList(); for (SkillInfo skill : skills) { @@ -39,7 +45,24 @@ public final class SkillListAdapter extends ArrayAdapter { }); return result; } - + private static List filterNondisplayedSkills(Collection skills, Player player, int category) { + final ArrayList result = new ArrayList(); + for (SkillInfo skill : skills) { + if (shouldDisplaySkill(skill, player)){ + if(category <0) + result.add(skill); + else if(skill.categoryType.equals(SkillCollection.SkillCategory.values()[category+1])) + result.add(skill); + } + } + Collections.sort(result, new Comparator() { + @Override + public int compare(SkillInfo a, SkillInfo b) { + return a.id.ordinal() - b.id.ordinal(); + } + }); + return result; + } private static boolean shouldDisplaySkill(SkillInfo skill, Player player) { if (player.hasSkill(skill.id)) return true; if (skill.levelupVisibility == SkillInfo.LevelUpType.alwaysShown) return true; @@ -134,4 +157,55 @@ public final class SkillListAdapter extends ArrayAdapter { return -1; } } + + public void sortByName(){ + Comparator comparatorName = new Comparator() { + @Override + public int compare(SkillInfo item1, SkillInfo item2) { + return r.getString( SkillInfoActivity.getSkillTitleResourceID(item1.id)).compareTo( + r.getString( SkillInfoActivity.getSkillTitleResourceID(item2.id))); + } + }; + this.sort(comparatorName); + } + + public void sortByPoints(){ + Comparator comparatorPoints = new Comparator() { + @Override + public int compare(SkillInfo item1, SkillInfo item2) { + if(player.getSkillLevel(item1.id) > player.getSkillLevel(item2.id)) + return -1; + else if(player.getSkillLevel(item1.id) < player.getSkillLevel(item2.id)) + return 1; + else + return r.getString( SkillInfoActivity.getSkillTitleResourceID(item1.id)).compareTo( + r.getString( SkillInfoActivity.getSkillTitleResourceID(item2.id))); + } + }; + this.sort(comparatorPoints); + } + + public void sortByUnlocked(){ + Comparator comparatorUnlocked = new Comparator() { + @Override + public int compare(SkillInfo item1, SkillInfo item2) { + // First compare by whether requirements are met + if(item1.canLevelUpSkillTo(player, player.getSkillLevel(item1.id) + 1) + && !(item2.canLevelUpSkillTo(player, player.getSkillLevel(item2.id) +1))) + return -1; + else if(!(item1.canLevelUpSkillTo(player, player.getSkillLevel(item1.id) +1)) + && item2.canLevelUpSkillTo(player, player.getSkillLevel(item2.id) +1)) + return 1; + else { // Then compare by number of requirements (complexity) + if(item1.levelupRequirements.length< item2.levelupRequirements.length) + return -1; + else if(item1.levelupRequirements.length > item2.levelupRequirements.length) + return 1; + return r.getString(SkillInfoActivity.getSkillTitleResourceID(item1.id)).compareTo( + r.getString(SkillInfoActivity.getSkillTitleResourceID(item2.id))); + } + } + }; + this.sort(comparatorUnlocked); + } }