author | sheepluva |
Wed, 07 Apr 2010 16:03:21 +0000 | |
changeset 3322 | 80afcb97eb46 |
parent 3321 | 988e39ef3c20 |
child 3325 | 652a8ebdf667 |
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" |
3305 | 12 |
#import "SplitViewRootController.h" |
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
13 |
|
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
14 |
|
2685 | 15 |
@implementation MainMenuViewController |
3305 | 16 |
@synthesize cover, versionLabel; |
2685 | 17 |
|
2740 | 18 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
19 |
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); |
|
20 |
} |
|
21 |
||
22 |
- (void)didReceiveMemoryWarning { |
|
23 |
// Releases the view if it doesn't have a superview. |
|
3305 | 24 |
self.cover = nil; |
25 |
self.versionLabel = nil; |
|
2740 | 26 |
[super didReceiveMemoryWarning]; |
3305 | 27 |
} |
28 |
||
29 |
- (void)dealloc { |
|
30 |
[versionLabel release]; |
|
31 |
[cover release]; |
|
32 |
[super dealloc]; |
|
33 |
} |
|
34 |
||
35 |
-(void) viewDidUnload { |
|
36 |
self.cover = nil; |
|
37 |
[super viewDidUnload]; |
|
2740 | 38 |
} |
39 |
||
2687
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
2685
diff
changeset
|
40 |
-(void) viewDidLoad { |
3245
252be02536ab
fix an error in passing strings between ObjC and Pascal
koda
parents:
3199
diff
changeset
|
41 |
char *ver; |
252be02536ab
fix an error in passing strings between ObjC and Pascal
koda
parents:
3199
diff
changeset
|
42 |
HW_versionInfo(NULL, &ver); |
3199 | 43 |
NSString *versionNumber = [[NSString alloc] initWithCString:ver]; |
3245
252be02536ab
fix an error in passing strings between ObjC and Pascal
koda
parents:
3199
diff
changeset
|
44 |
self.versionLabel.text = versionNumber; |
3199 | 45 |
[versionNumber release]; |
2723 | 46 |
|
3305 | 47 |
// listen to request to remove the modalviewcontroller |
48 |
[[NSNotificationCenter defaultCenter] addObserver:self |
|
49 |
selector:@selector(dismissModalViewController) |
|
50 |
name: @"dismissModalView" |
|
51 |
object:nil]; |
|
3321 | 52 |
|
53 |
// initialize some files the first time we load the game |
|
54 |
NSString *filePath = [[SDLUIKitDelegate sharedAppDelegate] dataFilePath:@"settings.plist"]; |
|
55 |
if (!([[NSFileManager defaultManager] fileExistsAtPath:filePath])) |
|
56 |
[NSThread detachNewThreadSelector:@selector(checkFirstRun) toTarget:self withObject:nil]; |
|
57 |
||
3305 | 58 |
[super viewDidLoad]; |
2685 | 59 |
} |
60 |
||
3305 | 61 |
// this is called to verify whether it's the first time the app is launched |
62 |
// if it is it blocks user interaction with an alertView until files are created |
|
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
63 |
-(void) checkFirstRun { |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
64 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
3321 | 65 |
NSLog(@"First time run, creating settings files"); |
66 |
||
67 |
// show a popup with an indicator to make the user wait |
|
68 |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Please wait",@"") |
|
69 |
message:nil |
|
70 |
delegate:nil |
|
71 |
cancelButtonTitle:nil |
|
72 |
otherButtonTitles:nil]; |
|
73 |
[alert show]; |
|
74 |
||
75 |
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] |
|
76 |
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; |
|
77 |
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50); |
|
78 |
[indicator startAnimating]; |
|
79 |
[alert addSubview:indicator]; |
|
80 |
[indicator release]; |
|
81 |
[alert release]; |
|
82 |
||
83 |
// create Default Team.plist |
|
84 |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); |
|
85 |
NSString *teamsDirectory = [[paths objectAtIndex:0] stringByAppendingString:@"/Teams/"]; |
|
86 |
[[NSFileManager defaultManager] createDirectoryAtPath:teamsDirectory |
|
87 |
withIntermediateDirectories:NO |
|
88 |
attributes:nil |
|
89 |
error:NULL]; |
|
90 |
||
91 |
NSMutableArray *hedgehogs = [[NSMutableArray alloc] init]; |
|
92 |
||
93 |
for (int i = 0; i < 8; i++) { |
|
94 |
NSString *hogName = [[NSString alloc] initWithFormat:@"hedgehog %d",i]; |
|
95 |
NSDictionary *hog = [[NSDictionary alloc] initWithObjectsAndKeys:@"100",@"health",@"0",@"level", |
|
96 |
hogName,@"hogname",@"NoHat",@"hat",nil]; |
|
97 |
[hogName release]; |
|
98 |
[hedgehogs addObject:hog]; |
|
99 |
[hog release]; |
|
100 |
} |
|
101 |
||
102 |
NSDictionary *defaultTeam = [[NSDictionary alloc] initWithObjectsAndKeys:@"4421353",@"color",@"0",@"hash", |
|
103 |
@"Default Team",@"teamname",@"Statue",@"grave",@"Plane",@"fort", |
|
104 |
@"Default",@"voicepack",@"hedgewars",@"flag",hedgehogs,@"hedgehogs",nil]; |
|
105 |
[hedgehogs release]; |
|
106 |
NSString *defaultTeamFile = [teamsDirectory stringByAppendingString:@"Default Team.plist"]; |
|
107 |
[defaultTeam writeToFile:defaultTeamFile atomically:YES]; |
|
108 |
[defaultTeam release]; |
|
109 |
||
110 |
// create settings.plist |
|
111 |
NSMutableDictionary *saveDict = [[NSMutableDictionary alloc] init]; |
|
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
112 |
|
3321 | 113 |
[saveDict setObject:@"" forKey:@"username"]; |
114 |
[saveDict setObject:@"" forKey:@"password"]; |
|
115 |
[saveDict setObject:@"1" forKey:@"music"]; |
|
116 |
[saveDict setObject:@"1" forKey:@"sounds"]; |
|
117 |
[saveDict setObject:@"0" forKey:@"alternate"]; |
|
3305 | 118 |
|
3321 | 119 |
NSString *filePath = [[SDLUIKitDelegate sharedAppDelegate] dataFilePath:@"settings.plist"]; |
120 |
[saveDict writeToFile:filePath atomically:YES]; |
|
121 |
[saveDict release]; |
|
122 |
||
123 |
// create other files |
|
124 |
||
125 |
// ok let the user take control |
|
126 |
[alert dismissWithClickedButtonIndex:0 animated:YES]; |
|
127 |
||
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
128 |
[pool release]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
129 |
[NSThread exit]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
130 |
} |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
131 |
|
3305 | 132 |
#pragma mark - |
3027 | 133 |
-(void) appear { |
3029
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
134 |
[[SDLUIKitDelegate sharedAppDelegate].uiwindow addSubview:self.view]; |
3063 | 135 |
[self release]; |
136 |
||
3027 | 137 |
[UIView beginAnimations:@"inserting main controller" context:NULL]; |
138 |
[UIView setAnimationDuration:1]; |
|
139 |
self.view.alpha = 1; |
|
140 |
[UIView commitAnimations]; |
|
3305 | 141 |
|
142 |
[NSTimer scheduledTimerWithTimeInterval:0.7 target:self selector:@selector(hideBehind) userInfo:nil repeats:NO]; |
|
3027 | 143 |
} |
144 |
||
145 |
-(void) disappear { |
|
3305 | 146 |
if (nil != cover) |
147 |
[cover release]; |
|
148 |
||
3027 | 149 |
[UIView beginAnimations:@"removing main controller" context:NULL]; |
150 |
[UIView setAnimationDuration:1]; |
|
151 |
self.view.alpha = 0; |
|
152 |
[UIView commitAnimations]; |
|
3063 | 153 |
[self retain]; |
3317
198ec44b6d92
minor tweaks, icon for ipad, merged overlayviewcontroller, pop viewcontroller when selected a hat
koda
parents:
3315
diff
changeset
|
154 |
//[self.view removeFromSuperview]; |
3027 | 155 |
} |
156 |
||
3305 | 157 |
// this is a silly way to hide the sdl contex that remained active |
158 |
-(void) hideBehind { |
|
159 |
if (nil == cover) { |
|
160 |
cover= [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; |
|
161 |
cover.backgroundColor = [UIColor blackColor]; |
|
162 |
} |
|
163 |
[[SDLUIKitDelegate sharedAppDelegate].uiwindow insertSubview:cover belowSubview:self.view]; |
|
2687
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
2685
diff
changeset
|
164 |
} |
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
2685
diff
changeset
|
165 |
|
3305 | 166 |
#pragma mark - |
167 |
-(IBAction) switchViews:(id) sender { |
|
168 |
UIButton *button = (UIButton *)sender; |
|
169 |
SplitViewRootController *splitViewController; |
|
170 |
UIAlertView *alert; |
|
171 |
||
172 |
switch (button.tag) { |
|
173 |
case 0: |
|
174 |
[[SDLUIKitDelegate sharedAppDelegate] startSDLgame]; |
|
175 |
break; |
|
176 |
case 2: |
|
177 |
// for now this controller is just to simplify code management |
|
178 |
splitViewController = [[SplitViewRootController alloc] initWithNibName:nil bundle:nil]; |
|
179 |
splitViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; |
|
180 |
[self presentModalViewController:splitViewController animated:YES]; |
|
181 |
break; |
|
182 |
default: |
|
183 |
alert = [[UIAlertView alloc] initWithTitle:@"Not Yet Implemented" |
|
184 |
message:@"Sorry, this feature is not yet implemented" |
|
185 |
delegate:nil |
|
186 |
cancelButtonTitle:@"Well, don't worry" |
|
187 |
otherButtonTitles:nil]; |
|
188 |
[alert show]; |
|
189 |
[alert release]; |
|
190 |
break; |
|
191 |
} |
|
192 |
} |
|
2740 | 193 |
|
3305 | 194 |
-(void) dismissModalViewController { |
195 |
[self dismissModalViewControllerAnimated:YES]; |
|
2740 | 196 |
} |
197 |
||
2685 | 198 |
@end |