author | nemo |
Fri, 09 Sep 2011 18:30:40 -0400 | |
changeset 5832 | f730c8a9777b |
parent 5700 | f0960a88ab0e |
child 5976 | 306cedbeb213 |
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" |
23 |
#import "CommodityFunctions.h" |
|
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 |
||
47 |
self.tableView.rowHeight = 50; |
|
48 |
} |
|
49 |
||
50 |
#pragma mark - |
|
51 |
#pragma mark Table view data source |
|
52 |
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { |
|
53 |
return 2; |
|
54 |
} |
|
55 |
||
56 |
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
57 |
if (section == 0) |
|
58 |
return 1; |
|
59 |
else |
|
60 |
return [self.waysToSupport count] - 1; |
|
61 |
} |
|
62 |
||
63 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
64 |
static NSString *CellIdentifier = @"Cell"; |
|
65 |
NSInteger row = [indexPath row]; |
|
66 |
NSInteger section = [indexPath section]; |
|
67 |
||
68 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
|
69 |
if (cell == nil) |
|
70 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
|
71 |
||
72 |
NSString *rowString = [self.waysToSupport objectAtIndex:(row + section)]; |
|
73 |
cell.textLabel.text = rowString; |
|
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5208
diff
changeset
|
74 |
NSString *imgString = nil; |
4115 | 75 |
|
76 |
if (section == 0) { |
|
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5208
diff
changeset
|
77 |
imgString = [BTN_DIRECTORY() stringByAppendingString:@"/StatsStar.png"]; |
4115 | 78 |
cell.textLabel.textAlignment = UITextAlignmentCenter; |
79 |
cell.imageView.image = nil; |
|
80 |
} else { |
|
81 |
cell.textLabel.textAlignment = UITextAlignmentLeft; |
|
82 |
switch (row) { |
|
83 |
case 0: |
|
84 |
imgString = @"fb.png"; |
|
85 |
break; |
|
86 |
case 1: |
|
87 |
imgString = @"tw.png"; |
|
88 |
break; |
|
89 |
case 2: |
|
90 |
imgString = @"Icon-Small.png"; |
|
91 |
break; |
|
4341 | 92 |
case 3: |
93 |
imgString = @"irc.png"; |
|
94 |
break; |
|
4115 | 95 |
default: |
96 |
DLog(@"No way"); |
|
97 |
break; |
|
98 |
} |
|
99 |
} |
|
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5208
diff
changeset
|
100 |
UIImage *img = [[UIImage alloc] initWithContentsOfFile:imgString]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5208
diff
changeset
|
101 |
cell.imageView.image = img; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5208
diff
changeset
|
102 |
if (section == 0) { |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5208
diff
changeset
|
103 |
UIImageView *imgView = [[UIImageView alloc] initWithImage:img]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5208
diff
changeset
|
104 |
cell.accessoryView = imgView; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5208
diff
changeset
|
105 |
[imgView release]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5208
diff
changeset
|
106 |
} |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5208
diff
changeset
|
107 |
[img release]; |
4115 | 108 |
|
109 |
return cell; |
|
110 |
} |
|
111 |
||
112 |
#pragma mark - |
|
113 |
#pragma mark Table view delegate |
|
114 |
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
115 |
NSString *urlString = nil; |
|
116 |
if ([indexPath section] == 0) |
|
117 |
urlString = @"http://itunes.apple.com/us/app/hedgewars/id391234866?affC=QQABAAAAHgAFasEiWjVwUGZOc3k1VGctQkRJazlacXhUclpBTVpiU2xteVdfUQ%3D%3D#&mt=8"; |
|
118 |
else |
|
119 |
switch ([indexPath row]) { |
|
120 |
case 0: |
|
121 |
urlString = @"http://www.facebook.com/Hedgewars"; |
|
122 |
break; |
|
123 |
case 1: |
|
124 |
urlString = @"http://twitter.com/hedgewars"; |
|
125 |
break; |
|
126 |
case 2: |
|
127 |
urlString = @"http://www.hedgewars.org"; |
|
128 |
break; |
|
4341 | 129 |
case 3: |
130 |
urlString = @"http://webchat.freenode.net/?channels=hedgewars"; |
|
131 |
break; |
|
4115 | 132 |
default: |
133 |
DLog(@"No way"); |
|
134 |
break; |
|
135 |
} |
|
136 |
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]]; |
|
137 |
} |
|
138 |
||
139 |
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger) section { |
|
140 |
if (section == 1) { |
|
141 |
UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 240)]; |
|
142 |
UIImage *img = [[UIImage alloc] initWithContentsOfFile:@"surprise.png"]; |
|
143 |
UIImageView *imgView = [[UIImageView alloc] initWithImage:img]; |
|
144 |
[img release]; |
|
145 |
imgView.center = CGPointMake(self.tableView.frame.size.width/2, 120); |
|
146 |
[footer addSubview:imgView]; |
|
147 |
[imgView release]; |
|
148 |
||
149 |
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 20)]; |
|
150 |
label.textAlignment = UITextAlignmentCenter; |
|
151 |
label.text = @" ♥ THANK YOU ♥ "; |
|
152 |
label.backgroundColor = [UIColor clearColor]; |
|
153 |
label.center = CGPointMake(self.tableView.frame.size.width/2, 250); |
|
154 |
[footer addSubview:label]; |
|
155 |
[label release]; |
|
156 |
||
157 |
return [footer autorelease]; |
|
158 |
} else |
|
159 |
return nil; |
|
160 |
} |
|
161 |
||
162 |
-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { |
|
163 |
// image height + label height |
|
164 |
return 265; |
|
165 |
} |
|
166 |
||
167 |
#pragma mark - |
|
168 |
#pragma mark Memory management |
|
169 |
-(void)didReceiveMemoryWarning { |
|
3884 | 170 |
[super didReceiveMemoryWarning]; |
171 |
} |
|
172 |
||
173 |
-(void) viewDidUnload { |
|
4115 | 174 |
self.waysToSupport = nil; |
175 |
MSG_DIDUNLOAD(); |
|
3884 | 176 |
[super viewDidUnload]; |
177 |
} |
|
178 |
||
179 |
-(void) dealloc { |
|
5208 | 180 |
releaseAndNil(waysToSupport); |
3884 | 181 |
[super dealloc]; |
182 |
} |
|
183 |
||
184 |
@end |