author | smxx |
Sat, 10 Apr 2010 21:36:40 +0000 | |
changeset 3333 | 560e2766c445 |
parent 3332 | 3c90a923f156 |
child 3335 | 2520ee7a5484 |
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" |
3325 | 13 |
#import "CommodityFunctions.h" |
2803
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 |
||
3325 | 83 |
// create a team |
84 |
createTeamNamed(@"Default Team"); |
|
3321 | 85 |
|
86 |
// create settings.plist |
|
87 |
NSMutableDictionary *saveDict = [[NSMutableDictionary alloc] init]; |
|
3332 | 88 |
|
3321 | 89 |
[saveDict setObject:@"" forKey:@"username"]; |
90 |
[saveDict setObject:@"" forKey:@"password"]; |
|
3332 | 91 |
[saveDict setObject:[NSNumber numberWithBool:YES] forKey:@"music"]; |
92 |
[saveDict setObject:[NSNumber numberWithBool:YES] forKey:@"sound"]; |
|
93 |
[saveDict setObject:[NSNumber numberWithBool:NO] forKey:@"alternate"]; |
|
3305 | 94 |
|
3321 | 95 |
NSString *filePath = [[SDLUIKitDelegate sharedAppDelegate] dataFilePath:@"settings.plist"]; |
96 |
[saveDict writeToFile:filePath atomically:YES]; |
|
3325 | 97 |
[saveDict release]; |
3321 | 98 |
// create other files |
99 |
||
100 |
// ok let the user take control |
|
101 |
[alert dismissWithClickedButtonIndex:0 animated:YES]; |
|
102 |
||
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
103 |
[pool release]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
104 |
[NSThread exit]; |
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 |
|
3305 | 107 |
#pragma mark - |
3027 | 108 |
-(void) appear { |
3029
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
109 |
[[SDLUIKitDelegate sharedAppDelegate].uiwindow addSubview:self.view]; |
3063 | 110 |
[self release]; |
111 |
||
3027 | 112 |
[UIView beginAnimations:@"inserting main controller" context:NULL]; |
113 |
[UIView setAnimationDuration:1]; |
|
114 |
self.view.alpha = 1; |
|
115 |
[UIView commitAnimations]; |
|
3305 | 116 |
|
117 |
[NSTimer scheduledTimerWithTimeInterval:0.7 target:self selector:@selector(hideBehind) userInfo:nil repeats:NO]; |
|
3027 | 118 |
} |
119 |
||
120 |
-(void) disappear { |
|
3305 | 121 |
if (nil != cover) |
122 |
[cover release]; |
|
123 |
||
3027 | 124 |
[UIView beginAnimations:@"removing main controller" context:NULL]; |
125 |
[UIView setAnimationDuration:1]; |
|
126 |
self.view.alpha = 0; |
|
127 |
[UIView commitAnimations]; |
|
3063 | 128 |
[self retain]; |
3317
198ec44b6d92
minor tweaks, icon for ipad, merged overlayviewcontroller, pop viewcontroller when selected a hat
koda
parents:
3315
diff
changeset
|
129 |
//[self.view removeFromSuperview]; |
3027 | 130 |
} |
131 |
||
3305 | 132 |
// this is a silly way to hide the sdl contex that remained active |
133 |
-(void) hideBehind { |
|
134 |
if (nil == cover) { |
|
135 |
cover= [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; |
|
136 |
cover.backgroundColor = [UIColor blackColor]; |
|
137 |
} |
|
138 |
[[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
|
139 |
} |
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
2685
diff
changeset
|
140 |
|
3305 | 141 |
#pragma mark - |
142 |
-(IBAction) switchViews:(id) sender { |
|
143 |
UIButton *button = (UIButton *)sender; |
|
144 |
SplitViewRootController *splitViewController; |
|
145 |
UIAlertView *alert; |
|
146 |
||
147 |
switch (button.tag) { |
|
148 |
case 0: |
|
149 |
[[SDLUIKitDelegate sharedAppDelegate] startSDLgame]; |
|
150 |
break; |
|
151 |
case 2: |
|
152 |
// for now this controller is just to simplify code management |
|
153 |
splitViewController = [[SplitViewRootController alloc] initWithNibName:nil bundle:nil]; |
|
154 |
splitViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; |
|
155 |
[self presentModalViewController:splitViewController animated:YES]; |
|
156 |
break; |
|
157 |
default: |
|
158 |
alert = [[UIAlertView alloc] initWithTitle:@"Not Yet Implemented" |
|
159 |
message:@"Sorry, this feature is not yet implemented" |
|
160 |
delegate:nil |
|
161 |
cancelButtonTitle:@"Well, don't worry" |
|
162 |
otherButtonTitles:nil]; |
|
163 |
[alert show]; |
|
164 |
[alert release]; |
|
165 |
break; |
|
166 |
} |
|
167 |
} |
|
2740 | 168 |
|
3305 | 169 |
-(void) dismissModalViewController { |
170 |
[self dismissModalViewControllerAnimated:YES]; |
|
2740 | 171 |
} |
172 |
||
2685 | 173 |
@end |