author | koda |
Wed, 23 Jun 2010 01:00:52 +0200 | |
changeset 3535 | 9e78c1f3d8d8 |
parent 3514 | 59dbd31e9953 |
child 3546 | ccf4854df294 |
permissions | -rw-r--r-- |
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" |
|
3340 | 12 |
#import "CommodityFunctions.h" |
3463 | 13 |
#import "SDL_sysvideo.h" |
3305 | 14 |
|
15 |
@implementation PopoverMenuViewController |
|
16 |
@synthesize menuList; |
|
17 |
||
18 |
||
3335 | 19 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
20 |
return rotationManager(interfaceOrientation); |
|
3305 | 21 |
} |
22 |
||
3335 | 23 |
|
3305 | 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; |
|
3357 | 31 |
|
3535
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3514
diff
changeset
|
32 |
NSArray *array = [[NSArray alloc] initWithObjects: |
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3514
diff
changeset
|
33 |
NSLocalizedString(@"Pause Game", @""), |
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3514
diff
changeset
|
34 |
NSLocalizedString(@"Chat", @""), |
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3514
diff
changeset
|
35 |
NSLocalizedString(@"End Game", @""), |
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3514
diff
changeset
|
36 |
nil]; |
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3514
diff
changeset
|
37 |
self.menuList = array; |
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3514
diff
changeset
|
38 |
[array release]; |
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3514
diff
changeset
|
39 |
|
3305 | 40 |
[super viewDidLoad]; |
41 |
} |
|
42 |
||
3490 | 43 |
-(void) viewDidUnload { |
3535
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3514
diff
changeset
|
44 |
self.menuList = nil; |
3490 | 45 |
[super viewDidUnload]; |
46 |
MSG_DIDUNLOAD(); |
|
47 |
} |
|
3305 | 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(); |
|
3463 | 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 |
*/ |
|
3305 | 93 |
break; |
94 |
case 2: |
|
3308 | 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 |
} |
|
3305 | 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 { |
|
3308 | 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 |
||
3305 | 132 |
if ([actionSheet cancelButtonIndex] != buttonIndex) { |
133 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"dismissPopover" object:nil]; |
|
134 |
HW_terminate(NO); |
|
135 |
} |
|
136 |
else |
|
137 |
if (!isPaused) |
|
138 |
HW_pause(); |
|
139 |
} |
|
140 |
||
141 |
@end |