summaryrefslogtreecommitdiffstats
path: root/game/code/ai/playanimonce.cpp
blob: 8069f9e2ebfdf86b39bfb90c1ee0043b176ea040 (plain) (blame)
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
//===========================================================================
// Copyright (C) 2002 Radical Entertainment Ltd.  All rights reserved.
//
// Component:   PlayAnimOnce
//
// Description: PlayAnimOnce is an AnimSwitch (See actionbuttonhandler) where, button
//              button press, the associated animation (AnimCollDSG object) is played
//              once, then the animation stops and the button disappears
//
// Authors:     Michael Riegger
//
//===========================================================================


//---------------------------------------------------------------------------
// Includes
//===========================================================================
#include <p3d/anim/multicontroller.hpp>
#include <ai/playanimonce.h>
#include <ai/sequencer/action.h>
#include <ai/sequencer/sequencer.h>
#include <ai/actionbuttonmanager.h>
#include <meta/actioneventlocator.h>
#include <meta/triggervolumetracker.h>
#include <events/eventmanager.h>
#include <events/eventdata.h>

//===========================================================================
// Local Constants, Typedefs, and Macros
//===========================================================================




//===========================================================================
// Global Data, Local Data, Local Classes
//===========================================================================

//===========================================================================
// Member Functions
//===========================================================================

//===========================================================================
// PlayAnimOnce::PlayAnimOnce
//===========================================================================
// Description:
//      PlayAnimOnce - ctor
//
// Constraints:
//      Needs certain things in the inventory
//
// Parameters:
//      ActionEventLocator, can't be NULL
//
// Return:
//      
//
//===========================================================================

using namespace ActionButton;

PlayAnimOnce::PlayAnimOnce( ActionEventLocator* pActionEventLocator )
: PlayAnim( pActionEventLocator ),
mWasPressed( false )
{
        
}

//===========================================================================
// PlayAnimOnce::~PlayAnimOnce
//===========================================================================
// Description:
//      PlayAnimOnce - dtor
//
// Constraints:
//
// Parameters:
//
// Return:
//      
//
//===========================================================================
PlayAnimOnce::~PlayAnimOnce()
{
    //
    // Make good and sure this thing isn't going to play sound anymore
    //
    GetEventManager()->TriggerEvent( EVENT_STOP_ANIMATION_SOUND, this );
}

bool PlayAnimOnce::OnButtonPressed( Character* pCharacter, Sequencer* pSeq )
{
    bool success;
    if ( mWasPressed == false )
    {
        // Don't think, play the animation, then remove this actionbuttonhandler from the manager

        // Force the animation to be NOT cyclic.
        //
        tMultiController* pAnimController = GetAnimController();

        pAnimController->SetCycleMode( FORCE_NON_CYCLIC );
        pAnimController->SetFrame( 0.0f );
        
        // Action will assign this value which will start the animation.
        //
        Action* pAction = 0;
        float fDirection = 1.0f;
        pSeq->BeginSequence();
        pAction = new AssignValueToFloat( GetAnimationDirection( ), fDirection );
        pSeq->AddAction( pAction );
        pSeq->EndSequence( );

        // Disallow the pressing of this button ever again
        mWasPressed = true;
        for (unsigned int i = 0 ; i < GetActionEventLocator()->GetNumTriggers() ; i++)
        {
            TriggerVolume* pTriggerVolume = GetActionEventLocator()->GetTriggerVolume( i );
            GetTriggerVolumeTracker()->RemoveTrigger( pTriggerVolume );  
        }
        if( mSoundName != NULL )
        {
            AnimSoundData data( mSoundName, mSettingsName );

            GetEventManager()->TriggerEvent( EVENT_START_ANIMATION_SOUND, &data );
        }
        success = true;
    }
    else
    {
        success = false;
    }
    return success;
}

//===========================================================================
// PlayAnimOnce::PositionCharacter
//===========================================================================
// Description:
//      PositionCharacter
//
// Constraints:
//
// Parameters:
//
// Return:
//      
//
//===========================================================================

void 
PlayAnimOnce::PositionCharacter( Character* pCharacter, Sequencer* pSeq )
{
    if ( mWasPressed == false )
    {
        AnimSwitch::PositionCharacter( pCharacter, pSeq );
    }
}