author | unc0rr |
Thu, 22 Sep 2011 11:44:39 +0400 | |
changeset 5989 | 23407ecb1826 |
parent 5976 | 306cedbeb213 |
child 6078 | 8c0cc07731e5 |
permissions | -rw-r--r-- |
3829 | 1 |
/* |
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
|
4976 | 3 |
* Copyright (c) 2009-2011 Vittorio Giovara <vittorio.giovara@gmail.com> |
3829 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
17 |
* |
|
18 |
* File created on 20/04/2010. |
|
19 |
*/ |
|
20 |
||
3547 | 21 |
|
22 |
#import "TeamConfigViewController.h" |
|
23 |
#import "CommodityFunctions.h" |
|
24 |
#import "SquareButtonView.h" |
|
25 |
||
26 |
@implementation TeamConfigViewController |
|
3739 | 27 |
@synthesize listOfTeams, listOfSelectedTeams, cachedContentsOfDir; |
3547 | 28 |
|
29 |
#pragma mark - |
|
30 |
#pragma mark View lifecycle |
|
31 |
-(void) viewDidLoad { |
|
32 |
[super viewDidLoad]; |
|
3697 | 33 |
|
3547 | 34 |
CGSize screenSize = [[UIScreen mainScreen] bounds].size; |
35 |
self.view.frame = CGRectMake(0, 0, screenSize.height, screenSize.width - 44); |
|
4082 | 36 |
|
4244 | 37 |
if ([self.tableView respondsToSelector:@selector(setBackgroundView:)]) { |
38 |
if (IS_IPAD()) |
|
39 |
[self.tableView setBackgroundView:nil]; |
|
40 |
else { |
|
4356 | 41 |
UIImage *backgroundImage = [[UIImage alloc] initWithContentsOfFile:@"background~iphone.png"]; |
4244 | 42 |
UIImageView *background = [[UIImageView alloc] initWithImage:backgroundImage]; |
43 |
[backgroundImage release]; |
|
44 |
[self.tableView setBackgroundView:background]; |
|
45 |
[background release]; |
|
46 |
} |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
47 |
} else |
4244 | 48 |
self.view.backgroundColor = [UIColor blackColor]; |
49 |
||
3917 | 50 |
self.tableView.separatorColor = UICOLOR_HW_YELLOW_BODER; |
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
51 |
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; |
3547 | 52 |
} |
53 |
||
54 |
-(void) viewWillAppear:(BOOL)animated { |
|
55 |
[super viewWillAppear:animated]; |
|
56 |
||
3739 | 57 |
NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:TEAMS_DIRECTORY() error:NULL]; |
3551 | 58 |
// avoid overwriting selected teams when returning on this view |
3971 | 59 |
if ([self.cachedContentsOfDir isEqualToArray:contentsOfDir] == NO) { |
3917 | 60 |
NSArray *colors = getAvailableColors(); |
3551 | 61 |
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:[contentsOfDir count]]; |
62 |
for (int i = 0; i < [contentsOfDir count]; i++) { |
|
63 |
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys: |
|
64 |
[contentsOfDir objectAtIndex:i],@"team", |
|
65 |
[NSNumber numberWithInt:4],@"number", |
|
3917 | 66 |
[colors objectAtIndex:i%[colors count]],@"color",nil]; |
3551 | 67 |
[array addObject:dict]; |
68 |
[dict release]; |
|
69 |
} |
|
70 |
self.listOfTeams = array; |
|
71 |
[array release]; |
|
3697 | 72 |
|
3551 | 73 |
NSMutableArray *emptyArray = [[NSMutableArray alloc] initWithObjects:nil]; |
74 |
self.listOfSelectedTeams = emptyArray; |
|
75 |
[emptyArray release]; |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
76 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
77 |
selectedTeamsCount = [self.listOfSelectedTeams count]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
78 |
allTeamsCount = [self.listOfTeams count]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
79 |
|
4920 | 80 |
NSArray *contents = [[NSArray alloc] initWithArray:contentsOfDir copyItems:YES]; |
81 |
self.cachedContentsOfDir = contents; |
|
82 |
[contents release]; |
|
3547 | 83 |
} |
84 |
[self.tableView reloadData]; |
|
85 |
} |
|
86 |
||
87 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
|
88 |
return rotationManager(interfaceOrientation); |
|
89 |
} |
|
90 |
||
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
91 |
-(NSInteger) filterNumberOfHogs:(NSInteger) hogs { |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
92 |
NSInteger numberOfHogs; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
93 |
if (hogs <= HW_getMaxNumberOfHogs() && hogs >= 1) |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
94 |
numberOfHogs = hogs; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
95 |
else { |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
96 |
if (hogs > HW_getMaxNumberOfHogs()) |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
97 |
numberOfHogs = 1; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
98 |
else |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
99 |
numberOfHogs = HW_getMaxNumberOfHogs(); |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
100 |
} |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
101 |
return numberOfHogs; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
102 |
} |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
103 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
104 |
-(UIImage *)drawHogsRepeated:(NSInteger) manyTimes { |
5976
306cedbeb213
fixed several 'retina display' images and added a bunch more (though just from upscaling the normal ones; might be nice to have 'em redrawn at a real higher resolution)
koda
parents:
5208
diff
changeset
|
105 |
NSString *imgString = [[NSString alloc] initWithFormat:@"%@/hedgehog.png",[[NSBundle mainBundle] resourcePath]]; |
306cedbeb213
fixed several 'retina display' images and added a bunch more (though just from upscaling the normal ones; might be nice to have 'em redrawn at a real higher resolution)
koda
parents:
5208
diff
changeset
|
106 |
UIImage *hogSprite = [[UIImage alloc] initWithContentsOfFile:imgString]; |
306cedbeb213
fixed several 'retina display' images and added a bunch more (though just from upscaling the normal ones; might be nice to have 'em redrawn at a real higher resolution)
koda
parents:
5208
diff
changeset
|
107 |
[imgString release]; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
108 |
CGFloat screenScale = getScreenScale(); |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
109 |
int w = hogSprite.size.width * screenScale; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
110 |
int h = hogSprite.size.height * screenScale; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
111 |
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
112 |
CGContextRef context = CGBitmapContextCreate(NULL, w * 3, h, 8, 4 * w * 3, colorSpace, kCGImageAlphaPremultipliedFirst); |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
113 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
114 |
// draw the two images in the current context |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
115 |
for (int i = 0; i < manyTimes; i++) |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
116 |
CGContextDrawImage(context, CGRectMake(i*8*screenScale, 0, w, h), [hogSprite CGImage]); |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
117 |
[hogSprite release]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
118 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
119 |
// Create bitmap image info from pixel data in current context |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
120 |
CGImageRef imageRef = CGBitmapContextCreateImage(context); |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
121 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
122 |
// Create a new UIImage object |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
123 |
UIImage *resultImage; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
124 |
if ([self respondsToSelector:@selector(imageWithCGImage:scale:orientation:)]) |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
125 |
resultImage = [UIImage imageWithCGImage:imageRef scale:screenScale orientation:UIImageOrientationUp]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
126 |
else |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
127 |
resultImage = [UIImage imageWithCGImage:imageRef]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
128 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
129 |
// Release colorspace, context and bitmap information |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
130 |
CGColorSpaceRelease(colorSpace); |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
131 |
CGContextRelease(context); |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
132 |
CFRelease(imageRef); |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
133 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
134 |
return resultImage; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
135 |
} |
3547 | 136 |
|
137 |
#pragma mark - |
|
138 |
#pragma mark Table view data source |
|
139 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
140 |
return 2; |
|
141 |
} |
|
142 |
||
143 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
144 |
if (section == 0) |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
145 |
return selectedTeamsCount; |
3547 | 146 |
else |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
147 |
return allTeamsCount; |
3547 | 148 |
} |
149 |
||
150 |
// Customize the appearance of table view cells. |
|
151 |
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
152 |
static NSString *CellIdentifier0 = @"Cell0"; |
|
153 |
static NSString *CellIdentifier1 = @"Cell1"; |
|
154 |
NSInteger section = [indexPath section]; |
|
155 |
UITableViewCell *cell; |
|
3697 | 156 |
|
3547 | 157 |
if (section == 0) { |
158 |
cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier0]; |
|
159 |
if (cell == nil) { |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
160 |
cell = [[[HoldTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0] autorelease]; |
3697 | 161 |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
162 |
SquareButtonView *squareButton = [[SquareButtonView alloc] initWithFrame:CGRectMake(0, 0, 36, 36)]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
163 |
cell.accessoryView = squareButton; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
164 |
[squareButton release]; |
3547 | 165 |
} |
3697 | 166 |
|
3547 | 167 |
NSMutableDictionary *selectedRow = [listOfSelectedTeams objectAtIndex:[indexPath row]]; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
168 |
cell.textLabel.text = [[selectedRow objectForKey:@"team"] stringByDeletingPathExtension]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
169 |
cell.textLabel.backgroundColor = [UIColor clearColor]; |
3697 | 170 |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
171 |
SquareButtonView *squareButton = (SquareButtonView *)cell.accessoryView; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
172 |
[squareButton selectColor:[[selectedRow objectForKey:@"color"] intValue]]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
173 |
NSNumber *hogNumber = [selectedRow objectForKey:@"number"]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
174 |
[squareButton setTitle:[hogNumber stringValue] forState:UIControlStateNormal]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
175 |
squareButton.ownerDictionary = selectedRow; |
3697 | 176 |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
177 |
cell.imageView.image = [self drawHogsRepeated:[hogNumber intValue]]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
178 |
((HoldTableViewCell *)cell).delegate = self; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
179 |
} else { |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
180 |
cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier1]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
181 |
if (cell == nil) |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
182 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
183 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
184 |
cell.textLabel.text = [[[listOfTeams objectAtIndex:[indexPath row]] objectForKey:@"team"] stringByDeletingPathExtension]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
185 |
cell.textLabel.backgroundColor = [UIColor clearColor]; |
3814 | 186 |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
187 |
NSString *teamPath = [NSString stringWithFormat:@"%@/%@.plist",TEAMS_DIRECTORY(),cell.textLabel.text]; |
3814 | 188 |
NSDictionary *firstHog = [[[NSDictionary dictionaryWithContentsOfFile:teamPath] objectForKey:@"hedgehogs"] objectAtIndex:0]; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
189 |
if ([[firstHog objectForKey:@"level"] intValue] != 0) { |
5976
306cedbeb213
fixed several 'retina display' images and added a bunch more (though just from upscaling the normal ones; might be nice to have 'em redrawn at a real higher resolution)
koda
parents:
5208
diff
changeset
|
190 |
NSString *imgString = [[NSString alloc] initWithFormat:@"%@/robotBadge.png",[[NSBundle mainBundle] resourcePath]]; |
306cedbeb213
fixed several 'retina display' images and added a bunch more (though just from upscaling the normal ones; might be nice to have 'em redrawn at a real higher resolution)
koda
parents:
5208
diff
changeset
|
191 |
UIImage *sprite = [[UIImage alloc] initWithContentsOfFile:imgString]; |
306cedbeb213
fixed several 'retina display' images and added a bunch more (though just from upscaling the normal ones; might be nice to have 'em redrawn at a real higher resolution)
koda
parents:
5208
diff
changeset
|
192 |
[imgString release]; |
3814 | 193 |
UIImageView *spriteView = [[UIImageView alloc] initWithImage:sprite]; |
194 |
[sprite release]; |
|
195 |
||
196 |
cell.accessoryView = spriteView; |
|
197 |
[spriteView release]; |
|
198 |
} else |
|
199 |
cell.accessoryView = nil; |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
200 |
} |
3697 | 201 |
|
3917 | 202 |
cell.textLabel.textColor = UICOLOR_HW_YELLOW_TEXT; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
203 |
cell.backgroundColor = UICOLOR_HW_ALMOSTBLACK; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
204 |
cell.selectionStyle = UITableViewCellSelectionStyleNone; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
205 |
|
3547 | 206 |
return cell; |
207 |
} |
|
208 |
||
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
209 |
-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
210 |
return 40.0; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
211 |
} |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
212 |
|
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
213 |
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { |
3983
aa24192417a8
use labels instead of images, should save ram and space
koda
parents:
3971
diff
changeset
|
214 |
CGRect frame = CGRectMake(0, 0, self.view.frame.size.width * 80/100, 30); |
aa24192417a8
use labels instead of images, should save ram and space
koda
parents:
3971
diff
changeset
|
215 |
NSString *text; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
216 |
if (section == 0) |
3983
aa24192417a8
use labels instead of images, should save ram and space
koda
parents:
3971
diff
changeset
|
217 |
text = NSLocalizedString(@"Playing Teams",@""); |
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
218 |
else |
3983
aa24192417a8
use labels instead of images, should save ram and space
koda
parents:
3971
diff
changeset
|
219 |
text = NSLocalizedString(@"Available Teams",@""); |
aa24192417a8
use labels instead of images, should save ram and space
koda
parents:
3971
diff
changeset
|
220 |
UILabel *theLabel = createBlueLabel(text, frame); |
3780
7c704e69242e
fade in when returning from game, labels rewritten so that they are drawn at runtime (more flexibility with i18n and iphone support)
koda
parents:
3739
diff
changeset
|
221 |
theLabel.center = CGPointMake(self.view.frame.size.width/2, 20); |
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
222 |
|
3780
7c704e69242e
fade in when returning from game, labels rewritten so that they are drawn at runtime (more flexibility with i18n and iphone support)
koda
parents:
3739
diff
changeset
|
223 |
UIView *theView = [[[UIView alloc] init] autorelease]; |
7c704e69242e
fade in when returning from game, labels rewritten so that they are drawn at runtime (more flexibility with i18n and iphone support)
koda
parents:
3739
diff
changeset
|
224 |
[theView addSubview:theLabel]; |
7c704e69242e
fade in when returning from game, labels rewritten so that they are drawn at runtime (more flexibility with i18n and iphone support)
koda
parents:
3739
diff
changeset
|
225 |
[theLabel release]; |
7c704e69242e
fade in when returning from game, labels rewritten so that they are drawn at runtime (more flexibility with i18n and iphone support)
koda
parents:
3739
diff
changeset
|
226 |
return theView; |
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
227 |
} |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
228 |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
229 |
-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { |
4538 | 230 |
return IS_IPAD() ? 40 : 20; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
231 |
} |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
232 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
233 |
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger) section { |
4538 | 234 |
NSInteger height = IS_IPAD() ? 40 : 20; |
235 |
UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, height)]; |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
236 |
footer.backgroundColor = [UIColor clearColor]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
237 |
|
4538 | 238 |
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width*80/100, height)]; |
239 |
label.center = CGPointMake(self.tableView.frame.size.width/2, height/2); |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
240 |
label.textAlignment = UITextAlignmentCenter; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
241 |
label.font = [UIFont italicSystemFontOfSize:12]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
242 |
label.textColor = [UIColor whiteColor]; |
4538 | 243 |
label.numberOfLines = 2; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
244 |
if (section == 0) |
4538 | 245 |
label.text = NSLocalizedString(@"Tap to add hogs or change color, touch and hold to remove a team.",@""); |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
246 |
else |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
247 |
label.text = NSLocalizedString(@"The robot badge indicates an AI-controlled team.",@""); |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
248 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
249 |
label.backgroundColor = [UIColor clearColor]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
250 |
[footer addSubview:label]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
251 |
[label release]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
252 |
return [footer autorelease]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
253 |
} |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
254 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
255 |
|
3547 | 256 |
#pragma mark - |
257 |
#pragma mark Table view delegate |
|
258 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
259 |
NSInteger row = [indexPath row]; |
|
260 |
NSInteger section = [indexPath section]; |
|
261 |
||
4486 | 262 |
if (section == 1 && [self.listOfTeams count] > row) { |
3547 | 263 |
[self.listOfSelectedTeams addObject:[self.listOfTeams objectAtIndex:row]]; |
3697 | 264 |
[self.listOfTeams removeObjectAtIndex:row]; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
265 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
266 |
NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:selectedTeamsCount inSection:0]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
267 |
allTeamsCount--; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
268 |
selectedTeamsCount++; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
269 |
[aTableView beginUpdates]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
270 |
[aTableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationRight]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
271 |
[aTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
272 |
[aTableView endUpdates]; |
3547 | 273 |
} |
4486 | 274 |
if (section == 0 && [self.listOfSelectedTeams count] > row) { |
275 |
NSMutableDictionary *selectedRow = [self.listOfSelectedTeams objectAtIndex:row]; |
|
276 |
UITableViewCell *cell = [aTableView cellForRowAtIndexPath:indexPath]; |
|
277 |
SquareButtonView *squareButton = (SquareButtonView *)cell.accessoryView; |
|
278 |
||
279 |
NSInteger increaseNumber = [[selectedRow objectForKey:@"number"] intValue] + 1; |
|
280 |
NSNumber *newNumber = [NSNumber numberWithInt:[self filterNumberOfHogs:increaseNumber]]; |
|
281 |
[squareButton setTitle:[newNumber stringValue] forState:UIControlStateNormal]; |
|
282 |
[selectedRow setObject:newNumber forKey:@"number"]; |
|
283 |
||
284 |
cell.imageView.image = [self drawHogsRepeated:[newNumber intValue]]; |
|
285 |
} |
|
3547 | 286 |
} |
287 |
||
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
288 |
-(void) holdAction:(NSString *)content { |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
289 |
NSInteger row; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
290 |
for (row = 0; row < [self.listOfSelectedTeams count]; row++) { |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
291 |
NSDictionary *dict = [self.listOfSelectedTeams objectAtIndex:row]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
292 |
if ([content isEqualToString:[[dict objectForKey:@"team"] stringByDeletingPathExtension]]) |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
293 |
break; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
294 |
} |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
295 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
296 |
[self.listOfTeams addObject:[self.listOfSelectedTeams objectAtIndex:row]]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
297 |
[self.listOfSelectedTeams removeObjectAtIndex:row]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
298 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
299 |
[self.tableView beginUpdates]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
300 |
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:row inSection:0]] withRowAnimation:UITableViewRowAnimationLeft]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
301 |
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:allTeamsCount inSection:1]] withRowAnimation:UITableViewRowAnimationLeft]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
302 |
allTeamsCount++; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
303 |
selectedTeamsCount--; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
304 |
[self.tableView endUpdates]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
305 |
} |
3547 | 306 |
|
307 |
#pragma mark - |
|
308 |
#pragma mark Memory management |
|
309 |
-(void) didReceiveMemoryWarning { |
|
310 |
// Relinquish ownership any cached data, images, etc that aren't in use. |
|
3739 | 311 |
self.cachedContentsOfDir = nil; |
3971 | 312 |
MSG_MEMCLEAN(); |
313 |
[super didReceiveMemoryWarning]; |
|
3547 | 314 |
} |
315 |
||
316 |
-(void) viewDidUnload { |
|
317 |
self.listOfTeams = nil; |
|
3739 | 318 |
self.listOfSelectedTeams = nil; |
319 |
self.cachedContentsOfDir = nil; |
|
3662
a44406f4369b
polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents:
3659
diff
changeset
|
320 |
MSG_DIDUNLOAD(); |
3547 | 321 |
[super viewDidUnload]; |
322 |
} |
|
323 |
||
324 |
||
325 |
-(void) dealloc { |
|
5208 | 326 |
releaseAndNil(listOfTeams); |
327 |
releaseAndNil(listOfSelectedTeams); |
|
328 |
releaseAndNil(cachedContentsOfDir); |
|
3547 | 329 |
[super dealloc]; |
330 |
} |
|
331 |
||
332 |
||
333 |
@end |
|
334 |