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