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 |
|
|
17 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
|
18 |
// Overriden to allow any orientation.
|
|
19 |
return YES;
|
|
20 |
}
|
|
21 |
|
|
22 |
-(void) didReceiveMemoryWarning {
|
|
23 |
// Releases the view if it doesn't have a superview.
|
|
24 |
[super didReceiveMemoryWarning];
|
|
25 |
|
|
26 |
// Release any cached data, images, etc that aren't in use.
|
|
27 |
}
|
|
28 |
|
|
29 |
-(void) viewDidLoad {
|
|
30 |
isPaused = NO;
|
|
31 |
self.tableView.allowsSelection = YES;
|
|
32 |
self.tableView.alwaysBounceVertical = YES;
|
|
33 |
self.tableView.delaysContentTouches = NO;
|
|
34 |
menuList = [[NSArray alloc] initWithObjects:
|
|
35 |
NSLocalizedString(@"Pause Game", @""),
|
|
36 |
NSLocalizedString(@"Chat", @""),
|
|
37 |
NSLocalizedString(@"End Game", @""),
|
|
38 |
nil];
|
|
39 |
[super viewDidLoad];
|
|
40 |
}
|
|
41 |
|
|
42 |
|
|
43 |
-(void) dealloc {
|
|
44 |
[menuList release];
|
|
45 |
[super dealloc];
|
|
46 |
}
|
|
47 |
|
|
48 |
#pragma mark -
|
|
49 |
#pragma mark tableView methods
|
|
50 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
|
|
51 |
return 1;
|
|
52 |
}
|
|
53 |
|
|
54 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
55 |
return 3;
|
|
56 |
}
|
|
57 |
|
|
58 |
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
59 |
static NSString *cellIdentifier = @"CellIdentifier";
|
|
60 |
|
|
61 |
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier];
|
|
62 |
if (nil == cell) {
|
|
63 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
|
|
64 |
reuseIdentifier:cellIdentifier] autorelease];
|
|
65 |
}
|
|
66 |
cell.textLabel.text = [menuList objectAtIndex:[indexPath row]];
|
|
67 |
|
|
68 |
return cell;
|
|
69 |
}
|
|
70 |
|
|
71 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
72 |
UIActionSheet *actionSheet;
|
|
73 |
|
|
74 |
switch ([indexPath row]) {
|
|
75 |
case 0:
|
|
76 |
HW_pause();
|
|
77 |
isPaused = !isPaused;
|
|
78 |
break;
|
|
79 |
case 1:
|
|
80 |
HW_chat();
|
|
81 |
//SDL_iPhoneKeyboardShow([SDLUIKitDelegate sharedAppDelegate].window);
|
|
82 |
break;
|
|
83 |
case 2:
|
|
84 |
actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Are you reeeeeally sure?", @"")
|
|
85 |
delegate:self
|
|
86 |
cancelButtonTitle:NSLocalizedString(@"Well, maybe not...", @"")
|
|
87 |
destructiveButtonTitle:NSLocalizedString(@"Of course!", @"")
|
|
88 |
otherButtonTitles:nil];
|
|
89 |
[actionSheet showInView:self.view];
|
|
90 |
[actionSheet release];
|
|
91 |
|
|
92 |
if (!isPaused)
|
|
93 |
HW_pause();
|
|
94 |
break;
|
|
95 |
default:
|
|
96 |
NSLog(@"Warning: unset case value in section!");
|
|
97 |
break;
|
|
98 |
}
|
|
99 |
|
|
100 |
[aTableView deselectRowAtIndexPath:indexPath animated:YES];
|
|
101 |
}
|
|
102 |
|
|
103 |
#pragma mark -
|
|
104 |
#pragma mark actionSheet methods
|
|
105 |
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
|
|
106 |
if ([actionSheet cancelButtonIndex] != buttonIndex) {
|
|
107 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"dismissPopover" object:nil];
|
|
108 |
HW_terminate(NO);
|
|
109 |
}
|
|
110 |
else
|
|
111 |
if (!isPaused)
|
|
112 |
HW_pause();
|
|
113 |
}
|
|
114 |
|
|
115 |
@end
|