llfloaterenvsettings.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:8k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llfloaterenvsettings.cpp
  3.  * @brief LLFloaterEnvSettings class definition
  4.  *
  5.  * $LicenseInfo:firstyear=2007&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2007-2010, Linden Research, Inc.
  8.  * 
  9.  * Second Life Viewer Source Code
  10.  * The source code in this file ("Source Code") is provided by Linden Lab
  11.  * to you under the terms of the GNU General Public License, version 2.0
  12.  * ("GPL"), unless you have obtained a separate licensing agreement
  13.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  14.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16.  * 
  17.  * There are special exceptions to the terms and conditions of the GPL as
  18.  * it is applied to this Source Code. View the full text of the exception
  19.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  20.  * online at
  21.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22.  * 
  23.  * By copying, modifying or distributing this software, you acknowledge
  24.  * that you have read and understood your obligations described above,
  25.  * and agree to abide by those obligations.
  26.  * 
  27.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29.  * COMPLETENESS OR PERFORMANCE.
  30.  * $/LicenseInfo$
  31.  */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llfloaterenvsettings.h"
  34. #include "llfloaterreg.h"
  35. #include "llfloaterwindlight.h"
  36. #include "llfloaterwater.h"
  37. #include "lluictrlfactory.h"
  38. #include "llsliderctrl.h"
  39. #include "llcombobox.h"
  40. #include "llcolorswatch.h"
  41. #include "llwlanimator.h"
  42. #include "llwlparamset.h"
  43. #include "llwlparammanager.h"
  44. #include "llwaterparammanager.h"
  45. #include "llmath.h"
  46. #include "llviewerwindow.h"
  47. #include "pipeline.h"
  48. #include <sstream>
  49. LLFloaterEnvSettings::LLFloaterEnvSettings(const LLSD& key)
  50.   : LLFloater(key)
  51. {
  52. //LLUICtrlFactory::getInstance()->buildFloater(this, "floater_env_settings.xml");
  53. }
  54. // virtual
  55. LLFloaterEnvSettings::~LLFloaterEnvSettings()
  56. {
  57. }
  58. // virtual
  59. BOOL LLFloaterEnvSettings::postBuild()
  60. {
  61. // load it up
  62. initCallbacks();
  63. syncMenu();
  64. return TRUE;
  65. }
  66. void LLFloaterEnvSettings::initCallbacks(void) 
  67. {
  68. // our three sliders
  69. getChild<LLUICtrl>("EnvTimeSlider")->setCommitCallback(boost::bind(&LLFloaterEnvSettings::onChangeDayTime, this, _1));
  70. getChild<LLUICtrl>("EnvCloudSlider")->setCommitCallback(boost::bind(&LLFloaterEnvSettings::onChangeCloudCoverage, this, _1));
  71. getChild<LLUICtrl>("EnvWaterFogSlider")->setCommitCallback(boost::bind(&LLFloaterEnvSettings::onChangeWaterFogDensity, this, _1, &LLWaterParamManager::instance()->mFogDensity));
  72. // color picker
  73. getChild<LLUICtrl>("EnvWaterColor")->setCommitCallback(boost::bind(&LLFloaterEnvSettings::onChangeWaterColor, this, _1, &LLWaterParamManager::instance()->mFogColor));
  74. // WL Top
  75. getChild<LLUICtrl>("EnvAdvancedSkyButton")->setCommitCallback(boost::bind(&LLFloaterEnvSettings::onOpenAdvancedSky, this));
  76.   getChild<LLUICtrl>("EnvAdvancedWaterButton")->setCommitCallback(boost::bind(&LLFloaterEnvSettings::onOpenAdvancedWater, this));
  77. getChild<LLUICtrl>("EnvUseEstateTimeButton")->setCommitCallback(boost::bind(&LLFloaterEnvSettings::onUseEstateTime, this));
  78. }
  79. // menu maintenance functions
  80. void LLFloaterEnvSettings::syncMenu()
  81. {
  82. LLSliderCtrl* sldr;
  83. sldr = getChild<LLSliderCtrl>("EnvTimeSlider");
  84. // sync the clock
  85. F32 val = (F32)LLWLParamManager::instance()->mAnimator.getDayTime();
  86. std::string timeStr = timeToString(val);
  87. LLTextBox* textBox;
  88. textBox = getChild<LLTextBox>("EnvTimeText");
  89. textBox->setValue(timeStr);
  90. // sync time slider which starts at 6 AM
  91. val -= 0.25;
  92. if(val < 0) 
  93. {
  94. val++;
  95. }
  96. sldr->setValue(val);
  97. // sync cloud coverage
  98. bool err;
  99. childSetValue("EnvCloudSlider", LLWLParamManager::instance()->mCurParams.getFloat("cloud_shadow", err));
  100. LLWaterParamManager * param_mgr = LLWaterParamManager::instance();
  101. // sync water params
  102. LLColor4 col = param_mgr->getFogColor();
  103. LLColorSwatchCtrl* colCtrl = getChild<LLColorSwatchCtrl>("EnvWaterColor");
  104. col.mV[3] = 1.0f;
  105. colCtrl->set(col);
  106. childSetValue("EnvWaterFogSlider", param_mgr->mFogDensity.mExp);
  107. param_mgr->setDensitySliderValue(param_mgr->mFogDensity.mExp);
  108. // turn off Use Estate Time button if it's already being used
  109. if(LLWLParamManager::instance()->mAnimator.mUseLindenTime)
  110. {
  111. childDisable("EnvUseEstateTimeButton");
  112. } else {
  113. childEnable("EnvUseEstateTimeButton");
  114. }
  115. if(!gPipeline.canUseVertexShaders())
  116. {
  117. childDisable("EnvWaterColor");
  118. childDisable("EnvWaterColorText");
  119. //childDisable("EnvAdvancedWaterButton");
  120. }
  121. else
  122. {
  123. childEnable("EnvWaterColor");
  124. childEnable("EnvWaterColorText");
  125. //childEnable("EnvAdvancedWaterButton");
  126. }
  127. // only allow access to these if they are using windlight
  128. if(!gPipeline.canUseWindLightShaders())
  129. {
  130. childDisable("EnvCloudSlider");
  131. childDisable("EnvCloudText");
  132. //childDisable("EnvAdvancedSkyButton");
  133. }
  134. else
  135. {
  136. childEnable("EnvCloudSlider");
  137. childEnable("EnvCloudText");
  138. //childEnable("EnvAdvancedSkyButton");
  139. }
  140. }
  141. void LLFloaterEnvSettings::onChangeDayTime(LLUICtrl* ctrl)
  142. {
  143. LLSliderCtrl* sldr = static_cast<LLSliderCtrl*>(ctrl);
  144. // deactivate animator
  145. LLWLParamManager::instance()->mAnimator.mIsRunning = false;
  146. LLWLParamManager::instance()->mAnimator.mUseLindenTime = false;
  147. F32 val = sldr->getValueF32() + 0.25f;
  148. if(val > 1.0) 
  149. {
  150. val--;
  151. }
  152. LLWLParamManager::instance()->mAnimator.setDayTime((F64)val);
  153. LLWLParamManager::instance()->mAnimator.update(
  154. LLWLParamManager::instance()->mCurParams);
  155. }
  156. void LLFloaterEnvSettings::onChangeCloudCoverage(LLUICtrl* ctrl)
  157. {
  158. LLSliderCtrl* sldr = static_cast<LLSliderCtrl*>(ctrl);
  159. // deactivate animator
  160. //LLWLParamManager::instance()->mAnimator.mIsRunning = false;
  161. //LLWLParamManager::instance()->mAnimator.mUseLindenTime = false;
  162. F32 val = sldr->getValueF32();
  163. LLWLParamManager::instance()->mCurParams.set("cloud_shadow", val);
  164. }
  165. void LLFloaterEnvSettings::onChangeWaterFogDensity(LLUICtrl* ctrl, WaterExpFloatControl* expFloatControl)
  166. {
  167. LLSliderCtrl* sldr;
  168. sldr = getChild<LLSliderCtrl>("EnvWaterFogSlider");
  169. F32 val = sldr->getValueF32();
  170. expFloatControl->mExp = val;
  171. LLWaterParamManager::instance()->setDensitySliderValue(val);
  172. expFloatControl->update(LLWaterParamManager::instance()->mCurParams);
  173. LLWaterParamManager::instance()->propagateParameters();
  174. }
  175. void LLFloaterEnvSettings::onChangeWaterColor(LLUICtrl* ctrl, WaterColorControl* colorControl)
  176. {
  177. LLColorSwatchCtrl* swatch = static_cast<LLColorSwatchCtrl*>(ctrl);
  178. *colorControl = swatch->get();
  179. colorControl->update(LLWaterParamManager::instance()->mCurParams);
  180. LLWaterParamManager::instance()->propagateParameters();
  181. }
  182. void LLFloaterEnvSettings::onOpenAdvancedSky()
  183. {
  184. LLFloaterReg::showInstance("env_windlight");
  185. }
  186. void LLFloaterEnvSettings::onOpenAdvancedWater()
  187. {
  188. LLFloaterReg::showInstance("env_water");
  189. }
  190. void LLFloaterEnvSettings::onUseEstateTime()
  191. {
  192. LLFloaterWindLight* wl = LLFloaterReg::findTypedInstance<LLFloaterWindLight>("env_windlight");
  193. if(wl)
  194. {
  195. LLComboBox* box = wl->getChild<LLComboBox>("WLPresetsCombo");
  196. box->selectByValue("");
  197. }
  198. LLWLParamManager::instance()->mAnimator.mIsRunning = true;
  199. LLWLParamManager::instance()->mAnimator.mUseLindenTime = true;
  200. }
  201. std::string LLFloaterEnvSettings::timeToString(F32 curTime)
  202. {
  203. S32 hours;
  204. S32 min;
  205. // get hours and minutes
  206. hours = (S32) (24.0 * curTime);
  207. curTime -= ((F32) hours / 24.0f);
  208. min = llround(24.0f * 60.0f * curTime);
  209. // handle case where it's 60
  210. if(min == 60) 
  211. {
  212. hours++;
  213. min = 0;
  214. }
  215. std::string newTime = getString("timeStr");
  216. struct tm * timeT;
  217. time_t secT = time(0);
  218. timeT = gmtime (&secT);
  219. timeT->tm_hour = hours;
  220. timeT->tm_min = min;
  221. secT = mktime (timeT);
  222. secT -= LLStringOps::getLocalTimeOffset ();
  223. LLSD substitution;
  224. substitution["datetime"] = (S32) secT;
  225. LLStringUtil::format (newTime, substitution);
  226. return newTime;
  227. }