author | koda |
Thu, 03 Feb 2011 00:23:41 +0100 | |
changeset 4912 | 862b134284b2 |
parent 4861 | 91f889289a47 |
child 4920 | bc3c077e15a2 |
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 { |
|
3971 | 38 |
self.menuList = nil; |
3547 | 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 |
3926
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3924
diff
changeset
|
52 |
SDL_VideoDevice *videoDevice = SDL_GetVideoDevice(); |
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3924
diff
changeset
|
53 |
if (videoDevice) { |
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3924
diff
changeset
|
54 |
SDL_VideoDisplay *display = &videoDevice->displays[0]; |
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3924
diff
changeset
|
55 |
if (display) |
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3924
diff
changeset
|
56 |
sdlwindow = display->windows; |
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3924
diff
changeset
|
57 |
} |
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3924
diff
changeset
|
58 |
[super viewDidLoad]; |
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3924
diff
changeset
|
59 |
} |
3697 | 60 |
|
3926
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3924
diff
changeset
|
61 |
-(void) viewWillAppear:(BOOL)animated { |
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3924
diff
changeset
|
62 |
if (sdlwindow == NULL) { |
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3924
diff
changeset
|
63 |
SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3924
diff
changeset
|
64 |
if (_this) { |
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3924
diff
changeset
|
65 |
SDL_VideoDisplay *display = &_this->displays[0]; |
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3924
diff
changeset
|
66 |
if (display) |
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3924
diff
changeset
|
67 |
sdlwindow = display->windows; |
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3924
diff
changeset
|
68 |
} |
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3924
diff
changeset
|
69 |
} |
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3924
diff
changeset
|
70 |
[super viewWillAppear:animated]; |
3547 | 71 |
} |
72 |
||
73 |
-(void) viewDidUnload { |
|
74 |
self.menuList = nil; |
|
3926
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3924
diff
changeset
|
75 |
sdlwindow = NULL; |
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
|
76 |
MSG_DIDUNLOAD(); |
3547 | 77 |
[super viewDidUnload]; |
78 |
} |
|
79 |
||
80 |
-(void) dealloc { |
|
81 |
[menuList release]; |
|
82 |
[super dealloc]; |
|
83 |
} |
|
84 |
||
85 |
#pragma mark - |
|
3648 | 86 |
#pragma mark animating |
87 |
-(void) present { |
|
88 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
|
89 |
self.view.backgroundColor = [UIColor clearColor]; |
|
90 |
self.view.frame = CGRectMake(screen.size.height, 0, 200, 170); |
|
3697 | 91 |
|
3648 | 92 |
[UIView beginAnimations:@"showing popover" context:NULL]; |
93 |
[UIView setAnimationDuration:0.35]; |
|
94 |
self.view.frame = CGRectMake(screen.size.height-200, 0, 200, 170); |
|
95 |
[UIView commitAnimations]; |
|
96 |
} |
|
97 |
||
98 |
-(void) dismiss { |
|
4912
862b134284b2
change order of statspage/gamerun when running in dual screen
koda
parents:
4861
diff
changeset
|
99 |
if (IS_IPAD() == NO) { |
862b134284b2
change order of statspage/gamerun when running in dual screen
koda
parents:
4861
diff
changeset
|
100 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
862b134284b2
change order of statspage/gamerun when running in dual screen
koda
parents:
4861
diff
changeset
|
101 |
[UIView beginAnimations:@"hiding popover" context:NULL]; |
862b134284b2
change order of statspage/gamerun when running in dual screen
koda
parents:
4861
diff
changeset
|
102 |
[UIView setAnimationDuration:0.35]; |
862b134284b2
change order of statspage/gamerun when running in dual screen
koda
parents:
4861
diff
changeset
|
103 |
self.view.frame = CGRectMake(screen.size.height, 0, 200, 170); |
862b134284b2
change order of statspage/gamerun when running in dual screen
koda
parents:
4861
diff
changeset
|
104 |
[UIView commitAnimations]; |
862b134284b2
change order of statspage/gamerun when running in dual screen
koda
parents:
4861
diff
changeset
|
105 |
} |
3697 | 106 |
|
3648 | 107 |
[self.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.35]; |
3697 | 108 |
|
3648 | 109 |
[self removeChat]; |
110 |
} |
|
111 |
||
112 |
#pragma mark - |
|
3547 | 113 |
#pragma mark tableView methods |
114 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
115 |
return 1; |
|
116 |
} |
|
117 |
||
118 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
119 |
return 3; |
|
120 |
} |
|
121 |
||
122 |
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
123 |
static NSString *cellIdentifier = @"CellIdentifier"; |
|
3697 | 124 |
|
3547 | 125 |
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier]; |
126 |
if (nil == cell) { |
|
127 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault |
|
128 |
reuseIdentifier:cellIdentifier] autorelease]; |
|
129 |
} |
|
130 |
cell.textLabel.text = [menuList objectAtIndex:[indexPath row]]; |
|
3697 | 131 |
|
3996 | 132 |
if (IS_IPAD()) |
3668
3f7a95234d8a
tap to play piano notes, fix for audio and pause glitch
koda
parents:
3667
diff
changeset
|
133 |
cell.textLabel.textAlignment = UITextAlignmentCenter; |
3697 | 134 |
|
3547 | 135 |
return cell; |
136 |
} |
|
137 |
||
138 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
139 |
UIActionSheet *actionSheet; |
|
3697 | 140 |
|
3547 | 141 |
switch ([indexPath row]) { |
142 |
case 0: |
|
3791
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3737
diff
changeset
|
143 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"show help ingame" object:nil]; |
3547 | 144 |
break; |
145 |
case 1: |
|
3648 | 146 |
if (SDL_iPhoneKeyboardIsShown(sdlwindow)) |
147 |
[self removeChat]; |
|
148 |
else { |
|
149 |
HW_chat(); |
|
150 |
SDL_iPhoneKeyboardShow(sdlwindow); |
|
151 |
} |
|
3547 | 152 |
break; |
153 |
case 2: |
|
154 |
// expand the view (and table) so that the actionsheet can be selected on the iPhone |
|
4008
d87619de120d
fix an annoying bug that didn't allow returning to the ifrontend
koda
parents:
3996
diff
changeset
|
155 |
if (IS_IPAD() == NO) { |
3648 | 156 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
3547 | 157 |
[self.tableView deselectRowAtIndexPath:indexPath animated:NO]; |
158 |
[UIView beginAnimations:@"table width more" context:NULL]; |
|
159 |
[UIView setAnimationDuration:0.2]; |
|
3648 | 160 |
self.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width); |
3547 | 161 |
[UIView commitAnimations]; |
162 |
} |
|
163 |
actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Are you reeeeeally sure?", @"") |
|
164 |
delegate:self |
|
165 |
cancelButtonTitle:NSLocalizedString(@"Well, maybe not...", @"") |
|
166 |
destructiveButtonTitle:NSLocalizedString(@"Of course!", @"") |
|
167 |
otherButtonTitles:nil]; |
|
168 |
[actionSheet showInView:self.view]; |
|
169 |
[actionSheet release]; |
|
3697 | 170 |
|
3547 | 171 |
break; |
172 |
default: |
|
3660 | 173 |
DLog(@"Warning: unset case value in section!"); |
3547 | 174 |
break; |
175 |
} |
|
3697 | 176 |
|
3547 | 177 |
[aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
178 |
} |
|
179 |
||
3648 | 180 |
-(void) removeChat { |
3667 | 181 |
if (SDL_iPhoneKeyboardIsShown(sdlwindow)) { |
3648 | 182 |
SDL_iPhoneKeyboardHide(sdlwindow); |
3667 | 183 |
HW_chatEnd(); |
184 |
} |
|
3648 | 185 |
} |
186 |
||
3547 | 187 |
#pragma mark - |
188 |
#pragma mark actionSheet methods |
|
189 |
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex { |
|
4912
862b134284b2
change order of statspage/gamerun when running in dual screen
koda
parents:
4861
diff
changeset
|
190 |
if (IS_IPAD() == NO) { |
3649 | 191 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
3547 | 192 |
[UIView beginAnimations:@"table width less" context:NULL]; |
193 |
[UIView setAnimationDuration:0.2]; |
|
3649 | 194 |
self.view.frame = CGRectMake(screen.size.height-200, 0, 200, 170); |
3547 | 195 |
[UIView commitAnimations]; |
196 |
} |
|
3697 | 197 |
|
3924 | 198 |
if ([actionSheet cancelButtonIndex] != buttonIndex) |
4861
91f889289a47
(ios) perform a small change about how to close the game window, should hopefully save memory and avoid crashes (who am i kidding? that's the usual PR talk...)
koda
parents:
4358
diff
changeset
|
199 |
HW_terminate(NO); |
3547 | 200 |
} |
201 |
||
202 |
@end |