aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llwindlightremotectrl.cpp
blob: b9111d3559f8d4e3e96aa704dd0085746e2f147a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
/**
* @file llwindlightremotectrl.cpp
* @brief toolbar remote for windlight options and presets
*
* $LicenseInfo:firstyear=2009&license=viewergpl$
*
* Copyright (c) 2009, McCabe Maxsted
*
* Imprudence Viewer Source Code
* The source code in this file ("Source Code") is provided to you
* under the terms of the GNU General Public License, version 2.0
* ("GPL"). Terms of the GPL can be found in doc/GPL-license.txt in
* this distribution, or online at
* http://secondlifegrid.net/programs/open_source/licensing/gplv2
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or
* online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
*
* ALL SOURCE CODE IS PROVIDED "AS IS." THE AUTHOR MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* $/LicenseInfo$
*/

#include "llviewerprecompiledheaders.h"

#include "llwindlightremotectrl.h"

#include "llbutton.h"
#include "llcombobox.h"
#include "llfloaterenvsettings.h"
#include "llfloaterwater.h"
#include "llfloaterwindlight.h"
#include "lloverlaybar.h"
#include "lluictrlfactory.h"
#include "llwlparammanager.h"
#include "llviewercontrol.h"
#include "llviewerwindow.h"

// [RLVa:KB] - Alternate: Imprudence-1.2.0
#include "rlvhandler.h"
// [/RLVa:KB]

class LLWindlightRemoteObserver : public LLWLPresetsObserver
{
public:
	LLWindlightRemoteObserver(LLWindlightRemoteCtrl* wind_rem) : mWindlightRemote(wind_rem){}
	virtual ~LLWindlightRemoteObserver() {}
	virtual void changed() { mWindlightRemote->refreshPresets(); }
private:
	LLWindlightRemoteCtrl* mWindlightRemote;
};


LLWindlightRemoteCtrl::LLWindlightRemoteCtrl() :
	mObserver(NULL)
{
	setIsChrome(TRUE);

	build();

	setFocusRoot(TRUE);
}

LLWindlightRemoteCtrl::~LLWindlightRemoteCtrl()
{
	delete mObserver;
	mObserver = NULL;
}

void LLWindlightRemoteCtrl::draw()
{
	LLButton* expand_button = getChild<LLButton>("Popup");
	if (expand_button)
	{
		if (expand_button->getToggleState())
		{
			expand_button->setImageOverlay("arrow_down.tga");
		}
		else
		{
			expand_button->setImageOverlay("arrow_up.tga");
		}
	}

// [RLVa:KB] - Alternate: Imprudence-1.2.0
	if (rlv_handler_t::isEnabled())
	{
		childSetEnabled("Environment", !gRlvHandler.hasBehaviour(RLV_BHVR_SETENV));
		getChild<LLComboBox>("Presets")->setEnabled(!gRlvHandler.hasBehaviour(RLV_BHVR_SETENV));
	}
// [/RLVA:KB]

	LLPanel::draw();
}

void LLWindlightRemoteCtrl::build()
{
	if (gSavedSettings.getBOOL("ShowWindlightSettingsPopup"))
	{
		LLUICtrlFactory::getInstance()->buildPanel(this, "panel_windlight_remote_expanded.xml");
	}
	else
	{
		LLUICtrlFactory::getInstance()->buildPanel(this, "panel_windlight_remote.xml");
	}
}

BOOL LLWindlightRemoteCtrl::postBuild()
{
	
	childSetAction("Environment", onClickToggleEnvironment, this);
	childSetAction("Popup", onClickPopupBtn, this);

	LLComboBox*	presetsCombo = getChild<LLComboBox>("Presets");
	if (presetsCombo)
	{
		presetsCombo->setSimple(LLWLParamManager::instance()->mCurParams.mName);
		presetsCombo->setCommitCallback(onCommitPreset);
		presetsCombo->setCallbackUserData(this);

		// set up observer to follow changes
		mObserver = new LLWindlightRemoteObserver(this);
		LLWLParamManager::addObserver(mObserver);

		// refresh list from current presets
		refreshPresets();
	}

	return TRUE;
}

void LLWindlightRemoteCtrl::refreshPresets()
{
	// If we're teleporting or just logging in, no UI to refresh
	if (gViewerWindow->getShowProgress())
	{
		return;
	}

	LLComboBox*	presetsCombo = getChild<LLComboBox>("Presets", TRUE, TRUE);
	if (presetsCombo)
	{
		// snag current preset
		LLWLParamManager * param_mgr = LLWLParamManager::instance();
		LLWLParamSet& currentParams = param_mgr->mCurParams;
		
		// clear in case presets names have changed
		presetsCombo->clearRows();

		std::map<std::string, LLWLParamSet>::iterator mIt = 
			param_mgr->mParamList.begin();
		for(; mIt != param_mgr->mParamList.end(); mIt++) 
		{
			presetsCombo->add(mIt->first);
		}
		
		// insert separator and add World menu options
		// presetsCombo->addSeparator(ADD_BOTTOM);
		// presetsCombo->addSimpleElement(getString("atmosphere"), ADD_BOTTOM);
		// presetsCombo->addSimpleElement(getString("lighting"), ADD_BOTTOM);
		// presetsCombo->addSimpleElement(getString("clouds"), ADD_BOTTOM);
		// presetsCombo->addSimpleElement(getString("advanced_water"), ADD_BOTTOM);
		presetsCombo->addSeparator(ADD_BOTTOM);
		presetsCombo->addSimpleElement(getString("sunrise"), ADD_BOTTOM);
		presetsCombo->addSimpleElement(getString("noon"), ADD_BOTTOM);
		presetsCombo->addSimpleElement(getString("sunset"), ADD_BOTTOM);
		presetsCombo->addSimpleElement(getString("midnight"), ADD_BOTTOM);
		presetsCombo->addSimpleElement(getString("revert_region"), ADD_BOTTOM);

		if (!currentParams.mName.empty())
		{
			presetsCombo->selectByValue(LLSD(currentParams.mName));
		}
		else
		{
			presetsCombo->selectByValue(LLSD("Default"));
		}
	}
}

