18 * File created on 30/10/2010. |
18 * File created on 30/10/2010. |
19 */ |
19 */ |
20 |
20 |
21 |
21 |
22 #import "ObjcExports.h" |
22 #import "ObjcExports.h" |
|
23 #import "OverlayViewController.h" |
23 #import "AmmoMenuViewController.h" |
24 #import "AmmoMenuViewController.h" |
24 #import "AudioToolbox/AudioToolbox.h" |
|
25 |
25 |
26 #pragma mark - |
26 #pragma mark - |
27 #pragma mark internal variables |
27 #pragma mark internal variables |
28 // actual game started (controls should be enabled) |
28 // actual game started (controls should be enabled) |
29 BOOL gameRunning; |
29 BOOL gameRunning; |
30 // black screen present |
30 // black screen present |
31 BOOL savedGame; |
31 BOOL savedGame; |
32 // cache the grenade time |
32 // cache the grenade time |
33 NSInteger grenadeTime; |
33 NSInteger grenadeTime; |
34 // the reference to the newMenu instance |
34 // the reference to the newMenu instance |
35 AmmoMenuViewController *amvc_instance; |
35 OverlayViewController *overlay_instance; |
36 // the audiosession must be initialized before using properties |
36 // the audiosession must be initialized before using properties |
37 BOOL gAudioSessionInited = NO; |
37 BOOL gAudioSessionInited = NO; |
38 |
38 |
39 #pragma mark - |
39 #pragma mark - |
40 #pragma mark functions called like oop |
40 #pragma mark functions called like oop |
41 void objcExportsInit() { |
41 void objcExportsInit(OverlayViewController* instance) { |
|
42 overlay_instance = instance; |
42 gameRunning = NO; |
43 gameRunning = NO; |
43 savedGame = NO; |
44 savedGame = NO; |
44 grenadeTime = 2; |
45 grenadeTime = 2; |
45 } |
46 } |
46 |
47 |
58 |
59 |
59 void inline setGrenadeTime(NSInteger value) { |
60 void inline setGrenadeTime(NSInteger value) { |
60 grenadeTime = value; |
61 grenadeTime = value; |
61 } |
62 } |
62 |
63 |
63 void inline setAmmoMenuInstance(AmmoMenuViewController *instance) { |
64 #pragma mark - |
64 amvc_instance = instance; |
65 #pragma mark functions called by pascal code |
|
66 void startSpinningProgress() { |
|
67 gameRunning = NO; |
|
68 overlay_instance.lowerIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; |
|
69 |
|
70 CGPoint center = overlay_instance.view.center; |
|
71 overlay_instance.lowerIndicator.center = (IS_DUALHEAD() ? CGPointMake(center.y, center.x) |
|
72 : CGPointMake(center.y, center.x * 5/3)); |
|
73 |
|
74 [overlay_instance.lowerIndicator startAnimating]; |
|
75 [overlay_instance.view addSubview:overlay_instance.lowerIndicator]; |
|
76 [overlay_instance.lowerIndicator release]; |
65 } |
77 } |
66 |
78 |
67 #pragma mark - |
79 void stopSpinningProgress() { |
68 #pragma mark functions called by pascal code |
80 [overlay_instance.lowerIndicator stopAnimating]; |
69 void startSpinning() { |
81 [overlay_instance.lowerIndicator removeFromSuperview]; |
70 gameRunning = NO; |
|
71 UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow]; |
|
72 UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; |
|
73 indicator.tag = ACTIVITYINDICATOR_TAG; |
|
74 int offset; |
|
75 if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) |
|
76 offset = -120; |
|
77 else |
|
78 offset = 120; |
|
79 if (IS_DUALHEAD()) |
|
80 indicator.center = CGPointMake(theWindow.frame.size.width/2, theWindow.frame.size.height/2 + offset); |
|
81 else |
|
82 indicator.center = CGPointMake(theWindow.frame.size.width/2 + offset, theWindow.frame.size.height/2); |
|
83 indicator.hidesWhenStopped = YES; |
|
84 [indicator startAnimating]; |
|
85 [theWindow addSubview:indicator]; |
|
86 [indicator release]; |
|
87 } |
|
88 |
|
89 void stopSpinning() { |
|
90 UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow]; |
|
91 UIActivityIndicatorView *indicator = (UIActivityIndicatorView *)[theWindow viewWithTag:ACTIVITYINDICATOR_TAG]; |
|
92 [indicator stopAnimating]; |
|
93 HW_zoomSet(1.7); |
82 HW_zoomSet(1.7); |
94 if (savedGame == NO) |
83 if (savedGame == NO) |
95 gameRunning = YES; |
84 gameRunning = YES; |
96 } |
85 } |
97 |
86 |
113 [theWindow performSelector:@selector(removeFromSuperview) withObject:theSegment afterDelay:ANIMATION_DURATION]; |
102 [theWindow performSelector:@selector(removeFromSuperview) withObject:theSegment afterDelay:ANIMATION_DURATION]; |
114 |
103 |
115 grenadeTime = 2; |
104 grenadeTime = 2; |
116 } |
105 } |
117 |
106 |
118 void replayBegan() { |
107 void saveBeganSynching() { |
119 UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow]; |
108 overlay_instance.view.backgroundColor = [UIColor blackColor]; |
120 UIView *blackView = [[UIView alloc] initWithFrame:theWindow.frame]; |
109 overlay_instance.view.alpha = 0.75; |
121 blackView.backgroundColor = [UIColor blackColor]; |
110 overlay_instance.view.userInteractionEnabled = NO; |
122 blackView.alpha = 0.6; |
|
123 blackView.tag = REPLAYBLACKVIEW_TAG; |
|
124 blackView.exclusiveTouch = NO; |
|
125 blackView.multipleTouchEnabled = NO; |
|
126 blackView.userInteractionEnabled = NO; |
|
127 |
111 |
128 UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; |
112 overlay_instance.savesIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; |
129 indicator.center = theWindow.center; |
113 |
130 [indicator startAnimating]; |
114 CGPoint center = overlay_instance.view.center; |
131 [blackView addSubview:indicator]; |
115 overlay_instance.savesIndicator.center = CGPointMake(center.y, center.x); |
132 [indicator release]; |
116 overlay_instance.savesIndicator.hidesWhenStopped = YES; |
133 [theWindow addSubview:blackView]; |
117 |
134 [blackView release]; |
118 [overlay_instance.savesIndicator startAnimating]; |
|
119 [overlay_instance.view addSubview:overlay_instance.savesIndicator]; |
|
120 [overlay_instance.savesIndicator release]; |
135 |
121 |
136 savedGame = YES; |
122 savedGame = YES; |
137 stopSpinning(); |
123 stopSpinningProgress(); |
138 } |
124 } |
139 |
125 |
140 void replayFinished() { |
126 void saveFinishedSynching() { |
141 UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow]; |
127 [UIView beginAnimations:@"fading from save synch" context:NULL]; |
142 UIView *blackView = (UIView *)[theWindow viewWithTag:REPLAYBLACKVIEW_TAG]; |
128 [UIView setAnimationDuration:1]; |
|
129 overlay_instance.view.backgroundColor = [UIColor clearColor]; |
|
130 overlay_instance.view.alpha = 1; |
|
131 overlay_instance.view.userInteractionEnabled = YES; |
|
132 [UIView commitAnimations]; |
143 |
133 |
144 [UIView beginAnimations:@"removing black" context:NULL]; |
134 [overlay_instance.savesIndicator stopAnimating]; |
145 [UIView setAnimationDuration:1]; |
135 [overlay_instance.savesIndicator performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1]; |
146 blackView.alpha = 0; |
|
147 [UIView commitAnimations]; |
|
148 [theWindow performSelector:@selector(removeFromSuperview) withObject:blackView afterDelay:1]; |
|
149 |
136 |
150 gameRunning = YES; |
137 gameRunning = YES; |
151 savedGame = NO; |
138 savedGame = NO; |
152 } |
139 } |
153 |
140 |
154 void updateVisualsNewTurn(void) { |
141 void updateVisualsNewTurn(void) { |
155 [amvc_instance updateAmmoVisuals]; |
142 [overlay_instance.amvc updateAmmoVisuals]; |
156 } |
143 } |
157 |
144 |
158 // dummy function to prevent linkage fail |
145 // dummy function to prevent linkage fail |
159 int SDL_main(int argc, char **argv) { |
146 int SDL_main(int argc, char **argv) { |
160 return 0; |
147 return 0; |
161 } |
148 } |
162 |
|
163 |
|