Android: Show patch code categories in list

This commit is contained in:
Connor McLaughlin 2021-05-29 20:51:53 +10:00
parent 1b0b88f60b
commit 0229f25fc3
3 changed files with 22 additions and 4 deletions

View file

@ -1029,7 +1029,8 @@ extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
env->GetMethodID(s_EmulationActivity_class, "hasInputDeviceVibration", "(I)Z")) == nullptr ||
(s_EmulationActivity_method_setInputDeviceVibration =
env->GetMethodID(s_EmulationActivity_class, "setInputDeviceVibration", "(IFF)V")) == nullptr ||
(s_PatchCode_constructor = env->GetMethodID(s_PatchCode_class, "<init>", "(ILjava/lang/String;Z)V")) == nullptr ||
(s_PatchCode_constructor =
env->GetMethodID(s_PatchCode_class, "<init>", "(ILjava/lang/String;Ljava/lang/String;Z)V")) == nullptr ||
(s_GameListEntry_constructor =
env->GetMethodID(s_GameListEntry_class, "<init>",
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;JLjava/lang/String;Ljava/lang/"
@ -1628,12 +1629,14 @@ DEFINE_JNI_ARGS_METHOD(jobject, AndroidHostInterface_getPatchCodeList, jobject o
{
const CheatCode& cc = cl->GetCode(i);
jstring group_str = cc.group.empty() ? nullptr : env->NewStringUTF(cc.group.c_str());
jstring desc_str = env->NewStringUTF(cc.description.c_str());
jobject java_cc =
env->NewObject(s_PatchCode_class, s_PatchCode_constructor, static_cast<jint>(i), desc_str, cc.enabled);
env->NewObject(s_PatchCode_class, s_PatchCode_constructor, static_cast<jint>(i), group_str, desc_str, cc.enabled);
env->SetObjectArrayElement(arr, i, java_cc);
env->DeleteLocalRef(java_cc);
env->DeleteLocalRef(desc_str);
env->DeleteLocalRef(group_str);
}
return arr;

View file

@ -581,7 +581,7 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde
boolean[] itemsChecked = new boolean[codes.length];
for (int i = 0; i < codes.length; i++) {
final PatchCode cc = codes[i];
items[i] = cc.getDescription();
items[i] = cc.getDisplayText();
itemsChecked[i] = cc.isEnabled();
}

View file

@ -1,12 +1,16 @@
package com.github.stenzek.duckstation;
public class PatchCode {
private static final String UNGROUPED_NAME = "Ungrouped";
private int mIndex;
private String mGroup;
private String mDescription;
private boolean mEnabled;
public PatchCode(int index, String description, boolean enabled) {
public PatchCode(int index, String group, String description, boolean enabled) {
mIndex = index;
mGroup = group;
mDescription = description;
mEnabled = enabled;
}
@ -15,6 +19,10 @@ public class PatchCode {
return mIndex;
}
public String getGroup() {
return mGroup;
}
public String getDescription() {
return mDescription;
}
@ -22,4 +30,11 @@ public class PatchCode {
public boolean isEnabled() {
return mEnabled;
}
public String getDisplayText() {
if (mGroup == null || mGroup.equals(UNGROUPED_NAME))
return mDescription;
else
return String.format("(%s) %s", mGroup, mDescription);
}
}