Skip to content

Commit

Permalink
Updated ammo to be edit text view, and added it to row.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsiemens committed Jan 27, 2014
1 parent af4ccb7 commit 75743ac
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 28 deletions.
8 changes: 5 additions & 3 deletions pathfinder-toolkit/res/layout/character_weapon_editor.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@
android:gravity="left|center_vertical"
android:text="@string/weapon_ammunition_header" />

<Spinner
android:id="@+id/spWeaponAmmo"
<EditText
android:id="@+id/etWeaponAmmo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="100dp" />
android:minWidth="100dp"
android:inputType="numberDecimal"
android:hint="@null" />
</LinearLayout>

<LinearLayout
Expand Down
12 changes: 12 additions & 0 deletions pathfinder-toolkit/res/layout/character_weapon_row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@
android:layout_height="fill_parent"
android:layout_weight="0.4"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="@string/weapon_ammunition_header"
android:textStyle="bold" />

<TextView
android:id="@+id/weaponAmmo"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="0.4"/>

</LinearLayout>

<LinearLayout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,25 @@
import com.lateensoft.pathfinder.toolkit.model.character.items.PTWeapon;

public class PTWeaponAdapter extends ArrayAdapter<PTWeapon> {
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) {
View row = convertView;
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);
Expand All @@ -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;
}
Expand All @@ -75,5 +75,6 @@ static class WeaponHolder {
TextView type;
TextView size;
TextView critical;
TextView ammo;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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));
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 75743ac

Please sign in to comment.