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