From 75743ac8f2ba613524f0c332ce49a8bd4354e2b2 Mon Sep 17 00:00:00 2001 From: Trevor Siemens Date: Mon, 27 Jan 2014 08:22:08 -0800 Subject: [PATCH] Updated ammo to be edit text view, and added it to row. --- .../res/layout/character_weapon_editor.xml | 8 ++-- .../res/layout/character_weapon_row.xml | 12 ++++++ .../adapters/character/PTWeaponAdapter.java | 39 ++++++++++--------- .../PTCharacterWeaponEditActivity.java | 16 +++++--- 4 files changed, 47 insertions(+), 28 deletions(-) diff --git a/pathfinder-toolkit/res/layout/character_weapon_editor.xml b/pathfinder-toolkit/res/layout/character_weapon_editor.xml index fdd0399..a7f99da 100644 --- a/pathfinder-toolkit/res/layout/character_weapon_editor.xml +++ b/pathfinder-toolkit/res/layout/character_weapon_editor.xml @@ -53,11 +53,13 @@ android:gravity="left|center_vertical" android:text="@string/weapon_ammunition_header" /> - + android:minWidth="100dp" + android:inputType="numberDecimal" + android:hint="@null" /> + + + + { - Context mContext; - int mLayoutResourceId; - PTWeapon[] mWeapons = null; - static final String TAG = "PTWeaponAdapter"; + Context m_context; + int m_layoutResourceId; + PTWeapon[] m_weapons = null; public PTWeaponAdapter(Context context, int layoutResourceId, PTWeapon[] weapons) { super(context, layoutResourceId, weapons); - mLayoutResourceId = layoutResourceId; - mContext = context; - mWeapons = weapons; + m_layoutResourceId = layoutResourceId; + m_context = context; + m_weapons = weapons; } public View getView(int position, View convertView, ViewGroup parent) { @@ -29,9 +28,9 @@ public View getView(int position, View convertView, ViewGroup parent) { WeaponHolder holder; if(row == null) { - LayoutInflater inflater = ((Activity)mContext).getLayoutInflater(); + LayoutInflater inflater = ((Activity)m_context).getLayoutInflater(); - row = inflater.inflate(mLayoutResourceId, parent, false); + row = inflater.inflate(m_layoutResourceId, parent, false); holder = new WeaponHolder(); holder.name = (TextView)row.findViewById(R.id.weaponName); @@ -44,22 +43,23 @@ public View getView(int position, View convertView, ViewGroup parent) { holder.type = (TextView)row.findViewById(R.id.weaponType); holder.size = (TextView)row.findViewById(R.id.weaponSize); holder.critical = (TextView)row.findViewById(R.id.weaponCrit); + holder.ammo = (TextView)row.findViewById(R.id.weaponAmmo); row.setTag(holder); } else { holder = (WeaponHolder)row.getTag(); } - holder.name.setText(mWeapons[position].getName()); - holder.weight.setText(Double.toString(mWeapons[position].getWeight())); - holder.totalAttackBonus.setText(Integer.toString(mWeapons[position].getTotalAttackBonus())); - holder.damage.setText(mWeapons[position].getDamage()); - holder.range.setText(Integer.toString(mWeapons[position].getRange())); - holder.specialProperties.setText(mWeapons[position].getSpecialProperties()); - holder.type.setText(mWeapons[position].getType()); - holder.size.setText(mWeapons[position].getSize()); - holder.critical.setText(mWeapons[position].getCritical()); - //holder.name.setText(mWeapons[position].getName()); + holder.name.setText(m_weapons[position].getName()); + holder.weight.setText(Double.toString(m_weapons[position].getWeight())); + holder.totalAttackBonus.setText(Integer.toString(m_weapons[position].getTotalAttackBonus())); + holder.damage.setText(m_weapons[position].getDamage()); + holder.range.setText(Integer.toString(m_weapons[position].getRange())); + holder.specialProperties.setText(m_weapons[position].getSpecialProperties()); + holder.type.setText(m_weapons[position].getType()); + holder.size.setText(m_weapons[position].getSize()); + holder.critical.setText(m_weapons[position].getCritical()); + holder.ammo.setText(Integer.toString(m_weapons[position].getAmmunition())); return row; } @@ -75,5 +75,6 @@ static class WeaponHolder { TextView type; TextView size; TextView critical; + TextView ammo; } } diff --git a/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/views/character/PTCharacterWeaponEditActivity.java b/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/views/character/PTCharacterWeaponEditActivity.java index 127e987..d7c7aa8 100644 --- a/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/views/character/PTCharacterWeaponEditActivity.java +++ b/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/views/character/PTCharacterWeaponEditActivity.java @@ -17,7 +17,7 @@ public class PTCharacterWeaponEditActivity extends PTParcelableEditorActivity { private static final int ATK_BONUS_OFFSET = 10; private Spinner m_highestAtkSpinner; - private Spinner m_ammoSpinner; + private EditText m_ammoET; private Spinner m_sizeSpinner; private Spinner m_typeSpinner; private Spinner m_rangeSpinner; @@ -37,7 +37,7 @@ protected void setupContentView() { m_nameET = (EditText) findViewById(R.id.etWeaponName); m_highestAtkSpinner = (Spinner) findViewById(R.id.spWeaponHighestAtk); - m_ammoSpinner = (Spinner) findViewById(R.id.spWeaponAmmo); + m_ammoET = (EditText) findViewById(R.id.etWeaponAmmo); m_typeSpinner = (Spinner) findViewById(R.id.spWeaponType); m_sizeSpinner = (Spinner) findViewById(R.id.spWeaponSize); m_rangeSpinner = (Spinner) findViewById(R.id.spWeaponRange); @@ -46,10 +46,9 @@ protected void setupContentView() { m_weightET = (EditText) findViewById(R.id.etWeaponWeight); m_specialPropertiesET = (EditText) findViewById( R.id.etWeaponSpecialProperties); - + setupSpinner(m_highestAtkSpinner, R.array.weapon_attack_bonus_options, ATK_BONUS_OFFSET, m_spinnerOnTouchListener); - setupSpinner(m_ammoSpinner, R.array.selectable_whole_values_strings, 0, m_spinnerOnTouchListener); setupSpinner(m_sizeSpinner, R.array.size_spinner_options, 0, m_spinnerOnTouchListener); setupSpinner(m_typeSpinner, R.array.weapon_type_options, 0, m_spinnerOnTouchListener); setupSpinner(m_rangeSpinner, R.array.weapon_range_options, 0, m_spinnerOnTouchListener); @@ -60,10 +59,10 @@ protected void setupContentView() { } else { setTitle(R.string.edit_weapon_title); m_nameET.setText(m_weapon.getName()); + m_ammoET.setText(Integer.toString(m_weapon.getAmmunition())); m_highestAtkSpinner.setSelection(m_weapon.getTotalAttackBonus() + ATK_BONUS_OFFSET); m_damageET.setText(m_weapon.getDamage()); m_criticalET.setText(m_weapon.getCritical()); - m_ammoSpinner.setSelection(m_weapon.getAmmunition()); m_sizeSpinner.setSelection(m_weapon.getSizeInt()); m_rangeSpinner.setSelection(m_weapon.getRange()/5); m_typeSpinner.setSelection(m_weapon.getTypeInt(this)); @@ -95,7 +94,12 @@ protected void updateEditedParcelableValues() throws InvalidValueException { } int range = m_rangeSpinner.getSelectedItemPosition()*5; - int ammo = m_ammoSpinner.getSelectedItemPosition(); + int ammo = m_weapon.getAmmunition(); + try { + ammo = Integer.parseInt(m_ammoET.getText().toString()); + } catch (NumberFormatException e) { + // Do not change ammo + } String damage = new String(m_damageET.getText().toString()); String critical = new String(m_criticalET.getText().toString()); String specialProperties = new String(m_specialPropertiesET.getText().toString());