Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "engines/grim/debug.h"
00025 #include "engines/grim/costume/keyframe_component.h"
00026 #include "engines/grim/costume/model_component.h"
00027
00028 namespace Grim {
00029
00030 KeyframeComponent::KeyframeComponent(Component *p, int parentID, const char *filename, tag32 t) :
00031 Component(p, parentID, filename, t), _priority1(1), _priority2(5), _anim(nullptr) {
00032 const char *comma = strchr(filename, ',');
00033 if (comma) {
00034 _name = Common::String(filename, comma);
00035 sscanf(comma + 1, "%d,%d", &_priority1, &_priority2);
00036 }
00037 }
00038
00039 KeyframeComponent::~KeyframeComponent() {
00040 delete _anim;
00041 }
00042
00043 void KeyframeComponent::fade(Animation::FadeMode fadeMode, int fadeLength) {
00044 _anim->fade(fadeMode, fadeLength);
00045 }
00046
00047 void KeyframeComponent::setKey(int val) {
00048 switch (val) {
00049 case 0:
00050 _anim->play(Animation::Once);
00051 break;
00052 case 1:
00053 _anim->play(Animation::Looping);
00054 break;
00055 case 2:
00056 _anim->play(Animation::PauseAtEnd);
00057 break;
00058 case 3:
00059 _anim->play(Animation::FadeAtEnd);
00060 break;
00061 case 4:
00062 reset();
00063 break;
00064 case 5:
00065 _anim->pause(true);
00066 break;
00067 case 6:
00068 _anim->pause(false);
00069 break;
00070 case 7:
00071 fade(Animation::FadeIn, 1000);
00072 _anim->activate();
00073 break;
00074 case 8:
00075 fade(Animation::FadeIn, 500);
00076 _anim->activate();
00077 break;
00078 case 9:
00079 fade(Animation::FadeIn, 250);
00080 _anim->activate();
00081 break;
00082 case 10:
00083 fade(Animation::FadeIn, 125);
00084 _anim->activate();
00085 break;
00086 case 11:
00087 fade(Animation::FadeOut, 1000);
00088 break;
00089 case 12:
00090 fade(Animation::FadeOut, 500);
00091 break;
00092 case 13:
00093 fade(Animation::FadeOut, 250);
00094 break;
00095 case 14:
00096 fade(Animation::FadeOut, 125);
00097 break;
00098 default:
00099 Debug::warning(Debug::Costumes, "Unknown key %d for component %s", val, _name.c_str());
00100 }
00101 }
00102
00103 void KeyframeComponent::reset() {
00104 if (_anim->getFadeMode() != Animation::FadeOut) {
00105 _anim->stop();
00106 }
00107 }
00108
00109 int KeyframeComponent::update(uint time) {
00110 if (!_anim->getIsActive())
00111 return 0;
00112
00113 return _anim->update((int)time);
00114 }
00115
00116 void KeyframeComponent::init() {
00117 if (_parent->isComponentType('M','M','D','L') ||
00118 _parent->isComponentType('M','O','D','L')) {
00119 ModelComponent *mc = static_cast<ModelComponent *>(_parent);
00120 _anim = new Animation(_name, mc->getAnimManager(), _priority1, _priority2);
00121 } else {
00122 Debug::warning(Debug::Costumes, "Parent of %s was not a model", _name.c_str());
00123 _anim = nullptr;
00124 }
00125 }
00126
00127 void KeyframeComponent::saveState(SaveGame *state) {
00128 _anim->saveState(state);
00129 }
00130
00131 void KeyframeComponent::restoreState(SaveGame *state) {
00132 _anim->restoreState(state);
00133 }
00134
00135 }