author | nemo |
Tue, 28 Dec 2010 18:47:44 -0500 | |
changeset 4755 | 7df529b4335c |
parent 4752 | d65705a67c4e |
child 4948 | c3dc41ae68fa |
permissions | -rw-r--r-- |
4028 | 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 30/10/2010. |
|
19 |
*/ |
|
20 |
||
21 |
||
22 |
#import "ObjcExports.h" |
|
4362
8dae325dc625
added missing graphics and fixed some glitches/crashes/bugs
koda
parents:
4034
diff
changeset
|
23 |
#import "AmmoMenuViewController.h" |
4461
2f4f5d649bcd
add a simple check to prevent loading sounds when device is muted
koda
parents:
4362
diff
changeset
|
24 |
#import "AudioToolbox/AudioToolbox.h" |
4028 | 25 |
|
26 |
#pragma mark - |
|
27 |
#pragma mark internal variables |
|
28 |
// actual game started (controls should be enabled) |
|
29 |
BOOL gameRunning; |
|
30 |
// black screen present |
|
31 |
BOOL savedGame; |
|
32 |
// cache the grenade time |
|
33 |
NSInteger grenadeTime; |
|
4362
8dae325dc625
added missing graphics and fixed some glitches/crashes/bugs
koda
parents:
4034
diff
changeset
|
34 |
// the reference to the newMenu instance |
8dae325dc625
added missing graphics and fixed some glitches/crashes/bugs
koda
parents:
4034
diff
changeset
|
35 |
AmmoMenuViewController *amvc_instance; |
4461
2f4f5d649bcd
add a simple check to prevent loading sounds when device is muted
koda
parents:
4362
diff
changeset
|
36 |
// the audiosession must be initialized before using properties |
2f4f5d649bcd
add a simple check to prevent loading sounds when device is muted
koda
parents:
4362
diff
changeset
|
37 |
BOOL gAudioSessionInited = NO; |
4028 | 38 |
|
39 |
#pragma mark - |
|
40 |
#pragma mark functions called like oop |
|
41 |
void objcExportsInit() { |
|
4034
634a8c8682de
add some phone rumbling to big explosions, airbomb and sinegun
koda
parents:
4028
diff
changeset
|
42 |
gameRunning = NO; |
634a8c8682de
add some phone rumbling to big explosions, airbomb and sinegun
koda
parents:
4028
diff
changeset
|
43 |
savedGame = NO; |
634a8c8682de
add some phone rumbling to big explosions, airbomb and sinegun
koda
parents:
4028
diff
changeset
|
44 |
grenadeTime = 2; |
4028 | 45 |
} |
46 |
||
47 |
BOOL inline isGameRunning() { |
|
48 |
return gameRunning; |
|
49 |
} |
|
50 |
||
51 |
void inline setGameRunning(BOOL value) { |
|
52 |
gameRunning = value; |
|
53 |
} |
|
54 |
||
55 |
NSInteger cachedGrenadeTime() { |
|
56 |
return grenadeTime; |
|
57 |
} |
|
58 |
||
59 |
void inline setGrenadeTime(NSInteger value) { |
|
60 |
grenadeTime = value; |
|
61 |
} |
|
62 |
||
4362
8dae325dc625
added missing graphics and fixed some glitches/crashes/bugs
koda
parents:
4034
diff
changeset
|
63 |
void inline setAmmoMenuInstance(AmmoMenuViewController *instance) { |
8dae325dc625
added missing graphics and fixed some glitches/crashes/bugs
koda
parents:
4034
diff
changeset
|
64 |
amvc_instance = instance; |
8dae325dc625
added missing graphics and fixed some glitches/crashes/bugs
koda
parents:
4034
diff
changeset
|
65 |
} |
8dae325dc625
added missing graphics and fixed some glitches/crashes/bugs
koda
parents:
4034
diff
changeset
|
66 |
|
4028 | 67 |
#pragma mark - |
68 |
#pragma mark functions called by pascal code |
|
69 |
void startSpinning() { |
|
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); |
|
94 |
if (savedGame == NO) |
|
95 |
gameRunning = YES; |
|
96 |
} |
|
97 |
||
98 |
void clearView() { |
|
4504
8906b2409d97
add the appirater class for getting more positive reviews
koda
parents:
4488
diff
changeset
|
99 |
// don't use any engine calls here as this function is called every time the ammomenu is opened |
4028 | 100 |
UIWindow *theWindow = (IS_DUALHEAD()) ? [SDLUIKitDelegate sharedAppDelegate].uiwindow : [[UIApplication sharedApplication] keyWindow]; |
101 |
UIButton *theButton = (UIButton *)[theWindow viewWithTag:CONFIRMATION_TAG]; |
|
102 |
UISegmentedControl *theSegment = (UISegmentedControl *)[theWindow viewWithTag:GRENADE_TAG]; |
|
103 |
||
104 |
[UIView beginAnimations:@"remove button" context:NULL]; |
|
105 |
[UIView setAnimationDuration:ANIMATION_DURATION]; |
|
106 |
theButton.alpha = 0; |
|
107 |
theSegment.alpha = 0; |
|
108 |
[UIView commitAnimations]; |
|
109 |
||
110 |
if (theButton) |
|
111 |
[theWindow performSelector:@selector(removeFromSuperview) withObject:theButton afterDelay:ANIMATION_DURATION]; |
|
112 |
if (theSegment) |
|
113 |
[theWindow performSelector:@selector(removeFromSuperview) withObject:theSegment afterDelay:ANIMATION_DURATION]; |
|
114 |
||
115 |
grenadeTime = 2; |
|
116 |
} |
|
117 |
||
118 |
void replayBegan() { |
|
119 |
UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow]; |
|
120 |
UIView *blackView = [[UIView alloc] initWithFrame:theWindow.frame]; |
|
121 |
blackView.backgroundColor = [UIColor blackColor]; |
|
122 |
blackView.alpha = 0.6; |
|
123 |
blackView.tag = REPLAYBLACKVIEW_TAG; |
|
124 |
blackView.exclusiveTouch = NO; |
|
125 |
blackView.multipleTouchEnabled = NO; |
|
126 |
blackView.userInteractionEnabled = NO; |
|
127 |
||
128 |
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; |
|
129 |
indicator.center = theWindow.center; |
|
130 |
[indicator startAnimating]; |
|
131 |
[blackView addSubview:indicator]; |
|
132 |
[indicator release]; |
|
133 |
[theWindow addSubview:blackView]; |
|
134 |
[blackView release]; |
|
135 |
||
136 |
savedGame = YES; |
|
137 |
stopSpinning(); |
|
138 |
} |
|
139 |
||
140 |
void replayFinished() { |
|
141 |
UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow]; |
|
142 |
UIView *blackView = (UIView *)[theWindow viewWithTag:REPLAYBLACKVIEW_TAG]; |
|
143 |
||
144 |
[UIView beginAnimations:@"removing black" context:NULL]; |
|
145 |
[UIView setAnimationDuration:1]; |
|
146 |
blackView.alpha = 0; |
|
147 |
[UIView commitAnimations]; |
|
148 |
[theWindow performSelector:@selector(removeFromSuperview) withObject:blackView afterDelay:1]; |
|
149 |
||
150 |
gameRunning = YES; |
|
151 |
savedGame = NO; |
|
152 |
} |
|
4034
634a8c8682de
add some phone rumbling to big explosions, airbomb and sinegun
koda
parents:
4028
diff
changeset
|
153 |
|
634a8c8682de
add some phone rumbling to big explosions, airbomb and sinegun
koda
parents:
4028
diff
changeset
|
154 |
void updateVisualsNewTurn(void) { |
4362
8dae325dc625
added missing graphics and fixed some glitches/crashes/bugs
koda
parents:
4034
diff
changeset
|
155 |
[amvc_instance updateAmmoVisuals]; |
4034
634a8c8682de
add some phone rumbling to big explosions, airbomb and sinegun
koda
parents:
4028
diff
changeset
|
156 |
} |
4461
2f4f5d649bcd
add a simple check to prevent loading sounds when device is muted
koda
parents:
4362
diff
changeset
|
157 |
|
4507
0f9b86942c19
audio_session is giving problems with multitasking so disabling it for now
koda
parents:
4504
diff
changeset
|
158 |
/* |
4461
2f4f5d649bcd
add a simple check to prevent loading sounds when device is muted
koda
parents:
4362
diff
changeset
|
159 |
// http://stackoverflow.com/questions/287543/how-to-programatically-sense-the-iphone-mute-switch |
2f4f5d649bcd
add a simple check to prevent loading sounds when device is muted
koda
parents:
4362
diff
changeset
|
160 |
BOOL isAppleDeviceMuted(void) { |
2f4f5d649bcd
add a simple check to prevent loading sounds when device is muted
koda
parents:
4362
diff
changeset
|
161 |
if (!gAudioSessionInited) { |
2f4f5d649bcd
add a simple check to prevent loading sounds when device is muted
koda
parents:
4362
diff
changeset
|
162 |
AudioSessionInterruptionListener inInterruptionListener = NULL; |
2f4f5d649bcd
add a simple check to prevent loading sounds when device is muted
koda
parents:
4362
diff
changeset
|
163 |
OSStatus error; |
4507
0f9b86942c19
audio_session is giving problems with multitasking so disabling it for now
koda
parents:
4504
diff
changeset
|
164 |
if ((error = AudioSessionInitialize(NULL, NULL, inInterruptionListener, NULL))) |
4461
2f4f5d649bcd
add a simple check to prevent loading sounds when device is muted
koda
parents:
4362
diff
changeset
|
165 |
DLog(@"*** Error *** error in AudioSessionInitialize: %d", error); |
2f4f5d649bcd
add a simple check to prevent loading sounds when device is muted
koda
parents:
4362
diff
changeset
|
166 |
else |
2f4f5d649bcd
add a simple check to prevent loading sounds when device is muted
koda
parents:
4362
diff
changeset
|
167 |
gAudioSessionInited = YES; |
2f4f5d649bcd
add a simple check to prevent loading sounds when device is muted
koda
parents:
4362
diff
changeset
|
168 |
} |
2f4f5d649bcd
add a simple check to prevent loading sounds when device is muted
koda
parents:
4362
diff
changeset
|
169 |
UInt32 propertySize = sizeof(CFStringRef); |
4504
8906b2409d97
add the appirater class for getting more positive reviews
koda
parents:
4488
diff
changeset
|
170 |
BOOL muteResult = NO; |
4461
2f4f5d649bcd
add a simple check to prevent loading sounds when device is muted
koda
parents:
4362
diff
changeset
|
171 |
|
2f4f5d649bcd
add a simple check to prevent loading sounds when device is muted
koda
parents:
4362
diff
changeset
|
172 |
// this checks if there is volume |
2f4f5d649bcd
add a simple check to prevent loading sounds when device is muted
koda
parents:
4362
diff
changeset
|
173 |
Float32 volume; |
2f4f5d649bcd
add a simple check to prevent loading sounds when device is muted
koda
parents:
4362
diff
changeset
|
174 |
OSStatus n = AudioSessionGetProperty(kAudioSessionProperty_CurrentHardwareOutputVolume, &propertySize, &volume); |
2f4f5d649bcd
add a simple check to prevent loading sounds when device is muted
koda
parents:
4362
diff
changeset
|
175 |
if (n != 0) |
4488 | 176 |
DLog( @"AudioSessionGetProperty 'volume': %d", n ); |
4507
0f9b86942c19
audio_session is giving problems with multitasking so disabling it for now
koda
parents:
4504
diff
changeset
|
177 |
BOOL volumeResult = (volume == 0.0f); |
4461
2f4f5d649bcd
add a simple check to prevent loading sounds when device is muted
koda
parents:
4362
diff
changeset
|
178 |
|
2f4f5d649bcd
add a simple check to prevent loading sounds when device is muted
koda
parents:
4362
diff
changeset
|
179 |
// this checks if the device is muted |
2f4f5d649bcd
add a simple check to prevent loading sounds when device is muted
koda
parents:
4362
diff
changeset
|
180 |
CFStringRef state; |
2f4f5d649bcd
add a simple check to prevent loading sounds when device is muted
koda
parents:
4362
diff
changeset
|
181 |
n = AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &propertySize, &state); |
2f4f5d649bcd
add a simple check to prevent loading sounds when device is muted
koda
parents:
4362
diff
changeset
|
182 |
if (n != 0) |
4488 | 183 |
DLog( @"AudioSessionGetProperty 'audioRoute': %d", n ); |
4504
8906b2409d97
add the appirater class for getting more positive reviews
koda
parents:
4488
diff
changeset
|
184 |
else { |
8906b2409d97
add the appirater class for getting more positive reviews
koda
parents:
4488
diff
changeset
|
185 |
NSString *result = (NSString *)state; |
8906b2409d97
add the appirater class for getting more positive reviews
koda
parents:
4488
diff
changeset
|
186 |
muteResult = ([result length] == 0); |
8906b2409d97
add the appirater class for getting more positive reviews
koda
parents:
4488
diff
changeset
|
187 |
releaseAndNil(result); |
8906b2409d97
add the appirater class for getting more positive reviews
koda
parents:
4488
diff
changeset
|
188 |
} |
4461
2f4f5d649bcd
add a simple check to prevent loading sounds when device is muted
koda
parents:
4362
diff
changeset
|
189 |
return volumeResult || muteResult; |
2f4f5d649bcd
add a simple check to prevent loading sounds when device is muted
koda
parents:
4362
diff
changeset
|
190 |
} |
4507
0f9b86942c19
audio_session is giving problems with multitasking so disabling it for now
koda
parents:
4504
diff
changeset
|
191 |
*/ |