From e68904da2ee403030e454bad73cd8dcfe6d3715c Mon Sep 17 00:00:00 2001 From: "SND\\MaddTheSane_cp" Date: Sun, 3 Mar 2013 00:39:53 +0000 Subject: Apply patch 13980, with fixes to get it working properly. This allows a cheat interface for OS X. git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@83306 e17a0e51-4ae3-4d35-97c3-1a29b211df97 --- macosx/CheatController.m | 91 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 macosx/CheatController.m (limited to 'macosx/CheatController.m') diff --git a/macosx/CheatController.m b/macosx/CheatController.m new file mode 100644 index 00000000..81fe9544 --- /dev/null +++ b/macosx/CheatController.m @@ -0,0 +1,91 @@ +// +// CheatController.m +// Pcsxr +// + +#import +#include "psxcommon.h" +#include "cheat.h" +#import "CheatController.h" +#import "ARCBridge.h" + +@implementation CheatController + +- (id)init +{ + self = [self initWithWindowNibName:@"CheatWindow"]; + return self; +} + +- (void)refresh +{ + [cheatView reloadData]; +} + +- (NSInteger)numberOfRowsInTableView:(NSTableView *)view +{ + return NumCheats; +} + +- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)col row:(NSInteger)idx +{ + if (idx >= NumCheats) + return nil; + NSString *ident = [col identifier]; + if ([ident isEqualToString:@"COL_NAME"]) { + return [NSString stringWithCString:Cheats[idx].Descr encoding:NSUTF8StringEncoding]; + } + if ([ident isEqualToString:@"COL_ENABLE"]) { + return [NSNumber numberWithInt: Cheats[idx].Enabled ? NSOnState : NSOffState]; + } + NSLog(@"Unknown column identifier: %@", ident); + return nil; +} + +- (void)tableView:(NSTableView *)tableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)col row:(NSInteger)row +{ + if (row >= NumCheats) + return; + NSString *ident = [col identifier]; + if ([ident isEqualToString:@"COL_ENABLE"]) { + Cheats[row].Enabled = [object integerValue] == NSOnState; + } +} + +- (IBAction)LoadCheats:(id)sender +{ + NSOpenPanel *openDlg = RETAINOBJ([NSOpenPanel openPanel]); + [openDlg setCanChooseFiles:YES]; + [openDlg setCanChooseDirectories:NO]; + + if ([openDlg runModal] == NSFileHandlingPanelOKButton) { + NSArray *files = [openDlg URLs]; + LoadCheats((const char *)[[[files objectAtIndex:0] path] fileSystemRepresentation]); + [self refresh]; + } + RELEASEOBJ(openDlg); +} + +- (IBAction)SaveCheats:(id)sender +{ + NSSavePanel *saveDlg = RETAINOBJ([NSSavePanel savePanel]); + [saveDlg setPrompt:NSLocalizedString(@"Save Cheats", nil)]; + if ([saveDlg runModal] == NSFileHandlingPanelOKButton) { + NSURL *url = [saveDlg URL]; + SaveCheats((const char *)[[url path] fileSystemRepresentation]); + } + RELEASEOBJ(saveDlg); +} + +- (IBAction)clear:(id)sender +{ + ClearAllCheats(); + [self refresh]; +} + +- (IBAction)close:(id)sender +{ + [[self window] close]; +} + +@end -- cgit v1.2.3