Browse Source

Snapshot of progress: moved to custom IJInventoryView.

preble 13 years ago
parent
commit
f791d3e403

+ 88 - 59
English.lproj/MainMenu.xib

@@ -12,8 +12,8 @@
 		</object>
 		<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
 			<bool key="EncodedWithXMLCoder">YES</bool>
-			<integer value="29"/>
 			<integer value="372"/>
+			<integer value="29"/>
 		</object>
 		<object class="NSArray" key="IBDocument.PluginDependencies">
 			<bool key="EncodedWithXMLCoder">YES</bool>
@@ -1128,26 +1128,26 @@
 								<int key="NSSegmentStyle">2</int>
 							</object>
 						</object>
-						<object class="NSCustomView" id="427079584">
+						<object class="NSCustomView" id="977606027">
 							<reference key="NSNextResponder" ref="439893737"/>
-							<int key="NSvFlags">278</int>
-							<string key="NSFrame">{{77, 295}, {432, 144}}</string>
+							<int key="NSvFlags">268</int>
+							<string key="NSFrame">{{78, 309}, {432, 144}}</string>
 							<reference key="NSSuperview" ref="439893737"/>
-							<string key="NSClassName">NSView</string>
+							<string key="NSClassName">IJInventoryView</string>
 						</object>
-						<object class="NSCustomView" id="637735386">
+						<object class="NSCustomView" id="991633424">
 							<reference key="NSNextResponder" ref="439893737"/>
-							<int key="NSvFlags">278</int>
-							<string key="NSFrame">{{77, 239}, {432, 48}}</string>
+							<int key="NSvFlags">268</int>
+							<string key="NSFrame">{{78, 242}, {432, 48}}</string>
 							<reference key="NSSuperview" ref="439893737"/>
-							<string key="NSClassName">NSView</string>
+							<string key="NSClassName">IJInventoryView</string>
 						</object>
-						<object class="NSCustomView" id="649603357">
+						<object class="NSCustomView" id="643984135">
 							<reference key="NSNextResponder" ref="439893737"/>
-							<int key="NSvFlags">278</int>
-							<string key="NSFrame">{{11, 247}, {48, 192}}</string>
+							<int key="NSvFlags">268</int>
+							<string key="NSFrame">{{11, 261}, {48, 192}}</string>
 							<reference key="NSSuperview" ref="439893737"/>
-							<string key="NSClassName">NSView</string>
+							<string key="NSClassName">IJInventoryView</string>
 						</object>
 					</object>
 					<string key="NSFrameSize">{551, 537}</string>
@@ -1467,27 +1467,27 @@
 				</object>
 				<object class="IBConnectionRecord">
 					<object class="IBOutletConnection" key="connection">
-						<string key="label">inventoryMatrixContainer</string>
+						<string key="label">inventoryView</string>
 						<reference key="source" ref="760161335"/>
-						<reference key="destination" ref="427079584"/>
+						<reference key="destination" ref="977606027"/>
 					</object>
-					<int key="connectionID">614</int>
+					<int key="connectionID">642</int>
 				</object>
 				<object class="IBConnectionRecord">
 					<object class="IBOutletConnection" key="connection">
-						<string key="label">quickMatrixContainer</string>
+						<string key="label">armorView</string>
 						<reference key="source" ref="760161335"/>
-						<reference key="destination" ref="637735386"/>
+						<reference key="destination" ref="643984135"/>
 					</object>
-					<int key="connectionID">616</int>
+					<int key="connectionID">645</int>
 				</object>
 				<object class="IBConnectionRecord">
 					<object class="IBOutletConnection" key="connection">
-						<string key="label">armorMatrixContainer</string>
+						<string key="label">quickView</string>
 						<reference key="source" ref="760161335"/>
-						<reference key="destination" ref="649603357"/>
+						<reference key="destination" ref="991633424"/>
 					</object>
-					<int key="connectionID">618</int>
+					<int key="connectionID">646</int>
 				</object>
 			</object>
 			<object class="IBMutableOrderedSet" key="objectRecords">
@@ -1861,9 +1861,9 @@
 							<reference ref="395301483"/>
 							<reference ref="574149520"/>
 							<reference ref="626341130"/>
-							<reference ref="427079584"/>
-							<reference ref="649603357"/>
-							<reference ref="637735386"/>
+							<reference ref="643984135"/>
+							<reference ref="977606027"/>
+							<reference ref="991633424"/>
 						</object>
 						<reference key="parent" ref="972006081"/>
 					</object>
