author | koda |
Fri, 02 Apr 2010 12:38:36 +0000 | |
changeset 3250 | d5cd1a617123 |
parent 3165 | 3ec07a7d8456 |
child 3251 | 221c163ad5d9 |
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 { |
|
3250
d5cd1a617123
intial support for team configuration on the ifrontend
koda
parents:
3165
diff
changeset
|
33 |
[cover release]; |
3113 | 34 |
[super dealloc]; |
35 |
} |
|
36 |
||
3250
d5cd1a617123
intial support for team configuration on the ifrontend
koda
parents:
3165
diff
changeset
|
37 |
-(void) viewDidUnload { |
d5cd1a617123
intial support for team configuration on the ifrontend
koda
parents:
3165
diff
changeset
|
38 |
self.cover = nil; |
d5cd1a617123
intial support for team configuration on the ifrontend
koda
parents:
3165
diff
changeset
|
39 |
[super viewDidUnload]; |
d5cd1a617123
intial support for team configuration on the ifrontend
koda
parents:
3165
diff
changeset
|
40 |
} |
d5cd1a617123
intial support for team configuration on the ifrontend
koda
parents:
3165
diff
changeset
|
41 |
|
3113 | 42 |
-(void) viewDidLoad { |
43 |
// initialize some files the first time we load the game |
|
44 |
[NSThread detachNewThreadSelector:@selector(checkFirstRun) toTarget:self withObject:nil]; |
|
3250
d5cd1a617123
intial support for team configuration on the ifrontend
koda
parents:
3165
diff
changeset
|
45 |
// listen to request to remove the modalviewcontroller |
3113 | 46 |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismissModalViewController) name: @"dismissModalView" object:nil]; |
47 |
||
48 |
[super viewDidLoad]; |
|
49 |
} |
|
50 |
||
51 |
// this is called to verify whether it's the first time the app is launched |
|
52 |
// if it is it blocks user interaction with an alertView until files are created |
|
53 |
-(void) checkFirstRun { |
|
54 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
|
55 |
||
56 |
NSString *filePath = [[SDLUIKitDelegate sharedAppDelegate] dataFilePath:@"settings.plist"]; |
|
57 |
if (!([[NSFileManager defaultManager] fileExistsAtPath:filePath])) { |
|
58 |
// file not present, means that also other files are absent |
|
59 |
NSLog(@"First time run, creating settings files"); |
|
60 |
||
61 |
// show a popup with an indicator to make the user wait |
|
62 |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"One-time Preferences Configuration",@"") |
|
63 |
message:nil |
|
64 |
delegate:nil |
|
65 |
cancelButtonTitle:nil |
|
66 |
otherButtonTitles:nil]; |
|
67 |
[alert show]; |
|
68 |
[alert release]; |
|
69 |
||
70 |
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; |
|
71 |
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50); |
|
72 |
[indicator startAnimating]; |
|
73 |
[alert addSubview:indicator]; |
|
74 |
[indicator release]; |
|
75 |
||
76 |
// create settings.plist |
|
77 |
NSMutableDictionary *saveDict = [[NSMutableDictionary alloc] init]; |
|
78 |
||
79 |
[saveDict setObject:@"" forKey:@"username"]; |
|
80 |
[saveDict setObject:@"" forKey:@"password"]; |
|
81 |
[saveDict setObject:@"1" forKey:@"music"]; |
|
82 |
[saveDict setObject:@"1" forKey:@"sounds"]; |
|
83 |
[saveDict setObject:@"0" forKey:@"alternate"]; |
|
84 |
||
85 |
[saveDict writeToFile:filePath atomically:YES]; |
|
86 |
[saveDict release]; |
|
87 |
||
88 |
// create other files |
|
89 |
||
90 |
[alert dismissWithClickedButtonIndex:0 animated:YES]; |
|
91 |
} |
|
92 |
[pool release]; |
|
93 |
[NSThread exit]; |
|
94 |
} |
|
95 |
||
96 |
#pragma mark - |
|
97 |
-(void) appear { |
|
98 |
[[SDLUIKitDelegate sharedAppDelegate].uiwindow addSubview:self.view]; |
|
99 |
[self release]; |
|
100 |
||
101 |
[UIView beginAnimations:@"inserting main controller" context:NULL]; |
|
102 |
[UIView setAnimationDuration:1]; |
|
103 |
self.view.alpha = 1; |
|
104 |
[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
|
105 |
|
3165
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3122
diff
changeset
|
106 |
[NSTimer scheduledTimerWithTimeInterval:0.7 target:self selector:@selector(hideBehind) userInfo:nil repeats:NO]; |
3113 | 107 |
} |
108 |
||
109 |
-(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
|
110 |
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
|
111 |
[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
|
112 |
|
3113 | 113 |
[UIView beginAnimations:@"removing main controller" context:NULL]; |
114 |
[UIView setAnimationDuration:1]; |
|
115 |
self.view.alpha = 0; |
|
116 |
[UIView commitAnimations]; |
|
117 |
||
118 |
[self retain]; |
|
119 |
[self.view removeFromSuperview]; |
|
120 |
} |
|
121 |
||
3165
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3122
diff
changeset
|
122 |
// 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
|
123 |
-(void) hideBehind { |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3122
diff
changeset
|
124 |
if (nil == cover) { |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3122
diff
changeset
|
125 |
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
|
126 |
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
|
127 |
} |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3122
diff
changeset
|
128 |
[[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
|
129 |
} |
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3122
diff
changeset
|
130 |
|
3113 | 131 |
#pragma mark - |
132 |
-(IBAction) switchViews:(id) sender { |
|
133 |
UIButton *button = (UIButton *)sender; |
|
134 |
SplitViewRootController *splitViewController; |
|
135 |
UIAlertView *alert; |
|
136 |
||
137 |
switch (button.tag) { |
|
138 |
case 0: |
|
139 |
[[SDLUIKitDelegate sharedAppDelegate] startSDLgame]; |
|
140 |
break; |
|
141 |
case 2: |
|
142 |
// for now this controller is just to simplify code management |
|
143 |
splitViewController = [[SplitViewRootController alloc] init]; |
|
144 |
splitViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; |
|
145 |
[self presentModalViewController:splitViewController animated:YES]; |
|
146 |
break; |
|
147 |
default: |
|
148 |
alert = [[UIAlertView alloc] initWithTitle:@"Not Yet Implemented" |
|
149 |
message:@"Sorry, this feature is not yet implemented" |
|
150 |
delegate:nil |
|
151 |
cancelButtonTitle:@"Well, don't worry" |
|
152 |
otherButtonTitles:nil]; |
|
153 |
[alert show]; |
|
154 |
[alert release]; |
|
155 |
break; |
|
156 |
} |
|
157 |
} |
|
158 |
||
159 |
-(void) dismissModalViewController { |
|
160 |
[self dismissModalViewControllerAnimated:YES]; |
|
161 |
} |
|
162 |
||
163 |
@end |