author | koda |
Sun, 17 Apr 2011 20:52:56 +0200 | |
changeset 5154 | 851f36579ed4 |
parent 5106 | 517bdd3865f1 |
child 5174 | f5294509783e |
permissions | -rw-r--r-- |
4028 | 1 |
/* |
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
|
4976 | 3 |
* Copyright (c) 2009-2011 Vittorio Giovara <vittorio.giovara@gmail.com> |
4028 | 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 |
5002
a9c44a8ffec8
we get our own AppDelegate, subclassing SDL_UikitAppDelegate so that we don't have to mess with sdl build system
koda
parents:
4976
diff
changeset
|
100 |
UIWindow *theWindow = (IS_DUALHEAD()) ? [HedgewarsAppDelegate sharedAppDelegate].uiwindow : [[UIApplication sharedApplication] keyWindow]; |
4028 | 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 |
} |
5106
517bdd3865f1
wow we're getting famous http://hg.libsdl.org/SDL/rev/8a04b596b472
koda
parents:
5002
diff
changeset
|
157 |
|
517bdd3865f1
wow we're getting famous http://hg.libsdl.org/SDL/rev/8a04b596b472
koda
parents:
5002
diff
changeset
|
158 |
// dummy function to prevent linkage fail |
517bdd3865f1
wow we're getting famous http://hg.libsdl.org/SDL/rev/8a04b596b472
koda
parents:
5002
diff
changeset
|
159 |
int SDL_main(int argc, char **argv) { |
517bdd3865f1
wow we're getting famous http://hg.libsdl.org/SDL/rev/8a04b596b472
koda
parents:
5002
diff
changeset
|
160 |
return 0; |
517bdd3865f1
wow we're getting famous http://hg.libsdl.org/SDL/rev/8a04b596b472
koda
parents:
5002
diff
changeset
|
161 |
} |
517bdd3865f1
wow we're getting famous http://hg.libsdl.org/SDL/rev/8a04b596b472
koda
parents:
5002
diff
changeset
|
162 |
|
517bdd3865f1
wow we're getting famous http://hg.libsdl.org/SDL/rev/8a04b596b472
koda
parents:
5002
diff
changeset
|
163 |