diff --git a/indra/newview/llenvironment.h b/indra/newview/llenvironment.h index a664513de8..49c2ba337e 100644 --- a/indra/newview/llenvironment.h +++ b/indra/newview/llenvironment.h @@ -259,6 +259,9 @@ public: void initialize(); bool isInitialized(); +// [RLVa:KB] - @setenv + virtual bool isTransition() { return false; } +// [/RLVa:KB] void clear(); @@ -318,6 +321,9 @@ public: virtual bool applyTimeDelta(const LLSettingsBase::Seconds& delta) override; virtual void animate() override; +// [RLVa:KB] - @setenv + bool isTransition() override { return true; } +// [/RLVa:KB] protected: LLSettingsSky::ptr_t mStartSky; @@ -327,6 +333,9 @@ public: }; DayInstance::ptr_t getSelectedEnvironmentInstance(); +// [RLVa:KB] - @setenv + DayInstance::ptr_t getCurrentEnvironmentInstance() { return mCurrentEnvironment; } +// [/RLVa:KB] DayInstance::ptr_t getSharedEnvironmentInstance(); protected: diff --git a/indra/newview/rlvactions.cpp b/indra/newview/rlvactions.cpp index 5fde3943e7..fd77515434 100644 --- a/indra/newview/rlvactions.cpp +++ b/indra/newview/rlvactions.cpp @@ -368,9 +368,11 @@ bool RlvActions::isLocalTp(const LLVector3d& posGlobal) // WindLight // -bool RlvActions::canChangeEnvironment() +bool RlvActions::canChangeEnvironment(const LLUUID& idRlvObject) { - return !gRlvHandler.hasBehaviour(RLV_BHVR_SETENV); + // User can (partially) change their environment settings if: + // - not specifically restricted from changing their environment (by any object other than the one specified) + return (idRlvObject.isNull()) ? !gRlvHandler.hasBehaviour(RLV_BHVR_SETENV) : !gRlvHandler.hasBehaviourExcept(RLV_BHVR_SETENV, idRlvObject); } // ============================================================================ diff --git a/indra/newview/rlvactions.h b/indra/newview/rlvactions.h index 060dc1a9c3..c1f2f46ec8 100644 --- a/indra/newview/rlvactions.h +++ b/indra/newview/rlvactions.h @@ -219,9 +219,9 @@ public: // ========= public: /* - * Returns true if the user can make changes to their WindLight environment + * Returns true if the user can make changes to their WindLight environment */ - static bool canChangeEnvironment(); + static bool canChangeEnvironment(const LLUUID& idRlvObject = LLUUID::null); // ================= diff --git a/indra/newview/rlvenvironment.cpp b/indra/newview/rlvenvironment.cpp index 91e043da23..5f70df750a 100644 --- a/indra/newview/rlvenvironment.cpp +++ b/indra/newview/rlvenvironment.cpp @@ -472,11 +472,42 @@ LLEnvironment::EnvSelection_t RlvEnvironment::getTargetEnvironment() return RlvActions::canChangeEnvironment() ? LLEnvironment::ENV_LOCAL : LLEnvironment::ENV_EDIT; } +// static +LLSettingsSky::ptr_t RlvEnvironment::getTargetSky(bool forSetCmd) +{ + LLEnvironment* pEnv = LLEnvironment::getInstance(); + + if (forSetCmd) + { + bool isSharedEnv = !pEnv->getEnvironmentFixedSky(LLEnvironment::ENV_LOCAL), + hasLocalDayCycle = !isSharedEnv && pEnv->getEnvironmentDay(LLEnvironment::ENV_LOCAL), + isLocalTransition = !hasLocalDayCycle && pEnv->getCurrentEnvironmentInstance()->isTransition(); + if ( (isSharedEnv) || (hasLocalDayCycle) || (isLocalTransition) ) + { + LLSettingsSky::ptr_t pSky = (isSharedEnv) ? pEnv->getEnvironmentFixedSky(LLEnvironment::ENV_PARCEL, true)->buildClone() + : (hasLocalDayCycle) ? pEnv->getEnvironmentFixedSky(LLEnvironment::ENV_LOCAL)->buildClone() + : pEnv->getEnvironmentFixedSky(LLEnvironment::ENV_LOCAL); + pEnv->setEnvironment(LLEnvironment::ENV_LOCAL, pSky); + pEnv->setSelectedEnvironment(LLEnvironment::ENV_LOCAL, LLEnvironment::TRANSITION_INSTANT); + pEnv->updateEnvironment(LLEnvironment::TRANSITION_INSTANT); + } + } + + return pEnv->getCurrentSky(); +} + + // static bool RlvEnvironment::onHandleCommand(const RlvCommand& rlvCmd, ERlvCmdRet& cmdRet, const std::string& strCmdPrefix, const handler_map_t& fnLookup, const legacy_handler_map_t& legacyFnLookup) { if ( (rlvCmd.getBehaviour().length() > strCmdPrefix.length() + 2) && (boost::starts_with(rlvCmd.getBehaviour(), strCmdPrefix)) ) { + if ( (RLV_TYPE_FORCE == rlvCmd.getParamType()) && (!RlvActions::canChangeEnvironment(rlvCmd.getObjectID())) ) + { + cmdRet = RLV_RET_FAILED_LOCK; + return true; + } + std::string strEnvCommand = rlvCmd.getBehaviour().substr(strCmdPrefix.length()); handler_map_t::const_iterator itFnEntry = fnLookup.find(strEnvCommand); @@ -517,21 +548,21 @@ bool RlvEnvironment::onForceCommand(const RlvCommand& rlvCmd, ERlvCmdRet& cmdRet template<> std::string RlvEnvironment::handleGetFn(const std::function& fn) { - LLSettingsSky::ptr_t pSky = LLEnvironment::instance().getCurrentSky(); + LLSettingsSky::ptr_t pSky = getTargetSky(); return std::to_string(fn(pSky)); } template<> std::string RlvEnvironment::handleGetFn(const std::function& fn) { - LLSettingsSky::ptr_t pSky = LLEnvironment::instance().getCurrentSky(); + LLSettingsSky::ptr_t pSky = getTargetSky(); return fn(pSky).asString(); } template<> std::string RlvEnvironment::handleGetFn(const std::function& fn) { - LLSettingsSky::ptr_t pSky = LLEnvironment::instance().getCurrentSky(); + LLSettingsSky::ptr_t pSky = getTargetSky(); LLVector2 replyVec = fn(pSky); return llformat("%f/%f", replyVec.mV[VX], replyVec.mV[VY]); } @@ -539,7 +570,7 @@ std::string RlvEnvironment::handleGetFn(const std::function std::string RlvEnvironment::handleGetFn(const std::function& fn) { - LLSettingsSky::ptr_t pSky = LLEnvironment::instance().getCurrentSky(); + LLSettingsSky::ptr_t pSky = getTargetSky(); LLColor3 replyColor = fn(pSky); return llformat("%f/%f/%f", replyColor.mV[VX], replyColor.mV[VY], replyColor.mV[VZ]); } @@ -551,7 +582,7 @@ ERlvCmdRet RlvEnvironment::handleSetFn(const std::string& strRlvOption, const st if (!RlvCommandOptionHelper::parseOption(strRlvOption, optionValue)) return RLV_RET_FAILED_PARAM; - LLSettingsSky::ptr_t pSky = LLEnvironment::instance().getCurrentSky(); + LLSettingsSky::ptr_t pSky = getTargetSky(true); fn(pSky, optionValue); pSky->update(); return RLV_RET_SUCCESS; @@ -562,7 +593,7 @@ std::string RlvEnvironment::handleLegacyGetFn(const std::function= 2) return LLStringUtil::null; - return std::to_string(getFn(LLEnvironment::instance().getCurrentSky()).mV[idxComponent]); + return std::to_string(getFn(getTargetSky()).mV[idxComponent]); } template<> @@ -570,11 +601,11 @@ std::string RlvEnvironment::handleLegacyGetFn(const std::function= VRED) && (idxComponent <= VBLUE) ) { - return std::to_string(getFn(LLEnvironment::instance().getCurrentSky()).mV[idxComponent]); + return std::to_string(getFn(getTargetSky()).mV[idxComponent]); } else if (idxComponent == VALPHA) { - const LLColor3& clr = getFn(LLEnvironment::instance().getCurrentSky()); + const LLColor3& clr = getFn(getTargetSky()); return std::to_string(llmax(clr.mV[VRED], clr.mV[VGREEN], clr.mV[VBLUE])); } return LLStringUtil::null; @@ -586,7 +617,7 @@ ERlvCmdRet RlvEnvironment::handleLegacySetFn(float optionValue, LLVec if (idxComponent >= 2) return RLV_RET_FAILED_UNKNOWN; - LLSettingsSky::ptr_t pSky = LLEnvironment::instance().getCurrentSky(); + LLSettingsSky::ptr_t pSky = getTargetSky(true); curValue.mV[idxComponent] = optionValue; setFn(pSky, curValue); pSky->update(); @@ -597,7 +628,7 @@ ERlvCmdRet RlvEnvironment::handleLegacySetFn(float optionValue, LLVec template<> ERlvCmdRet RlvEnvironment::handleLegacySetFn(float optionValue, LLColor3 curValue, const std::function& setFn, U32 idxComponent) { - LLSettingsSky::ptr_t pSky = LLEnvironment::instance().getCurrentSky(); + LLSettingsSky::ptr_t pSky = getTargetSky(true); if ( (idxComponent >= VRED) && (idxComponent <= VBLUE) ) { curValue.mV[idxComponent] = optionValue; @@ -691,7 +722,7 @@ void RlvEnvironment::registerLegacySkyFn(const std::string& strFnName, const std float optionValue; if (!RlvCommandOptionHelper::parseOption(strRlvOption, optionValue)) return RLV_RET_FAILED_PARAM; - return handleLegacySetFn(optionValue, getFn(LLEnvironment::instance().getCurrentSky()), setFn, idxComponent);; + return handleLegacySetFn(optionValue, getFn(getTargetSky(true)), setFn, idxComponent);; })); } diff --git a/indra/newview/rlvenvironment.h b/indra/newview/rlvenvironment.h index 2d19ab2341..146160ea79 100644 --- a/indra/newview/rlvenvironment.h +++ b/indra/newview/rlvenvironment.h @@ -34,6 +34,7 @@ public: bool onForceCommand(const RlvCommand& rlvCmd, ERlvCmdRet& cmdRet) override; protected: static LLEnvironment::EnvSelection_t getTargetEnvironment(); + static LLSettingsSky::ptr_t getTargetSky(bool forSetCmd = false); typedef std::map> handler_map_t; typedef std::map> legacy_handler_map_t; static bool onHandleCommand(const RlvCommand& rlvCmd, ERlvCmdRet& cmdRet, const std::string& strCmdPrefix, const handler_map_t& fnLookup, const legacy_handler_map_t& legacyFnLookup);