File: ActionCallbacks.cpp

package info (click to toggle)
criticalmass 1%3A1.0.0-1.5
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 18,740 kB
  • sloc: ansic: 47,628; cpp: 25,167; sh: 12,025; xml: 3,532; perl: 3,271; makefile: 662; python: 66; awk: 40; lisp: 33
file content (212 lines) | stat: -rw-r--r-- 4,671 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// Description:
//   Action callbacks for mouse and keyboard events.
//
// Copyright (C) 2001 Frank Becker
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation;  either version 2 of the License,  or (at your option) any  later
// version.
//
// This program is distributed in the hope that it will be useful,  but  WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
//
#include "SDL.h"

#include <Trace.hpp>

#include <Input.hpp>
#include <Video.hpp>
#include <Hero.hpp>
#include <Direction.hpp>
#include <Camera.hpp>
#include <MenuManager.hpp>
#include <ActionCallbacks.hpp>
#include <Audio.hpp>

void MotionAction::performAction( Trigger &trigger, bool /*isDown*/)
{
//    XTRACE();
    switch( GameState::context)
    {
	case Context::eInGame:
	    HeroS::instance()->move( trigger.fData1, trigger.fData2);
	    break;
	case Context::eCameraFlyby:
	    CameraS::instance()->mouseLook( trigger.fData1, trigger.fData2);
	    break;
	default:
	    break;
    }
}

void MotionLeftAction::performAction( Trigger &, bool isDown)
{
//    XTRACE();
    switch( GameState::context)
    {
	case Context::eInGame:
	    HeroS::instance()->move( Direction::eLeft, isDown);
	    break;
	case Context::eCameraFlyby:
	    CameraS::instance()->move( Direction::eLeft, isDown);
	    break;
	default:
	    break;
    }
}


void MotionRightAction::performAction( Trigger &, bool isDown)
{
//    XTRACE();
    switch( GameState::context)
    {
	case Context::eInGame:
	    HeroS::instance()->move( Direction::eRight, isDown);
	    break;
	case Context::eCameraFlyby:
	    CameraS::instance()->move( Direction::eRight, isDown);
	    break;
	default:
	    break;
    }
}

void MotionUpAction::performAction( Trigger &, bool isDown)
{
//    XTRACE();
    switch( GameState::context)
    {
	case Context::eInGame:
	    HeroS::instance()->move( Direction::eUp, isDown);
	    break;
	case Context::eCameraFlyby:
	    CameraS::instance()->move( Direction::eUp, isDown);
	    break;
	default:
	    break;
    }
}

void MotionDownAction::performAction( Trigger &, bool isDown)
{
//    XTRACE();
    switch( GameState::context)
    {
	case Context::eInGame:
	    HeroS::instance()->move( Direction::eDown, isDown);
	    break;
	case Context::eCameraFlyby:
	    CameraS::instance()->move( Direction::eDown, isDown);
	    break;
	default:
	    break;
    }
}

void WeaponFireAction::performAction( Trigger &, bool isDown)
{
//    XTRACE();
    switch( GameState::context)
    {
	case Context::eInGame:
	    HeroS::instance()->weaponFire( isDown, _numWeap);
	    break;
	case Context::eCameraFlyby:
	    HeroS::instance()->weaponFire( isDown, _numWeap);
	    break;
	default:
	    break;
    }
}

void SnapshotAction::performAction( Trigger &, bool isDown)
{
//    XTRACE();
    if( !isDown) return;

    VideoS::instance()->takeSnapshot();
}

void ConfirmAction::performAction( Trigger &, bool isDown)
{
//    XTRACE();
    if( !isDown) return;

    LOG_INFO << "Yes Sir!" << endl;

#if 0
    switch( GameState::context)
    {
	default:
	    break;
    }
#endif
}

void ChangeContext::performAction( Trigger &, bool isDown)
{
//    XTRACE();
    if( !isDown) return;

    if( GameState::context == Context::eInGame)
    {
	LOG_INFO << "eCameraFlyby..." << endl;
	GameState::context = Context::eCameraFlyby;
	GameState::stopwatch.pause();
    }
    else if( GameState::context == Context::eCameraFlyby)
    {
	LOG_INFO << "eInGame..." << endl;
	GameState::context = Context::eInGame;
	GameState::stopwatch.start();
    }
}

void CritterBoard::performAction( Trigger &, bool isDown)
{
//    XTRACE();
    if( !isDown) return;

//    LOG_INFO << "toggle CritterBoard..." << endl;
    VideoS::instance()->toggleCritterBoard();
}

void PauseGame::performAction( Trigger &, bool isDown)
{
//    XTRACE();
    if( !isDown) return;

    if( GameState::context == Context::ePaused)
    {
	LOG_INFO << "un-pausing..." << endl;
	GameState::context = _prevContext;
	GameState::stopwatch.start();
    }
    else
    {
	LOG_INFO << "pausing..." << endl;
	_prevContext = GameState::context;
	GameState::context = Context::ePaused;
	GameState::stopwatch.pause();
    }
}

void EscapeAction::performAction( Trigger &, bool isDown)
{
//    XTRACE();
    if( !isDown) return;

    switch( GameState::context)
    {
	case Context::eMenu:
	    break;

	default:
//	    LOG_INFO << "Menu mode..." << endl;
            MenuManagerS::instance()->turnMenuOn();
	    break;
    }
}