author | koda |
Sat, 24 Sep 2011 04:53:53 +0200 | |
changeset 6008 | 215f0c9719e3 |
parent 6004 | b92a6626b0e5 |
child 6017 | 24631fd2fb9e |
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" |
|
23 |
#import "CommodityFunctions.h" |
|
6004 | 24 |
#import <QuartzCore/QuartzCore.h> |
4757 | 25 |
|
26 |
@implementation StatsPageViewController |
|
4760 | 27 |
@synthesize statsArray; |
4757 | 28 |
|
29 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
30 |
return rotationManager(interfaceOrientation); |
|
31 |
} |
|
32 |
||
4766 | 33 |
-(void) viewDidLoad { |
34 |
if ([self.tableView respondsToSelector:@selector(setBackgroundView:)]) |
|
35 |
self.tableView.backgroundView = nil; |
|
36 |
||
37 |
NSString *imgName; |
|
38 |
if (IS_IPAD()) |
|
39 |
imgName = @"mediumBackground~ipad.png"; |
|
40 |
else |
|
41 |
imgName = @"smallerBackground~iphone.png"; |
|
42 |
||
43 |
if ([self.tableView respondsToSelector:@selector(setBackgroundView:)]) { |
|
44 |
UIImage *backgroundImage = [[UIImage alloc] initWithContentsOfFile:imgName]; |
|
45 |
UIImageView *background = [[UIImageView alloc] initWithImage:backgroundImage]; |
|
46 |
[backgroundImage release]; |
|
47 |
[self.tableView setBackgroundView:background]; |
|
48 |
[background release]; |
|
49 |
} else |
|
50 |
self.view.backgroundColor = [UIColor blackColor]; |
|
51 |
||
52 |
self.tableView.separatorColor = UICOLOR_HW_YELLOW_BODER; |
|
53 |
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; |
|
54 |
||
55 |
[super viewDidLoad]; |
|
56 |
} |
|
57 |
||
4757 | 58 |
#pragma mark - |
59 |
#pragma mark Table view data source |
|
60 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
6004 | 61 |
return 3; |
4757 | 62 |
} |
63 |
||
64 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
6004 | 65 |
if (section == 0) |
4760 | 66 |
return 1; |
4856 | 67 |
else if (section == 1) |
68 |
return [[self.statsArray objectAtIndex:0] count]; |
|
4757 | 69 |
else |
4856 | 70 |
return [self.statsArray count] - 2; |
4757 | 71 |
} |
72 |
||
73 |
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
74 |
static NSString *CellIdentifier0 = @"Cell0"; |
|
4760 | 75 |
NSInteger section = [indexPath section]; |
76 |
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
|
77 |
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
|
78 |
NSString *imgPath = ICONS_DIRECTORY(); |
4757 | 79 |
|
80 |
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier0]; |
|
81 |
if (cell == nil) |
|
82 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0] autorelease]; |
|
83 |
||
4856 | 84 |
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
|
85 |
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
|
86 |
imgPath = [[NSBundle mainBundle] resourcePath]; |
4856 | 87 |
cell.textLabel.text = [self.statsArray objectAtIndex:1]; |
4766 | 88 |
cell.textLabel.textColor = UICOLOR_HW_YELLOW_TEXT; |
4856 | 89 |
} else if (section == 1) { // teams ranking |
90 |
// color, # kills, teamname |
|
91 |
NSArray *info = [[[self.statsArray objectAtIndex:0] objectAtIndex:row] componentsSeparatedByString:@" "]; |
|
92 |
NSUInteger color = [[info objectAtIndex:0] intValue]; |
|
93 |
cell.textLabel.textColor = [UIColor colorWithRed:((color >> 16) & 0xFF)/255.0f |
|
94 |
green:((color >> 8) & 0xFF)/255.0f |
|
95 |
blue:(color & 0xFF)/255.0f |
|
96 |
alpha:1.0f]; |
|
97 |
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
|
98 |
imgName = [NSString stringWithFormat:@"StatsMedal%d",row+1]; |
4856 | 99 |
} 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
|
100 |
imgName = @"iconDamage"; |
4856 | 101 |
cell.textLabel.text = [self.statsArray objectAtIndex:row + 2]; |
4766 | 102 |
cell.textLabel.textColor = UICOLOR_HW_YELLOW_TEXT; |
4757 | 103 |
} |
4856 | 104 |
|
5976
306cedbeb213
fixed several 'retina display' images and added a bunch more (though just from upscaling the normal ones; might be nice to have 'em redrawn at a real higher resolution)
koda
parents:
5208
diff
changeset
|
105 |
NSString *imgString = [[NSString alloc] initWithFormat:@"%@/%@.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
|
106 |
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
|
107 |
[imgString release]; |
4856 | 108 |
UIImageView *imgView = [[UIImageView alloc] initWithImage:img]; |
109 |
cell.imageView.image = img; |
|
110 |
[img release]; |
|
111 |
cell.accessoryView = imgView; |
|
112 |
[imgView release]; |
|
113 |
||
114 |
cell.textLabel.textAlignment = UITextAlignmentCenter; |
|
4819 | 115 |
cell.textLabel.adjustsFontSizeToFitWidth = YES; |
4766 | 116 |
cell.backgroundColor = [UIColor blackColor]; |
117 |
cell.selectionStyle = UITableViewCellSelectionStyleNone; |
|
4757 | 118 |
|
119 |
return cell; |
|
120 |
} |
|
121 |
||
4766 | 122 |
-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { |
123 |
return 160; |
|
124 |
} |
|
125 |
||
126 |
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { |
|
127 |
if (section == 0) { |
|
128 |
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 160)]; |
|
129 |
UIImage *img = [[UIImage alloc] initWithContentsOfFile:@"smallerTitle.png"]; |
|
130 |
UIImageView *imgView = [[UIImageView alloc] initWithImage:img]; |
|
131 |
[img release]; |
|
132 |
imgView.center = CGPointMake(self.tableView.frame.size.height/2, 160/2); |
|
133 |
[header addSubview:imgView]; |
|
134 |
[imgView release]; |
|
135 |
||
136 |
return [header autorelease]; |
|
137 |
} else |
|
138 |
return nil; |
|
139 |
} |
|
140 |
||
6004 | 141 |
-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { |
142 |
return self.tableView.rowHeight + 30; |
|
143 |
} |
|
144 |
||
145 |
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { |
|
146 |
if (section == 2) { |
|
147 |
||
148 |
UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.tableView.rowHeight)]; |
|
149 |
footer.autoresizingMask = UIViewAutoresizingFlexibleWidth; |
|
150 |
||
151 |
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 17, self.view.frame.size.width, self.tableView.rowHeight)]; |
|
152 |
button.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; |
|
153 |
[button setTitle:NSLocalizedString(@"Done",@"") forState:UIControlStateNormal]; |
|
154 |
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; |
|
155 |
[button setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted]; |
|
156 |
||
157 |
button.titleLabel.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; |
|
158 |
button.backgroundColor = UICOLOR_HW_ALMOSTBLACK; |
|
159 |
[button.layer setBorderWidth:1]; |
|
160 |
[button.layer setBorderColor:UICOLOR_HW_YELLOW_BODER.CGColor]; |
|
161 |
[button.layer setCornerRadius:9.0f]; |
|
162 |
[button.layer setMasksToBounds:YES]; |
|
163 |
[button addTarget:self action:@selector(dismissView) forControlEvents:UIControlEventTouchUpInside]; |
|
164 |
[footer addSubview:button]; |
|
165 |
[button release]; |
|
166 |
||
167 |
return [footer autorelease]; |
|
168 |
} else |
|
169 |
return nil; |
|
170 |
} |
|
171 |
||
4757 | 172 |
#pragma mark - |
6004 | 173 |
#pragma mark button delegate |
174 |
-(void) dismissView { |
|
175 |
[AudioManagerController playClickSound]; |
|
176 |
[self dismissModalViewControllerAnimated:YES]; |
|
4757 | 177 |
} |
178 |
||
179 |
#pragma mark - |
|
180 |
#pragma mark Memory management |
|
181 |
-(void) didReceiveMemoryWarning { |
|
182 |
// Releases the view if it doesn't have a superview. |
|
183 |
[super didReceiveMemoryWarning]; |
|
4760 | 184 |
self.statsArray = nil; |
4757 | 185 |
} |
186 |
||
187 |
-(void) dealloc { |
|
5208 | 188 |
releaseAndNil(statsArray); |
4757 | 189 |
[super dealloc]; |
190 |
} |
|
191 |
||
192 |
||
193 |
@end |
|
194 |