From 98e28178024decb67fa6bd844d2188d8c2b5017d Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sat, 23 Jul 2022 17:20:57 +0200 Subject: Android: Add setting for enabling graphics mods --- .../dolphinemu/dolphinemu/features/settings/model/BooleanSetting.java | 1 + .../dolphinemu/features/settings/ui/SettingsFragmentPresenter.java | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'Source/Android/app/src/main/java/org') diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/BooleanSetting.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/BooleanSetting.java index 44ee61ed71..d09aaa75b1 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/BooleanSetting.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/BooleanSetting.java @@ -200,6 +200,7 @@ public enum BooleanSetting implements AbstractBooleanSetting "WaitForShadersBeforeStarting", false), GFX_SAVE_TEXTURE_CACHE_TO_STATE(Settings.FILE_GFX, Settings.SECTION_GFX_SETTINGS, "SaveTextureCacheToState", true), + GFX_MODS_ENABLE(Settings.FILE_GFX, Settings.SECTION_GFX_SETTINGS, "EnableMods", false), GFX_ENHANCE_FORCE_FILTERING(Settings.FILE_GFX, Settings.SECTION_GFX_ENHANCEMENTS, "ForceFiltering", false), diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java index 8dda6b64c6..137d2e3dc5 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java @@ -756,7 +756,9 @@ public final class SettingsFragmentPresenter private void addAdvancedGraphicsSettings(ArrayList sl) { - sl.add(new HeaderSetting(mContext, R.string.custom_textures, 0)); + sl.add(new HeaderSetting(mContext, R.string.gfx_mods_and_custom_textures, 0)); + sl.add(new CheckBoxSetting(mContext, BooleanSetting.GFX_MODS_ENABLE, + R.string.gfx_mods, R.string.gfx_mods_description)); sl.add(new CheckBoxSetting(mContext, BooleanSetting.GFX_HIRES_TEXTURES, R.string.load_custom_texture, R.string.load_custom_texture_description)); sl.add(new CheckBoxSetting(mContext, BooleanSetting.GFX_CACHE_HIRES_TEXTURES, -- cgit v1.2.3 From 41a26f76fae1e580f99c471dc70ea420f3d598e6 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sat, 23 Jul 2022 14:45:26 +0200 Subject: Android: Add Cheat.supportsCode method Patches, AR codes and Gecko codes have an associated code that the GUI can show, but graphics mods don't. --- .../dolphinemu/dolphinemu/features/cheats/model/AbstractCheat.java | 5 +++++ .../org/dolphinemu/dolphinemu/features/cheats/model/Cheat.java | 7 ++++++- .../dolphinemu/features/cheats/ui/CheatDetailsFragment.java | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) (limited to 'Source/Android/app/src/main/java/org') diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/AbstractCheat.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/AbstractCheat.java index 9a86d58533..2c33ccc616 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/AbstractCheat.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/AbstractCheat.java @@ -9,6 +9,11 @@ public abstract class AbstractCheat implements Cheat { private Runnable mChangedCallback = null; + public boolean supportsCode() + { + return true; + } + public int trySet(@NonNull String name, @NonNull String creator, @NonNull String notes, @NonNull String code) { diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/Cheat.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/Cheat.java index 75a3befc6f..142931b9cb 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/Cheat.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/Cheat.java @@ -17,6 +17,8 @@ public interface Cheat boolean supportsNotes(); + boolean supportsCode(); + @NonNull String getName(); @@ -33,7 +35,10 @@ public interface Cheat } @NonNull - String getCode(); + default String getCode() + { + return ""; + } int trySet(@NonNull String name, @NonNull String creator, @NonNull String notes, @NonNull String code); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatDetailsFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatDetailsFragment.java index e5a027f64b..9c207996bb 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatDetailsFragment.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatDetailsFragment.java @@ -31,6 +31,7 @@ public class CheatDetailsFragment extends Fragment private EditText mEditCreator; private TextView mLabelNotes; private EditText mEditNotes; + private TextView mLabelCode; private EditText mEditCode; private Button mButtonDelete; private Button mButtonEdit; @@ -59,6 +60,7 @@ public class CheatDetailsFragment extends Fragment mEditCreator = view.findViewById(R.id.edit_creator); mLabelNotes = view.findViewById(R.id.label_notes); mEditNotes = view.findViewById(R.id.edit_notes); + mLabelCode = view.findViewById(R.id.label_code); mEditCode = view.findViewById(R.id.edit_code); mButtonDelete = view.findViewById(R.id.button_delete); mButtonEdit = view.findViewById(R.id.button_edit); @@ -158,10 +160,13 @@ public class CheatDetailsFragment extends Fragment int creatorVisibility = cheat != null && cheat.supportsCreator() ? View.VISIBLE : View.GONE; int notesVisibility = cheat != null && cheat.supportsNotes() ? View.VISIBLE : View.GONE; + int codeVisibility = cheat != null && cheat.supportsCode() ? View.VISIBLE : View.GONE; mLabelCreator.setVisibility(creatorVisibility); mEditCreator.setVisibility(creatorVisibility); mLabelNotes.setVisibility(notesVisibility); mEditNotes.setVisibility(notesVisibility); + mLabelCode.setVisibility(codeVisibility); + mEditCode.setVisibility(codeVisibility); boolean userDefined = cheat != null && cheat.getUserDefined(); mButtonDelete.setEnabled(userDefined); -- cgit v1.2.3 From 45f6d36c4581b37d6b3eff0a8004301d685adf55 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sat, 23 Jul 2022 14:51:18 +0200 Subject: Android: Split AbstractCheat into ReadOnlyCheat and AbstractCheat ReadOnlyCheat will be used by graphics mods. --- .../features/cheats/model/AbstractCheat.java | 24 +-------------- .../features/cheats/model/ReadOnlyCheat.java | 36 ++++++++++++++++++++++ 2 files changed, 37 insertions(+), 23 deletions(-) create mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/ReadOnlyCheat.java (limited to 'Source/Android/app/src/main/java/org') diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/AbstractCheat.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/AbstractCheat.java index 2c33ccc616..d672013b4e 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/AbstractCheat.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/AbstractCheat.java @@ -3,12 +3,9 @@ package org.dolphinemu.dolphinemu.features.cheats.model; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -public abstract class AbstractCheat implements Cheat +public abstract class AbstractCheat extends ReadOnlyCheat { - private Runnable mChangedCallback = null; - public boolean supportsCode() { return true; @@ -43,25 +40,6 @@ public abstract class AbstractCheat implements Cheat return result; } - public void setEnabled(boolean enabled) - { - setEnabledImpl(enabled); - onChanged(); - } - - public void setChangedCallback(@Nullable Runnable callback) - { - mChangedCallback = callback; - } - - protected void onChanged() - { - if (mChangedCallback != null) - mChangedCallback.run(); - } - protected abstract int trySetImpl(@NonNull String name, @NonNull String creator, @NonNull String notes, @NonNull String code); - - protected abstract void setEnabledImpl(boolean enabled); } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/ReadOnlyCheat.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/ReadOnlyCheat.java new file mode 100644 index 0000000000..9751c414f8 --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/ReadOnlyCheat.java @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +package org.dolphinemu.dolphinemu.features.cheats.model; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +public abstract class ReadOnlyCheat implements Cheat +{ + private Runnable mChangedCallback = null; + + public int trySet(@NonNull String name, @NonNull String creator, @NonNull String notes, + @NonNull String code) + { + throw new UnsupportedOperationException(); + } + + public void setEnabled(boolean enabled) + { + setEnabledImpl(enabled); + onChanged(); + } + + public void setChangedCallback(@Nullable Runnable callback) + { + mChangedCallback = callback; + } + + protected void onChanged() + { + if (mChangedCallback != null) + mChangedCallback.run(); + } + + protected abstract void setEnabledImpl(boolean enabled); +} -- cgit v1.2.3 From 8f410bff15e1549a3f54e33ec0f4cf511ebea7df Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sat, 23 Jul 2022 17:14:26 +0200 Subject: Android: Add graphics mods support to CheatsActivity --- .../features/cheats/model/CheatsViewModel.java | 24 +++++++++ .../features/cheats/model/GraphicsMod.java | 61 ++++++++++++++++++++++ .../features/cheats/model/GraphicsModGroup.java | 27 ++++++++++ .../features/cheats/ui/CheatsAdapter.java | 16 +++++- 4 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/GraphicsMod.java create mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/GraphicsModGroup.java (limited to 'Source/Android/app/src/main/java/org') 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 mGeckoCheatsDownloadedEvent = new MutableLiveData<>(null); private final MutableLiveData mOpenDetailsViewEvent = new MutableLiveData<>(false); + private GraphicsModGroup mGraphicsModGroup; + private ArrayList mGraphicsMods; private ArrayList mPatchCheats; private ArrayList mARCheats; private ArrayList 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 getGraphicsMods() + { + return mGraphicsMods; + } + public ArrayList 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 @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 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 graphicsMods = mViewModel.getGraphicsMods(); + if (position < graphicsMods.size()) + return new CheatItem(graphicsMods.get(position)); + position -= graphicsMods.size(); + // Patches if (position == 0) -- cgit v1.2.3 From 3bd2bca38508965348bff45e4a77baa945abf33d Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sat, 23 Jul 2022 17:38:32 +0200 Subject: Android: Add warning if graphics mods are not enabled --- .../features/cheats/ui/CheatWarningFragment.java | 63 ----------------- .../cheats/ui/CheatsDisabledWarningFragment.java | 16 +++++ .../ui/GraphicsModsDisabledWarningFragment.java | 16 +++++ .../cheats/ui/SettingDisabledWarningFragment.java | 80 ++++++++++++++++++++++ 4 files changed, 112 insertions(+), 63 deletions(-) delete mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatWarningFragment.java create mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatsDisabledWarningFragment.java create mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/GraphicsModsDisabledWarningFragment.java create mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/SettingDisabledWarningFragment.java (limited to 'Source/Android/app/src/main/java/org') diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatWarningFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatWarningFragment.java deleted file mode 100644 index df6d9d94b0..0000000000 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatWarningFragment.java +++ /dev/null @@ -1,63 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later - -package org.dolphinemu.dolphinemu.features.cheats.ui; - -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.Button; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; - -import org.dolphinemu.dolphinemu.R; -import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting; -import org.dolphinemu.dolphinemu.features.settings.model.Settings; -import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag; -import org.dolphinemu.dolphinemu.features.settings.ui.SettingsActivity; - -public class CheatWarningFragment extends Fragment implements View.OnClickListener -{ - private View mView; - - @Nullable - @Override - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, - @Nullable Bundle savedInstanceState) - { - return inflater.inflate(R.layout.fragment_cheat_warning, container, false); - } - - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) - { - mView = view; - - Button settingsButton = view.findViewById(R.id.button_settings); - settingsButton.setOnClickListener(this); - - CheatsActivity activity = (CheatsActivity) requireActivity(); - CheatsActivity.setOnFocusChangeListenerRecursively(view, - (v, hasFocus) -> activity.onListViewFocusChange(hasFocus)); - } - - @Override - public void onResume() - { - super.onResume(); - - CheatsActivity activity = (CheatsActivity) requireActivity(); - try (Settings settings = activity.loadGameSpecificSettings()) - { - boolean cheatsEnabled = BooleanSetting.MAIN_ENABLE_CHEATS.getBoolean(settings); - mView.setVisibility(cheatsEnabled ? View.GONE : View.VISIBLE); - } - } - - public void onClick(View view) - { - SettingsActivity.launch(requireContext(), MenuTag.CONFIG_GENERAL); - } -} diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatsDisabledWarningFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatsDisabledWarningFragment.java new file mode 100644 index 0000000000..f2dfd7b341 --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatsDisabledWarningFragment.java @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +package org.dolphinemu.dolphinemu.features.cheats.ui; + +import org.dolphinemu.dolphinemu.R; +import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting; +import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag; + +public class CheatsDisabledWarningFragment extends SettingDisabledWarningFragment +{ + public CheatsDisabledWarningFragment() + { + super(BooleanSetting.MAIN_ENABLE_CHEATS, MenuTag.CONFIG_GENERAL, + R.string.cheats_disabled_warning); + } +} diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/GraphicsModsDisabledWarningFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/GraphicsModsDisabledWarningFragment.java new file mode 100644 index 0000000000..eaf26f094b --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/GraphicsModsDisabledWarningFragment.java @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +package org.dolphinemu.dolphinemu.features.cheats.ui; + +import org.dolphinemu.dolphinemu.R; +import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting; +import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag; + +public class GraphicsModsDisabledWarningFragment extends SettingDisabledWarningFragment +{ + public GraphicsModsDisabledWarningFragment() + { + super(BooleanSetting.GFX_MODS_ENABLE, MenuTag.ADVANCED_GRAPHICS, + R.string.gfx_mods_disabled_warning); + } +} diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/SettingDisabledWarningFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/SettingDisabledWarningFragment.java new file mode 100644 index 0000000000..c239c5c9af --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/SettingDisabledWarningFragment.java @@ -0,0 +1,80 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +package org.dolphinemu.dolphinemu.features.cheats.ui; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; + +import org.dolphinemu.dolphinemu.R; +import org.dolphinemu.dolphinemu.features.settings.model.AbstractBooleanSetting; +import org.dolphinemu.dolphinemu.features.settings.model.Settings; +import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag; +import org.dolphinemu.dolphinemu.features.settings.ui.SettingsActivity; + +public abstract class SettingDisabledWarningFragment extends Fragment + implements View.OnClickListener +{ + private View mView; + + private final AbstractBooleanSetting mSetting; + private final MenuTag mSettingShortcut; + private final int mText; + + public SettingDisabledWarningFragment(AbstractBooleanSetting setting, MenuTag settingShortcut, + int text) + { + mSetting = setting; + mSettingShortcut = settingShortcut; + mText = text; + } + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, + @Nullable Bundle savedInstanceState) + { + return inflater.inflate(R.layout.fragment_cheat_warning, container, false); + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) + { + mView = view; + + TextView textView = view.findViewById(R.id.text_warning); + textView.setText(mText); + + Button settingsButton = view.findViewById(R.id.button_settings); + settingsButton.setOnClickListener(this); + + CheatsActivity activity = (CheatsActivity) requireActivity(); + CheatsActivity.setOnFocusChangeListenerRecursively(view, + (v, hasFocus) -> activity.onListViewFocusChange(hasFocus)); + } + + @Override + public void onResume() + { + super.onResume(); + + CheatsActivity activity = (CheatsActivity) requireActivity(); + try (Settings settings = activity.loadGameSpecificSettings()) + { + boolean cheatsEnabled = mSetting.getBoolean(settings); + mView.setVisibility(cheatsEnabled ? View.GONE : View.VISIBLE); + } + } + + public void onClick(View view) + { + SettingsActivity.launch(requireContext(), mSettingShortcut); + } +} -- cgit v1.2.3