From 0cccfddd34db5dd8239b5cc8a21f328fd4c4bc5d Mon Sep 17 00:00:00 2001 From: preble Date: Tue, 14 Dec 2010 22:17:38 -0500 Subject: [PATCH] Streamlined keyboard item-adding. --- Classes/IJInventoryWindowController.h | 1 + Classes/IJInventoryWindowController.m | 70 +++++++++++++++++++++++++++ Classes/IJTableView.h | 16 ++++++ Classes/IJTableView.m | 25 ++++++++++ English.lproj/MainMenu.xib | 36 +++++++++++--- InsideJob.xcodeproj/project.pbxproj | 8 +++ README.markdown | 4 ++ 7 files changed, 153 insertions(+), 7 deletions(-) create mode 100644 Classes/IJTableView.h create mode 100644 Classes/IJTableView.m diff --git a/Classes/IJInventoryWindowController.h b/Classes/IJInventoryWindowController.h index 3dcbea4..fdb76d2 100644 --- a/Classes/IJInventoryWindowController.h +++ b/Classes/IJInventoryWindowController.h @@ -61,5 +61,6 @@ - (IBAction)worldSelectionChanged:(id)sender; - (IBAction)updateItemSearchFilter:(id)sender; - (IBAction)makeSearchFieldFirstResponder:(id)sender; +- (IBAction)itemTableViewDoubleClicked:(id)sender; @end diff --git a/Classes/IJInventoryWindowController.m b/Classes/IJInventoryWindowController.m index 2d22499..94ab68c 100644 --- a/Classes/IJInventoryWindowController.m +++ b/Classes/IJInventoryWindowController.m @@ -45,6 +45,9 @@ keys = [keys sortedArrayUsingSelector:@selector(compare:)]; allItemIds = [[NSArray alloc] initWithArray:keys]; filteredItemIds = [allItemIds retain]; + + [itemTableView setTarget:self]; + [itemTableView setDoubleAction:@selector(itemTableViewDoubleClicked:)]; } - (void)dealloc @@ -323,6 +326,18 @@ #pragma mark - #pragma mark IJInventoryViewDelegate +- (IJInventoryView *)inventoryViewForItemArray:(NSMutableArray *)theItemArray +{ + if (theItemArray == normalInventory) + return inventoryView; + if (theItemArray == quickInventory) + return quickView; + if (theItemArray == armorInventory) + return armorView; + + return nil; +} + - (NSMutableArray *)itemArrayForInventoryView:(IJInventoryView *)theInventoryView slotOffset:(int*)slotOffset { if (theInventoryView == inventoryView) @@ -509,6 +524,42 @@ return YES; } +- (NSMutableArray *)inventoryArrayWithEmptySlot:(NSUInteger *)slot +{ + for (NSMutableArray *inventoryArray in [NSArray arrayWithObjects:quickInventory, normalInventory, nil]) + { + __block BOOL found = NO; + [inventoryArray enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) { + IJInventoryItem *item = obj; + if (item.count == 0) + { + *slot = index; + *stop = YES; + found = YES; + } + }]; + if (found) + return inventoryArray; + } + return nil; +} + +- (IBAction)itemTableViewDoubleClicked:(id)sender +{ + NSUInteger slot; + NSMutableArray *inventoryArray = [self inventoryArrayWithEmptySlot:&slot]; + if (!inventoryArray) + return; + + IJInventoryItem *item = [inventoryArray objectAtIndex:slot]; + item.itemId = [[filteredItemIds objectAtIndex:[itemTableView selectedRow]] shortValue]; + item.count = 1; + [self markDirty]; + + IJInventoryView *invView = [self inventoryViewForItemArray:inventoryArray]; + [invView reloadItemAtIndex:slot]; + [self inventoryView:invView selectedItemAtIndex:slot]; +} #pragma mark - #pragma mark NSWindowDelegate @@ -547,4 +598,23 @@ [NSApp terminate:nil]; } + +#pragma mark - +#pragma mark NSControlTextEditingDelegate + +- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)command +{ + if (command == @selector(moveDown:)) + { + if ([itemTableView numberOfRows] > 0) + { + [self.window makeFirstResponder:itemTableView]; + [itemTableView selectRowIndexes:[NSIndexSet indexSetWithIndex:0] byExtendingSelection:NO]; + } + return YES; + } + return YES; +} + + @end diff --git a/Classes/IJTableView.h b/Classes/IJTableView.h new file mode 100644 index 0000000..75b67a4 --- /dev/null +++ b/Classes/IJTableView.h @@ -0,0 +1,16 @@ +// +// IJTableView.h +// InsideJob +// +// Created by Adam Preble on 12/14/10. +// Copyright 2010 Adam Preble. All rights reserved. +// + +#import + + +@interface IJTableView : NSTableView { + +} + +@end diff --git a/Classes/IJTableView.m b/Classes/IJTableView.m new file mode 100644 index 0000000..a35d041 --- /dev/null +++ b/Classes/IJTableView.m @@ -0,0 +1,25 @@ +// +// IJTableView.m +// InsideJob +// +// Created by Adam Preble on 12/14/10. +// Copyright 2010 Adam Preble. All rights reserved. +// + +#import "IJTableView.h" + + +@implementation IJTableView + +- (void)keyDown:(NSEvent *)theEvent +{ + unichar ch = [[theEvent characters] characterAtIndex:0]; + if (ch == '\r') // return key + { + [self sendAction:[self doubleAction] to:[self target]]; + return; + } + [super keyDown:theEvent]; +} + +@end diff --git a/English.lproj/MainMenu.xib b/English.lproj/MainMenu.xib index cdca301..8ee7afa 100644 --- a/English.lproj/MainMenu.xib +++ b/English.lproj/MainMenu.xib @@ -924,7 +924,6 @@ 3 YES - YES @@ -956,7 +955,6 @@ 3 YES - YES @@ -983,7 +981,6 @@ 3 YES - YES @@ -1419,6 +1416,14 @@ 684 + + + delegate + + + + 685 + @@ -2154,6 +2159,7 @@ 649.IBViewBoundsToFrameTransform 650.IBPluginDependency 651.IBPluginDependency + 652.CustomClassName 652.IBPluginDependency 654.IBPluginDependency 655.IBPluginDependency @@ -2330,6 +2336,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + IJTableView com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -2377,7 +2384,7 @@ - 684 + 685 @@ -2398,7 +2405,7 @@ IBProjectSource - IJInventoryView.h + Classes/IJInventoryView.h @@ -2408,6 +2415,7 @@ YES YES + itemTableViewDoubleClicked: makeSearchFieldFirstResponder: menuSelectWorld: updateItemSearchFilter: @@ -2419,12 +2427,14 @@ id id id + id YES YES + itemTableViewDoubleClicked: makeSearchFieldFirstResponder: menuSelectWorld: updateItemSearchFilter: @@ -2432,6 +2442,10 @@ YES + + itemTableViewDoubleClicked: + id + makeSearchFieldFirstResponder: id @@ -2526,7 +2540,15 @@ IBProjectSource - IJInventoryWindowController.h + Classes/IJInventoryWindowController.h + + + + IJTableView + NSTableView + + IBProjectSource + Classes/IJTableView.h @@ -2545,7 +2567,7 @@ IBProjectSource - InsideJobAppDelegate.h + Classes/InsideJobAppDelegate.h diff --git a/InsideJob.xcodeproj/project.pbxproj b/InsideJob.xcodeproj/project.pbxproj index 24e10a7..6e3810c 100644 --- a/InsideJob.xcodeproj/project.pbxproj +++ b/InsideJob.xcodeproj/project.pbxproj @@ -16,6 +16,7 @@ 668B27B2125D8F8E0060BF71 /* IJInventoryItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 668B27B1125D8F8E0060BF71 /* IJInventoryItem.m */; }; 668B27F2125D963F0060BF71 /* IJInventoryWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 668B27F1125D963F0060BF71 /* IJInventoryWindowController.m */; }; 668B290F125E40560060BF71 /* Items.csv in Resources */ = {isa = PBXBuildFile; fileRef = 668B28D8125E370A0060BF71 /* Items.csv */; }; + 6697AD7212B86762001890C6 /* IJTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 6697AD7112B86762001890C6 /* IJTableView.m */; }; 66BC00031260215C005A23F4 /* IJInventoryView.m in Sources */ = {isa = PBXBuildFile; fileRef = 66BC00021260215C005A23F4 /* IJInventoryView.m */; }; 66BC000E12602359005A23F4 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 66BC000D12602359005A23F4 /* QuartzCore.framework */; }; 66BC033B1260CC59005A23F4 /* MAAttachedWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 66BC033A1260CC59005A23F4 /* MAAttachedWindow.m */; }; @@ -53,6 +54,9 @@ 668B27F0125D963F0060BF71 /* IJInventoryWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IJInventoryWindowController.h; sourceTree = ""; }; 668B27F1125D963F0060BF71 /* IJInventoryWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IJInventoryWindowController.m; sourceTree = ""; }; 668B28D8125E370A0060BF71 /* Items.csv */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Items.csv; sourceTree = ""; }; + 6697AD7012B86762001890C6 /* IJTableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IJTableView.h; sourceTree = ""; }; + 6697AD7112B86762001890C6 /* IJTableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IJTableView.m; sourceTree = ""; }; + 6697ADA812B86A07001890C6 /* README.markdown */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README.markdown; sourceTree = ""; wrapsLines = 1; }; 66BC00011260215C005A23F4 /* IJInventoryView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IJInventoryView.h; sourceTree = ""; }; 66BC00021260215C005A23F4 /* IJInventoryView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IJInventoryView.m; sourceTree = ""; }; 66BC000D12602359005A23F4 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; @@ -128,6 +132,7 @@ 29B97314FDCFA39411CA2CEA /* InsideJob */ = { isa = PBXGroup; children = ( + 6697ADA812B86A07001890C6 /* README.markdown */, 080E96DDFE201D6D7F000001 /* Classes */, 29B97315FDCFA39411CA2CEA /* Other Sources */, 29B97317FDCFA39411CA2CEA /* Resources */, @@ -211,6 +216,8 @@ children = ( 66BC03391260CC59005A23F4 /* MAAttachedWindow.h */, 66BC033A1260CC59005A23F4 /* MAAttachedWindow.m */, + 6697AD7012B86762001890C6 /* IJTableView.h */, + 6697AD7112B86762001890C6 /* IJTableView.m */, ); name = "Views & Windows"; sourceTree = ""; @@ -305,6 +312,7 @@ 66BC033B1260CC59005A23F4 /* MAAttachedWindow.m in Sources */, 66BC03621260D095005A23F4 /* IJItemPropertiesViewController.m in Sources */, 66BC04F812619072005A23F4 /* NSColor+Additions.m in Sources */, + 6697AD7212B86762001890C6 /* IJTableView.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/README.markdown b/README.markdown index fbedb30..d211cfa 100644 --- a/README.markdown +++ b/README.markdown @@ -33,6 +33,10 @@ After changing your inventory you will need to save the currently open world usi ### Release Notes +#### Unreleased (changes not in the binary builds) + +- Streamlined keyboard item-adding: search with Command-F, down arrow to navigate to item, then return adds it to the first available inventory slot. + #### 1.0.1 - November 2, 2010 - Added Halloween update items (thanks to nickloose)