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 "llvieweruictrlfactory.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 gUICtrlFactory->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 LLViewHandle* handlep = ((LLViewHandle*)userdata);
00100 LLFloater* self = getFloaterByHandle(*handlep);
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 = LLUICtrlFactory::getButtonByName(self, "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 LLViewHandle(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 = LLUICtrlFactory::getButtonByName(self, "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 LLViewHandle(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::saveAnim( void *userdata )
00184 {
00185 LLPreviewAnim* self = (LLPreviewAnim*) userdata;
00186 const LLInventoryItem *item = self->getItem();
00187
00188 if(item)
00189 {
00190 LLKeyframeMotion* motionp = (LLKeyframeMotion*)gAgent.getAvatarObject()->createMotion( item->getAssetUUID() );
00191 if (motionp && motionp->isLoaded())
00192 {
00193 LLFilePicker& picker = LLFilePicker::instance();
00194 LLString proposed_name = item->getName() + LLString(".xaf");
00195 if (picker.getSaveFile(LLFilePicker::FFSAVE_ANIM, proposed_name.c_str()))
00196 {
00197 apr_file_t* fp = ll_apr_file_open(picker.getFirstFile(), LL_APR_W);
00198 if (!fp)
00199 {
00200 llwarns << "Unable to open file " << picker.getFirstFile() << llendl;
00201 return;
00202 }
00203 motionp->writeCAL3D(fp);
00204 apr_file_close(fp);
00205 }
00206 }
00207 }
00208 }
00209
00210 void LLPreviewAnim::onClose(bool app_quitting)
00211 {
00212 const LLInventoryItem *item = getItem();
00213
00214 if(item)
00215 {
00216 gAgent.getAvatarObject()->stopMotion(item->getAssetUUID());
00217 gAgent.sendAnimationRequest(item->getAssetUUID(), ANIM_REQUEST_STOP);
00218
00219 LLVOAvatar* avatar = gAgent.getAvatarObject();
00220 LLMotion* motion = avatar->findMotion(item->getAssetUUID());
00221
00222 if (motion)
00223 {
00224 motion->setDeactivateCallback(NULL, (void *)NULL);
00225 }
00226 }
00227 destroy();
00228 }