author | koda |
Sun, 09 Oct 2011 03:04:45 +0200 | |
changeset 6109 | f6726ec81e64 |
parent 6108 | 7a8da11a6144 |
child 6115 | 485cfecadc9a |
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" |
|
6108 | 23 |
#import <QuartzCore/QuartzCore.h> |
3547 | 24 |
#import "SquareButtonView.h" |
25 |
||
6078
8c0cc07731e5
headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
5976
diff
changeset
|
26 |
|
3547 | 27 |
@implementation TeamConfigViewController |
3739 | 28 |
@synthesize listOfTeams, listOfSelectedTeams, cachedContentsOfDir; |
3547 | 29 |
|
30 |
#pragma mark - |
|
31 |
#pragma mark View lifecycle |
|
32 |
-(void) viewDidLoad { |
|
33 |
[super viewDidLoad]; |
|
3697 | 34 |
|
3547 | 35 |
CGSize screenSize = [[UIScreen mainScreen] bounds].size; |
36 |
self.view.frame = CGRectMake(0, 0, screenSize.height, screenSize.width - 44); |
|
4082 | 37 |
|
6108 | 38 |
if (IS_IPAD()) { |
39 |
[self.tableView setBackgroundColorForAnyTable:[UIColor darkBlueColorTransparent]]; |
|
40 |
self.tableView.layer.borderColor = [[UIColor darkYellowColor] CGColor]; |
|
41 |
self.tableView.layer.borderWidth = 2.7f; |
|
42 |
self.tableView.layer.cornerRadius = 8; |
|
43 |
self.tableView.contentInset = UIEdgeInsetsMake(10, 0, 10, 0); |
|
44 |
} else { |
|
45 |
UIImage *backgroundImage = [[UIImage alloc] initWithContentsOfFile:@"background~iphone.png"]; |
|
46 |
UIImageView *background = [[UIImageView alloc] initWithImage:backgroundImage]; |
|
47 |
[backgroundImage release]; |
|
48 |
[self.tableView setBackgroundView:background]; |
|
49 |
[background release]; |
|
50 |
} |
|
4244 | 51 |
|
6108 | 52 |
self.tableView.indicatorStyle = UIScrollViewIndicatorStyleWhite; |
53 |
self.tableView.separatorColor = [UIColor whiteColor]; |
|
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
54 |
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; |
3547 | 55 |
} |
56 |
||
57 |
-(void) viewWillAppear:(BOOL)animated { |
|
58 |
[super viewWillAppear:animated]; |
|
59 |
||
3739 | 60 |
NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:TEAMS_DIRECTORY() error:NULL]; |
3551 | 61 |
// avoid overwriting selected teams when returning on this view |
3971 | 62 |
if ([self.cachedContentsOfDir isEqualToArray:contentsOfDir] == NO) { |
6078
8c0cc07731e5
headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
5976
diff
changeset
|
63 |
NSArray *colors = [HWUtils teamColors]; |
3551 | 64 |
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:[contentsOfDir count]]; |
65 |
for (int i = 0; i < [contentsOfDir count]; i++) { |
|
66 |
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys: |
|
67 |
[contentsOfDir objectAtIndex:i],@"team", |
|
68 |
[NSNumber numberWithInt:4],@"number", |
|
3917 | 69 |
[colors objectAtIndex:i%[colors count]],@"color",nil]; |
3551 | 70 |
[array addObject:dict]; |
71 |
[dict release]; |
|
72 |
} |
|
73 |
self.listOfTeams = array; |
|
74 |
[array release]; |
|
3697 | 75 |
|
3551 | 76 |
NSMutableArray *emptyArray = [[NSMutableArray alloc] initWithObjects:nil]; |
77 |
self.listOfSelectedTeams = emptyArray; |
|
78 |
[emptyArray release]; |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
79 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
80 |
selectedTeamsCount = [self.listOfSelectedTeams count]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
81 |
allTeamsCount = [self.listOfTeams count]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
82 |
|
4920 | 83 |
NSArray *contents = [[NSArray alloc] initWithArray:contentsOfDir copyItems:YES]; |
84 |
self.cachedContentsOfDir = contents; |
|
85 |
[contents release]; |
|
3547 | 86 |
} |
87 |
[self.tableView reloadData]; |
|
88 |
} |
|
89 |
||
90 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
|
91 |
return rotationManager(interfaceOrientation); |
|
92 |
} |
|
93 |
||
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
94 |
-(NSInteger) filterNumberOfHogs:(NSInteger) hogs { |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
95 |
NSInteger numberOfHogs; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
96 |
if (hogs <= HW_getMaxNumberOfHogs() && hogs >= 1) |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
97 |
numberOfHogs = hogs; |
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 |
if (hogs > HW_getMaxNumberOfHogs()) |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
100 |
numberOfHogs = 1; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
101 |
else |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
102 |
numberOfHogs = HW_getMaxNumberOfHogs(); |
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 |
return numberOfHogs; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
105 |
} |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
106 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
107 |
-(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
|
108 |
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
|
109 |
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
|
110 |
[imgString release]; |
6078
8c0cc07731e5
headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
5976
diff
changeset
|
111 |
CGFloat screenScale = [[UIScreen mainScreen] scale]; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
112 |
int w = hogSprite.size.width * screenScale; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
113 |
int h = hogSprite.size.height * screenScale; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
114 |
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
115 |
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
|
116 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
117 |
// draw the two images in the current context |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
118 |
for (int i = 0; i < manyTimes; i++) |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
119 |
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
|
120 |
[hogSprite release]; |
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 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
|
123 |
CGImageRef imageRef = CGBitmapContextCreateImage(context); |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
124 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
125 |
// Create a new UIImage object |
6078
8c0cc07731e5
headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
5976
diff
changeset
|
126 |
UIImage *resultImage = [UIImage imageWithCGImage:imageRef scale:screenScale orientation:UIImageOrientationUp]; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
127 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
128 |
// Release colorspace, context and bitmap information |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
129 |
CGColorSpaceRelease(colorSpace); |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
130 |
CGContextRelease(context); |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
131 |
CFRelease(imageRef); |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
132 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
133 |
return resultImage; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
134 |
} |
3547 | 135 |
|
136 |
#pragma mark - |
|
137 |
#pragma mark Table view data source |
|
138 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
139 |
return 2; |
|
140 |
} |
|
141 |
||
142 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
6107 | 143 |
return (section == 0 ? selectedTeamsCount : allTeamsCount); |
3547 | 144 |
} |
145 |
||
146 |
// Customize the appearance of table view cells. |
|
147 |
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
148 |
static NSString *CellIdentifier0 = @"Cell0"; |
|
149 |
static NSString *CellIdentifier1 = @"Cell1"; |
|
150 |
NSInteger section = [indexPath section]; |
|
151 |
UITableViewCell *cell; |
|
3697 | 152 |
|
3547 | 153 |
if (section == 0) { |
154 |
cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier0]; |
|
155 |
if (cell == nil) { |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
156 |
cell = [[[HoldTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0] autorelease]; |
3697 | 157 |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
158 |
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
|
159 |
cell.accessoryView = squareButton; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
160 |
[squareButton release]; |
3547 | 161 |
} |
3697 | 162 |
|
3547 | 163 |
NSMutableDictionary *selectedRow = [listOfSelectedTeams objectAtIndex:[indexPath row]]; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
164 |
cell.textLabel.text = [[selectedRow objectForKey:@"team"] stringByDeletingPathExtension]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
165 |
cell.textLabel.backgroundColor = [UIColor clearColor]; |
3697 | 166 |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
167 |
SquareButtonView *squareButton = (SquareButtonView *)cell.accessoryView; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
168 |
[squareButton selectColor:[[selectedRow objectForKey:@"color"] intValue]]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
169 |
NSNumber *hogNumber = [selectedRow objectForKey:@"number"]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
170 |
[squareButton setTitle:[hogNumber stringValue] forState:UIControlStateNormal]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
171 |
squareButton.ownerDictionary = selectedRow; |
3697 | 172 |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
173 |
cell.imageView.image = [self drawHogsRepeated:[hogNumber intValue]]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
174 |
((HoldTableViewCell *)cell).delegate = self; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
175 |
} else { |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
176 |
cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier1]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
177 |
if (cell == nil) |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
178 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
179 |
|
6107 | 180 |
cell.textLabel.text = [[[self.listOfTeams objectAtIndex:[indexPath row]] objectForKey:@"team"] stringByDeletingPathExtension]; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
181 |
cell.textLabel.backgroundColor = [UIColor clearColor]; |
3814 | 182 |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
183 |
NSString *teamPath = [NSString stringWithFormat:@"%@/%@.plist",TEAMS_DIRECTORY(),cell.textLabel.text]; |
3814 | 184 |
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
|
185 |
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
|
186 |
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
|
187 |
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
|
188 |
[imgString release]; |
3814 | 189 |
UIImageView *spriteView = [[UIImageView alloc] initWithImage:sprite]; |
190 |
[sprite release]; |
|
191 |
||
192 |
cell.accessoryView = spriteView; |
|
193 |
[spriteView release]; |
|
194 |
} else |
|
195 |
cell.accessoryView = nil; |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
196 |
} |
3697 | 197 |
|
6078
8c0cc07731e5
headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
5976
diff
changeset
|
198 |
cell.textLabel.textColor = [UIColor lightYellowColor]; |
8c0cc07731e5
headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
5976
diff
changeset
|
199 |
cell.backgroundColor = [UIColor blackColorTransparent]; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
200 |
cell.selectionStyle = UITableViewCellSelectionStyleNone; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
201 |
|
3547 | 202 |
return cell; |
203 |
} |
|
204 |
||
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
205 |
-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { |
6108 | 206 |
return 45.0; |
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
207 |
} |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
208 |
|
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
209 |
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { |
3983
aa24192417a8
use labels instead of images, should save ram and space
koda
parents:
3971
diff
changeset
|
210 |
CGRect frame = CGRectMake(0, 0, self.view.frame.size.width * 80/100, 30); |
6078
8c0cc07731e5
headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
5976
diff
changeset
|
211 |
NSString *text = (section == 0) ? NSLocalizedString(@"Playing Teams",@"") : NSLocalizedString(@"Available Teams",@""); |
8c0cc07731e5
headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
5976
diff
changeset
|
212 |
UILabel *theLabel = [[UILabel alloc] initWithFrame:frame andTitle:text]; |
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
|
213 |
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
|
214 |
|
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
|
215 |
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
|
216 |
[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
|
217 |
[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
|
218 |
return theView; |
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
219 |
} |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
220 |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
221 |
-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { |
4538 | 222 |
return IS_IPAD() ? 40 : 20; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
223 |
} |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
224 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
225 |
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger) section { |
4538 | 226 |
NSInteger height = IS_IPAD() ? 40 : 20; |
227 |
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
|
228 |
footer.backgroundColor = [UIColor clearColor]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
229 |
|
4538 | 230 |
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width*80/100, height)]; |
231 |
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
|
232 |
label.textAlignment = UITextAlignmentCenter; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
233 |
label.font = [UIFont italicSystemFontOfSize:12]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
234 |
label.textColor = [UIColor whiteColor]; |
4538 | 235 |
label.numberOfLines = 2; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
236 |
if (section == 0) |
4538 | 237 |
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
|
238 |
else |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
239 |
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
|
240 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
241 |
label.backgroundColor = [UIColor clearColor]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
242 |
[footer addSubview:label]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
243 |
[label release]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
244 |
return [footer autorelease]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
245 |
} |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
246 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
247 |
|
3547 | 248 |
#pragma mark - |
249 |
#pragma mark Table view delegate |
|
250 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
251 |
NSInteger row = [indexPath row]; |
|
252 |
NSInteger section = [indexPath section]; |
|
253 |
||
4486 | 254 |
if (section == 1 && [self.listOfTeams count] > row) { |
3547 | 255 |
[self.listOfSelectedTeams addObject:[self.listOfTeams objectAtIndex:row]]; |
3697 | 256 |
[self.listOfTeams removeObjectAtIndex:row]; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
257 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
258 |
NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:selectedTeamsCount inSection:0]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
259 |
allTeamsCount--; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
260 |
selectedTeamsCount++; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
261 |
[aTableView beginUpdates]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
262 |
[aTableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationRight]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
263 |
[aTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
264 |
[aTableView endUpdates]; |
3547 | 265 |
} |
4486 | 266 |
if (section == 0 && [self.listOfSelectedTeams count] > row) { |
267 |
NSMutableDictionary *selectedRow = [self.listOfSelectedTeams objectAtIndex:row]; |
|
268 |
UITableViewCell *cell = [aTableView cellForRowAtIndexPath:indexPath]; |
|
269 |
SquareButtonView *squareButton = (SquareButtonView *)cell.accessoryView; |
|
270 |
||
271 |
NSInteger increaseNumber = [[selectedRow objectForKey:@"number"] intValue] + 1; |
|
272 |
NSNumber *newNumber = [NSNumber numberWithInt:[self filterNumberOfHogs:increaseNumber]]; |
|
273 |
[squareButton setTitle:[newNumber stringValue] forState:UIControlStateNormal]; |
|
274 |
[selectedRow setObject:newNumber forKey:@"number"]; |
|
275 |
||
276 |
cell.imageView.image = [self drawHogsRepeated:[newNumber intValue]]; |
|
277 |
} |
|
3547 | 278 |
} |
279 |
||
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
280 |
-(void) holdAction:(NSString *)content { |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
281 |
NSInteger row; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
282 |
for (row = 0; row < [self.listOfSelectedTeams count]; row++) { |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
283 |
NSDictionary *dict = [self.listOfSelectedTeams objectAtIndex:row]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
284 |
if ([content isEqualToString:[[dict objectForKey:@"team"] stringByDeletingPathExtension]]) |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
285 |
break; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
286 |
} |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
287 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
288 |
[self.listOfTeams addObject:[self.listOfSelectedTeams objectAtIndex:row]]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
289 |
[self.listOfSelectedTeams removeObjectAtIndex:row]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
290 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
291 |
[self.tableView beginUpdates]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
292 |
[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
|
293 |
[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
|
294 |
allTeamsCount++; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
295 |
selectedTeamsCount--; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
296 |
[self.tableView endUpdates]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
297 |
} |
3547 | 298 |
|
299 |
#pragma mark - |
|
300 |
#pragma mark Memory management |
|
301 |
-(void) didReceiveMemoryWarning { |
|
6107 | 302 |
if ([[HedgewarsAppDelegate sharedAppDelegate] isInGame]) { |
303 |
self.listOfSelectedTeams = nil; |
|
304 |
self.listOfTeams = nil; |
|
305 |
} |
|
3739 | 306 |
self.cachedContentsOfDir = nil; |
3971 | 307 |
MSG_MEMCLEAN(); |
308 |
[super didReceiveMemoryWarning]; |
|
3547 | 309 |
} |
310 |
||
311 |
-(void) viewDidUnload { |
|
312 |
self.listOfTeams = nil; |
|
3739 | 313 |
self.listOfSelectedTeams = nil; |
314 |
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
|
315 |
MSG_DIDUNLOAD(); |
3547 | 316 |
[super viewDidUnload]; |
317 |
} |
|
318 |
||
319 |
||
320 |
-(void) dealloc { |
|
5208 | 321 |
releaseAndNil(listOfTeams); |
322 |
releaseAndNil(listOfSelectedTeams); |
|
323 |
releaseAndNil(cachedContentsOfDir); |
|
3547 | 324 |
[super dealloc]; |
325 |
} |
|
326 |
||
327 |
||
328 |
@end |
|
329 |