Armor items are now properly inverted.
This commit is contained in:
parent
9edad26faa
commit
879afd1822
@ -17,6 +17,8 @@ extern NSString * const IJPasteboardTypeInventoryItem;
|
||||
int rows;
|
||||
int cols;
|
||||
|
||||
BOOL invert;
|
||||
|
||||
NSEvent *mouseDownEvent;
|
||||
|
||||
NSArray *items;
|
||||
@ -27,7 +29,7 @@ extern NSString * const IJPasteboardTypeInventoryItem;
|
||||
}
|
||||
@property (nonatomic, assign) id<IJInventoryViewDelegate> delegate;
|
||||
|
||||
- (void)setRows:(int)numberOfRows columns:(int)numberOfColumns;
|
||||
- (void)setRows:(int)numberOfRows columns:(int)numberOfColumns invert:(BOOL)invert;
|
||||
- (void)setItems:(NSArray *)theItems;
|
||||
- (NSPoint)pointForItemAtIndex:(int)index;
|
||||
- (void)reloadItemAtIndex:(int)itemIndex;
|
||||
|
||||
@ -61,11 +61,15 @@ const static CGFloat cellOffset = 40;
|
||||
{
|
||||
int x = index % cols;
|
||||
int y = index / cols;
|
||||
if (invert)
|
||||
y = rows - 1 - y;
|
||||
return CGPointMake(x * cellOffset, self.bounds.size.height - y * cellOffset);
|
||||
}
|
||||
|
||||
- (void)setRows:(int)numberOfRows columns:(int)numberOfColumns
|
||||
- (void)setRows:(int)numberOfRows columns:(int)numberOfColumns invert:(BOOL)inv
|
||||
{
|
||||
invert = inv;
|
||||
|
||||
CALayer *layer = [CALayer layer];
|
||||
|
||||
layer.bounds = NSRectToCGRect(self.bounds);
|
||||
@ -93,7 +97,12 @@ const static CGFloat cellOffset = 40;
|
||||
{
|
||||
CALayer *layer = [CALayer layer];
|
||||
layer.anchorPoint = CGPointZero;
|
||||
layer.position = CGPointMake(x * cellOffset, y * cellOffset);
|
||||
|
||||
if (invert)
|
||||
layer.position = CGPointMake(x * cellOffset, (rows - 1 - y) * cellOffset);
|
||||
else
|
||||
layer.position = CGPointMake(x * cellOffset, y * cellOffset);
|
||||
|
||||
layer.bounds = CGRectMake(0, 0, cellSize, cellSize);
|
||||
layer.borderWidth = 1.0;
|
||||
layer.borderColor = [self borderColor];
|
||||
@ -121,11 +130,6 @@ const static CGFloat cellOffset = 40;
|
||||
}
|
||||
}
|
||||
|
||||
- (CALayer *)layerAtRow:(int)row column:(int)column
|
||||
{
|
||||
return [self.layer.sublayers objectAtIndex:row * cols + column];
|
||||
}
|
||||
|
||||
- (void)reloadItemAtIndex:(int)itemIndex
|
||||
{
|
||||
IJInventoryItem *item = [items objectAtIndex:itemIndex];
|
||||
@ -157,6 +161,8 @@ const static CGFloat cellOffset = 40;
|
||||
point.y = self.bounds.size.height - point.y;
|
||||
point.x /= cellOffset;
|
||||
point.y /= cellOffset;
|
||||
if (invert)
|
||||
point.y = rows - 1 - floor(point.y);
|
||||
int index = floor(point.y) * cols + floor(point.x); // flip y
|
||||
return index;
|
||||
}
|
||||
|
||||
@ -32,9 +32,9 @@
|
||||
normalInventory = [[NSMutableArray alloc] init];
|
||||
statusTextField.stringValue = @"";
|
||||
|
||||
[inventoryView setRows:3 columns:9];
|
||||
[quickView setRows:1 columns:9];
|
||||
[armorView setRows:4 columns:1];
|
||||
[inventoryView setRows:3 columns:9 invert:NO];
|
||||
[quickView setRows:1 columns:9 invert:NO];
|
||||
[armorView setRows:4 columns:1 invert:YES];
|
||||
inventoryView.delegate = self;
|
||||
quickView.delegate = self;
|
||||
armorView.delegate = self;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user