@@ -2113,22 +2113,22 @@
 						<reference key="parent" ref="626341130"/>
 					</object>
 					<object class="IBObjectRecord">
-						<int key="objectID">612</int>
-						<reference key="object" ref="427079584"/>
+						<int key="objectID">641</int>
+						<reference key="object" ref="977606027"/>
+						<object class="NSMutableArray" key="children">
+							<bool key="EncodedWithXMLCoder">YES</bool>
+						</object>
 						<reference key="parent" ref="439893737"/>
-						<string key="objectName">Matrix Placeholder</string>
 					</object>
 					<object class="IBObjectRecord">
-						<int key="objectID">615</int>
-						<reference key="object" ref="637735386"/>
+						<int key="objectID">643</int>
+						<reference key="object" ref="991633424"/>
 						<reference key="parent" ref="439893737"/>
-						<string key="objectName">Matrix Placeholder</string>
 					</object>
 					<object class="IBObjectRecord">
-						<int key="objectID">617</int>
-						<reference key="object" ref="649603357"/>
+						<int key="objectID">644</int>
+						<reference key="object" ref="643984135"/>
 						<reference key="parent" ref="439893737"/>
-						<string key="objectName">Matrix Placeholder</string>
 					</object>
 				</object>
 			</object>
@@ -2274,12 +2274,12 @@
 					<string>600.IBViewBoundsToFrameTransform</string>
 					<string>601.IBPluginDependency</string>
 					<string>601.IBSegmentedControlInspectorSelectedSegmentMetadataKey</string>
-					<string>612.IBPluginDependency</string>
-					<string>612.IBViewBoundsToFrameTransform</string>
-					<string>615.IBPluginDependency</string>
-					<string>615.IBViewBoundsToFrameTransform</string>
-					<string>617.IBPluginDependency</string>
-					<string>617.IBViewBoundsToFrameTransform</string>
+					<string>641.IBPluginDependency</string>
+					<string>641.IBViewBoundsToFrameTransform</string>
+					<string>643.IBPluginDependency</string>
+					<string>643.IBViewBoundsToFrameTransform</string>
+					<string>644.IBPluginDependency</string>
+					<string>644.IBViewBoundsToFrameTransform</string>
 					<string>74.IBPluginDependency</string>
 					<string>74.ImportedFromIB2</string>
 					<string>75.IBPluginDependency</string>
@@ -2454,15 +2454,15 @@
 					<integer value="0"/>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
 					<object class="NSAffineTransform">
-						<bytes key="NSTransformStruct">AUGgAABDcAAAA</bytes>
+						<bytes key="NSTransformStruct">AUJsAABDmoAAA</bytes>
 					</object>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
 					<object class="NSAffineTransform">
-						<bytes key="NSTransformStruct">AUKaAABDcAAAA</bytes>
+						<bytes key="NSTransformStruct">AUJsAABDcgAAA</bytes>
 					</object>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
 					<object class="NSAffineTransform">
-						<bytes key="NSTransformStruct">AUGgAABDcAAAA</bytes>
+						<bytes key="NSTransformStruct">AUIQAABDSgAAA</bytes>
 					</object>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
 					<integer value="1"/>
@@ -2498,11 +2498,19 @@
 				</object>
 			</object>
 			<nil key="sourceID"/>
-			<int key="maxID">618</int>
+			<int key="maxID">646</int>
 		</object>
 		<object class="IBClassDescriber" key="IBDocument.Classes">
 			<object class="NSMutableArray" key="referencedPartialClassDescriptions">
 				<bool key="EncodedWithXMLCoder">YES</bool>
+				<object class="IBPartialClassDescription">
+					<string key="className">IJInventoryView</string>
+					<string key="superclassName">NSView</string>
+					<object class="IBClassDescriptionSource" key="sourceIdentifier">
+						<string key="majorKey">IBProjectSource</string>
+						<string key="minorKey">IJInventoryView.h</string>
+					</object>
+				</object>
 				<object class="IBPartialClassDescription">
 					<string key="className">IJInventoryWindowController</string>
 					<string key="superclassName">NSWindowController</string>
@@ -2521,19 +2529,19 @@
 						<bool key="EncodedWithXMLCoder">YES</bool>
 						<object class="NSArray" key="dict.sortedKeys">
 							<bool key="EncodedWithXMLCoder">YES</bool>
