00001
00032 #include "llviewerprecompiledheaders.h"
00033
00034 #include "llpreviewanim.h"
00035 #include "llbutton.h"
00036 #include "llresmgr.h"
00037 #include "llinventory.h"
00038 #include "llinventoryview.h"
00039 #include "llvoavatar.h"
00040 #include "llagent.h"
00041 #include "llkeyframemotion.h"
00042 #include "llfilepicker.h"
00043 #include "lllineeditor.h"
00044 #include "lluictrlfactory.h"
00045 #include "lluictrlfactory.h"
00046
00047 extern LLAgent gAgent;
00048
00049 LLPreviewAnim::LLPreviewAnim(const std::string& name, const LLRect& rect, const std::string& title, const LLUUID& item_uuid, const S32& activate, const LLUUID& object_uuid ) :
00050 LLPreview( name, rect, title, item_uuid, object_uuid)
00051 {
00052 LLUICtrlFactory::getInstance()->buildFloater(this,"floater_preview_animation.xml");
00053
00054 childSetAction("Anim play btn",playAnim,this);
00055 childSetAction("Anim audition btn",auditionAnim,this);
00056
00057 const LLInventoryItem* item = getItem();
00058
00059 childSetCommitCallback("desc", LLPreview::onText, this);
00060 childSetText("desc", item->getDescription());
00061 childSetPrevalidate("desc", &LLLineEditor::prevalidatePrintableNotPipe);
00062
00063 setTitle(title);
00064
00065 if (!getHost())
00066 {
00067 LLRect curRect = getRect();
00068 translate(rect.mLeft - curRect.mLeft, rect.mTop - curRect.mTop);
00069 }
00070
00071
00072 if(item)
00073 {
00074 gAgent.getAvatarObject()->createMotion(item->getAssetUUID());
00075 }
00076
00077 switch ( activate )
00078 {
00079 case 1:
00080 {
00081 playAnim( (void *) this );
00082 break;
00083 }
00084 case 2:
00085 {
00086 auditionAnim( (void *) this );
00087 break;
00088 }
00089 default:
00090 {
00091
00092 }
00093 }
00094 }
00095
00096
00097 void LLPreviewAnim::endAnimCallback( void *userdata )
00098 {
00099 LLHandle<LLFloater>* handlep = ((LLHandle<LLFloater>*)userdata);
00100 LLFloater* self = handlep->get();
00101 delete handlep;
00102 if (self)
00103 {
00104 self->childSetValue("Anim play btn", FALSE);
00105 self->childSetValue("Anim audition btn", FALSE);
00106 }
00107 }
00108
00109
00110 void LLPreviewAnim::playAnim( void *userdata )
00111 {
00112 LLPreviewAnim* self = (LLPreviewAnim*) userdata;
00113 const LLInventoryItem *item = self->getItem();
00114
00115 if(item)
00116 {
00117 LLUUID itemID=item->getAssetUUID();
00118
00119 LLButton* btn = self->getChild<LLButton>("Anim play btn");
00120 if (btn)
00121 {
00122 btn->toggleState();
00123 }
00124
00125 if (self->childGetValue("Anim play btn").asBoolean() )
00126 {
00127 self->mPauseRequest = NULL;
00128 gAgent.sendAnimationRequest(itemID, ANIM_REQUEST_START);
00129
00130 LLVOAvatar* avatar = gAgent.getAvatarObject();
00131 LLMotion* motion = avatar->findMotion(itemID);
00132
00133 if (motion)
00134 {
00135 motion->setDeactivateCallback(&endAnimCallback, (void *)(new LLHandle<LLFloater>(self->getHandle())));
00136 }
00137 }
00138 else
00139 {
00140 gAgent.getAvatarObject()->stopMotion(itemID);
00141 gAgent.sendAnimationRequest(itemID, ANIM_REQUEST_STOP);
00142 }
00143 }
00144 }
00145
00146
00147 void LLPreviewAnim::auditionAnim( void *userdata )
00148 {
00149 LLPreviewAnim* self = (LLPreviewAnim*) userdata;
00150 const LLInventoryItem *item = self->getItem();
00151
00152 if(item)
00153 {
00154 LLUUID itemID=item->getAssetUUID();
00155
00156 LLButton* btn = self->getChild<LLButton>("Anim audition btn");
00157 if (btn)
00158 {
00159 btn->toggleState();
00160 }
00161
00162 if (self->childGetValue("Anim audition btn").asBoolean() )
00163 {
00164 self->mPauseRequest = NULL;
00165 gAgent.getAvatarObject()->startMotion(item->getAssetUUID());
00166
00167 LLVOAvatar* avatar = gAgent.getAvatarObject();
00168 LLMotion* motion = avatar->findMotion(itemID);
00169
00170 if (motion)
00171 {
00172 motion->setDeactivateCallback(&endAnimCallback, (void *)(new LLHandle<LLFloater>(self->getHandle())));
00173 }
00174 }
00175 else
00176 {
00177 gAgent.getAvatarObject()->stopMotion(itemID);
00178 gAgent.sendAnimationRequest(itemID, ANIM_REQUEST_STOP);
00179 }
00180 }
00181 }
00182
00183 void LLPreviewAnim::onClose(bool app_quitting)
00184 {
00185 const LLInventoryItem *item = getItem();
00186
00187 if(item)
00188 {
00189 gAgent.getAvatarObject()->stopMotion(item->getAssetUUID());
00190 gAgent.sendAnimationRequest(item->getAssetUUID(), ANIM_REQUEST_STOP);
00191
00192 LLVOAvatar* avatar = gAgent.getAvatarObject();
00193 LLMotion* motion = avatar->findMotion(item->getAssetUUID());
00194
00195 if (motion)
00196 {
00197 motion->setDeactivateCallback(NULL, (void *)NULL);
00198 }
00199 }
00200 destroy();
00201 }