author | koda |
Sat, 18 Feb 2012 11:59:59 +0100 | |
changeset 6708 | 314929f0a3e1 |
parent 6700 | e04da46ee43c |
child 6709 | 018539298042 |
permissions | -rw-r--r-- |
4757 | 1 |
/* |
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
|
6700 | 3 |
* Copyright (c) 2009-2012 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 { |
6708 | 33 |
[self.tableView setBackgroundColorForAnyTable:[UIColor clearColor]]; |
4766 | 34 |
|
6708 | 35 |
NSString *imgName = (IS_IPAD()) ? @"mediumBackground~ipad.png" : @"smallerBackground~iphone.png"; |
36 |
UIImage *img = [[UIImage alloc] initWithContentsOfFile:imgName]; |
|
37 |
UIImageView *background = [[UIImageView alloc] initWithImage:img]; |
|
38 |
[img release]; |
|
39 |
background.frame = self.view.frame; |
|
40 |
background.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; |
|
41 |
[self.view insertSubview:background atIndex:0]; |
|
42 |
[background release]; |
|
4766 | 43 |
|
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
|
44 |
self.tableView.separatorColor = [UIColor darkYellowColor]; |
4766 | 45 |
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; |
46 |
||
47 |
[super viewDidLoad]; |
|
48 |
} |
|
49 |
||
4757 | 50 |
#pragma mark - |
51 |
#pragma mark Table view data source |
|
52 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
6004 | 53 |
return 3; |
4757 | 54 |
} |
55 |
||
56 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
6004 | 57 |
if (section == 0) |
4760 | 58 |
return 1; |
4856 | 59 |
else if (section == 1) |
60 |
return [[self.statsArray objectAtIndex:0] count]; |
|
4757 | 61 |
else |
4856 | 62 |
return [self.statsArray count] - 2; |
4757 | 63 |
} |
64 |
||
65 |
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
66 |
static NSString *CellIdentifier0 = @"Cell0"; |
|
4760 | 67 |
NSInteger section = [indexPath section]; |
68 |
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
|
69 |
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
|
70 |
NSString *imgPath = ICONS_DIRECTORY(); |
4757 | 71 |
|
72 |
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier0]; |
|
73 |
if (cell == nil) |
|
74 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0] autorelease]; |
|
75 |
||
4856 | 76 |
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
|
77 |
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
|
78 |
imgPath = [[NSBundle mainBundle] resourcePath]; |
4856 | 79 |
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
|
80 |
cell.textLabel.textColor = [UIColor lightYellowColor]; |
4856 | 81 |
} else if (section == 1) { // teams ranking |
82 |
// color, # kills, teamname |
|
83 |
NSArray *info = [[[self.statsArray objectAtIndex:0] objectAtIndex:row] componentsSeparatedByString:@" "]; |
|
84 |
NSUInteger color = [[info objectAtIndex:0] intValue]; |
|
85 |
cell.textLabel.textColor = [UIColor colorWithRed:((color >> 16) & 0xFF)/255.0f |
|
86 |
green:((color >> 8) & 0xFF)/255.0f |
|
87 |
blue:(color & 0xFF)/255.0f |
|
88 |
alpha:1.0f]; |
|
89 |
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
|
90 |
imgName = [NSString stringWithFormat:@"StatsMedal%d",row+1]; |
4856 | 91 |
} 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
|
92 |
imgName = @"iconDamage"; |
4856 | 93 |
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
|
94 |
cell.textLabel.textColor = [UIColor lightYellowColor]; |
4757 | 95 |
} |
4856 | 96 |
|
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 |
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
|
98 |
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
|
99 |
[imgString release]; |
4856 | 100 |
UIImageView *imgView = [[UIImageView alloc] initWithImage:img]; |
101 |
cell.imageView.image = img; |
|
102 |
[img release]; |
|
103 |
cell.accessoryView = imgView; |
|
104 |
[imgView release]; |
|
105 |
||
106 |
cell.textLabel.textAlignment = UITextAlignmentCenter; |
|
4819 | 107 |
cell.textLabel.adjustsFontSizeToFitWidth = YES; |
4766 | 108 |
cell.backgroundColor = [UIColor blackColor]; |
109 |
cell.selectionStyle = UITableViewCellSelectionStyleNone; |
|
4757 | 110 |
|
111 |
return cell; |
|
112 |
} |
|
113 |
||
4766 | 114 |
-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { |
115 |
return 160; |
|
116 |
} |
|
117 |
||
118 |
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { |
|
119 |
if (section == 0) { |
|
120 |
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 160)]; |
|
6708 | 121 |
header.autoresizingMask = UIViewAutoresizingFlexibleWidth; |
122 |
||
4766 | 123 |
UIImage *img = [[UIImage alloc] initWithContentsOfFile:@"smallerTitle.png"]; |
124 |
UIImageView *imgView = [[UIImageView alloc] initWithImage:img]; |
|
125 |
[img release]; |
|
6708 | 126 |
imgView.center = CGPointMake(self.tableView.frame.size.width/2, 160/2); |
127 |
imgView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; |
|
4766 | 128 |
[header addSubview:imgView]; |
129 |
[imgView release]; |
|
130 |
||
131 |
return [header autorelease]; |
|
132 |
} else |
|
133 |
return nil; |
|
134 |
} |
|
135 |
||
6004 | 136 |
-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { |
137 |
return self.tableView.rowHeight + 30; |
|
138 |
} |
|
139 |
||
140 |
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { |
|
141 |
if (section == 2) { |
|
6708 | 142 |
UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width * 70 / 100, self.tableView.rowHeight)]; |
6004 | 143 |
footer.autoresizingMask = UIViewAutoresizingFlexibleWidth; |
144 |
||
6708 | 145 |
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 17, self.view.frame.size.width * 70 / 100, self.tableView.rowHeight)]; |
6004 | 146 |
button.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; |
147 |
[button setTitle:NSLocalizedString(@"Done",@"") forState:UIControlStateNormal]; |
|
148 |
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; |
|
149 |
[button setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted]; |
|
150 |
||
151 |
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
|
152 |
button.backgroundColor = [UIColor blackColorTransparent]; |
6004 | 153 |
[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
|
154 |
[button.layer setBorderColor:[[UIColor darkYellowColor] CGColor]]; |
6004 | 155 |
[button.layer setCornerRadius:9.0f]; |
156 |
[button.layer setMasksToBounds:YES]; |
|
157 |
[button addTarget:self action:@selector(dismissView) forControlEvents:UIControlEventTouchUpInside]; |
|
158 |
[footer addSubview:button]; |
|
159 |
[button release]; |
|
160 |
||
161 |
return [footer autorelease]; |
|
162 |
} else |
|
163 |
return nil; |
|
164 |
} |
|
165 |
||
4757 | 166 |
#pragma mark - |
6004 | 167 |
#pragma mark button delegate |
168 |
-(void) dismissView { |
|
169 |
[AudioManagerController playClickSound]; |
|
170 |
[self dismissModalViewControllerAnimated:YES]; |
|
4757 | 171 |
} |
172 |
||
173 |
#pragma mark - |
|
174 |
#pragma mark Memory management |
|
175 |
-(void) didReceiveMemoryWarning { |
|
176 |
// Releases the view if it doesn't have a superview. |
|
177 |
[super didReceiveMemoryWarning]; |
|
4760 | 178 |
self.statsArray = nil; |
4757 | 179 |
} |
180 |
||
181 |
-(void) dealloc { |
|
5208 | 182 |
releaseAndNil(statsArray); |
4757 | 183 |
[super dealloc]; |
184 |
} |
|
185 |
||
186 |
||
187 |
@end |
|
188 |