diff --git a/DataValuesV110.png b/DataValuesV110.png new file mode 100644 index 0000000..987e395 Binary files /dev/null and b/DataValuesV110.png differ diff --git a/DataValuesV110Transparent.png b/DataValuesV110Transparent.png new file mode 100644 index 0000000..911786b Binary files /dev/null and b/DataValuesV110Transparent.png differ diff --git a/IJInventoryItem.h b/IJInventoryItem.h index 8484d04..47ff45b 100644 --- a/IJInventoryItem.h +++ b/IJInventoryItem.h @@ -29,6 +29,7 @@ @property (nonatomic, assign) uint8_t slot; @property (nonatomic, readonly) NSString *itemName; +@property (nonatomic, readonly) NSImage *image; + (id)emptyItemWithSlot:(uint8_t)slot; diff --git a/IJInventoryItem.m b/IJInventoryItem.m index 2fed41c..db29a4a 100644 --- a/IJInventoryItem.m +++ b/IJInventoryItem.m @@ -29,6 +29,69 @@ return [NSString stringWithFormat:@"%d", self.itemId]; } +- (NSImage *)image +{ + NSSize itemImageSize = NSMakeSize(32, 32); + NSPoint atlasOffset; + NSUInteger itemsPerRow = 9; + NSUInteger pixelsPerColumn = 36; + NSUInteger pixelsPerRow = 56; + + int index; + + if (self.itemId <= 85) + { + if (self.itemId <= 20) + index = self.itemId - 1; // first item is 1 + else if (self.itemId == 35) + index = self.itemId - (35 - 20); + else if (self.itemId >= 37) + index = self.itemId - (37 - 21); + atlasOffset = NSMakePoint(36, 75); + } + else if (self.itemId >= 256 && self.itemId <= 346) + { + index = self.itemId - 256; + atlasOffset = NSMakePoint(445, 23+52); + } + else if (self.itemId >= 2556 && self.itemId <= 2557) + { + index = self.itemId - 2556; + atlasOffset = NSMakePoint(445+pixelsPerColumn, 23+52); + } + else + { + NSLog(@"%s error: unrecognized item id %d", __PRETTY_FUNCTION__, self.itemId); + return nil; + } + + atlasOffset.x += pixelsPerColumn * (index % itemsPerRow); + atlasOffset.y += pixelsPerRow * (index / itemsPerRow); + + NSRect atlasRect = NSMakeRect(atlasOffset.x, atlasOffset.y, itemImageSize.width, itemImageSize.height); + + + NSImage *atlas = [NSImage imageNamed:@"DataValuesV110Transparent.png"]; + NSImage *output = [[NSImage alloc] initWithSize:itemImageSize]; + + atlasRect.origin.y = atlas.size.height - atlasRect.origin.y; + + [NSGraphicsContext saveGraphicsState]; + + [output lockFocus]; + + [atlas drawInRect:NSMakeRect(0, 0, itemImageSize.width, itemImageSize.height) + fromRect:atlasRect + operation:NSCompositeCopy + fraction:1.0]; + + [output unlockFocus]; + + [NSGraphicsContext restoreGraphicsState]; + + return output; +} + + (NSDictionary *)itemIdLookup { static NSDictionary *lookup = nil; diff --git a/InsideJob.xcodeproj/project.pbxproj b/InsideJob.xcodeproj/project.pbxproj index 6d29a9b..be118ca 100644 --- a/InsideJob.xcodeproj/project.pbxproj +++ b/InsideJob.xcodeproj/project.pbxproj @@ -20,6 +20,7 @@ 668B297C125E5DF00060BF71 /* ItemPicker.xib in Resources */ = {isa = PBXBuildFile; fileRef = 668B297B125E5DF00060BF71 /* ItemPicker.xib */; }; 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 */; }; 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,6 +54,7 @@ 668B297B125E5DF00060BF71 /* ItemPicker.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ItemPicker.xib; sourceTree = ""; }; 66BCFC2A125E9A51005A23F4 /* Credits.rtf */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; path = Credits.rtf; sourceTree = ""; }; 66BCFC35125EA53E005A23F4 /* InsideJob.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = InsideJob.icns; sourceTree = ""; }; + 66BCFE61125FCEC6005A23F4 /* DataValuesV110Transparent.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = DataValuesV110Transparent.png; sourceTree = ""; }; 8D1107310486CEB800E47090 /* InsideJob-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "InsideJob-Info.plist"; sourceTree = ""; }; 8D1107320486CEB800E47090 /* Inside Job.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Inside Job.app"; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -133,6 +135,7 @@ 29B97317FDCFA39411CA2CEA /* Resources */ = { isa = PBXGroup; children = ( + 66BCFE61125FCEC6005A23F4 /* DataValuesV110Transparent.png */, 66BCFC35125EA53E005A23F4 /* InsideJob.icns */, 8D1107310486CEB800E47090 /* InsideJob-Info.plist */, 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */, @@ -245,6 +248,7 @@ 668B297C125E5DF00060BF71 /* ItemPicker.xib in Resources */, 66BCFC2B125E9A51005A23F4 /* Credits.rtf in Resources */, 66BCFC36125EA53E005A23F4 /* InsideJob.icns in Resources */, + 66BCFE62125FCEC6005A23F4 /* DataValuesV110Transparent.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; };