-							<string>armorMatrixContainer</string>
-							<string>inventoryMatrixContainer</string>
+							<string>armorView</string>
+							<string>inventoryView</string>
 							<string>outlineView</string>
-							<string>quickMatrixContainer</string>
+							<string>quickView</string>
 							<string>statusTextField</string>
 							<string>worldSelectionControl</string>
 						</object>
 						<object class="NSMutableArray" key="dict.values">
 							<bool key="EncodedWithXMLCoder">YES</bool>
-							<string>NSView</string>
-							<string>NSView</string>
+							<string>IJInventoryView</string>
+							<string>IJInventoryView</string>
 							<string>NSOutlineView</string>
-							<string>NSView</string>
+							<string>IJInventoryView</string>
 							<string>NSTextField</string>
 							<string>NSSegmentedControl</string>
 						</object>
@@ -2542,30 +2550,30 @@
 						<bool key="EncodedWithXMLCoder">YES</bool>
 						<object class="NSArray" key="dict.sortedKeys">
 							<bool key="EncodedWithXMLCoder">YES</bool>
-							<string>armorMatrixContainer</string>
-							<string>inventoryMatrixContainer</string>
+							<string>armorView</string>
+							<string>inventoryView</string>
 							<string>outlineView</string>
-							<string>quickMatrixContainer</string>
+							<string>quickView</string>
 							<string>statusTextField</string>
 							<string>worldSelectionControl</string>
 						</object>
 						<object class="NSMutableArray" key="dict.values">
 							<bool key="EncodedWithXMLCoder">YES</bool>
 							<object class="IBToOneOutletInfo">
-								<string key="name">armorMatrixContainer</string>
-								<string key="candidateClassName">NSView</string>
+								<string key="name">armorView</string>
+								<string key="candidateClassName">IJInventoryView</string>
 							</object>
 							<object class="IBToOneOutletInfo">
-								<string key="name">inventoryMatrixContainer</string>
-								<string key="candidateClassName">NSView</string>
+								<string key="name">inventoryView</string>
+								<string key="candidateClassName">IJInventoryView</string>
 							</object>
 							<object class="IBToOneOutletInfo">
 								<string key="name">outlineView</string>
 								<string key="candidateClassName">NSOutlineView</string>
 							</object>
 							<object class="IBToOneOutletInfo">
-								<string key="name">quickMatrixContainer</string>
-								<string key="candidateClassName">NSView</string>
+								<string key="name">quickView</string>
+								<string key="candidateClassName">IJInventoryView</string>
 							</object>
 							<object class="IBToOneOutletInfo">
 								<string key="name">statusTextField</string>
@@ -3059,6 +3067,27 @@
 						<string key="minorKey">Foundation.framework/Headers/NSURLDownload.h</string>
 					</object>
 				</object>
+				<object class="IBPartialClassDescription">
+					<string key="className">NSObject</string>
+					<object class="IBClassDescriptionSource" key="sourceIdentifier">
+						<string key="majorKey">IBFrameworkSource</string>
+						<string key="minorKey">QuartzCore.framework/Headers/CAAnimation.h</string>
+					</object>
+				</object>
+				<object class="IBPartialClassDescription">
+					<string key="className">NSObject</string>
+					<object class="IBClassDescriptionSource" key="sourceIdentifier">
+						<string key="majorKey">IBFrameworkSource</string>
+						<string key="minorKey">QuartzCore.framework/Headers/CALayer.h</string>
+					</object>
+				</object>
+				<object class="IBPartialClassDescription">
+					<string key="className">NSObject</string>
+					<object class="IBClassDescriptionSource" key="sourceIdentifier">
+						<string key="majorKey">IBFrameworkSource</string>
+						<string key="minorKey">QuartzCore.framework/Headers/CIImageProvider.h</string>
+					</object>
+				</object>
 				<object class="IBPartialClassDescription">
 					<string key="className">NSOutlineView</string>
 					<string key="superclassName">NSTableView</string>

+ 1 - 1
IJInventoryItem.h

@@ -17,7 +17,7 @@
 #define IJInventorySlotArmorFirst (100) // feet
 
 
