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