mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 05:09:34 -06:00
Android: Allow viewing/editing the actual codes
This commit is contained in:
@ -22,12 +22,15 @@ public class ARCheat extends AbstractCheat
|
||||
@NonNull
|
||||
public native String getName();
|
||||
|
||||
@NonNull
|
||||
public native String getCode();
|
||||
|
||||
public native boolean getUserDefined();
|
||||
|
||||
public native boolean getEnabled();
|
||||
|
||||
@Override
|
||||
protected native int trySetImpl(@NonNull String name);
|
||||
protected native int trySetImpl(@NonNull String name, @NonNull String code);
|
||||
|
||||
@Override
|
||||
protected native void setEnabledImpl(boolean enabled);
|
||||
|
@ -9,12 +9,12 @@ public abstract class AbstractCheat implements Cheat
|
||||
{
|
||||
private Runnable mChangedCallback = null;
|
||||
|
||||
public int trySet(@NonNull String name)
|
||||
public int trySet(@NonNull String name, @NonNull String code)
|
||||
{
|
||||
if (name.isEmpty())
|
||||
return TRY_SET_FAIL_NO_NAME;
|
||||
|
||||
int result = trySetImpl(name);
|
||||
int result = trySetImpl(name, code);
|
||||
|
||||
if (result == TRY_SET_SUCCESS)
|
||||
onChanged();
|
||||
@ -39,7 +39,7 @@ public abstract class AbstractCheat implements Cheat
|
||||
mChangedCallback.run();
|
||||
}
|
||||
|
||||
protected abstract int trySetImpl(@NonNull String name);
|
||||
protected abstract int trySetImpl(@NonNull String name, @NonNull String code);
|
||||
|
||||
protected abstract void setEnabledImpl(boolean enabled);
|
||||
}
|
||||
|
@ -7,13 +7,19 @@ import androidx.annotation.Nullable;
|
||||
|
||||
public interface Cheat
|
||||
{
|
||||
int TRY_SET_FAIL_CODE_MIXED_ENCRYPTION = -3;
|
||||
int TRY_SET_FAIL_NO_CODE_LINES = -2;
|
||||
int TRY_SET_FAIL_NO_NAME = -1;
|
||||
int TRY_SET_SUCCESS = 0;
|
||||
// Result codes greater than 0 represent an error on the corresponding code line (one-indexed)
|
||||
|
||||
@NonNull
|
||||
String getName();
|
||||
|
||||
int trySet(@NonNull String name);
|
||||
@NonNull
|
||||
String getCode();
|
||||
|
||||
int trySet(@NonNull String name, @NonNull String code);
|
||||
|
||||
boolean getUserDefined();
|
||||
|
||||
|
@ -22,12 +22,15 @@ public class GeckoCheat extends AbstractCheat
|
||||
@NonNull
|
||||
public native String getName();
|
||||
|
||||
@NonNull
|
||||
public native String getCode();
|
||||
|
||||
public native boolean getUserDefined();
|
||||
|
||||
public native boolean getEnabled();
|
||||
|
||||
@Override
|
||||
protected native int trySetImpl(@NonNull String name);
|
||||
protected native int trySetImpl(@NonNull String name, @NonNull String code);
|
||||
|
||||
@Override
|
||||
protected native void setEnabledImpl(boolean enabled);
|
||||
|
@ -22,12 +22,15 @@ public class PatchCheat extends AbstractCheat
|
||||
@NonNull
|
||||
public native String getName();
|
||||
|
||||
@NonNull
|
||||
public native String getCode();
|
||||
|
||||
public native boolean getUserDefined();
|
||||
|
||||
public native boolean getEnabled();
|
||||
|
||||
@Override
|
||||
protected native int trySetImpl(@NonNull String name);
|
||||
protected native int trySetImpl(@NonNull String name, @NonNull String code);
|
||||
|
||||
@Override
|
||||
protected native void setEnabledImpl(boolean enabled);
|
||||
|
@ -23,6 +23,7 @@ public class CheatDetailsFragment extends Fragment
|
||||
{
|
||||
private View mRoot;
|
||||
private EditText mEditName;
|
||||
private EditText mEditCode;
|
||||
private Button mButtonEdit;
|
||||
private Button mButtonCancel;
|
||||
private Button mButtonOk;
|
||||
@ -43,6 +44,7 @@ public class CheatDetailsFragment extends Fragment
|
||||
{
|
||||
mRoot = view.findViewById(R.id.root);
|
||||
mEditName = view.findViewById(R.id.edit_name);
|
||||
mEditCode = view.findViewById(R.id.edit_code);
|
||||
mButtonEdit = view.findViewById(R.id.button_edit);
|
||||
mButtonCancel = view.findViewById(R.id.button_cancel);
|
||||
mButtonOk = view.findViewById(R.id.button_ok);
|
||||
@ -65,13 +67,14 @@ public class CheatDetailsFragment extends Fragment
|
||||
private void clearEditErrors()
|
||||
{
|
||||
mEditName.setError(null);
|
||||
mEditCode.setError(null);
|
||||
}
|
||||
|
||||
private void onOkClicked(View view)
|
||||
{
|
||||
clearEditErrors();
|
||||
|
||||
int result = mCheat.trySet(mEditName.getText().toString());
|
||||
int result = mCheat.trySet(mEditName.getText().toString(), mEditCode.getText().toString());
|
||||
|
||||
switch (result)
|
||||
{
|
||||
@ -80,7 +83,16 @@ public class CheatDetailsFragment extends Fragment
|
||||
mViewModel.setIsEditing(false);
|
||||
break;
|
||||
case Cheat.TRY_SET_FAIL_NO_NAME:
|
||||
mEditName.setError(getText(R.string.cheats_error_no_name));
|
||||
mEditName.setError(getString(R.string.cheats_error_no_name));
|
||||
break;
|
||||
case Cheat.TRY_SET_FAIL_NO_CODE_LINES:
|
||||
mEditCode.setError(getString(R.string.cheats_error_no_code_lines));
|
||||
break;
|
||||
case Cheat.TRY_SET_FAIL_CODE_MIXED_ENCRYPTION:
|
||||
mEditCode.setError(getString(R.string.cheats_error_mixed_encryption));
|
||||
break;
|
||||
default:
|
||||
mEditCode.setError(getString(R.string.cheats_error_on_line, result));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -101,6 +113,7 @@ public class CheatDetailsFragment extends Fragment
|
||||
if (!isEditing && cheat != null)
|
||||
{
|
||||
mEditName.setText(cheat.getName());
|
||||
mEditCode.setText(cheat.getCode());
|
||||
}
|
||||
|
||||
mCheat = cheat;
|
||||
@ -109,6 +122,7 @@ public class CheatDetailsFragment extends Fragment
|
||||
private void onIsEditingUpdated(boolean isEditing)
|
||||
{
|
||||
mEditName.setEnabled(isEditing);
|
||||
mEditCode.setEnabled(isEditing);
|
||||
|
||||
mButtonEdit.setVisibility(isEditing ? View.GONE : View.VISIBLE);
|
||||
mButtonCancel.setVisibility(isEditing ? View.VISIBLE : View.GONE);
|
||||
|
@ -45,9 +45,39 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/label_name"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintBottom_toTopOf="@id/label_code"
|
||||
tools:text="Hyrule Field Speed Hack" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/label_code"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/TextAppearance.AppCompat.Headline"
|
||||
android:textSize="18sp"
|
||||
android:text="@string/cheats_code"
|
||||
android:layout_margin="@dimen/spacing_large"
|
||||
android:labelFor="@id/edit_code"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/edit_name"
|
||||
app:layout_constraintBottom_toTopOf="@id/edit_code" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/edit_code"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="108sp"
|
||||
android:layout_marginHorizontal="@dimen/spacing_large"
|
||||
android:importantForAutofill="no"
|
||||
android:inputType="textMultiLine"
|
||||
android:typeface="monospace"
|
||||
android:gravity="start"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/label_code"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
tools:text="0x8003d63c:dword:0x60000000\n0x8003d658:dword:0x60000000" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
@ -390,8 +390,12 @@
|
||||
<string name="cheats">Cheats</string>
|
||||
<string name="cheats_with_game_id">Cheats: %1$s</string>
|
||||
<string name="cheats_name">Name</string>
|
||||
<string name="cheats_code">Code</string>
|
||||
<string name="cheats_edit">Edit</string>
|
||||
<string name="cheats_error_no_name">Name can\'t be empty</string>
|
||||
<string name="cheats_error_no_code_lines">Code can\'t be empty</string>
|
||||
<string name="cheats_error_on_line">Error on line %1$d</string>
|
||||
<string name="cheats_error_mixed_encryption">Lines must either be all encrypted or all decrypted</string>
|
||||
|
||||
<!-- Convert Screen -->
|
||||
<string name="convert_format">Format</string>
|
||||
|
Reference in New Issue
Block a user