diff options
| author | JosJuice <josjuice@gmail.com> | 2022-07-23 17:14:26 +0200 |
|---|---|---|
| committer | JosJuice <josjuice@gmail.com> | 2022-07-23 21:58:45 +0200 |
| commit | 8f410bff15e1549a3f54e33ec0f4cf511ebea7df (patch) | |
| tree | 295e6373580fce23d1d93a403c17e6b5de87d292 /Source/Android/app/src/main/java | |
| parent | 45f6d36c4581b37d6b3eff0a8004301d685adf55 (diff) | |
Android: Add graphics mods support to CheatsActivity
Diffstat (limited to 'Source/Android/app/src/main/java')
4 files changed, 126 insertions, 2 deletions
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/CheatsViewModel.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/CheatsViewModel.java index 0238628319..4d9900c168 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/CheatsViewModel.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/CheatsViewModel.java @@ -24,10 +24,13 @@ public class CheatsViewModel extends ViewModel private final MutableLiveData<Integer> mGeckoCheatsDownloadedEvent = new MutableLiveData<>(null); private final MutableLiveData<Boolean> mOpenDetailsViewEvent = new MutableLiveData<>(false); + private GraphicsModGroup mGraphicsModGroup; + private ArrayList<GraphicsMod> mGraphicsMods; private ArrayList<PatchCheat> mPatchCheats; private ArrayList<ARCheat> mARCheats; private ArrayList<GeckoCheat> mGeckoCheats; + private boolean mGraphicsModsNeedSaving = false; private boolean mPatchCheatsNeedSaving = false; private boolean mARCheatsNeedSaving = false; private boolean mGeckoCheatsNeedSaving = false; @@ -37,13 +40,23 @@ public class CheatsViewModel extends ViewModel if (mLoaded) return; + mGraphicsModGroup = GraphicsModGroup.load(gameID); + mGraphicsMods = new ArrayList<>(); + Collections.addAll(mGraphicsMods, mGraphicsModGroup.getMods()); + mPatchCheats = new ArrayList<>(); Collections.addAll(mPatchCheats, PatchCheat.loadCodes(gameID, revision)); + mARCheats = new ArrayList<>(); Collections.addAll(mARCheats, ARCheat.loadCodes(gameID, revision)); + mGeckoCheats = new ArrayList<>(); Collections.addAll(mGeckoCheats, GeckoCheat.loadCodes(gameID, revision)); + for (GraphicsMod mod : mGraphicsMods) + { + mod.setChangedCallback(() -> mGraphicsModsNeedSaving = true); + } for (PatchCheat cheat : mPatchCheats) { cheat.setChangedCallback(() -> mPatchCheatsNeedSaving = true); @@ -62,6 +75,12 @@ public class CheatsViewModel extends ViewModel public void saveIfNeeded(String gameID, int revision) { + if (mGraphicsModsNeedSaving) + { + mGraphicsModGroup.save(); + mGraphicsModsNeedSaving = false; + } + if (mPatchCheatsNeedSaving) { PatchCheat.saveCodes(gameID, revision, mPatchCheats.toArray(new PatchCheat[0])); @@ -280,6 +299,11 @@ public class CheatsViewModel extends ViewModel mOpenDetailsViewEvent.setValue(false); } + public ArrayList<GraphicsMod> getGraphicsMods() + { + return mGraphicsMods; + } + public ArrayList<PatchCheat> getPatchCheats() { return mPatchCheats; diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/GraphicsMod.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/GraphicsMod.java new file mode 100644 index 0000000000..241d15093f --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/GraphicsMod.java @@ -0,0 +1,61 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +package org.dolphinemu.dolphinemu.features.cheats.model; + +import androidx.annotation.Keep; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +public class GraphicsMod extends ReadOnlyCheat +{ + @Keep + private final long mPointer; + + // When a C++ GraphicsModGroup object is destroyed, it also destroys the GraphicsMods it owns. + // To avoid getting dangling pointers, we keep a reference to the GraphicsModGroup here. + @Keep + private final GraphicsModGroup mParent; + + @Keep + private GraphicsMod(long pointer, GraphicsModGroup parent) + { + mPointer = pointer; + mParent = parent; + } + + public boolean supportsCreator() + { + return true; + } + + public boolean supportsNotes() + { + return true; + } + + public boolean supportsCode() + { + return false; + } + + @NonNull + public native String getName(); + + @NonNull + public native String getCreator(); + + @NonNull + public native String getNotes(); + + public boolean getUserDefined() + { + // Technically graphics mods can be user defined, but we don't support editing graphics mods + // in the GUI, and editability is what this really controls + return false; + } + + public native boolean getEnabled(); + + @Override + protected native void setEnabledImpl(boolean enabled); +} diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/GraphicsModGroup.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/GraphicsModGroup.java new file mode 100644 index 0000000000..0cb0a3c456 --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/GraphicsModGroup.java @@ -0,0 +1,27 @@ +package org.dolphinemu.dolphinemu.features.cheats.model; + +import androidx.annotation.Keep; +import androidx.annotation.NonNull; + +public class GraphicsModGroup +{ + @Keep + private final long mPointer; + + @Keep + private GraphicsModGroup(long pointer) + { + mPointer = pointer; + } + + @Override + public native void finalize(); + + @NonNull + public native GraphicsMod[] getMods(); + + public native void save(); + + @NonNull + public static native GraphicsModGroup load(String gameId); +} diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatsAdapter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatsAdapter.java index ec256cf6e2..e5be47a3f1 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatsAdapter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatsAdapter.java @@ -13,6 +13,7 @@ import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.features.cheats.model.ARCheat; import org.dolphinemu.dolphinemu.features.cheats.model.CheatsViewModel; import org.dolphinemu.dolphinemu.features.cheats.model.GeckoCheat; +import org.dolphinemu.dolphinemu.features.cheats.model.GraphicsMod; import org.dolphinemu.dolphinemu.features.cheats.model.PatchCheat; import java.util.ArrayList; @@ -90,8 +91,8 @@ public class CheatsAdapter extends RecyclerView.Adapter<CheatItemViewHolder> @Override public int getItemCount() { - return mViewModel.getARCheats().size() + mViewModel.getGeckoCheats().size() + - mViewModel.getPatchCheats().size() + 7; + return mViewModel.getGraphicsMods().size() + mViewModel.getPatchCheats().size() + + mViewModel.getARCheats().size() + mViewModel.getGeckoCheats().size() + 8; } @Override @@ -108,6 +109,17 @@ public class CheatsAdapter extends RecyclerView.Adapter<CheatItemViewHolder> private CheatItem getItemAt(int position) { + // Graphics mods + + if (position == 0) + return new CheatItem(CheatItem.TYPE_HEADER, R.string.cheats_header_graphics_mod); + position -= 1; + + ArrayList<GraphicsMod> graphicsMods = mViewModel.getGraphicsMods(); + if (position < graphicsMods.size()) + return new CheatItem(graphicsMods.get(position)); + position -= graphicsMods.size(); + // Patches if (position == 0) |
