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

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llfloaterdaycycle.cpp
  3.  * @brief LLFloaterDayCycle 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 "llfloaterdaycycle.h"
  34. #include "pipeline.h"
  35. #include "llsky.h"
  36. #include "llsliderctrl.h"
  37. #include "llmultislider.h"
  38. #include "llmultisliderctrl.h"
  39. #include "llspinctrl.h"
  40. #include "llcheckboxctrl.h"
  41. #include "lluictrlfactory.h"
  42. #include "llviewercamera.h"
  43. #include "llcombobox.h"
  44. #include "lllineeditor.h"
  45. #include "llwlanimator.h"
  46. #include "v4math.h"
  47. #include "llviewerdisplay.h"
  48. #include "llviewercontrol.h"
  49. #include "llviewerwindow.h"
  50. #include "llwlparamset.h"
  51. #include "llwlparammanager.h"
  52. #include "llpostprocess.h"
  53. #include "llfloaterwindlight.h"
  54. std::map<std::string, LLWLSkyKey> LLFloaterDayCycle::sSliderToKey;
  55. const F32 LLFloaterDayCycle::sHoursPerDay = 24.0f;
  56. LLFloaterDayCycle::LLFloaterDayCycle(const LLSD& key)
  57. : LLFloater(key)
  58. {
  59. //LLUICtrlFactory::getInstance()->buildFloater(this, "floater_day_cycle_options.xml");
  60. }
  61. BOOL LLFloaterDayCycle::postBuild()
  62. {
  63. // add the combo boxes
  64. LLComboBox* keyCombo = getChild<LLComboBox>("WLKeyPresets");
  65. if(keyCombo != NULL) 
  66. {
  67. keyCombo->removeall();
  68. std::map<std::string, LLWLParamSet>::iterator mIt = 
  69. LLWLParamManager::instance()->mParamList.begin();
  70. for(; mIt != LLWLParamManager::instance()->mParamList.end(); mIt++) 
  71. {
  72. keyCombo->add(std::string(mIt->first));
  73. }
  74. // set defaults on combo boxes
  75. keyCombo->selectFirstItem();
  76. }
  77. // add the time slider
  78. LLMultiSliderCtrl* sldr = getChild<LLMultiSliderCtrl>("WLTimeSlider");
  79. sldr->addSlider();
  80. // load it up
  81. initCallbacks();
  82. syncMenu();
  83. syncSliderTrack();
  84. return TRUE;
  85. }
  86. LLFloaterDayCycle::~LLFloaterDayCycle()
  87. {
  88. }
  89. void LLFloaterDayCycle::initCallbacks(void) 
  90. {
  91. // WL Day Cycle
  92. getChild<LLUICtrl>("WLTimeSlider")->setCommitCallback(boost::bind(&LLFloaterDayCycle::onTimeSliderMoved, this, _1));
  93. getChild<LLUICtrl>("WLDayCycleKeys")->setCommitCallback(boost::bind(&LLFloaterDayCycle::onKeyTimeMoved, this, _1));
  94. getChild<LLUICtrl>("WLCurKeyHour")->setCommitCallback(boost::bind(&LLFloaterDayCycle::onKeyTimeChanged, this, _1));
  95. getChild<LLUICtrl>("WLCurKeyMin")->setCommitCallback(boost::bind(&LLFloaterDayCycle::onKeyTimeChanged, this, _1));
  96. getChild<LLUICtrl>("WLKeyPresets")->setCommitCallback(boost::bind(&LLFloaterDayCycle::onKeyPresetChanged, this, _1));
  97. getChild<LLUICtrl>("WLLengthOfDayHour")->setCommitCallback(boost::bind(&LLFloaterDayCycle::onTimeRateChanged, this, _1));
  98. getChild<LLUICtrl>("WLLengthOfDayMin")->setCommitCallback(boost::bind(&LLFloaterDayCycle::onTimeRateChanged, this, _1));
  99. getChild<LLUICtrl>("WLLengthOfDaySec")->setCommitCallback(boost::bind(&LLFloaterDayCycle::onTimeRateChanged, this, _1));
  100. getChild<LLUICtrl>("WLUseLindenTime")->setCommitCallback(boost::bind(&LLFloaterDayCycle::onUseLindenTime, this, _1));
  101. getChild<LLUICtrl>("WLAnimSky")->setCommitCallback(boost::bind(&LLFloaterDayCycle::onRunAnimSky, this, _1));
  102. getChild<LLUICtrl>("WLStopAnimSky")->setCommitCallback(boost::bind(&LLFloaterDayCycle::onStopAnimSky, this, _1));
  103. getChild<LLUICtrl>("WLLoadDayCycle")->setCommitCallback(boost::bind(&LLFloaterDayCycle::onLoadDayCycle, this, _1));
  104. getChild<LLUICtrl>("WLSaveDayCycle")->setCommitCallback(boost::bind(&LLFloaterDayCycle::onSaveDayCycle, this, _1));
  105. getChild<LLUICtrl>("WLAddKey")->setCommitCallback(boost::bind(&LLFloaterDayCycle::onAddKey, this, _1));
  106. getChild<LLUICtrl>("WLDeleteKey")->setCommitCallback(boost::bind(&LLFloaterDayCycle::onDeleteKey, this, _1));
  107. }
  108. void LLFloaterDayCycle::syncMenu()
  109. {
  110. // std::map<std::string, LLVector4> & currentParams = LLWLParamManager::instance()->mCurParams.mParamValues;
  111. // set time
  112. LLMultiSliderCtrl* sldr = getChild<LLMultiSliderCtrl>("WLTimeSlider");
  113. sldr->setCurSliderValue((F32)LLWLParamManager::instance()->mAnimator.getDayTime() * sHoursPerDay);
  114. LLSpinCtrl* secSpin = getChild<LLSpinCtrl>("WLLengthOfDaySec");
  115. LLSpinCtrl* minSpin = getChild<LLSpinCtrl>("WLLengthOfDayMin");
  116. LLSpinCtrl* hourSpin = getChild<LLSpinCtrl>("WLLengthOfDayHour");
  117. F32 curRate;
  118. F32 hours, min, sec;
  119. // get the current rate
  120. curRate = LLWLParamManager::instance()->mDay.mDayRate;
  121. hours = (F32)((int)(curRate / 60 / 60));
  122. curRate -= (hours * 60 * 60);
  123. min = (F32)((int)(curRate / 60));
  124. curRate -= (min * 60);
  125. sec = curRate;
  126. hourSpin->setValue(hours);
  127. minSpin->setValue(min);
  128. secSpin->setValue(sec);
  129. // turn off Use Estate Time button if it's already being used
  130. if( LLWLParamManager::instance()->mAnimator.mUseLindenTime == true)
  131. {
  132. childDisable("WLUseLindenTime");
  133. else 
  134. {
  135. childEnable("WLUseLindenTime");
  136. }
  137. }
  138. void LLFloaterDayCycle::syncSliderTrack()
  139. {
  140. // clear the slider
  141. LLMultiSliderCtrl* kSldr = getChild<LLMultiSliderCtrl>("WLDayCycleKeys");
  142. kSldr->clear();
  143. sSliderToKey.clear();
  144. // add sliders
  145. std::map<F32, std::string>::iterator mIt = 
  146. LLWLParamManager::instance()->mDay.mTimeMap.begin();
  147. for(; mIt != LLWLParamManager::instance()->mDay.mTimeMap.end(); mIt++) 
  148. {
  149. addSliderKey(mIt->first * sHoursPerDay, mIt->second);
  150. }
  151. }
  152. void LLFloaterDayCycle::syncTrack()
  153. {
  154. // if no keys, do nothing
  155. if(sSliderToKey.size() == 0) 
  156. {
  157. return;
  158. }
  159. LLMultiSliderCtrl* sldr;
  160. sldr = getChild<LLMultiSliderCtrl>( 
  161. "WLDayCycleKeys");
  162. llassert_always(sSliderToKey.size() == sldr->getValue().size());
  163. LLMultiSliderCtrl* tSldr;
  164. tSldr = getChild<LLMultiSliderCtrl>( 
  165. "WLTimeSlider");
  166. // create a new animation track
  167. LLWLParamManager::instance()->mDay.clearKeys();
  168. // add the keys one by one
  169. std::map<std::string, LLWLSkyKey>::iterator mIt = sSliderToKey.begin();
  170. for(; mIt != sSliderToKey.end(); mIt++) 
  171. {
  172. LLWLParamManager::instance()->mDay.addKey(mIt->second.time / sHoursPerDay, 
  173. mIt->second.presetName);
  174. }
  175. // set the param manager's track to the new one
  176. LLWLParamManager::instance()->resetAnimator(
  177. tSldr->getCurSliderValue() / sHoursPerDay, false);
  178. LLWLParamManager::instance()->mAnimator.update(
  179. LLWLParamManager::instance()->mCurParams);
  180. }
  181. void LLFloaterDayCycle::onRunAnimSky(LLUICtrl* ctrl)
  182. {
  183. // if no keys, do nothing
  184. if(sSliderToKey.size() == 0) 
  185. {
  186. return;
  187. }
  188. LLMultiSliderCtrl* sldr;
  189. sldr = getChild<LLMultiSliderCtrl>("WLDayCycleKeys");
  190. llassert_always(sSliderToKey.size() == sldr->getValue().size());
  191. LLMultiSliderCtrl* tSldr;
  192. tSldr = getChild<LLMultiSliderCtrl>("WLTimeSlider");
  193. // turn off linden time
  194. LLWLParamManager::instance()->mAnimator.mUseLindenTime = false;
  195. // set the param manager's track to the new one
  196. LLWLParamManager::instance()->resetAnimator(
  197. tSldr->getCurSliderValue() / sHoursPerDay, true);
  198. llassert_always(LLWLParamManager::instance()->mAnimator.mTimeTrack.size() == sldr->getValue().size());
  199. }
  200. void LLFloaterDayCycle::onStopAnimSky(LLUICtrl* ctrl)
  201. {
  202. // if no keys, do nothing
  203. if(sSliderToKey.size() == 0) {
  204. return;
  205. }
  206. // turn off animation and using linden time
  207. LLWLParamManager::instance()->mAnimator.mIsRunning = false;
  208. LLWLParamManager::instance()->mAnimator.mUseLindenTime = false;
  209. }
  210. void LLFloaterDayCycle::onUseLindenTime(LLUICtrl* ctrl)
  211. {
  212. LLComboBox* box = getChild<LLComboBox>("WLPresetsCombo");
  213. box->selectByValue("");
  214. LLWLParamManager::instance()->mAnimator.mIsRunning = true;
  215. LLWLParamManager::instance()->mAnimator.mUseLindenTime = true;
  216. }
  217. void LLFloaterDayCycle::onLoadDayCycle(LLUICtrl* ctrl)
  218. {
  219. LLWLParamManager::instance()->mDay.loadDayCycle("Default.xml");
  220. // sync it all up
  221. syncSliderTrack();
  222. syncMenu();
  223. // set the param manager's track to the new one
  224. LLMultiSliderCtrl* tSldr;
  225. tSldr = getChild<LLMultiSliderCtrl>( 
  226. "WLTimeSlider");
  227. LLWLParamManager::instance()->resetAnimator(
  228. tSldr->getCurSliderValue() / sHoursPerDay, false);
  229. // and draw it
  230. LLWLParamManager::instance()->mAnimator.update(
  231. LLWLParamManager::instance()->mCurParams);
  232. }
  233. void LLFloaterDayCycle::onSaveDayCycle(LLUICtrl* ctrl)
  234. {
  235. LLWLParamManager::instance()->mDay.saveDayCycle("Default.xml");
  236. }
  237. void LLFloaterDayCycle::onTimeSliderMoved(LLUICtrl* ctrl)
  238. {
  239. LLMultiSliderCtrl* sldr = getChild<LLMultiSliderCtrl>( 
  240. "WLTimeSlider");
  241. /// get the slider value
  242. F32 val = sldr->getCurSliderValue() / sHoursPerDay;
  243. // set the value, turn off animation
  244. LLWLParamManager::instance()->mAnimator.setDayTime((F64)val);
  245. LLWLParamManager::instance()->mAnimator.mIsRunning = false;
  246. LLWLParamManager::instance()->mAnimator.mUseLindenTime = false;
  247. // then call update once
  248. LLWLParamManager::instance()->mAnimator.update(
  249. LLWLParamManager::instance()->mCurParams);
  250. }
  251. void LLFloaterDayCycle::onKeyTimeMoved(LLUICtrl* ctrl)
  252. {
  253. LLComboBox* comboBox = getChild<LLComboBox>("WLKeyPresets");
  254. LLMultiSliderCtrl* sldr = getChild<LLMultiSliderCtrl>("WLDayCycleKeys");
  255. LLSpinCtrl* hourSpin = getChild<LLSpinCtrl>("WLCurKeyHour");
  256. LLSpinCtrl* minSpin = getChild<LLSpinCtrl>("WLCurKeyMin");
  257. if(sldr->getValue().size() == 0) {
  258. return;
  259. }
  260. // make sure we have a slider
  261. const std::string& curSldr = sldr->getCurSlider();
  262. if(curSldr == "") {
  263. return;
  264. }
  265. F32 time = sldr->getCurSliderValue();
  266. // check to see if a key exists
  267. std::string presetName = sSliderToKey[curSldr].presetName;
  268. sSliderToKey[curSldr].time = time;
  269. // if it exists, turn on check box
  270. comboBox->selectByValue(presetName);
  271. // now set the spinners
  272. F32 hour = (F32)((S32)time);
  273. F32 min = (time - hour) * 60;
  274. // handle imprecision
  275. if(min >= 59) {
  276. min = 0;
  277. hour += 1;
  278. }
  279. hourSpin->set(hour);
  280. minSpin->set(min);
  281. syncTrack();
  282. }
  283. void LLFloaterDayCycle::onKeyTimeChanged(LLUICtrl* ctrl)
  284. {
  285. // if no keys, skipped
  286. if(sSliderToKey.size() == 0) {
  287. return;
  288. }
  289. LLMultiSliderCtrl* sldr = getChild<LLMultiSliderCtrl>( 
  290. "WLDayCycleKeys");
  291. LLSpinCtrl* hourSpin = getChild<LLSpinCtrl>( 
  292. "WLCurKeyHour");
  293. LLSpinCtrl* minSpin = getChild<LLSpinCtrl>( 
  294. "WLCurKeyMin");
  295. F32 hour = hourSpin->get();
  296. F32 min = minSpin->get();
  297. F32 val = hour + min / 60.0f;
  298. const std::string& curSldr = sldr->getCurSlider();
  299. sldr->setCurSliderValue(val, TRUE);
  300. F32 time = sldr->getCurSliderValue() / sHoursPerDay;
  301. // now set the key's time in the sliderToKey map
  302. std::string presetName = sSliderToKey[curSldr].presetName;
  303. sSliderToKey[curSldr].time = time;
  304. syncTrack();
  305. }
  306. void LLFloaterDayCycle::onKeyPresetChanged(LLUICtrl* ctrl)
  307. {
  308. // get the time
  309. LLComboBox* comboBox = getChild<LLComboBox>( 
  310. "WLKeyPresets");
  311. LLMultiSliderCtrl* sldr = getChild<LLMultiSliderCtrl>( 
  312. "WLDayCycleKeys");
  313. // do nothing if no sliders
  314. if(sldr->getValue().size() == 0) {
  315. return;
  316. }
  317. // change the map
  318. std::string newPreset(comboBox->getSelectedValue().asString());
  319. const std::string& curSldr = sldr->getCurSlider();
  320. // if null, don't use
  321. if(curSldr == "") {
  322. return;
  323. }
  324. sSliderToKey[curSldr].presetName = newPreset;
  325. syncTrack();
  326. }
  327. void LLFloaterDayCycle::onTimeRateChanged(LLUICtrl* ctrl)
  328. {
  329. // get the time
  330. LLSpinCtrl* secSpin = getChild<LLSpinCtrl>( 
  331. "WLLengthOfDaySec");
  332. LLSpinCtrl* minSpin = getChild<LLSpinCtrl>( 
  333. "WLLengthOfDayMin");
  334. LLSpinCtrl* hourSpin = getChild<LLSpinCtrl>( 
  335. "WLLengthOfDayHour");
  336. F32 hour;
  337. hour = (F32)hourSpin->getValue().asReal();
  338. F32 min;
  339. min = (F32)minSpin->getValue().asReal();
  340. F32 sec;
  341. sec = (F32)secSpin->getValue().asReal();
  342. F32 time = 60.0f * 60.0f * hour + 60.0f * min + sec;
  343. if(time <= 0) {
  344. time = 1;
  345. }
  346. LLWLParamManager::instance()->mDay.mDayRate = time;
  347. syncTrack();
  348. }
  349. void LLFloaterDayCycle::onAddKey(LLUICtrl* ctrl)
  350. {
  351. LLComboBox* comboBox = getChild<LLComboBox>( 
  352. "WLKeyPresets");
  353. LLMultiSliderCtrl* kSldr = getChild<LLMultiSliderCtrl>( 
  354. "WLDayCycleKeys");
  355. LLMultiSliderCtrl* tSldr = getChild<LLMultiSliderCtrl>( 
  356. "WLTimeSlider");
  357. llassert_always(sSliderToKey.size() == kSldr->getValue().size());
  358. // get the values
  359. std::string newPreset(comboBox->getSelectedValue().asString());
  360. // add the slider key
  361. addSliderKey(tSldr->getCurSliderValue(), newPreset);
  362. syncTrack();
  363. }
  364. void LLFloaterDayCycle::addSliderKey(F32 time, const std::string & presetName)
  365. {
  366. LLMultiSliderCtrl* kSldr = getChild<LLMultiSliderCtrl>( 
  367. "WLDayCycleKeys");
  368. // make a slider
  369. const std::string& sldrName = kSldr->addSlider(time);
  370. if(sldrName == "") {
  371. return;
  372. }
  373. // set the key
  374. LLWLSkyKey newKey;
  375. newKey.presetName = presetName;
  376. newKey.time = kSldr->getCurSliderValue();
  377. llassert_always(sldrName != LLStringUtil::null);
  378. // add to map
  379. sSliderToKey.insert(std::pair<std::string, LLWLSkyKey>(sldrName, newKey));
  380. llassert_always(sSliderToKey.size() == kSldr->getValue().size());
  381. }
  382. void LLFloaterDayCycle::deletePreset(std::string& presetName)
  383. {
  384. LLMultiSliderCtrl* sldr = getChild<LLMultiSliderCtrl>("WLDayCycleKeys");
  385. /// delete any reference
  386. std::map<std::string, LLWLSkyKey>::iterator curr_preset, next_preset;
  387. for(curr_preset = sSliderToKey.begin(); curr_preset != sSliderToKey.end(); curr_preset = next_preset)
  388. {
  389. next_preset = curr_preset;
  390. ++next_preset;
  391. if (curr_preset->second.presetName == presetName)
  392. {
  393. sldr->deleteSlider(curr_preset->first);
  394. sSliderToKey.erase(curr_preset);
  395. }
  396. }
  397. }
  398. void LLFloaterDayCycle::onDeleteKey(LLUICtrl* ctrl)
  399. {
  400. if(sSliderToKey.size() == 0) {
  401. return;
  402. }
  403. LLComboBox* comboBox = getChild<LLComboBox>( 
  404. "WLKeyPresets");
  405. LLMultiSliderCtrl* sldr = getChild<LLMultiSliderCtrl>("WLDayCycleKeys");
  406. // delete from map
  407. const std::string& sldrName = sldr->getCurSlider();
  408. std::map<std::string, LLWLSkyKey>::iterator mIt = sSliderToKey.find(sldrName);
  409. sSliderToKey.erase(mIt);
  410. sldr->deleteCurSlider();
  411. if(sSliderToKey.size() == 0) {
  412. return;
  413. }
  414. const std::string& name = sldr->getCurSlider();
  415. comboBox->selectByValue(sSliderToKey[name].presetName);
  416. F32 time = sSliderToKey[name].time;
  417. LLSpinCtrl* hourSpin = getChild<LLSpinCtrl>("WLCurKeyHour");
  418. LLSpinCtrl* minSpin = getChild<LLSpinCtrl>("WLCurKeyMin");
  419. // now set the spinners
  420. F32 hour = (F32)((S32)time);
  421. F32 min = (time - hour) / 60;
  422. hourSpin->set(hour);
  423. minSpin->set(min);
  424. syncTrack();
  425. }