author | antonc27 <antonc27@mail.ru> |
Sun, 20 Sep 2015 02:52:49 +0200 | |
branch | ios-revival |
changeset 11188 | 3dbea499390d |
parent 11118 | 600a5af8d61f |
child 11213 | 6e5fd5ea5acb |
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 |
|
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
6869
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
4757 | 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; |
11118
600a5af8d61f
- Fix for strange problem with table view in StatsPage - rowHeight is 1 by default. So, fixed by implicit size.
antonc27 <antonc27@mail.ru>
parents:
11116
diff
changeset
|
47 |
|
600a5af8d61f
- Fix for strange problem with table view in StatsPage - rowHeight is 1 by default. So, fixed by implicit size.
antonc27 <antonc27@mail.ru>
parents:
11116
diff
changeset
|
48 |
aTableView.rowHeight = 44; |
600a5af8d61f
- Fix for strange problem with table view in StatsPage - rowHeight is 1 by default. So, fixed by implicit size.
antonc27 <antonc27@mail.ru>
parents:
11116
diff
changeset
|
49 |
|
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
|
50 |
[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
|
51 |
[aTableView release]; |
4766 | 52 |
|
53 |
[super viewDidLoad]; |
|
54 |
} |
|
55 |
||
4757 | 56 |
#pragma mark - |
57 |
#pragma mark Table view data source |
|
58 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
6004 | 59 |
return 3; |
4757 | 60 |
} |
61 |
||
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
|
62 |
-(NSInteger) tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section { |
6004 | 63 |
if (section == 0) |
4760 | 64 |
return 1; |
4856 | 65 |
else if (section == 1) |
66 |
return [[self.statsArray objectAtIndex:0] count]; |
|
4757 | 67 |
else |
4856 | 68 |
return [self.statsArray count] - 2; |
4757 | 69 |
} |
70 |
||
71 |
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
72 |
static NSString *CellIdentifier0 = @"Cell0"; |
|
4760 | 73 |
NSInteger section = [indexPath section]; |
74 |
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
|
75 |
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
|
76 |
NSString *imgPath = ICONS_DIRECTORY(); |
4757 | 77 |
|
78 |
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier0]; |
|
79 |
if (cell == nil) |
|
80 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0] autorelease]; |
|
81 |
||
4856 | 82 |
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
|
83 |
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
|
84 |
imgPath = [[NSBundle mainBundle] resourcePath]; |
4856 | 85 |
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
|
86 |
cell.textLabel.textColor = [UIColor lightYellowColor]; |
4856 | 87 |
} else if (section == 1) { // teams ranking |
88 |
// color, # kills, teamname |
|
89 |
NSArray *info = [[[self.statsArray objectAtIndex:0] objectAtIndex:row] componentsSeparatedByString:@" "]; |
|
90 |
NSUInteger color = [[info objectAtIndex:0] intValue]; |
|
91 |
cell.textLabel.textColor = [UIColor colorWithRed:((color >> 16) & 0xFF)/255.0f |
|
92 |
green:((color >> 8) & 0xFF)/255.0f |
|
93 |
blue:(color & 0xFF)/255.0f |
|
94 |
alpha:1.0f]; |
|
95 |
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
|
96 |
imgName = [NSString stringWithFormat:@"StatsMedal%d",row+1]; |
4856 | 97 |
} 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
|
98 |
imgName = @"iconDamage"; |
4856 | 99 |
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
|
100 |
cell.textLabel.textColor = [UIColor lightYellowColor]; |
4757 | 101 |
} |
4856 | 102 |
|
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
|
103 |
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
|
104 |
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
|
105 |
[imgString release]; |
4856 | 106 |
UIImageView *imgView = [[UIImageView alloc] initWithImage:img]; |
107 |
cell.imageView.image = img; |
|
108 |
[img release]; |
|
109 |
cell.accessoryView = imgView; |
|
110 |
[imgView release]; |
|
111 |
||
112 |
cell.textLabel.textAlignment = UITextAlignmentCenter; |
|
4819 | 113 |
cell.textLabel.adjustsFontSizeToFitWidth = YES; |
4766 | 114 |
cell.backgroundColor = [UIColor blackColor]; |
115 |
cell.selectionStyle = UITableViewCellSelectionStyleNone; |
|
4757 | 116 |
|
117 |
return cell; |
|
118 |
} |
|
119 |
||
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
|
120 |
-(CGFloat) tableView:(UITableView *)aTableView heightForHeaderInSection:(NSInteger)section { |
4766 | 121 |
return 160; |
122 |
} |
|
123 |
||
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 *)tableView:(UITableView *)aTableView viewForHeaderInSection:(NSInteger)section { |
4766 | 125 |
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
|
126 |
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, aTableView.frame.size.width, 160)]; |
6708 | 127 |
header.autoresizingMask = UIViewAutoresizingFlexibleWidth; |
128 |
||
4766 | 129 |
UIImage *img = [[UIImage alloc] initWithContentsOfFile:@"smallerTitle.png"]; |
130 |
UIImageView *imgView = [[UIImageView alloc] initWithImage:img]; |
|
131 |
[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
|
132 |
imgView.center = CGPointMake(aTableView.frame.size.width/2, 160/2); |
6708 | 133 |
imgView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; |
4766 | 134 |
[header addSubview:imgView]; |
135 |
[imgView release]; |
|
136 |
||
137 |
return [header autorelease]; |
|
138 |
} else |
|
139 |
return nil; |
|
140 |
} |
|
141 |
||
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
|
142 |
-(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
|
143 |
return aTableView.rowHeight + 30; |
6004 | 144 |
} |
145 |
||
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 *)tableView:(UITableView *)aTableView viewForFooterInSection:(NSInteger)section { |
6004 | 147 |
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
|
148 |
UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width * 70 / 100, aTableView.rowHeight)]; |
6004 | 149 |
footer.autoresizingMask = UIViewAutoresizingFlexibleWidth; |
150 |
||
6711 | 151 |
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 17, self.view.frame.size.width * 70 / 100, aTableView.rowHeight) |
152 |
andTitle:NSLocalizedString(@"Done",@"")]; |
|
6004 | 153 |
button.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; |
154 |
[button addTarget:self action:@selector(dismissView) forControlEvents:UIControlEventTouchUpInside]; |
|
155 |
[footer addSubview:button]; |
|
156 |
[button release]; |
|
157 |
||
158 |
return [footer autorelease]; |
|
159 |
} else |
|
160 |
return nil; |
|
161 |
} |
|
162 |
||
4757 | 163 |
#pragma mark - |
6004 | 164 |
#pragma mark button delegate |
165 |
-(void) dismissView { |
|
6869
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
166 |
[[AudioManagerController mainManager] playClickSound]; |
11116
102684240fe8
- Interscreen transitions fixed
Anton Malmygin <antonc27@mail.ru>
parents:
10108
diff
changeset
|
167 |
[self dismissViewControllerAnimated:YES completion:nil]; |
4757 | 168 |
} |
169 |
||
170 |
#pragma mark - |
|
171 |
#pragma mark Memory management |
|
172 |
-(void) didReceiveMemoryWarning { |
|
173 |
// Releases the view if it doesn't have a superview. |
|
174 |
[super didReceiveMemoryWarning]; |
|
4760 | 175 |
self.statsArray = nil; |
4757 | 176 |
} |
177 |
||
178 |
-(void) dealloc { |
|
5208 | 179 |
releaseAndNil(statsArray); |
4757 | 180 |
[super dealloc]; |
181 |
} |
|
182 |
||
183 |
||
184 |
@end |
|
185 |