mirror of
https://github.com/ogoguel/activegs-ios.git
synced 2024-12-27 17:29:42 +00:00
added save states controls to options menu; support for saving and restoring states on a game-by-game basis
This commit is contained in:
parent
44cad3ea15
commit
1d420f51e7
@ -19,6 +19,8 @@
|
|||||||
#import <ExternalAccessory/ExternalAccessory.h>
|
#import <ExternalAccessory/ExternalAccessory.h>
|
||||||
#include "../kegs/src/paddles.h"
|
#include "../kegs/src/paddles.h"
|
||||||
#import "../kegs/iOS/emulatorView.h"
|
#import "../kegs/iOS/emulatorView.h"
|
||||||
|
#include "../kegs/src/SaveState.h"
|
||||||
|
#include "../common/activedownload.h"
|
||||||
|
|
||||||
#ifdef ACTIVEGS_CUSTOMKEYS
|
#ifdef ACTIVEGS_CUSTOMKEYS
|
||||||
#include "UICustomKey.h"
|
#include "UICustomKey.h"
|
||||||
@ -273,6 +275,11 @@ int isHardwareKeyboard()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@interface KBDController() {
|
||||||
|
UISegmentedControl *saveStateSegmentedControl;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
@implementation KBDController
|
@implementation KBDController
|
||||||
|
|
||||||
@synthesize textField = _textField;
|
@synthesize textField = _textField;
|
||||||
@ -878,6 +885,40 @@ extern int x_frame_rate ;
|
|||||||
printf("control not found\n");
|
printf("control not found\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-(void) saveStateButtonPressed:(id)sender {
|
||||||
|
MyString dir = CDownload::getPersistentPath();
|
||||||
|
dir = dir + ACTIVEGS_DIRECTORY_SEPARATOR + "savestates" + ACTIVEGS_DIRECTORY_SEPARATOR + config.name;
|
||||||
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||||
|
NSError *error;
|
||||||
|
[fileManager createDirectoryAtPath:[NSString stringWithCString:dir.c_str() encoding:NSUTF8StringEncoding] withIntermediateDirectories:YES attributes:nil error:&error];
|
||||||
|
dir += ACTIVEGS_DIRECTORY_SEPARATOR;
|
||||||
|
NSString *segIndex = [saveStateSegmentedControl titleForSegmentAtIndex:[saveStateSegmentedControl selectedSegmentIndex]];
|
||||||
|
dir += "save";
|
||||||
|
dir += [segIndex UTF8String];
|
||||||
|
g_savestate.saveState(dir.c_str());
|
||||||
|
[pManager setNotificationText:[NSString stringWithFormat:@"Saved State #%@",segIndex]];
|
||||||
|
}
|
||||||
|
|
||||||
|
-(void) loadStateButtonPressed:(id)sender {
|
||||||
|
NSString *segIndex = [saveStateSegmentedControl titleForSegmentAtIndex:[saveStateSegmentedControl selectedSegmentIndex]];
|
||||||
|
MyString dir = CDownload::getPersistentPath();
|
||||||
|
dir += ACTIVEGS_DIRECTORY_SEPARATOR;
|
||||||
|
dir += "savestates";
|
||||||
|
dir += ACTIVEGS_DIRECTORY_SEPARATOR;
|
||||||
|
dir += config.name;
|
||||||
|
dir += ACTIVEGS_DIRECTORY_SEPARATOR;
|
||||||
|
dir += "save";
|
||||||
|
dir += [segIndex UTF8String];
|
||||||
|
FILE *fHandle = fopen(dir.c_str(),"r");
|
||||||
|
if ( fHandle == NULL ) {
|
||||||
|
[pManager setNotificationText:[NSString stringWithFormat:@"State #%@ Does Not Exist",segIndex]];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
g_savestate.restoreState(dir.c_str());
|
||||||
|
[pManager setNotificationText:[NSString stringWithFormat:@"Loaded State #%@",segIndex]];
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
-(void)addRuntimeControls
|
-(void)addRuntimeControls
|
||||||
{
|
{
|
||||||
@ -904,7 +945,7 @@ extern int x_frame_rate ;
|
|||||||
|
|
||||||
UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(OPTIONMARGIN,l,OPTIONWIDTH,LINEHEIGHT)];
|
UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(OPTIONMARGIN,l,OPTIONWIDTH,LINEHEIGHT)];
|
||||||
label.text = [NSString stringWithUTF8String:runtimeControlDefs[i].name];
|
label.text = [NSString stringWithUTF8String:runtimeControlDefs[i].name];
|
||||||
label.textAlignment = UITextAlignmentCenter;
|
label.textAlignment = NSTextAlignmentCenter;
|
||||||
label.font = [UIFont systemFontOfSize:12*res];
|
label.font = [UIFont systemFontOfSize:12*res];
|
||||||
label.backgroundColor = [UIColor clearColor];
|
label.backgroundColor = [UIColor clearColor];
|
||||||
[self.runtimeControlsOptions addSubview:label];
|
[self.runtimeControlsOptions addSubview:label];
|
||||||
@ -934,6 +975,51 @@ extern int x_frame_rate ;
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// hack in some save state controls
|
||||||
|
l += 2.0;
|
||||||
|
UILabel* saveStatelabel = [[UILabel alloc] initWithFrame:CGRectMake(OPTIONMARGIN,l,OPTIONWIDTH,LINEHEIGHT)];
|
||||||
|
saveStatelabel.text = @"Save States";
|
||||||
|
saveStatelabel.textAlignment = NSTextAlignmentCenter;
|
||||||
|
saveStatelabel.font = [UIFont systemFontOfSize:12*res];
|
||||||
|
saveStatelabel.backgroundColor = [UIColor clearColor];
|
||||||
|
[self.runtimeControlsOptions addSubview:saveStatelabel];
|
||||||
|
l += LINEHEIGHT;
|
||||||
|
|
||||||
|
saveStateSegmentedControl = [[UISegmentedControl alloc] initWithFrame:CGRectMake(OPTIONMARGIN, l, OPTIONWIDTH, LINEHEIGHT)];
|
||||||
|
for (int segIndex = 0; segIndex < 6; segIndex++) {
|
||||||
|
[saveStateSegmentedControl insertSegmentWithTitle:[NSString stringWithFormat:@"%d",segIndex] atIndex:segIndex animated:NO];
|
||||||
|
}
|
||||||
|
[saveStateSegmentedControl setSelectedSegmentIndex:0];
|
||||||
|
[self.runtimeControlsOptions addSubview:saveStateSegmentedControl];
|
||||||
|
|
||||||
|
l += LINEHEIGHT;
|
||||||
|
l += 2.0;
|
||||||
|
|
||||||
|
UIButton *saveStateButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||||
|
saveStateButton.frame = CGRectMake(OPTIONMARGIN,l,OPTIONWIDTH * 0.4,LINEHEIGHT);
|
||||||
|
[saveStateButton setTitle:@"Save" forState:UIControlStateNormal];
|
||||||
|
saveStateButton.titleLabel.font = [UIFont systemFontOfSize:12*res];
|
||||||
|
[saveStateButton setTitleColor:self.view.tintColor forState:UIControlStateNormal];
|
||||||
|
saveStateButton.backgroundColor = [UIColor clearColor];
|
||||||
|
saveStateButton.layer.borderWidth = 1.0f;
|
||||||
|
saveStateButton.layer.borderColor = [self.view.tintColor CGColor];
|
||||||
|
[saveStateButton addTarget:self action:@selector(saveStateButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
|
||||||
|
[self.runtimeControlsOptions addSubview:saveStateButton];
|
||||||
|
|
||||||
|
UIButton *loadStateButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||||
|
loadStateButton.frame = CGRectMake((OPTIONWIDTH + OPTIONMARGIN) - (OPTIONWIDTH * 0.4),l,OPTIONWIDTH * 0.4,LINEHEIGHT);
|
||||||
|
[loadStateButton setTitle:@"Load" forState:UIControlStateNormal];
|
||||||
|
loadStateButton.titleLabel.font = [UIFont systemFontOfSize:12*res];
|
||||||
|
loadStateButton.backgroundColor = [UIColor clearColor];
|
||||||
|
[loadStateButton setTitleColor:self.view.tintColor forState:UIControlStateNormal];
|
||||||
|
loadStateButton.layer.borderWidth = 1.0f;
|
||||||
|
loadStateButton.layer.borderColor = [self.view.tintColor CGColor];
|
||||||
|
[loadStateButton addTarget:self action:@selector(loadStateButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
|
||||||
|
[self.runtimeControlsOptions addSubview:loadStateButton];
|
||||||
|
|
||||||
|
l+=LINEHEIGHT;
|
||||||
|
nbs++;
|
||||||
|
|
||||||
float w = OPTIONWIDTH+OPTIONMARGIN*2;
|
float w = OPTIONWIDTH+OPTIONMARGIN*2;
|
||||||
|
|
||||||
// resize la vue correctement
|
// resize la vue correctement
|
||||||
@ -1034,9 +1120,6 @@ extern int x_frame_rate ;
|
|||||||
-(void)addDiskSelection
|
-(void)addDiskSelection
|
||||||
{
|
{
|
||||||
|
|
||||||
self.diskSelectionOptions;
|
|
||||||
self.diskSelection;
|
|
||||||
|
|
||||||
self.diskSelectionOptions = nil;
|
self.diskSelectionOptions = nil;
|
||||||
self.diskSelection = nil;
|
self.diskSelection = nil;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user