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