-@interface IJInventoryItem : NSObject {
+@interface IJInventoryItem : NSObject <NSCoding> {
 	uint16_t itemId;
 	uint16_t damage;
 	uint8_t count;

+ 21 - 0
IJInventoryItem.m

@@ -20,6 +20,27 @@
 	return obj;
 }
 
+- (id)initWithCoder:(NSCoder *)decoder
+{
+	if ((self = [super init]))
+	{
+		itemId = [decoder decodeIntForKey:@"itemId"];
+		slot = [decoder decodeIntForKey:@"slot"];
+		damage = [decoder decodeIntForKey:@"damage"];
+		count = [decoder decodeIntForKey:@"count"];
+	}
+	return self;
+}
+
+- (void)encodeWithCoder:(NSCoder *)coder
+{
+	[coder encodeInt:itemId forKey:@"itemId"];
+	[coder encodeInt:slot forKey:@"slot"];
+	[coder encodeInt:damage forKey:@"damage"];
+	[coder encodeInt:count forKey:@"count"];
+}
+
+
 - (NSString *)itemName
 {
 	NSString *name = [[IJInventoryItem itemIdLookup] objectForKey:[NSNumber numberWithShort:self.itemId]];

+ 24 - 0
IJInventoryView.h

@@ -0,0 +1,24 @@
+//
+//  IJInventoryView.h
+//  InsideJob
+//
+//  Created by Adam Preble on 10/9/10.
+//  Copyright 2010 Adam Preble. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface IJInventoryView : NSView {
+	int rows;
+	int cols;
+	
+	NSEvent *mouseDownEvent;
+	
+	NSArray *items;
+}
+
+- (void)setRows:(int)numberOfRows columns:(int)numberOfColumns;
+- (void)setItems:(NSArray *)theItems;
+
+@end

+ 229 - 0
IJInventoryView.m

@@ -0,0 +1,229 @@
+//
+//  IJInventoryView.m
+//  InsideJob
+//
+//  Created by Adam Preble on 10/9/10.
+//  Copyright 2010 Adam Preble. All rights reserved.
+//
+
+#import "IJInventoryView.h"
+#import "IJInventoryItem.h"
+
+NSString * const IJPasteboardTypeInventoryItem = @"net.adampreble.insidejob.inventoryitem";
+
+const static CGFloat cellSize = 32;
+const static CGFloat cellOffset = 40;
+
+@implementation IJInventoryView
+
+- (id)initWithFrame:(NSRect)frameRect
+{
+    if (self = [super initWithFrame:frameRect])
+	{
+        // Initialization code here.
+		[self registerForDraggedTypes:[NSArray arrayWithObjects:IJPasteboardTypeInventoryItem, nil]];
+    }
+    return self;
+}
+
+- (void)dealloc
+{
+	[items release];
+	[mouseDownEvent release];
+	[super dealloc];
+}
+
+- (void)awakeFromNib
+{
+}
+
+- (void)setRows:(int)numberOfRows columns:(int)numberOfColumns
+{
+	CALayer *layer = [CALayer layer];
+	
+	layer.bounds = NSRectToCGRect(self.bounds);
+	layer.anchorPoint = CGPointZero;
+	layer.position = CGPointZero; //CGPointMake(NSMidX(self.bounds), NSMidY(self.bounds));
+	layer.geometryFlipped = YES;
+	
+	[self setLayer:layer];
+	[self setWantsLayer:YES];
+	
+
+	rows = numberOfRows;
+	cols = numberOfColumns;
+	
+	// reset the layers
+	
+	for (CALayer *layer in self.layer.sublayers)
+	{
+		[layer removeFromSuperlayer];
+	}
+	
+	for (int y = 0; y < rows; y++)
+	{
+		for (int x = 0; x < cols; x++)
+		{
+			CALayer *layer = [CALayer layer];
+			layer.anchorPoint = CGPointZero;
+			layer.position = CGPointMake(x * cellOffset, y * cellOffset);
+			layer.bounds = CGRectMake(0, 0, cellSize, cellSize);
+			layer.borderWidth = 1.0;
+			layer.borderColor = CGColorGetConstantColor(kCGColorBlack);
+			[self.layer addSublayer:layer];
+		}
+	}
+}
+
+- (CALayer *)layerAtRow:(int)row column:(int)column
+{
+	return [self.layer.sublayers objectAtIndex:row * cols + column];
+}
+
+- (void)setItems:(NSArray *)theItems
+{
+	[items autorelease];
+	[theItems retain];
+	items = theItems;
+	
+	//NSLog(@"%@ sublayers=%@", [self layer], self.layer.sublayers);
+	[items enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
+		IJInventoryItem *item = obj;
+		CALayer *layer = [self.layer.sublayers objectAtIndex:idx];
+		layer.contents = item.image;
+	}];
+}
+
+- (int)itemIndexForPoint:(NSPoint)point
+{
+	point.y = self.bounds.size.height - point.y;
+	point.x /= cellOffset;
+	point.y /= cellOffset;
+	int index = floor(point.y) * cols + floor(point.x); // flip y
+	return index;
+}
+
+- (IJInventoryItem *)itemAtPoint:(NSPoint)point
+{
+	return [items objectAtIndex:[self itemIndexForPoint:point]];
+}
+
+#pragma mark -
+#pragma mark Drag & Drop: Source
+
+- (void)mouseDown:(NSEvent *)theEvent
+{
+	[theEvent retain];
+	[mouseDownEvent release];
+	mouseDownEvent = theEvent;
+}
+
+- (void)mouseDragged:(NSEvent *)theEvent
+{
+	NSPoint mouseDownPoint = [mouseDownEvent locationInWindow];
+	NSPoint mouseDragPoint = [theEvent locationInWindow];
+	float dragDistance = hypot(mouseDownPoint.x - mouseDragPoint.x, mouseDownPoint.y - mouseDragPoint.y);
+	if (dragDistance < 3)
+		return;
+	
+	// Find the IJInventoryItem:
+	NSPoint pointInView = [self convertPoint:mouseDownPoint fromView:nil];
+	IJInventoryItem *item = [self itemAtPoint:pointInView];
+	if (item.itemId == 0)
+		return; // can't drag nothing
+	
+	NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:NSDragPboard];
+	
+	[pasteboard declareTypes:[NSArray arrayWithObjects:IJPasteboardTypeInventoryItem, nil] owner:nil];
+	
+	[pasteboard setData:[NSKeyedArchiver archivedDataWithRootObject:item]
+				forType:IJPasteboardTypeInventoryItem];
+	
+	NSImage *image = item.image;
+	
+	NSPoint dragPoint = NSMakePoint(pointInView.x - image.size.width*0.5, pointInView.y - image.size.height*0.5);
+	
+	[self dragImage:item.image
+				 at:dragPoint
+			 offset:NSZeroSize
+			  event:mouseDownEvent
+		 pasteboard:pasteboard
+			 source:self
+		  slideBack:YES];
+}
+
+
+- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal
+{
+	return NSDragOperationEvery;
+}
+//- (void)draggedImage:(NSImage *)image beganAt:(NSPoint)screenPoint
+//{
+//	NSLog(@"%s", __PRETTY_FUNCTION__);
+//}
+- (void)draggedImage:(NSImage *)image endedAt:(NSPoint)screenPoint operation:(NSDragOperation)operation
+{
+	NSLog(@"%s operation=%d", __PRETTY_FUNCTION__, operation);
+}
+//- (void)draggedImage:(NSImage *)image movedTo:(NSPoint)screenPoint
+//{
+//	NSLog(@"%s", __PRETTY_FUNCTION__);
+//}
+
+
+#pragma mark -
+#pragma mark Drag & Drop: Destination
+
+- (void)moveHighlightToLayerAtIndex:(int)index
+{
+	[self.layer.sublayers enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
+		CALayer *layer = obj;
+		if (idx == index)
+			layer.borderColor = CGColorGetConstantColor(kCGColorWhite);
+		else
+			layer.borderColor = CGColorGetConstantColor(kCGColorBlack);
+	}];
+}
+
+- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
+{
+	// TODO: Detect and ignore same slot.
+	int index = [self itemIndexForPoint:[self convertPoint:[sender draggingLocation] fromView:nil]];
+	[self moveHighlightToLayerAtIndex:index];
+	
+	if ([[sender draggingSource] isKindOfClass:[self class]])
+		return NSDragOperationMove; // moving between inventories
+	else
+		return NSDragOperationCopy; // copying from the item selector, presumably
+}
+- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender
+{
+	// TODO: Detect and ignore same slot.
+	int index = [self itemIndexForPoint:[self convertPoint:[sender draggingLocation] fromView:nil]];
+	[self moveHighlightToLayerAtIndex:index];
+
+	if ([[sender draggingSource] isKindOfClass:[self class]])
+		return NSDragOperationMove; // moving between inventories
+	else
+		return NSDragOperationCopy; // copying from the item selector, presumably
+}
+
+- (void)draggingExited:(id <NSDraggingInfo>)sender
+{
+	[self moveHighlightToLayerAtIndex:-1];
+}
+- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
+{
+	return YES;
+}
+- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
+{
+	return YES;
+}
+- (void)concludeDragOperation:(id <NSDraggingInfo>)sender
+{
+	[self moveHighlightToLayerAtIndex:-1];
+}
+
+
+@end

