3547
|
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 "GameConfigViewController.h"
|
|
13 |
#import "SplitViewRootController.h"
|
|
14 |
#import "CommodityFunctions.h"
|
|
15 |
|
|
16 |
@implementation MainMenuViewController
|
|
17 |
@synthesize versionLabel;
|
|
18 |
|
|
19 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
|
|
20 |
return rotationManager(interfaceOrientation);
|
|
21 |
}
|
|
22 |
|
|
23 |
- (void)didReceiveMemoryWarning {
|
|
24 |
// Releases the view if it doesn't have a superview.
|
|
25 |
[super didReceiveMemoryWarning];
|
|
26 |
if (settingsViewController.view.superview == nil)
|
|
27 |
settingsViewController = nil;
|
|
28 |
if (gameConfigViewController.view.superview == nil)
|
|
29 |
gameConfigViewController = nil;
|
|
30 |
MSG_MEMCLEAN();
|
|
31 |
}
|
|
32 |
|
|
33 |
-(void) viewDidLoad {
|
|
34 |
char *ver;
|
|
35 |
HW_versionInfo(NULL, &ver);
|
|
36 |
NSString *versionNumber = [[NSString alloc] initWithCString:ver];
|
|
37 |
self.versionLabel.text = versionNumber;
|
|
38 |
[versionNumber release];
|
|
39 |
|
|
40 |
// listen to request to remove the modalviewcontroller
|
|
41 |
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
42 |
selector:@selector(dismissModalViewController)
|
|
43 |
name: @"dismissModalView"
|
|
44 |
object:nil];
|
|
45 |
|
|
46 |
// initialize some files the first time we load the game
|
|
47 |
if (!([[NSFileManager defaultManager] fileExistsAtPath:SETTINGS_FILE()]))
|
|
48 |
[NSThread detachNewThreadSelector:@selector(checkFirstRun) toTarget:self withObject:nil];
|
|
49 |
|
|
50 |
[super viewDidLoad];
|
|
51 |
}
|
|
52 |
|
|
53 |
// this is called to verify whether it's the first time the app is launched
|
|
54 |
// if it is it blocks user interaction with an alertView until files are created
|
|
55 |
-(void) checkFirstRun {
|
|
56 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
57 |
NSLog(@"First time run, creating settings files at %@", SETTINGS_FILE());
|
|
58 |
|
|
59 |
// show a popup with an indicator to make the user wait
|
|
60 |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Please wait",@"")
|
|
61 |
message:nil
|
|
62 |
delegate:nil
|
|
63 |
cancelButtonTitle:nil
|
|
64 |
otherButtonTitles:nil];
|
|
65 |
[alert show];
|
|
66 |
|
|
67 |
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]
|
|
68 |
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
|
|
69 |
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);
|
|
70 |
[indicator startAnimating];
|
|
71 |
[alert addSubview:indicator];
|
|
72 |
[indicator release];
|
|
73 |
|
|
74 |
// create default files (teams/weapons/scheme)
|
|
75 |
createTeamNamed(@"Pirates");
|
|
76 |
createTeamNamed(@"Ninjas");
|
|
77 |
createWeaponNamed(@"Default");
|
|
78 |
createSchemeNamed(@"Default");
|
|
79 |
|
|
80 |
// create settings.plist
|
|
81 |
NSMutableDictionary *saveDict = [[NSMutableDictionary alloc] init];
|
|
82 |
|
|
83 |
[saveDict setObject:@"" forKey:@"username"];
|
|
84 |
[saveDict setObject:@"" forKey:@"password"];
|
|
85 |
[saveDict setObject:[NSNumber numberWithBool:YES] forKey:@"music"];
|
|
86 |
[saveDict setObject:[NSNumber numberWithBool:YES] forKey:@"sound"];
|
|
87 |
[saveDict setObject:[NSNumber numberWithBool:NO] forKey:@"alternate"];
|
|
88 |
|
|
89 |
[saveDict writeToFile:SETTINGS_FILE() atomically:YES];
|
|
90 |
[saveDict release];
|
|
91 |
|
|
92 |
// ok let the user take control
|
|
93 |
[alert dismissWithClickedButtonIndex:0 animated:YES];
|
|
94 |
[alert release];
|
|
95 |
|
|
96 |
[pool release];
|
3621
|
97 |
|
|
98 |
// TODO: instead of this useless runtime initialization, check that all ammos remain compatible with engine
|
3547
|
99 |
}
|
|
100 |
|
|
101 |
#pragma mark -
|
|
102 |
-(IBAction) switchViews:(id) sender {
|
|
103 |
UIButton *button = (UIButton *)sender;
|
|
104 |
UIAlertView *alert;
|
|
105 |
NSString *debugStr;
|
|
106 |
|
|
107 |
switch (button.tag) {
|
|
108 |
case 0:
|
|
109 |
gameConfigViewController = [[GameConfigViewController alloc] initWithNibName:@"GameConfigViewController" bundle:nil];
|
|
110 |
|
|
111 |
[self presentModalViewController:gameConfigViewController animated:YES];
|
|
112 |
break;
|
|
113 |
case 2:
|
|
114 |
if (nil == settingsViewController) {
|
|
115 |
settingsViewController = [[SplitViewRootController alloc] initWithNibName:nil bundle:nil];
|
|
116 |
settingsViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
|
|
117 |
}
|
|
118 |
|
|
119 |
[self presentModalViewController:settingsViewController animated:YES];
|
|
120 |
break;
|
|
121 |
case 3:
|
|
122 |
debugStr = [[NSString alloc] initWithContentsOfFile:DEBUG_FILE()];
|
|
123 |
UITextView *scroll = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.height, self.view.frame.size.width)];
|
|
124 |
scroll.text = debugStr;
|
|
125 |
[debugStr release];
|
|
126 |
scroll.editable = NO;
|
|
127 |
|
|
128 |
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
129 |
[btn addTarget:scroll action:@selector(removeFromSuperview) forControlEvents:UIControlEventTouchUpInside];
|
|
130 |
btn.backgroundColor = [UIColor blackColor];
|
|
131 |
btn.frame = CGRectMake(self.view.frame.size.height-70, 0, 70, 70);
|
|
132 |
[scroll addSubview:btn];
|
|
133 |
[self.view addSubview:scroll];
|
|
134 |
[scroll release];
|
|
135 |
break;
|
|
136 |
default:
|
|
137 |
alert = [[UIAlertView alloc] initWithTitle:@"Not Yet Implemented"
|
|
138 |
message:@"Sorry, this feature is not yet implemented"
|
|
139 |
delegate:nil
|
|
140 |
cancelButtonTitle:@"Well, don't worry"
|
|
141 |
otherButtonTitles:nil];
|
|
142 |
[alert show];
|
|
143 |
[alert release];
|
|
144 |
break;
|
|
145 |
}
|
|
146 |
}
|
|
147 |
|
|
148 |
// allows child controllers to return to the main controller
|
|
149 |
-(void) dismissModalViewController {
|
|
150 |
[self dismissModalViewControllerAnimated:YES];
|
|
151 |
}
|
|
152 |
|
|
153 |
|
|
154 |
-(void) viewDidUnload {
|
|
155 |
self.versionLabel = nil;
|
|
156 |
gameConfigViewController = nil;
|
|
157 |
settingsViewController = nil;
|
|
158 |
[super viewDidUnload];
|
|
159 |
MSG_DIDUNLOAD();
|
|
160 |
}
|
|
161 |
|
|
162 |
-(void) dealloc {
|
|
163 |
[versionLabel release];
|
|
164 |
[settingsViewController release];
|
|
165 |
[gameConfigViewController release];
|
|
166 |
[super dealloc];
|
|
167 |
}
|
|
168 |
|
|
169 |
@end
|