author | Wuzzy <Wuzzy2@mail.ru> |
Thu, 25 Jul 2019 19:18:48 +0200 | |
changeset 15276 | a0e425458694 |
parent 13171 | ba5c794adae3 |
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 "FlagsViewController.h" |
|
4478 | 21 |
#import <QuartzCore/QuartzCore.h> |
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:
5208
diff
changeset
|
22 |
|
3547 | 23 |
|
24 |
@implementation FlagsViewController |
|
3950 | 25 |
@synthesize teamDictionary, flagArray, communityArray, lastIndexPath; |
3547 | 26 |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11148
diff
changeset
|
27 |
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
3547 | 28 |
return rotationManager(interfaceOrientation); |
29 |
} |
|
30 |
||
31 |
#pragma mark - |
|
32 |
#pragma mark View lifecycle |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11148
diff
changeset
|
33 |
- (void)viewDidLoad { |
3547 | 34 |
[super viewDidLoad]; |
35 |
||
3950 | 36 |
NSMutableArray *array_na = [[NSMutableArray alloc] init]; |
37 |
NSMutableArray *array_cm = [[NSMutableArray alloc] init]; |
|
8441 | 38 |
|
3950 | 39 |
for (NSString *name in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:FLAGS_DIRECTORY() error:NULL]) { |
40 |
if ([name hasPrefix:@"cm_"]) { |
|
41 |
NSString *processed = [name substringFromIndex:3]; |
|
42 |
[array_cm addObject:processed]; |
|
43 |
} else |
|
44 |
[array_na addObject:name]; |
|
45 |
} |
|
8441 | 46 |
|
3950 | 47 |
self.flagArray = array_na; |
48 |
self.communityArray = array_cm; |
|
3697 | 49 |
|
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
|
50 |
self.title = NSLocalizedString(@"Set team flag",@""); |
3547 | 51 |
} |
52 |
||
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11148
diff
changeset
|
53 |
- (void)viewWillAppear:(BOOL)animated { |
3547 | 54 |
[super viewWillAppear:animated]; |
3950 | 55 |
// reloadData needed because team might change |
3547 | 56 |
[self.tableView reloadData]; |
3950 | 57 |
//[self.tableView setContentOffset:CGPointMake(0,0) animated:NO]; |
3547 | 58 |
} |
59 |
||
60 |
||
61 |
#pragma mark - |
|
62 |
#pragma mark Table view data source |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11148
diff
changeset
|
63 |
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { |
3950 | 64 |
return 2; |
3547 | 65 |
} |
66 |
||
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11148
diff
changeset
|
67 |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
3950 | 68 |
if (section == 0) |
69 |
return [self.flagArray count]; |
|
70 |
else |
|
71 |
return [self.communityArray count]; |
|
3547 | 72 |
} |
73 |
||
74 |
// Customize the appearance of table view cells. |
|
75 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
76 |
static NSString *CellIdentifier = @"Cell"; |
|
3950 | 77 |
NSInteger row = [indexPath row]; |
3697 | 78 |
|
3547 | 79 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
80 |
if (cell == nil) { |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11148
diff
changeset
|
81 |
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; |
3547 | 82 |
} |
3697 | 83 |
|
3950 | 84 |
NSString *flagName = nil; |
85 |
NSArray *source = nil; |
|
86 |
if ([indexPath section] == 0) { |
|
87 |
source = self.flagArray; |
|
88 |
flagName = [source objectAtIndex:row]; |
|
89 |
} else { |
|
90 |
source = self.communityArray; |
|
91 |
flagName = [NSString stringWithFormat:@"cm_%@",[source objectAtIndex:row]]; |
|
92 |
} |
|
93 |
NSString *flagFile = [[NSString alloc] initWithFormat:@"%@/%@", FLAGS_DIRECTORY(), flagName]; |
|
3547 | 94 |
UIImage *flagSprite = [[UIImage alloc] initWithContentsOfFile:flagFile]; |
95 |
cell.imageView.image = flagSprite; |
|
6104 | 96 |
cell.imageView.layer.borderWidth = 1; |
97 |
cell.imageView.layer.borderColor = [[UIColor blackColor] CGColor]; |
|
3697 | 98 |
|
3950 | 99 |
cell.textLabel.text = [[source objectAtIndex:row] stringByDeletingPathExtension]; |
100 |
if ([[flagName stringByDeletingPathExtension] isEqualToString:[self.teamDictionary objectForKey:@"flag"]]) { |
|
3547 | 101 |
cell.accessoryType = UITableViewCellAccessoryCheckmark; |
102 |
self.lastIndexPath = indexPath; |
|
103 |
} else { |
|
104 |
cell.accessoryType = UITableViewCellAccessoryNone; |
|
105 |
} |
|
3697 | 106 |
|
3547 | 107 |
return cell; |
108 |
} |
|
109 |
||
13171
ba5c794adae3
- Some not-so-important pretty formatting
antonc27 <antonc27@mail.ru>
parents:
12877
diff
changeset
|
110 |
- (NSString *)tableView:(UITableView *)aTableView titleForHeaderInSection:(NSInteger)section { |
3950 | 111 |
NSString *sectionTitle = nil; |
112 |
switch (section) { |
|
113 |
case 0: |
|
114 |
sectionTitle = NSLocalizedString(@"Worldwide", @""); |
|
115 |
break; |
|
116 |
case 1: |
|
117 |
sectionTitle = NSLocalizedString(@"Community", @""); |
|
118 |
break; |
|
119 |
default: |
|
120 |
DLog(@"nope"); |
|
121 |
break; |
|
122 |
} |
|
123 |
return sectionTitle; |
|
124 |
} |
|
125 |
||
3547 | 126 |
|
127 |
#pragma mark - |
|
128 |
#pragma mark Table view delegate |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11148
diff
changeset
|
129 |
- (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
|
130 |
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
|
131 |
NSInteger oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
064a53861759
- Refactoring in order to remove some warning related to using of int instead of NSInteger
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
132 |
NSInteger newSection = [indexPath section]; |
064a53861759
- Refactoring in order to remove some warning related to using of int instead of NSInteger
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
133 |
NSInteger oldSection = (lastIndexPath != nil) ? [lastIndexPath section] : -1; |
8441 | 134 |
|
3950 | 135 |
if (newRow != oldRow || newSection != oldSection) { |
136 |
NSString *flag = nil; |
|
137 |
if ([indexPath section] == 0) |
|
138 |
flag = [self.flagArray objectAtIndex:newRow]; |
|
139 |
else |
|
140 |
flag = [NSString stringWithFormat:@"cm_%@",[self.communityArray objectAtIndex:newRow]]; |
|
8441 | 141 |
|
3547 | 142 |
// if the two selected rows differ update data on the hog dictionary and reload table content |
3950 | 143 |
[self.teamDictionary setValue:[flag stringByDeletingPathExtension] forKey:@"flag"]; |
3547 | 144 |
|
145 |
// tell our boss to write this new stuff on disk |
|
146 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil]; |
|
147 |
||
148 |
UITableViewCell *newCell = [aTableView cellForRowAtIndexPath:indexPath]; |
|
149 |
newCell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
150 |
UITableViewCell *oldCell = [aTableView cellForRowAtIndexPath:lastIndexPath]; |
|
151 |
oldCell.accessoryType = UITableViewCellAccessoryNone; |
|
152 |
self.lastIndexPath = indexPath; |
|
153 |
[aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
|
154 |
} |
|
155 |
[aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
|
156 |
[self.navigationController popViewControllerAnimated:YES]; |
|
157 |
} |
|
158 |
||
159 |
||
160 |
#pragma mark - |
|
161 |
#pragma mark Memory management |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11148
diff
changeset
|
162 |
|
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11148
diff
changeset
|
163 |
- (void)didReceiveMemoryWarning { |
3950 | 164 |
self.lastIndexPath = nil; |
165 |
MSG_MEMCLEAN(); |
|
3547 | 166 |
[super didReceiveMemoryWarning]; |
167 |
} |
|
168 |
||
169 |
@end |
|
170 |