author | antonc27 <antonc27@mail.ru> |
Sat, 30 Dec 2017 01:22:11 +0100 | |
branch | ios-develop |
changeset 12877 | 00215a7ec5f5 |
parent 11554 | 893722a2a1f9 |
child 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 "TeamConfigViewController.h" |
|
6108 | 21 |
#import <QuartzCore/QuartzCore.h> |
3547 | 22 |
#import "SquareButtonView.h" |
23 |
||
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:
5976
diff
changeset
|
24 |
|
3547 | 25 |
@implementation TeamConfigViewController |
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
26 |
@synthesize tableView, selectedTeamsCount, allTeamsCount, listOfAllTeams, listOfSelectedTeams, cachedContentsOfDir; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
27 |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11554
diff
changeset
|
28 |
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
29 |
return rotationManager(interfaceOrientation); |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
30 |
} |
3547 | 31 |
|
32 |
#pragma mark - |
|
33 |
#pragma mark View lifecycle |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11554
diff
changeset
|
34 |
- (void)viewDidLoad { |
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
35 |
UITableView *aTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
36 |
style:UITableViewStyleGrouped]; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
37 |
aTableView.delegate = self; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
38 |
aTableView.dataSource = self; |
6108 | 39 |
if (IS_IPAD()) { |
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
40 |
[aTableView setBackgroundColorForAnyTable:[UIColor darkBlueColorTransparent]]; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
41 |
aTableView.layer.borderColor = [[UIColor darkYellowColor] CGColor]; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
42 |
aTableView.layer.borderWidth = 2.7f; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
43 |
aTableView.layer.cornerRadius = 8; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
44 |
aTableView.contentInset = UIEdgeInsetsMake(10, 0, 10, 0); |
6108 | 45 |
} else { |
46 |
UIImage *backgroundImage = [[UIImage alloc] initWithContentsOfFile:@"background~iphone.png"]; |
|
47 |
UIImageView *background = [[UIImageView alloc] initWithImage:backgroundImage]; |
|
11146
f5e552f97eda
- Fixes for cropped background image on iPhone
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
48 |
background.contentMode = UIViewContentModeScaleAspectFill; |
f5e552f97eda
- Fixes for cropped background image on iPhone
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
49 |
background.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; |
6220 | 50 |
[self.view addSubview:background]; |
51 |
[aTableView setBackgroundColorForAnyTable:[UIColor clearColor]]; |
|
6108 | 52 |
} |
4244 | 53 |
|
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
54 |
aTableView.indicatorStyle = UIScrollViewIndicatorStyleWhite; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
55 |
aTableView.separatorColor = [UIColor whiteColor]; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
56 |
aTableView.separatorStyle = UITableViewCellSeparatorStyleNone; |
6634
e00762923086
ios game configuration page supports rotation, with some enhancements (like the new slider); some glitches here and there
koda
parents:
6264
diff
changeset
|
57 |
aTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; |
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
58 |
self.tableView = aTableView; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
59 |
|
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
60 |
[self.view addSubview:self.tableView]; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
61 |
[super viewDidLoad]; |
3547 | 62 |
} |
63 |
||
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11554
diff
changeset
|
64 |
- (void)viewWillAppear:(BOOL)animated { |
3739 | 65 |
NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:TEAMS_DIRECTORY() error:NULL]; |
3971 | 66 |
if ([self.cachedContentsOfDir isEqualToArray:contentsOfDir] == NO) { |
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
67 |
self.cachedContentsOfDir = contentsOfDir; |
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:
5976
diff
changeset
|
68 |
NSArray *colors = [HWUtils teamColors]; |
3551 | 69 |
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:[contentsOfDir count]]; |
6908
896ed2afcfb8
ios: turn on more warning messages and start correcting them
koda
parents:
6832
diff
changeset
|
70 |
for (NSUInteger i = 0; i < [contentsOfDir count]; i++) { |
3551 | 71 |
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys: |
72 |
[contentsOfDir objectAtIndex:i],@"team", |
|
73 |
[NSNumber numberWithInt:4],@"number", |
|
3917 | 74 |
[colors objectAtIndex:i%[colors count]],@"color",nil]; |
3551 | 75 |
[array addObject:dict]; |
76 |
} |
|
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
77 |
self.listOfAllTeams = array; |
3697 | 78 |
|
3551 | 79 |
NSMutableArray *emptyArray = [[NSMutableArray alloc] initWithObjects:nil]; |
80 |
self.listOfSelectedTeams = emptyArray; |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
81 |
|
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
82 |
self.selectedTeamsCount = [self.listOfSelectedTeams count]; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
83 |
self.allTeamsCount = [self.listOfAllTeams count]; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
84 |
[self.tableView reloadData]; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
85 |
} |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
86 |
|
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
87 |
[super viewWillAppear:animated]; |
3547 | 88 |
} |
89 |
||
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11554
diff
changeset
|
90 |
- (NSInteger)filterNumberOfHogs:(NSInteger)hogs { |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
91 |
NSInteger numberOfHogs; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
92 |
if (hogs <= HW_getMaxNumberOfHogs() && hogs >= 1) |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
93 |
numberOfHogs = hogs; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
94 |
else { |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
95 |
if (hogs > HW_getMaxNumberOfHogs()) |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
96 |
numberOfHogs = 1; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
97 |
else |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
98 |
numberOfHogs = HW_getMaxNumberOfHogs(); |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
99 |
} |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
100 |
return numberOfHogs; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
101 |
} |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
102 |
|
3547 | 103 |
#pragma mark - |
104 |
#pragma mark Table view data source |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11554
diff
changeset
|
105 |
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { |
3547 | 106 |
return 2; |
107 |
} |
|
108 |
||
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11554
diff
changeset
|
109 |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
110 |
return (section == 0 ? self.selectedTeamsCount : self.allTeamsCount); |
3547 | 111 |
} |
112 |
||
113 |
// Customize the appearance of table view cells. |
|
114 |
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
115 |
static NSString *CellIdentifier0 = @"Cell0"; |
|
116 |
static NSString *CellIdentifier1 = @"Cell1"; |
|
117 |
NSInteger section = [indexPath section]; |
|
118 |
UITableViewCell *cell; |
|
3697 | 119 |
|
3547 | 120 |
if (section == 0) { |
121 |
cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier0]; |
|
122 |
if (cell == nil) { |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11554
diff
changeset
|
123 |
cell = [[HoldTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0]; |
3697 | 124 |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
125 |
SquareButtonView *squareButton = [[SquareButtonView alloc] initWithFrame:CGRectMake(0, 0, 36, 36)]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
126 |
cell.accessoryView = squareButton; |
3547 | 127 |
} |
3697 | 128 |
|
3547 | 129 |
NSMutableDictionary *selectedRow = [listOfSelectedTeams objectAtIndex:[indexPath row]]; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
130 |
cell.textLabel.text = [[selectedRow objectForKey:@"team"] stringByDeletingPathExtension]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
131 |
cell.textLabel.backgroundColor = [UIColor clearColor]; |
3697 | 132 |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
133 |
SquareButtonView *squareButton = (SquareButtonView *)cell.accessoryView; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
134 |
[squareButton selectColor:[[selectedRow objectForKey:@"color"] intValue]]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
135 |
NSNumber *hogNumber = [selectedRow objectForKey:@"number"]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
136 |
[squareButton setTitle:[hogNumber stringValue] forState:UIControlStateNormal]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
137 |
squareButton.ownerDictionary = selectedRow; |
3697 | 138 |
|
6209 | 139 |
cell.imageView.image = [UIImage drawHogsRepeated:[hogNumber intValue]]; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
140 |
((HoldTableViewCell *)cell).delegate = self; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
141 |
} else { |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
142 |
cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier1]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
143 |
if (cell == nil) |
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11554
diff
changeset
|
144 |
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1]; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
145 |
|
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
146 |
cell.textLabel.text = [[[self.listOfAllTeams objectAtIndex:[indexPath row]] objectForKey:@"team"] stringByDeletingPathExtension]; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
147 |
cell.textLabel.backgroundColor = [UIColor clearColor]; |
8441 | 148 |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
149 |
NSString *teamPath = [NSString stringWithFormat:@"%@/%@.plist",TEAMS_DIRECTORY(),cell.textLabel.text]; |
3814 | 150 |
NSDictionary *firstHog = [[[NSDictionary dictionaryWithContentsOfFile:teamPath] objectForKey:@"hedgehogs"] objectAtIndex:0]; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
151 |
if ([[firstHog objectForKey:@"level"] intValue] != 0) { |
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
|
152 |
NSString *imgString = [[NSString alloc] initWithFormat:@"%@/robotBadge.png",[[NSBundle mainBundle] resourcePath]]; |
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
|
153 |
UIImage *sprite = [[UIImage alloc] initWithContentsOfFile:imgString]; |
3814 | 154 |
UIImageView *spriteView = [[UIImageView alloc] initWithImage:sprite]; |
8441 | 155 |
|
3814 | 156 |
cell.accessoryView = spriteView; |
157 |
} else |
|
158 |
cell.accessoryView = nil; |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
159 |
} |
3697 | 160 |
|
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:
5976
diff
changeset
|
161 |
cell.textLabel.textColor = [UIColor lightYellowColor]; |
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:
5976
diff
changeset
|
162 |
cell.backgroundColor = [UIColor blackColorTransparent]; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
163 |
cell.selectionStyle = UITableViewCellSelectionStyleNone; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
164 |
|
3547 | 165 |
return cell; |
166 |
} |
|
167 |
||
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
168 |
-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { |
6108 | 169 |
return 45.0; |
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
170 |
} |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
171 |
|
6636 | 172 |
-(UIView *)tableView:(UITableView *)aTableView viewForHeaderInSection:(NSInteger)section { |
173 |
CGRect frame = CGRectMake(0, 0, self.view.frame.size.width * 70/100, 30); |
|
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:
5976
diff
changeset
|
174 |
NSString *text = (section == 0) ? NSLocalizedString(@"Playing Teams",@"") : NSLocalizedString(@"Available Teams",@""); |
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:
5976
diff
changeset
|
175 |
UILabel *theLabel = [[UILabel alloc] initWithFrame:frame andTitle:text]; |
3780
7c704e69242e
fade in when returning from game, labels rewritten so that they are drawn at runtime (more flexibility with i18n and iphone support)
koda
parents:
3739
diff
changeset
|
176 |
theLabel.center = CGPointMake(self.view.frame.size.width/2, 20); |
6636 | 177 |
theLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; |
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
178 |
|
6636 | 179 |
UIView *theView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, aTableView.frame.size.width, 30)]; |
180 |
theView.autoresizingMask = UIViewAutoresizingFlexibleWidth; |
|
3780
7c704e69242e
fade in when returning from game, labels rewritten so that they are drawn at runtime (more flexibility with i18n and iphone support)
koda
parents:
3739
diff
changeset
|
181 |
[theView addSubview:theLabel]; |
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11554
diff
changeset
|
182 |
return theView; |
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
183 |
} |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
184 |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
185 |
-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { |
11352
d98070707214
- Small size adjustments for footer labels on GameConfig screen
antonc27 <antonc27@mail.ru>
parents:
11148
diff
changeset
|
186 |
return IS_IPAD() ? 40 : 30; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
187 |
} |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
188 |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11554
diff
changeset
|
189 |
-(UIView *)tableView:(UITableView *)aTableView viewForFooterInSection:(NSInteger)section { |
11352
d98070707214
- Small size adjustments for footer labels on GameConfig screen
antonc27 <antonc27@mail.ru>
parents:
11148
diff
changeset
|
190 |
NSInteger height = IS_IPAD() ? 40 : 30; |
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
191 |
UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, aTableView.frame.size.width, height)]; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
192 |
footer.backgroundColor = [UIColor clearColor]; |
6636 | 193 |
footer.autoresizingMask = UIViewAutoresizingFlexibleWidth; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
194 |
|
11352
d98070707214
- Small size adjustments for footer labels on GameConfig screen
antonc27 <antonc27@mail.ru>
parents:
11148
diff
changeset
|
195 |
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, aTableView.frame.size.width*90/100, height)]; |
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
196 |
label.center = CGPointMake(aTableView.frame.size.width/2, height/2); |
11554
893722a2a1f9
- Some warnings fixed with text alignment on iOS front-end
antonc27 <antonc27@mail.ru>
parents:
11354
diff
changeset
|
197 |
label.textAlignment = NSTextAlignmentCenter; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
198 |
label.font = [UIFont italicSystemFontOfSize:12]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
199 |
label.textColor = [UIColor whiteColor]; |
4538 | 200 |
label.numberOfLines = 2; |
6636 | 201 |
label.backgroundColor = [UIColor clearColor]; |
11354
a0163b8302c5
- Fix for wrong footer labels size on autorotation on GameConfig screen
antonc27 <antonc27@mail.ru>
parents:
11352
diff
changeset
|
202 |
label.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth; |
6636 | 203 |
|
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
204 |
if (section == 0) |
4538 | 205 |
label.text = NSLocalizedString(@"Tap to add hogs or change color, touch and hold to remove a team.",@""); |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
206 |
else |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
207 |
label.text = NSLocalizedString(@"The robot badge indicates an AI-controlled team.",@""); |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
208 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
209 |
[footer addSubview:label]; |
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11554
diff
changeset
|
210 |
return footer; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
211 |
} |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
212 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
213 |
|
3547 | 214 |
#pragma mark - |
215 |
#pragma mark Table view delegate |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11554
diff
changeset
|
216 |
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
6908
896ed2afcfb8
ios: turn on more warning messages and start correcting them
koda
parents:
6832
diff
changeset
|
217 |
NSUInteger row = [indexPath row]; |
896ed2afcfb8
ios: turn on more warning messages and start correcting them
koda
parents:
6832
diff
changeset
|
218 |
NSUInteger section = [indexPath section]; |
3547 | 219 |
|
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
220 |
if (section == 1 && [self.listOfAllTeams count] > row) { |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
221 |
[self.listOfSelectedTeams addObject:[self.listOfAllTeams objectAtIndex:row]]; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
222 |
[self.listOfAllTeams removeObjectAtIndex:row]; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
223 |
|
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
224 |
NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:selectedTeamsCount inSection:0]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
225 |
allTeamsCount--; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
226 |
selectedTeamsCount++; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
227 |
[aTableView beginUpdates]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
228 |
[aTableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationRight]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
229 |
[aTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
230 |
[aTableView endUpdates]; |
3547 | 231 |
} |
4486 | 232 |
if (section == 0 && [self.listOfSelectedTeams count] > row) { |
233 |
NSMutableDictionary *selectedRow = [self.listOfSelectedTeams objectAtIndex:row]; |
|
234 |
UITableViewCell *cell = [aTableView cellForRowAtIndexPath:indexPath]; |
|
235 |
SquareButtonView *squareButton = (SquareButtonView *)cell.accessoryView; |
|
236 |
||
237 |
NSInteger increaseNumber = [[selectedRow objectForKey:@"number"] intValue] + 1; |
|
11148
064a53861759
- Refactoring in order to remove some warning related to using of int instead of NSInteger
antonc27 <antonc27@mail.ru>
parents:
11146
diff
changeset
|
238 |
NSNumber *newNumber = [NSNumber numberWithInteger:[self filterNumberOfHogs:increaseNumber]]; |
4486 | 239 |
[squareButton setTitle:[newNumber stringValue] forState:UIControlStateNormal]; |
240 |
[selectedRow setObject:newNumber forKey:@"number"]; |
|
241 |
||
6209 | 242 |
cell.imageView.image = [UIImage drawHogsRepeated:[newNumber intValue]]; |
4486 | 243 |
} |
3547 | 244 |
} |
245 |
||
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11554
diff
changeset
|
246 |
- (void)holdAction:(NSString *)content onTable:(UITableView *)aTableView { |
6908
896ed2afcfb8
ios: turn on more warning messages and start correcting them
koda
parents:
6832
diff
changeset
|
247 |
NSUInteger row; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
248 |
for (row = 0; row < [self.listOfSelectedTeams count]; row++) { |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
249 |
NSDictionary *dict = [self.listOfSelectedTeams objectAtIndex:row]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
250 |
if ([content isEqualToString:[[dict objectForKey:@"team"] stringByDeletingPathExtension]]) |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
251 |
break; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
252 |
} |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
253 |
|
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
254 |
[self.listOfAllTeams addObject:[self.listOfSelectedTeams objectAtIndex:row]]; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
255 |
[self.listOfSelectedTeams removeObjectAtIndex:row]; |
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
256 |
|
6115
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
257 |
[aTableView beginUpdates]; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
258 |
[aTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:row inSection:0]] withRowAnimation:UITableViewRowAnimationLeft]; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
259 |
[aTableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:allTeamsCount inSection:1]] withRowAnimation:UITableViewRowAnimationLeft]; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
260 |
self.allTeamsCount++; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
261 |
self.selectedTeamsCount--; |
485cfecadc9a
HUGE refactoring of the ipad interface, finally understood how to use interface builder with custom uiviewcontrollers, as well as converted some uitableviewcontrollers to uiviewcontrollers for simplicity
koda
parents:
6108
diff
changeset
|
262 |
[aTableView endUpdates]; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
4356
diff
changeset
|
263 |
} |
3547 | 264 |
|
265 |
#pragma mark - |
|
266 |
#pragma mark Memory management |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11554
diff
changeset
|
267 |
|
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11554
diff
changeset
|
268 |
- (void)didReceiveMemoryWarning { |
3739 | 269 |
self.cachedContentsOfDir = nil; |
3971 | 270 |
MSG_MEMCLEAN(); |
271 |
[super didReceiveMemoryWarning]; |
|
3547 | 272 |
} |
273 |
||
274 |
@end |
|
275 |