1 /* |
|
2 * Hedgewars-iOS, a Hedgewars port for iOS devices |
|
3 * Copyright (c) 2009-2011 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 |
|
21 |
|
22 #import "InGameMenuViewController.h" |
|
23 #import "SDL_sysvideo.h" |
|
24 #import "SDL_uikitkeyboard.h" |
|
25 |
|
26 //FIXME: add a proper #import when this is exposed in SDL |
|
27 extern UIView *SDL_getUikitView(void *); |
|
28 |
|
29 #define VIEW_HEIGHT 200 |
|
30 |
|
31 @implementation InGameMenuViewController |
|
32 |
|
33 |
|
34 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
35 return rotationManager(interfaceOrientation); |
|
36 } |
|
37 |
|
38 #pragma mark - |
|
39 #pragma mark animating |
|
40 -(void) present { |
|
41 CGRect screen = [[UIScreen mainScreen] bounds]; |
|
42 self.view.backgroundColor = [UIColor clearColor]; |
|
43 self.view.frame = CGRectMake(screen.size.height, 0, 200, VIEW_HEIGHT); |
|
44 |
|
45 [UIView beginAnimations:@"showing popover" context:NULL]; |
|
46 [UIView setAnimationDuration:0.35]; |
|
47 self.view.frame = CGRectMake(screen.size.height-200, 0, 200, VIEW_HEIGHT); |
|
48 [UIView commitAnimations]; |
|
49 } |
|
50 |
|
51 -(void) dismiss { |
|
52 if (IS_IPAD() == NO) { |
|
53 CGRect screen = [[UIScreen mainScreen] bounds]; |
|
54 [UIView beginAnimations:@"hiding popover" context:NULL]; |
|
55 [UIView setAnimationDuration:0.35]; |
|
56 self.view.frame = CGRectMake(screen.size.height, 0, 200, VIEW_HEIGHT); |
|
57 [UIView commitAnimations]; |
|
58 [self.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.35]; |
|
59 } |
|
60 |
|
61 SDL_iPhoneKeyboardHide((SDL_Window *)HW_getSDLWindow()); |
|
62 } |
|
63 |
|
64 #pragma mark - |
|
65 #pragma mark tableView methods |
|
66 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
67 return 1; |
|
68 } |
|
69 |
|
70 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
71 return 3; |
|
72 } |
|
73 |
|
74 -(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
75 static NSString *cellIdentifier = @"CellIdentifier"; |
|
76 |
|
77 NSInteger row = [indexPath row]; |
|
78 NSString *cellTitle; |
|
79 if (row == 0) |
|
80 cellTitle = NSLocalizedString(@"Show Help", @""); |
|
81 else if (row == 1) |
|
82 cellTitle = NSLocalizedString(@"Tag", @""); |
|
83 else |
|
84 cellTitle = NSLocalizedString(@"End Game", @""); |
|
85 |
|
86 UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier]; |
|
87 if (nil == cell) { |
|
88 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault |
|
89 reuseIdentifier:cellIdentifier] autorelease]; |
|
90 } |
|
91 cell.textLabel.text = cellTitle; |
|
92 |
|
93 if (IS_IPAD()) |
|
94 cell.textLabel.textAlignment = UITextAlignmentCenter; |
|
95 |
|
96 return cell; |
|
97 } |
|
98 |
|
99 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
100 UIActionSheet *actionSheet; |
|
101 |
|
102 switch ([indexPath row]) { |
|
103 case 0: |
|
104 [[NSNotificationCenter defaultCenter] postNotificationName:@"show help ingame" object:nil]; |
|
105 |
|
106 break; |
|
107 case 1: |
|
108 HW_chat(); |
|
109 SDL_iPhoneKeyboardShow((SDL_Window *)HW_getSDLWindow()); |
|
110 |
|
111 break; |
|
112 case 2: |
|
113 actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Are you reeeeeally sure?", @"") |
|
114 delegate:self |
|
115 cancelButtonTitle:NSLocalizedString(@"Well, maybe not...", @"") |
|
116 destructiveButtonTitle:NSLocalizedString(@"Of course!", @"") |
|
117 otherButtonTitles:nil]; |
|
118 [actionSheet showInView:(IS_IPAD() ? self.view : SDL_getUikitView(HW_getSDLWindow()))]; |
|
119 [actionSheet release]; |
|
120 |
|
121 break; |
|
122 default: |
|
123 DLog(@"Warning: unset case value in section!"); |
|
124 break; |
|
125 } |
|
126 |
|
127 [aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
|
128 } |
|
129 |
|
130 #pragma mark - |
|
131 #pragma mark actionSheet methods |
|
132 -(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex { |
|
133 if ([actionSheet cancelButtonIndex] != buttonIndex) { |
|
134 SDL_iPhoneKeyboardHide((SDL_Window *)HW_getSDLWindow()); |
|
135 HW_terminate(NO); |
|
136 } |
|
137 } |
|
138 |
|
139 @end |
|