author | palewolf |
Sun, 28 Mar 2010 23:41:58 +0000 | |
changeset 3151 | 3f23113d9df4 |
parent 3122 | e005359efc59 |
child 3165 | 3ec07a7d8456 |
permissions | -rw-r--r-- |
3113 | 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 "SplitViewRootController.h" |
|
13 |
||
14 |
// in case we don't want SDL_mixer... |
|
15 |
//#import "SoundEffect.h" |
|
16 |
//SoundEffect *erasingSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Erase" ofType:@"caf"]]; |
|
17 |
//SoundEffect *selectSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Select" ofType:@"caf"]]; |
|
18 |
||
19 |
||
20 |
@implementation MainMenuViewController |
|
3122
e005359efc59
hide the background gl context that remains active (might be worth freeing ithide the background gl context that remains active (might be worth freeing it))
koda
parents:
3113
diff
changeset
|
21 |
@synthesize cover; |
3113 | 22 |
|
23 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
24 |
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); |
|
25 |
} |
|
26 |
||
27 |
- (void)didReceiveMemoryWarning { |
|
28 |
// Releases the view if it doesn't have a superview. |
|
29 |
[super didReceiveMemoryWarning]; |
|
30 |
} |
|
31 |
||
32 |
- (void)dealloc { |
|
33 |
[super dealloc]; |
|
34 |
} |
|
35 |
||
36 |
-(void) viewDidLoad { |
|
37 |
// initialize some files the first time we load the game |
|
38 |
[NSThread detachNewThreadSelector:@selector(checkFirstRun) toTarget:self withObject:nil]; |
|
39 |
// listet to request to remove the modalviewcontroller |
|
40 |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismissModalViewController) name: @"dismissModalView" object:nil]; |
|
41 |
||
42 |
[super viewDidLoad]; |
|
43 |
} |
|
44 |
||
45 |
// this is called to verify whether it's the first time the app is launched |
|
46 |
// if it is it blocks user interaction with an alertView until files are created |
|
47 |
-(void) checkFirstRun { |
|
48 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
|
49 |
||
50 |
NSString *filePath = [[SDLUIKitDelegate sharedAppDelegate] dataFilePath:@"settings.plist"]; |
|
51 |
if (!([[NSFileManager defaultManager] fileExistsAtPath:filePath])) { |
|
52 |
// file not present, means that also other files are absent |
|
53 |
NSLog(@"First time run, creating settings files"); |
|
54 |
||
55 |
// show a popup with an indicator to make the user wait |
|
56 |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"One-time Preferences Configuration",@"") |
|
57 |
message:nil |
|
58 |
delegate:nil |
|
59 |
cancelButtonTitle:nil |
|
60 |
otherButtonTitles:nil]; |
|
61 |
[alert show]; |
|
62 |
[alert release]; |
|
63 |
||
64 |
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; |
|
65 |
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50); |
|
66 |
[indicator startAnimating]; |
|
67 |
[alert addSubview:indicator]; |
|
68 |
[indicator release]; |
|
69 |
||
70 |
// create settings.plist |
|
71 |
NSMutableDictionary *saveDict = [[NSMutableDictionary alloc] init]; |
|
72 |
||
73 |
[saveDict setObject:@"" forKey:@"username"]; |
|
74 |
[saveDict setObject:@"" forKey:@"password"]; |
|
75 |
[saveDict setObject:@"1" forKey:@"music"]; |
|
76 |
[saveDict setObject:@"1" forKey:@"sounds"]; |
|
77 |
[saveDict setObject:@"0" forKey:@"alternate"]; |
|
78 |
||
79 |
[saveDict writeToFile:filePath atomically:YES]; |
|
80 |
[saveDict release]; |
|
81 |
||
82 |
// create other files |
|
83 |
||
84 |
[alert dismissWithClickedButtonIndex:0 animated:YES]; |
|
85 |
} |
|
86 |
[pool release]; |
|
87 |
[NSThread exit]; |
|
88 |
} |
|
89 |
||
90 |
#pragma mark - |
|
91 |
-(void) appear { |
|
92 |
[[SDLUIKitDelegate sharedAppDelegate].uiwindow addSubview:self.view]; |
|
93 |
[self release]; |
|
94 |
||
95 |
[UIView beginAnimations:@"inserting main controller" context:NULL]; |
|
96 |
[UIView setAnimationDuration:1]; |
|
97 |
self.view.alpha = 1; |
|
98 |
[UIView commitAnimations]; |
|
3122
e005359efc59
hide the background gl context that remains active (might be worth freeing ithide the background gl context that remains active (might be worth freeing it))
koda
parents:
3113
diff
changeset
|
99 |
|
e005359efc59
hide the background gl context that remains active (might be worth freeing ithide the background gl context that remains active (might be worth freeing it))
koda
parents:
3113
diff
changeset
|
100 |
// this is a silly way to hide the sdl contex that remained active |
e005359efc59
hide the background gl context that remains active (might be worth freeing ithide the background gl context that remains active (might be worth freeing it))
koda
parents:
3113
diff
changeset
|
101 |
if (nil == cover) { |
e005359efc59
hide the background gl context that remains active (might be worth freeing ithide the background gl context that remains active (might be worth freeing it))
koda
parents:
3113
diff
changeset
|
102 |
cover= [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; |
e005359efc59
hide the background gl context that remains active (might be worth freeing ithide the background gl context that remains active (might be worth freeing it))
koda
parents:
3113
diff
changeset
|
103 |
cover.backgroundColor = [UIColor blackColor]; |
e005359efc59
hide the background gl context that remains active (might be worth freeing ithide the background gl context that remains active (might be worth freeing it))
koda
parents:
3113
diff
changeset
|
104 |
} |
e005359efc59
hide the background gl context that remains active (might be worth freeing ithide the background gl context that remains active (might be worth freeing it))
koda
parents:
3113
diff
changeset
|
105 |
[[SDLUIKitDelegate sharedAppDelegate].uiwindow insertSubview:cover belowSubview:self.view]; |
3113 | 106 |
} |
107 |
||
108 |
-(void) disappear { |
|
3122
e005359efc59
hide the background gl context that remains active (might be worth freeing ithide the background gl context that remains active (might be worth freeing it))
koda
parents:
3113
diff
changeset
|
109 |
if (nil != cover) |
e005359efc59
hide the background gl context that remains active (might be worth freeing ithide the background gl context that remains active (might be worth freeing it))
koda
parents:
3113
diff
changeset
|
110 |
[cover release]; |
e005359efc59
hide the background gl context that remains active (might be worth freeing ithide the background gl context that remains active (might be worth freeing it))
koda
parents:
3113
diff
changeset
|
111 |
|
3113 | 112 |
[UIView beginAnimations:@"removing main controller" context:NULL]; |
113 |
[UIView setAnimationDuration:1]; |
|
114 |
self.view.alpha = 0; |
|
115 |
[UIView commitAnimations]; |
|
116 |
||
117 |
[self retain]; |
|
118 |
[self.view removeFromSuperview]; |
|
119 |
} |
|
120 |
||
121 |
#pragma mark - |
|
122 |
-(IBAction) switchViews:(id) sender { |
|
123 |
UIButton *button = (UIButton *)sender; |
|
124 |
SplitViewRootController *splitViewController; |
|
125 |
UIAlertView *alert; |
|
126 |
||
127 |
switch (button.tag) { |
|
128 |
case 0: |
|
129 |
[[SDLUIKitDelegate sharedAppDelegate] startSDLgame]; |
|
130 |
break; |
|
131 |
case 2: |
|
132 |
// for now this controller is just to simplify code management |
|
133 |
splitViewController = [[SplitViewRootController alloc] init]; |
|
134 |
splitViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; |
|
135 |
[self presentModalViewController:splitViewController animated:YES]; |
|
136 |
break; |
|
137 |
default: |
|
138 |
alert = [[UIAlertView alloc] initWithTitle:@"Not Yet Implemented" |
|
139 |
message:@"Sorry, this feature is not yet implemented" |
|
140 |
delegate:nil |
|
141 |
cancelButtonTitle:@"Well, don't worry" |
|
142 |
otherButtonTitles:nil]; |
|
143 |
[alert show]; |
|
144 |
[alert release]; |
|
145 |
break; |
|
146 |
} |
|
147 |
} |
|
148 |
||
149 |
-(void) dismissModalViewController { |
|
150 |
[self dismissModalViewControllerAnimated:YES]; |
|
151 |
} |
|
152 |
||
153 |
@end |