author | nemo |
Tue, 24 Oct 2017 18:55:19 -0400 | |
changeset 12759 | df9d9d19406a |
parent 11549 | 893722a2a1f9 |
child 12872 | 00215a7ec5f5 |
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]; |
11213
6e5fd5ea5acb
- Fix for autorotation of table view of StatsPageVC
antonc27 <antonc27@mail.ru>
parents:
11118
diff
changeset
|
32 |
aTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; |
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
|
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; |
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
|
48 |
|
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 |
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
|
50 |
|
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
|
51 |
[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
|
52 |
[aTableView release]; |
4766 | 53 |
|
54 |
[super viewDidLoad]; |
|
55 |
} |
|
56 |
||
11223
93bc68aa41d3
- Workaround for team's name with spaces in StatsPage
antonc27 <antonc27@mail.ru>
parents:
11213
diff
changeset
|
57 |
#pragma mark - Helpers |
93bc68aa41d3
- Workaround for team's name with spaces in StatsPage
antonc27 <antonc27@mail.ru>
parents:
11213
diff
changeset
|
58 |
|
93bc68aa41d3
- Workaround for team's name with spaces in StatsPage
antonc27 <antonc27@mail.ru>
parents:
11213
diff
changeset
|
59 |
- (NSString *)teamNameFromInfo: (NSArray *)info |
93bc68aa41d3
- Workaround for team's name with spaces in StatsPage
antonc27 <antonc27@mail.ru>
parents:
11213
diff
changeset
|
60 |
{ |
93bc68aa41d3
- Workaround for team's name with spaces in StatsPage
antonc27 <antonc27@mail.ru>
parents:
11213
diff
changeset
|
61 |
NSString *teamName = [NSString stringWithString:[info objectAtIndex:2]]; |
93bc68aa41d3
- Workaround for team's name with spaces in StatsPage
antonc27 <antonc27@mail.ru>
parents:
11213
diff
changeset
|
62 |
|
93bc68aa41d3
- Workaround for team's name with spaces in StatsPage
antonc27 <antonc27@mail.ru>
parents:
11213
diff
changeset
|
63 |
for (int i=3; i < [info count]; i++) |
93bc68aa41d3
- Workaround for team's name with spaces in StatsPage
antonc27 <antonc27@mail.ru>
parents:
11213
diff
changeset
|
64 |
{ |
93bc68aa41d3
- Workaround for team's name with spaces in StatsPage
antonc27 <antonc27@mail.ru>
parents:
11213
diff
changeset
|
65 |
teamName = [teamName stringByAppendingFormat:@" %@", [info objectAtIndex:i]]; |
93bc68aa41d3
- Workaround for team's name with spaces in StatsPage
antonc27 <antonc27@mail.ru>
parents:
11213
diff
changeset
|
66 |
} |
93bc68aa41d3
- Workaround for team's name with spaces in StatsPage
antonc27 <antonc27@mail.ru>
parents:
11213
diff
changeset
|
67 |
|
93bc68aa41d3
- Workaround for team's name with spaces in StatsPage
antonc27 <antonc27@mail.ru>
parents:
11213
diff
changeset
|
68 |
return teamName; |
93bc68aa41d3
- Workaround for team's name with spaces in StatsPage
antonc27 <antonc27@mail.ru>
parents:
11213
diff
changeset
|
69 |
} |
93bc68aa41d3
- Workaround for team's name with spaces in StatsPage
antonc27 <antonc27@mail.ru>
parents:
11213
diff
changeset
|
70 |
|
4757 | 71 |
#pragma mark - |
72 |
#pragma mark Table view data source |
|
73 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
6004 | 74 |
return 3; |
4757 | 75 |
} |
76 |
||
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
|
77 |
-(NSInteger) tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section { |
6004 | 78 |
if (section == 0) |
4760 | 79 |
return 1; |
4856 | 80 |
else if (section == 1) |
81 |
return [[self.statsArray objectAtIndex:0] count]; |
|
4757 | 82 |
else |
4856 | 83 |
return [self.statsArray count] - 2; |
4757 | 84 |
} |
85 |
||
86 |
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
87 |
static NSString *CellIdentifier0 = @"Cell0"; |
|
4760 | 88 |
NSInteger section = [indexPath section]; |
89 |
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
|
90 |
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
|
91 |
NSString *imgPath = ICONS_DIRECTORY(); |
4757 | 92 |
|
93 |
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier0]; |
|
94 |
if (cell == nil) |
|
95 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0] autorelease]; |
|
96 |
||
4856 | 97 |
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
|
98 |
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
|
99 |
imgPath = [[NSBundle mainBundle] resourcePath]; |
4856 | 100 |
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
|
101 |
cell.textLabel.textColor = [UIColor lightYellowColor]; |
4856 | 102 |
} else if (section == 1) { // teams ranking |
103 |
// color, # kills, teamname |
|
104 |
NSArray *info = [[[self.statsArray objectAtIndex:0] objectAtIndex:row] componentsSeparatedByString:@" "]; |
|
105 |
NSUInteger color = [[info objectAtIndex:0] intValue]; |
|
106 |
cell.textLabel.textColor = [UIColor colorWithRed:((color >> 16) & 0xFF)/255.0f |
|
107 |
green:((color >> 8) & 0xFF)/255.0f |
|
108 |
blue:(color & 0xFF)/255.0f |
|
109 |
alpha:1.0f]; |
|
11231
bb3e57426a07
- Localization for missed strings in StatsPage (for both eng and rus)
antonc27 <antonc27@mail.ru>
parents:
11223
diff
changeset
|
110 |
cell.textLabel.text = [NSString stringWithFormat:@"%d. %@ (%@ %@)", row+1, [self teamNameFromInfo:info], [info objectAtIndex:1], NSLocalizedString(@"kills", nil)]; |
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
|
111 |
imgName = [NSString stringWithFormat:@"StatsMedal%d",row+1]; |
4856 | 112 |
} 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
|
113 |
imgName = @"iconDamage"; |
4856 | 114 |
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
|
115 |
cell.textLabel.textColor = [UIColor lightYellowColor]; |
4757 | 116 |
} |
4856 | 117 |
|
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
|
118 |
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
|
119 |
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
|
120 |
[imgString release]; |
4856 | 121 |
UIImageView *imgView = [[UIImageView alloc] initWithImage:img]; |
122 |
cell.imageView.image = img; |
|
123 |
[img release]; |
|
124 |
cell.accessoryView = imgView; |
|
125 |
[imgView release]; |
|
126 |
||
11549
893722a2a1f9
- Some warnings fixed with text alignment on iOS front-end
antonc27 <antonc27@mail.ru>
parents:
11231
diff
changeset
|
127 |
cell.textLabel.textAlignment = NSTextAlignmentCenter; |
4819 | 128 |
cell.textLabel.adjustsFontSizeToFitWidth = YES; |
4766 | 129 |
cell.backgroundColor = [UIColor blackColor]; |
130 |
cell.selectionStyle = UITableViewCellSelectionStyleNone; |
|
4757 | 131 |
|
132 |
return cell; |
|
133 |
} |
|
134 |
||
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
|
135 |
-(CGFloat) tableView:(UITableView *)aTableView heightForHeaderInSection:(NSInteger)section { |
11213
6e5fd5ea5acb
- Fix for autorotation of table view of StatsPageVC
antonc27 <antonc27@mail.ru>
parents:
11118
diff
changeset
|
136 |
return (section == 0) ? 160 : 40; |
4766 | 137 |
} |
138 |
||
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
|
139 |
-(UIView *)tableView:(UITableView *)aTableView viewForHeaderInSection:(NSInteger)section { |
4766 | 140 |
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
|
141 |
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, aTableView.frame.size.width, 160)]; |
6708 | 142 |
header.autoresizingMask = UIViewAutoresizingFlexibleWidth; |
143 |
||
4766 | 144 |
UIImage *img = [[UIImage alloc] initWithContentsOfFile:@"smallerTitle.png"]; |
145 |
UIImageView *imgView = [[UIImageView alloc] initWithImage:img]; |
|
146 |
[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
|
147 |
imgView.center = CGPointMake(aTableView.frame.size.width/2, 160/2); |
6708 | 148 |
imgView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; |
4766 | 149 |
[header addSubview:imgView]; |
150 |
[imgView release]; |
|
151 |
||
152 |
return [header autorelease]; |
|
153 |
} else |
|
154 |
return nil; |
|
155 |
} |
|
156 |
||
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
|
157 |
-(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
|
158 |
return aTableView.rowHeight + 30; |
6004 | 159 |
} |
160 |
||
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
|
161 |
-(UIView *)tableView:(UITableView *)aTableView viewForFooterInSection:(NSInteger)section { |
6004 | 162 |
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
|
163 |
UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width * 70 / 100, aTableView.rowHeight)]; |
6004 | 164 |
footer.autoresizingMask = UIViewAutoresizingFlexibleWidth; |
165 |
||
6711 | 166 |
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 17, self.view.frame.size.width * 70 / 100, aTableView.rowHeight) |
167 |
andTitle:NSLocalizedString(@"Done",@"")]; |
|
6004 | 168 |
button.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; |
169 |
[button addTarget:self action:@selector(dismissView) forControlEvents:UIControlEventTouchUpInside]; |
|
170 |
[footer addSubview:button]; |
|
171 |
[button release]; |
|
172 |
||
173 |
return [footer autorelease]; |
|
174 |
} else |
|
175 |
return nil; |
|
176 |
} |
|
177 |
||
4757 | 178 |
#pragma mark - |
6004 | 179 |
#pragma mark button delegate |
180 |
-(void) dismissView { |
|
6869
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
181 |
[[AudioManagerController mainManager] playClickSound]; |
11116
102684240fe8
- Interscreen transitions fixed
Anton Malmygin <antonc27@mail.ru>
parents:
10108
diff
changeset
|
182 |
[self dismissViewControllerAnimated:YES completion:nil]; |
4757 | 183 |
} |
184 |
||
185 |
#pragma mark - |
|
186 |
#pragma mark Memory management |
|
187 |
-(void) didReceiveMemoryWarning { |
|
188 |
// Releases the view if it doesn't have a superview. |
|
189 |
[super didReceiveMemoryWarning]; |
|
4760 | 190 |
self.statsArray = nil; |
4757 | 191 |
} |
192 |
||
193 |
-(void) dealloc { |
|
5208 | 194 |
releaseAndNil(statsArray); |
4757 | 195 |
[super dealloc]; |
196 |
} |
|
197 |
||
198 |
||
199 |
@end |
|
200 |