author | koda |
Sun, 25 Jul 2010 01:59:41 +0200 | |
changeset 3668 | 3f7a95234d8a |
parent 3667 | 9359a70df013 |
child 3697 | d5b30d6373fc |
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 |
NSArray *array = [[NSArray alloc] initWithObjects: |
|
3668
3f7a95234d8a
tap to play piano notes, fix for audio and pause glitch
koda
parents:
3667
diff
changeset
|
30 |
NSLocalizedString(@"Return to Game", @""), |
3547 | 31 |
NSLocalizedString(@"Chat", @""), |
32 |
NSLocalizedString(@"End Game", @""), |
|
33 |
nil]; |
|
34 |
self.menuList = array; |
|
35 |
[array release]; |
|
36 |
||
3647
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3598
diff
changeset
|
37 |
// 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
|
38 |
SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3598
diff
changeset
|
39 |
SDL_VideoDisplay *display = &_this->displays[0]; |
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3598
diff
changeset
|
40 |
sdlwindow = display->windows; |
3648 | 41 |
|
3547 | 42 |
[super viewDidLoad]; |
43 |
} |
|
44 |
||
45 |
-(void) viewDidUnload { |
|
46 |
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
|
47 |
MSG_DIDUNLOAD(); |
3547 | 48 |
[super viewDidUnload]; |
49 |
} |
|
50 |
||
51 |
-(void) dealloc { |
|
52 |
[menuList release]; |
|
53 |
[super dealloc]; |
|
54 |
} |
|
55 |
||
56 |
#pragma mark - |
|
3648 | 57 |
#pragma mark animating |
58 |
-(void) present { |
|
59 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
|
60 |
self.view.backgroundColor = [UIColor clearColor]; |
|
61 |
self.view.frame = CGRectMake(screen.size.height, 0, 200, 170); |
|
62 |
||
63 |
[UIView beginAnimations:@"showing popover" context:NULL]; |
|
64 |
[UIView setAnimationDuration:0.35]; |
|
65 |
self.view.frame = CGRectMake(screen.size.height-200, 0, 200, 170); |
|
66 |
[UIView commitAnimations]; |
|
67 |
} |
|
68 |
||
69 |
-(void) dismiss { |
|
70 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
|
71 |
[UIView beginAnimations:@"hiding popover" context:NULL]; |
|
72 |
[UIView setAnimationDuration:0.35]; |
|
73 |
self.view.frame = CGRectMake(screen.size.height, 0, 200, 170); |
|
74 |
[UIView commitAnimations]; |
|
75 |
||
76 |
[self.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.35]; |
|
77 |
||
78 |
[self removeChat]; |
|
79 |
} |
|
80 |
||
81 |
#pragma mark - |
|
3547 | 82 |
#pragma mark tableView methods |
83 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
84 |
return 1; |
|
85 |
} |
|
86 |
||
87 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
88 |
return 3; |
|
89 |
} |
|
90 |
||
91 |
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
92 |
static NSString *cellIdentifier = @"CellIdentifier"; |
|
93 |
||
94 |
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier]; |
|
95 |
if (nil == cell) { |
|
96 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault |
|
97 |
reuseIdentifier:cellIdentifier] autorelease]; |
|
98 |
} |
|
99 |
cell.textLabel.text = [menuList objectAtIndex:[indexPath row]]; |
|
100 |
||
3668
3f7a95234d8a
tap to play piano notes, fix for audio and pause glitch
koda
parents:
3667
diff
changeset
|
101 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) |
3f7a95234d8a
tap to play piano notes, fix for audio and pause glitch
koda
parents:
3667
diff
changeset
|
102 |
cell.textLabel.textAlignment = UITextAlignmentCenter; |
3f7a95234d8a
tap to play piano notes, fix for audio and pause glitch
koda
parents:
3667
diff
changeset
|
103 |
|
3547 | 104 |
return cell; |
105 |
} |
|
106 |
||
107 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
108 |
UIActionSheet *actionSheet; |
|
109 |
||
110 |
switch ([indexPath row]) { |
|
111 |
case 0: |
|
112 |
HW_pause(); |
|
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 |
break; |
|
141 |
default: |
|
3660 | 142 |
DLog(@"Warning: unset case value in section!"); |
3547 | 143 |
break; |
144 |
} |
|
145 |
||
146 |
[aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
|
147 |
} |
|
148 |
||
3648 | 149 |
-(void) removeChat { |
3667 | 150 |
if (SDL_iPhoneKeyboardIsShown(sdlwindow)) { |
3648 | 151 |
SDL_iPhoneKeyboardHide(sdlwindow); |
3667 | 152 |
HW_chatEnd(); |
153 |
} |
|
3648 | 154 |
} |
155 |
||
3547 | 156 |
#pragma mark - |
157 |
#pragma mark actionSheet methods |
|
158 |
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex { |
|
159 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){ |
|
3649 | 160 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
3547 | 161 |
[UIView beginAnimations:@"table width less" context:NULL]; |
162 |
[UIView setAnimationDuration:0.2]; |
|
3649 | 163 |
self.view.frame = CGRectMake(screen.size.height-200, 0, 200, 170); |
3547 | 164 |
[UIView commitAnimations]; |
165 |
} |
|
166 |
||
3598 | 167 |
if ([actionSheet cancelButtonIndex] != buttonIndex) |
3668
3f7a95234d8a
tap to play piano notes, fix for audio and pause glitch
koda
parents:
3667
diff
changeset
|
168 |
HW_terminate(NO); |
3547 | 169 |
} |
170 |
||
171 |
@end |