PageRenderTime 45ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llfloatereditdaycycle.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 825 lines | 575 code | 155 blank | 95 comment | 78 complexity | c080fcd7edffb8e353e2294abcd8be4e MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llfloatereditdaycycle.cpp
  3. * @brief Floater to create or edit a day cycle
  4. *
  5. * $LicenseInfo:firstyear=2011&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2011, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "llviewerprecompiledheaders.h"
  27. #include "llfloatereditdaycycle.h"
  28. // libs
  29. #include "llbutton.h"
  30. #include "llcheckboxctrl.h"
  31. #include "llcombobox.h"
  32. #include "llloadingindicator.h"
  33. #include "llmultisliderctrl.h"
  34. #include "llnotifications.h"
  35. #include "llnotificationsutil.h"
  36. #include "llspinctrl.h"
  37. #include "lltimectrl.h"
  38. // newview
  39. #include "llagent.h"
  40. #include "lldaycyclemanager.h"
  41. #include "llenvmanager.h"
  42. #include "llregioninfomodel.h"
  43. #include "llviewerregion.h"
  44. #include "llwlparammanager.h"
  45. const F32 LLFloaterEditDayCycle::sHoursPerDay = 24.0f;
  46. LLFloaterEditDayCycle::LLFloaterEditDayCycle(const LLSD &key)
  47. : LLFloater(key)
  48. , mDayCycleNameEditor(NULL)
  49. , mDayCyclesCombo(NULL)
  50. , mTimeSlider(NULL)
  51. , mKeysSlider(NULL)
  52. , mSkyPresetsCombo(NULL)
  53. , mTimeCtrl(NULL)
  54. , mMakeDefaultCheckBox(NULL)
  55. , mSaveButton(NULL)
  56. {
  57. }
  58. // virtual
  59. BOOL LLFloaterEditDayCycle::postBuild()
  60. {
  61. mDayCycleNameEditor = getChild<LLLineEditor>("day_cycle_name");
  62. mDayCyclesCombo = getChild<LLComboBox>("day_cycle_combo");
  63. mTimeSlider = getChild<LLMultiSliderCtrl>("WLTimeSlider");
  64. mKeysSlider = getChild<LLMultiSliderCtrl>("WLDayCycleKeys");
  65. mSkyPresetsCombo = getChild<LLComboBox>("WLSkyPresets");
  66. mTimeCtrl = getChild<LLTimeCtrl>("time");
  67. mSaveButton = getChild<LLButton>("save");
  68. mMakeDefaultCheckBox = getChild<LLCheckBoxCtrl>("make_default_cb");
  69. initCallbacks();
  70. // add the time slider
  71. mTimeSlider->addSlider();
  72. return TRUE;
  73. }
  74. // virtual
  75. void LLFloaterEditDayCycle::onOpen(const LLSD& key)
  76. {
  77. bool new_day = isNewDay();
  78. std::string param = key.asString();
  79. std::string floater_title = getString(std::string("title_") + param);
  80. std::string hint = getString(std::string("hint_" + param));
  81. // Update floater title.
  82. setTitle(floater_title);
  83. // Update the hint at the top.
  84. getChild<LLUICtrl>("hint")->setValue(hint);
  85. // Hide the hint to the right of the combo if we're invoked to create a new preset.
  86. getChildView("note")->setVisible(!new_day);
  87. // Switch between the day cycle presets combobox and day cycle name input field.
  88. mDayCyclesCombo->setVisible(!new_day);
  89. mDayCycleNameEditor->setVisible(new_day);
  90. // TODO: Make sure only one instance of the floater exists?
  91. reset();
  92. }
  93. // virtual
  94. void LLFloaterEditDayCycle::onClose(bool app_quitting)
  95. {
  96. if (!app_quitting) // there's no point to change environment if we're quitting
  97. {
  98. LLEnvManagerNew::instance().usePrefs(); // revert changes made to current day cycle
  99. }
  100. }
  101. // virtual
  102. void LLFloaterEditDayCycle::draw()
  103. {
  104. syncTimeSlider();
  105. LLFloater::draw();
  106. }
  107. void LLFloaterEditDayCycle::initCallbacks(void)
  108. {
  109. mDayCycleNameEditor->setKeystrokeCallback(boost::bind(&LLFloaterEditDayCycle::onDayCycleNameEdited, this), NULL);
  110. mDayCyclesCombo->setCommitCallback(boost::bind(&LLFloaterEditDayCycle::onDayCycleSelected, this));
  111. mDayCyclesCombo->setTextEntryCallback(boost::bind(&LLFloaterEditDayCycle::onDayCycleNameEdited, this));
  112. mTimeSlider->setCommitCallback(boost::bind(&LLFloaterEditDayCycle::onTimeSliderMoved, this));
  113. mKeysSlider->setCommitCallback(boost::bind(&LLFloaterEditDayCycle::onKeyTimeMoved, this));
  114. mTimeCtrl->setCommitCallback(boost::bind(&LLFloaterEditDayCycle::onKeyTimeChanged, this));
  115. mSkyPresetsCombo->setCommitCallback(boost::bind(&LLFloaterEditDayCycle::onKeyPresetChanged, this));
  116. getChild<LLButton>("WLAddKey")->setClickedCallback(boost::bind(&LLFloaterEditDayCycle::onAddKey, this));
  117. getChild<LLButton>("WLDeleteKey")->setClickedCallback(boost::bind(&LLFloaterEditDayCycle::onDeleteKey, this));
  118. mSaveButton->setCommitCallback(boost::bind(&LLFloaterEditDayCycle::onBtnSave, this));
  119. mSaveButton->setRightMouseDownCallback(boost::bind(&LLFloaterEditDayCycle::dumpTrack, this));
  120. getChild<LLButton>("cancel")->setCommitCallback(boost::bind(&LLFloaterEditDayCycle::onBtnCancel, this));
  121. // Connect to env manager events.
  122. LLEnvManagerNew& env_mgr = LLEnvManagerNew::instance();
  123. env_mgr.setRegionSettingsChangeCallback(boost::bind(&LLFloaterEditDayCycle::onRegionSettingsChange, this));
  124. env_mgr.setRegionChangeCallback(boost::bind(&LLFloaterEditDayCycle::onRegionChange, this));
  125. env_mgr.setRegionSettingsAppliedCallback(boost::bind(&LLFloaterEditDayCycle::onRegionSettingsApplied, this, _1));
  126. // Connect to day cycle manager events.
  127. LLDayCycleManager::instance().setModifyCallback(boost::bind(&LLFloaterEditDayCycle::onDayCycleListChange, this));
  128. // Connect to sky preset list changes.
  129. LLWLParamManager::instance().setPresetListChangeCallback(boost::bind(&LLFloaterEditDayCycle::onSkyPresetListChange, this));
  130. // Connect to region info updates.
  131. LLRegionInfoModel::instance().setUpdateCallback(boost::bind(&LLFloaterEditDayCycle::onRegionInfoUpdate, this));
  132. }
  133. void LLFloaterEditDayCycle::syncTimeSlider()
  134. {
  135. // set time
  136. mTimeSlider->setCurSliderValue((F32)LLWLParamManager::getInstance()->mAnimator.getDayTime() * sHoursPerDay);
  137. }
  138. void LLFloaterEditDayCycle::loadTrack()
  139. {
  140. // clear the slider
  141. mKeysSlider->clear();
  142. mSliderToKey.clear();
  143. // add sliders
  144. lldebugs << "Adding " << LLWLParamManager::getInstance()->mDay.mTimeMap.size() << " keys to slider" << llendl;
  145. LLWLDayCycle& cur_dayp = LLWLParamManager::instance().mDay;
  146. for (std::map<F32, LLWLParamKey>::iterator it = cur_dayp.mTimeMap.begin(); it != cur_dayp.mTimeMap.end(); ++it)
  147. {
  148. addSliderKey(it->first * sHoursPerDay, it->second);
  149. }
  150. // set drop-down menu to match preset of currently-selected keyframe (one is automatically selected initially)
  151. const std::string& cur_sldr = mKeysSlider->getCurSlider();
  152. if (strlen(cur_sldr.c_str()) > 0) // only do this if there is a curSldr, otherwise we put an invalid entry into the map
  153. {
  154. mSkyPresetsCombo->selectByValue(mSliderToKey[cur_sldr].keyframe.toStringVal());
  155. }
  156. syncTimeSlider();
  157. }
  158. void LLFloaterEditDayCycle::applyTrack()
  159. {
  160. lldebugs << "Applying track (" << mSliderToKey.size() << ")" << llendl;
  161. // if no keys, do nothing
  162. if (mSliderToKey.size() == 0)
  163. {
  164. lldebugs << "No keys, not syncing" << llendl;
  165. return;
  166. }
  167. llassert_always(mSliderToKey.size() == mKeysSlider->getValue().size());
  168. // create a new animation track
  169. LLWLParamManager::getInstance()->mDay.clearKeyframes();
  170. // add the keys one by one
  171. for (std::map<std::string, SliderKey>::iterator it = mSliderToKey.begin();
  172. it != mSliderToKey.end(); ++it)
  173. {
  174. LLWLParamManager::getInstance()->mDay.addKeyframe(it->second.time / sHoursPerDay,
  175. it->second.keyframe);
  176. }
  177. // set the param manager's track to the new one
  178. LLWLParamManager::getInstance()->resetAnimator(
  179. mTimeSlider->getCurSliderValue() / sHoursPerDay, false);
  180. LLWLParamManager::getInstance()->mAnimator.update(
  181. LLWLParamManager::getInstance()->mCurParams);
  182. }
  183. void LLFloaterEditDayCycle::refreshSkyPresetsList()
  184. {
  185. // Don't allow selecting region skies for a local day cycle,
  186. // because thus we may end up with invalid day cycle.
  187. bool include_region_skies = getSelectedDayCycle().scope == LLEnvKey::SCOPE_REGION;
  188. mSkyPresetsCombo->removeall();
  189. LLWLParamManager::preset_name_list_t region_presets;
  190. LLWLParamManager::preset_name_list_t user_presets, sys_presets;
  191. LLWLParamManager::instance().getPresetNames(region_presets, user_presets, sys_presets);
  192. if (include_region_skies)
  193. {
  194. // Add region presets.
  195. for (LLWLParamManager::preset_name_list_t::const_iterator it = region_presets.begin(); it != region_presets.end(); ++it)
  196. {
  197. std::string preset_name = *it;
  198. std::string item_title = preset_name + " (" + getRegionName() + ")";
  199. mSkyPresetsCombo->add(preset_name, LLWLParamKey(*it, LLEnvKey::SCOPE_REGION).toStringVal());
  200. }
  201. if (!region_presets.empty())
  202. {
  203. mSkyPresetsCombo->addSeparator();
  204. }
  205. }
  206. // Add user presets.
  207. for (LLWLParamManager::preset_name_list_t::const_iterator it = user_presets.begin(); it != user_presets.end(); ++it)
  208. {
  209. mSkyPresetsCombo->add(*it, LLWLParamKey(*it, LLEnvKey::SCOPE_LOCAL).toStringVal());
  210. }
  211. if (!user_presets.empty())
  212. {
  213. mSkyPresetsCombo->addSeparator();
  214. }
  215. // Add system presets.
  216. for (LLWLParamManager::preset_name_list_t::const_iterator it = sys_presets.begin(); it != sys_presets.end(); ++it)
  217. {
  218. mSkyPresetsCombo->add(*it, LLWLParamKey(*it, LLEnvKey::SCOPE_LOCAL).toStringVal());
  219. }
  220. // set defaults on combo boxes
  221. mSkyPresetsCombo->selectFirstItem();
  222. }
  223. void LLFloaterEditDayCycle::refreshDayCyclesList()
  224. {
  225. llassert(isNewDay() == false);
  226. mDayCyclesCombo->removeall();
  227. #if 0 // Disable editing existing day cycle until the workflow is clear enough.
  228. const LLSD& region_day = LLEnvManagerNew::instance().getRegionSettings().getWLDayCycle();
  229. if (region_day.size() > 0)
  230. {
  231. LLWLParamKey key(getRegionName(), LLEnvKey::SCOPE_REGION);
  232. mDayCyclesCombo->add(key.name, key.toLLSD());
  233. mDayCyclesCombo->addSeparator();
  234. }
  235. #endif
  236. LLDayCycleManager::preset_name_list_t user_days, sys_days;
  237. LLDayCycleManager::instance().getPresetNames(user_days, sys_days);
  238. // Add user days.
  239. for (LLDayCycleManager::preset_name_list_t::const_iterator it = user_days.begin(); it != user_days.end(); ++it)
  240. {
  241. mDayCyclesCombo->add(*it, LLWLParamKey(*it, LLEnvKey::SCOPE_LOCAL).toLLSD());
  242. }
  243. if (user_days.size() > 0)
  244. {
  245. mDayCyclesCombo->addSeparator();
  246. }
  247. // Add system days.
  248. for (LLDayCycleManager::preset_name_list_t::const_iterator it = sys_days.begin(); it != sys_days.end(); ++it)
  249. {
  250. mDayCyclesCombo->add(*it, LLWLParamKey(*it, LLEnvKey::SCOPE_LOCAL).toLLSD());
  251. }
  252. mDayCyclesCombo->setLabel(getString("combo_label"));
  253. }
  254. void LLFloaterEditDayCycle::onTimeSliderMoved()
  255. {
  256. /// get the slider value
  257. F32 val = mTimeSlider->getCurSliderValue() / sHoursPerDay;
  258. // set the value, turn off animation
  259. LLWLParamManager::getInstance()->mAnimator.setDayTime((F64)val);
  260. LLWLParamManager::getInstance()->mAnimator.deactivate();
  261. // then call update once
  262. LLWLParamManager::getInstance()->mAnimator.update(
  263. LLWLParamManager::getInstance()->mCurParams);
  264. }
  265. void LLFloaterEditDayCycle::onKeyTimeMoved()
  266. {
  267. if (mKeysSlider->getValue().size() == 0)
  268. {
  269. return;
  270. }
  271. // make sure we have a slider
  272. const std::string& cur_sldr = mKeysSlider->getCurSlider();
  273. if (cur_sldr == "")
  274. {
  275. return;
  276. }
  277. F32 time24 = mKeysSlider->getCurSliderValue();
  278. // check to see if a key exists
  279. LLWLParamKey key = mSliderToKey[cur_sldr].keyframe;
  280. lldebugs << "Setting key time: " << time24 << LL_ENDL;
  281. mSliderToKey[cur_sldr].time = time24;
  282. // if it exists, turn on check box
  283. mSkyPresetsCombo->selectByValue(key.toStringVal());
  284. mTimeCtrl->setTime24(time24);
  285. applyTrack();
  286. }
  287. void LLFloaterEditDayCycle::onKeyTimeChanged()
  288. {
  289. // if no keys, skipped
  290. if (mSliderToKey.size() == 0)
  291. {
  292. return;
  293. }
  294. F32 time24 = mTimeCtrl->getTime24();
  295. const std::string& cur_sldr = mKeysSlider->getCurSlider();
  296. mKeysSlider->setCurSliderValue(time24, TRUE);
  297. F32 time = mKeysSlider->getCurSliderValue() / sHoursPerDay;
  298. // now set the key's time in the sliderToKey map
  299. lldebugs << "Setting key time: " << time << LL_ENDL;
  300. mSliderToKey[cur_sldr].time = time;
  301. applyTrack();
  302. }
  303. void LLFloaterEditDayCycle::onKeyPresetChanged()
  304. {
  305. // do nothing if no sliders
  306. if (mKeysSlider->getValue().size() == 0)
  307. {
  308. return;
  309. }
  310. // change the map
  311. std::string stringVal = mSkyPresetsCombo->getSelectedValue().asString();
  312. LLWLParamKey new_key(stringVal);
  313. llassert(!new_key.name.empty());
  314. const std::string& cur_sldr = mKeysSlider->getCurSlider();
  315. // if null, don't use
  316. if (cur_sldr == "")
  317. {
  318. return;
  319. }
  320. mSliderToKey[cur_sldr].keyframe = new_key;
  321. // Apply changes to current day cycle.
  322. applyTrack();
  323. }
  324. void LLFloaterEditDayCycle::onAddKey()
  325. {
  326. llassert_always(mSliderToKey.size() == mKeysSlider->getValue().size());
  327. S32 max_sliders;
  328. LLEnvKey::EScope scope = LLEnvKey::SCOPE_LOCAL; // *TODO: editing region day cycle
  329. switch (scope)
  330. {
  331. case LLEnvKey::SCOPE_LOCAL:
  332. max_sliders = 20; // *HACK this should be LLWLPacketScrubber::MAX_LOCAL_KEY_FRAMES;
  333. break;
  334. case LLEnvKey::SCOPE_REGION:
  335. max_sliders = 12; // *HACK this should be LLWLPacketScrubber::MAX_REGION_KEY_FRAMES;
  336. break;
  337. default:
  338. max_sliders = (S32) mKeysSlider->getMaxValue();
  339. break;
  340. }
  341. if ((S32)mSliderToKey.size() >= max_sliders)
  342. {
  343. LLSD args;
  344. args["SCOPE"] = LLEnvManagerNew::getScopeString(scope);
  345. args["MAX"] = max_sliders;
  346. LLNotificationsUtil::add("DayCycleTooManyKeyframes", args, LLSD(), LLNotificationFunctorRegistry::instance().DONOTHING);
  347. return;
  348. }
  349. // add the slider key
  350. std::string key_val = mSkyPresetsCombo->getSelectedValue().asString();
  351. LLWLParamKey sky_params(key_val);
  352. llassert(!sky_params.name.empty());
  353. F32 time = mTimeSlider->getCurSliderValue();
  354. addSliderKey(time, sky_params);
  355. // apply the change to current day cycles
  356. applyTrack();
  357. }
  358. void LLFloaterEditDayCycle::addSliderKey(F32 time, LLWLParamKey keyframe)
  359. {
  360. // make a slider
  361. const std::string& sldr_name = mKeysSlider->addSlider(time);
  362. if (sldr_name.empty())
  363. {
  364. return;
  365. }
  366. // set the key
  367. SliderKey newKey(keyframe, mKeysSlider->getCurSliderValue());
  368. llassert_always(sldr_name != LLStringUtil::null);
  369. // add to map
  370. mSliderToKey.insert(std::pair<std::string, SliderKey>(sldr_name, newKey));
  371. llassert_always(mSliderToKey.size() == mKeysSlider->getValue().size());
  372. }
  373. LLWLParamKey LLFloaterEditDayCycle::getSelectedDayCycle()
  374. {
  375. LLWLParamKey dc_key;
  376. if (mDayCycleNameEditor->getVisible())
  377. {
  378. dc_key.name = mDayCycleNameEditor->getText();
  379. dc_key.scope = LLEnvKey::SCOPE_LOCAL;
  380. }
  381. else
  382. {
  383. LLSD combo_val = mDayCyclesCombo->getValue();
  384. if (!combo_val.isArray()) // manually typed text
  385. {
  386. dc_key.name = combo_val.asString();
  387. dc_key.scope = LLEnvKey::SCOPE_LOCAL;
  388. }
  389. else
  390. {
  391. dc_key.fromLLSD(combo_val);
  392. }
  393. }
  394. return dc_key;
  395. }
  396. bool LLFloaterEditDayCycle::isNewDay() const
  397. {
  398. return mKey.asString() == "new";
  399. }
  400. void LLFloaterEditDayCycle::dumpTrack()
  401. {
  402. LL_DEBUGS("Windlight") << "Dumping day cycle" << LL_ENDL;
  403. LLWLDayCycle& cur_dayp = LLWLParamManager::instance().mDay;
  404. for (std::map<F32, LLWLParamKey>::iterator it = cur_dayp.mTimeMap.begin(); it != cur_dayp.mTimeMap.end(); ++it)
  405. {
  406. F32 time = it->first * 24.0f;
  407. S32 h = (S32) time;
  408. S32 m = (S32) ((time - h) * 60.0f);
  409. LL_DEBUGS("Windlight") << llformat("(%.3f) %02d:%02d", time, h, m) << " => " << it->second.name << LL_ENDL;
  410. }
  411. }
  412. void LLFloaterEditDayCycle::enableEditing(bool enable)
  413. {
  414. mSkyPresetsCombo->setEnabled(enable);
  415. mTimeCtrl->setEnabled(enable);
  416. getChild<LLPanel>("day_cycle_slider_panel")->setCtrlsEnabled(enable);
  417. mSaveButton->setEnabled(enable);
  418. mMakeDefaultCheckBox->setEnabled(enable);
  419. }
  420. void LLFloaterEditDayCycle::reset()
  421. {
  422. // clear the slider
  423. mKeysSlider->clear();
  424. mSliderToKey.clear();
  425. refreshSkyPresetsList();
  426. if (isNewDay())
  427. {
  428. mDayCycleNameEditor->setValue(LLSD());
  429. F32 time = 0.5f * sHoursPerDay;
  430. mSaveButton->setEnabled(FALSE); // will be enabled as soon as users enters a name
  431. mTimeSlider->setCurSliderValue(time);
  432. addSliderKey(time, LLWLParamKey("Default", LLEnvKey::SCOPE_LOCAL));
  433. onKeyTimeMoved(); // update the time control and sky sky combo
  434. applyTrack();
  435. }
  436. else
  437. {
  438. refreshDayCyclesList();
  439. // Disable controls until a day cycle to edit is selected.
  440. enableEditing(false);
  441. }
  442. }
  443. void LLFloaterEditDayCycle::saveRegionDayCycle()
  444. {
  445. LLEnvManagerNew& env_mgr = LLEnvManagerNew::instance();
  446. LLWLDayCycle& cur_dayp = LLWLParamManager::instance().mDay; // the day cycle being edited
  447. // Get current day cycle and the sky preset it references.
  448. LLSD day_cycle = cur_dayp.asLLSD();
  449. LLSD sky_map;
  450. cur_dayp.getSkyMap(sky_map);
  451. // Apply it to the region.
  452. LLEnvironmentSettings new_region_settings;
  453. new_region_settings.saveParams(day_cycle, sky_map, env_mgr.getRegionSettings().getWaterParams(), 0.0f);
  454. #if 1
  455. LLEnvManagerNew::instance().setRegionSettings(new_region_settings);
  456. #else // Temporary disabled ability to upload new region settings from the Day Cycle Editor.
  457. if (!LLEnvManagerNew::instance().sendRegionSettings(new_region_settings))
  458. {
  459. llwarns << "Error applying region environment settings" << llendl;
  460. return;
  461. }
  462. setApplyProgress(true);
  463. #endif
  464. }
  465. void LLFloaterEditDayCycle::setApplyProgress(bool started)
  466. {
  467. LLLoadingIndicator* indicator = getChild<LLLoadingIndicator>("progress_indicator");
  468. indicator->setVisible(started);
  469. if (started)
  470. {
  471. indicator->start();
  472. }
  473. else
  474. {
  475. indicator->stop();
  476. }
  477. }
  478. bool LLFloaterEditDayCycle::getApplyProgress() const
  479. {
  480. return getChild<LLLoadingIndicator>("progress_indicator")->getVisible();
  481. }
  482. void LLFloaterEditDayCycle::onDeleteKey()
  483. {
  484. if (mSliderToKey.size() == 0)
  485. {
  486. return;
  487. }
  488. else if (mSliderToKey.size() == 1)
  489. {
  490. LLNotifications::instance().add("EnvCannotDeleteLastDayCycleKey", LLSD(), LLSD());
  491. return;
  492. }
  493. // delete from map
  494. const std::string& sldr_name = mKeysSlider->getCurSlider();
  495. std::map<std::string, SliderKey>::iterator mIt = mSliderToKey.find(sldr_name);
  496. mSliderToKey.erase(mIt);
  497. mKeysSlider->deleteCurSlider();
  498. if (mSliderToKey.size() == 0)
  499. {
  500. return;
  501. }
  502. const std::string& name = mKeysSlider->getCurSlider();
  503. mSkyPresetsCombo->selectByValue(mSliderToKey[name].keyframe.toStringVal());
  504. F32 time24 = mSliderToKey[name].time;
  505. mTimeCtrl->setTime24(time24);
  506. applyTrack();
  507. }
  508. void LLFloaterEditDayCycle::onRegionSettingsChange()
  509. {
  510. LL_DEBUGS("Windlight") << "Region settings changed" << LL_ENDL;
  511. if (getApplyProgress()) // our region settings have being applied
  512. {
  513. setApplyProgress(false);
  514. // Change preference if requested.
  515. if (mMakeDefaultCheckBox->getValue())
  516. {
  517. LL_DEBUGS("Windlight") << "Changed environment preference to region settings" << llendl;
  518. LLEnvManagerNew::instance().setUseRegionSettings(true);
  519. }
  520. closeFloater();
  521. }
  522. }
  523. void LLFloaterEditDayCycle::onRegionChange()
  524. {
  525. LL_DEBUGS("Windlight") << "Region changed" << LL_ENDL;
  526. // If we're editing the region day cycle
  527. if (getSelectedDayCycle().scope == LLEnvKey::SCOPE_REGION)
  528. {
  529. reset(); // undoes all unsaved changes
  530. }
  531. }
  532. void LLFloaterEditDayCycle::onRegionSettingsApplied(bool success)
  533. {
  534. LL_DEBUGS("Windlight") << "Region settings applied: " << success << LL_ENDL;
  535. if (!success)
  536. {
  537. // stop progress indicator
  538. setApplyProgress(false);
  539. }
  540. }
  541. void LLFloaterEditDayCycle::onRegionInfoUpdate()
  542. {
  543. LL_DEBUGS("Windlight") << "Region info updated" << LL_ENDL;
  544. bool can_edit = true;
  545. // If we've selected the region day cycle for editing.
  546. if (getSelectedDayCycle().scope == LLEnvKey::SCOPE_REGION)
  547. {
  548. // check whether we have the access
  549. can_edit = LLEnvManagerNew::canEditRegionSettings();
  550. }
  551. enableEditing(can_edit);
  552. }
  553. void LLFloaterEditDayCycle::onDayCycleNameEdited()
  554. {
  555. // Disable saving a day cycle having empty name.
  556. LLWLParamKey key = getSelectedDayCycle();
  557. mSaveButton->setEnabled(!key.name.empty());
  558. }
  559. void LLFloaterEditDayCycle::onDayCycleSelected()
  560. {
  561. LLSD day_data;
  562. LLWLParamKey dc_key = getSelectedDayCycle();
  563. bool can_edit = true;
  564. if (dc_key.scope == LLEnvKey::SCOPE_LOCAL)
  565. {
  566. if (!LLDayCycleManager::instance().getPreset(dc_key.name, day_data))
  567. {
  568. llwarns << "No day cycle named " << dc_key.name << llendl;
  569. return;
  570. }
  571. }
  572. else
  573. {
  574. day_data = LLEnvManagerNew::instance().getRegionSettings().getWLDayCycle();
  575. if (day_data.size() == 0)
  576. {
  577. llwarns << "Empty region day cycle" << llendl;
  578. llassert(day_data.size() > 0);
  579. return;
  580. }
  581. can_edit = LLEnvManagerNew::canEditRegionSettings();
  582. }
  583. // We may need to add or remove region skies from the list.
  584. refreshSkyPresetsList();
  585. F32 slider_time = mTimeSlider->getCurSliderValue() / sHoursPerDay;
  586. LLWLParamManager::instance().applyDayCycleParams(day_data, dc_key.scope, slider_time);
  587. loadTrack();
  588. enableEditing(can_edit);
  589. }
  590. void LLFloaterEditDayCycle::onBtnSave()
  591. {
  592. LLDayCycleManager& day_mgr = LLDayCycleManager::instance();
  593. LLWLParamKey selected_day = getSelectedDayCycle();
  594. if (selected_day.scope == LLEnvKey::SCOPE_REGION)
  595. {
  596. saveRegionDayCycle();
  597. closeFloater();
  598. return;
  599. }
  600. std::string name = selected_day.name;
  601. if (name.empty())
  602. {
  603. // *TODO: show an alert
  604. llwarns << "Empty day cycle name" << llendl;
  605. return;
  606. }
  607. // Don't allow overwriting system presets.
  608. if (day_mgr.isSystemPreset(name))
  609. {
  610. LLNotificationsUtil::add("WLNoEditDefault");
  611. return;
  612. }
  613. // Save, ask for confirmation for overwriting an existing preset.
  614. if (day_mgr.presetExists(name))
  615. {
  616. LLNotificationsUtil::add("WLSavePresetAlert", LLSD(), LLSD(), boost::bind(&LLFloaterEditDayCycle::onSaveAnswer, this, _1, _2));
  617. }
  618. else
  619. {
  620. // new preset, hence no confirmation needed
  621. onSaveConfirmed();
  622. }
  623. }
  624. void LLFloaterEditDayCycle::onBtnCancel()
  625. {
  626. closeFloater();
  627. }
  628. bool LLFloaterEditDayCycle::onSaveAnswer(const LLSD& notification, const LLSD& response)
  629. {
  630. S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
  631. // If they choose save, do it. Otherwise, don't do anything
  632. if (option == 0)
  633. {
  634. onSaveConfirmed();
  635. }
  636. return false;
  637. }
  638. void LLFloaterEditDayCycle::onSaveConfirmed()
  639. {
  640. std::string name = getSelectedDayCycle().name;
  641. // Save preset.
  642. LLSD data = LLWLParamManager::instance().mDay.asLLSD();
  643. LL_DEBUGS("Windlight") << "Saving day cycle " << name << ": " << data << LL_ENDL;
  644. LLDayCycleManager::instance().savePreset(name, data);
  645. // Change preference if requested.
  646. if (mMakeDefaultCheckBox->getValue())
  647. {
  648. LL_DEBUGS("Windlight") << name << " is now the new preferred day cycle" << llendl;
  649. LLEnvManagerNew::instance().setUseDayCycle(name);
  650. }
  651. closeFloater();
  652. }
  653. void LLFloaterEditDayCycle::onDayCycleListChange()
  654. {
  655. if (!isNewDay())
  656. {
  657. refreshDayCyclesList();
  658. }
  659. }
  660. void LLFloaterEditDayCycle::onSkyPresetListChange()
  661. {
  662. refreshSkyPresetsList();
  663. // Refresh sliders from the currently visible day cycle.
  664. loadTrack();
  665. }
  666. // static
  667. std::string LLFloaterEditDayCycle::getRegionName()
  668. {
  669. return gAgent.getRegion() ? gAgent.getRegion()->getName() : LLTrans::getString("Unknown");
  670. }