// static
void LLWindlightRemoteCtrl::onCommitPreset(LLUICtrl* ctrl, void* data)
{
	LLWindlightRemoteCtrl* self = (LLWindlightRemoteCtrl*)data;

	LLComboBox*	presetsCombo = self->getChild<LLComboBox>("Presets");

	LLCtrlListInterface* presets = presetsCombo ? presetsCombo->getListInterface() : NULL;
	if (presets)
	{
		S32 index = presets->getFirstSelectedIndex();
		if (index < 0)
		{
			// Open Advanced Sky
			LLFloaterWindLight::show();
			return;
		}

		// check for World menu options; if none, apply preset
		std::string selected = presetsCombo->getSelectedValue().asString();

		if (selected == self->getString("atmosphere"))
		{
			if (!LLFloaterWindLight::instance()->getVisible())
			{
				LLFloaterWindLight::show();
			}
			LLFloaterWindLight::instance()->selectTab("Atmosphere");
		}
		else if (selected == self->getString("lighting"))
		{
			if (!LLFloaterWindLight::instance()->getVisible())
			{
				LLFloaterWindLight::show();
			}
			LLFloaterWindLight::instance()->selectTab("Lighting");
		}
		else if (selected == self->getString("clouds"))
		{
			if (!LLFloaterWindLight::instance()->getVisible())
			{
				LLFloaterWindLight::show();
			}
			LLFloaterWindLight::instance()->selectTab("Clouds");
		}
		else if (selected == self->getString("advanced_water"))
		{
			LLFloaterWater::show();
		}
		else if (selected == self->getString("sunrise"))
		{
			// set the value, turn off animation
			LLWLParamManager::instance()->mAnimator.setDayTime(0.25);
			LLWLParamManager::instance()->mAnimator.mIsRunning = false;
			LLWLParamManager::instance()->mAnimator.mUseLindenTime = false;

			// then call update once
			LLWLParamManager::instance()->mAnimator.update(
				LLWLParamManager::instance()->mCurParams);
		}
		else if (selected == self->getString("noon"))
		{
			// set the value, turn off animation
			LLWLParamManager::instance()->mAnimator.setDayTime(0.567);
			LLWLParamManager::instance()->mAnimator.mIsRunning = false;
			LLWLParamManager::instance()->mAnimator.mUseLindenTime = false;

			// then call update once
			LLWLParamManager::instance()->mAnimator.update(
				LLWLParamManager::instance()->mCurParams);
		}
		else if (selected == self->getString("sunset"))
		{
			// set the value, turn off animation
			LLWLParamManager::instance()->mAnimator.setDayTime(0.75);
			LLWLParamManager::instance()->mAnimator.mIsRunning = false;
			LLWLParamManager::instance()->mAnimator.mUseLindenTime = false;

			// then call update once
			LLWLParamManager::instance()->mAnimator.update(
				LLWLParamManager::instance()->mCurParams);
		}
		else if (selected == self->getString("midnight"))
		{
			// set the value, turn off animation
			LLWLParamManager::instance()->mAnimator.setDayTime(0.0);
			LLWLParamManager::instance()->mAnimator.mIsRunning = false;
			LLWLParamManager::instance()->mAnimator.mUseLindenTime = false;

			// then call update once
			LLWLParamManager::instance()->mAnimator.update(
				LLWLParamManager::instance()->mCurParams);
		}
		else if (selected == self->getString("revert_region"))
		{
			LLWLParamManager::instance()->mAnimator.mIsRunning = true;
			LLWLParamManager::instance()->mAnimator.mUseLindenTime = true;	
		}
		else
		{
			// Apply preset
			LLWLParamManager::instance()->mAnimator.mIsRunning = false;
			LLWLParamManager::instance()->mAnimator.mUseLindenTime = false;
			LLWLParamManager::instance()->loadPreset(selected, true);
		}
	}
}

// static
void LLWindlightRemoteCtrl::onClickToggleEnvironment(void* data)
{
	// if evn settings not there or is hidden, show it
	if(	!LLFloaterEnvSettings::isOpen() || 
		!LLFloaterEnvSettings::instance()->getVisible()) 
	{
		LLFloaterEnvSettings::show();
	
	// otherwise, close it button acts like a toggle
	} 
	else 
	{
		LLFloaterEnvSettings::instance()->close();
	}
}

//static
void LLWindlightRemoteCtrl::onClickPopupBtn(void* data)
{
	LLWindlightRemoteCtrl* remotep = (LLWindlightRemoteCtrl*)data;

	remotep->deleteAllChildren();
	remotep->build();
	gOverlayBar->layoutButtons();
}