author | palewolf |
Tue, 30 Mar 2010 20:34:16 +0000 | |
changeset 3192 | b2e3e83cf3b2 |
parent 3165 | 3ec07a7d8456 |
child 3250 | d5cd1a617123 |
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 |
|
3165
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3122
diff
changeset
|
100 |
[NSTimer scheduledTimerWithTimeInterval:0.7 target:self selector:@selector(hideBehind) userInfo:nil repeats:NO]; |
3113 | 101 |
} |
102 |
||
103 |
-(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
|
104 |
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
|
105 |
[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
|
106 |
|
3113 | 107 |
[UIView beginAnimations:@"removing main controller" context:NULL]; |
108 |
[UIView setAnimationDuration:1]; |
|
109 |
self.view.alpha = 0; |
|
110 |
[UIView commitAnimations]; |
|
111 |
||
112 |
[self retain]; |
|
113 |
[self.view removeFromSuperview]; |
|
114 |
} |
|
115 |
||
3165
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3122
diff
changeset
|
116 |
// this is a silly way to hide the sdl contex that remained active |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3122
diff
changeset
|
117 |
-(void) hideBehind { |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3122
diff
changeset
|
118 |
if (nil == cover) { |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3122
diff
changeset
|
119 |
cover= [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3122
diff
changeset
|
120 |
cover.backgroundColor = [UIColor blackColor]; |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3122
diff
changeset
|
121 |
} |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3122
diff
changeset
|
122 |
[[SDLUIKitDelegate sharedAppDelegate].uiwindow insertSubview:cover belowSubview:self.view]; |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3122
diff
changeset
|
123 |
} |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3122
diff
changeset
|
124 |
|
3113 | 125 |
#pragma mark - |
126 |
-(IBAction) switchViews:(id) sender { |
|
127 |
UIButton *button = (UIButton *)sender; |
|
128 |
SplitViewRootController *splitViewController; |
|
129 |
UIAlertView *alert; |
|
130 |
||
131 |
switch (button.tag) { |
|
132 |
case 0: |
|
133 |
[[SDLUIKitDelegate sharedAppDelegate] startSDLgame]; |
|
134 |
break; |
|
135 |
case 2: |
|
136 |
// for now this controller is just to simplify code management |
|
137 |
splitViewController = [[SplitViewRootController alloc] init]; |
|
138 |
splitViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; |
|
139 |
[self presentModalViewController:splitViewController animated:YES]; |
|
140 |
break; |
|
141 |
default: |
|
142 |
alert = [[UIAlertView alloc] initWithTitle:@"Not Yet Implemented" |
|
143 |
message:@"Sorry, this feature is not yet implemented" |
|
144 |
delegate:nil |
|
145 |
cancelButtonTitle:@"Well, don't worry" |
|
146 |
otherButtonTitles:nil]; |
|
147 |
[alert show]; |
|
148 |
[alert release]; |
|
149 |
break; |
|
150 |
} |
|
151 |
} |
|
152 |
||
153 |
-(void) dismissModalViewController { |
|
154 |
[self dismissModalViewControllerAnimated:YES]; |
|
155 |
} |
|
156 |
||
157 |
@end |