-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathItemSelectionPopup.m
55 lines (47 loc) · 1.37 KB
/
ItemSelectionPopup.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// ItemSelectionPopup.m
// mingame
//
// Created by Jason Baker on 9/1/17.
// Copyright © 2017 Jason Baker. All rights reserved.
//
#import "ItemSelectionPopup.h"
#import "GameRenderer.h"
#import "UIButton+UserData.h"
@implementation ItemSelectionPopup
- (instancetype)init
{
self = [super init];
if (self) {
self.maxX = 0;
self.maxY = 0;
self.buttonX = 10;
self.buttonY = 10;
}
return self;
}
- (UIButton *) addButtonWithData:(NSObject*)data sprite:(UIImage*)sprite {
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
button.userData = data;
button.frame = CGRectMake(self.buttonX, self.buttonY, 30, 30);
self.maxX = MAX(self.maxX, self.buttonX);
self.maxY = MAX(self.maxY, self.buttonY);
self.buttonX += 40;
if (sprite != nil) {
[button setBackgroundImage:sprite forState:UIControlStateNormal];
}
[button addTarget:self action:@selector(handleButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:button];
return button;
}
- (void) handleButtonClick:(UIButton*)button {
[self.buttonDelegate handleButtonClickData:button.userData selectionPopup:self];
}
- (void) moveToNextButtonRow {
self.buttonY += 40;
self.buttonX = 10;
}
- (void) resizeToFitButtons {
self.frame = CGRectMake(0, 0, self.maxX + 40, self.maxY + 40);
}
@end