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