author | koda |
Thu, 09 Feb 2012 18:59:46 +0100 | |
changeset 6658 | 2cccf6b2b89d |
parent 6078 | 8c0cc07731e5 |
child 6700 | e04da46ee43c |
permissions | -rw-r--r-- |
3884 | 1 |
/* |
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
|
4976 | 3 |
* Copyright (c) 2009-2011 Vittorio Giovara <vittorio.giovara@gmail.com> |
3884 | 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 |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
17 |
* |
|
18 |
* File created on 19/09/2010. |
|
19 |
*/ |
|
20 |
||
3891 | 21 |
|
3884 | 22 |
#import "SupportViewController.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:
6074
diff
changeset
|
23 |
|
3884 | 24 |
|
25 |
@implementation SupportViewController |
|
4115 | 26 |
@synthesize waysToSupport; |
3884 | 27 |
|
4115 | 28 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
3884 | 29 |
return rotationManager(interfaceOrientation); |
30 |
} |
|
31 |
||
4115 | 32 |
#pragma mark - |
33 |
#pragma mark View lifecycle |
|
34 |
-(void) viewDidLoad { |
|
35 |
[super viewDidLoad]; |
|
36 |
||
37 |
NSArray *array = [[NSArray alloc] initWithObjects: |
|
38 |
NSLocalizedString(@"Leave a positive review on iTunes!",@""), |
|
39 |
NSLocalizedString(@"Join us on Facebook",@""), |
|
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5208
diff
changeset
|
40 |
NSLocalizedString(@"Follow us on Twitter",@""), |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5208
diff
changeset
|
41 |
NSLocalizedString(@"Visit our website",@""), |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5208
diff
changeset
|
42 |
NSLocalizedString(@"Chat with the devs in IRC",@""), |
4115 | 43 |
nil]; |
44 |
self.waysToSupport = array; |
|
45 |
[array release]; |
|
46 |
||
6074
047eaed35cbb
ios major refactoring for ios settings, now they are presented differently on iphone/ipad, code is simplified and optimized, and ui is a little refreshed (eg. no more stuck selected fields)
koda
parents:
5976
diff
changeset
|
47 |
self.navigationItem.title = @"♥"; |
4115 | 48 |
self.tableView.rowHeight = 50; |
49 |
} |
|
50 |
||
51 |
#pragma mark - |
|
52 |
#pragma mark Table view data source |
|
53 |
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { |
|
54 |
return 2; |
|
55 |
} |
|
56 |
||
57 |
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
58 |
if (section == 0) |
|
59 |
return 1; |
|
60 |
else |
|
61 |
return [self.waysToSupport count] - 1; |
|
62 |
} |
|
63 |
||
64 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
65 |
static NSString *CellIdentifier = @"Cell"; |
|
66 |
NSInteger row = [indexPath row]; |
|
67 |
NSInteger section = [indexPath section]; |
|
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:
5700
diff
changeset
|
68 |
NSString *imgName = @""; |
4115 | 69 |
|
70 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
|
71 |
if (cell == nil) |
|
72 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
|
73 |
||
74 |
NSString *rowString = [self.waysToSupport objectAtIndex:(row + section)]; |
|
75 |
cell.textLabel.text = rowString; |
|
76 |
||
77 |
if (section == 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:
5700
diff
changeset
|
78 |
imgName = @"star"; |
4115 | 79 |
cell.textLabel.textAlignment = UITextAlignmentCenter; |
80 |
cell.imageView.image = nil; |
|
81 |
} else { |
|
82 |
cell.textLabel.textAlignment = UITextAlignmentLeft; |
|
83 |
switch (row) { |
|
84 |
case 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:
5700
diff
changeset
|
85 |
imgName = @"fb"; |
4115 | 86 |
break; |
87 |
case 1: |
|
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:
5700
diff
changeset
|
88 |
imgName = @"tw"; |
4115 | 89 |
break; |
90 |
case 2: |
|
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:
5700
diff
changeset
|
91 |
imgName = @"hedgehog"; |
4115 | 92 |
break; |
4341 | 93 |
case 3: |
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:
5700
diff
changeset
|
94 |
imgName = @"irc"; |
4341 | 95 |
break; |
4115 | 96 |
default: |
97 |
DLog(@"No way"); |
|
98 |
break; |
|
99 |
} |
|
100 |
} |
|
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:
5700
diff
changeset
|
101 |
|
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:
5700
diff
changeset
|
102 |
NSString *imgString = [[NSString alloc] initWithFormat:@"%@/%@.png",[[NSBundle mainBundle] resourcePath],imgName]; |
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5208
diff
changeset
|
103 |
UIImage *img = [[UIImage alloc] initWithContentsOfFile:imgString]; |
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:
5700
diff
changeset
|
104 |
[imgString release]; |
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5208
diff
changeset
|
105 |
cell.imageView.image = img; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5208
diff
changeset
|
106 |
if (section == 0) { |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5208
diff
changeset
|
107 |
UIImageView *imgView = [[UIImageView alloc] initWithImage:img]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5208
diff
changeset
|
108 |
cell.accessoryView = imgView; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5208
diff
changeset
|
109 |
[imgView release]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5208
diff
changeset
|
110 |
} |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5208
diff
changeset
|
111 |
[img release]; |
4115 | 112 |
|
113 |
return cell; |
|
114 |
} |
|
115 |
||
116 |
#pragma mark - |
|
117 |
#pragma mark Table view delegate |
|
118 |
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
119 |
NSString *urlString = nil; |
|
120 |
if ([indexPath section] == 0) |
|
121 |
urlString = @"http://itunes.apple.com/us/app/hedgewars/id391234866?affC=QQABAAAAHgAFasEiWjVwUGZOc3k1VGctQkRJazlacXhUclpBTVpiU2xteVdfUQ%3D%3D#&mt=8"; |
|
122 |
else |
|
123 |
switch ([indexPath row]) { |
|
124 |
case 0: |
|
125 |
urlString = @"http://www.facebook.com/Hedgewars"; |
|
126 |
break; |
|
127 |
case 1: |
|
128 |
urlString = @"http://twitter.com/hedgewars"; |
|
129 |
break; |
|
130 |
case 2: |
|
131 |
urlString = @"http://www.hedgewars.org"; |
|
132 |
break; |
|
4341 | 133 |
case 3: |
134 |
urlString = @"http://webchat.freenode.net/?channels=hedgewars"; |
|
135 |
break; |
|
4115 | 136 |
default: |
137 |
DLog(@"No way"); |
|
138 |
break; |
|
139 |
} |
|
140 |
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]]; |
|
141 |
} |
|
142 |
||
143 |
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger) section { |
|
144 |
if (section == 1) { |
|
145 |
UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 240)]; |
|
6658
2cccf6b2b89d
added MGSplitViewController, popular replacement for uisplitviewcontrollers: this brings rotation support to our settings pages! weapons and schemes are the only controllers displaying minor glitches
koda
parents:
6078
diff
changeset
|
146 |
footer.autoresizingMask = UIViewAutoresizingFlexibleWidth; |
2cccf6b2b89d
added MGSplitViewController, popular replacement for uisplitviewcontrollers: this brings rotation support to our settings pages! weapons and schemes are the only controllers displaying minor glitches
koda
parents:
6078
diff
changeset
|
147 |
|
4115 | 148 |
UIImage *img = [[UIImage alloc] initWithContentsOfFile:@"surprise.png"]; |
149 |
UIImageView *imgView = [[UIImageView alloc] initWithImage:img]; |
|
150 |
[img release]; |
|
151 |
imgView.center = CGPointMake(self.tableView.frame.size.width/2, 120); |
|
6658
2cccf6b2b89d
added MGSplitViewController, popular replacement for uisplitviewcontrollers: this brings rotation support to our settings pages! weapons and schemes are the only controllers displaying minor glitches
koda
parents:
6078
diff
changeset
|
152 |
imgView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; |
4115 | 153 |
[footer addSubview:imgView]; |
154 |
[imgView release]; |
|
155 |
||
156 |
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 20)]; |
|
6658
2cccf6b2b89d
added MGSplitViewController, popular replacement for uisplitviewcontrollers: this brings rotation support to our settings pages! weapons and schemes are the only controllers displaying minor glitches
koda
parents:
6078
diff
changeset
|
157 |
label.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; |
4115 | 158 |
label.textAlignment = UITextAlignmentCenter; |
159 |
label.text = @" ♥ THANK YOU ♥ "; |
|
160 |
label.backgroundColor = [UIColor clearColor]; |
|
161 |
label.center = CGPointMake(self.tableView.frame.size.width/2, 250); |
|
162 |
[footer addSubview:label]; |
|
163 |
[label release]; |
|
164 |
||
165 |
return [footer autorelease]; |
|
166 |
} else |
|
167 |
return nil; |
|
168 |
} |
|
169 |
||
170 |
-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { |
|
171 |
// image height + label height |
|
172 |
return 265; |
|
173 |
} |
|
174 |
||
175 |
#pragma mark - |
|
176 |
#pragma mark Memory management |
|
177 |
-(void)didReceiveMemoryWarning { |
|
3884 | 178 |
[super didReceiveMemoryWarning]; |
179 |
} |
|
180 |
||
181 |
-(void) viewDidUnload { |
|
4115 | 182 |
self.waysToSupport = nil; |
183 |
MSG_DIDUNLOAD(); |
|
3884 | 184 |
[super viewDidUnload]; |
185 |
} |
|
186 |
||
187 |
-(void) dealloc { |
|
5208 | 188 |
releaseAndNil(waysToSupport); |
3884 | 189 |
[super dealloc]; |
190 |
} |
|
191 |
||
192 |
@end |