@@ -155,27 +155,102 @@ public boolean onOptionsItemSelected(MenuItem item)
155
155
}
156
156
return true ;
157
157
158
- case R .id .save_action :
158
+ case R .id .restart_action :
159
+ // Restart the core
160
+ pauseCore ();
161
+ restartCore ();
162
+ resumeCore ();
163
+ return true ;
164
+
165
+ case R .id .save_state_action :
166
+ // Create a confirmation dialog
167
+ AlertDialog .Builder builder = new AlertDialog .Builder (NooActivity .this );
168
+ builder .setTitle ("Save State" );
169
+ builder .setNegativeButton ("Cancel" , null );
170
+ builder .setPositiveButton ("OK" , new DialogInterface .OnClickListener ()
171
+ {
172
+ @ Override
173
+ public void onClick (DialogInterface dialog , int id )
174
+ {
175
+ // Save the state if confirmed
176
+ pauseCore ();
177
+ saveState ();
178
+ resumeCore ();
179
+ }
180
+ });
181
+
182
+ // Use the message with extra information if a state file doesn't exist yet
183
+ if (checkState () == 1 ) // File fail
184
+ builder .setMessage ("Saving and loading states is dangerous and can lead to data " +
185
+ "loss. States are also not guaranteed to be compatible across emulator " +
186
+ "versions. Please rely on in-game saving to keep your progress, and back up " +
187
+ ".sav files before using this feature. Do you want to save the current state?" );
188
+ else
189
+ builder .setMessage ("Do you want to overwrite the saved " +
190
+ "state with the current state? This can't be undone!" );
191
+ builder .create ().show ();
192
+ return true ;
193
+
194
+ case R .id .load_state_action :
195
+ // Create a confirmation dialog, or an error if something went wrong
196
+ AlertDialog .Builder builder2 = new AlertDialog .Builder (NooActivity .this );
197
+ builder2 .setTitle ("Load State" );
198
+ switch (checkState ())
199
+ {
200
+ case 0 : // Success
201
+ builder2 .setMessage ("Do you want to load the saved state " +
202
+ "and lose the current state? This can't be undone!" );
203
+ builder2 .setNegativeButton ("Cancel" , null );
204
+ builder2 .setPositiveButton ("OK" , new DialogInterface .OnClickListener ()
205
+ {
206
+ @ Override
207
+ public void onClick (DialogInterface dialog , int id )
208
+ {
209
+ // Load the state if confirmed
210
+ pauseCore ();
211
+ loadState ();
212
+ resumeCore ();
213
+ }
214
+ });
215
+ break ;
216
+
217
+ case 1 : // File fail
218
+ builder2 .setMessage ("The state file doesn't exist or couldn't be opened." );
219
+ builder2 .setNegativeButton ("OK" , null );
220
+ break ;
221
+
222
+ case 2 : // Format fail
223
+ builder2 .setMessage ("The state file doesn't have a valid format." );
224
+ builder2 .setNegativeButton ("OK" , null );
225
+ break ;
226
+
227
+ case 3 : // Version fail
228
+ builder2 .setMessage ("The state file isn't compatible with this version of NooDS." );
229
+ builder2 .setPositiveButton ("OK" , null );
230
+ break ;
231
+ }
232
+ builder2 .create ().show ();
233
+ return true ;
234
+
235
+ case R .id .save_type_action :
159
236
final boolean gba = isGbaMode ();
160
237
final String [] names = getResources ().getStringArray (gba ? R .array .save_entries_gba : R .array .save_entries_nds );
161
238
final int [] values = getResources ().getIntArray (gba ? R .array .save_values_gba : R .array .save_values_nds );
162
239
163
240
// Create the save type dialog
164
- AlertDialog .Builder builder = new AlertDialog .Builder (this );
165
- builder .setTitle ("Change Save Type" );
166
-
167
- builder .setItems (names , new DialogInterface .OnClickListener ()
241
+ AlertDialog .Builder builder3 = new AlertDialog .Builder (this );
242
+ builder3 .setTitle ("Change Save Type" );
243
+ builder3 .setItems (names , new DialogInterface .OnClickListener ()
168
244
{
169
245
@ Override
170
246
public void onClick (DialogInterface dialog , final int which )
171
247
{
172
248
// Confirm the change because accidentally resizing a working save file could be bad!
173
- AlertDialog .Builder builder2 = new AlertDialog .Builder (NooActivity .this );
174
- builder2 .setTitle ("Changing Save Type" );
175
- builder2 .setMessage ("Are you sure? This may result in data loss!" );
176
- builder2 .setNegativeButton ("Cancel" , null );
177
-
178
- builder2 .setPositiveButton ("OK" , new DialogInterface .OnClickListener ()
249
+ AlertDialog .Builder builder4 = new AlertDialog .Builder (NooActivity .this );
250
+ builder4 .setTitle ("Changing Save Type" );
251
+ builder4 .setMessage ("Are you sure? This may result in data loss!" );
252
+ builder4 .setNegativeButton ("Cancel" , null );
253
+ builder4 .setPositiveButton ("OK" , new DialogInterface .OnClickListener ()
179
254
{
180
255
@ Override
181
256
public void onClick (DialogInterface dialog , int id )
@@ -190,19 +265,10 @@ public void onClick(DialogInterface dialog, int id)
190
265
resumeCore ();
191
266
}
192
267
});
193
-
194
- builder2 .create ().show ();
268
+ builder4 .create ().show ();
195
269
}
196
270
});
197
-
198
- builder .create ().show ();
199
- return true ;
200
-
201
- case R .id .restart_action :
202
- // Restart the core
203
- pauseCore ();
204
- restartCore ();
205
- resumeCore ();
271
+ builder3 .create ().show ();
206
272
return true ;
207
273
208
274
case R .id .bindings_action :
@@ -472,6 +538,9 @@ else if (showingFps)
472
538
public static native void runFrame ();
473
539
public static native void writeSave ();
474
540
public static native void restartCore ();
541
+ public static native int checkState ();
542
+ public static native boolean saveState ();
543
+ public static native boolean loadState ();
475
544
public static native void pressScreen (int x , int y );
476
545
public static native void releaseScreen ();
477
546
public static native void resizeGbaSave (int size );
0 commit comments