author | koda |
Tue, 07 Feb 2012 02:10:15 +0100 | |
changeset 6646 | 436289cfebf5 |
parent 6078 | 8c0cc07731e5 |
child 6700 | e04da46ee43c |
permissions | -rw-r--r-- |
4757 | 1 |
/* |
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
|
4976 | 3 |
* Copyright (c) 2009-2011 Vittorio Giovara <vittorio.giovara@gmail.com> |
4757 | 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 30/12/2010. |
|
19 |
*/ |
|
20 |
||
21 |
||
22 |
#import "StatsPageViewController.h" |
|
6004 | 23 |
#import <QuartzCore/QuartzCore.h> |
4757 | 24 |
|
25 |
@implementation StatsPageViewController |
|
4760 | 26 |
@synthesize statsArray; |
4757 | 27 |
|
28 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
29 |
return rotationManager(interfaceOrientation); |
|
30 |
} |
|
31 |
||
4766 | 32 |
-(void) viewDidLoad { |
33 |
if ([self.tableView respondsToSelector:@selector(setBackgroundView:)]) |
|
34 |
self.tableView.backgroundView = nil; |
|
35 |
||
36 |
NSString *imgName; |
|
37 |
if (IS_IPAD()) |
|
38 |
imgName = @"mediumBackground~ipad.png"; |
|
39 |
else |
|
40 |
imgName = @"smallerBackground~iphone.png"; |
|
41 |
||
42 |
if ([self.tableView respondsToSelector:@selector(setBackgroundView:)]) { |
|
43 |
UIImage *backgroundImage = [[UIImage alloc] initWithContentsOfFile:imgName]; |
|
44 |
UIImageView *background = [[UIImageView alloc] initWithImage:backgroundImage]; |
|
45 |
[backgroundImage release]; |
|
46 |
[self.tableView setBackgroundView:background]; |
|
47 |
[background release]; |
|
48 |
} else |
|
49 |
self.view.backgroundColor = [UIColor blackColor]; |
|
50 |
||
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:
6017
diff
changeset
|
51 |
self.tableView.separatorColor = [UIColor darkYellowColor]; |
4766 | 52 |
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; |
53 |
||
54 |
[super viewDidLoad]; |
|
55 |
} |
|
56 |
||
4757 | 57 |
#pragma mark - |
58 |
#pragma mark Table view data source |
|
59 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
6004 | 60 |
return 3; |
4757 | 61 |
} |
62 |
||
63 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
6004 | 64 |
if (section == 0) |
4760 | 65 |
return 1; |
4856 | 66 |
else if (section == 1) |
67 |
return [[self.statsArray objectAtIndex:0] count]; |
|
4757 | 68 |
else |
4856 | 69 |
return [self.statsArray count] - 2; |
4757 | 70 |
} |
71 |
||
72 |
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
73 |
static NSString *CellIdentifier0 = @"Cell0"; |
|
4760 | 74 |
NSInteger section = [indexPath section]; |
75 |
NSInteger row = [indexPath row]; |
|
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
|
76 |
NSString *imgName = @""; |
5982
283be2ca54a7
mad several updates to the resource copying phase in the ios project file, changed paths of some images and added some smaller forts version
koda
parents:
5976
diff
changeset
|
77 |
NSString *imgPath = ICONS_DIRECTORY(); |
4757 | 78 |
|
79 |
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier0]; |
|
80 |
if (cell == nil) |
|
81 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0] autorelease]; |
|
82 |
||
4856 | 83 |
if (section == 0) { // winning team |
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
|
84 |
imgName = @"star"; |
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
|
85 |
imgPath = [[NSBundle mainBundle] resourcePath]; |
4856 | 86 |
cell.textLabel.text = [self.statsArray objectAtIndex:1]; |
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:
6017
diff
changeset
|
87 |
cell.textLabel.textColor = [UIColor lightYellowColor]; |
4856 | 88 |
} else if (section == 1) { // teams ranking |
89 |
// color, # kills, teamname |
|
90 |
NSArray *info = [[[self.statsArray objectAtIndex:0] objectAtIndex:row] componentsSeparatedByString:@" "]; |
|
91 |
NSUInteger color = [[info objectAtIndex:0] intValue]; |
|
92 |
cell.textLabel.textColor = [UIColor colorWithRed:((color >> 16) & 0xFF)/255.0f |
|
93 |
green:((color >> 8) & 0xFF)/255.0f |
|
94 |
blue:(color & 0xFF)/255.0f |
|
95 |
alpha:1.0f]; |
|
96 |
cell.textLabel.text = [NSString stringWithFormat:@"%d. %@ (%@ kills)", row+1, [info objectAtIndex:2], [info objectAtIndex:1]]; |
|
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
|
97 |
imgName = [NSString stringWithFormat:@"StatsMedal%d",row+1]; |
4856 | 98 |
} else if (section == 2) { // general info |
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
|
99 |
imgName = @"iconDamage"; |
4856 | 100 |
cell.textLabel.text = [self.statsArray objectAtIndex:row + 2]; |
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:
6017
diff
changeset
|
101 |
cell.textLabel.textColor = [UIColor lightYellowColor]; |
4757 | 102 |
} |
4856 | 103 |
|
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
|
104 |
NSString *imgString = [[NSString alloc] initWithFormat:@"%@/%@.png",imgPath,imgName]; |
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 |
UIImage *img = [[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
|
106 |
[imgString release]; |
4856 | 107 |
UIImageView *imgView = [[UIImageView alloc] initWithImage:img]; |
108 |
cell.imageView.image = img; |
|
109 |
[img release]; |
|
110 |
cell.accessoryView = imgView; |
|
111 |
[imgView release]; |
|
112 |
||
113 |
cell.textLabel.textAlignment = UITextAlignmentCenter; |
|
4819 | 114 |
cell.textLabel.adjustsFontSizeToFitWidth = YES; |
4766 | 115 |
cell.backgroundColor = [UIColor blackColor]; |
116 |
cell.selectionStyle = UITableViewCellSelectionStyleNone; |
|
4757 | 117 |
|
118 |
return cell; |
|
119 |
} |
|
120 |
||
4766 | 121 |
-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { |
122 |
return 160; |
|
123 |
} |
|
124 |
||
125 |
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { |
|
126 |
if (section == 0) { |
|
127 |
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 160)]; |
|
128 |
UIImage *img = [[UIImage alloc] initWithContentsOfFile:@"smallerTitle.png"]; |
|
129 |
UIImageView *imgView = [[UIImageView alloc] initWithImage:img]; |
|
130 |
[img release]; |
|
131 |
imgView.center = CGPointMake(self.tableView.frame.size.height/2, 160/2); |
|
132 |
[header addSubview:imgView]; |
|
133 |
[imgView release]; |
|
134 |
||
135 |
return [header autorelease]; |
|
136 |
} else |
|
137 |
return nil; |
|
138 |
} |
|
139 |
||
6004 | 140 |
-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { |
141 |
return self.tableView.rowHeight + 30; |
|
142 |
} |
|
143 |
||
144 |
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { |
|
145 |
if (section == 2) { |
|
146 |
||
6017
24631fd2fb9e
better memory cleanup for audiomanager and position of lower stats button
koda
parents:
6004
diff
changeset
|
147 |
UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.height * 70 / 100, self.tableView.rowHeight)]; |
6004 | 148 |
footer.autoresizingMask = UIViewAutoresizingFlexibleWidth; |
149 |
||
6017
24631fd2fb9e
better memory cleanup for audiomanager and position of lower stats button
koda
parents:
6004
diff
changeset
|
150 |
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 17, self.view.frame.size.height * 70 / 100, self.tableView.rowHeight)]; |
6004 | 151 |
button.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; |
152 |
[button setTitle:NSLocalizedString(@"Done",@"") forState:UIControlStateNormal]; |
|
153 |
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; |
|
154 |
[button setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted]; |
|
155 |
||
156 |
button.titleLabel.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; |
|
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:
6017
diff
changeset
|
157 |
button.backgroundColor = [UIColor blackColorTransparent]; |
6004 | 158 |
[button.layer setBorderWidth:1]; |
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:
6017
diff
changeset
|
159 |
[button.layer setBorderColor:[[UIColor darkYellowColor] CGColor]]; |
6004 | 160 |
[button.layer setCornerRadius:9.0f]; |
161 |
[button.layer setMasksToBounds:YES]; |
|
162 |
[button addTarget:self action:@selector(dismissView) forControlEvents:UIControlEventTouchUpInside]; |
|
163 |
[footer addSubview:button]; |
|
164 |
[button release]; |
|
165 |
||
166 |
return [footer autorelease]; |
|
167 |
} else |
|
168 |
return nil; |
|
169 |
} |
|
170 |
||
4757 | 171 |
#pragma mark - |
6004 | 172 |
#pragma mark button delegate |
173 |
-(void) dismissView { |
|
174 |
[AudioManagerController playClickSound]; |
|
175 |
[self dismissModalViewControllerAnimated:YES]; |
|
4757 | 176 |
} |
177 |
||
178 |
#pragma mark - |
|
179 |
#pragma mark Memory management |
|
180 |
-(void) didReceiveMemoryWarning { |
|
181 |
// Releases the view if it doesn't have a superview. |
|
182 |
[super didReceiveMemoryWarning]; |
|
4760 | 183 |
self.statsArray = nil; |
4757 | 184 |
} |
185 |
||
186 |
-(void) dealloc { |
|
5208 | 187 |
releaseAndNil(statsArray); |
4757 | 188 |
[super dealloc]; |
189 |
} |
|
190 |
||
191 |
||
192 |
@end |
|
193 |