author | koda |
Sat, 31 Jul 2010 10:42:40 +0200 | |
changeset 3693 | 09892cdb8f95 |
parent 3667 | 9359a70df013 |
child 3697 | d5b30d6373fc |
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 |
|
18 |
@synthesize versionLabel; |
|
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]; |
|
27 |
if (settingsViewController.view.superview == nil) |
|
28 |
settingsViewController = nil; |
|
29 |
if (gameConfigViewController.view.superview == nil) |
|
30 |
gameConfigViewController = nil; |
|
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]; |
|
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) |
|
55 |
name: @"dismissModalView" |
|
56 |
object:nil]; |
|
57 |
||
58 |
// initialize some files the first time we load the game |
|
59 |
if (!([[NSFileManager defaultManager] fileExistsAtPath:SETTINGS_FILE()])) |
|
60 |
[NSThread detachNewThreadSelector:@selector(checkFirstRun) toTarget:self withObject:nil]; |
|
61 |
||
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()); |
3547 | 70 |
|
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]; |
|
78 |
||
79 |
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] |
|
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]; |
|
85 |
||
86 |
// create default files (teams/weapons/scheme) |
|
87 |
createTeamNamed(@"Pirates"); |
|
88 |
createTeamNamed(@"Ninjas"); |
|
89 |
createWeaponNamed(@"Default"); |
|
90 |
createSchemeNamed(@"Default"); |
|
91 |
||
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]; |
|
102 |
[saveDict release]; |
|
103 |
||
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: |
|
121 |
gameConfigViewController = [[GameConfigViewController alloc] initWithNibName:@"GameConfigViewController" bundle:nil]; |
|
122 |
||
123 |
[self presentModalViewController:gameConfigViewController animated:YES]; |
|
124 |
break; |
|
125 |
case 2: |
|
126 |
if (nil == settingsViewController) { |
|
127 |
settingsViewController = [[SplitViewRootController alloc] initWithNibName:nil bundle:nil]; |
|
128 |
settingsViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; |
|
129 |
} |
|
130 |
||
131 |
[self presentModalViewController:settingsViewController animated:YES]; |
|
132 |
break; |
|
133 |
case 3: |
|
134 |
debugStr = [[NSString alloc] initWithContentsOfFile:DEBUG_FILE()]; |
|
135 |
UITextView *scroll = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.height, self.view.frame.size.width)]; |
|
136 |
scroll.text = debugStr; |
|
137 |
[debugStr release]; |
|
138 |
scroll.editable = NO; |
|
139 |
||
140 |
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; |
|
141 |
[btn addTarget:scroll action:@selector(removeFromSuperview) forControlEvents:UIControlEventTouchUpInside]; |
|
142 |
btn.backgroundColor = [UIColor blackColor]; |
|
143 |
btn.frame = CGRectMake(self.view.frame.size.height-70, 0, 70, 70); |
|
144 |
[scroll addSubview:btn]; |
|
145 |
[self.view addSubview:scroll]; |
|
146 |
[scroll release]; |
|
147 |
break; |
|
148 |
default: |
|
149 |
alert = [[UIAlertView alloc] initWithTitle:@"Not Yet Implemented" |
|
150 |
message:@"Sorry, this feature is not yet implemented" |
|
151 |
delegate:nil |
|
152 |
cancelButtonTitle:@"Well, don't worry" |
|
153 |
otherButtonTitles:nil]; |
|
154 |
[alert show]; |
|
155 |
[alert release]; |
|
156 |
break; |
|
157 |
} |
|
158 |
} |
|
159 |
||
160 |
// allows child controllers to return to the main controller |
|
161 |
-(void) dismissModalViewController { |
|
162 |
[self dismissModalViewControllerAnimated:YES]; |
|
163 |
} |
|
164 |
||
165 |
||
166 |
-(void) viewDidUnload { |
|
167 |
self.versionLabel = nil; |
|
168 |
gameConfigViewController = nil; |
|
169 |
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
|
170 |
MSG_DIDUNLOAD(); |
3547 | 171 |
[super viewDidUnload]; |
172 |
} |
|
173 |
||
174 |
-(void) dealloc { |
|
175 |
[versionLabel release]; |
|
176 |
[settingsViewController release]; |
|
177 |
[gameConfigViewController release]; |
|
178 |
[super dealloc]; |
|
179 |
} |
|
180 |
||
181 |
@end |