Browse Source

Streamlined keyboard item-adding.

preble 13 years ago
parent
commit
0cccfddd34

+ 1 - 0
Classes/IJInventoryWindowController.h

@@ -61,5 +61,6 @@
 - (IBAction)worldSelectionChanged:(id)sender;
 - (IBAction)updateItemSearchFilter:(id)sender;
 - (IBAction)makeSearchFieldFirstResponder:(id)sender;
+- (IBAction)itemTableViewDoubleClicked:(id)sender;
 
 @end

+ 70 - 0
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

+ 16 - 0
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 <Cocoa/Cocoa.h>
+
+
+@interface IJTableView : NSTableView {
+
+}
+
+@end

+ 25 - 0
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

+ 29 - 7
English.lproj/MainMenu.xib

@@ -924,7 +924,6 @@
 													</object>
 													<int key="NSResizingMask">3</int>
 													<bool key="NSIsResizeable">YES</bool>
-													<bool key="NSIsEditable">YES</bool>
 													<reference key="NSTableView" ref="497206092"/>
 												</object>
 												<object class="NSTableColumn" id="1010230928">
@@ -956,7 +955,6 @@
 													</object>
 													<int key="NSResizingMask">3</int>
 													<bool key="NSIsResizeable">YES</bool>
-													<bool key="NSIsEditable">YES</bool>
 													<reference key="NSTableView" ref="497206092"/>
 												</object>
 												<object class="NSTableColumn" id="696979695">
@@ -983,7 +981,6 @@
 													</object>
 													<int key="NSResizingMask">3</int>
 													<bool key="NSIsResizeable">YES</bool>
-													<bool key="NSIsEditable">YES</bool>
 													<reference key="NSTableView" ref="497206092"/>
 												</object>
 											</object>
@@ -1419,6 +1416,14 @@
 					</object>
 					<int key="connectionID">684</int>
 				</object>
+				<object class="IBConnectionRecord">
+					<object class="IBOutletConnection" key="connection">
+						<string key="label">delegate</string>
+						<reference key="source" ref="17633893"/>
+						<reference key="destination" ref="760161335"/>
+					</object>
+					<int key="connectionID">685</int>
+				</object>
 			</object>
 			<object class="IBMutableOrderedSet" key="objectRecords">
 				<object class="NSArray" key="orderedObjects">
@@ -2154,6 +2159,7 @@
 					<string>649.IBViewBoundsToFrameTransform</string>
 					<string>650.IBPluginDependency</string>
 					<string>651.IBPluginDependency</string>
+					<string>652.CustomClassName</string>
 					<string>652.IBPluginDependency</string>
 					<string>654.IBPluginDependency</string>
 					<string>655.IBPluginDependency</string>
@@ -2330,6 +2336,7 @@
 					</object>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+					<string>IJTableView</string>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -2377,7 +2384,7 @@
 				</object>
 			</object>
 			<nil key="sourceID"/>
-			<int key="maxID">684</int>
+			<int key="maxID">685</int>
 		</object>
 		<object class="IBClassDescriber" key="IBDocument.Classes">
 			<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -2398,7 +2405,7 @@
 					</object>
 					<object class="IBClassDescriptionSource" key="sourceIdentifier">
 						<string key="majorKey">IBProjectSource</string>
-						<string key="minorKey">IJInventoryView.h</string>
+						<string key="minorKey">Classes/IJInventoryView.h</string>
 					</object>
 				</object>
 				<object class="IBPartialClassDescription">
@@ -2408,6 +2415,7 @@
 						<bool key="EncodedWithXMLCoder">YES</bool>
 						<object class="NSArray" key="dict.sortedKeys">
 							<bool key="EncodedWithXMLCoder">YES</bool>
+							<string>itemTableViewDoubleClicked:</string>
 							<string>makeSearchFieldFirstResponder:</string>
 							<string>menuSelectWorld:</string>
 							<string>updateItemSearchFilter:</string>
@@ -2419,12 +2427,14 @@
 							<string>id</string>
 							<string>id</string>
 							<string>id</string>
+							<string>id</string>
 						</object>
 					</object>
 					<object class="NSMutableDictionary" key="actionInfosByName">
 						<bool key="EncodedWithXMLCoder">YES</bool>
 						<object class="NSArray" key="dict.sortedKeys">
 							<bool key="EncodedWithXMLCoder">YES</bool>
+							<string>itemTableViewDoubleClicked:</string>
 							<string>makeSearchFieldFirstResponder:</string>
 							<string>menuSelectWorld:</string>
 							<string>updateItemSearchFilter:</string>
@@ -2432,6 +2442,10 @@
 						</object>
 						<object class="NSMutableArray" key="dict.values">
 							<bool key="EncodedWithXMLCoder">YES</bool>
+							<object class="IBActionInfo">
+								<string key="name">itemTableViewDoubleClicked:</string>
+								<string key="candidateClassName">id</string>
+							</object>
 							<object class="IBActionInfo">
 								<string key="name">makeSearchFieldFirstResponder:</string>
 								<string key="candidateClassName">id</string>
@@ -2526,7 +2540,15 @@
 					</object>
 					<object class="IBClassDescriptionSource" key="sourceIdentifier">
 						<string key="majorKey">IBProjectSource</string>
-						<string key="minorKey">IJInventoryWindowController.h</string>
+						<string key="minorKey">Classes/IJInventoryWindowController.h</string>
+					</object>
+				</object>
+				<object class="IBPartialClassDescription">
+					<string key="className">IJTableView</string>
+					<string key="superclassName">NSTableView</string>
+					<object class="IBClassDescriptionSource" key="sourceIdentifier">
+						<string key="majorKey">IBProjectSource</string>
+						<string key="minorKey">Classes/IJTableView.h</string>
 					</object>
 				</object>
 				<object class="IBPartialClassDescription">
@@ -2545,7 +2567,7 @@
 					</object>
 					<object class="IBClassDescriptionSource" key="sourceIdentifier">
 						<string key="majorKey">IBProjectSource</string>
-						<string key="minorKey">InsideJobAppDelegate.h</string>
+						<string key="minorKey">Classes/InsideJobAppDelegate.h</string>
 					</object>
 				</object>
 			</object>

+ 8 - 0
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 = "<group>"; };
 		668B27F1125D963F0060BF71 /* IJInventoryWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IJInventoryWindowController.m; sourceTree = "<group>"; };
 		668B28D8125E370A0060BF71 /* Items.csv */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Items.csv; sourceTree = "<group>"; };
+		6697AD7012B86762001890C6 /* IJTableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IJTableView.h; sourceTree = "<group>"; };
+		6697AD7112B86762001890C6 /* IJTableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IJTableView.m; sourceTree = "<group>"; };
+		6697ADA812B86A07001890C6 /* README.markdown */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README.markdown; sourceTree = "<group>"; wrapsLines = 1; };
 		66BC00011260215C005A23F4 /* IJInventoryView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IJInventoryView.h; sourceTree = "<group>"; };
 		66BC00021260215C005A23F4 /* IJInventoryView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IJInventoryView.m; sourceTree = "<group>"; };
 		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 = "<group>";
@@ -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;
 		};

+ 4 - 0
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)