Adds Edit Speed screen to the monster editor.
This commit is contained in:
@@ -80,12 +80,14 @@ public class EditMonsterFragment extends MCFragment {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
mHolder.basicInfoButton.setOnClickListener(v -> {
|
||||
NavDirections action = EditMonsterFragmentDirections.actionEditMonsterFragmentToEditBasicInfoFragment();
|
||||
View view = getView();
|
||||
assert view != null;
|
||||
Navigation.findNavController(view).navigate(action);
|
||||
});
|
||||
|
||||
mHolder.armorButton.setOnClickListener(v -> {
|
||||
NavDirections action = EditMonsterFragmentDirections.actionEditMonsterFragmentToEditArmorFragment();
|
||||
View view = getView();
|
||||
@@ -93,6 +95,13 @@ public class EditMonsterFragment extends MCFragment {
|
||||
Navigation.findNavController(view).navigate(action);
|
||||
});
|
||||
|
||||
mHolder.speedButton.setOnClickListener(v -> {
|
||||
NavDirections action = EditMonsterFragmentDirections.actionEditMonsterFragmentToEditSpeedFragment();
|
||||
View view = getView();
|
||||
assert view != null;
|
||||
Navigation.findNavController(view).navigate(action);
|
||||
});
|
||||
|
||||
requireActivity().getOnBackPressedDispatcher().addCallback(getViewLifecycleOwner(), new OnBackPressedCallback(true) {
|
||||
@Override
|
||||
public void handleOnBackPressed() {
|
||||
@@ -144,10 +153,12 @@ public class EditMonsterFragment extends MCFragment {
|
||||
|
||||
TextView basicInfoButton;
|
||||
TextView armorButton;
|
||||
TextView speedButton;
|
||||
|
||||
ViewHolder(View root) {
|
||||
basicInfoButton = root.findViewById(R.id.basicInfo);
|
||||
armorButton = root.findViewById(R.id.armor);
|
||||
speedButton = root.findViewById(R.id.speed);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,10 +21,17 @@ public class EditMonsterViewModel extends ViewModel {
|
||||
private final MutableLiveData<Boolean> mHasChanges;
|
||||
private final MutableLiveData<Boolean> mHasCustomHitPoints;
|
||||
private final MutableLiveData<Boolean> mHasShield;
|
||||
private final MutableLiveData<Boolean> mCanHover;
|
||||
private final MutableLiveData<Boolean> mHasCustomSpeed;
|
||||
private final MutableLiveData<ArmorType> mArmorType;
|
||||
private final MutableLiveData<Integer> mHitDice;
|
||||
private final MutableLiveData<Integer> mNaturalArmorBonus;
|
||||
private final MutableLiveData<Integer> mShieldBonus;
|
||||
private final MutableLiveData<Integer> mWalkSpeed;
|
||||
private final MutableLiveData<Integer> mBurrowSpeed;
|
||||
private final MutableLiveData<Integer> mClimbSpeed;
|
||||
private final MutableLiveData<Integer> mFlySpeed;
|
||||
private final MutableLiveData<Integer> mSwimSpeed;
|
||||
private final MutableLiveData<String> mName;
|
||||
private final MutableLiveData<String> mErrorMessage;
|
||||
private final MutableLiveData<String> mSize;
|
||||
@@ -33,6 +40,7 @@ public class EditMonsterViewModel extends ViewModel {
|
||||
private final MutableLiveData<String> mAlignment;
|
||||
private final MutableLiveData<String> mCustomHitPoints;
|
||||
private final MutableLiveData<String> mCustomArmor;
|
||||
private final MutableLiveData<String> mCustomSpeed;
|
||||
|
||||
public EditMonsterViewModel() {
|
||||
|
||||
@@ -53,6 +61,14 @@ public class EditMonsterViewModel extends ViewModel {
|
||||
mHasShield = new MutableLiveData<>(false);
|
||||
mShieldBonus = new MutableLiveData<>(0);
|
||||
mCustomArmor = new MutableLiveData<>("");
|
||||
mWalkSpeed = new MutableLiveData<>(0);
|
||||
mBurrowSpeed = new MutableLiveData<>(0);
|
||||
mClimbSpeed = new MutableLiveData<>(0);
|
||||
mFlySpeed = new MutableLiveData<>(0);
|
||||
mSwimSpeed = new MutableLiveData<>(0);
|
||||
mCanHover = new MutableLiveData<>(false);
|
||||
mHasCustomSpeed = new MutableLiveData<>(false);
|
||||
mCustomSpeed = new MutableLiveData<>("");
|
||||
// TODO: consider initializing this to true so all new monsters need saving
|
||||
mHasChanges = new MutableLiveData<>(false);
|
||||
}
|
||||
@@ -73,6 +89,15 @@ public class EditMonsterViewModel extends ViewModel {
|
||||
mHasShield.setValue(monster.shieldBonus != 0);
|
||||
mShieldBonus.setValue(monster.shieldBonus);
|
||||
mCustomArmor.setValue(monster.otherArmorDescription);
|
||||
mWalkSpeed.setValue(monster.walkSpeed);
|
||||
mBurrowSpeed.setValue(monster.burrowSpeed);
|
||||
mClimbSpeed.setValue(monster.climbSpeed);
|
||||
mFlySpeed.setValue(monster.flySpeed);
|
||||
mSwimSpeed.setValue(monster.swimSpeed);
|
||||
mCanHover.setValue(monster.canHover);
|
||||
mHasCustomSpeed.setValue(monster.hasCustomSpeed);
|
||||
mCustomSpeed.setValue(monster.customSpeedDescription);
|
||||
|
||||
mHasChanges.setValue(false);
|
||||
}
|
||||
|
||||
@@ -297,6 +322,136 @@ public class EditMonsterViewModel extends ViewModel {
|
||||
return mShieldBonus.getValue().toString();
|
||||
}
|
||||
|
||||
public LiveData<Integer> getWalkSpeed() {
|
||||
return mWalkSpeed;
|
||||
}
|
||||
|
||||
public void setWalkSpeed(int walkSpeed) {
|
||||
if (!Objects.equals(mWalkSpeed.getValue(), walkSpeed)) {
|
||||
mWalkSpeed.setValue(walkSpeed);
|
||||
mHasChanges.setValue(true);
|
||||
Logger.logDebug(String.format("Setting walk speed to %d ft.", walkSpeed));
|
||||
}
|
||||
}
|
||||
|
||||
public void incrementWalkSpeed() {
|
||||
setWalkSpeed(mWalkSpeed.getValue() + 5);
|
||||
}
|
||||
|
||||
public void decrementWalkSpeed() {
|
||||
setWalkSpeed(mWalkSpeed.getValue() - 5);
|
||||
}
|
||||
|
||||
public LiveData<Integer> getBurrowSpeed() {
|
||||
return mBurrowSpeed;
|
||||
}
|
||||
|
||||
public void setBurrowSpeed(int burrowSpeed) {
|
||||
if (!Objects.equals(mBurrowSpeed.getValue(), burrowSpeed)) {
|
||||
mBurrowSpeed.setValue(burrowSpeed);
|
||||
mHasChanges.setValue(true);
|
||||
}
|
||||
}
|
||||
|
||||
public LiveData<Integer> getClimbSpeed() {
|
||||
return mClimbSpeed;
|
||||
}
|
||||
|
||||
public void setClimbSpeed(int climbSpeed) {
|
||||
if (!Objects.equals(mClimbSpeed.getValue(), climbSpeed)) {
|
||||
mClimbSpeed.setValue(climbSpeed);
|
||||
mHasChanges.setValue(true);
|
||||
}
|
||||
}
|
||||
|
||||
public LiveData<Integer> getFlySpeed() {
|
||||
return mFlySpeed;
|
||||
}
|
||||
|
||||
public void setFlySpeed(int flySpeed) {
|
||||
if (!Objects.equals(mFlySpeed.getValue(), flySpeed)) {
|
||||
mFlySpeed.setValue(flySpeed);
|
||||
mHasChanges.setValue(true);
|
||||
}
|
||||
}
|
||||
|
||||
public LiveData<Integer> getSwimSpeed() {
|
||||
return mSwimSpeed;
|
||||
}
|
||||
|
||||
public void setSwimSpeed(int swimSpeed) {
|
||||
if (!Objects.equals(mSwimSpeed.getValue(), swimSpeed)) {
|
||||
mSwimSpeed.setValue(swimSpeed);
|
||||
mHasChanges.setValue(true);
|
||||
}
|
||||
}
|
||||
|
||||
public LiveData<Boolean> getCanHover() {
|
||||
return mCanHover;
|
||||
}
|
||||
|
||||
public void setCanHover(boolean canHover) {
|
||||
if (!Objects.equals(mCanHover.getValue(), canHover)) {
|
||||
mCanHover.setValue(canHover);
|
||||
mHasChanges.setValue(true);
|
||||
}
|
||||
}
|
||||
|
||||
public LiveData<Boolean> getHasCustomSpeed() {
|
||||
return mHasCustomSpeed;
|
||||
}
|
||||
|
||||
public void setHasCustomSpeed(boolean hasCustomSpeed) {
|
||||
if (!Objects.equals(mHasCustomSpeed.getValue(), hasCustomSpeed)) {
|
||||
mHasCustomSpeed.setValue(hasCustomSpeed);
|
||||
mHasChanges.setValue(true);
|
||||
}
|
||||
}
|
||||
|
||||
public LiveData<String> getCustomSpeed() {
|
||||
return mCustomSpeed;
|
||||
}
|
||||
|
||||
public void setCustomSpeed(String customSpeed) {
|
||||
if (!Objects.equals(mCustomSpeed.getValue(), customSpeed)) {
|
||||
mCustomSpeed.setValue(customSpeed);
|
||||
mHasChanges.setValue(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void incrementBurrowSpeed() {
|
||||
setBurrowSpeed(mBurrowSpeed.getValue() + 5);
|
||||
}
|
||||
|
||||
public void decrementBurrowSpeed() {
|
||||
setBurrowSpeed(mBurrowSpeed.getValue() - 5);
|
||||
}
|
||||
|
||||
public void incrementClimbSpeed() {
|
||||
setClimbSpeed(mClimbSpeed.getValue() + 5);
|
||||
}
|
||||
|
||||
public void decrementClimbSpeed() {
|
||||
setClimbSpeed(mClimbSpeed.getValue() - 5);
|
||||
}
|
||||
|
||||
public void incrementFlySpeed() {
|
||||
setFlySpeed(mFlySpeed.getValue() + 5);
|
||||
}
|
||||
|
||||
public void decrementFlySpeed() {
|
||||
setFlySpeed(mFlySpeed.getValue() - 5);
|
||||
}
|
||||
|
||||
public void incrementSwimSpeed() {
|
||||
setSwimSpeed(mSwimSpeed.getValue() + 5);
|
||||
}
|
||||
|
||||
public void decrementSwimSpeed() {
|
||||
setSwimSpeed(mSwimSpeed.getValue() - 5);
|
||||
}
|
||||
|
||||
|
||||
public Monster buildMonster() {
|
||||
Monster monster = new Monster();
|
||||
|
||||
@@ -313,6 +468,14 @@ public class EditMonsterViewModel extends ViewModel {
|
||||
monster.naturalArmorBonus = mNaturalArmorBonus.getValue();
|
||||
monster.shieldBonus = mShieldBonus.getValue();
|
||||
monster.otherArmorDescription = mCustomArmor.getValue();
|
||||
monster.walkSpeed = mWalkSpeed.getValue();
|
||||
monster.burrowSpeed = mBurrowSpeed.getValue();
|
||||
monster.climbSpeed = mClimbSpeed.getValue();
|
||||
monster.flySpeed = mFlySpeed.getValue();
|
||||
monster.swimSpeed = mSwimSpeed.getValue();
|
||||
monster.canHover = mCanHover.getValue();
|
||||
monster.hasCustomSpeed = mHasCustomSpeed.getValue();
|
||||
monster.customSpeedDescription = mCustomSpeed.getValue();
|
||||
|
||||
return monster;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
package com.majinnaibu.monstercards.ui.editmonster;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.widget.SwitchCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.navigation.NavBackStackEntry;
|
||||
import androidx.navigation.NavController;
|
||||
import androidx.navigation.Navigation;
|
||||
|
||||
import com.majinnaibu.monstercards.R;
|
||||
import com.majinnaibu.monstercards.utils.TextChangedListener;
|
||||
|
||||
public class EditSpeedFragment extends Fragment {
|
||||
private EditMonsterViewModel mViewModel;
|
||||
private ViewHolder mHolder;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
NavController navController = Navigation.findNavController(requireActivity(), R.id.nav_host_fragment);
|
||||
NavBackStackEntry backStackEntry = navController.getBackStackEntry(R.id.edit_monster_navigation);
|
||||
mViewModel = new ViewModelProvider(backStackEntry).get(EditMonsterViewModel.class);
|
||||
|
||||
// Inflate the layout for this fragment
|
||||
View root = inflater.inflate(R.layout.fragment_edit_speed, container, false);
|
||||
|
||||
mHolder = new ViewHolder(root);
|
||||
|
||||
mViewModel.getWalkSpeed().observe(getViewLifecycleOwner(), value -> {
|
||||
mHolder.baseSpeed.setText(String.format(getString(R.string.format_distance_in_feet), value));
|
||||
});
|
||||
mHolder.incrementBaseSpeed.setOnClickListener(v -> mViewModel.incrementWalkSpeed());
|
||||
mHolder.decrementBaseSpeed.setOnClickListener(v -> mViewModel.decrementWalkSpeed());
|
||||
|
||||
mViewModel.getBurrowSpeed().observe(getViewLifecycleOwner(), value -> {
|
||||
mHolder.burrowSpeed.setText(String.format(getString(R.string.format_distance_in_feet), value));
|
||||
});
|
||||
mHolder.incrementBurrowSpeed.setOnClickListener(v -> mViewModel.incrementBurrowSpeed());
|
||||
mHolder.decrementBurrowSpeed.setOnClickListener(v -> mViewModel.decrementBurrowSpeed());
|
||||
|
||||
mViewModel.getClimbSpeed().observe(getViewLifecycleOwner(), value -> mHolder.climbSpeed.setText(String.format(getString(R.string.format_distance_in_feet), value)));
|
||||
mHolder.incrementClimbSpeed.setOnClickListener(v -> mViewModel.incrementClimbSpeed());
|
||||
mHolder.decrementBurrowSpeed.setOnClickListener(v -> mViewModel.decrementClimbSpeed());
|
||||
|
||||
mViewModel.getFlySpeed().observe(getViewLifecycleOwner(), value -> mHolder.flySpeed.setText(String.format(getString(R.string.format_distance_in_feet), value)));
|
||||
mHolder.incrementFlySpeed.setOnClickListener(v -> mViewModel.incrementFlySpeed());
|
||||
mHolder.decrementBurrowSpeed.setOnClickListener(v -> mViewModel.decrementFlySpeed());
|
||||
|
||||
mViewModel.getSwimSpeed().observe(getViewLifecycleOwner(), value -> mHolder.swimSpeed.setText(String.format(getString(R.string.format_distance_in_feet), value)));
|
||||
mHolder.incrementSwimSpeed.setOnClickListener(v -> mViewModel.incrementSwimSpeed());
|
||||
mHolder.decrementBurrowSpeed.setOnClickListener(v -> mViewModel.decrementSwimSpeed());
|
||||
|
||||
mViewModel.getCanHover().observe(getViewLifecycleOwner(), value -> mHolder.canHover.setChecked(value));
|
||||
mHolder.canHover.setOnCheckedChangeListener((buttonView, isChecked) -> mViewModel.setCanHover(isChecked));
|
||||
|
||||
mViewModel.getHasCustomSpeed().observe(getViewLifecycleOwner(), value -> mHolder.hasCustomSpeed.setChecked(value));
|
||||
mHolder.hasCustomSpeed.setOnCheckedChangeListener((buttonView, isChecked) -> mViewModel.setHasCustomSpeed(isChecked));
|
||||
|
||||
//mViewModel.getCustomSpeed().observe(getViewLifecycleOwner(), value -> mHolder.customSpeed.setText(value));
|
||||
mHolder.customSpeed.setText(mViewModel.getCustomSpeed().getValue());
|
||||
mHolder.customSpeed.addTextChangedListener(new TextChangedListener((TextChangedListener.OnTextChangedCallback) (s, start, before, count) -> mViewModel.setCustomSpeed(s.toString())));
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
private static class ViewHolder {
|
||||
|
||||
final TextView baseSpeed;
|
||||
final Button incrementBaseSpeed;
|
||||
final Button decrementBaseSpeed;
|
||||
final TextView burrowSpeed;
|
||||
final Button incrementBurrowSpeed;
|
||||
final Button decrementBurrowSpeed;
|
||||
final TextView climbSpeed;
|
||||
final Button incrementClimbSpeed;
|
||||
final Button decrementClimbSpeed;
|
||||
final TextView flySpeed;
|
||||
final Button incrementFlySpeed;
|
||||
final Button decrementFlySpeed;
|
||||
final TextView swimSpeed;
|
||||
final Button incrementSwimSpeed;
|
||||
final Button decrementSwimSpeed;
|
||||
final SwitchCompat canHover;
|
||||
final SwitchCompat hasCustomSpeed;
|
||||
final EditText customSpeed;
|
||||
|
||||
ViewHolder(View root) {
|
||||
baseSpeed = root.findViewById(R.id.baseSpeed);
|
||||
incrementBaseSpeed = root.findViewById(R.id.baseSpeed_increment);
|
||||
decrementBaseSpeed = root.findViewById(R.id.baseSpeed_decrement);
|
||||
burrowSpeed = root.findViewById(R.id.burrowSpeed);
|
||||
incrementBurrowSpeed = root.findViewById(R.id.burrowSpeed_increment);
|
||||
decrementBurrowSpeed = root.findViewById(R.id.burrowSpeed_decrement);
|
||||
climbSpeed = root.findViewById(R.id.climbSpeed);
|
||||
incrementClimbSpeed = root.findViewById(R.id.climbSpeed_increment);
|
||||
decrementClimbSpeed = root.findViewById(R.id.climbSpeed_decrement);
|
||||
flySpeed = root.findViewById(R.id.flySpeed);
|
||||
incrementFlySpeed = root.findViewById(R.id.flySpeed_increment);
|
||||
decrementFlySpeed = root.findViewById(R.id.flySpeed_decrement);
|
||||
swimSpeed = root.findViewById(R.id.swimSpeed);
|
||||
incrementSwimSpeed = root.findViewById(R.id.swimSpeed_increment);
|
||||
decrementSwimSpeed = root.findViewById(R.id.swimSpeed_decrement);
|
||||
canHover = root.findViewById(R.id.canHover);
|
||||
hasCustomSpeed = root.findViewById(R.id.hasCustomSpeed);
|
||||
customSpeed = root.findViewById(R.id.customSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user