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