author | nemo |
Thu, 11 Mar 2010 04:31:50 +0000 | |
changeset 2973 | b51a0f57cd43 |
parent 2805 | 36a8cebb91e8 |
child 3006 | da6023c2745b |
permissions | -rw-r--r-- |
2685 | 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" |
|
2799 | 11 |
#import "PascalImports.h" |
2685 | 12 |
|
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
13 |
// in case we don't want SDL_mixer... |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
14 |
//#import "SoundEffect.h" |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
15 |
//SoundEffect *erasingSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Erase" ofType:@"caf"]]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
16 |
//SoundEffect *selectSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Select" ofType:@"caf"]]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
17 |
|
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
18 |
|
2685 | 19 |
@implementation MainMenuViewController |
20 |
||
2743 | 21 |
@synthesize versionLabel, settingsViewController, mainView; |
2685 | 22 |
|
2740 | 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 |
// Release any cached data, images, etc that aren't in use. |
|
32 |
if (nil == self.settingsViewController.view.superview) { |
|
33 |
self.settingsViewController = nil; |
|
2799 | 34 |
[settingsViewController release]; |
2740 | 35 |
} |
36 |
} |
|
37 |
||
2687
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
2685
diff
changeset
|
38 |
-(void) viewDidLoad { |
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
39 |
[NSThread detachNewThreadSelector:@selector(checkFirstRun) toTarget:self withObject:nil]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
40 |
|
2799 | 41 |
char *ver; |
42 |
HW_versionInfo(NULL, &ver); |
|
43 |
self.versionLabel.text = [[NSString stringWithUTF8String:ver] autorelease]; |
|
2740 | 44 |
[super viewDidLoad]; |
2685 | 45 |
} |
2723 | 46 |
|
2685 | 47 |
- (void)viewDidUnload { |
48 |
// Release any retained subviews of the main view. |
|
49 |
self.versionLabel = nil; |
|
50 |
} |
|
51 |
||
52 |
- (void)dealloc { |
|
53 |
[versionLabel release]; |
|
2740 | 54 |
[settingsViewController release]; |
55 |
[super dealloc]; |
|
2685 | 56 |
} |
57 |
||
2694
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
58 |
// disable the buttons when to prevent launching twice the game |
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
59 |
-(void) viewWillDisappear:(BOOL)animated { |
2743 | 60 |
self.mainView.userInteractionEnabled = NO; |
2694
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
61 |
[super viewWillDisappear:animated]; |
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
62 |
} |
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
63 |
|
2743 | 64 |
-(void) viewDidAppear:(BOOL)animated { |
65 |
self.mainView.userInteractionEnabled = YES; |
|
66 |
[super viewDidAppear:animated]; |
|
2694
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
67 |
} |
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
68 |
|
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
69 |
-(void) checkFirstRun { |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
70 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
71 |
|
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
72 |
NSString *filePath = [[SDLUIKitDelegate sharedAppDelegate] dataFilePath:@"settings.plist"]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
73 |
if (!([[NSFileManager defaultManager] fileExistsAtPath:filePath])) { |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
74 |
// file not present, means that also other files are absent |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
75 |
NSLog(@"First time run, creating settings files"); |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
76 |
|
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
77 |
// show a popup with an indicator to make the user wait |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
78 |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"One-time Preferences Configuration",@"") |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
79 |
message:nil |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
80 |
delegate:nil |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
81 |
cancelButtonTitle:nil |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
82 |
otherButtonTitles:nil]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
83 |
[alert show]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
84 |
|
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
85 |
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
86 |
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
87 |
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50); |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
88 |
[indicator startAnimating]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
89 |
[alert addSubview:indicator]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
90 |
[indicator release]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
91 |
|
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
92 |
// create settings.plist |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
93 |
NSMutableDictionary *saveDict = [[NSMutableDictionary alloc] init]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
94 |
|
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
95 |
[saveDict setObject:@"" forKey:@"username"]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
96 |
[saveDict setObject:@"" forKey:@"password"]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
97 |
[saveDict setObject:@"1" forKey:@"music"]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
98 |
[saveDict setObject:@"1" forKey:@"sounds"]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
99 |
[saveDict setObject:@"0" forKey:@"alternate"]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
100 |
|
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
101 |
[saveDict writeToFile:filePath atomically:YES]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
102 |
[saveDict release]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
103 |
|
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
104 |
// create other files |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
105 |
|
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
106 |
// memory cleanup |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
107 |
[alert dismissWithClickedButtonIndex:0 animated:YES]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
108 |
[alert release]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
109 |
} |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
110 |
[pool release]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
111 |
[NSThread exit]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
112 |
} |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
113 |
|
2740 | 114 |
#pragma mark - |
115 |
#pragma mark Action buttons |
|
2685 | 116 |
-(IBAction) startPlaying { |
117 |
[[SDLUIKitDelegate sharedAppDelegate] startSDLgame]; |
|
118 |
} |
|
2687
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
2685
diff
changeset
|
119 |
|
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
2685
diff
changeset
|
120 |
-(IBAction) notYetImplemented { |
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
2685
diff
changeset
|
121 |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Not Yet Implemented" |
2740 | 122 |
message:@"Sorry, this feature is not yet implemented" |
123 |
delegate:nil |
|
124 |
cancelButtonTitle:@"Well, don't worry" |
|
125 |
otherButtonTitles:nil]; |
|
2687
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
2685
diff
changeset
|
126 |
[alert show]; |
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
2685
diff
changeset
|
127 |
[alert release]; |
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
2685
diff
changeset
|
128 |
} |
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
2685
diff
changeset
|
129 |
|
2740 | 130 |
-(IBAction) switchViews:(id)sender { |
131 |
||
132 |
// view not displayed or not created |
|
133 |
if (nil == self.settingsViewController.view.superview) { |
|
134 |
// view not created |
|
135 |
if (nil == self.settingsViewController) { |
|
136 |
SettingsViewController *controller = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" |
|
137 |
bundle:nil]; |
|
138 |
self.settingsViewController = controller; |
|
139 |
[controller release]; |
|
140 |
} |
|
2805 | 141 |
self.settingsViewController.view.frame = CGRectMake(0, -257, 480, 278); |
2799 | 142 |
self.settingsViewController.parentView = self.mainView; |
2740 | 143 |
|
2805 | 144 |
[UIView beginAnimations:@"Settings SwitchView" context:NULL]; |
2799 | 145 |
[UIView setAnimationDuration:1]; |
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
146 |
|
2805 | 147 |
self.settingsViewController.view.frame = CGRectMake(0, 21, 480, 278); |
148 |
self.mainView.frame = CGRectMake(0, 299, 480, 278); |
|
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
149 |
[UIView commitAnimations]; |
2740 | 150 |
|
2805 | 151 |
[self.view insertSubview:settingsViewController.view atIndex:0]; |
2740 | 152 |
} |
153 |
||
154 |
} |
|
155 |
||
2685 | 156 |
@end |