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