author | smxx |
Fri, 16 Apr 2010 14:37:28 +0000 | |
changeset 3346 | 967fd96f7373 |
parent 3335 | 2520ee7a5484 |
child 3356 | 3ae3fccb439e |
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 { |
3335 | 19 |
return rotationManager(interfaceOrientation); |
2740 | 20 |
} |
21 |
||
22 |
- (void)didReceiveMemoryWarning { |
|
23 |
// Releases the view if it doesn't have a superview. |
|
24 |
[super didReceiveMemoryWarning]; |
|
3305 | 25 |
} |
26 |
||
27 |
- (void)dealloc { |
|
28 |
[versionLabel release]; |
|
29 |
[cover release]; |
|
30 |
[super dealloc]; |
|
31 |
} |
|
32 |
||
33 |
-(void) viewDidUnload { |
|
34 |
self.cover = nil; |
|
3335 | 35 |
self.versionLabel = nil; |
3305 | 36 |
[super viewDidUnload]; |
2740 | 37 |
} |
38 |
||
2687
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
2685
diff
changeset
|
39 |
-(void) viewDidLoad { |
3245
252be02536ab
fix an error in passing strings between ObjC and Pascal
koda
parents:
3199
diff
changeset
|
40 |
char *ver; |
252be02536ab
fix an error in passing strings between ObjC and Pascal
koda
parents:
3199
diff
changeset
|
41 |
HW_versionInfo(NULL, &ver); |
3199 | 42 |
NSString *versionNumber = [[NSString alloc] initWithCString:ver]; |
3245
252be02536ab
fix an error in passing strings between ObjC and Pascal
koda
parents:
3199
diff
changeset
|
43 |
self.versionLabel.text = versionNumber; |
3199 | 44 |
[versionNumber release]; |
2723 | 45 |
|
3305 | 46 |
// listen to request to remove the modalviewcontroller |
47 |
[[NSNotificationCenter defaultCenter] addObserver:self |
|
48 |
selector:@selector(dismissModalViewController) |
|
49 |
name: @"dismissModalView" |
|
50 |
object:nil]; |
|
3321 | 51 |
|
52 |
// initialize some files the first time we load the game |
|
3335 | 53 |
if (!([[NSFileManager defaultManager] fileExistsAtPath:SETTINGS_FILE()])) |
3321 | 54 |
[NSThread detachNewThreadSelector:@selector(checkFirstRun) toTarget:self withObject:nil]; |
55 |
||
3305 | 56 |
[super viewDidLoad]; |
2685 | 57 |
} |
58 |
||
3305 | 59 |
// this is called to verify whether it's the first time the app is launched |
60 |
// 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
|
61 |
-(void) checkFirstRun { |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
62 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
3335 | 63 |
NSLog(@"First time run, creating settings files at %@", SETTINGS_FILE()); |
3321 | 64 |
|
65 |
// show a popup with an indicator to make the user wait |
|
66 |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Please wait",@"") |
|
67 |
message:nil |
|
68 |
delegate:nil |
|
69 |
cancelButtonTitle:nil |
|
70 |
otherButtonTitles:nil]; |
|
71 |
[alert show]; |
|
72 |
||
73 |
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] |
|
74 |
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; |
|
75 |
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50); |
|
76 |
[indicator startAnimating]; |
|
77 |
[alert addSubview:indicator]; |
|
78 |
[indicator release]; |
|
79 |
[alert release]; |
|
80 |
||
3325 | 81 |
// create a team |
82 |
createTeamNamed(@"Default Team"); |
|
3321 | 83 |
|
84 |
// create settings.plist |
|
85 |
NSMutableDictionary *saveDict = [[NSMutableDictionary alloc] init]; |
|
3332 | 86 |
|
3321 | 87 |
[saveDict setObject:@"" forKey:@"username"]; |
88 |
[saveDict setObject:@"" forKey:@"password"]; |
|
3332 | 89 |
[saveDict setObject:[NSNumber numberWithBool:YES] forKey:@"music"]; |
90 |
[saveDict setObject:[NSNumber numberWithBool:YES] forKey:@"sound"]; |
|
91 |
[saveDict setObject:[NSNumber numberWithBool:NO] forKey:@"alternate"]; |
|
3305 | 92 |
|
3335 | 93 |
[saveDict writeToFile:SETTINGS_FILE() atomically:YES]; |
3325 | 94 |
[saveDict release]; |
3321 | 95 |
|
96 |
// ok let the user take control |
|
97 |
[alert dismissWithClickedButtonIndex:0 animated:YES]; |
|
98 |
||
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
99 |
[pool release]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
100 |
[NSThread exit]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
101 |
} |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
102 |
|
3305 | 103 |
#pragma mark - |
3027 | 104 |
-(void) appear { |
3029
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
105 |
[[SDLUIKitDelegate sharedAppDelegate].uiwindow addSubview:self.view]; |
3063 | 106 |
[self release]; |
107 |
||
3027 | 108 |
[UIView beginAnimations:@"inserting main controller" context:NULL]; |
109 |
[UIView setAnimationDuration:1]; |
|
110 |
self.view.alpha = 1; |
|
111 |
[UIView commitAnimations]; |
|
3305 | 112 |
|
113 |
[NSTimer scheduledTimerWithTimeInterval:0.7 target:self selector:@selector(hideBehind) userInfo:nil repeats:NO]; |
|
3027 | 114 |
} |
115 |
||
116 |
-(void) disappear { |
|
3305 | 117 |
if (nil != cover) |
118 |
[cover release]; |
|
119 |
||
3027 | 120 |
[UIView beginAnimations:@"removing main controller" context:NULL]; |
121 |
[UIView setAnimationDuration:1]; |
|
122 |
self.view.alpha = 0; |
|
123 |
[UIView commitAnimations]; |
|
3063 | 124 |
[self retain]; |
3317
198ec44b6d92
minor tweaks, icon for ipad, merged overlayviewcontroller, pop viewcontroller when selected a hat
koda
parents:
3315
diff
changeset
|
125 |
//[self.view removeFromSuperview]; |
3027 | 126 |
} |
127 |
||
3305 | 128 |
// this is a silly way to hide the sdl contex that remained active |
129 |
-(void) hideBehind { |
|
130 |
if (nil == cover) { |
|
131 |
cover= [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; |
|
132 |
cover.backgroundColor = [UIColor blackColor]; |
|
133 |
} |
|
134 |
[[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
|
135 |
} |
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
2685
diff
changeset
|
136 |
|
3305 | 137 |
#pragma mark - |
138 |
-(IBAction) switchViews:(id) sender { |
|
139 |
UIButton *button = (UIButton *)sender; |
|
140 |
SplitViewRootController *splitViewController; |
|
141 |
UIAlertView *alert; |
|
142 |
||
143 |
switch (button.tag) { |
|
144 |
case 0: |
|
145 |
[[SDLUIKitDelegate sharedAppDelegate] startSDLgame]; |
|
146 |
break; |
|
147 |
case 2: |
|
148 |
// for now this controller is just to simplify code management |
|
149 |
splitViewController = [[SplitViewRootController alloc] initWithNibName:nil bundle:nil]; |
|
150 |
splitViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; |
|
151 |
[self presentModalViewController:splitViewController animated:YES]; |
|
152 |
break; |
|
153 |
default: |
|
154 |
alert = [[UIAlertView alloc] initWithTitle:@"Not Yet Implemented" |
|
155 |
message:@"Sorry, this feature is not yet implemented" |
|
156 |
delegate:nil |
|
157 |
cancelButtonTitle:@"Well, don't worry" |
|
158 |
otherButtonTitles:nil]; |
|
159 |
[alert show]; |
|
160 |
[alert release]; |
|
161 |
break; |
|
162 |
} |
|
163 |
} |
|
2740 | 164 |
|
3305 | 165 |
-(void) dismissModalViewController { |
166 |
[self dismissModalViewControllerAnimated:YES]; |
|
2740 | 167 |
} |
168 |
||
2685 | 169 |
@end |