Permalink
Browse files

front: Added advanced cheat editing mode

  • Loading branch information...
fzurita committed Mar 19, 2016
1 parent 8c46f26 commit e25c14ec7cc01ec6ac80424da4fb03025ffb79a3
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" >
+
+ <LinearLayout
+ android:id="@+id/linearLayout1"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical" >
+
+ <EditText
+ android:id="@+id/textCheatTitle"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_margin="5dp"
+ android:hint="@string/cheatEditor_hint_cheatTitle"
+ android:inputType="textNoSuggestions|text"
+ android:singleLine="true"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
+
+ <EditText
+ android:id="@+id/textCheatNotes"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_margin="5dp"
+ android:gravity="top|start"
+ android:hint="@string/cheatEditor_hint_cheatNotes"
+ android:lines="8"
+ android:maxLines="10"
+ android:minLines="1"
+ android:scrollbars="vertical"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
+
+ <EditText
+ android:id="@+id/textCheat"
+ android:layout_width="match_parent"
+ android:layout_height="150dp"
+ android:layout_margin="5dp"
+ android:digits="0123456789ABCDEF"
+ android:gravity="top"
+ android:hint="@string/cheatEditor_hint_cheatData"
+ android:inputType="textCapCharacters"
+ android:lines="8"
+ android:maxLines="10"
+ android:minLines="1"
+ android:singleLine="false"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:typeface="monospace" />
+
+ <EditText
+ android:id="@+id/textOptions"
+ android:layout_width="match_parent"
+ android:layout_height="150dp"
+ android:layout_margin="5dp"
+ android:gravity="top"
+ android:hint="@string/cheatEditor_hint_optionData"
+ android:lines="8"
+ android:maxLines="10"
+ android:minLines="1"
+ android:singleLine="false"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:typeface="monospace" />
+ </LinearLayout>
+
+</ScrollView>
@@ -6,15 +6,29 @@
<LinearLayout
android:layout_width="fill_parent"
+ style="?android:attr/buttonBarStyle"
android:layout_height="wrap_content"
android:orientation="horizontal" >
- <ImageButton
+ <Button
android:id="@+id/imgBtnChtAdd"
- android:layout_width="50dp"
- android:layout_height="50dp"
+ style="?android:attr/buttonBarButtonStyle"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
android:contentDescription="@string/cheatEditor_add"
- android:src="@drawable/ic_plus" />
+ android:drawableLeft="@android:drawable/ic_menu_add"
+ android:drawableStart="@android:drawable/ic_menu_add"
+ android:text="@string/cheatEditor_add"/>
+
+ <Button
+ android:id="@+id/imgBtnChtAddAvanced"
+ style="?android:attr/buttonBarButtonStyle"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:contentDescription="@string/cheatEditor_add_advanced"
+ android:drawableLeft="@android:drawable/ic_menu_add"
+ android:drawableStart="@android:drawable/ic_menu_add"
+ android:text="@string/cheatEditor_add_advanced"/>
</LinearLayout>
<ListView
@@ -4,6 +4,9 @@
<item
android:id="@+id/menuItem_edit"
android:title="@string/cheatEditor_edit1"/>
+ <item
+ android:id="@+id/menuItem_advaned_edit"
+ android:title="@string/cheatEditor_edit2"/>
<item
android:id="@+id/menuItem_delete"
android:title="@string/cheatEditor_delete"/>
View
@@ -541,13 +541,17 @@
<string name="cheatEditor_info">Cheat information</string>
<string name="cheatEditor_saveConfirm">Save cheat file?</string>
<string name="cheatEditor_edit1">Edit cheat</string>
+ <string name="cheatEditor_edit2">Advanced edit cheat</string>
<string name="cheatEditor_invalid_value">N/A</string>
<string name="cheatEditor_delete">Delete cheat</string>
<string name="cheatEditor_add">Add cheat</string>
+ <string name="cheatEditor_add_advanced">Add advanced cheat</string>
<string name="cheatEditor_save">Save cheat</string>
<string name="cheatEditor_hint_cheatTitle">Cheat Title</string>
<string name="cheatEditor_hint_cheatNotes">Cheat Notes (optional)</string>
<string name="cheatEditor_hint_cheatAddress">Address</string>
+ <string name="cheatEditor_hint_cheatData">Enter cheat data</string>
+ <string name="cheatEditor_hint_optionData">Enter option data</string>
<string name="cheatEditor_hint_value">Value</string>
<string name="cheatEditor_hint_value_description">Description</string>
<string name="cheatEditor_add_option">Add option</string>
@@ -30,9 +30,9 @@
import paulscode.android.mupen64plusae.MenuListView;
import paulscode.android.mupen64plusae.cheat.CheatUtils.Cheat;
import paulscode.android.mupen64plusae.compat.AppCompatListActivity;
+import paulscode.android.mupen64plusae.dialog.EditCheatAdvancedDialog;
+import paulscode.android.mupen64plusae.dialog.EditCheatAdvancedDialog.OnAdvancedEditCompleteListener;
import paulscode.android.mupen64plusae.dialog.EditCheatDialog;
-import paulscode.android.mupen64plusae.dialog.EditCheatDialog.CheatAddressData;
-import paulscode.android.mupen64plusae.dialog.EditCheatDialog.CheatOptionData;
import paulscode.android.mupen64plusae.dialog.EditCheatDialog.OnEditCompleteListener;
import paulscode.android.mupen64plusae.dialog.MenuDialogFragment;
import paulscode.android.mupen64plusae.dialog.MenuDialogFragment.OnDialogMenuItemSelectedListener;
@@ -57,9 +57,21 @@
import android.widget.ListView;
import android.widget.TextView;
-public class CheatEditorActivity extends AppCompatListActivity implements View.OnClickListener, ExtractCheatListener,
- OnDialogMenuItemSelectedListener, OnEditCompleteListener
+public class CheatEditorActivity extends AppCompatListActivity implements ExtractCheatListener,
+ OnDialogMenuItemSelectedListener, OnEditCompleteListener, OnAdvancedEditCompleteListener
{
+
+ static public final class CheatOptionData
+ {
+ public String description;
+ public int value;
+ }
+
+ static public final class CheatAddressData
+ {
+ public long address;
+ public int value;
+ }
private static class CheatListAdapter extends ArrayAdapter<Cheat>
{
private static final int RESID = R.layout.list_item_two_text_icon;
@@ -126,7 +138,38 @@ protected void onCreate( Bundle savedInstanceState )
setContentView( R.layout.cheat_editor );
reload( mRomCrc, mRomCountryCode );
- findViewById( R.id.imgBtnChtAdd ).setOnClickListener( this );
+ findViewById( R.id.imgBtnChtAdd ).setOnClickListener( new View.OnClickListener()
+ {
+
+ @Override
+ public void onClick(View v)
+ {
+ //Add a cheat
+ mSelectedCheat = -1;
+ int stringId = R.string.cheatEditor_edit1;
+ EditCheatDialog editCheatDialogFragment = EditCheatDialog.newInstance(getString(stringId), null, null,
+ null, null, getCheatTitles());
+
+ FragmentManager fm = getSupportFragmentManager();
+ editCheatDialogFragment.show(fm, STATE_CHEAT_EDIT_DIALOG_FRAGMENT);
+ }
+ } );
+ findViewById( R.id.imgBtnChtAddAvanced ).setOnClickListener( new View.OnClickListener()
+ {
+
+ @Override
+ public void onClick(View v)
+ {
+ //Add a cheat
+ mSelectedCheat = -1;
+ int stringId = R.string.cheatEditor_edit2;
+ EditCheatAdvancedDialog editCheatDialogFragment = EditCheatAdvancedDialog.newInstance(getString(stringId), null, null,
+ null, null, getCheatTitles());
+
+ FragmentManager fm = getSupportFragmentManager();
+ editCheatDialogFragment.show(fm, STATE_CHEAT_EDIT_DIALOG_FRAGMENT);
+ }
+ } );
//default state is cancelled unless we save
setResult(RESULT_CANCELED, null);
@@ -201,7 +244,10 @@ public void onDialogMenuItemSelected( int dialogId, MenuItem item)
switch( item.getItemId() )
{
case R.id.menuItem_edit:
- CreateCheatEditorDialog();
+ CreateCheatEditorDialog(false);
+ break;
+ case R.id.menuItem_advaned_edit:
+ CreateCheatEditorDialog(true);
break;
case R.id.menuItem_delete:
promptDelete(mSelectedCheat);
@@ -211,7 +257,7 @@ public void onDialogMenuItemSelected( int dialogId, MenuItem item)
}
}
- private void CreateCheatEditorDialog()
+ private void CreateCheatEditorDialog(boolean advanced)
{
int stringId = R.string.cheatEditor_edit1;
final Cheat cheat = userCheats.get( mSelectedCheat );
@@ -237,12 +283,14 @@ private void CreateCheatEditorDialog()
if(!valueString.contains("?"))
{
addressData.value = Integer.valueOf(valueString, 16);
+ addressList.add(addressData);
}
else
{
+ //The cheat with the option goes at the front
addressData.value = -1;
+ addressList.add(0, addressData);
}
- addressList.add(addressData);
}
}
@@ -263,25 +311,24 @@ private void CreateCheatEditorDialog()
}
}
- EditCheatDialog editCheatDialogFragment =
- EditCheatDialog.newInstance(getString(stringId), cheat.name, cheat.desc,
- addressList, optionsList, getCheatTitles());
-
- FragmentManager fm = getSupportFragmentManager();
- editCheatDialogFragment.show(fm, STATE_CHEAT_EDIT_DIALOG_FRAGMENT);
- }
-
- @Override
- public void onClick(View v)
- {
- //Add a cheat
- mSelectedCheat = -1;
- int stringId = R.string.cheatEditor_edit1;
- EditCheatDialog editCheatDialogFragment = EditCheatDialog.newInstance(getString(stringId), null, null,
- null, null, getCheatTitles());
-
- FragmentManager fm = getSupportFragmentManager();
- editCheatDialogFragment.show(fm, STATE_CHEAT_EDIT_DIALOG_FRAGMENT);
+ if(advanced)
+ {
+ EditCheatAdvancedDialog editCheatDialogFragment =
+ EditCheatAdvancedDialog.newInstance(getString(stringId), cheat.name, cheat.desc,
+ addressList, optionsList, getCheatTitles());
+
+ FragmentManager fm = getSupportFragmentManager();
+ editCheatDialogFragment.show(fm, STATE_CHEAT_EDIT_DIALOG_FRAGMENT);
+ }
+ else
+ {
+ EditCheatDialog editCheatDialogFragment =
+ EditCheatDialog.newInstance(getString(stringId), cheat.name, cheat.desc,
+ addressList, optionsList, getCheatTitles());
+
+ FragmentManager fm = getSupportFragmentManager();
+ editCheatDialogFragment.show(fm, STATE_CHEAT_EDIT_DIALOG_FRAGMENT);
+ }
}
private List<String> getCheatTitles()
@@ -345,20 +392,20 @@ public void onEditComplete(int selectedButton, String name, String comment, List
cheat.desc = comment.replace( '\n', ' ' );
- //There are options present, ignore the first value in the first code
- int startIndex = 0;
String optionAddressString = new String();
- if(!options.isEmpty() && !address.isEmpty())
- {
- optionAddressString = String.format("%08X ????\n", address.get(0).address);
- ++startIndex;
- }
//Build the codes
StringBuilder builder = new StringBuilder();
- for(int index = startIndex; index < address.size(); ++index)
+ for(CheatAddressData data : address)
{
- builder.append(String.format("%08X %04X\n", address.get(index).address, address.get(index).value));
+ if(data.value != -1)
+ {
+ builder.append(String.format("%08X %04X\n", data.address, data.value));
+ }
+ else
+ {
+ optionAddressString = String.format("%08X ????\n", data.address);
+ }
}
cheat.code = builder.toString() + optionAddressString;
@@ -386,4 +433,11 @@ public void onEditComplete(int selectedButton, String name, String comment, List
}
}
}
+
+ @Override
+ public void onAdvancedEditComplete(int selectedButton, String name, String comment, List<CheatAddressData> address,
+ List<CheatOptionData> options)
+ {
+ onEditComplete(selectedButton, name, comment, address, options);
+ }
}
Oops, something went wrong.

0 comments on commit e25c14e

Please sign in to comment.