author | koda |
Sat, 17 Jul 2010 06:56:39 +0200 | |
changeset 3648 | 2477029463ed |
parent 3647 | 0d0df215fb52 |
child 3649 | bc35f8fee587 |
permissions | -rw-r--r-- |
3547 | 1 |
// |
2 |
// popupMenuViewController.m |
|
3 |
// HedgewarsMobile |
|
4 |
// |
|
5 |
// Created by Vittorio on 25/03/10. |
|
6 |
// Copyright 2010 __MyCompanyName__. All rights reserved. |
|
7 |
// |
|
8 |
||
9 |
#import "SDL_uikitappdelegate.h" |
|
3647
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3598
diff
changeset
|
10 |
#import "InGameMenuViewController.h" |
3547 | 11 |
#import "PascalImports.h" |
12 |
#import "CommodityFunctions.h" |
|
13 |
#import "SDL_sysvideo.h" |
|
14 |
||
3647
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3598
diff
changeset
|
15 |
@implementation InGameMenuViewController |
3547 | 16 |
@synthesize menuList; |
17 |
||
18 |
||
19 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
20 |
return rotationManager(interfaceOrientation); |
|
21 |
} |
|
22 |
||
23 |
-(void) didReceiveMemoryWarning { |
|
24 |
// Releases the view if it doesn't have a superview. |
|
25 |
[super didReceiveMemoryWarning]; |
|
26 |
} |
|
27 |
||
28 |
-(void) viewDidLoad { |
|
29 |
isPaused = NO; |
|
30 |
||
31 |
NSArray *array = [[NSArray alloc] initWithObjects: |
|
32 |
NSLocalizedString(@"Pause Game", @""), |
|
33 |
NSLocalizedString(@"Chat", @""), |
|
34 |
NSLocalizedString(@"End Game", @""), |
|
35 |
nil]; |
|
36 |
self.menuList = array; |
|
37 |
[array release]; |
|
38 |
||
3647
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3598
diff
changeset
|
39 |
// 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
|
40 |
SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3598
diff
changeset
|
41 |
SDL_VideoDisplay *display = &_this->displays[0]; |
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3598
diff
changeset
|
42 |
sdlwindow = display->windows; |
3648 | 43 |
|
3547 | 44 |
[super viewDidLoad]; |
45 |
} |
|
46 |
||
47 |
-(void) viewDidUnload { |
|
48 |
self.menuList = nil; |
|
49 |
[super viewDidUnload]; |
|
50 |
MSG_DIDUNLOAD(); |
|
51 |
} |
|
52 |
||
53 |
-(void) dealloc { |
|
54 |
[menuList release]; |
|
55 |
[super dealloc]; |
|
56 |
} |
|
57 |
||
58 |
#pragma mark - |
|
3648 | 59 |
#pragma mark animating |
60 |
-(void) present { |
|
61 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
|
62 |
self.view.backgroundColor = [UIColor clearColor]; |
|
63 |
self.view.frame = CGRectMake(screen.size.height, 0, 200, 170); |
|
64 |
||
65 |
[UIView beginAnimations:@"showing popover" context:NULL]; |
|
66 |
[UIView setAnimationDuration:0.35]; |
|
67 |
self.view.frame = CGRectMake(screen.size.height-200, 0, 200, 170); |
|
68 |
[UIView commitAnimations]; |
|
69 |
} |
|
70 |
||
71 |
-(void) dismiss { |
|
72 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
|
73 |
[UIView beginAnimations:@"hiding popover" context:NULL]; |
|
74 |
[UIView setAnimationDuration:0.35]; |
|
75 |
self.view.frame = CGRectMake(screen.size.height, 0, 200, 170); |
|
76 |
[UIView commitAnimations]; |
|
77 |
||
78 |
[self.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.35]; |
|
79 |
||
80 |
[self removeChat]; |
|
81 |
} |
|
82 |
||
83 |
#pragma mark - |
|
3547 | 84 |
#pragma mark tableView methods |
85 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
86 |
return 1; |
|
87 |
} |
|
88 |
||
89 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
90 |
return 3; |
|
91 |
} |
|
92 |
||
93 |
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
94 |
static NSString *cellIdentifier = @"CellIdentifier"; |
|
95 |
||
96 |
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier]; |
|
97 |
if (nil == cell) { |
|
98 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault |
|
99 |
reuseIdentifier:cellIdentifier] autorelease]; |
|
100 |
} |
|
101 |
cell.textLabel.text = [menuList objectAtIndex:[indexPath row]]; |
|
102 |
||
103 |
return cell; |
|
104 |
} |
|
105 |
||
106 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
107 |
UIActionSheet *actionSheet; |
|
108 |
||
109 |
switch ([indexPath row]) { |
|
110 |
case 0: |
|
111 |
HW_pause(); |
|
112 |
isPaused = !isPaused; |
|
113 |
break; |
|
114 |
case 1: |
|
3648 | 115 |
if (SDL_iPhoneKeyboardIsShown(sdlwindow)) |
116 |
[self removeChat]; |
|
117 |
else { |
|
118 |
HW_chat(); |
|
119 |
SDL_iPhoneKeyboardShow(sdlwindow); |
|
120 |
} |
|
3547 | 121 |
break; |
122 |
case 2: |
|
123 |
// expand the view (and table) so that the actionsheet can be selected on the iPhone |
|
124 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { |
|
3648 | 125 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
3547 | 126 |
[self.tableView deselectRowAtIndexPath:indexPath animated:NO]; |
127 |
[UIView beginAnimations:@"table width more" context:NULL]; |
|
128 |
[UIView setAnimationDuration:0.2]; |
|
3648 | 129 |
self.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width); |
3547 | 130 |
[UIView commitAnimations]; |
131 |
} |
|
132 |
actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Are you reeeeeally sure?", @"") |
|
133 |
delegate:self |
|
134 |
cancelButtonTitle:NSLocalizedString(@"Well, maybe not...", @"") |
|
135 |
destructiveButtonTitle:NSLocalizedString(@"Of course!", @"") |
|
136 |
otherButtonTitles:nil]; |
|
137 |
[actionSheet showInView:self.view]; |
|
138 |
[actionSheet release]; |
|
139 |
||
140 |
if (!isPaused) |
|
141 |
HW_pause(); |
|
142 |
break; |
|
143 |
default: |
|
144 |
NSLog(@"Warning: unset case value in section!"); |
|
145 |
break; |
|
146 |
} |
|
147 |
||
148 |
[aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
|
149 |
} |
|
150 |
||
3648 | 151 |
-(void) removeChat { |
152 |
HW_chatEnd(); |
|
153 |
if (SDL_iPhoneKeyboardIsShown(sdlwindow)) |
|
154 |
SDL_iPhoneKeyboardHide(sdlwindow); |
|
155 |
} |
|
156 |
||
3547 | 157 |
#pragma mark - |
158 |
#pragma mark actionSheet methods |
|
159 |
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex { |
|
160 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){ |
|
161 |
[UIView beginAnimations:@"table width less" context:NULL]; |
|
162 |
[UIView setAnimationDuration:0.2]; |
|
163 |
self.view.frame = CGRectMake(280, 0, 200, 170); |
|
164 |
[UIView commitAnimations]; |
|
165 |
} |
|
166 |
||
3598 | 167 |
if ([actionSheet cancelButtonIndex] != buttonIndex) |
3547 | 168 |
HW_terminate(NO); |
169 |
else |
|
170 |
if (!isPaused) |
|
171 |
HW_pause(); |
|
172 |
} |
|
173 |
||
174 |
@end |