/indra/newview/llfloaterenvironmentsettings.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 282 lines · 189 code · 52 blank · 41 comment · 23 complexity · 49f0264cef76c1bf595c722d00d49a64 MD5 · raw file

  1. /**
  2. * @file llfloaterenvironmentsettings.cpp
  3. * @brief LLFloaterEnvironmentSettings class definition
  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 "llfloaterenvironmentsettings.h"
  28. #include "llcombobox.h"
  29. #include "llradiogroup.h"
  30. #include "lldaycyclemanager.h"
  31. #include "llenvmanager.h"
  32. #include "llwaterparammanager.h"
  33. #include "llwlparamset.h"
  34. #include "llwlparammanager.h"
  35. LLFloaterEnvironmentSettings::LLFloaterEnvironmentSettings(const LLSD &key)
  36. : LLFloater(key)
  37. ,mRegionSettingsRadioGroup(NULL)
  38. ,mDayCycleSettingsRadioGroup(NULL)
  39. ,mWaterPresetCombo(NULL)
  40. ,mSkyPresetCombo(NULL)
  41. ,mDayCyclePresetCombo(NULL)
  42. {
  43. }
  44. // virtual
  45. BOOL LLFloaterEnvironmentSettings::postBuild()
  46. {
  47. mRegionSettingsRadioGroup = getChild<LLRadioGroup>("region_settings_radio_group");
  48. mRegionSettingsRadioGroup->setCommitCallback(boost::bind(&LLFloaterEnvironmentSettings::onSwitchRegionSettings, this));
  49. mDayCycleSettingsRadioGroup = getChild<LLRadioGroup>("sky_dayc_settings_radio_group");
  50. mDayCycleSettingsRadioGroup->setCommitCallback(boost::bind(&LLFloaterEnvironmentSettings::onSwitchDayCycle, this));
  51. mWaterPresetCombo = getChild<LLComboBox>("water_settings_preset_combo");
  52. mWaterPresetCombo->setCommitCallback(boost::bind(&LLFloaterEnvironmentSettings::onSelectWaterPreset, this));
  53. mSkyPresetCombo = getChild<LLComboBox>("sky_settings_preset_combo");
  54. mSkyPresetCombo->setCommitCallback(boost::bind(&LLFloaterEnvironmentSettings::onSelectSkyPreset, this));
  55. mDayCyclePresetCombo = getChild<LLComboBox>("dayc_settings_preset_combo");
  56. mDayCyclePresetCombo->setCommitCallback(boost::bind(&LLFloaterEnvironmentSettings::onSelectDayCyclePreset, this));
  57. childSetCommitCallback("ok_btn", boost::bind(&LLFloaterEnvironmentSettings::onBtnOK, this), NULL);
  58. getChild<LLUICtrl>("ok_btn")->setRightMouseDownCallback(boost::bind(&LLEnvManagerNew::dumpUserPrefs, LLEnvManagerNew::getInstance()));
  59. childSetCommitCallback("cancel_btn", boost::bind(&LLFloaterEnvironmentSettings::onBtnCancel, this), NULL);
  60. getChild<LLUICtrl>("cancel_btn")->setRightMouseDownCallback(boost::bind(&LLEnvManagerNew::dumpPresets, LLEnvManagerNew::getInstance()));
  61. setCloseCallback(boost::bind(&LLFloaterEnvironmentSettings::cancel, this));
  62. LLEnvManagerNew::instance().setPreferencesChangeCallback(boost::bind(&LLFloaterEnvironmentSettings::refresh, this));
  63. LLDayCycleManager::instance().setModifyCallback(boost::bind(&LLFloaterEnvironmentSettings::populateDayCyclePresetsList, this));
  64. LLWLParamManager::instance().setPresetListChangeCallback(boost::bind(&LLFloaterEnvironmentSettings::populateSkyPresetsList, this));
  65. LLWaterParamManager::instance().setPresetListChangeCallback(boost::bind(&LLFloaterEnvironmentSettings::populateWaterPresetsList, this));
  66. return TRUE;
  67. }
  68. // virtual
  69. void LLFloaterEnvironmentSettings::onOpen(const LLSD& key)
  70. {
  71. refresh();
  72. }
  73. void LLFloaterEnvironmentSettings::onSwitchRegionSettings()
  74. {
  75. getChild<LLView>("user_environment_settings")->setEnabled(mRegionSettingsRadioGroup->getSelectedIndex() != 0);
  76. apply();
  77. }
  78. void LLFloaterEnvironmentSettings::onSwitchDayCycle()
  79. {
  80. bool is_fixed_sky = mDayCycleSettingsRadioGroup->getSelectedIndex() == 0;
  81. mSkyPresetCombo->setEnabled(is_fixed_sky);
  82. mDayCyclePresetCombo->setEnabled(!is_fixed_sky);
  83. apply();
  84. }
  85. void LLFloaterEnvironmentSettings::onSelectWaterPreset()
  86. {
  87. apply();
  88. }
  89. void LLFloaterEnvironmentSettings::onSelectSkyPreset()
  90. {
  91. apply();
  92. }
  93. void LLFloaterEnvironmentSettings::onSelectDayCyclePreset()
  94. {
  95. apply();
  96. }
  97. void LLFloaterEnvironmentSettings::onBtnOK()
  98. {
  99. // Save and apply new user preferences.
  100. bool use_region_settings = mRegionSettingsRadioGroup->getSelectedIndex() == 0;
  101. bool use_fixed_sky = mDayCycleSettingsRadioGroup->getSelectedIndex() == 0;
  102. std::string water_preset = mWaterPresetCombo->getValue().asString();
  103. std::string sky_preset = mSkyPresetCombo->getValue().asString();
  104. std::string day_cycle = mDayCyclePresetCombo->getValue().asString();
  105. LLEnvManagerNew::instance().setUserPrefs(
  106. water_preset,
  107. sky_preset,
  108. day_cycle,
  109. use_fixed_sky,
  110. use_region_settings);
  111. // *TODO: This triggers applying user preferences again, which is suboptimal.
  112. closeFloater();
  113. }
  114. void LLFloaterEnvironmentSettings::onBtnCancel()
  115. {
  116. closeFloater();
  117. }
  118. void LLFloaterEnvironmentSettings::refresh()
  119. {
  120. LLEnvManagerNew& env_mgr = LLEnvManagerNew::instance();
  121. bool use_region_settings = env_mgr.getUseRegionSettings();
  122. bool use_fixed_sky = env_mgr.getUseFixedSky();
  123. // Set up radio buttons according to user preferences.
  124. mRegionSettingsRadioGroup->setSelectedIndex(use_region_settings ? 0 : 1);
  125. mDayCycleSettingsRadioGroup->setSelectedIndex(use_fixed_sky ? 0 : 1);
  126. // Populate the combo boxes with appropriate lists of available presets.
  127. populateWaterPresetsList();
  128. populateSkyPresetsList();
  129. populateDayCyclePresetsList();
  130. // Enable/disable other controls based on user preferences.
  131. getChild<LLView>("user_environment_settings")->setEnabled(!use_region_settings);
  132. mSkyPresetCombo->setEnabled(use_fixed_sky);
  133. mDayCyclePresetCombo->setEnabled(!use_fixed_sky);
  134. // Select the current presets in combo boxes.
  135. mWaterPresetCombo->selectByValue(env_mgr.getWaterPresetName());
  136. mSkyPresetCombo->selectByValue(env_mgr.getSkyPresetName());
  137. mDayCyclePresetCombo->selectByValue(env_mgr.getDayCycleName());
  138. }
  139. void LLFloaterEnvironmentSettings::apply()
  140. {
  141. // Update environment with the user choice.
  142. bool use_region_settings = mRegionSettingsRadioGroup->getSelectedIndex() == 0;
  143. bool use_fixed_sky = mDayCycleSettingsRadioGroup->getSelectedIndex() == 0;
  144. std::string water_preset = mWaterPresetCombo->getValue().asString();
  145. std::string sky_preset = mSkyPresetCombo->getValue().asString();
  146. std::string day_cycle = mDayCyclePresetCombo->getValue().asString();
  147. LLEnvManagerNew& env_mgr = LLEnvManagerNew::instance();
  148. if (use_region_settings)
  149. {
  150. env_mgr.useRegionSettings();
  151. }
  152. else
  153. {
  154. if (use_fixed_sky)
  155. {
  156. env_mgr.useSkyPreset(sky_preset);
  157. }
  158. else
  159. {
  160. env_mgr.useDayCycle(day_cycle, LLEnvKey::SCOPE_LOCAL);
  161. }
  162. env_mgr.useWaterPreset(water_preset);
  163. }
  164. }
  165. void LLFloaterEnvironmentSettings::cancel()
  166. {
  167. // Revert environment to user preferences.
  168. LLEnvManagerNew::instance().usePrefs();
  169. }
  170. void LLFloaterEnvironmentSettings::populateWaterPresetsList()
  171. {
  172. mWaterPresetCombo->removeall();
  173. std::list<std::string> user_presets, system_presets;
  174. LLWaterParamManager::instance().getPresetNames(user_presets, system_presets);
  175. // Add user presets first.
  176. for (std::list<std::string>::const_iterator it = user_presets.begin(); it != user_presets.end(); ++it)
  177. {
  178. mWaterPresetCombo->add(*it);
  179. }
  180. if (user_presets.size() > 0)
  181. {
  182. mWaterPresetCombo->addSeparator();
  183. }
  184. // Add system presets.
  185. for (std::list<std::string>::const_iterator it = system_presets.begin(); it != system_presets.end(); ++it)
  186. {
  187. mWaterPresetCombo->add(*it);
  188. }
  189. }
  190. void LLFloaterEnvironmentSettings::populateSkyPresetsList()
  191. {
  192. mSkyPresetCombo->removeall();
  193. LLWLParamManager::preset_name_list_t region_presets; // unused as we don't list region presets here
  194. LLWLParamManager::preset_name_list_t user_presets, sys_presets;
  195. LLWLParamManager::instance().getPresetNames(region_presets, user_presets, sys_presets);
  196. // Add user presets.
  197. for (LLWLParamManager::preset_name_list_t::const_iterator it = user_presets.begin(); it != user_presets.end(); ++it)
  198. {
  199. mSkyPresetCombo->add(*it);
  200. }
  201. if (!user_presets.empty())
  202. {
  203. mSkyPresetCombo->addSeparator();
  204. }
  205. // Add system presets.
  206. for (LLWLParamManager::preset_name_list_t::const_iterator it = sys_presets.begin(); it != sys_presets.end(); ++it)
  207. {
  208. mSkyPresetCombo->add(*it);
  209. }
  210. }
  211. void LLFloaterEnvironmentSettings::populateDayCyclePresetsList()
  212. {
  213. mDayCyclePresetCombo->removeall();
  214. LLDayCycleManager::preset_name_list_t user_days, sys_days;
  215. LLDayCycleManager::instance().getPresetNames(user_days, sys_days);
  216. // Add user days.
  217. for (LLDayCycleManager::preset_name_list_t::const_iterator it = user_days.begin(); it != user_days.end(); ++it)
  218. {
  219. mDayCyclePresetCombo->add(*it);
  220. }
  221. if (user_days.size() > 0)
  222. {
  223. mDayCyclePresetCombo->addSeparator();
  224. }
  225. // Add system days.
  226. for (LLDayCycleManager::preset_name_list_t::const_iterator it = sys_days.begin(); it != sys_days.end(); ++it)
  227. {
  228. mDayCyclePresetCombo->add(*it);
  229. }
  230. }