author | koda |
Mon, 02 Aug 2010 00:55:24 +0200 | |
changeset 3703 | 12d17c6e8855 |
parent 3701 | 8c449776ebe6 |
child 3737 | 2ba6ac8a114b |
permissions | -rw-r--r-- |
3547 | 1 |
// |
2 |
// MainMenuViewController.m |
|
3 |
// hwengine |
|
4 |
// |
|
5 |
// Created by Vittorio on 08/01/10. |
|
6 |
// Copyright 2010 __MyCompanyName__. All rights reserved. |
|
7 |
// |
|
8 |
||
9 |
#import "MainMenuViewController.h" |
|
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3701
diff
changeset
|
10 |
#import "CommodityFunctions.h" |
3547 | 11 |
#import "SDL_uikitappdelegate.h" |
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3701
diff
changeset
|
12 |
#import "SDL_mixer.h" |
3547 | 13 |
#import "PascalImports.h" |
14 |
#import "GameConfigViewController.h" |
|
15 |
#import "SplitViewRootController.h" |
|
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3701
diff
changeset
|
16 |
#import "AboutViewController.h" |
3547 | 17 |
|
18 |
@implementation MainMenuViewController |
|
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3701
diff
changeset
|
19 |
@synthesize versionLabel, gameConfigViewController, settingsViewController, aboutViewController; |
3547 | 20 |
|
21 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
22 |
return rotationManager(interfaceOrientation); |
|
23 |
} |
|
24 |
||
25 |
- (void)didReceiveMemoryWarning { |
|
26 |
// Releases the view if it doesn't have a superview. |
|
27 |
[super didReceiveMemoryWarning]; |
|
3701 | 28 |
if (self.settingsViewController.view.superview == nil) |
29 |
self.settingsViewController = nil; |
|
30 |
if (self.gameConfigViewController.view.superview == nil) |
|
31 |
self.gameConfigViewController = nil; |
|
3547 | 32 |
MSG_MEMCLEAN(); |
33 |
} |
|
34 |
||
3667 | 35 |
// using a different thread for audio 'cos it's slow |
36 |
-(void) initAudioThread { |
|
37 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
|
38 |
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 1, 512); |
|
39 |
[pool release]; |
|
40 |
} |
|
41 |
||
3547 | 42 |
-(void) viewDidLoad { |
3667 | 43 |
[NSThread detachNewThreadSelector:@selector(initAudioThread) |
44 |
toTarget:self |
|
45 |
withObject:nil]; |
|
3697 | 46 |
|
3547 | 47 |
char *ver; |
48 |
HW_versionInfo(NULL, &ver); |
|
49 |
NSString *versionNumber = [[NSString alloc] initWithCString:ver]; |
|
50 |
self.versionLabel.text = versionNumber; |
|
51 |
[versionNumber release]; |
|
52 |
||
53 |
// listen to request to remove the modalviewcontroller |
|
54 |
[[NSNotificationCenter defaultCenter] addObserver:self |
|
55 |
selector:@selector(dismissModalViewController) |
|
3697 | 56 |
name: @"dismissModalView" |
3547 | 57 |
object:nil]; |
3697 | 58 |
|
3547 | 59 |
// initialize some files the first time we load the game |
3697 | 60 |
if (!([[NSFileManager defaultManager] fileExistsAtPath:SETTINGS_FILE()])) |
3547 | 61 |
[NSThread detachNewThreadSelector:@selector(checkFirstRun) toTarget:self withObject:nil]; |
3697 | 62 |
|
3547 | 63 |
[super viewDidLoad]; |
64 |
} |
|
65 |
||
66 |
// this is called to verify whether it's the first time the app is launched |
|
67 |
// if it is it blocks user interaction with an alertView until files are created |
|
68 |
-(void) checkFirstRun { |
|
69 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
|
3660 | 70 |
DLog(@"First time run, creating settings files at %@", SETTINGS_FILE()); |
3697 | 71 |
|
3547 | 72 |
// show a popup with an indicator to make the user wait |
73 |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Please wait",@"") |
|
74 |
message:nil |
|
75 |
delegate:nil |
|
76 |
cancelButtonTitle:nil |
|
77 |
otherButtonTitles:nil]; |
|
78 |
[alert show]; |
|
3697 | 79 |
|
80 |
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] |
|
3547 | 81 |
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; |
82 |
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50); |
|
83 |
[indicator startAnimating]; |
|
84 |
[alert addSubview:indicator]; |
|
85 |
[indicator release]; |
|
3697 | 86 |
|
3547 | 87 |
// create default files (teams/weapons/scheme) |
88 |
createTeamNamed(@"Pirates"); |
|
89 |
createTeamNamed(@"Ninjas"); |
|
90 |
createWeaponNamed(@"Default"); |
|
91 |
createSchemeNamed(@"Default"); |
|
3697 | 92 |
|
3547 | 93 |
// create settings.plist |
94 |
NSMutableDictionary *saveDict = [[NSMutableDictionary alloc] init]; |
|
95 |
||
96 |
[saveDict setObject:@"" forKey:@"username"]; |
|
97 |
[saveDict setObject:@"" forKey:@"password"]; |
|
98 |
[saveDict setObject:[NSNumber numberWithBool:YES] forKey:@"music"]; |
|
99 |
[saveDict setObject:[NSNumber numberWithBool:YES] forKey:@"sound"]; |
|
100 |
[saveDict setObject:[NSNumber numberWithBool:NO] forKey:@"alternate"]; |
|
101 |
||
102 |
[saveDict writeToFile:SETTINGS_FILE() atomically:YES]; |
|
3697 | 103 |
[saveDict release]; |
104 |
||
3547 | 105 |
// ok let the user take control |
106 |
[alert dismissWithClickedButtonIndex:0 animated:YES]; |
|
107 |
[alert release]; |
|
108 |
||
109 |
[pool release]; |
|
3621 | 110 |
|
111 |
// TODO: instead of this useless runtime initialization, check that all ammos remain compatible with engine |
|
3547 | 112 |
} |
113 |
||
114 |
#pragma mark - |
|
115 |
-(IBAction) switchViews:(id) sender { |
|
116 |
UIButton *button = (UIButton *)sender; |
|
117 |
UIAlertView *alert; |
|
118 |
NSString *debugStr; |
|
119 |
||
120 |
switch (button.tag) { |
|
121 |
case 0: |
|
3701 | 122 |
if (nil == self.gameConfigViewController) { |
123 |
GameConfigViewController *gcvc = [[GameConfigViewController alloc] initWithNibName:@"GameConfigViewController" bundle:nil]; |
|
124 |
self.gameConfigViewController = gcvc; |
|
125 |
[gcvc release]; |
|
126 |
} |
|
3547 | 127 |
|
3701 | 128 |
[self presentModalViewController:self.gameConfigViewController animated:YES]; |
3547 | 129 |
break; |
130 |
case 2: |
|
3701 | 131 |
if (nil == self.settingsViewController) { |
132 |
SplitViewRootController *svrc = [[SplitViewRootController alloc] initWithNibName:nil bundle:nil]; |
|
133 |
svrc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; |
|
134 |
self.settingsViewController = svrc; |
|
135 |
[svrc release]; |
|
3547 | 136 |
} |
3697 | 137 |
|
3701 | 138 |
[self presentModalViewController:self.settingsViewController animated:YES]; |
3547 | 139 |
break; |
140 |
case 3: |
|
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3701
diff
changeset
|
141 |
if (nil == self.aboutViewController) { |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3701
diff
changeset
|
142 |
AboutViewController *about = [[AboutViewController alloc] initWithNibName:@"AboutViewController" bundle:nil]; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3701
diff
changeset
|
143 |
about.modalTransitionStyle = UIModalPresentationFormSheet; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3701
diff
changeset
|
144 |
self.aboutViewController = about; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3701
diff
changeset
|
145 |
[about release]; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3701
diff
changeset
|
146 |
} |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3701
diff
changeset
|
147 |
|
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3701
diff
changeset
|
148 |
[self presentModalViewController:self.aboutViewController animated:YES]; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3701
diff
changeset
|
149 |
/* |
3547 | 150 |
debugStr = [[NSString alloc] initWithContentsOfFile:DEBUG_FILE()]; |
151 |
UITextView *scroll = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.height, self.view.frame.size.width)]; |
|
152 |
scroll.text = debugStr; |
|
153 |
[debugStr release]; |
|
154 |
scroll.editable = NO; |
|
3697 | 155 |
|
3547 | 156 |
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; |
157 |
[btn addTarget:scroll action:@selector(removeFromSuperview) forControlEvents:UIControlEventTouchUpInside]; |
|
158 |
btn.backgroundColor = [UIColor blackColor]; |
|
159 |
btn.frame = CGRectMake(self.view.frame.size.height-70, 0, 70, 70); |
|
160 |
[scroll addSubview:btn]; |
|
161 |
[self.view addSubview:scroll]; |
|
162 |
[scroll release]; |
|
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3701
diff
changeset
|
163 |
*/ |
3547 | 164 |
break; |
165 |
default: |
|
166 |
alert = [[UIAlertView alloc] initWithTitle:@"Not Yet Implemented" |
|
167 |
message:@"Sorry, this feature is not yet implemented" |
|
168 |
delegate:nil |
|
169 |
cancelButtonTitle:@"Well, don't worry" |
|
170 |
otherButtonTitles:nil]; |
|
171 |
[alert show]; |
|
172 |
[alert release]; |
|
173 |
break; |
|
174 |
} |
|
175 |
} |
|
176 |
||
177 |
// allows child controllers to return to the main controller |
|
178 |
-(void) dismissModalViewController { |
|
179 |
[self dismissModalViewControllerAnimated:YES]; |
|
180 |
} |
|
181 |
||
182 |
-(void) viewDidUnload { |
|
183 |
self.versionLabel = nil; |
|
3701 | 184 |
self.gameConfigViewController = nil; |
185 |
self.settingsViewController = nil; |
|
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3701
diff
changeset
|
186 |
self.aboutViewController = nil; |
3662
a44406f4369b
polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents:
3660
diff
changeset
|
187 |
MSG_DIDUNLOAD(); |
3547 | 188 |
[super viewDidUnload]; |
189 |
} |
|
190 |
||
191 |
-(void) dealloc { |
|
192 |
[versionLabel release]; |
|
193 |
[settingsViewController release]; |
|
194 |
[gameConfigViewController release]; |
|
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3701
diff
changeset
|
195 |
[aboutViewController release]; |
3547 | 196 |
[super dealloc]; |
197 |
} |
|
198 |
||
199 |
@end |