+ 8 - 13
IJInventoryWindowController.h

@@ -8,10 +8,10 @@
 
 #import <Cocoa/Cocoa.h>
 
-@class IJItemMatrix;
+@class IJInventoryView;
 @class IJMinecraftLevel;
 
-@interface IJInventoryWindowController : NSWindowController {
+@interface IJInventoryWindowController : NSWindowController <NSCollectionViewDelegate> {
 	IJMinecraftLevel *level;
 	NSArray *inventory;
 	
@@ -19,14 +19,9 @@
 	NSSegmentedControl *worldSelectionControl;
 	NSTextField *statusTextField;
 	
-	NSView *inventoryMatrixContainer;
-	IJItemMatrix *inventoryMatrix;
-	
-	NSView *quickMatrixContainer;
-	IJItemMatrix *quickMatrix;
-	
-	NSView *armorMatrixContainer;
-	IJItemMatrix *armorMatrix;
+	IJInventoryView *inventoryView;
+	IJInventoryView *quickView;
+	IJInventoryView *armorView;
 	
 	NSArray *rootItems;
 	NSMutableArray *armorItem;
@@ -40,9 +35,9 @@
 @property (nonatomic, assign) IBOutlet NSOutlineView *outlineView;
 @property (nonatomic, assign) IBOutlet NSSegmentedControl *worldSelectionControl;
 @property (nonatomic, assign) IBOutlet NSTextField *statusTextField;
-@property (nonatomic, assign) IBOutlet NSView *inventoryMatrixContainer;
-@property (nonatomic, assign) IBOutlet NSView *quickMatrixContainer;
-@property (nonatomic, assign) IBOutlet NSView *armorMatrixContainer;
+@property (nonatomic, assign) IBOutlet IJInventoryView *inventoryView;
+@property (nonatomic, assign) IBOutlet IJInventoryView *quickView;
+@property (nonatomic, assign) IBOutlet IJInventoryView *armorView;
 
 @property (nonatomic, retain) NSNumber *worldTime;
 

+ 18 - 28
IJInventoryWindowController.m

@@ -9,15 +9,15 @@
 #import "IJInventoryWindowController.h"
 #import "IJMinecraftLevel.h"
 #import "IJInventoryItem.h"
-#import "IJItemMatrix.h"
 #import "IJItemPickerWindowController.h"
+#import "IJInventoryView.h"
 
 @implementation IJInventoryWindowController
 
 @synthesize outlineView;
 @synthesize worldSelectionControl;
 @synthesize statusTextField;
-@synthesize inventoryMatrixContainer, quickMatrixContainer, armorMatrixContainer;
+@synthesize inventoryView, armorView, quickView;
 
 
 - (void)awakeFromNib
@@ -28,15 +28,11 @@
 	rootItems = [[NSArray alloc] initWithObjects:armorItem, quickItem, inventoryItem, nil];
 	statusTextField.stringValue = @"";
 	
-	inventoryMatrix = [IJItemMatrix itemMatrixWithFrame:inventoryMatrixContainer.bounds rows:3 columns:9];
-	[inventoryMatrixContainer addSubview:inventoryMatrix];
-	
-	quickMatrix = [IJItemMatrix itemMatrixWithFrame:quickMatrixContainer.bounds rows:1 columns:9];
-	[quickMatrixContainer addSubview:quickMatrix];
-	
-	armorMatrix = [IJItemMatrix itemMatrixWithFrame:armorMatrixContainer.bounds rows:4 columns:1];
-	[armorMatrixContainer addSubview:armorMatrix];
+	[inventoryView setRows:3 columns:9];
+	[quickView setRows:1 columns:9];
+	[armorView setRows:4 columns:1];
 }
+
 - (void)dealloc
 {
 	[inventory release];
@@ -132,24 +128,9 @@
 	[outlineView reloadData];
 	[outlineView expandItem:nil expandChildren:YES];
 	
-	for (IJInventoryItem *item in inventoryItem)
-	{
-		int slot = item.slot - IJInventorySlotNormalFirst;
-		NSImageCell *cell = [inventoryMatrix cellAtRow:slot/9 column:slot%9];
-		cell.image = item.image;
-	}
-	for (IJInventoryItem *item in quickItem)
-	{
-		int slot = item.slot - IJInventorySlotQuickFirst;
-		NSImageCell *cell = [quickMatrix cellAtRow:0 column:slot];
-		cell.image = item.image;
-	}
-	for (IJInventoryItem *item in armorItem)
-	{
-		int slot = item.slot - IJInventorySlotArmorFirst;
-		NSImageCell *cell = [armorMatrix cellAtRow:3-slot column:0];
-		cell.image = item.image;
-	}
+	[inventoryView setItems:inventoryItem];
+	[quickView setItems:quickItem];
+	[armorView setItems:armorItem];
 	
 	dirty = NO;
 	statusTextField.stringValue = @"";
@@ -387,5 +368,14 @@
 	}
 }
 
