Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
furkanzkafka committed Apr 27, 2024
2 parents 75dce8b + 17de0ba commit 19f238c
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 82 deletions.
26 changes: 26 additions & 0 deletions app/src/main/java/com/example/proj2/Classes/Ability.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,32 @@ public Ability(){
this.ratioAD = ratioAD;
this.ratioAP = ratioAP;
}

/**
* Constructor for the Ability class with parameters.
* @param name Name of the ability.
* @param damageType Type of damage (0: Attack Damage, 1: Ability Power, 2: True Damage).
* @param rank Rank of the ability.
* @param damage Damage values of the ability.
* @param isDamage Boolean indicating if the ability deals damage.
* @param isSummon Boolean indicating if the ability summons.
* @param isStack Boolean indicating if the ability stacks.
* @param isCritiable Boolean indicating if the ability is critiable.
* @param isMaxHP Boolean indicating if the ability is based on max HP.
* @param isMaxHPDOT Boolean indicating if the ability deals max HP based damage over time.
* @param isDOT Boolean indicating if the ability deals damage over time.
* @param duration Duration of the ability effect.
* @param perSecond Damage per second of the ability.
* @param dotDamage Damage values of the damage over time effect.
* @param dotRatio Ratios of the damage over time effect.
* @param summonAA Summon attack damage values.
* @param summonRatioAD Summon ability power ratios.
* @param summonRatioAP Summon ability power ratios.
* @param instances Number of instances of the ability.
* @param ratioBAD Ratios of the ability.
* @param ratioAD Ratios of the ability.
* @param ratioAP Ratios of the ability.
*/
public Ability(String name, int damageType, int rank, ArrayList<Double> damage, boolean isDamage, boolean isSummon, boolean isStack, boolean isCritiable, boolean isMaxHP, boolean isMaxHPDOT, boolean isDOT, double duration, double perSecond, ArrayList<Double> dotDamage, ArrayList<Double> dotRatio, ArrayList<Double> summonAA, ArrayList<Double> summonRatioAD, ArrayList<Double> summonRatioAP, int instances, ArrayList<Double> ratioBAD, ArrayList<Double> ratioAD, ArrayList<Double> ratioAP) {
Name = name;
this.damageType = damageType;
Expand Down
34 changes: 26 additions & 8 deletions app/src/main/java/com/example/proj2/Classes/ItemViewModel.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.proj2.Classes;

import android.util.Log;
import android.widget.ImageButton;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
Expand All @@ -9,13 +10,18 @@
import com.google.firebase.firestore.DocumentReference;
import com.google.firebase.firestore.FirebaseFirestore;

import java.util.HashMap;
import java.util.Map;

/**
* The ItemViewModel class is a ViewModel responsible for managing item data.
* It provides methods to fetch item data from Firestore, select items.
*/
public class ItemViewModel extends ViewModel {
private MutableLiveData<Item> selectedItem = new MutableLiveData<>();
private MutableLiveData<String> itemName = new MutableLiveData<>();
private MutableLiveData<Integer> slot = new MutableLiveData<>();
private MutableLiveData<Map<Integer, Integer>> slotResourceMap = new MutableLiveData<>(new HashMap<>());

private FirebaseFirestore db = FirebaseFirestore.getInstance();

/**
Expand Down Expand Up @@ -55,20 +61,32 @@ public void selectItem(Item item) {
}

/**
* Gets the LiveData object representing the item name.
* Gets the LiveData object representing the ImageButton.
*
* @return The LiveData object representing the item name
* @return The LiveData object representing the ImageButton's ID
*/
public LiveData<String> getItemName() {
return itemName;
public LiveData<Integer> getSlot() {
return slot;
}

/**
* Sets the item name.
*
* @param info The name of the item to set
* @param btnID The ImageButton's ID to set
*/
public void setItemName(String info) {
itemName.setValue(info);
public void setSlot(int btnID) {
slot.postValue(btnID);
}
public void setItemImageResource(int slotId, int resourceId) {
Map<Integer, Integer> currentMap = slotResourceMap.getValue();
if (currentMap == null) {
currentMap = new HashMap<>();
}
currentMap.put(slotId, resourceId);
slotResourceMap.setValue(currentMap);
}

public LiveData<Map<Integer, Integer>> getSlotResourceMap() {
return slotResourceMap;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public class ItemSelectionActivity extends AppCompatActivity {
// Initialize Firestore database reference
private FirebaseFirestore db = FirebaseFirestore.getInstance();

/**
* Sets up the layout and initializes the ViewModel for handling item data.
*
* @param savedInstanceState If non-null, this activity is being re-constructed from a previous saved state
* as given here.
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down
49 changes: 26 additions & 23 deletions app/src/main/java/com/example/proj2/ItemSelectionFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,42 +24,45 @@
import com.example.proj2.databinding.FragmentItemSelectionBinding;
import com.example.proj2.databinding.FragmentSecondBinding;

/**
* Fragment allowing users to select items.
*/
public class ItemSelectionFragment extends Fragment {
private FragmentItemSelectionBinding binding;

/**
* Creates a new instance of the ItemSelectionFragment.
*
* @return A new instance of ItemSelectionFragment.
*/
public static ItemSelectionFragment newInstance() {
return new ItemSelectionFragment();
}

/**
* Inflates the layout of the fragment and initializes the ViewModel for handling item data.
*
* @param inflater The LayoutInflater object that can be used to inflate
* any views in the fragment.
* @param container If non-null, this is the parent view that the fragment's UI should be attached to.
* @param savedInstanceState If non-null, this fragment is being re-constructed from a previous saved state
* as given here.
* @return The root view of the inflated layout.
*/
@Override
public View onCreateView( @NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
binding = FragmentItemSelectionBinding.inflate(inflater, container, false);
//Log.d("item selection","fragment");
//ViewModels
// Use requireActivity() to ensure the ViewModel is scoped to the host activity
ItemViewModel itemViewModel = new ViewModelProvider(requireActivity()).get(ItemViewModel.class);


// Set the click listener for items
Button item1button = binding.button1;
// ImageButton item2button = view.findViewById(R.id.button2);
// ImageButton item3button = view.findViewById(R.id.button3);
// ImageButton item4button = view.findViewById(R.id.button4);
// ImageButton item5button = view.findViewById(R.id.button5);
// ImageButton item6button = view.findViewById(R.id.button6);


// item1button.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// String itemName = "Doran's Blade";
// itemViewModel.fetchItemData(itemName);
// }
// });

return binding.getRoot();
}

/**
* Sets up UI elements and click listeners for item selection.
*
* @param view The root view of the fragment's layout.
* @param savedInstanceState If non-null, this fragment is being re-constructed from a previous saved state
* as given here.
*/
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Log.d("item selection","fragment");
Expand Down
29 changes: 29 additions & 0 deletions app/src/main/java/com/example/proj2/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,21 @@
import android.view.Menu;
import android.view.MenuItem;

/**
* MainActivity class representing the main activity of the application.
*/
public class MainActivity extends AppCompatActivity {

private AppBarConfiguration appBarConfiguration;
private ActivityMainBinding binding;

/**
* Called when the activity is starting. This is where most initialization should go.
*
* @param savedInstanceState If the activity is being re-initialized after previously being shut down
* then this Bundle contains the data it most recently supplied in
* onSaveInstanceState(Bundle). Note: Otherwise it is null.
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -46,13 +56,26 @@ public void onClick(View view) {
});
}

/**
* Initialize the contents of the Activity's standard options menu.
*
* @param menu The options menu in which you place your items.
* @return You must return true for the menu to be displayed;
* if you return false it will not be shown.
*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

/**
* Called whenever an item in the options menu is selected.
*
* @param item The menu item that was selected.
* @return Return false to allow normal menu processing to proceed, true to consume it here.
*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
Expand All @@ -68,6 +91,12 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}

/**
* Navigate up within the activity's navigation hierarchy.
*
* @return True if Up navigation completed successfully and this Activity was finished,
* false otherwise.
*/
@Override
public boolean onSupportNavigateUp() {
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_main);
Expand Down
Loading

0 comments on commit 19f238c

Please sign in to comment.