author | antonc27 <antonc27@mail.ru> |
Sat, 30 Dec 2017 01:22:11 +0100 | |
branch | ios-develop |
changeset 12877 | 00215a7ec5f5 |
parent 11221 | e68b3e392091 |
permissions | -rw-r--r-- |
3829 | 1 |
/* |
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
|
6700 | 3 |
* Copyright (c) 2009-2012 Vittorio Giovara <vittorio.giovara@gmail.com> |
3829 | 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:
8441
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3829 | 17 |
*/ |
18 |
||
3547 | 19 |
|
20 |
#import "LevelViewController.h" |
|
21 |
||
22 |
||
23 |
@implementation LevelViewController |
|
24 |
@synthesize teamDictionary, levelArray, levelSprites, lastIndexPath; |
|
25 |
||
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11221
diff
changeset
|
26 |
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
3547 | 27 |
return rotationManager(interfaceOrientation); |
28 |
} |
|
29 |
||
30 |
#pragma mark - |
|
31 |
#pragma mark View lifecycle |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11221
diff
changeset
|
32 |
- (void)viewDidLoad { |
3547 | 33 |
[super viewDidLoad]; |
34 |
||
35 |
NSArray *array = [[NSArray alloc] initWithObjects: |
|
36 |
NSLocalizedString(@"Brutal",@""), |
|
37 |
NSLocalizedString(@"Aggressive",@""), |
|
38 |
NSLocalizedString(@"Bully",@""), |
|
39 |
NSLocalizedString(@"Average",@""), |
|
40 |
NSLocalizedString(@"Weaky",@""), |
|
41 |
nil]; |
|
42 |
self.levelArray = array; |
|
3697 | 43 |
|
3662
a44406f4369b
polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents:
3547
diff
changeset
|
44 |
self.title = NSLocalizedString(@"Set difficulty level",@""); |
3547 | 45 |
} |
46 |
||
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11221
diff
changeset
|
47 |
- (void)viewWillAppear:(BOOL)animated { |
3547 | 48 |
[super viewWillAppear:animated]; |
8441 | 49 |
|
3880 | 50 |
if ([[[[self.teamDictionary objectForKey:@"hedgehogs"] objectAtIndex:0] objectForKey:@"level"] intValue] == 0) |
51 |
numberOfSections = 1; |
|
52 |
else |
|
53 |
numberOfSections = 2; |
|
8441 | 54 |
|
3547 | 55 |
[self.tableView reloadData]; |
56 |
// this moves the tableview to the top |
|
57 |
[self.tableView setContentOffset:CGPointMake(0,0) animated:NO]; |
|
58 |
} |
|
59 |
||
60 |
#pragma mark - |
|
61 |
#pragma mark Table view data source |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11221
diff
changeset
|
62 |
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { |
3880 | 63 |
return numberOfSections; |
3547 | 64 |
} |
65 |
||
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11221
diff
changeset
|
66 |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
3880 | 67 |
if (section == 0) |
68 |
return 1; |
|
69 |
else |
|
70 |
return 5; |
|
3547 | 71 |
} |
72 |
||
73 |
// Customize the appearance of table view cells. |
|
74 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
3880 | 75 |
static NSString *CellIdentifier0 = @"Cell0"; |
76 |
static NSString *CellIdentifier1 = @"Cell1"; |
|
3697 | 77 |
|
3547 | 78 |
NSInteger row = [indexPath row]; |
3880 | 79 |
NSInteger section = [indexPath section]; |
80 |
UITableViewCell *cell; |
|
8441 | 81 |
|
3880 | 82 |
if (section == 0) { |
83 |
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier0]; |
|
84 |
if (cell == nil) { |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11221
diff
changeset
|
85 |
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0]; |
3880 | 86 |
UISwitch *theSwitch = [[UISwitch alloc] init]; |
87 |
[theSwitch addTarget:self action:@selector(switchValueChanged:) forControlEvents:UIControlEventValueChanged]; |
|
88 |
cell.accessoryView = theSwitch; |
|
89 |
} |
|
4149
51200479f9d8
update ios port with new health modes, increase sd turns, new game modes, fixed bugs that prevented the creation of AI controlled teams, revisited update modes
koda
parents:
3971
diff
changeset
|
90 |
UISwitch *theSwitch = (UISwitch *)cell.accessoryView; |
51200479f9d8
update ios port with new health modes, increase sd turns, new game modes, fixed bugs that prevented the creation of AI controlled teams, revisited update modes
koda
parents:
3971
diff
changeset
|
91 |
if (numberOfSections == 1) |
51200479f9d8
update ios port with new health modes, increase sd turns, new game modes, fixed bugs that prevented the creation of AI controlled teams, revisited update modes
koda
parents:
3971
diff
changeset
|
92 |
theSwitch.on = NO; |
51200479f9d8
update ios port with new health modes, increase sd turns, new game modes, fixed bugs that prevented the creation of AI controlled teams, revisited update modes
koda
parents:
3971
diff
changeset
|
93 |
else |
51200479f9d8
update ios port with new health modes, increase sd turns, new game modes, fixed bugs that prevented the creation of AI controlled teams, revisited update modes
koda
parents:
3971
diff
changeset
|
94 |
theSwitch.on = YES; |
3880 | 95 |
cell.textLabel.text = NSLocalizedString(@"Hogs controlled by AI",@""); |
96 |
} else { |
|
97 |
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1]; |
|
98 |
if (cell == nil) |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11221
diff
changeset
|
99 |
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1]; |
8441 | 100 |
|
3880 | 101 |
cell.textLabel.text = [levelArray objectAtIndex:row]; |
102 |
NSDictionary *hog = [[self.teamDictionary objectForKey:@"hedgehogs"] objectAtIndex:0]; |
|
103 |
if ([[hog objectForKey:@"level"] intValue] == row+1) { |
|
104 |
cell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
105 |
self.lastIndexPath = indexPath; |
|
106 |
} else { |
|
107 |
cell.accessoryType = UITableViewCellAccessoryNone; |
|
108 |
} |
|
8441 | 109 |
|
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:
5208
diff
changeset
|
110 |
NSString *botlevelPath = [[NSString alloc] initWithFormat:@"%@/bot%d.png",[[NSBundle mainBundle] resourcePath],row+1]; |
3880 | 111 |
UIImage *levelImage = [[UIImage alloc] initWithContentsOfFile:botlevelPath]; |
112 |
cell.imageView.image = levelImage; |
|
3547 | 113 |
} |
8441 | 114 |
|
3547 | 115 |
return cell; |
116 |
} |
|
117 |
||
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11221
diff
changeset
|
118 |
- (void)switchValueChanged:(id)sender { |
3880 | 119 |
UISwitch *theSwitch = (UISwitch *)sender; |
120 |
NSIndexSet *sections = [[NSIndexSet alloc] initWithIndex:1]; |
|
121 |
NSMutableArray *hogs = [self.teamDictionary objectForKey:@"hedgehogs"]; |
|
3883
5934ddf9ed5d
fixed the voice selection where you couldn't hear a preview sound
koda
parents:
3880
diff
changeset
|
122 |
NSInteger level; |
8441 | 123 |
|
3880 | 124 |
if (theSwitch.on) { |
125 |
numberOfSections = 2; |
|
126 |
[self.tableView insertSections:sections withRowAnimation:UITableViewRowAnimationFade]; |
|
11210
2e80c9861818
- Better random number generation for front-end: random() replaced with arc4random_uniform()
antonc27 <antonc27@mail.ru>
parents:
11148
diff
changeset
|
127 |
level = 1 + arc4random_uniform((int)[levelArray count] - 1); |
3880 | 128 |
} else { |
129 |
numberOfSections = 1; |
|
130 |
[self.tableView deleteSections:sections withRowAnimation:UITableViewRowAnimationFade]; |
|
3883
5934ddf9ed5d
fixed the voice selection where you couldn't hear a preview sound
koda
parents:
3880
diff
changeset
|
131 |
level = 0; |
5934ddf9ed5d
fixed the voice selection where you couldn't hear a preview sound
koda
parents:
3880
diff
changeset
|
132 |
} |
3547 | 133 |
|
11148
064a53861759
- Refactoring in order to remove some warning related to using of int instead of NSInteger
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
134 |
DLog(@"New level is %ld", (long)level); |
3883
5934ddf9ed5d
fixed the voice selection where you couldn't hear a preview sound
koda
parents:
3880
diff
changeset
|
135 |
for (NSMutableDictionary *hog in hogs) |
11148
064a53861759
- Refactoring in order to remove some warning related to using of int instead of NSInteger
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
136 |
[hog setObject:[NSNumber numberWithInteger:level] forKey:@"level"]; |
3883
5934ddf9ed5d
fixed the voice selection where you couldn't hear a preview sound
koda
parents:
3880
diff
changeset
|
137 |
|
5934ddf9ed5d
fixed the voice selection where you couldn't hear a preview sound
koda
parents:
3880
diff
changeset
|
138 |
[self.tableView reloadData]; |
5934ddf9ed5d
fixed the voice selection where you couldn't hear a preview sound
koda
parents:
3880
diff
changeset
|
139 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil]; |
3547 | 140 |
} |
141 |
||
142 |
||
143 |
#pragma mark - |
|
144 |
#pragma mark Table view delegate |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11221
diff
changeset
|
145 |
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
11148
064a53861759
- Refactoring in order to remove some warning related to using of int instead of NSInteger
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
146 |
NSInteger newRow = [indexPath row]; |
064a53861759
- Refactoring in order to remove some warning related to using of int instead of NSInteger
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
147 |
NSInteger oldRow = (self.lastIndexPath != nil) ? [self.lastIndexPath row] : -1; |
3697 | 148 |
|
8441 | 149 |
if ([indexPath section] != 0) { |
3880 | 150 |
if (newRow != oldRow) { |
151 |
NSMutableArray *hogs = [self.teamDictionary objectForKey:@"hedgehogs"]; |
|
8441 | 152 |
|
4284
57a501a69e5f
update iFrontend with new schemes and weaps, fix up smaller glitches
koda
parents:
4149
diff
changeset
|
153 |
NSInteger level = newRow + 1; |
3880 | 154 |
for (NSMutableDictionary *hog in hogs) |
11148
064a53861759
- Refactoring in order to remove some warning related to using of int instead of NSInteger
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
155 |
[hog setObject:[NSNumber numberWithInteger:level] forKey:@"level"]; |
064a53861759
- Refactoring in order to remove some warning related to using of int instead of NSInteger
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
156 |
DLog(@"New level is %ld", (long)level); |
8441 | 157 |
|
3880 | 158 |
// tell our boss to write this new stuff on disk |
159 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil]; |
|
160 |
[self.tableView reloadData]; |
|
8441 | 161 |
|
3880 | 162 |
self.lastIndexPath = indexPath; |
163 |
[self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
|
3547 | 164 |
} |
165 |
} |
|
166 |
[self.tableView deselectRowAtIndexPath:indexPath animated:YES]; |
|
167 |
} |
|
168 |
||
169 |
||
170 |
#pragma mark - |
|
171 |
#pragma mark Memory management |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11221
diff
changeset
|
172 |
|
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11221
diff
changeset
|
173 |
- (void)didReceiveMemoryWarning { |
3971 | 174 |
self.lastIndexPath = nil; |
175 |
MSG_MEMCLEAN(); |
|
3547 | 176 |
[super didReceiveMemoryWarning]; |
177 |
} |
|
178 |
||
179 |
@end |
|
180 |