PageRenderTime 97ms CodeModel.GetById 32ms app.highlight 31ms RepoModel.GetById 19ms app.codeStats 0ms

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