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
This commit is contained in:
SND\MaddTheSane_cp 2013-08-16 00:20:10 +00:00
parent c69572dc23
commit 30195666f4
3 changed files with 1749 additions and 152 deletions

View File

@ -5,15 +5,28 @@
#import <Cocoa/Cocoa.h>
@interface CheatController : NSWindowController <NSWindowDelegate>
@interface CheatController : NSWindowController <NSWindowDelegate, NSTableViewDataSource, NSTableViewDelegate>
{
IBOutlet NSTableView *cheatView;
IBOutlet NSWindow *editCheatWindow;
IBOutlet NSTableView *editCheatView;
IBOutlet NSNumberFormatter *addressFormatter;
IBOutlet NSNumberFormatter *valueFormatter;
NSMutableArray *tempCheatCodes;
}
@property (readwrite, retain) NSMutableArray *tempCheatCodes;
- (void)refresh;
-(IBAction)SaveCheats:(id)sender;
-(IBAction)LoadCheats:(id)sender;
-(IBAction)clear:(id)sender;
-(IBAction)close:(id)sender;
- (IBAction)saveCheats:(id)sender;
- (IBAction)loadCheats:(id)sender;
- (IBAction)clear:(id)sender;
- (IBAction)editCheat:(id)sender;
- (IBAction)addCheat:(id)sender;
- (IBAction)closeCheatEdit:(id)sender;
- (IBAction)removeCheatValue:(id)sender;
- (IBAction)addCheatValue:(id)sender;
@end

View File

@ -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
{
[self close];
[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
{
AddCheat(NULL, "0 0");
}
@end

File diff suppressed because it is too large Load Diff