author | dag10 <gottlieb.drew@gmail.com> |
Wed, 16 Jan 2013 18:34:43 -0500 | |
changeset 8393 | 85bd6c7b2641 |
parent 6908 | 896ed2afcfb8 |
child 8441 | a00b0fa0dbd7 |
permissions | -rw-r--r-- |
3829 | 1 |
/* |
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
|
6700 | 3 |
* Copyright (c) 2009-2012 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 |
||
3547 | 19 |
|
20 |
#import "TeamConfigViewController.h" |
|
6108 | 21 |
#import <QuartzCore/QuartzCore.h> |
3547 | 22 |
#import "SquareButtonView.h" |
23 |
||
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
|
24 |
|
3547 | 25 |
@implementation TeamConfigViewController |
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
26 |
@synthesize tableView, selectedTeamsCount, allTeamsCount, listOfAllTeams, listOfSelectedTeams, cachedContentsOfDir; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
27 |
|
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
28 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
29 |
return rotationManager(interfaceOrientation); |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
30 |
} |
3547 | 31 |
|
32 |
#pragma mark - |
|
33 |
#pragma mark View lifecycle |
|
34 |
-(void) viewDidLoad { |
|
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
35 |
UITableView *aTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
36 |
style:UITableViewStyleGrouped]; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
37 |
aTableView.delegate = self; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
38 |
aTableView.dataSource = self; |
6108 | 39 |
if (IS_IPAD()) { |
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
40 |
[aTableView setBackgroundColorForAnyTable:[UIColor darkBlueColorTransparent]]; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
41 |
aTableView.layer.borderColor = [[UIColor darkYellowColor] CGColor]; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
42 |
aTableView.layer.borderWidth = 2.7f; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
43 |
aTableView.layer.cornerRadius = 8; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
44 |
aTableView.contentInset = UIEdgeInsetsMake(10, 0, 10, 0); |
6108 | 45 |
} else { |
46 |
UIImage *backgroundImage = [[UIImage alloc] initWithContentsOfFile:@"background~iphone.png"]; |
|
47 |
UIImageView *background = [[UIImageView alloc] initWithImage:backgroundImage]; |
|
48 |
[backgroundImage release]; |
|
6220 | 49 |
[self.view addSubview:background]; |
6108 | 50 |
[background release]; |
6220 | 51 |
[aTableView setBackgroundColorForAnyTable:[UIColor clearColor]]; |
6108 | 52 |
} |
4244 | 53 |
|
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
54 |
aTableView.indicatorStyle = UIScrollViewIndicatorStyleWhite; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
55 |
aTableView.separatorColor = [UIColor whiteColor]; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
56 |
aTableView.separatorStyle = UITableViewCellSeparatorStyleNone; |
6634
e00762923086
ios game configuration page supports rotation, with some enhancements (like the new slider); some glitches here and there
koda
parents:
6264
diff
changeset
|
57 |
aTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; |
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
58 |
self.tableView = aTableView; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
59 |
[aTableView release]; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
60 |
|
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
61 |
[self.view addSubview:self.tableView]; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
62 |
[super viewDidLoad]; |
3547 | 63 |
} |
64 |
||
65 |
-(void) viewWillAppear:(BOOL)animated { |
|
3739 | 66 |
NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:TEAMS_DIRECTORY() error:NULL]; |
3971 | 67 |
if ([self.cachedContentsOfDir isEqualToArray:contentsOfDir] == NO) { |
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
68 |
self.cachedContentsOfDir = contentsOfDir; |
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
|
69 |
NSArray *colors = [HWUtils teamColors]; |
3551 | 70 |
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:[contentsOfDir count]]; |
6908
896ed2afcfb8
ios: turn on more warning messages and start correcting them
koda
parents:
6832
diff
changeset
|
71 |
for (NSUInteger i = 0; i < [contentsOfDir count]; i++) { |
3551 | 72 |
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys: |
73 |
[contentsOfDir objectAtIndex:i],@"team", |
|
74 |
[NSNumber numberWithInt:4],@"number", |
|
3917 | 75 |
[colors objectAtIndex:i%[colors count]],@"color",nil]; |
3551 | 76 |
[array addObject:dict]; |
77 |
[dict release]; |
|
78 |
} |
|
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
79 |
self.listOfAllTeams = array; |
3551 | 80 |
[array release]; |
3697 | 81 |
|
3551 | 82 |
NSMutableArray *emptyArray = [[NSMutableArray alloc] initWithObjects:nil]; |
83 |
self.listOfSelectedTeams = emptyArray; |
|
84 |
[emptyArray release]; |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
85 |
|
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
86 |
self.selectedTeamsCount = [self.listOfSelectedTeams count]; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
87 |
self.allTeamsCount = [self.listOfAllTeams count]; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
88 |
[self.tableView reloadData]; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
89 |
} |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
90 |
|
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
91 |
[super viewWillAppear:animated]; |
3547 | 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 |
|
3547 | 107 |
#pragma mark - |
108 |
#pragma mark Table view data source |
|
109 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
110 |
return 2; |
|
111 |
} |
|
112 |
||
113 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
114 |
return (section == 0 ? self.selectedTeamsCount : self.allTeamsCount); |
3547 | 115 |
} |
116 |
||
117 |
// Customize the appearance of table view cells. |
|
118 |
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
119 |
static NSString *CellIdentifier0 = @"Cell0"; |
|
120 |
static NSString *CellIdentifier1 = @"Cell1"; |
|
121 |
NSInteger section = [indexPath section]; |
|
122 |
UITableViewCell *cell; |
|
3697 | 123 |
|
3547 | 124 |
if (section == 0) { |
125 |
cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier0]; |
|
126 |
if (cell == nil) { |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
127 |
cell = [[[HoldTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0] autorelease]; |
3697 | 128 |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
129 |
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
|
130 |
cell.accessoryView = squareButton; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
131 |
[squareButton release]; |
3547 | 132 |
} |
3697 | 133 |
|
3547 | 134 |
NSMutableDictionary *selectedRow = [listOfSelectedTeams objectAtIndex:[indexPath row]]; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
135 |
cell.textLabel.text = [[selectedRow objectForKey:@"team"] stringByDeletingPathExtension]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
136 |
cell.textLabel.backgroundColor = [UIColor clearColor]; |
3697 | 137 |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
138 |
SquareButtonView *squareButton = (SquareButtonView *)cell.accessoryView; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
139 |
[squareButton selectColor:[[selectedRow objectForKey:@"color"] intValue]]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
140 |
NSNumber *hogNumber = [selectedRow objectForKey:@"number"]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
141 |
[squareButton setTitle:[hogNumber stringValue] forState:UIControlStateNormal]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
142 |
squareButton.ownerDictionary = selectedRow; |
3697 | 143 |
|
6209 | 144 |
cell.imageView.image = [UIImage drawHogsRepeated:[hogNumber intValue]]; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
145 |
((HoldTableViewCell *)cell).delegate = self; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
146 |
} else { |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
147 |
cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier1]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
148 |
if (cell == nil) |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
149 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
150 |
|
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
151 |
cell.textLabel.text = [[[self.listOfAllTeams objectAtIndex:[indexPath row]] objectForKey:@"team"] stringByDeletingPathExtension]; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
152 |
cell.textLabel.backgroundColor = [UIColor clearColor]; |
3814 | 153 |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
154 |
NSString *teamPath = [NSString stringWithFormat:@"%@/%@.plist",TEAMS_DIRECTORY(),cell.textLabel.text]; |
3814 | 155 |
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
|
156 |
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
|
157 |
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
|
158 |
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
|
159 |
[imgString release]; |
3814 | 160 |
UIImageView *spriteView = [[UIImageView alloc] initWithImage:sprite]; |
161 |
[sprite release]; |
|
162 |
||
163 |
cell.accessoryView = spriteView; |
|
164 |
[spriteView release]; |
|
165 |
} else |
|
166 |
cell.accessoryView = nil; |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
167 |
} |
3697 | 168 |
|
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
|
169 |
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
|
170 |
cell.backgroundColor = [UIColor blackColorTransparent]; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
171 |
cell.selectionStyle = UITableViewCellSelectionStyleNone; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
172 |
|
3547 | 173 |
return cell; |
174 |
} |
|
175 |
||
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
176 |
-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { |
6108 | 177 |
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
|
178 |
} |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
179 |
|
6636 | 180 |
-(UIView *)tableView:(UITableView *)aTableView viewForHeaderInSection:(NSInteger)section { |
181 |
CGRect frame = CGRectMake(0, 0, self.view.frame.size.width * 70/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
|
182 |
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
|
183 |
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
|
184 |
theLabel.center = CGPointMake(self.view.frame.size.width/2, 20); |
6636 | 185 |
theLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; |
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
186 |
|
6636 | 187 |
UIView *theView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, aTableView.frame.size.width, 30)]; |
188 |
theView.autoresizingMask = UIViewAutoresizingFlexibleWidth; |
|
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
|
189 |
[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
|
190 |
[theLabel release]; |
6636 | 191 |
return [theView autorelease]; |
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
192 |
} |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
193 |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
194 |
-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { |
4538 | 195 |
return IS_IPAD() ? 40 : 20; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
196 |
} |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
197 |
|
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
198 |
-(UIView *)tableView:(UITableView *)aTableView viewForFooterInSection:(NSInteger) section { |
4538 | 199 |
NSInteger height = IS_IPAD() ? 40 : 20; |
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
200 |
UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, aTableView.frame.size.width, height)]; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
201 |
footer.backgroundColor = [UIColor clearColor]; |
6636 | 202 |
footer.autoresizingMask = UIViewAutoresizingFlexibleWidth; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
203 |
|
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
204 |
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, aTableView.frame.size.width*80/100, height)]; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
205 |
label.center = CGPointMake(aTableView.frame.size.width/2, height/2); |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
206 |
label.textAlignment = UITextAlignmentCenter; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
207 |
label.font = [UIFont italicSystemFontOfSize:12]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
208 |
label.textColor = [UIColor whiteColor]; |
4538 | 209 |
label.numberOfLines = 2; |
6636 | 210 |
label.backgroundColor = [UIColor clearColor]; |
211 |
label.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; |
|
212 |
||
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
213 |
if (section == 0) |
4538 | 214 |
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
|
215 |
else |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
216 |
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
|
217 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
218 |
[footer addSubview:label]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
219 |
[label release]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
220 |
return [footer autorelease]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
221 |
} |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
222 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
223 |
|
3547 | 224 |
#pragma mark - |
225 |
#pragma mark Table view delegate |
|
226 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
6908
896ed2afcfb8
ios: turn on more warning messages and start correcting them
koda
parents:
6832
diff
changeset
|
227 |
NSUInteger row = [indexPath row]; |
896ed2afcfb8
ios: turn on more warning messages and start correcting them
koda
parents:
6832
diff
changeset
|
228 |
NSUInteger section = [indexPath section]; |
3547 | 229 |
|
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
230 |
if (section == 1 && [self.listOfAllTeams count] > row) { |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
231 |
[self.listOfSelectedTeams addObject:[self.listOfAllTeams objectAtIndex:row]]; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
232 |
[self.listOfAllTeams removeObjectAtIndex:row]; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
233 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
234 |
NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:selectedTeamsCount inSection:0]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
235 |
allTeamsCount--; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
236 |
selectedTeamsCount++; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
237 |
[aTableView beginUpdates]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
238 |
[aTableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationRight]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
239 |
[aTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
240 |
[aTableView endUpdates]; |
3547 | 241 |
} |
4486 | 242 |
if (section == 0 && [self.listOfSelectedTeams count] > row) { |
243 |
NSMutableDictionary *selectedRow = [self.listOfSelectedTeams objectAtIndex:row]; |
|
244 |
UITableViewCell *cell = [aTableView cellForRowAtIndexPath:indexPath]; |
|
245 |
SquareButtonView *squareButton = (SquareButtonView *)cell.accessoryView; |
|
246 |
||
247 |
NSInteger increaseNumber = [[selectedRow objectForKey:@"number"] intValue] + 1; |
|
248 |
NSNumber *newNumber = [NSNumber numberWithInt:[self filterNumberOfHogs:increaseNumber]]; |
|
249 |
[squareButton setTitle:[newNumber stringValue] forState:UIControlStateNormal]; |
|
250 |
[selectedRow setObject:newNumber forKey:@"number"]; |
|
251 |
||
6209 | 252 |
cell.imageView.image = [UIImage drawHogsRepeated:[newNumber intValue]]; |
4486 | 253 |
} |
3547 | 254 |
} |
255 |
||
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
256 |
-(void) holdAction:(NSString *)content onTable:(UITableView *)aTableView { |
6908
896ed2afcfb8
ios: turn on more warning messages and start correcting them
koda
parents:
6832
diff
changeset
|
257 |
NSUInteger row; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
258 |
for (row = 0; row < [self.listOfSelectedTeams count]; row++) { |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
259 |
NSDictionary *dict = [self.listOfSelectedTeams objectAtIndex:row]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
260 |
if ([content isEqualToString:[[dict objectForKey:@"team"] stringByDeletingPathExtension]]) |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
261 |
break; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
262 |
} |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
263 |
|
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
264 |
[self.listOfAllTeams addObject:[self.listOfSelectedTeams objectAtIndex:row]]; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
265 |
[self.listOfSelectedTeams removeObjectAtIndex:row]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
266 |
|
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
267 |
[aTableView beginUpdates]; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
268 |
[aTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:row inSection:0]] withRowAnimation:UITableViewRowAnimationLeft]; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
269 |
[aTableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:allTeamsCount inSection:1]] withRowAnimation:UITableViewRowAnimationLeft]; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
270 |
self.allTeamsCount++; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
271 |
self.selectedTeamsCount--; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
272 |
[aTableView endUpdates]; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
273 |
} |
3547 | 274 |
|
275 |
#pragma mark - |
|
276 |
#pragma mark Memory management |
|
277 |
-(void) didReceiveMemoryWarning { |
|
3739 | 278 |
self.cachedContentsOfDir = nil; |
3971 | 279 |
MSG_MEMCLEAN(); |
280 |
[super didReceiveMemoryWarning]; |
|
3547 | 281 |
} |
282 |
||
283 |
-(void) viewDidUnload { |
|
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
284 |
self.tableView = nil; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
285 |
self.listOfAllTeams = nil; |
3739 | 286 |
self.listOfSelectedTeams = nil; |
287 |
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
|
288 |
MSG_DIDUNLOAD(); |
3547 | 289 |
[super viewDidUnload]; |
290 |
} |
|
291 |
||
292 |
||
293 |
-(void) dealloc { |
|
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
294 |
releaseAndNil(tableView); |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
295 |
releaseAndNil(listOfAllTeams); |
5208 | 296 |
releaseAndNil(listOfSelectedTeams); |
297 |
releaseAndNil(cachedContentsOfDir); |
|
3547 | 298 |
[super dealloc]; |
299 |
} |
|
300 |
||
301 |
||
302 |
@end |
|
303 |