author | koda |
Fri, 04 Nov 2011 00:38:37 +0100 | |
changeset 6276 | 1e2f8da1860a |
parent 6266 | b02a1e92dba2 |
child 6301 | 1259736c0134 |
permissions | -rw-r--r-- |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
1 |
/* |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
3 |
* Copyright (c) 2009-2011 Vittorio Giovara <vittorio.giovara@gmail.com> |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
4 |
* |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
7 |
* the Free Software Foundation; version 2 of the License |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
8 |
* |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
13 |
* |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
17 |
* |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
18 |
* File created on 18/04/2011. |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
19 |
*/ |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
20 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
21 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
22 |
#import "GameInterfaceBridge.h" |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
23 |
#import "EngineProtocolNetwork.h" |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
24 |
#import "OverlayViewController.h" |
5158
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
25 |
#import "StatsPageViewController.h" |
6000
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
5709
diff
changeset
|
26 |
#import "AudioManagerController.h" |
5174
f5294509783e
initial refactoring of ObjcExports and OverlayViewController
koda
parents:
5166
diff
changeset
|
27 |
#import "ObjcExports.h" |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
28 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
29 |
@implementation GameInterfaceBridge |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
30 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
31 |
// main routine for calling the actual game engine |
6266
b02a1e92dba2
convert gameinterfacebridge in simple-to-use class methods
koda
parents:
6265
diff
changeset
|
32 |
+(void) engineLaunchOn:(NSInteger) ipcPort withArgument:(NSString *)path { |
5156 | 33 |
const char *gameArgs[11]; |
6209 | 34 |
CGFloat width, height; |
35 |
CGFloat screenScale = [[UIScreen mainScreen] safeScale]; |
|
6265
a6944f94c19f
aaand remove also ipcport from the class interface as well
koda
parents:
6263
diff
changeset
|
36 |
NSString *ipcString = [[NSString alloc] initWithFormat:@"%d",ipcPort]; |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
37 |
NSString *localeString = [[NSString alloc] initWithFormat:@"%@.txt", [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode]]; |
5206 | 38 |
NSUserDefaults *settings = [NSUserDefaults standardUserDefaults]; |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
39 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
40 |
if (IS_DUALHEAD()) { |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
41 |
CGRect screenBounds = [[[UIScreen screens] objectAtIndex:1] bounds]; |
6209 | 42 |
width = screenBounds.size.width; |
43 |
height = screenBounds.size.height; |
|
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
44 |
} else { |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
45 |
CGRect screenBounds = [[UIScreen mainScreen] bounds]; |
6209 | 46 |
width = screenBounds.size.height; |
47 |
height = screenBounds.size.width; |
|
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
48 |
} |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
49 |
|
6209 | 50 |
NSString *horizontalSize = [[NSString alloc] initWithFormat:@"%d", (int)(width * screenScale)]; |
51 |
NSString *verticalSize = [[NSString alloc] initWithFormat:@"%d", (int)(height * screenScale)]; |
|
5662
99083392cd4f
FREE AT LAST!!! SDL came around a (mostly) sane way for implementing rotation events, so we can scrap all the workaround code that has been added to workaround it!! Also this allows us to use proper (internal) multitasking handling and can simplify optional settings and other yet unexplored features. Yay!
koda
parents:
5370
diff
changeset
|
52 |
NSString *rotation = [[NSString alloc] initWithString:@"0"]; |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
53 |
|
6078
8c0cc07731e5
headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
6020
diff
changeset
|
54 |
NSString *modelId = [HWUtils modelType]; |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
55 |
NSInteger tmpQuality; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
56 |
if ([modelId hasPrefix:@"iPhone1"] || [modelId hasPrefix:@"iPod1,1"] || [modelId hasPrefix:@"iPod2,1"]) // = iPhone and iPhone 3G or iPod Touch or iPod Touch 2G |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
57 |
tmpQuality = 0x00000001 | 0x00000002 | 0x00000008 | 0x00000040; // rqLowRes | rqBlurryLand | rqSimpleRope | rqKillFlakes |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
58 |
else if ([modelId hasPrefix:@"iPhone2"] || [modelId hasPrefix:@"iPod3"]) // = iPhone 3GS or iPod Touch 3G |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
59 |
tmpQuality = 0x00000002 | 0x00000040; // rqBlurryLand | rqKillFlakes |
5709 | 60 |
else if ([modelId hasPrefix:@"iPad1"] || [modelId hasPrefix:@"iPod4"]) // = iPad 1G or iPod Touch 4G |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
61 |
tmpQuality = 0x00000002; // rqBlurryLand |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
62 |
else // = everything else |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
63 |
tmpQuality = 0; // full quality |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
64 |
|
6276
1e2f8da1860a
while formatting the ammomenu code i found out that it's simpler to move than i thought, and fixed a small glitch when animation was disabled
koda
parents:
6266
diff
changeset
|
65 |
// disable ammomenu animation |
1e2f8da1860a
while formatting the ammomenu code i found out that it's simpler to move than i thought, and fixed a small glitch when animation was disabled
koda
parents:
6266
diff
changeset
|
66 |
tmpQuality = tmpQuality | 0x00000080; |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
67 |
// disable tooltips on iPhone |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
68 |
if (IS_IPAD() == NO) |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
69 |
tmpQuality = tmpQuality | 0x00000400; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
70 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
71 |
// prevents using an empty nickname |
5206 | 72 |
NSString *username = [settings objectForKey:@"username"]; |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
73 |
if ([username length] == 0) |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
74 |
username = [NSString stringWithFormat:@"MobileUser-%@",ipcString]; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
75 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
76 |
gameArgs[ 0] = [ipcString UTF8String]; //ipcPort |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
77 |
gameArgs[ 1] = [horizontalSize UTF8String]; //cScreenWidth |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
78 |
gameArgs[ 2] = [verticalSize UTF8String]; //cScreenHeight |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
79 |
gameArgs[ 3] = [[NSString stringWithFormat:@"%d",tmpQuality] UTF8String]; //quality |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
80 |
gameArgs[ 4] = "en.txt";//[localeString UTF8String]; //cLocaleFName |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
81 |
gameArgs[ 5] = [username UTF8String]; //UserNick |
5206 | 82 |
gameArgs[ 6] = [[[settings objectForKey:@"sound"] stringValue] UTF8String]; //isSoundEnabled |
83 |
gameArgs[ 7] = [[[settings objectForKey:@"music"] stringValue] UTF8String]; //isMusicEnabled |
|
84 |
gameArgs[ 8] = [[[settings objectForKey:@"alternate"] stringValue] UTF8String]; //cAltDamage |
|
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
85 |
gameArgs[ 9] = [rotation UTF8String]; //rotateQt |
6263
ec41637ceb64
don't keep track of the savepath and of engineprotocol objects
koda
parents:
6261
diff
changeset
|
86 |
gameArgs[10] = ([HWUtils gameType] == gtSave) ? [path UTF8String] : NULL; //recordFileName |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
87 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
88 |
[verticalSize release]; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
89 |
[horizontalSize release]; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
90 |
[rotation release]; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
91 |
[localeString release]; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
92 |
[ipcString release]; |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
93 |
|
6247
6dfad55fd71c
unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents:
6246
diff
changeset
|
94 |
[HWUtils setGameStatus:gsLoading]; |
5194 | 95 |
|
6265
a6944f94c19f
aaand remove also ipcport from the class interface as well
koda
parents:
6263
diff
changeset
|
96 |
// this is the pascal function that starts the game |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
97 |
Game(gameArgs); |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
98 |
} |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
99 |
|
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
100 |
// prepares the controllers for hosting a game |
6266
b02a1e92dba2
convert gameinterfacebridge in simple-to-use class methods
koda
parents:
6265
diff
changeset
|
101 |
+(void) prepareEngineOn:(NSString *)pathOrNil withOptions:(NSDictionary *)optionsOrNil { |
6265
a6944f94c19f
aaand remove also ipcport from the class interface as well
koda
parents:
6263
diff
changeset
|
102 |
EngineProtocolNetwork *proto = [[EngineProtocolNetwork alloc] init]; |
a6944f94c19f
aaand remove also ipcport from the class interface as well
koda
parents:
6263
diff
changeset
|
103 |
NSInteger ipcPort = [proto spawnThread:pathOrNil withOptions:optionsOrNil]; |
6263
ec41637ceb64
don't keep track of the savepath and of engineprotocol objects
koda
parents:
6261
diff
changeset
|
104 |
|
6261
7050772ae46a
remove the need of saving the calling controller (disabling stats, but they were already broken by a previous commit)
koda
parents:
6259
diff
changeset
|
105 |
CGRect theFrame = [[UIScreen mainScreen] bounds]; |
7050772ae46a
remove the need of saving the calling controller (disabling stats, but they were already broken by a previous commit)
koda
parents:
6259
diff
changeset
|
106 |
UIWindow *thisWindow = [[HedgewarsAppDelegate sharedAppDelegate] uiwindow]; |
5157 | 107 |
// we add a black view hiding the background |
5156 | 108 |
UIView *blackView = [[UIView alloc] initWithFrame:theFrame]; |
6261
7050772ae46a
remove the need of saving the calling controller (disabling stats, but they were already broken by a previous commit)
koda
parents:
6259
diff
changeset
|
109 |
[thisWindow addSubview:blackView]; |
5156 | 110 |
blackView.opaque = YES; |
111 |
blackView.backgroundColor = [UIColor blackColor]; |
|
5157 | 112 |
blackView.alpha = 0; |
6261
7050772ae46a
remove the need of saving the calling controller (disabling stats, but they were already broken by a previous commit)
koda
parents:
6259
diff
changeset
|
113 |
|
5157 | 114 |
// when dual screen we apply a little transition |
115 |
if (IS_DUALHEAD()) { |
|
116 |
[UIView beginAnimations:@"fade out" context:NULL]; |
|
117 |
[UIView setAnimationDuration:1]; |
|
118 |
blackView.alpha = 1; |
|
119 |
[UIView commitAnimations]; |
|
5166
d1eb1560b4d5
and now for something completely different, overlay refactoring!
koda
parents:
5158
diff
changeset
|
120 |
} else |
d1eb1560b4d5
and now for something completely different, overlay refactoring!
koda
parents:
5158
diff
changeset
|
121 |
blackView.alpha = 1; |
5157 | 122 |
|
5220
76a2246f18f0
when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
5207
diff
changeset
|
123 |
// keep track of uncompleted games |
5224
6e8fbbfb0de5
muuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuusic for the ios frontend finally
koda
parents:
5220
diff
changeset
|
124 |
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; |
6263
ec41637ceb64
don't keep track of the savepath and of engineprotocol objects
koda
parents:
6261
diff
changeset
|
125 |
[userDefaults setObject:pathOrNil forKey:@"savedGamePath"]; |
5224
6e8fbbfb0de5
muuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuusic for the ios frontend finally
koda
parents:
5220
diff
changeset
|
126 |
[userDefaults synchronize]; |
6e8fbbfb0de5
muuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuusic for the ios frontend finally
koda
parents:
5220
diff
changeset
|
127 |
|
6000
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
5709
diff
changeset
|
128 |
[AudioManagerController pauseBackgroundMusic]; |
5220
76a2246f18f0
when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
5207
diff
changeset
|
129 |
|
5157 | 130 |
// SYSTEMS ARE GO!! |
6265
a6944f94c19f
aaand remove also ipcport from the class interface as well
koda
parents:
6263
diff
changeset
|
131 |
[self engineLaunchOn:ipcPort withArgument:pathOrNil]; |
5224
6e8fbbfb0de5
muuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuusic for the ios frontend finally
koda
parents:
5220
diff
changeset
|
132 |
|
5220
76a2246f18f0
when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
5207
diff
changeset
|
133 |
// remove completed games notification |
5224
6e8fbbfb0de5
muuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuusic for the ios frontend finally
koda
parents:
5220
diff
changeset
|
134 |
[userDefaults setObject:@"" forKey:@"savedGamePath"]; |
6e8fbbfb0de5
muuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuusic for the ios frontend finally
koda
parents:
5220
diff
changeset
|
135 |
[userDefaults synchronize]; |
5220
76a2246f18f0
when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
5207
diff
changeset
|
136 |
|
5157 | 137 |
// now we can remove the cover with a transition |
6020
c792d4b3e080
this finally fixes the interaction between RestoredGameViewController and StatsPagesViewController
koda
parents:
6018
diff
changeset
|
138 |
blackView.frame = theFrame; |
c792d4b3e080
this finally fixes the interaction between RestoredGameViewController and StatsPagesViewController
koda
parents:
6018
diff
changeset
|
139 |
blackView.alpha = 1; |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
140 |
[UIView beginAnimations:@"fade in" context:NULL]; |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
141 |
[UIView setAnimationDuration:1]; |
5156 | 142 |
blackView.alpha = 0; |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
143 |
[UIView commitAnimations]; |
5156 | 144 |
[blackView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1]; |
145 |
[blackView release]; |
|
146 |
||
5157 | 147 |
// the overlay is not needed any more and can be removed |
6259
02765411a912
move objc overlay creation after sdlwindow has been created
koda
parents:
6247
diff
changeset
|
148 |
[[OverlayViewController mainOverlay] removeOverlay]; |
5158
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
149 |
|
6000
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
5709
diff
changeset
|
150 |
[AudioManagerController playBackgroundMusic]; |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
151 |
} |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
152 |
|
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
153 |
// set up variables for a local game |
6266
b02a1e92dba2
convert gameinterfacebridge in simple-to-use class methods
koda
parents:
6265
diff
changeset
|
154 |
+(void) startLocalGame:(NSDictionary *)withOptions { |
6247
6dfad55fd71c
unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents:
6246
diff
changeset
|
155 |
[HWUtils setGameType:gtLocal]; |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
156 |
|
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
157 |
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init]; |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
158 |
[outputFormatter setDateFormat:@"yyyy-MM-dd '@' HH.mm"]; |
6263
ec41637ceb64
don't keep track of the savepath and of engineprotocol objects
koda
parents:
6261
diff
changeset
|
159 |
NSString *savePath = [[NSString alloc] initWithFormat:@"%@%@.hws",SAVES_DIRECTORY(),[outputFormatter stringFromDate:[NSDate date]]]; |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
160 |
[outputFormatter release]; |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
161 |
|
5158
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
162 |
// in the rare case in which a savefile with the same name exists the older one must be removed (or it gets corrupted) |
6263
ec41637ceb64
don't keep track of the savepath and of engineprotocol objects
koda
parents:
6261
diff
changeset
|
163 |
if ([[NSFileManager defaultManager] fileExistsAtPath:savePath]) |
ec41637ceb64
don't keep track of the savepath and of engineprotocol objects
koda
parents:
6261
diff
changeset
|
164 |
[[NSFileManager defaultManager] removeItemAtPath:savePath error:nil]; |
5158
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
165 |
|
6266
b02a1e92dba2
convert gameinterfacebridge in simple-to-use class methods
koda
parents:
6265
diff
changeset
|
166 |
[GameInterfaceBridge prepareEngineOn:savePath withOptions:withOptions]; |
6263
ec41637ceb64
don't keep track of the savepath and of engineprotocol objects
koda
parents:
6261
diff
changeset
|
167 |
[savePath release]; |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
168 |
} |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
169 |
|
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
170 |
// set up variables for a save game |
6266
b02a1e92dba2
convert gameinterfacebridge in simple-to-use class methods
koda
parents:
6265
diff
changeset
|
171 |
+(void) startSaveGame:(NSString *)atPath { |
6247
6dfad55fd71c
unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents:
6246
diff
changeset
|
172 |
[HWUtils setGameType:gtSave]; |
6266
b02a1e92dba2
convert gameinterfacebridge in simple-to-use class methods
koda
parents:
6265
diff
changeset
|
173 |
[GameInterfaceBridge prepareEngineOn:atPath withOptions:nil]; |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
174 |
} |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
175 |
|
6266
b02a1e92dba2
convert gameinterfacebridge in simple-to-use class methods
koda
parents:
6265
diff
changeset
|
176 |
+(void) startMissionGame:(NSString *)withScript { |
6247
6dfad55fd71c
unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents:
6246
diff
changeset
|
177 |
[HWUtils setGameType:gtMission]; |
6083
72c882c0fd0f
first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
6078
diff
changeset
|
178 |
|
6084 | 179 |
NSString *missionPath = [[NSString alloc] initWithFormat:@"escript Missions/Training/%@.lua",withScript]; |
6263
ec41637ceb64
don't keep track of the savepath and of engineprotocol objects
koda
parents:
6261
diff
changeset
|
180 |
NSDictionary *missionLine = [[NSDictionary alloc] initWithObjectsAndKeys:missionPath,@"mission_command",nil]; |
6084 | 181 |
[missionPath release]; |
6263
ec41637ceb64
don't keep track of the savepath and of engineprotocol objects
koda
parents:
6261
diff
changeset
|
182 |
|
6266
b02a1e92dba2
convert gameinterfacebridge in simple-to-use class methods
koda
parents:
6265
diff
changeset
|
183 |
[GameInterfaceBridge prepareEngineOn:nil withOptions:missionLine]; |
6263
ec41637ceb64
don't keep track of the savepath and of engineprotocol objects
koda
parents:
6261
diff
changeset
|
184 |
[missionLine release]; |
6083
72c882c0fd0f
first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
6078
diff
changeset
|
185 |
} |
72c882c0fd0f
first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
6078
diff
changeset
|
186 |
|
6261
7050772ae46a
remove the need of saving the calling controller (disabling stats, but they were already broken by a previous commit)
koda
parents:
6259
diff
changeset
|
187 |
/* |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
188 |
-(void) gameHasEndedWithStats:(NSArray *)stats { |
6020
c792d4b3e080
this finally fixes the interaction between RestoredGameViewController and StatsPagesViewController
koda
parents:
6018
diff
changeset
|
189 |
// wrap this around a retain/realse to prevent being deallocated too soon |
c792d4b3e080
this finally fixes the interaction between RestoredGameViewController and StatsPagesViewController
koda
parents:
6018
diff
changeset
|
190 |
[self retain]; |
c792d4b3e080
this finally fixes the interaction between RestoredGameViewController and StatsPagesViewController
koda
parents:
6018
diff
changeset
|
191 |
// display stats page if there is something to display |
5158
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
192 |
if (stats != nil) { |
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
193 |
StatsPageViewController *statsPage = [[StatsPageViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
194 |
statsPage.statsArray = stats; |
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
195 |
statsPage.modalTransitionStyle = UIModalTransitionStyleCoverVertical; |
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
196 |
if ([statsPage respondsToSelector:@selector(setModalPresentationStyle:)]) |
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
197 |
statsPage.modalPresentationStyle = UIModalPresentationPageSheet; |
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
198 |
|
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
199 |
[self.parentController presentModalViewController:statsPage animated:YES]; |
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
200 |
[statsPage release]; |
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
201 |
} |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
202 |
|
5157 | 203 |
// can remove the savefile if the replay has ended |
6247
6dfad55fd71c
unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents:
6246
diff
changeset
|
204 |
if ([HWUtils gameType] == gtSave) |
5157 | 205 |
[[NSFileManager defaultManager] removeItemAtPath:self.savePath error:nil]; |
6020
c792d4b3e080
this finally fixes the interaction between RestoredGameViewController and StatsPagesViewController
koda
parents:
6018
diff
changeset
|
206 |
[self release]; |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
207 |
} |
6261
7050772ae46a
remove the need of saving the calling controller (disabling stats, but they were already broken by a previous commit)
koda
parents:
6259
diff
changeset
|
208 |
*/ |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
209 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
210 |
@end |