3305
|
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"
|
|
10 |
#import "PopoverMenuViewController.h"
|
|
11 |
#import "PascalImports.h"
|
|
12 |
|
|
13 |
@implementation PopoverMenuViewController
|
|
14 |
@synthesize menuList;
|
|
15 |
|
|
16 |
|
3335
|
17 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
|
|
18 |
return rotationManager(interfaceOrientation);
|
3305
|
19 |
}
|
|
20 |
|
3335
|
21 |
|
3305
|
22 |
-(void) didReceiveMemoryWarning {
|
|
23 |
// Releases the view if it doesn't have a superview.
|
|
24 |
[super didReceiveMemoryWarning];
|
3308
|
25 |
self.menuList = nil;
|
3305
|
26 |
}
|
|
27 |
|
|
28 |
-(void) viewDidLoad {
|
|
29 |
isPaused = NO;
|
|
30 |
self.tableView.allowsSelection = YES;
|
|
31 |
self.tableView.alwaysBounceVertical = YES;
|
|
32 |
self.tableView.delaysContentTouches = NO;
|
|
33 |
menuList = [[NSArray alloc] initWithObjects:
|
|
34 |
NSLocalizedString(@"Pause Game", @""),
|
|
35 |
NSLocalizedString(@"Chat", @""),
|
|
36 |
NSLocalizedString(@"End Game", @""),
|
|
37 |
nil];
|
|
38 |
[super viewDidLoad];
|
|
39 |
}
|
|
40 |
|
|
41 |
|
|
42 |
-(void) dealloc {
|
|
43 |
[menuList release];
|
|
44 |
[super dealloc];
|
|
45 |
}
|
|
46 |
|
|
47 |
#pragma mark -
|
|
48 |
#pragma mark tableView methods
|
|
49 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
|
|
50 |
return 1;
|
|
51 |
}
|
|
52 |
|
|
53 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
54 |
return 3;
|
|
55 |
}
|
|
56 |
|
|
57 |
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
58 |
static NSString *cellIdentifier = @"CellIdentifier";
|
|
59 |
|
|
60 |
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier];
|
|
61 |
if (nil == cell) {
|
|
62 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
|
|
63 |
reuseIdentifier:cellIdentifier] autorelease];
|
|
64 |
}
|
|
65 |
cell.textLabel.text = [menuList objectAtIndex:[indexPath row]];
|
|
66 |
|
|
67 |
return cell;
|
|
68 |
}
|
|
69 |
|
|
70 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
71 |
UIActionSheet *actionSheet;
|
|
72 |
|
|
73 |
switch ([indexPath row]) {
|
|
74 |
case 0:
|
|
75 |
HW_pause();
|
|
76 |
isPaused = !isPaused;
|
|
77 |
break;
|
|
78 |
case 1:
|
|
79 |
HW_chat();
|
|
80 |
//SDL_iPhoneKeyboardShow([SDLUIKitDelegate sharedAppDelegate].window);
|
|
81 |
break;
|
|
82 |
case 2:
|
3308
|
83 |
// expand the view (and table) so that the actionsheet can be selected on the iPhone
|
|
84 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
|
|
85 |
[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
|
|
86 |
[UIView beginAnimations:@"table width more" context:NULL];
|
|
87 |
[UIView setAnimationDuration:0.2];
|
|
88 |
self.view.frame = CGRectMake(0, 0, 480, 320);
|
|
89 |
[UIView commitAnimations];
|
|
90 |
}
|
3305
|
91 |
actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Are you reeeeeally sure?", @"")
|
|
92 |
delegate:self
|
|
93 |
cancelButtonTitle:NSLocalizedString(@"Well, maybe not...", @"")
|
|
94 |
destructiveButtonTitle:NSLocalizedString(@"Of course!", @"")
|
|
95 |
otherButtonTitles:nil];
|
|
96 |
[actionSheet showInView:self.view];
|
|
97 |
[actionSheet release];
|
|
98 |
|
|
99 |
if (!isPaused)
|
|
100 |
HW_pause();
|
|
101 |
break;
|
|
102 |
default:
|
|
103 |
NSLog(@"Warning: unset case value in section!");
|
|
104 |
break;
|
|
105 |
}
|
|
106 |
|
|
107 |
[aTableView deselectRowAtIndexPath:indexPath animated:YES];
|
|
108 |
}
|
|
109 |
|
|
110 |
#pragma mark -
|
|
111 |
#pragma mark actionSheet methods
|
|
112 |
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
|
3308
|
113 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
|
|
114 |
[UIView beginAnimations:@"table width less" context:NULL];
|
|
115 |
[UIView setAnimationDuration:0.2];
|
|
116 |
self.view.frame = CGRectMake(280, 0, 200, 170);
|
|
117 |
[UIView commitAnimations];
|
|
118 |
}
|
|
119 |
|
3305
|
120 |
if ([actionSheet cancelButtonIndex] != buttonIndex) {
|
|
121 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"dismissPopover" object:nil];
|
|
122 |
HW_terminate(NO);
|
|
123 |
}
|
|
124 |
else
|
|
125 |
if (!isPaused)
|
|
126 |
HW_pause();
|
|
127 |
}
|
|
128 |
|
|
129 |
@end
|