author | koda |
Sun, 19 Feb 2012 01:22:59 +0100 | |
changeset 6718 | 686ebfd50f56 |
parent 6711 | 76e96101a84f |
child 6832 | fae8fd118da9 |
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" |
|
23 |
||
24 |
@implementation StatsPageViewController |
|
4760 | 25 |
@synthesize statsArray; |
4757 | 26 |
|
27 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
28 |
return rotationManager(interfaceOrientation); |
|
29 |
} |
|
30 |
||
4766 | 31 |
-(void) viewDidLoad { |
6709
018539298042
oh i thought i had converted every uitableviewcontroller to uiviewcontroller+tableview; this also restores displaying statitstics after game
koda
parents:
6708
diff
changeset
|
32 |
UITableView *aTableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStyleGrouped]; |
018539298042
oh i thought i had converted every uitableviewcontroller to uiviewcontroller+tableview; this also restores displaying statitstics after game
koda
parents:
6708
diff
changeset
|
33 |
[aTableView 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 |
|
6709
018539298042
oh i thought i had converted every uitableviewcontroller to uiviewcontroller+tableview; this also restores displaying statitstics after game
koda
parents:
6708
diff
changeset
|
44 |
aTableView.separatorColor = [UIColor darkYellowColor]; |
018539298042
oh i thought i had converted every uitableviewcontroller to uiviewcontroller+tableview; this also restores displaying statitstics after game
koda
parents:
6708
diff
changeset
|
45 |
aTableView.separatorStyle = UITableViewCellSeparatorStyleNone; |
018539298042
oh i thought i had converted every uitableviewcontroller to uiviewcontroller+tableview; this also restores displaying statitstics after game
koda
parents:
6708
diff
changeset
|
46 |
aTableView.delegate = self; |
018539298042
oh i thought i had converted every uitableviewcontroller to uiviewcontroller+tableview; this also restores displaying statitstics after game
koda
parents:
6708
diff
changeset
|
47 |
aTableView.dataSource = self; |
018539298042
oh i thought i had converted every uitableviewcontroller to uiviewcontroller+tableview; this also restores displaying statitstics after game
koda
parents:
6708
diff
changeset
|
48 |
|
018539298042
oh i thought i had converted every uitableviewcontroller to uiviewcontroller+tableview; this also restores displaying statitstics after game
koda
parents:
6708
diff
changeset
|
49 |
[self.view addSubview:aTableView]; |
018539298042
oh i thought i had converted every uitableviewcontroller to uiviewcontroller+tableview; this also restores displaying statitstics after game
koda
parents:
6708
diff
changeset
|
50 |
[aTableView release]; |
4766 | 51 |
|
52 |
[super viewDidLoad]; |
|
53 |
} |
|
54 |
||
4757 | 55 |
#pragma mark - |
56 |
#pragma mark Table view data source |
|
57 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
6004 | 58 |
return 3; |
4757 | 59 |
} |
60 |
||
6709
018539298042
oh i thought i had converted every uitableviewcontroller to uiviewcontroller+tableview; this also restores displaying statitstics after game
koda
parents:
6708
diff
changeset
|
61 |
-(NSInteger) tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section { |
6004 | 62 |
if (section == 0) |
4760 | 63 |
return 1; |
4856 | 64 |
else if (section == 1) |
65 |
return [[self.statsArray objectAtIndex:0] count]; |
|
4757 | 66 |
else |
4856 | 67 |
return [self.statsArray count] - 2; |
4757 | 68 |
} |
69 |
||
70 |
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
71 |
static NSString *CellIdentifier0 = @"Cell0"; |
|
4760 | 72 |
NSInteger section = [indexPath section]; |
73 |
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
|
74 |
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
|
75 |
NSString *imgPath = ICONS_DIRECTORY(); |
4757 | 76 |
|
77 |
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier0]; |
|
78 |
if (cell == nil) |
|
79 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0] autorelease]; |
|
80 |
||
4856 | 81 |
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
|
82 |
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
|
83 |
imgPath = [[NSBundle mainBundle] resourcePath]; |
4856 | 84 |
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
|
85 |
cell.textLabel.textColor = [UIColor lightYellowColor]; |
4856 | 86 |
} else if (section == 1) { // teams ranking |
87 |
// color, # kills, teamname |
|
88 |
NSArray *info = [[[self.statsArray objectAtIndex:0] objectAtIndex:row] componentsSeparatedByString:@" "]; |
|
89 |
NSUInteger color = [[info objectAtIndex:0] intValue]; |
|
90 |
cell.textLabel.textColor = [UIColor colorWithRed:((color >> 16) & 0xFF)/255.0f |
|
91 |
green:((color >> 8) & 0xFF)/255.0f |
|
92 |
blue:(color & 0xFF)/255.0f |
|
93 |
alpha:1.0f]; |
|
94 |
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
|
95 |
imgName = [NSString stringWithFormat:@"StatsMedal%d",row+1]; |
4856 | 96 |
} 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
|
97 |
imgName = @"iconDamage"; |
4856 | 98 |
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
|
99 |
cell.textLabel.textColor = [UIColor lightYellowColor]; |
4757 | 100 |
} |
4856 | 101 |
|
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
|
102 |
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
|
103 |
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
|
104 |
[imgString release]; |
4856 | 105 |
UIImageView *imgView = [[UIImageView alloc] initWithImage:img]; |
106 |
cell.imageView.image = img; |
|
107 |
[img release]; |
|
108 |
cell.accessoryView = imgView; |
|
109 |
[imgView release]; |
|
110 |
||
111 |
cell.textLabel.textAlignment = UITextAlignmentCenter; |
|
4819 | 112 |
cell.textLabel.adjustsFontSizeToFitWidth = YES; |
4766 | 113 |
cell.backgroundColor = [UIColor blackColor]; |
114 |
cell.selectionStyle = UITableViewCellSelectionStyleNone; |
|
4757 | 115 |
|
116 |
return cell; |
|
117 |
} |
|
118 |
||
6709
018539298042
oh i thought i had converted every uitableviewcontroller to uiviewcontroller+tableview; this also restores displaying statitstics after game
koda
parents:
6708
diff
changeset
|
119 |
-(CGFloat) tableView:(UITableView *)aTableView heightForHeaderInSection:(NSInteger)section { |
4766 | 120 |
return 160; |
121 |
} |
|
122 |
||
6709
018539298042
oh i thought i had converted every uitableviewcontroller to uiviewcontroller+tableview; this also restores displaying statitstics after game
koda
parents:
6708
diff
changeset
|
123 |
-(UIView *)tableView:(UITableView *)aTableView viewForHeaderInSection:(NSInteger)section { |
4766 | 124 |
if (section == 0) { |
6709
018539298042
oh i thought i had converted every uitableviewcontroller to uiviewcontroller+tableview; this also restores displaying statitstics after game
koda
parents:
6708
diff
changeset
|
125 |
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, aTableView.frame.size.width, 160)]; |
6708 | 126 |
header.autoresizingMask = UIViewAutoresizingFlexibleWidth; |
127 |
||
4766 | 128 |
UIImage *img = [[UIImage alloc] initWithContentsOfFile:@"smallerTitle.png"]; |
129 |
UIImageView *imgView = [[UIImageView alloc] initWithImage:img]; |
|
130 |
[img release]; |
|
6709
018539298042
oh i thought i had converted every uitableviewcontroller to uiviewcontroller+tableview; this also restores displaying statitstics after game
koda
parents:
6708
diff
changeset
|
131 |
imgView.center = CGPointMake(aTableView.frame.size.width/2, 160/2); |
6708 | 132 |
imgView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; |
4766 | 133 |
[header addSubview:imgView]; |
134 |
[imgView release]; |
|
135 |
||
136 |
return [header autorelease]; |
|
137 |
} else |
|
138 |
return nil; |
|
139 |
} |
|
140 |
||
6709
018539298042
oh i thought i had converted every uitableviewcontroller to uiviewcontroller+tableview; this also restores displaying statitstics after game
koda
parents:
6708
diff
changeset
|
141 |
-(CGFloat) tableView:(UITableView *)aTableView heightForFooterInSection:(NSInteger)section { |
018539298042
oh i thought i had converted every uitableviewcontroller to uiviewcontroller+tableview; this also restores displaying statitstics after game
koda
parents:
6708
diff
changeset
|
142 |
return aTableView.rowHeight + 30; |
6004 | 143 |
} |
144 |
||
6709
018539298042
oh i thought i had converted every uitableviewcontroller to uiviewcontroller+tableview; this also restores displaying statitstics after game
koda
parents:
6708
diff
changeset
|
145 |
-(UIView *)tableView:(UITableView *)aTableView viewForFooterInSection:(NSInteger)section { |
6004 | 146 |
if (section == 2) { |
6709
018539298042
oh i thought i had converted every uitableviewcontroller to uiviewcontroller+tableview; this also restores displaying statitstics after game
koda
parents:
6708
diff
changeset
|
147 |
UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width * 70 / 100, aTableView.rowHeight)]; |
6004 | 148 |
footer.autoresizingMask = UIViewAutoresizingFlexibleWidth; |
149 |
||
6711 | 150 |
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 17, self.view.frame.size.width * 70 / 100, aTableView.rowHeight) |
151 |
andTitle:NSLocalizedString(@"Done",@"")]; |
|
6004 | 152 |
button.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; |
153 |
[button addTarget:self action:@selector(dismissView) forControlEvents:UIControlEventTouchUpInside]; |
|
154 |
[footer addSubview:button]; |
|
155 |
[button release]; |
|
156 |
||
157 |
return [footer autorelease]; |
|
158 |
} else |
|
159 |
return nil; |
|
160 |
} |
|
161 |
||
4757 | 162 |
#pragma mark - |
6004 | 163 |
#pragma mark button delegate |
164 |
-(void) dismissView { |
|
165 |
[AudioManagerController playClickSound]; |
|
166 |
[self dismissModalViewControllerAnimated:YES]; |
|
4757 | 167 |
} |
168 |
||
169 |
#pragma mark - |
|
170 |
#pragma mark Memory management |
|
171 |
-(void) didReceiveMemoryWarning { |
|
172 |
// Releases the view if it doesn't have a superview. |
|
173 |
[super didReceiveMemoryWarning]; |
|
4760 | 174 |
self.statsArray = nil; |
4757 | 175 |
} |
176 |
||
177 |
-(void) dealloc { |
|
5208 | 178 |
releaseAndNil(statsArray); |
4757 | 179 |
[super dealloc]; |
180 |
} |
|
181 |
||
182 |
||
183 |
@end |
|
184 |