diff options
| author | SND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97> | 2013-08-16 00:20:10 +0000 |
|---|---|---|
| committer | SND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97> | 2013-08-16 00:20:10 +0000 |
| commit | 30195666f40ca64b0bdf34ed783215d27f000cd7 (patch) | |
| tree | 0122eaa03f575d2117f380b481c9df58907d60a0 /macosx/CheatController.m | |
| parent | c69572dc23f70fcf72d5ed49729de8f6d4abed0a (diff) | |
| download | pcsxr-30195666f40ca64b0bdf34ed783215d27f000cd7.tar.gz | |
Some work on the cheat window on OS X. Note that the changes are disabled by default.
git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@86679 e17a0e51-4ae3-4d35-97c3-1a29b211df97
Diffstat (limited to 'macosx/CheatController.m')
| -rw-r--r-- | macosx/CheatController.m | 165 |
1 files changed, 143 insertions, 22 deletions
diff --git a/macosx/CheatController.m b/macosx/CheatController.m index db13d5dc..17bbab9e 100644 --- a/macosx/CheatController.m +++ b/macosx/CheatController.m @@ -10,13 +10,66 @@ #import "ARCBridge.h" #import "PcsxrCheatHandler.h" +#define kTempCheatCodesName @"tempCheatCodes" +@interface PcsxrCheatTempObject : NSObject +{ + uint32_t address; + uint16_t value; +} +@property (readwrite) uint32_t address; +@property (readwrite) uint16_t value; + +- (id)initWithAddress:(uint32_t)add value:(uint16_t)val; +@end + +@implementation PcsxrCheatTempObject +@synthesize address, value; + +- (id)initWithAddress:(uint32_t)add value:(uint16_t)val +{ + if (self = [super init]) { + self.address = add; + self.value = val; + } + return self; +} + +- (id)initWithCheatCode:(CheatCode *)theCheat +{ + return [self initWithAddress:theCheat->Addr value:theCheat->Val]; +} + +- (NSString*)description +{ + return [NSString stringWithFormat:@"%u %u", address, value]; +} + +@end + @implementation CheatController +@synthesize tempCheatCodes; - (id)init { return self = [self initWithWindowNibName:@"CheatWindow"]; } +- (id)initWithCoder:(NSCoder *)aDecoder +{ + if (self = [super initWithCoder:aDecoder]) { + self.tempCheatCodes = AUTORELEASEOBJ([[NSMutableArray alloc] init]); + } + return self; +} + +- (id)initWithWindow:(NSWindow *)window +{ + if (self = [super initWithWindow:window]) { + self.tempCheatCodes = AUTORELEASEOBJ([[NSMutableArray alloc] init]); + } + return self; +} + - (void)refresh { [cheatView reloadData]; @@ -24,37 +77,53 @@ - (NSInteger)numberOfRowsInTableView:(NSTableView *)view { - return NumCheats; + if (view == cheatView) { + return NumCheats; + } else + return 0; } - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)col row:(NSInteger)idx { - if (idx >= NumCheats) + if (tableView == cheatView) { + if (idx >= NumCheats) + return nil; + NSString *ident = [col identifier]; + if ([ident isEqualToString:@"COL_NAME"]) { + return @(Cheats[idx].Descr); + } else if ([ident isEqualToString:@"COL_ENABLE"]) { + return @( Cheats[idx].Enabled ? NSOnState : NSOffState); + } + NSLog(@"Unknown column identifier: %@", ident); + return nil; + } else return nil; - NSString *ident = [col identifier]; - if ([ident isEqualToString:@"COL_NAME"]) { - return @(Cheats[idx].Descr); - } else if ([ident isEqualToString:@"COL_ENABLE"]) { - return @( Cheats[idx].Enabled ? NSOnState : NSOffState); - } - NSLog(@"Unknown column identifier: %@", ident); - return nil; } +#if 0 +- (void)awakeFromNib +{ + [addressFormatter setPositivePrefix:@"0x"]; + [valueFormatter setPositivePrefix:@"0x"]; +} +#endif + - (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; - } else if ([ident isEqualToString:@"COL_NAME"]) { - free(Cheats[row].Descr); - Cheats[row].Descr = strdup([object UTF8String]); + if (tableView == cheatView) { + if (row >= NumCheats) + return; + NSString *ident = [col identifier]; + if ([ident isEqualToString:@"COL_ENABLE"]) { + Cheats[row].Enabled = [object integerValue] == NSOnState; + } else if ([ident isEqualToString:@"COL_NAME"]) { + free(Cheats[row].Descr); + Cheats[row].Descr = strdup([object UTF8String]); + } } } -- (IBAction)LoadCheats:(id)sender +- (IBAction)loadCheats:(id)sender { NSOpenPanel *openDlg = RETAINOBJ([NSOpenPanel openPanel]); [openDlg setCanChooseFiles:YES]; @@ -70,7 +139,7 @@ RELEASEOBJ(openDlg); } -- (IBAction)SaveCheats:(id)sender +- (IBAction)saveCheats:(id)sender { NSSavePanel *saveDlg = RETAINOBJ([NSSavePanel savePanel]); [saveDlg setAllowedFileTypes:[PcsxrCheatHandler supportedUTIs]]; @@ -90,9 +159,61 @@ [self refresh]; } -- (IBAction)close:(id)sender +- (IBAction)closeCheatEdit:(id)sender +{ + [NSApp endSheet:editCheatWindow returnCode:[sender tag] == 1 ? NSCancelButton : NSOKButton]; +} + +- (IBAction)removeCheatValue:(id)sender +{ + NSIndexSet *toRemoveIndex = [editCheatView selectedRowIndexes]; + [self willChange:NSKeyValueChangeRemoval valuesAtIndexes:toRemoveIndex forKey:kTempCheatCodesName]; + [tempCheatCodes removeObjectsAtIndexes:toRemoveIndex]; + [self didChange:NSKeyValueChangeRemoval valuesAtIndexes:toRemoveIndex forKey:kTempCheatCodesName]; +} + +- (IBAction)addCheatValue:(id)sender +{ + [self willChange:NSKeyValueChangeInsertion valuesAtIndexes:[NSIndexSet indexSetWithIndex:[tempCheatCodes count]] forKey:kTempCheatCodesName]; + [tempCheatCodes addObject:AUTORELEASEOBJ([[PcsxrCheatTempObject alloc] init])]; + [self didChange:NSKeyValueChangeInsertion valuesAtIndexes:[NSIndexSet indexSetWithIndex:[tempCheatCodes count]] forKey:kTempCheatCodesName]; +} + +- (void)editCheatCodeSheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo +{ + if (returnCode == NSOKButton) { + //FIXME: Expand the current cheat code list as needed + //FIXME: Contract the current cheat code list as needed + + const char *tmpCheat = [[tempCheatCodes componentsJoinedByString:@"\n"] cStringUsingEncoding:NSASCIIStringEncoding]; + char *cheatCpy = strdup(tmpCheat); + EditCheat((int)[cheatView selectedRow], Cheats[[cheatView selectedRow]].Descr, cheatCpy); + free(cheatCpy); + } + + [sheet orderOut:nil]; +} + +- (IBAction)editCheat:(id)sender +{ + [self willChangeValueForKey:kTempCheatCodesName]; + [tempCheatCodes removeAllObjects]; + + Cheat *currentCheat = &Cheats[[cheatView selectedRow]]; + + for (NSInteger i = 0; i < currentCheat->n; i++) { + CheatCode *curCode = &CheatCodes[currentCheat->First + i]; + PcsxrCheatTempObject *tmpobj = [[PcsxrCheatTempObject alloc] initWithCheatCode:curCode]; + [tempCheatCodes addObject:tmpobj]; + RELEASEOBJ(tmpobj); + } + [self didChangeValueForKey:kTempCheatCodesName]; + [NSApp beginSheet:editCheatWindow modalForWindow:[self window] modalDelegate:self didEndSelector:@selector(editCheatCodeSheetDidEnd:returnCode:contextInfo:) contextInfo:NULL]; +} + +- (IBAction)addCheat:(id)sender { - [self close]; + AddCheat(NULL, "0 0"); } @end |
