author | koda |
Sat, 04 Sep 2010 16:24:00 +0200 | |
changeset 3829 | 81db3c85784b |
parent 3791 | 98072b3871c1 |
child 3922 | 44804043b691 |
permissions | -rw-r--r-- |
3829 | 1 |
/* |
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
|
3 |
* Copyright (c) 2009-2010 Vittorio Giovara <vittorio.giovara@gmail.com> |
|
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 25/03/2010. |
|
19 |
*/ |
|
20 |
||
3547 | 21 |
|
22 |
#import "SDL_uikitappdelegate.h" |
|
3647
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3598
diff
changeset
|
23 |
#import "InGameMenuViewController.h" |
3547 | 24 |
#import "PascalImports.h" |
25 |
#import "CommodityFunctions.h" |
|
26 |
#import "SDL_sysvideo.h" |
|
27 |
||
3647
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3598
diff
changeset
|
28 |
@implementation InGameMenuViewController |
3547 | 29 |
@synthesize menuList; |
30 |
||
31 |
||
32 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
33 |
return rotationManager(interfaceOrientation); |
|
34 |
} |
|
35 |
||
36 |
-(void) didReceiveMemoryWarning { |
|
37 |
// Releases the view if it doesn't have a superview. |
|
38 |
[super didReceiveMemoryWarning]; |
|
39 |
} |
|
40 |
||
41 |
-(void) viewDidLoad { |
|
42 |
NSArray *array = [[NSArray alloc] initWithObjects: |
|
3701 | 43 |
NSLocalizedString(@"Show Help", @""), |
3737
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3701
diff
changeset
|
44 |
NSLocalizedString(@"Tag", @""), |
3547 | 45 |
NSLocalizedString(@"End Game", @""), |
46 |
nil]; |
|
47 |
self.menuList = array; |
|
48 |
[array release]; |
|
3697 | 49 |
|
3647
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3598
diff
changeset
|
50 |
// save the sdl window (!= uikit window) for future reference |
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3598
diff
changeset
|
51 |
SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3598
diff
changeset
|
52 |
SDL_VideoDisplay *display = &_this->displays[0]; |
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3598
diff
changeset
|
53 |
sdlwindow = display->windows; |
3697 | 54 |
|
3547 | 55 |
[super viewDidLoad]; |
56 |
} |
|
57 |
||
58 |
-(void) viewDidUnload { |
|
59 |
self.menuList = nil; |
|
3662
a44406f4369b
polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents:
3660
diff
changeset
|
60 |
MSG_DIDUNLOAD(); |
3547 | 61 |
[super viewDidUnload]; |
62 |
} |
|
63 |
||
64 |
-(void) dealloc { |
|
65 |
[menuList release]; |
|
66 |
[super dealloc]; |
|
67 |
} |
|
68 |
||
69 |
#pragma mark - |
|
3648 | 70 |
#pragma mark animating |
71 |
-(void) present { |
|
72 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
|
73 |
self.view.backgroundColor = [UIColor clearColor]; |
|
74 |
self.view.frame = CGRectMake(screen.size.height, 0, 200, 170); |
|
3697 | 75 |
|
3648 | 76 |
[UIView beginAnimations:@"showing popover" context:NULL]; |
77 |
[UIView setAnimationDuration:0.35]; |
|
78 |
self.view.frame = CGRectMake(screen.size.height-200, 0, 200, 170); |
|
79 |
[UIView commitAnimations]; |
|
80 |
} |
|
81 |
||
82 |
-(void) dismiss { |
|
83 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
|
84 |
[UIView beginAnimations:@"hiding popover" context:NULL]; |
|
85 |
[UIView setAnimationDuration:0.35]; |
|
86 |
self.view.frame = CGRectMake(screen.size.height, 0, 200, 170); |
|
87 |
[UIView commitAnimations]; |
|
3697 | 88 |
|
3648 | 89 |
[self.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.35]; |
3697 | 90 |
|
3648 | 91 |
[self removeChat]; |
92 |
} |
|
93 |
||
94 |
#pragma mark - |
|
3547 | 95 |
#pragma mark tableView methods |
96 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
97 |
return 1; |
|
98 |
} |
|
99 |
||
100 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
101 |
return 3; |
|
102 |
} |
|
103 |
||
104 |
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
105 |
static NSString *cellIdentifier = @"CellIdentifier"; |
|
3697 | 106 |
|
3547 | 107 |
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier]; |
108 |
if (nil == cell) { |
|
109 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault |
|
110 |
reuseIdentifier:cellIdentifier] autorelease]; |
|
111 |
} |
|
112 |
cell.textLabel.text = [menuList objectAtIndex:[indexPath row]]; |
|
3697 | 113 |
|
3668
3f7a95234d8a
tap to play piano notes, fix for audio and pause glitch
koda
parents:
3667
diff
changeset
|
114 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) |
3f7a95234d8a
tap to play piano notes, fix for audio and pause glitch
koda
parents:
3667
diff
changeset
|
115 |
cell.textLabel.textAlignment = UITextAlignmentCenter; |
3697 | 116 |
|
3547 | 117 |
return cell; |
118 |
} |
|
119 |
||
120 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
121 |
UIActionSheet *actionSheet; |
|
3697 | 122 |
|
3547 | 123 |
switch ([indexPath row]) { |
124 |
case 0: |
|
3791
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3737
diff
changeset
|
125 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"show help ingame" object:nil]; |
3547 | 126 |
break; |
127 |
case 1: |
|
3648 | 128 |
if (SDL_iPhoneKeyboardIsShown(sdlwindow)) |
129 |
[self removeChat]; |
|
130 |
else { |
|
131 |
HW_chat(); |
|
132 |
SDL_iPhoneKeyboardShow(sdlwindow); |
|
133 |
} |
|
3547 | 134 |
break; |
135 |
case 2: |
|
136 |
// expand the view (and table) so that the actionsheet can be selected on the iPhone |
|
137 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { |
|
3648 | 138 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
3547 | 139 |
[self.tableView deselectRowAtIndexPath:indexPath animated:NO]; |
140 |
[UIView beginAnimations:@"table width more" context:NULL]; |
|
141 |
[UIView setAnimationDuration:0.2]; |
|
3648 | 142 |
self.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width); |
3547 | 143 |
[UIView commitAnimations]; |
144 |
} |
|
145 |
actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Are you reeeeeally sure?", @"") |
|
146 |
delegate:self |
|
147 |
cancelButtonTitle:NSLocalizedString(@"Well, maybe not...", @"") |
|
148 |
destructiveButtonTitle:NSLocalizedString(@"Of course!", @"") |
|
149 |
otherButtonTitles:nil]; |
|
150 |
[actionSheet showInView:self.view]; |
|
151 |
[actionSheet release]; |
|
3697 | 152 |
|
3547 | 153 |
break; |
154 |
default: |
|
3660 | 155 |
DLog(@"Warning: unset case value in section!"); |
3547 | 156 |
break; |
157 |
} |
|
3697 | 158 |
|
3547 | 159 |
[aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
160 |
} |
|
161 |
||
3648 | 162 |
-(void) removeChat { |
3667 | 163 |
if (SDL_iPhoneKeyboardIsShown(sdlwindow)) { |
3648 | 164 |
SDL_iPhoneKeyboardHide(sdlwindow); |
3667 | 165 |
HW_chatEnd(); |
166 |
} |
|
3648 | 167 |
} |
168 |
||
3547 | 169 |
#pragma mark - |
170 |
#pragma mark actionSheet methods |
|
171 |
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex { |
|
172 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){ |
|
3649 | 173 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
3547 | 174 |
[UIView beginAnimations:@"table width less" context:NULL]; |
175 |
[UIView setAnimationDuration:0.2]; |
|
3649 | 176 |
self.view.frame = CGRectMake(screen.size.height-200, 0, 200, 170); |
3547 | 177 |
[UIView commitAnimations]; |
178 |
} |
|
3697 | 179 |
|
3598 | 180 |
if ([actionSheet cancelButtonIndex] != buttonIndex) |
3697 | 181 |
HW_terminate(NO); |
3547 | 182 |
} |
183 |
||
184 |
@end |