From 4e4dbd4012838521edfdc9e3b5f0f9768759a476 Mon Sep 17 00:00:00 2001 From: Inusaito Sayori Date: Thu, 14 May 2015 23:55:20 -0400 Subject: [PATCH] Satisfy Issue 1916: Local Gesture Preview/Play Adds a dropdown option to gesture preview button to preview locally. Note that any chat commands in gestures will still work as they normally would! Translators: do your thing or hold your peace. (floater_preview_gesture.xml) These code changes will look nicer viewer without space changes~ --- indra/llcharacter/llmultigesture.cpp | 2 + indra/llcharacter/llmultigesture.h | 3 + indra/newview/chatbar_as_cmdline.cpp | 27 +++++++++ indra/newview/llgesturemgr.cpp | 58 +++++++++++++------ indra/newview/llgesturemgr.h | 4 +- indra/newview/llpreviewgesture.cpp | 21 ++++--- indra/newview/llpreviewgesture.h | 4 +- .../xui/en-us/floater_preview_gesture.xml | 6 +- 8 files changed, 91 insertions(+), 34 deletions(-) diff --git a/indra/llcharacter/llmultigesture.cpp b/indra/llcharacter/llmultigesture.cpp index d8290681a..ef42576dc 100644 --- a/indra/llcharacter/llmultigesture.cpp +++ b/indra/llcharacter/llmultigesture.cpp @@ -49,6 +49,7 @@ LLMultiGesture::LLMultiGesture() mReplaceText(), mSteps(), mPlaying(FALSE), + mLocal(false), mCurrentStep(0), mDoneCallback(NULL) { @@ -63,6 +64,7 @@ LLMultiGesture::~LLMultiGesture() void LLMultiGesture::reset() { mPlaying = FALSE; + mLocal = false; mCurrentStep = 0; mWaitTimer.reset(); mWaitingTimer = FALSE; diff --git a/indra/llcharacter/llmultigesture.h b/indra/llcharacter/llmultigesture.h index 4c5a29cf0..8e4821357 100644 --- a/indra/llcharacter/llmultigesture.h +++ b/indra/llcharacter/llmultigesture.h @@ -79,6 +79,9 @@ public: // Is the gesture currently playing? BOOL mPlaying; + // Is the gesture to be played locally? + bool mLocal; + // "instruction pointer" for steps S32 mCurrentStep; diff --git a/indra/newview/chatbar_as_cmdline.cpp b/indra/newview/chatbar_as_cmdline.cpp index dc1c77e41..82ae5514e 100644 --- a/indra/newview/chatbar_as_cmdline.cpp +++ b/indra/newview/chatbar_as_cmdline.cpp @@ -667,3 +667,30 @@ void cmdline_printchat(const std::string& message) LLFloaterChat::addChat(chat); } +static void fake_local_chat(LLChat chat, const std::string& name) +{ + chat.mFromName = name; + chat.mText = name + chat.mText; + LLFloaterChat::addChat(chat); +} +void fake_local_chat(std::string msg) +{ + bool action(LLStringUtil::startsWith(msg, "/me") && (msg[3] == ' ' || msg[3] == '\'')); + if (action) msg.erase(0, 4); + LLChat chat((action ? " " : ": ") + msg); + chat.mFromID = gAgentID; + chat.mSourceType = CHAT_SOURCE_SYSTEM; + if (rlv_handler_t::isEnabled()) chat.mRlvLocFiltered = chat.mRlvNamesFiltered = true; + chat.mPosAgent = gAgent.getPositionAgent(); + chat.mURL = "secondlife:///app/agent/" + gAgentID.asString() + "/about"; + if (action) chat.mChatStyle = CHAT_STYLE_IRC; + if (!LLAvatarNameCache::getNSName(gAgentID, chat.mFromName)) + { + LLAvatarNameCache::get(gAgentID, boost::bind(fake_local_chat, chat, boost::bind(&LLAvatarName::getNSName, _2, main_name_system()))); + } + else + { + chat.mText = chat.mFromName + chat.mText; + LLFloaterChat::addChat(chat); + } +} diff --git a/indra/newview/llgesturemgr.cpp b/indra/newview/llgesturemgr.cpp index 517266097..3a1a076e5 100644 --- a/indra/newview/llgesturemgr.cpp +++ b/indra/newview/llgesturemgr.cpp @@ -61,6 +61,8 @@ #include "shcommandhandler.h" #endif //shy_mod +void fake_local_chat(std::string msg); + // Longest time, in seconds, to wait for all animations to stop playing const F32 MAX_WAIT_ANIM_SECS = 30.f; @@ -522,7 +524,7 @@ void LLGestureMgr::replaceGesture(const LLUUID& item_id, const LLUUID& new_asset LLGestureMgr::instance().replaceGesture(base_item_id, gesture, new_asset_id); } -void LLGestureMgr::playGesture(LLMultiGesture* gesture) +void LLGestureMgr::playGesture(LLMultiGesture* gesture, bool local) { if (!gesture) return; @@ -531,6 +533,7 @@ void LLGestureMgr::playGesture(LLMultiGesture* gesture) // Add to list of playing gesture->mPlaying = TRUE; + gesture->mLocal = local; mPlaying.push_back(gesture); // Load all needed assets to minimize the delays @@ -608,7 +611,7 @@ void LLGestureMgr::playGesture(LLMultiGesture* gesture) // Convenience function that looks up the item_id for you. -void LLGestureMgr::playGesture(const LLUUID& item_id) +void LLGestureMgr::playGesture(const LLUUID& item_id, bool local) { const LLUUID& base_item_id = get_linked_uuid(item_id); @@ -826,8 +829,7 @@ void LLGestureMgr::stepGesture(LLMultiGesture* gesture) { // look in signaled animations (simulator's view of what is // currently playing. - LLVOAvatar::AnimIterator play_it = gAgentAvatarp->mSignaledAnimations.find(*gest_it); - if (play_it != gAgentAvatarp->mSignaledAnimations.end()) + if (gesture->mLocal ? !!gAgentAvatarp->findMotion(*gest_it) : (gAgentAvatarp->mSignaledAnimations.find(*gest_it) != gAgentAvatarp->mSignaledAnimations.end())) { ++gest_it; } @@ -970,21 +972,37 @@ void LLGestureMgr::runStep(LLMultiGesture* gesture, LLGestureStep* step) if (anim_step->mFlags & ANIM_FLAG_STOP) { - gAgent.sendAnimationRequest(anim_step->mAnimAssetID, ANIM_REQUEST_STOP); - // remove it from our request set in case we just requested it - std::set::iterator set_it = gesture->mRequestedAnimIDs.find(anim_step->mAnimAssetID); - if (set_it != gesture->mRequestedAnimIDs.end()) + if (gesture->mLocal) { - gesture->mRequestedAnimIDs.erase(set_it); + gAgentAvatarp->stopMotion(anim_step->mAnimAssetID); + } + else + { + gAgent.sendAnimationRequest(anim_step->mAnimAssetID, ANIM_REQUEST_STOP); + // remove it from our request set in case we just requested it + std::set::iterator set_it = gesture->mRequestedAnimIDs.find(anim_step->mAnimAssetID); + if (set_it != gesture->mRequestedAnimIDs.end()) + { + gesture->mRequestedAnimIDs.erase(set_it); + } } } else { - gAgent.sendAnimationRequest(anim_step->mAnimAssetID, ANIM_REQUEST_START); - // Indicate that we've requested this animation to play as - // part of this gesture (but it won't start playing for at - // least one round-trip to simulator). - gesture->mRequestedAnimIDs.insert(anim_step->mAnimAssetID); + if (gesture->mLocal) + { + gAgentAvatarp->startMotion(anim_step->mAnimAssetID); + // Indicate we're playing this animation now. + gesture->mPlayingAnimIDs.insert(anim_step->mAnimAssetID); + } + else + { + gAgent.sendAnimationRequest(anim_step->mAnimAssetID, ANIM_REQUEST_START); + // Indicate that we've requested this animation to play as + // part of this gesture (but it won't start playing for at + // least one round-trip to simulator). + gesture->mRequestedAnimIDs.insert(anim_step->mAnimAssetID); + } } gesture->mCurrentStep++; break; @@ -994,7 +1012,10 @@ void LLGestureMgr::runStep(LLMultiGesture* gesture, LLGestureStep* step) LLGestureStepSound* sound_step = (LLGestureStepSound*)step; const LLUUID& sound_id = sound_step->mSoundAssetID; const F32 volume = 1.f; - send_sound_trigger(sound_id, volume); + if (gesture->mLocal) + gAudiop->triggerSound(sound_id, gAgentID, volume, LLAudioEngine::AUDIO_TYPE_UI, gAgent.getPositionGlobal()); + else + send_sound_trigger(sound_id, volume); gesture->mCurrentStep++; break; } @@ -1011,7 +1032,7 @@ void LLGestureMgr::runStep(LLMultiGesture* gesture, LLGestureStep* step) #if SHY_MOD //Command handler if(!SHCommandHandler::handleCommand(true, chat_text, gAgentID, gAgentAvatarp))//returns true if handled #endif //shy_mod - gChatBar->sendChatFromViewer(chat_text, CHAT_TYPE_NORMAL, animate); + gesture->mLocal ? fake_local_chat(chat_text) : gChatBar->sendChatFromViewer(chat_text, CHAT_TYPE_NORMAL, animate); } gesture->mCurrentStep++; break; @@ -1284,7 +1305,10 @@ void LLGestureMgr::stopGesture(LLMultiGesture* gesture) for (set_it = gesture->mPlayingAnimIDs.begin(); set_it != gesture->mPlayingAnimIDs.end(); ++set_it) { const LLUUID& anim_id = *set_it; - gAgent.sendAnimationRequest(anim_id, ANIM_REQUEST_STOP); + if (gesture->mLocal) + gAgentAvatarp->stopMotion(anim_id, TRUE); + else + gAgent.sendAnimationRequest(anim_id, ANIM_REQUEST_STOP); } std::vector::iterator it; diff --git a/indra/newview/llgesturemgr.h b/indra/newview/llgesturemgr.h index 9f112261b..419ae77e7 100644 --- a/indra/newview/llgesturemgr.h +++ b/indra/newview/llgesturemgr.h @@ -103,8 +103,8 @@ public: const item_map_t& getActiveGestures() const { return mActive; } // Force a gesture to be played, for example, if it is being // previewed. - void playGesture(LLMultiGesture* gesture); - void playGesture(const LLUUID& item_id); + void playGesture(LLMultiGesture* gesture, bool local = false); + void playGesture(const LLUUID& item_id, bool local = false); // Stop all requested or playing anims for this gesture // Also remove from playing list diff --git a/indra/newview/llpreviewgesture.cpp b/indra/newview/llpreviewgesture.cpp index eb5a75972..b6e31b52e 100644 --- a/indra/newview/llpreviewgesture.cpp +++ b/indra/newview/llpreviewgesture.cpp @@ -44,6 +44,7 @@ #include "lldatapacker.h" #include "lldelayedgestureerror.h" #include "llfloatergesture.h" // for some label constants +#include "llflyoutbutton.h" #include "llgesturemgr.h" #include "llinventorydefines.h" #include "llinventoryfunctions.h" @@ -493,17 +494,17 @@ BOOL LLPreviewGesture::postBuild() mWaitTimeEditor = edit; // Buttons at the bottom - check = getChild( "active_check"); + check = getChild("active_check"); check->setCommitCallback(boost::bind(&LLPreviewGesture::onCommitActive,this)); mActiveCheck = check; - btn = getChild( "save_btn"); + btn = getChild("save_btn"); btn->setClickedCallback(boost::bind(&LLPreviewGesture::onClickSave,this)); mSaveBtn = btn; - btn = getChild( "preview_btn"); - btn->setClickedCallback(boost::bind(&LLPreviewGesture::onClickPreview,this)); - mPreviewBtn = btn; + LLFlyoutButton* flyout = getChild("preview_btn"); + flyout->setCommitCallback(boost::bind(&LLPreviewGesture::onClickPreview, this, _2)); + mPreviewBtn = flyout; // Populate the comboboxes @@ -1740,7 +1741,7 @@ void LLPreviewGesture::onClickSave() saveIfNeeded(); } -void LLPreviewGesture::onClickPreview() +void LLPreviewGesture::onClickPreview(bool local) { if (!mPreviewGesture) { @@ -1754,17 +1755,15 @@ void LLPreviewGesture::onClickPreview() mPreviewBtn->setLabel(getString("stop_txt")); // play it, and delete when done - LLGestureMgr::instance().playGesture(mPreviewGesture); - - refresh(); + LLGestureMgr::instance().playGesture(mPreviewGesture, local); } else { // Will call onDonePreview() below LLGestureMgr::instance().stopGesture(mPreviewGesture); - - refresh(); } + + refresh(); } diff --git a/indra/newview/llpreviewgesture.h b/indra/newview/llpreviewgesture.h index d4d7228f4..7bb27063f 100644 --- a/indra/newview/llpreviewgesture.h +++ b/indra/newview/llpreviewgesture.h @@ -137,7 +137,7 @@ protected: void onCommitActive(); void onClickSave(); - void onClickPreview(); + void onClickPreview(bool local); void onDonePreview(LLMultiGesture* gesture); @@ -170,7 +170,7 @@ protected: LLCheckBoxCtrl* mActiveCheck; LLButton* mSaveBtn; - LLButton* mPreviewBtn; + class LLFlyoutButton* mPreviewBtn; LLMultiGesture* mPreviewGesture; BOOL mDirty; diff --git a/indra/newview/skins/default/xui/en-us/floater_preview_gesture.xml b/indra/newview/skins/default/xui/en-us/floater_preview_gesture.xml index c17398f9d..c93bd8dae 100644 --- a/indra/newview/skins/default/xui/en-us/floater_preview_gesture.xml +++ b/indra/newview/skins/default/xui/en-us/floater_preview_gesture.xml @@ -101,8 +101,10 @@ unless you add wait steps. name="active_check" tool_tip="Active gestures can be triggered by chatting their trigger phrases or pressing their hot keys. Gestures usually become inactive when there is a key binding conflict." width="100" /> -