author | koda |
Sat, 24 Jul 2010 23:23:10 +0200 | |
changeset 3667 | 9359a70df013 |
parent 3662 | a44406f4369b |
child 3668 | 3f7a95234d8a |
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; |
|
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
|
49 |
MSG_DIDUNLOAD(); |
3547 | 50 |
[super viewDidUnload]; |
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: |
|
3660 | 144 |
DLog(@"Warning: unset case value in section!"); |
3547 | 145 |
break; |
146 |
} |
|
147 |
||
148 |
[aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
|
149 |
} |
|
150 |
||
3648 | 151 |
-(void) removeChat { |
3667 | 152 |
if (SDL_iPhoneKeyboardIsShown(sdlwindow)) { |
3648 | 153 |
SDL_iPhoneKeyboardHide(sdlwindow); |
3667 | 154 |
HW_chatEnd(); |
155 |
} |
|
3648 | 156 |
} |
157 |
||
3547 | 158 |
#pragma mark - |
159 |
#pragma mark actionSheet methods |
|
160 |
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex { |
|
161 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){ |
|
3649 | 162 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
3547 | 163 |
[UIView beginAnimations:@"table width less" context:NULL]; |
164 |
[UIView setAnimationDuration:0.2]; |
|
3649 | 165 |
self.view.frame = CGRectMake(screen.size.height-200, 0, 200, 170); |
3547 | 166 |
[UIView commitAnimations]; |
167 |
} |
|
168 |
||
3598 | 169 |
if ([actionSheet cancelButtonIndex] != buttonIndex) |
3547 | 170 |
HW_terminate(NO); |
171 |
else |
|
172 |
if (!isPaused) |
|
173 |
HW_pause(); |
|
174 |
} |
|
175 |
||
176 |
@end |