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