+#pragma mark -
+#pragma mark NSCollectionViewDelegate
+
+- (BOOL)collectionView:(NSCollectionView *)collectionView writeItemsAtIndexes:(NSIndexSet *)indexes toPasteboard:(NSPasteboard *)pasteboard
+{
+	NSLog(@"%s", __PRETTY_FUNCTION__);
+	[pasteboard declareTypes:[NSArray arrayWithObjects:@"net.adampreble.insidejob.item", nil] owner:self];
+	return YES;
+}
 
 @end

+ 0 - 18
IJItemMatrix.h

@@ -1,18 +0,0 @@
-//
-//  IJItemMatrix.h
-//  InsideJob
-//
-//  Created by Adam Preble on 10/8/10.
-//  Copyright 2010 Adam Preble. All rights reserved.
-//
-
-#import <Cocoa/Cocoa.h>
-
-
-@interface IJItemMatrix : NSMatrix {
-
-}
-
-+ (id)itemMatrixWithFrame:(NSRect)frame rows:(int)rows columns:(int)cols;
-
-@end

+ 0 - 47
IJItemMatrix.m

@@ -1,47 +0,0 @@
-//
-//  IJItemMatrix.m
-//  InsideJob
-//
-//  Created by Adam Preble on 10/8/10.
-//  Copyright 2010 Adam Preble. All rights reserved.
-//
-
-#import "IJItemMatrix.h"
-
-
-@implementation IJItemMatrix
-
-+ (id)itemMatrixWithFrame:(NSRect)frame rows:(int)rows columns:(int)cols
-{
-	NSMatrix *matrix = nil; // output
-	NSImageCell *imageCellPrototype = [[[NSImageCell alloc] init] autorelease];
-	[imageCellPrototype setImageFrameStyle:NSImageFrameGrayBezel];
-	matrix = [[[self class] alloc] initWithFrame:frame
-											mode:NSHighlightModeMatrix
-									   prototype:imageCellPrototype
-									numberOfRows:rows
-								 numberOfColumns:cols];
-	[matrix setCellSize:NSMakeSize(32+16, 32+16)];
-	[matrix setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
-	[matrix setDrawsBackground:NO];
-	[matrix setDrawsCellBackground:NO];
-	[matrix setIntercellSpacing:NSMakeSize(0, 0)];
-	return [matrix autorelease];
-}
-
-- (id)initWithCoder:(NSCoder *)aDecoder
-{
-    if (self = [super initWithCoder:aDecoder])
-	{
-        // Initialization code here.
-    }
-    return self;
-}
-
-- (void)dealloc
-{
-	[super dealloc];
-}
-
-
-@end

+ 10 - 6
InsideJob.xcodeproj/project.pbxproj

@@ -18,10 +18,11 @@
 		668B290F125E40560060BF71 /* Items.csv in Resources */ = {isa = PBXBuildFile; fileRef = 668B28D8125E370A0060BF71 /* Items.csv */; };
 		668B2979125E5DD40060BF71 /* IJItemPickerWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 668B2978125E5DD40060BF71 /* IJItemPickerWindowController.m */; };
 		668B297C125E5DF00060BF71 /* ItemPicker.xib in Resources */ = {isa = PBXBuildFile; fileRef = 668B297B125E5DF00060BF71 /* ItemPicker.xib */; };
