author | koda |
Sat, 02 Oct 2010 04:23:32 +0200 | |
changeset 3922 | 44804043b691 |
parent 3903 | db01c37494af |
child 3923 | 694e6f6e0e30 |
permissions | -rw-r--r-- |
3829 | 1 |
/* |
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
|
3 |
* Copyright (c) 2009-2010 Vittorio Giovara <vittorio.giovara@gmail.com> |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
17 |
* |
|
18 |
* File created on 08/01/2010. |
|
19 |
*/ |
|
20 |
||
3547 | 21 |
|
22 |
#import "MainMenuViewController.h" |
|
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3701
diff
changeset
|
23 |
#import "CommodityFunctions.h" |
3547 | 24 |
#import "SDL_uikitappdelegate.h" |
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3701
diff
changeset
|
25 |
#import "SDL_mixer.h" |
3547 | 26 |
#import "PascalImports.h" |
27 |
#import "GameConfigViewController.h" |
|
28 |
#import "SplitViewRootController.h" |
|
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3701
diff
changeset
|
29 |
#import "AboutViewController.h" |
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
3891
diff
changeset
|
30 |
#import "SavedGamesViewController.h" |
3547 | 31 |
|
32 |
@implementation MainMenuViewController |
|
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
3891
diff
changeset
|
33 |
@synthesize versionLabel, gameConfigViewController, settingsViewController, aboutViewController, savedGamesViewController; |
3547 | 34 |
|
35 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
36 |
return rotationManager(interfaceOrientation); |
|
37 |
} |
|
38 |
||
39 |
- (void)didReceiveMemoryWarning { |
|
40 |
// Releases the view if it doesn't have a superview. |
|
41 |
[super didReceiveMemoryWarning]; |
|
3701 | 42 |
if (self.settingsViewController.view.superview == nil) |
43 |
self.settingsViewController = nil; |
|
44 |
if (self.gameConfigViewController.view.superview == nil) |
|
45 |
self.gameConfigViewController = nil; |
|
3547 | 46 |
MSG_MEMCLEAN(); |
47 |
} |
|
48 |
||
3667 | 49 |
// using a different thread for audio 'cos it's slow |
50 |
-(void) initAudioThread { |
|
51 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
|
3737
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
52 |
// do somthing in the future |
3667 | 53 |
[pool release]; |
54 |
} |
|
55 |
||
3884 | 56 |
// check if some configuration files are already set; if they are present it means that the current copy must be updated |
57 |
-(void) createNecessaryFiles { |
|
3752
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
58 |
BOOL doCreateFiles = NO; |
3737
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
59 |
NSString *resDir = [[NSBundle mainBundle] resourcePath]; |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
60 |
|
3752
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
61 |
NSString *versionFileToCheck = [NSString stringWithFormat:@"%@/version.txt",DOCUMENTS_FOLDER()]; |
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
62 |
if ([[NSFileManager defaultManager] fileExistsAtPath:versionFileToCheck]) { |
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
63 |
NSString *currentVersion = [NSString stringWithContentsOfFile:versionFileToCheck encoding:NSUTF8StringEncoding error:nil]; |
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
64 |
NSString *newVersion = [NSString stringWithContentsOfFile:[NSString stringWithFormat:@"%@/Settings/version.txt",resDir] encoding:NSUTF8StringEncoding error:nil]; |
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
65 |
if ([currentVersion intValue] < [newVersion intValue]) { |
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
66 |
doCreateFiles = YES; |
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
67 |
[newVersion writeToFile:versionFileToCheck atomically:YES encoding:NSUTF8StringEncoding error:nil]; |
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
68 |
} |
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
69 |
} else { |
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
70 |
doCreateFiles = YES; |
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
71 |
[[NSFileManager defaultManager] copyItemAtPath:[NSString stringWithFormat:@"%@/Settings/version.txt",resDir] toPath:versionFileToCheck error:nil]; |
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
72 |
} |
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
73 |
|
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
74 |
|
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
75 |
if (doCreateFiles == YES) { |
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
76 |
NSError *err = nil; |
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
77 |
NSString *directoryToCheck, *fileToCheck, *fileToUpdate; |
3738 | 78 |
DLog(@"Creating necessary files"); |
79 |
||
3891 | 80 |
// create an empty saves directory by deleting the previous one (saves are incompatible between releases) |
81 |
if ([[NSFileManager defaultManager] fileExistsAtPath:SAVES_DIRECTORY()]) |
|
82 |
[[NSFileManager defaultManager] removeItemAtPath:SAVES_DIRECTORY() error:NULL]; |
|
83 |
[[NSFileManager defaultManager] createDirectoryAtPath:SAVES_DIRECTORY() withIntermediateDirectories:NO attributes:nil error:NULL]; |
|
84 |
||
3737
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
85 |
// if the settings file is already present, we merge current preferences with the update |
3752
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
86 |
directoryToCheck = [NSString stringWithFormat:@"%@/Settings/settings.plist",resDir]; |
3737
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
87 |
if ([[NSFileManager defaultManager] fileExistsAtPath:SETTINGS_FILE()]) { |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
88 |
NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:SETTINGS_FILE()]; |
3752
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
89 |
NSMutableDictionary *update = [[NSMutableDictionary alloc] initWithContentsOfFile:directoryToCheck]; |
3737
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
90 |
[update addEntriesFromDictionary:settings]; |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
91 |
[settings release]; |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
92 |
[update writeToFile:SETTINGS_FILE() atomically:YES]; |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
93 |
[update release]; |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
94 |
} else |
3752
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
95 |
[[NSFileManager defaultManager] copyItemAtPath:directoryToCheck toPath:SETTINGS_FILE() error:&err]; |
3737
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
96 |
|
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
97 |
// if the teams are already present we merge the old teams if they still exist |
3752
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
98 |
directoryToCheck = [NSString stringWithFormat:@"%@/Settings/Teams",resDir]; |
3737
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
99 |
if ([[NSFileManager defaultManager] fileExistsAtPath:TEAMS_DIRECTORY()]) { |
3752
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
100 |
for (NSString *str in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:directoryToCheck error:nil]) { |
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
101 |
fileToCheck = [NSString stringWithFormat:@"%@/%@",TEAMS_DIRECTORY(),str]; |
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
102 |
fileToUpdate = [NSString stringWithFormat:@"%@/Settings/Teams/%@",resDir,str]; |
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
103 |
if ([[NSFileManager defaultManager] fileExistsAtPath:fileToCheck]) { |
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
104 |
NSDictionary *team = [[NSDictionary alloc] initWithContentsOfFile:fileToCheck]; |
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
105 |
NSMutableDictionary *update = [[NSMutableDictionary alloc] initWithContentsOfFile:fileToUpdate]; |
3737
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
106 |
[update addEntriesFromDictionary:team]; |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
107 |
[team release]; |
3752
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
108 |
[update writeToFile:fileToCheck atomically:YES]; |
3737
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
109 |
[update release]; |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
110 |
} |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
111 |
} |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
112 |
} else |
3752
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
113 |
[[NSFileManager defaultManager] copyItemAtPath:directoryToCheck toPath:TEAMS_DIRECTORY() error:&err]; |
3697 | 114 |
|
3737
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
115 |
// the same holds for schemes (but they're arrays) |
3752
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
116 |
directoryToCheck = [NSString stringWithFormat:@"%@/Settings/Schemes",resDir]; |
3737
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
117 |
if ([[NSFileManager defaultManager] fileExistsAtPath:SCHEMES_DIRECTORY()]) { |
3752
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
118 |
for (NSString *str in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:directoryToCheck error:nil]) { |
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
119 |
fileToCheck = [NSString stringWithFormat:@"%@/%@",SCHEMES_DIRECTORY(),str]; |
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
120 |
fileToUpdate = [NSString stringWithFormat:@"%@/Settings/Schemes/%@",resDir,str]; |
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
121 |
if ([[NSFileManager defaultManager] fileExistsAtPath:fileToCheck]) { |
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
122 |
NSArray *scheme = [[NSArray alloc] initWithContentsOfFile:fileToCheck]; |
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
123 |
NSArray *update = [[NSArray alloc] initWithContentsOfFile:fileToUpdate]; |
3737
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
124 |
if ([update count] > [scheme count]) |
3752
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
125 |
[update writeToFile:fileToCheck atomically:YES]; |
3737
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
126 |
[update release]; |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
127 |
[scheme release]; |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
128 |
} |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
129 |
} |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
130 |
} else |
3752
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
131 |
[[NSFileManager defaultManager] copyItemAtPath:directoryToCheck toPath:SCHEMES_DIRECTORY() error:&err]; |
3737
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
132 |
|
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
133 |
// we create weapons the first time only, they are autoupdated each time |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
134 |
if ([[NSFileManager defaultManager] fileExistsAtPath:WEAPONS_DIRECTORY()] == NO) { |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
135 |
[[NSFileManager defaultManager] createDirectoryAtPath:WEAPONS_DIRECTORY() |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
136 |
withIntermediateDirectories:YES |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
137 |
attributes:nil |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
138 |
error:&err]; |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
139 |
createWeaponNamed(@"Default", 0); |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
140 |
createWeaponNamed(@"Crazy", 1); |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
141 |
createWeaponNamed(@"Pro mode", 2); |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
142 |
createWeaponNamed(@"Shoppa", 3); |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
143 |
createWeaponNamed(@"Basketball", 4); |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
144 |
createWeaponNamed(@"Minefield", 5); |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
145 |
} |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
146 |
|
3752
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
147 |
DLog(@"Success"); |
3738 | 148 |
|
3737
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
149 |
if (err != nil) |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
150 |
DLog(@"%@", err); |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
151 |
} |
3884 | 152 |
} |
153 |
||
154 |
/* // ask the user to leave a review for this app |
|
155 |
-(void) reviewCounter { |
|
156 |
CGFloat reviewInt = [[NSUserDefaults standardUserDefaults] integerForKey: @"intValueKey"]; |
|
157 |
||
158 |
if (reviewInt) { |
|
159 |
reviewInt++; |
|
160 |
[[NSUserDefaults standardUserDefaults] setInteger:reviewInt forKey:@"intValueKey"]; |
|
161 |
} else { |
|
162 |
CGFloat start = 1; |
|
163 |
NSUserDefaults *reviewPrefs = [NSUserDefaults standardUserDefaults]; |
|
164 |
[reviewPrefs setInteger:start forKey: @"intValueKey"]; |
|
165 |
[reviewPrefs synchronize]; // writes modifications to disk |
|
166 |
} |
|
167 |
||
168 |
if (1) { |
|
169 |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Mabuhay!" |
|
170 |
message:@"Looks like you Enjoy using this app. Could you spare a moment of your time to review it in the AppStore?" |
|
171 |
delegate:self |
|
172 |
cancelButtonTitle:nil |
|
173 |
otherButtonTitles: @"OK, I'll Review It Now", @"Remind Me Later", @"Don't Remind Me", nil]; |
|
174 |
[alert show]; |
|
175 |
[alert release]; |
|
176 |
||
177 |
reviewInt++; |
|
178 |
||
179 |
[[NSUserDefaults standardUserDefaults] setInteger:reviewInt forKey:@"intValueKey"]; |
|
180 |
} |
|
181 |
} |
|
182 |
||
183 |
#pragma mark - |
|
184 |
#pragma mark alert view delegate |
|
185 |
-(void) alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger) buttonIndex { |
|
186 |
// the user clicked one of the OK/Cancel buttons |
|
187 |
if (buttonIndex == 0) { |
|
188 |
NSString *str = @"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa"; |
|
189 |
str = [NSString stringWithFormat:@"%@/wa/viewContentsUserReviews?", str]; |
|
190 |
str = [NSString stringWithFormat:@"%@type=Vittorio+Giovara&id=", str]; |
|
191 |
||
192 |
// Here is the app id from itunesconnect |
|
193 |
str = [NSString stringWithFormat:@"%@391234866", str]; |
|
194 |
||
195 |
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=391234866&onlyLatestVersion=true&pageNumber=0&sortOrdering=1&type=Purple+Software"]]; |
|
196 |
} else if (buttonIndex == 1) { |
|
197 |
int startAgain = 0; |
|
198 |
[[NSUserDefaults standardUserDefaults] setInteger:startAgain forKey:@"intValueKey"]; |
|
199 |
||
200 |
} else if (buttonIndex == 2) { |
|
201 |
int neverRemind = 4; |
|
202 |
[[NSUserDefaults standardUserDefaults] setInteger:neverRemind forKey:@"intValueKey"]; |
|
203 |
} |
|
204 |
} */ |
|
205 |
||
206 |
#pragma mark - |
|
207 |
-(void) viewDidLoad { |
|
208 |
[NSThread detachNewThreadSelector:@selector(initAudioThread) |
|
209 |
toTarget:self |
|
210 |
withObject:nil]; |
|
211 |
||
212 |
char *ver; |
|
213 |
HW_versionInfo(NULL, &ver); |
|
214 |
NSString *versionNumber = [[NSString alloc] initWithCString:ver]; |
|
215 |
self.versionLabel.text = @"";//versionNumber; |
|
216 |
[versionNumber release]; |
|
217 |
||
218 |
// listen to request to remove the modalviewcontroller |
|
219 |
[[NSNotificationCenter defaultCenter] addObserver:self |
|
220 |
selector:@selector(dismissModalViewController) |
|
221 |
name: @"dismissModalView" |
|
222 |
object:nil]; |
|
223 |
||
224 |
[self createNecessaryFiles]; |
|
3737
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
225 |
|
3547 | 226 |
[super viewDidLoad]; |
227 |
} |
|
228 |
||
229 |
||
230 |
#pragma mark - |
|
231 |
-(IBAction) switchViews:(id) sender { |
|
232 |
UIButton *button = (UIButton *)sender; |
|
233 |
UIAlertView *alert; |
|
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
3891
diff
changeset
|
234 |
NSString *xib = nil; |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
3891
diff
changeset
|
235 |
NSString *debugStr = nil; |
3547 | 236 |
|
3783 | 237 |
playSound(@"clickSound"); |
3547 | 238 |
switch (button.tag) { |
239 |
case 0: |
|
3701 | 240 |
if (nil == self.gameConfigViewController) { |
3737
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
241 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
242 |
xib = nil; |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
243 |
else |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
244 |
xib = @"GameConfigViewController"; |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
245 |
|
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3703
diff
changeset
|
246 |
GameConfigViewController *gcvc = [[GameConfigViewController alloc] initWithNibName:xib bundle:nil]; |
3752
73c2d7d5643b
add the new flag, fix a couple of hicups in creating config files, swap animation between settings and lobby
koda
parents:
3738
diff
changeset
|
247 |
gcvc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; |
3701 | 248 |
self.gameConfigViewController = gcvc; |
249 |
[gcvc release]; |
|
250 |
} |
|
3547 | 251 |
|
3701 | 252 |
[self presentModalViewController:self.gameConfigViewController animated:YES]; |
3547 | 253 |
break; |
254 |
case 2: |
|
3701 | 255 |
if (nil == self.settingsViewController) { |
256 |
SplitViewRootController *svrc = [[SplitViewRootController alloc] initWithNibName:nil bundle:nil]; |
|
3753 | 257 |
svrc.modalTransitionStyle = UIModalTransitionStyleCoverVertical; |
3701 | 258 |
self.settingsViewController = svrc; |
259 |
[svrc release]; |
|
3547 | 260 |
} |
3697 | 261 |
|
3701 | 262 |
[self presentModalViewController:self.settingsViewController animated:YES]; |
3547 | 263 |
break; |
264 |
case 3: |
|
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
3891
diff
changeset
|
265 |
#ifdef DEBUG |
3547 | 266 |
debugStr = [[NSString alloc] initWithContentsOfFile:DEBUG_FILE()]; |
267 |
UITextView *scroll = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.height, self.view.frame.size.width)]; |
|
268 |
scroll.text = debugStr; |
|
269 |
[debugStr release]; |
|
270 |
scroll.editable = NO; |
|
3697 | 271 |
|
3547 | 272 |
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; |
273 |
[btn addTarget:scroll action:@selector(removeFromSuperview) forControlEvents:UIControlEventTouchUpInside]; |
|
274 |
btn.backgroundColor = [UIColor blackColor]; |
|
275 |
btn.frame = CGRectMake(self.view.frame.size.height-70, 0, 70, 70); |
|
276 |
[scroll addSubview:btn]; |
|
277 |
[self.view addSubview:scroll]; |
|
278 |
[scroll release]; |
|
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
3891
diff
changeset
|
279 |
#else |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
3891
diff
changeset
|
280 |
if (nil == self.aboutViewController) { |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
3891
diff
changeset
|
281 |
AboutViewController *about = [[AboutViewController alloc] initWithNibName:@"AboutViewController" bundle:nil]; |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
3891
diff
changeset
|
282 |
about.modalTransitionStyle = UIModalTransitionStyleCoverVertical; |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
3891
diff
changeset
|
283 |
about.modalPresentationStyle = UIModalPresentationFormSheet; |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
3891
diff
changeset
|
284 |
self.aboutViewController = about; |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
3891
diff
changeset
|
285 |
[about release]; |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
3891
diff
changeset
|
286 |
} |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
3891
diff
changeset
|
287 |
|
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
3891
diff
changeset
|
288 |
[self presentModalViewController:self.aboutViewController animated:YES]; |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
3891
diff
changeset
|
289 |
#endif |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
3891
diff
changeset
|
290 |
break; |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
3891
diff
changeset
|
291 |
case 4: |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
3891
diff
changeset
|
292 |
if (nil == self.savedGamesViewController) { |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
3891
diff
changeset
|
293 |
SavedGamesViewController *savedgames = [[SavedGamesViewController alloc] initWithNibName:@"SavedGamesViewController" bundle:nil]; |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
3891
diff
changeset
|
294 |
savedgames.modalTransitionStyle = UIModalTransitionStyleCoverVertical; |
3903 | 295 |
savedgames.modalPresentationStyle = UIModalPresentationPageSheet; |
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
3891
diff
changeset
|
296 |
self.savedGamesViewController = savedgames; |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
3891
diff
changeset
|
297 |
[savedgames release]; |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
3891
diff
changeset
|
298 |
} |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
3891
diff
changeset
|
299 |
|
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
3891
diff
changeset
|
300 |
[self presentModalViewController:self.savedGamesViewController animated:YES]; |
3547 | 301 |
break; |
302 |
default: |
|
303 |
alert = [[UIAlertView alloc] initWithTitle:@"Not Yet Implemented" |
|
304 |
message:@"Sorry, this feature is not yet implemented" |
|
305 |
delegate:nil |
|
306 |
cancelButtonTitle:@"Well, don't worry" |
|
307 |
otherButtonTitles:nil]; |
|
308 |
[alert show]; |
|
309 |
[alert release]; |
|
310 |
break; |
|
311 |
} |
|
312 |
} |
|
313 |
||
3753 | 314 |
// must be kept for compatibility with the settings page |
3547 | 315 |
-(void) dismissModalViewController { |
316 |
[self dismissModalViewControllerAnimated:YES]; |
|
317 |
} |
|
318 |
||
319 |
-(void) viewDidUnload { |
|
3783 | 320 |
[[NSNotificationCenter defaultCenter] removeObserver:self]; |
3547 | 321 |
self.versionLabel = nil; |
3701 | 322 |
self.gameConfigViewController = nil; |
323 |
self.settingsViewController = nil; |
|
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3701
diff
changeset
|
324 |
self.aboutViewController = nil; |
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
3891
diff
changeset
|
325 |
self.savedGamesViewController = nil; |
3662
a44406f4369b
polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents:
3660
diff
changeset
|
326 |
MSG_DIDUNLOAD(); |
3547 | 327 |
[super viewDidUnload]; |
328 |
} |
|
329 |
||
330 |
-(void) dealloc { |
|
331 |
[versionLabel release]; |
|
332 |
[settingsViewController release]; |
|
333 |
[gameConfigViewController release]; |
|
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3701
diff
changeset
|
334 |
[aboutViewController release]; |
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
3891
diff
changeset
|
335 |
[savedGamesViewController release]; |
3547 | 336 |
[super dealloc]; |
337 |
} |
|
338 |
||
339 |
@end |