+		66BC00031260215C005A23F4 /* IJInventoryView.m in Sources */ = {isa = PBXBuildFile; fileRef = 66BC00021260215C005A23F4 /* IJInventoryView.m */; };
+		66BC000E12602359005A23F4 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 66BC000D12602359005A23F4 /* QuartzCore.framework */; };
 		66BCFC2B125E9A51005A23F4 /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 66BCFC2A125E9A51005A23F4 /* Credits.rtf */; };
 		66BCFC36125EA53E005A23F4 /* InsideJob.icns in Resources */ = {isa = PBXBuildFile; fileRef = 66BCFC35125EA53E005A23F4 /* InsideJob.icns */; };
 		66BCFE62125FCEC6005A23F4 /* DataValuesV110Transparent.png in Resources */ = {isa = PBXBuildFile; fileRef = 66BCFE61125FCEC6005A23F4 /* DataValuesV110Transparent.png */; };
-		66BCFEE812600847005A23F4 /* IJItemMatrix.m in Sources */ = {isa = PBXBuildFile; fileRef = 66BCFEE712600847005A23F4 /* IJItemMatrix.m */; };
 		8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
 		8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
 		8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
@@ -53,11 +54,12 @@
 		668B2977125E5DD40060BF71 /* IJItemPickerWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IJItemPickerWindowController.h; sourceTree = "<group>"; };
 		668B2978125E5DD40060BF71 /* IJItemPickerWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IJItemPickerWindowController.m; sourceTree = "<group>"; };
 		668B297B125E5DF00060BF71 /* ItemPicker.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ItemPicker.xib; sourceTree = "<group>"; };
+		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; };
 		66BCFC2A125E9A51005A23F4 /* Credits.rtf */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; path = Credits.rtf; sourceTree = "<group>"; };
 		66BCFC35125EA53E005A23F4 /* InsideJob.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = InsideJob.icns; sourceTree = "<group>"; };
 		66BCFE61125FCEC6005A23F4 /* DataValuesV110Transparent.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = DataValuesV110Transparent.png; sourceTree = "<group>"; };
-		66BCFEE612600847005A23F4 /* IJItemMatrix.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IJItemMatrix.h; sourceTree = "<group>"; };
-		66BCFEE712600847005A23F4 /* IJItemMatrix.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IJItemMatrix.m; sourceTree = "<group>"; };
 		8D1107310486CEB800E47090 /* InsideJob-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "InsideJob-Info.plist"; sourceTree = "<group>"; };
 		8D1107320486CEB800E47090 /* Inside Job.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Inside Job.app"; sourceTree = BUILT_PRODUCTS_DIR; };
 /* End PBXFileReference section */
@@ -69,6 +71,7 @@
 			files = (
 				8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */,
 				668B2560125D5C1C0060BF71 /* libz.dylib in Frameworks */,
+				66BC000E12602359005A23F4 /* QuartzCore.framework in Frameworks */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -90,6 +93,7 @@
 		1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */ = {
 			isa = PBXGroup;
 			children = (
+				66BC000D12602359005A23F4 /* QuartzCore.framework */,
 				668B255F125D5C1C0060BF71 /* libz.dylib */,
 				1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */,
 			);
@@ -188,8 +192,8 @@
 				668B27F1125D963F0060BF71 /* IJInventoryWindowController.m */,
 				668B2977125E5DD40060BF71 /* IJItemPickerWindowController.h */,
 				668B2978125E5DD40060BF71 /* IJItemPickerWindowController.m */,
-				66BCFEE612600847005A23F4 /* IJItemMatrix.h */,
-				66BCFEE712600847005A23F4 /* IJItemMatrix.m */,
+				66BC00011260215C005A23F4 /* IJInventoryView.h */,
+				66BC00021260215C005A23F4 /* IJInventoryView.m */,
 			);
 			name = Interface;
 			sourceTree = "<group>";
@@ -272,7 +276,7 @@
 				668B27B2125D8F8E0060BF71 /* IJInventoryItem.m in Sources */,
 				668B27F2125D963F0060BF71 /* IJInventoryWindowController.m in Sources */,
 				668B2979125E5DD40060BF71 /* IJItemPickerWindowController.m in Sources */,
-				66BCFEE812600847005A23F4 /* IJItemMatrix.m in Sources */,
+				66BC00031260215C005A23F4 /* IJInventoryView.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};