llfloaterwindlight.cpp 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590
  1. /**
  2. * @file llfloaterwindlight.cpp
  3. * @brief LLFloaterWindlight class implementation
  4. *
  5. * $LicenseInfo:firstyear=2007&license=viewergpl$
  6. *
  7. * Copyright (c) 2007-2009, 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 "boost/tokenizer.hpp"
  34. #include "llfloaterwindlight.h"
  35. #include "imageids.h"
  36. #include "llbutton.h"
  37. #include "llcheckboxctrl.h"
  38. #include "llcombobox.h"
  39. #include "llmultisliderctrl.h"
  40. #include "llnotifications.h"
  41. #include "llsliderctrl.h"
  42. #include "llspinctrl.h"
  43. #include "lluictrlfactory.h"
  44. #include "llcolorswatch.h"
  45. #include "llenvironment.h"
  46. #include "llenvsettings.h"
  47. #include "llpipeline.h"
  48. //MK
  49. #include "mkrlinterface.h"
  50. //mk
  51. #include "lltexturectrl.h"
  52. #include "llviewercontrol.h"
  53. #include "llwlskyparammgr.h"
  54. #include "llwlwaterparammgr.h"
  55. constexpr F32 HOUR_PER_DAY = 24.f;
  56. ///////////////////////////////////////////////////////////////////////////////
  57. // LLPanelWLDayCycle class (used to be a separate floater in LL's viewer)
  58. ///////////////////////////////////////////////////////////////////////////////
  59. // Convenience structure for holding keys mapped to sliders
  60. struct LLWLSkyKey
  61. {
  62. public:
  63. std::string mPresetName;
  64. F32 mTime;
  65. };
  66. class LLPanelWLDayCycle final : public LLPanel
  67. {
  68. protected:
  69. LOG_CLASS(LLPanelWLDayCycle);
  70. public:
  71. LLPanelWLDayCycle(const std::string& name)
  72. : LLPanel(name)
  73. {
  74. }
  75. ~LLPanelWLDayCycle() override
  76. {
  77. }
  78. bool postBuild() override;
  79. void refresh() override;
  80. // Adds a new preset to the combo
  81. void addPreset(const std::string& name);
  82. // Deletes any and all reference to a preset in keys
  83. void deletePreset(const std::string& name);
  84. private:
  85. static LLPanelWLDayCycle* getSelf();
  86. void refreshNames(std::string new_selection = LLStringUtil::null);
  87. // Adds a slider to the track
  88. void addSliderKey(F32 time, const std::string& name);
  89. // Makes sure key slider has what is in day cycle
  90. void syncSliderTrack();
  91. // Makes sure day cycle data structure has what is in menu
  92. void syncTrack();
  93. static void onClickHelp(void* userdata);
  94. static void onTimeSliderMoved(LLUICtrl* ctrl, void* userdata);
  95. static void onKeyTimeMoved(LLUICtrl* ctrl, void* userdata);
  96. static void onKeyTimeChanged(LLUICtrl* ctrl, void* userdata);
  97. static void onKeyPresetChanged(LLUICtrl* ctrl, void* userdata);
  98. static void onRunAnimSky(void* userdata);
  99. static void onStopAnimSky(void*);
  100. static void onTimeRateChanged(LLUICtrl* ctrl, void* userdata);
  101. static void onAddKey(void* userdata);
  102. static void onDeleteKey(void* userdata);
  103. static void onNewDayCycle(void* userdata);
  104. static void onSaveDayCycle(void* userdata);
  105. static void onDeleteDayCycle(void* userdata);
  106. static void onChangeDayCycle(LLUICtrl* ctrl, void* userdata);
  107. static bool newPromptCallback(const LLSD& notification,
  108. const LLSD& response);
  109. static bool saveAlertCallback(const LLSD& notification,
  110. const LLSD& response);
  111. static bool deleteAlertCallback(const LLSD& notification,
  112. const LLSD& response);
  113. private:
  114. LLComboBox* mWLDayCycleCombo;
  115. LLComboBox* mWLKeyPresets;
  116. LLMultiSliderCtrl* mWLTimeSlider;
  117. LLMultiSliderCtrl* mWLDayCycleKeys;
  118. LLSpinCtrl* mWLCurKeyHour;
  119. LLSpinCtrl* mWLCurKeyMin;
  120. LLSpinCtrl* mWLLengthOfDayHour;
  121. LLSpinCtrl* mWLLengthOfDayMin;
  122. LLSpinCtrl* mWLLengthOfDaySec;
  123. LLButton* mPlayBtn;
  124. LLButton* mStopBtn;
  125. LLTextBox* mNoLivePreviewText;
  126. // Map of sliders to parameters
  127. typedef std::map<std::string, LLWLSkyKey> skykey_map_t;
  128. static skykey_map_t sSliderToKey;
  129. };
  130. LLPanelWLDayCycle::skykey_map_t LLPanelWLDayCycle::sSliderToKey;
  131. //static
  132. LLPanelWLDayCycle* LLPanelWLDayCycle::getSelf()
  133. {
  134. LLFloaterWindlight* dcp = LLFloaterWindlight::findInstance();
  135. return dcp ? dcp->mPanelDayCycle : NULL;
  136. }
  137. //virtual
  138. bool LLPanelWLDayCycle::postBuild()
  139. {
  140. mWLDayCycleCombo = getChild<LLComboBox>("WLDayCycleCombo");
  141. refreshNames();
  142. mWLDayCycleCombo->setCommitCallback(onChangeDayCycle);
  143. mWLDayCycleCombo->setCallbackUserData(this);
  144. mWLKeyPresets = getChild<LLComboBox>("WLKeyPresets");
  145. for (LLWLSkyParamMgr::paramset_map_t::iterator
  146. it = gWLSkyParamMgr.mParamList.begin(),
  147. end = gWLSkyParamMgr.mParamList.end();
  148. it != end; ++it)
  149. {
  150. const std::string& name = it->first;
  151. if (name != "current parcel environment")
  152. {
  153. mWLKeyPresets->add(name);
  154. }
  155. }
  156. mWLKeyPresets->selectFirstItem();
  157. mWLKeyPresets->setCommitCallback(onKeyPresetChanged);
  158. mWLKeyPresets->setCallbackUserData(this);
  159. mWLTimeSlider = getChild<LLMultiSliderCtrl>("WLTimeSlider");
  160. mWLTimeSlider->addSlider();
  161. mWLTimeSlider->setCommitCallback(onTimeSliderMoved);
  162. mWLTimeSlider->setCallbackUserData(this);
  163. mWLDayCycleKeys = getChild<LLMultiSliderCtrl>("WLDayCycleKeys");
  164. mWLDayCycleKeys->setCommitCallback(onKeyTimeMoved);
  165. mWLDayCycleKeys->setCallbackUserData(this);
  166. mWLCurKeyHour = getChild<LLSpinCtrl>("WLCurKeyHour");
  167. mWLCurKeyHour->setCommitCallback(onKeyTimeChanged);
  168. mWLCurKeyHour->setCallbackUserData(this);
  169. mWLCurKeyMin = getChild<LLSpinCtrl>("WLCurKeyMin");
  170. mWLCurKeyMin->setCommitCallback(onKeyTimeChanged);
  171. mWLCurKeyMin->setCallbackUserData(this);
  172. mWLLengthOfDayHour = getChild<LLSpinCtrl>("WLLengthOfDayHour");
  173. mWLLengthOfDayHour->setCommitCallback(onTimeRateChanged);
  174. mWLLengthOfDayHour->setCallbackUserData(this);
  175. mWLLengthOfDayMin = getChild<LLSpinCtrl>("WLLengthOfDayMin");
  176. mWLLengthOfDayMin->setCommitCallback(onTimeRateChanged);
  177. mWLLengthOfDayMin->setCallbackUserData(this);
  178. mWLLengthOfDaySec = getChild<LLSpinCtrl>("WLLengthOfDaySec");
  179. mWLLengthOfDaySec->setCommitCallback(onTimeRateChanged);
  180. mWLLengthOfDaySec->setCallbackUserData(this);
  181. mPlayBtn = getChild<LLButton>("WLAnimSky");
  182. mPlayBtn->setClickedCallback(onRunAnimSky, this);
  183. mStopBtn = getChild<LLButton>("WLStopAnimSky");
  184. mStopBtn->setClickedCallback(onStopAnimSky, this);
  185. mNoLivePreviewText = getChild<LLTextBox>("no_live_preview_text");
  186. childSetAction("WLNewDayCycle", onNewDayCycle, this);
  187. childSetAction("WLSaveDayCycle", onSaveDayCycle, this);
  188. childSetAction("WLDeleteDayCycle", onDeleteDayCycle, this);
  189. childSetAction("WLAddKey", onAddKey, this);
  190. childSetAction("WLDeleteKey", onDeleteKey, this);
  191. childSetAction("WLDayCycleHelp", onClickHelp, this);
  192. refresh();
  193. syncSliderTrack();
  194. return true;
  195. }
  196. //virtual
  197. void LLPanelWLDayCycle::refresh()
  198. {
  199. // Set time
  200. mWLTimeSlider->setCurSliderValue((F32)gWLSkyParamMgr.mAnimator.getDayTime() *
  201. HOUR_PER_DAY);
  202. // Get the current rate
  203. F32 seconds = gWLSkyParamMgr.mDay.mDayLenth;
  204. F32 hours = (F32)((S32)(seconds / 3600.f));
  205. seconds -= hours * 3600.f;
  206. F32 min = (F32)((S32)(seconds / 60));
  207. seconds -= min * 60.f;
  208. mWLLengthOfDayHour->setValue(hours);
  209. mWLLengthOfDayMin->setValue(min);
  210. mWLLengthOfDaySec->setValue(seconds);
  211. // Preview. *TODO: no more available: remove !
  212. mPlayBtn->setEnabled(false);
  213. mStopBtn->setEnabled(false);
  214. mNoLivePreviewText->setVisible(false);
  215. onStopAnimSky(this);
  216. }
  217. void LLPanelWLDayCycle::refreshNames(std::string new_selection)
  218. {
  219. // Refresh the available day cycles presets list
  220. LLWLDayCycle::findPresets();
  221. mWLDayCycleCombo->removeall();
  222. for (LLWLDayCycle::names_list_t::iterator
  223. it = LLWLDayCycle::sPresetNames.begin(),
  224. end = LLWLDayCycle::sPresetNames.end();
  225. it != end; ++it)
  226. {
  227. mWLDayCycleCombo->add(*it);
  228. }
  229. // Set (possibly new) selected entry in combo box
  230. if (new_selection.empty())
  231. {
  232. new_selection = "Default";
  233. }
  234. mWLDayCycleCombo->selectByValue(LLSD(new_selection));
  235. }
  236. void LLPanelWLDayCycle::addPreset(const std::string& name)
  237. {
  238. mWLKeyPresets->add(name);
  239. mWLKeyPresets->sortByName();
  240. }
  241. void LLPanelWLDayCycle::deletePreset(const std::string& name)
  242. {
  243. // Remove from combo
  244. mWLKeyPresets->remove(name);
  245. // Delete any reference
  246. for (skykey_map_t::iterator it = sSliderToKey.begin(),
  247. end = sSliderToKey.end();
  248. it != end; )
  249. {
  250. skykey_map_t::iterator cur = it++;
  251. if (cur->second.mPresetName == name)
  252. {
  253. mWLDayCycleKeys->deleteSlider(cur->first);
  254. sSliderToKey.erase(cur);
  255. }
  256. }
  257. }
  258. void LLPanelWLDayCycle::syncSliderTrack()
  259. {
  260. // Clear the slider
  261. mWLDayCycleKeys->clear();
  262. sSliderToKey.clear();
  263. // Add sliders
  264. for (std::map<F32, std::string>::iterator
  265. it = gWLSkyParamMgr.mDay.mTimeMap.begin(),
  266. end = gWLSkyParamMgr.mDay.mTimeMap.end();
  267. it != end; ++it)
  268. {
  269. addSliderKey(it->first * HOUR_PER_DAY, it->second);
  270. }
  271. }
  272. void LLPanelWLDayCycle::syncTrack()
  273. {
  274. // If no keys, do nothing
  275. if (!sSliderToKey.size())
  276. {
  277. return;
  278. }
  279. // Create a new animation track
  280. gWLSkyParamMgr.mDay.clearKeys();
  281. // Add the keys one by one
  282. for (skykey_map_t::iterator it = sSliderToKey.begin(),
  283. end = sSliderToKey.end();
  284. it != end; ++it)
  285. {
  286. gWLSkyParamMgr.mDay.addKey(it->second.mTime / HOUR_PER_DAY,
  287. it->second.mPresetName);
  288. }
  289. // Set the param manager's track to the new one
  290. gWLSkyParamMgr.resetAnimator(mWLTimeSlider->getCurSliderValue() /
  291. HOUR_PER_DAY,
  292. false);
  293. gWLSkyParamMgr.mAnimator.update(gWLSkyParamMgr.mCurParams);
  294. }
  295. //static
  296. void LLPanelWLDayCycle::onClickHelp(void* userdata)
  297. {
  298. LLPanelWLDayCycle* self = (LLPanelWLDayCycle*)userdata;
  299. if (self)
  300. {
  301. LLFloater* parent = self->getParentFloater();
  302. if (parent)
  303. {
  304. gNotifications.add(parent->contextualNotification("HelpDayCycle"));
  305. }
  306. }
  307. }
  308. //static
  309. void LLPanelWLDayCycle::addSliderKey(F32 time, const std::string& name)
  310. {
  311. // Make a slider
  312. const std::string& slider_name = mWLDayCycleKeys->addSlider(time);
  313. if (slider_name.empty())
  314. {
  315. return;
  316. }
  317. // Set the key
  318. LLWLSkyKey new_key;
  319. new_key.mPresetName = name;
  320. new_key.mTime = mWLDayCycleKeys->getCurSliderValue();
  321. // Add to map
  322. sSliderToKey[slider_name] = new_key;
  323. }
  324. //static
  325. void LLPanelWLDayCycle::onRunAnimSky(void* userdata)
  326. {
  327. LLPanelWLDayCycle* self = (LLPanelWLDayCycle*)userdata;
  328. if (!self || sSliderToKey.size() == 0)
  329. {
  330. return;
  331. }
  332. // Turn off estate time
  333. gSavedSettings.setBool("UseWLEstateTime", false);
  334. // Set the param manager's track to the new one
  335. gWLSkyParamMgr.resetAnimator(self->mWLTimeSlider->getCurSliderValue() /
  336. HOUR_PER_DAY,
  337. true);
  338. }
  339. //static
  340. void LLPanelWLDayCycle::onStopAnimSky(void*)
  341. {
  342. // If no keys, do nothing
  343. if (sSliderToKey.size() > 0)
  344. {
  345. // Turn off animation and using linden time
  346. gWLSkyParamMgr.animate(false);
  347. }
  348. }
  349. //static
  350. void LLPanelWLDayCycle::onChangeDayCycle(LLUICtrl* ctrl, void* userdata)
  351. {
  352. LLPanelWLDayCycle* self = (LLPanelWLDayCycle*)userdata;
  353. LLComboBox* combo = (LLComboBox*)ctrl;
  354. if (!self || !combo) return;
  355. std::string name = combo->getSelectedValue().asString();
  356. if (name.empty())
  357. {
  358. return;
  359. }
  360. gWLSkyParamMgr.mDay.loadDayCycle(name);
  361. // Sync it all up
  362. self->syncSliderTrack();
  363. self->refresh();
  364. // Set the param manager's track to the new one
  365. gWLSkyParamMgr.resetAnimator(self->mWLTimeSlider->getCurSliderValue() /
  366. HOUR_PER_DAY,
  367. false);
  368. // And draw it
  369. gWLSkyParamMgr.mAnimator.update(gWLSkyParamMgr.mCurParams);
  370. }
  371. //static
  372. bool LLPanelWLDayCycle::newPromptCallback(const LLSD& notification,
  373. const LLSD& response)
  374. {
  375. LLPanelWLDayCycle* self = getSelf();
  376. if (!self || LLNotification::getSelectedOption(notification, response))
  377. {
  378. return false;
  379. }
  380. std::string name = response["message"].asString();
  381. if (name.empty())
  382. {
  383. return false;
  384. }
  385. // Refresh the available day cycles presets list
  386. LLWLDayCycle::findPresets();
  387. if (LLWLDayCycle::sPresetNames.count(name))
  388. {
  389. // Otherwise, send a message to the user
  390. gNotifications.add("ExistsPresetAlert");
  391. return false;
  392. }
  393. gWLSkyParamMgr.mDay.saveDayCycle(name);
  394. self->refreshNames(name);
  395. // Sync it all up
  396. self->onChangeDayCycle(self->mWLDayCycleCombo, self);
  397. return false;
  398. }
  399. //static
  400. void LLPanelWLDayCycle::onNewDayCycle(void* userdata)
  401. {
  402. gNotifications.add("NewDayCycle", LLSD(), LLSD(), newPromptCallback);
  403. }
  404. //static
  405. bool LLPanelWLDayCycle::saveAlertCallback(const LLSD& notification,
  406. const LLSD& response)
  407. {
  408. if (LLNotification::getSelectedOption(notification, response) == 0)
  409. {
  410. std::string name = notification["payload"]["name"].asString();
  411. gWLSkyParamMgr.mDay.saveDayCycle(name + ".xml");
  412. }
  413. return false;
  414. }
  415. //static
  416. void LLPanelWLDayCycle::onSaveDayCycle(void* userdata)
  417. {
  418. LLPanelWLDayCycle* self = (LLPanelWLDayCycle*)userdata;
  419. if (!self) return;
  420. // Get the name
  421. std::string name = self->mWLDayCycleCombo->getSelectedItemLabel();
  422. if (!name.empty()) // Do not save with an empty name
  423. {
  424. LLSD payload;
  425. payload["name"] = name;
  426. gNotifications.add("WLSavePresetAlert", LLSD(), payload,
  427. saveAlertCallback);
  428. }
  429. }
  430. //static
  431. bool LLPanelWLDayCycle::deleteAlertCallback(const LLSD& notification,
  432. const LLSD& response)
  433. {
  434. LLPanelWLDayCycle* self = getSelf();
  435. if (!self || LLNotification::getSelectedOption(notification, response))
  436. {
  437. return false;
  438. }
  439. LLComboBox* combo = self->mWLDayCycleCombo;
  440. std::string name = combo->getSelectedValue().asString();
  441. if (name.empty())
  442. {
  443. return false;
  444. }
  445. #if 0 // We do not care: only the user settings get deleted
  446. // Check to see if it is a default and should not be deleted
  447. if (name == "Default")
  448. {
  449. gNotifications.add("PresetNoEditDefault");
  450. return false;
  451. }
  452. #endif
  453. LLWLDayCycle::removeDayCycle(name);
  454. self->refreshNames();
  455. // Sync it all up
  456. self->onChangeDayCycle(self->mWLDayCycleCombo, self);
  457. return false;
  458. }
  459. //static
  460. void LLPanelWLDayCycle::onDeleteDayCycle(void* userdata)
  461. {
  462. LLPanelWLDayCycle* self = (LLPanelWLDayCycle*)userdata;
  463. if (!self) return;
  464. std::string name = self->mWLDayCycleCombo->getSelectedValue().asString();
  465. if (!name.empty())
  466. {
  467. LLSD args;
  468. args["NAME"] = name;
  469. gNotifications.add("WLDeletePresetAlert", args, LLSD(),
  470. deleteAlertCallback);
  471. }
  472. }
  473. //static
  474. void LLPanelWLDayCycle::onTimeSliderMoved(LLUICtrl* ctrl, void* userdata)
  475. {
  476. LLPanelWLDayCycle* self = (LLPanelWLDayCycle*)userdata;
  477. if (!self) return;
  478. F32 val = self->mWLTimeSlider->getCurSliderValue() / HOUR_PER_DAY;
  479. LLFloaterWindlight::setDayTime(val);
  480. }
  481. //static
  482. void LLPanelWLDayCycle::onKeyTimeMoved(LLUICtrl* ctrl, void* userdata)
  483. {
  484. LLPanelWLDayCycle* self = (LLPanelWLDayCycle*)userdata;
  485. if (!self) return;
  486. LLComboBox* combo = self->mWLKeyPresets;
  487. LLMultiSliderCtrl* slider = self->mWLDayCycleKeys;
  488. if (slider->getValue().size() == 0)
  489. {
  490. return;
  491. }
  492. // Make sure we have a slider
  493. const std::string& cur_slider = slider->getCurSlider();
  494. if (cur_slider.empty())
  495. {
  496. return;
  497. }
  498. F32 time = slider->getCurSliderValue();
  499. // Check to see if a key exists
  500. std::string name = sSliderToKey[cur_slider].mPresetName;
  501. sSliderToKey[cur_slider].mTime = time;
  502. // If it exists, turn on check box
  503. combo->selectByValue(name);
  504. // Now set the spinners
  505. F32 hour = (F32)((S32)time);
  506. F32 min = (time - hour) * 60;
  507. // handle imprecision
  508. if (min >= 59.f)
  509. {
  510. min = 0.f;
  511. hour += 1.f;
  512. }
  513. self->mWLCurKeyHour->set(hour);
  514. self->mWLCurKeyMin->set(min);
  515. self->syncTrack();
  516. }
  517. //static
  518. void LLPanelWLDayCycle::onKeyTimeChanged(LLUICtrl* ctrl, void* userdata)
  519. {
  520. LLPanelWLDayCycle* self = (LLPanelWLDayCycle*)userdata;
  521. if (!self) return;
  522. // If no keys, skipped
  523. if (sSliderToKey.size() == 0)
  524. {
  525. return;
  526. }
  527. LLMultiSliderCtrl* slider = self->mWLDayCycleKeys;
  528. F32 hour = self->mWLCurKeyHour->get();
  529. F32 min = self->mWLCurKeyMin->get();
  530. F32 val = hour + min / 60.0f;
  531. const std::string& cur_slider = slider->getCurSlider();
  532. slider->setCurSliderValue(val, true);
  533. F32 time = slider->getCurSliderValue() / HOUR_PER_DAY;
  534. // Now set the key's time in the sliderToKey map
  535. sSliderToKey[cur_slider].mTime = time;
  536. self->syncTrack();
  537. }
  538. //static
  539. void LLPanelWLDayCycle::onKeyPresetChanged(LLUICtrl* ctrl, void* userdata)
  540. {
  541. LLPanelWLDayCycle* self = (LLPanelWLDayCycle*)userdata;
  542. if (!self) return;
  543. // Get the time
  544. LLComboBox* combo = self->mWLKeyPresets;
  545. LLMultiSliderCtrl* slider = self->mWLDayCycleKeys;
  546. // Do nothing if no sliders
  547. if (slider->getValue().size() == 0)
  548. {
  549. return;
  550. }
  551. // Change the map
  552. const std::string& cur_slider = slider->getCurSlider();
  553. // If empty, do not use
  554. if (cur_slider.empty())
  555. {
  556. return;
  557. }
  558. std::string name = combo->getSelectedValue().asString();
  559. sSliderToKey[cur_slider].mPresetName = name;
  560. self->syncTrack();
  561. }
  562. //static
  563. void LLPanelWLDayCycle::onTimeRateChanged(LLUICtrl* ctrl, void* userdata)
  564. {
  565. LLPanelWLDayCycle* self = (LLPanelWLDayCycle*)userdata;
  566. if (!self) return;
  567. // Get the time
  568. F32 hour = self->mWLLengthOfDayHour->getValue().asReal();
  569. F32 min = self->mWLLengthOfDayMin->getValue().asReal();
  570. F32 sec = self->mWLLengthOfDaySec->getValue().asReal();
  571. F32 time = 3600.f * hour + 60.f * min + sec;
  572. if (time <= 0.f)
  573. {
  574. time = 1.f;
  575. }
  576. gWLSkyParamMgr.mDay.mDayLenth = time;
  577. self->syncTrack();
  578. }
  579. //static
  580. void LLPanelWLDayCycle::onAddKey(void* userdata)
  581. {
  582. LLPanelWLDayCycle* self = (LLPanelWLDayCycle*)userdata;
  583. if (!self) return;
  584. // Get the values
  585. std::string name = self->mWLKeyPresets->getSelectedValue().asString();
  586. // Add the slider key
  587. self->addSliderKey(self->mWLTimeSlider->getCurSliderValue(), name);
  588. self->syncTrack();
  589. }
  590. //static
  591. void LLPanelWLDayCycle::onDeleteKey(void* userdata)
  592. {
  593. LLPanelWLDayCycle* self = (LLPanelWLDayCycle*)userdata;
  594. if (!self || sSliderToKey.size() == 0)
  595. {
  596. return;
  597. }
  598. LLMultiSliderCtrl* slider = self->mWLDayCycleKeys;
  599. // Delete from map
  600. const std::string& slider_name = slider->getCurSlider();
  601. skykey_map_t::iterator it = sSliderToKey.find(slider_name);
  602. if (it != sSliderToKey.end())
  603. {
  604. sSliderToKey.erase(it);
  605. }
  606. slider->deleteCurSlider();
  607. if (sSliderToKey.size() == 0)
  608. {
  609. return;
  610. }
  611. const std::string& name = slider->getCurSlider();
  612. self->mWLKeyPresets->selectByValue(sSliderToKey[name].mPresetName);
  613. F32 time = sSliderToKey[name].mTime;
  614. F32 hour = (F32)((S32)time);
  615. F32 min = (time - hour) / 60;
  616. // Now set the spinners
  617. self->mWLCurKeyHour->set(hour);
  618. self->mWLCurKeyMin->set(min);
  619. self->syncTrack();
  620. }
  621. ///////////////////////////////////////////////////////////////////////////////
  622. // LLPanelWLSky class (used to be a separate floater in LL's viewer)
  623. ///////////////////////////////////////////////////////////////////////////////
  624. class LLPanelWLSky final : public LLPanel
  625. {
  626. protected:
  627. LOG_CLASS(LLPanelWLSky);
  628. public:
  629. LLPanelWLSky(const std::string& name)
  630. : LLPanel(name)
  631. {
  632. }
  633. ~LLPanelWLSky() override
  634. {
  635. }
  636. bool postBuild() override;
  637. void refresh() override;
  638. private:
  639. static LLPanelWLSky* getSelf();
  640. static void onColorControlRMoved(LLUICtrl* ctrl, void* userdata);
  641. static void onColorControlGMoved(LLUICtrl* ctrl, void* userdata);
  642. static void onColorControlBMoved(LLUICtrl* ctrl, void* userdata);
  643. static void onColorControlIMoved(LLUICtrl* ctrl, void* userdata);
  644. static void onFloatControlMoved(LLUICtrl* ctrl, void* userdata);
  645. static void onGlowRMoved(LLUICtrl* ctrl, void* userdata);
  646. static void onGlowBMoved(LLUICtrl* ctrl, void* userdata);
  647. static void onSunMoved(LLUICtrl* ctrl, void* userdata);
  648. static void onStarAlphaMoved(LLUICtrl* ctrl, void*);
  649. static void onCloudScrollXMoved(LLUICtrl* ctrl, void*);
  650. static void onCloudScrollYMoved(LLUICtrl* ctrl, void*);
  651. static void onCloudScrollXToggled(LLUICtrl* ctrl, void* userdata);
  652. static void onCloudScrollYToggled(LLUICtrl* ctrl, void* userdata);
  653. static void onNewPreset(void*);
  654. static void onSavePreset(void* userdata);
  655. static void onDeletePreset(void* userdata);
  656. static void onChangePresetName(LLUICtrl* ctrl, void* userdata);
  657. static bool newPromptCallback(const LLSD& notification,
  658. const LLSD& response);
  659. static bool saveAlertCallback(const LLSD& notification,
  660. const LLSD& response);
  661. static bool deleteAlertCallback(const LLSD& notification,
  662. const LLSD& response);
  663. private:
  664. LLCheckBoxCtrl* mWLCloudLockX;
  665. LLCheckBoxCtrl* mWLCloudLockY;
  666. LLComboBox* mWLPresetsCombo;
  667. LLSliderCtrl* mWLBlueHorizonR;
  668. LLSliderCtrl* mWLBlueHorizonG;
  669. LLSliderCtrl* mWLBlueHorizonB;
  670. LLSliderCtrl* mWLBlueHorizonI;
  671. LLSliderCtrl* mWLHazeDensity;
  672. LLSliderCtrl* mWLHazeHorizon;
  673. LLSliderCtrl* mWLDensityMult;
  674. LLSliderCtrl* mWLMaxAltitude;
  675. LLSliderCtrl* mWLBlueDensityR;
  676. LLSliderCtrl* mWLBlueDensityG;
  677. LLSliderCtrl* mWLBlueDensityB;
  678. LLSliderCtrl* mWLBlueDensityI;
  679. LLSliderCtrl* mWLSunlightR;
  680. LLSliderCtrl* mWLSunlightG;
  681. LLSliderCtrl* mWLSunlightB;
  682. LLSliderCtrl* mWLSunlightI;
  683. LLSliderCtrl* mWLGlowR;
  684. LLSliderCtrl* mWLGlowB;
  685. LLSliderCtrl* mWLAmbientR;
  686. LLSliderCtrl* mWLAmbientG;
  687. LLSliderCtrl* mWLAmbientB;
  688. LLSliderCtrl* mWLAmbientI;
  689. LLSliderCtrl* mWLSunAngle;
  690. LLSliderCtrl* mWLEastAngle;
  691. LLSliderCtrl* mWLCloudColorR;
  692. LLSliderCtrl* mWLCloudColorG;
  693. LLSliderCtrl* mWLCloudColorB;
  694. LLSliderCtrl* mWLCloudColorI;
  695. LLSliderCtrl* mWLCloudX;
  696. LLSliderCtrl* mWLCloudY;
  697. LLSliderCtrl* mWLCloudDensity;
  698. LLSliderCtrl* mWLCloudDetailX;
  699. LLSliderCtrl* mWLCloudDetailY;
  700. LLSliderCtrl* mWLCloudDetailDensity;
  701. LLSliderCtrl* mWLCloudCoverage;
  702. LLSliderCtrl* mWLCloudScale;
  703. LLSliderCtrl* mWLCloudScrollX;
  704. LLSliderCtrl* mWLCloudScrollY;
  705. LLSliderCtrl* mWLDistanceMult;
  706. LLSliderCtrl* mWLGamma;
  707. LLSliderCtrl* mWLStarAlpha;
  708. typedef std::set<std::string> presets_list_t;
  709. static presets_list_t sDefaultPresets;
  710. };
  711. //static
  712. LLPanelWLSky* LLPanelWLSky::getSelf()
  713. {
  714. LLFloaterWindlight* wlp = LLFloaterWindlight::findInstance();
  715. return wlp ? wlp->mPanelSky : NULL;
  716. }
  717. constexpr F32 SUN_AMBIENT_SLIDER_FACTOR = 1.f / 3.f;
  718. LLPanelWLSky::presets_list_t LLPanelWLSky::sDefaultPresets;
  719. //virtual
  720. bool LLPanelWLSky::postBuild()
  721. {
  722. // Presets
  723. std::string def_days = getString("WLDefaultSkyNames");
  724. // No editing or deleting of the blank string
  725. sDefaultPresets.emplace("");
  726. typedef boost::tokenizer<boost::char_separator<char> > boost_tokenizer;
  727. boost_tokenizer tokens(def_days, boost::char_separator<char>(":"));
  728. for (boost_tokenizer::iterator token_iter = tokens.begin();
  729. token_iter != tokens.end(); ++token_iter)
  730. {
  731. std::string tok(*token_iter);
  732. sDefaultPresets.emplace(tok);
  733. }
  734. mWLPresetsCombo = getChild<LLComboBox>("WLPresetsCombo");
  735. for (LLWLSkyParamMgr::paramset_map_t::iterator
  736. it = gWLSkyParamMgr.mParamList.begin(),
  737. end = gWLSkyParamMgr.mParamList.end();
  738. it != end; ++it)
  739. {
  740. mWLPresetsCombo->add(it->first);
  741. }
  742. // Entry for when we are in estate time
  743. mWLPresetsCombo->add(LLStringUtil::null);
  744. // Set default on combo box
  745. mWLPresetsCombo->selectByValue(LLSD("Default"));
  746. mWLPresetsCombo->setCommitCallback(onChangePresetName);
  747. mWLPresetsCombo->setCallbackUserData(this);
  748. // Blue horizon
  749. mWLBlueHorizonR = getChild<LLSliderCtrl>("WLBlueHorizonR");
  750. mWLBlueHorizonR->setCommitCallback(onColorControlRMoved);
  751. mWLBlueHorizonR->setCallbackUserData(&gWLSkyParamMgr.mBlueHorizon);
  752. mWLBlueHorizonG = getChild<LLSliderCtrl>("WLBlueHorizonG");
  753. mWLBlueHorizonG->setCommitCallback(onColorControlGMoved);
  754. mWLBlueHorizonG->setCallbackUserData(&gWLSkyParamMgr.mBlueHorizon);
  755. mWLBlueHorizonB = getChild<LLSliderCtrl>("WLBlueHorizonB");
  756. mWLBlueHorizonB->setCommitCallback(onColorControlBMoved);
  757. mWLBlueHorizonB->setCallbackUserData(&gWLSkyParamMgr.mBlueHorizon);
  758. mWLBlueHorizonI = getChild<LLSliderCtrl>("WLBlueHorizonI");
  759. mWLBlueHorizonI->setCommitCallback(onColorControlIMoved);
  760. mWLBlueHorizonI->setCallbackUserData(&gWLSkyParamMgr.mBlueHorizon);
  761. // Haze: density, horizon, multiplier and max altitude
  762. mWLHazeDensity = getChild<LLSliderCtrl>("WLHazeDensity");
  763. mWLHazeDensity->setCommitCallback(onColorControlRMoved);
  764. mWLHazeDensity->setCallbackUserData(&gWLSkyParamMgr.mHazeDensity);
  765. mWLHazeHorizon = getChild<LLSliderCtrl>("WLHazeHorizon");
  766. mWLHazeHorizon->setCommitCallback(onColorControlRMoved);
  767. mWLHazeHorizon->setCallbackUserData(&gWLSkyParamMgr.mHazeHorizon);
  768. mWLDensityMult = getChild<LLSliderCtrl>("WLDensityMult");
  769. mWLDensityMult->setCommitCallback(onFloatControlMoved);
  770. mWLDensityMult->setCallbackUserData(&gWLSkyParamMgr.mDensityMult);
  771. mWLMaxAltitude = getChild<LLSliderCtrl>("WLMaxAltitude");
  772. mWLMaxAltitude->setCommitCallback(onFloatControlMoved);
  773. mWLMaxAltitude->setCallbackUserData(&gWLSkyParamMgr.mMaxAlt);
  774. // Blue density
  775. mWLBlueDensityR = getChild<LLSliderCtrl>("WLBlueDensityR");
  776. mWLBlueDensityR->setCommitCallback(onColorControlRMoved);
  777. mWLBlueDensityR->setCallbackUserData(&gWLSkyParamMgr.mBlueDensity);
  778. mWLBlueDensityG = getChild<LLSliderCtrl>("WLBlueDensityG");
  779. mWLBlueDensityG->setCommitCallback(onColorControlGMoved);
  780. mWLBlueDensityG->setCallbackUserData(&gWLSkyParamMgr.mBlueDensity);
  781. mWLBlueDensityB = getChild<LLSliderCtrl>("WLBlueDensityB");
  782. mWLBlueDensityB->setCommitCallback(onColorControlBMoved);
  783. mWLBlueDensityB->setCallbackUserData(&gWLSkyParamMgr.mBlueDensity);
  784. mWLBlueDensityI = getChild<LLSliderCtrl>("WLBlueDensityI");
  785. mWLBlueDensityI->setCommitCallback(onColorControlIMoved);
  786. mWLBlueDensityI->setCallbackUserData(&gWLSkyParamMgr.mBlueDensity);
  787. // Sunlight
  788. mWLSunlightR = getChild<LLSliderCtrl>("WLSunlightR");
  789. mWLSunlightR->setCommitCallback(onColorControlRMoved);
  790. mWLSunlightR->setCallbackUserData(&gWLSkyParamMgr.mSunlight);
  791. mWLSunlightG = getChild<LLSliderCtrl>("WLSunlightG");
  792. mWLSunlightG->setCommitCallback(onColorControlGMoved);
  793. mWLSunlightG->setCallbackUserData(&gWLSkyParamMgr.mSunlight);
  794. mWLSunlightB = getChild<LLSliderCtrl>("WLSunlightB");
  795. mWLSunlightB->setCommitCallback(onColorControlBMoved);
  796. mWLSunlightB->setCallbackUserData(&gWLSkyParamMgr.mSunlight);
  797. mWLSunlightI = getChild<LLSliderCtrl>("WLSunlightI");
  798. mWLSunlightI->setCommitCallback(onColorControlIMoved);
  799. mWLSunlightI->setCallbackUserData(&gWLSkyParamMgr.mSunlight);
  800. // Glow
  801. mWLGlowR = getChild<LLSliderCtrl>("WLGlowR");
  802. mWLGlowR->setCommitCallback(onGlowRMoved);
  803. mWLGlowR->setCallbackUserData(&gWLSkyParamMgr.mGlow);
  804. mWLGlowB = getChild<LLSliderCtrl>("WLGlowB");
  805. mWLGlowB->setCommitCallback(onGlowBMoved);
  806. mWLGlowB->setCallbackUserData(&gWLSkyParamMgr.mGlow);
  807. // Ambient
  808. mWLAmbientR = getChild<LLSliderCtrl>("WLAmbientR");
  809. mWLAmbientR->setCommitCallback(onColorControlRMoved);
  810. mWLAmbientR->setCallbackUserData(&gWLSkyParamMgr.mAmbient);
  811. mWLAmbientG = getChild<LLSliderCtrl>("WLAmbientG");
  812. mWLAmbientG->setCommitCallback(onColorControlGMoved);
  813. mWLAmbientG->setCallbackUserData(&gWLSkyParamMgr.mAmbient);
  814. mWLAmbientB = getChild<LLSliderCtrl>("WLAmbientB");
  815. mWLAmbientB->setCommitCallback(onColorControlBMoved);
  816. mWLAmbientB->setCallbackUserData(&gWLSkyParamMgr.mAmbient);
  817. mWLAmbientI = getChild<LLSliderCtrl>("WLAmbientI");
  818. mWLAmbientI->setCommitCallback(onColorControlIMoved);
  819. mWLAmbientI->setCallbackUserData(&gWLSkyParamMgr.mAmbient);
  820. // Time of day
  821. mWLSunAngle = getChild<LLSliderCtrl>("WLSunAngle");
  822. mWLSunAngle->setCommitCallback(onSunMoved);
  823. mWLSunAngle->setCallbackUserData(&gWLSkyParamMgr.mLightnorm);
  824. mWLEastAngle = getChild<LLSliderCtrl>("WLEastAngle");
  825. mWLEastAngle->setCommitCallback(onSunMoved);
  826. mWLEastAngle->setCallbackUserData(&gWLSkyParamMgr.mLightnorm);
  827. // Clouds color
  828. mWLCloudColorR = getChild<LLSliderCtrl>("WLCloudColorR");
  829. mWLCloudColorR->setCommitCallback(onColorControlRMoved);
  830. mWLCloudColorR->setCallbackUserData(&gWLSkyParamMgr.mCloudColor);
  831. mWLCloudColorG = getChild<LLSliderCtrl>("WLCloudColorG");
  832. mWLCloudColorG->setCommitCallback(onColorControlGMoved);
  833. mWLCloudColorG->setCallbackUserData(&gWLSkyParamMgr.mCloudColor);
  834. mWLCloudColorB = getChild<LLSliderCtrl>("WLCloudColorB");
  835. mWLCloudColorB->setCommitCallback(onColorControlBMoved);
  836. mWLCloudColorB->setCallbackUserData(&gWLSkyParamMgr.mCloudColor);
  837. mWLCloudColorI = getChild<LLSliderCtrl>("WLCloudColorI");
  838. mWLCloudColorI->setCommitCallback(onColorControlIMoved);
  839. mWLCloudColorI->setCallbackUserData(&gWLSkyParamMgr.mCloudColor);
  840. // Cloud main: speed and density
  841. mWLCloudX = getChild<LLSliderCtrl>("WLCloudX");
  842. mWLCloudX->setCommitCallback(onColorControlRMoved);
  843. mWLCloudX->setCallbackUserData(&gWLSkyParamMgr.mCloudMain);
  844. mWLCloudY = getChild<LLSliderCtrl>("WLCloudY");
  845. mWLCloudY->setCommitCallback(onColorControlGMoved);
  846. mWLCloudY->setCallbackUserData(&gWLSkyParamMgr.mCloudMain);
  847. mWLCloudDensity = getChild<LLSliderCtrl>("WLCloudDensity");
  848. mWLCloudDensity->setCommitCallback(onColorControlBMoved);
  849. mWLCloudDensity->setCallbackUserData(&gWLSkyParamMgr.mCloudMain);
  850. // Cloud detail: speed and density
  851. mWLCloudDetailX = getChild<LLSliderCtrl>("WLCloudDetailX");
  852. mWLCloudDetailX->setCommitCallback(onColorControlRMoved);
  853. mWLCloudDetailX->setCallbackUserData(&gWLSkyParamMgr.mCloudDetail);
  854. mWLCloudDetailY = getChild<LLSliderCtrl>("WLCloudDetailY");
  855. mWLCloudDetailY->setCommitCallback(onColorControlGMoved);
  856. mWLCloudDetailY->setCallbackUserData(&gWLSkyParamMgr.mCloudDetail);
  857. mWLCloudDetailDensity = getChild<LLSliderCtrl>("WLCloudDetailDensity");
  858. mWLCloudDetailDensity->setCommitCallback(onColorControlBMoved);
  859. mWLCloudDetailDensity->setCallbackUserData(&gWLSkyParamMgr.mCloudDetail);
  860. // Cloud misc: coverage, scale, locking, scrolling and distance multipler
  861. mWLCloudCoverage = getChild<LLSliderCtrl>("WLCloudCoverage");
  862. mWLCloudCoverage->setCommitCallback(onFloatControlMoved);
  863. mWLCloudCoverage->setCallbackUserData(&gWLSkyParamMgr.mCloudCoverage);
  864. mWLCloudScale = getChild<LLSliderCtrl>("WLCloudScale");
  865. mWLCloudScale->setCommitCallback(onFloatControlMoved);
  866. mWLCloudScale->setCallbackUserData(&gWLSkyParamMgr.mCloudScale);
  867. mWLCloudLockX = getChild<LLCheckBoxCtrl>("WLCloudLockX");
  868. mWLCloudLockX->setCommitCallback(onCloudScrollXToggled);
  869. mWLCloudLockX->setCallbackUserData(this);
  870. mWLCloudLockY = getChild<LLCheckBoxCtrl>("WLCloudLockY");
  871. mWLCloudLockY->setCommitCallback(onCloudScrollYToggled);
  872. mWLCloudLockY->setCallbackUserData(this);
  873. mWLCloudScrollX = getChild<LLSliderCtrl>("WLCloudScrollX");
  874. mWLCloudScrollX->setCommitCallback(onCloudScrollXMoved);
  875. mWLCloudScrollX->setCallbackUserData(this);
  876. mWLCloudScrollY = getChild<LLSliderCtrl>("WLCloudScrollY");
  877. mWLCloudScrollY->setCommitCallback(onCloudScrollYMoved);
  878. mWLCloudScrollY->setCallbackUserData(this);
  879. mWLDistanceMult = getChild<LLSliderCtrl>("WLDistanceMult");
  880. mWLDistanceMult->setCommitCallback(onFloatControlMoved);
  881. mWLDistanceMult->setCallbackUserData(&gWLSkyParamMgr.mDistanceMult);
  882. // Dome
  883. mWLGamma = getChild<LLSliderCtrl>("WLGamma");
  884. mWLGamma->setCommitCallback(onFloatControlMoved);
  885. mWLGamma->setCallbackUserData(&gWLSkyParamMgr.mWLGamma);
  886. mWLStarAlpha = getChild<LLSliderCtrl>("WLStarAlpha");
  887. mWLStarAlpha->setCommitCallback(onStarAlphaMoved);
  888. mWLStarAlpha->setCallbackUserData(this);
  889. // Load/save/delete
  890. childSetAction("WLNewPreset", onNewPreset, this);
  891. childSetAction("WLSavePreset", onSavePreset, this);
  892. childSetAction("WLDeletePreset", onDeletePreset, this);
  893. refresh();
  894. return true;
  895. }
  896. //virtual
  897. void LLPanelWLSky::refresh()
  898. {
  899. LLWLParamSet& cur_params = gWLSkyParamMgr.mCurParams;
  900. bool err;
  901. // Blue horizon
  902. gWLSkyParamMgr.mBlueHorizon =
  903. cur_params.getVector(gWLSkyParamMgr.mBlueHorizon.mName, err);
  904. F32 red = gWLSkyParamMgr.mBlueHorizon.r * 0.5f;
  905. F32 green = gWLSkyParamMgr.mBlueHorizon.g * 0.5f;
  906. F32 blue = gWLSkyParamMgr.mBlueHorizon.b * 0.5f;
  907. mWLBlueHorizonR->setValue(red);
  908. mWLBlueHorizonG->setValue(green);
  909. mWLBlueHorizonB->setValue(blue);
  910. mWLBlueHorizonI->setValue(llmax(red, green, blue));
  911. // Haze: density, horizon, multiplier and altitude
  912. gWLSkyParamMgr.mHazeDensity =
  913. cur_params.getVector(gWLSkyParamMgr.mHazeDensity.mName, err);
  914. mWLHazeDensity->setValue(gWLSkyParamMgr.mHazeDensity.r);
  915. gWLSkyParamMgr.mHazeHorizon =
  916. cur_params.getVector(gWLSkyParamMgr.mHazeHorizon.mName, err);
  917. mWLHazeHorizon->setValue(gWLSkyParamMgr.mHazeHorizon.r);
  918. gWLSkyParamMgr.mDensityMult =
  919. cur_params.getVector(gWLSkyParamMgr.mDensityMult.mName, err);
  920. mWLDensityMult->setValue(gWLSkyParamMgr.mDensityMult.x *
  921. gWLSkyParamMgr.mDensityMult.mult);
  922. gWLSkyParamMgr.mMaxAlt = cur_params.getVector(gWLSkyParamMgr.mMaxAlt.mName,
  923. err);
  924. mWLMaxAltitude->setValue(gWLSkyParamMgr.mMaxAlt.x);
  925. // Blue density
  926. gWLSkyParamMgr.mBlueDensity =
  927. cur_params.getVector(gWLSkyParamMgr.mBlueDensity.mName, err);
  928. red = gWLSkyParamMgr.mBlueDensity.r * 0.5f;
  929. green = gWLSkyParamMgr.mBlueDensity.g * 0.5f;
  930. blue = gWLSkyParamMgr.mBlueDensity.b * 0.5f;
  931. mWLBlueDensityR->setValue(red);
  932. mWLBlueDensityG->setValue(green);
  933. mWLBlueDensityB->setValue(blue);
  934. mWLBlueDensityI->setValue(llmax(red, green, blue));
  935. // Lighting
  936. // Sunlight
  937. gWLSkyParamMgr.mSunlight =
  938. cur_params.getVector(gWLSkyParamMgr.mSunlight.mName, err);
  939. red = gWLSkyParamMgr.mSunlight.r * SUN_AMBIENT_SLIDER_FACTOR;
  940. green = gWLSkyParamMgr.mSunlight.g * SUN_AMBIENT_SLIDER_FACTOR;
  941. blue = gWLSkyParamMgr.mSunlight.b * SUN_AMBIENT_SLIDER_FACTOR;
  942. mWLSunlightR->setValue(red);
  943. mWLSunlightG->setValue(green);
  944. mWLSunlightB->setValue(blue);
  945. mWLSunlightI->setValue(llmax(red, green, blue));
  946. // Glow
  947. gWLSkyParamMgr.mGlow = cur_params.getVector(gWLSkyParamMgr.mGlow.mName,
  948. err);
  949. mWLGlowR->setValue(2.f - gWLSkyParamMgr.mGlow.r / 20.f);
  950. mWLGlowB->setValue(gWLSkyParamMgr.mGlow.b / -5.f);
  951. // Ambient
  952. gWLSkyParamMgr.mAmbient =
  953. cur_params.getVector(gWLSkyParamMgr.mAmbient.mName, err);
  954. red = gWLSkyParamMgr.mAmbient.r * SUN_AMBIENT_SLIDER_FACTOR;
  955. green = gWLSkyParamMgr.mAmbient.g * SUN_AMBIENT_SLIDER_FACTOR;
  956. blue = gWLSkyParamMgr.mAmbient.b * SUN_AMBIENT_SLIDER_FACTOR;
  957. mWLAmbientR->setValue(red);
  958. mWLAmbientG->setValue(green);
  959. mWLAmbientB->setValue(blue);
  960. mWLAmbientI->setValue(llmax(red, green, blue));
  961. // Sun angles
  962. constexpr F32 TWO_PI_INV = 1.f / F_TWO_PI;
  963. F32 value = cur_params.getFloat("sun_angle", err);
  964. mWLSunAngle->setValue(value * TWO_PI_INV);
  965. value = cur_params.getFloat("east_angle", err);
  966. mWLEastAngle->setValue(value * TWO_PI_INV);
  967. // Clouds color
  968. gWLSkyParamMgr.mCloudColor =
  969. cur_params.getVector(gWLSkyParamMgr.mCloudColor.mName, err);
  970. red = gWLSkyParamMgr.mCloudColor.r;
  971. green = gWLSkyParamMgr.mCloudColor.g;
  972. blue = gWLSkyParamMgr.mCloudColor.b;
  973. mWLCloudColorR->setValue(red);
  974. mWLCloudColorG->setValue(green);
  975. mWLCloudColorB->setValue(blue);
  976. mWLCloudColorI->setValue(llmax(red, green, blue));
  977. // Cloud main
  978. gWLSkyParamMgr.mCloudMain =
  979. cur_params.getVector(gWLSkyParamMgr.mCloudMain.mName, err);
  980. mWLCloudX->setValue(gWLSkyParamMgr.mCloudMain.r);
  981. mWLCloudY->setValue(gWLSkyParamMgr.mCloudMain.g);
  982. mWLCloudDensity->setValue(gWLSkyParamMgr.mCloudMain.b);
  983. // Cloud detail
  984. gWLSkyParamMgr.mCloudDetail =
  985. cur_params.getVector(gWLSkyParamMgr.mCloudDetail.mName, err);
  986. mWLCloudDetailX->setValue(gWLSkyParamMgr.mCloudDetail.r);
  987. mWLCloudDetailY->setValue(gWLSkyParamMgr.mCloudDetail.g);
  988. mWLCloudDetailDensity->setValue(gWLSkyParamMgr.mCloudDetail.b);
  989. // Cloud coverage
  990. gWLSkyParamMgr.mCloudCoverage =
  991. cur_params.getVector(gWLSkyParamMgr.mCloudCoverage.mName, err);
  992. mWLCloudCoverage->setValue(gWLSkyParamMgr.mCloudCoverage.x);
  993. // Cloud scale
  994. gWLSkyParamMgr.mCloudScale =
  995. cur_params.getVector(gWLSkyParamMgr.mCloudScale.mName, err);
  996. mWLCloudScale->setValue(gWLSkyParamMgr.mCloudScale.x);
  997. // Cloud scrolling. BEWARE: Windlight uses an offset of 10 for these.
  998. bool lock_x = !cur_params.getEnableCloudScrollX();
  999. mWLCloudLockX->set(lock_x);
  1000. mWLCloudScrollX->setEnabled(!lock_x);
  1001. mWLCloudScrollX->setValue(cur_params.getCloudScrollX() - 10.f);
  1002. bool lock_y = !cur_params.getEnableCloudScrollY();
  1003. mWLCloudLockY->set(lock_y);
  1004. mWLCloudScrollY->setEnabled(!lock_y);
  1005. mWLCloudScrollY->setValue(cur_params.getCloudScrollY() - 10.f);
  1006. gWLSkyParamMgr.mDistanceMult =
  1007. cur_params.getVector(gWLSkyParamMgr.mDistanceMult.mName, err);
  1008. mWLDistanceMult->setValue(gWLSkyParamMgr.mDistanceMult.x);
  1009. // Dome
  1010. gWLSkyParamMgr.mWLGamma =
  1011. cur_params.getVector(gWLSkyParamMgr.mWLGamma.mName, err);
  1012. mWLGamma->setValue(gWLSkyParamMgr.mWLGamma.x);
  1013. mWLStarAlpha->setValue(cur_params.getStarBrightness());
  1014. }
  1015. //static
  1016. void LLPanelWLSky::onColorControlRMoved(LLUICtrl* ctrl, void* userdata)
  1017. {
  1018. LLPanelWLSky* self = getSelf();
  1019. if (!self || !ctrl || !userdata) return;
  1020. LLSliderCtrl* slider = (LLSliderCtrl*)ctrl;
  1021. WLColorControl* color_ctrl = (WLColorControl*)userdata;
  1022. gWLSkyParamMgr.animate(false);
  1023. color_ctrl->r = slider->getValueF32();
  1024. if (color_ctrl->isSunOrAmbientColor)
  1025. {
  1026. color_ctrl->r *= 3.f;
  1027. }
  1028. if (color_ctrl->isBlueHorizonOrDensity)
  1029. {
  1030. color_ctrl->r *= 2.f;
  1031. }
  1032. // Move i if it is the max
  1033. if (color_ctrl->r >= color_ctrl->g &&
  1034. color_ctrl->r >= color_ctrl->b &&
  1035. color_ctrl->hasSliderName)
  1036. {
  1037. color_ctrl->i = color_ctrl->r;
  1038. std::string name = color_ctrl->mSliderName;
  1039. name.append("I");
  1040. if (color_ctrl->isSunOrAmbientColor)
  1041. {
  1042. self->childSetValue(name.c_str(), color_ctrl->r / 3.f);
  1043. }
  1044. else if (color_ctrl->isBlueHorizonOrDensity)
  1045. {
  1046. self->childSetValue(name.c_str(), color_ctrl->r * 0.5f);
  1047. }
  1048. else
  1049. {
  1050. self->childSetValue(name.c_str(), color_ctrl->r);
  1051. }
  1052. }
  1053. color_ctrl->update(gWLSkyParamMgr.mCurParams);
  1054. gWLSkyParamMgr.propagateParameters();
  1055. }
  1056. //static
  1057. void LLPanelWLSky::onColorControlGMoved(LLUICtrl* ctrl, void* userdata)
  1058. {
  1059. LLPanelWLSky* self = getSelf();
  1060. if (!self || !ctrl || !userdata) return;
  1061. LLSliderCtrl* slider = (LLSliderCtrl*)ctrl;
  1062. WLColorControl* color_ctrl = (WLColorControl*)userdata;
  1063. gWLSkyParamMgr.animate(false);
  1064. color_ctrl->g = slider->getValueF32();
  1065. if (color_ctrl->isSunOrAmbientColor)
  1066. {
  1067. color_ctrl->g *= 3.f;
  1068. }
  1069. if (color_ctrl->isBlueHorizonOrDensity)
  1070. {
  1071. color_ctrl->g *= 2.f;
  1072. }
  1073. // Move i if it is the max
  1074. if (color_ctrl->g >= color_ctrl->r &&
  1075. color_ctrl->g >= color_ctrl->b &&
  1076. color_ctrl->hasSliderName)
  1077. {
  1078. color_ctrl->i = color_ctrl->g;
  1079. std::string name = color_ctrl->mSliderName;
  1080. name.append("I");
  1081. if (color_ctrl->isSunOrAmbientColor)
  1082. {
  1083. self->childSetValue(name.c_str(), color_ctrl->g / 3.f);
  1084. }
  1085. else if (color_ctrl->isBlueHorizonOrDensity)
  1086. {
  1087. self->childSetValue(name.c_str(), color_ctrl->g * 0.5f);
  1088. }
  1089. else
  1090. {
  1091. self->childSetValue(name.c_str(), color_ctrl->g);
  1092. }
  1093. }
  1094. color_ctrl->update(gWLSkyParamMgr.mCurParams);
  1095. gWLSkyParamMgr.propagateParameters();
  1096. }
  1097. //static
  1098. void LLPanelWLSky::onColorControlBMoved(LLUICtrl* ctrl, void* userdata)
  1099. {
  1100. LLPanelWLSky* self = getSelf();
  1101. if (!self || !ctrl || !userdata) return;
  1102. LLSliderCtrl* slider = (LLSliderCtrl*)ctrl;
  1103. WLColorControl* color_ctrl = (WLColorControl*)userdata;
  1104. gWLSkyParamMgr.animate(false);
  1105. color_ctrl->b = slider->getValueF32();
  1106. if (color_ctrl->isSunOrAmbientColor)
  1107. {
  1108. color_ctrl->b *= 3.f;
  1109. }
  1110. if (color_ctrl->isBlueHorizonOrDensity)
  1111. {
  1112. color_ctrl->b *= 2.f;
  1113. }
  1114. // Move i if it is the max
  1115. if (color_ctrl->hasSliderName && color_ctrl->b >= color_ctrl->r &&
  1116. color_ctrl->b >= color_ctrl->g)
  1117. {
  1118. color_ctrl->i = color_ctrl->b;
  1119. std::string name = color_ctrl->mSliderName;
  1120. name.append("I");
  1121. if (color_ctrl->isSunOrAmbientColor)
  1122. {
  1123. self->childSetValue(name.c_str(), color_ctrl->b / 3.f);
  1124. }
  1125. else if (color_ctrl->isBlueHorizonOrDensity)
  1126. {
  1127. self->childSetValue(name.c_str(), color_ctrl->b * 0.5f);
  1128. }
  1129. else
  1130. {
  1131. self->childSetValue(name.c_str(), color_ctrl->b);
  1132. }
  1133. }
  1134. color_ctrl->update(gWLSkyParamMgr.mCurParams);
  1135. gWLSkyParamMgr.propagateParameters();
  1136. }
  1137. //static
  1138. void LLPanelWLSky::onColorControlIMoved(LLUICtrl* ctrl, void* userdata)
  1139. {
  1140. LLPanelWLSky* self = getSelf();
  1141. if (!self || !ctrl || !userdata) return;
  1142. gWLSkyParamMgr.animate(false);
  1143. LLSliderCtrl* slider = (LLSliderCtrl*)ctrl;
  1144. WLColorControl* color_ctrl = (WLColorControl*)userdata;
  1145. color_ctrl->i = slider->getValueF32();
  1146. // Only for sliders where we pass a name
  1147. if (color_ctrl->hasSliderName)
  1148. {
  1149. // Set it to the top
  1150. F32 max_val = llmax(color_ctrl->r, color_ctrl->g, color_ctrl->b);
  1151. F32 i_val;
  1152. if (color_ctrl->isSunOrAmbientColor)
  1153. {
  1154. i_val = color_ctrl->i * 3.f;
  1155. }
  1156. else if (color_ctrl->isBlueHorizonOrDensity)
  1157. {
  1158. i_val = color_ctrl->i * 2.f;
  1159. }
  1160. else
  1161. {
  1162. i_val = color_ctrl->i;
  1163. }
  1164. // Get the names of the other sliders
  1165. std::string r_name = color_ctrl->mSliderName;
  1166. r_name.append("R");
  1167. std::string g_name = color_ctrl->mSliderName;
  1168. g_name.append("G");
  1169. std::string b_name = color_ctrl->mSliderName;
  1170. b_name.append("B");
  1171. if (i_val == 0.f)
  1172. {
  1173. color_ctrl->r = color_ctrl->g = color_ctrl->b = 0.f;
  1174. }
  1175. else if (max_val == 0.f)
  1176. {
  1177. // If all at the start, set them all to the intensity
  1178. color_ctrl->r = color_ctrl->g = color_ctrl->b = i_val;
  1179. }
  1180. else
  1181. {
  1182. // Add delta amounts to each
  1183. F32 factor = 1.f + (i_val - max_val) / max_val;
  1184. color_ctrl->r *= factor;
  1185. color_ctrl->g *= factor;
  1186. color_ctrl->b *= factor;
  1187. }
  1188. // Divide sun color vals by three
  1189. if (color_ctrl->isSunOrAmbientColor)
  1190. {
  1191. constexpr F32 ONETHIRD = 1.f / 3.f;
  1192. self->childSetValue(r_name.c_str(), color_ctrl->r * ONETHIRD);
  1193. self->childSetValue(g_name.c_str(), color_ctrl->g * ONETHIRD);
  1194. self->childSetValue(b_name.c_str(), color_ctrl->b * ONETHIRD);
  1195. }
  1196. else if (color_ctrl->isBlueHorizonOrDensity)
  1197. {
  1198. self->childSetValue(r_name.c_str(), color_ctrl->r * 0.5f);
  1199. self->childSetValue(g_name.c_str(), color_ctrl->g * 0.5f);
  1200. self->childSetValue(b_name.c_str(), color_ctrl->b * 0.5f);
  1201. }
  1202. else
  1203. {
  1204. // Set the sliders to the new vals
  1205. self->childSetValue(r_name.c_str(), color_ctrl->r);
  1206. self->childSetValue(g_name.c_str(), color_ctrl->g);
  1207. self->childSetValue(b_name.c_str(), color_ctrl->b);
  1208. }
  1209. }
  1210. // Now update the current parameters and send them to shaders
  1211. color_ctrl->update(gWLSkyParamMgr.mCurParams);
  1212. gWLSkyParamMgr.propagateParameters();
  1213. }
  1214. //static
  1215. void LLPanelWLSky::onGlowRMoved(LLUICtrl* ctrl, void* userdata)
  1216. {
  1217. if (!ctrl || !userdata) return;
  1218. LLSliderCtrl* slider = (LLSliderCtrl*)ctrl;
  1219. WLColorControl* color_ctrl = (WLColorControl*)userdata;
  1220. gWLSkyParamMgr.animate(false);
  1221. // Scaled by 20
  1222. color_ctrl->r = (2.f - slider->getValueF32()) * 20.f;
  1223. color_ctrl->update(gWLSkyParamMgr.mCurParams);
  1224. gWLSkyParamMgr.propagateParameters();
  1225. }
  1226. //static
  1227. void LLPanelWLSky::onGlowBMoved(LLUICtrl* ctrl, void* userdata)
  1228. {
  1229. if (!ctrl || !userdata) return;
  1230. LLSliderCtrl* slider = (LLSliderCtrl*)ctrl;
  1231. WLColorControl* color_ctrl = (WLColorControl*)userdata;
  1232. gWLSkyParamMgr.animate(false);
  1233. // NOTE that we want NEGATIVE (-) B and NOT by 20 as 20 is too big
  1234. color_ctrl->b = -slider->getValueF32() * 5.f;
  1235. color_ctrl->update(gWLSkyParamMgr.mCurParams);
  1236. gWLSkyParamMgr.propagateParameters();
  1237. }
  1238. //static
  1239. void LLPanelWLSky::onFloatControlMoved(LLUICtrl* ctrl, void* userdata)
  1240. {
  1241. if (!ctrl || !userdata) return;
  1242. LLSliderCtrl* slider = (LLSliderCtrl*)ctrl;
  1243. WLFloatControl* float_ctrl = (WLFloatControl*)userdata;
  1244. gWLSkyParamMgr.animate(false);
  1245. float_ctrl->x = slider->getValueF32() / float_ctrl->mult;
  1246. float_ctrl->update(gWLSkyParamMgr.mCurParams);
  1247. gWLSkyParamMgr.propagateParameters();
  1248. }
  1249. //static
  1250. void LLPanelWLSky::onSunMoved(LLUICtrl* ctrl, void* userdata)
  1251. {
  1252. LLPanelWLSky* self = getSelf();
  1253. if (!self || !ctrl || !userdata) return;
  1254. WLColorControl* color_ctrl = (WLColorControl*)userdata;
  1255. gWLSkyParamMgr.animate(false);
  1256. LLWLParamSet& cur_params = gWLSkyParamMgr.mCurParams;
  1257. // Get the two angles
  1258. cur_params.setSunAngle(F_TWO_PI * self->mWLSunAngle->getValueF32());
  1259. cur_params.setEastAngle(F_TWO_PI * self->mWLEastAngle->getValueF32());
  1260. F32 sun_angle = cur_params.getSunAngle();
  1261. F32 east_angle = cur_params.getEastAngle();
  1262. // Set the sun vector
  1263. F32 cos_sun_angle = cosf(sun_angle);
  1264. color_ctrl->r = -sinf(east_angle) * cos_sun_angle;
  1265. color_ctrl->g = sinf(sun_angle);
  1266. color_ctrl->b = cosf(east_angle) * cos_sun_angle;
  1267. color_ctrl->i = 1.f;
  1268. color_ctrl->update(cur_params);
  1269. gWLSkyParamMgr.propagateParameters();
  1270. }
  1271. //static
  1272. void LLPanelWLSky::onStarAlphaMoved(LLUICtrl* ctrl, void*)
  1273. {
  1274. if (ctrl)
  1275. {
  1276. gWLSkyParamMgr.animate(false);
  1277. LLSliderCtrl* slider = (LLSliderCtrl*)ctrl;
  1278. gWLSkyParamMgr.mCurParams.setStarBrightness(slider->getValueF32());
  1279. }
  1280. }
  1281. //static
  1282. bool LLPanelWLSky::newPromptCallback(const LLSD& notification,
  1283. const LLSD& response)
  1284. {
  1285. LLPanelWLSky* self = getSelf();
  1286. if (!self || LLNotification::getSelectedOption(notification, response))
  1287. {
  1288. return false;
  1289. }
  1290. std::string text = response["message"].asString();
  1291. if (text.empty())
  1292. {
  1293. return false;
  1294. }
  1295. LLComboBox* combo = self->mWLPresetsCombo;
  1296. if (gWLSkyParamMgr.mParamList.find(text) ==
  1297. gWLSkyParamMgr.mParamList.end())
  1298. {
  1299. // Add the current parameters to the list if not there
  1300. gWLSkyParamMgr.addParamSet(text, gWLSkyParamMgr.mCurParams);
  1301. combo->add(text);
  1302. combo->sortByName();
  1303. // Add a blank to the bottom
  1304. combo->selectFirstItem();
  1305. if (combo->getSimple().empty())
  1306. {
  1307. combo->remove(0);
  1308. }
  1309. combo->add(LLStringUtil::null);
  1310. combo->setSelectedByValue(text, true);
  1311. LLFloaterWindlight* floaterp =
  1312. dynamic_cast<LLFloaterWindlight*>(self->getParentFloater());
  1313. if (floaterp)
  1314. {
  1315. floaterp->mPanelDayCycle->addPreset(text);
  1316. }
  1317. gWLSkyParamMgr.savePreset(text);
  1318. }
  1319. else
  1320. {
  1321. // Otherwise, send a message to the user
  1322. gNotifications.add("ExistsPresetAlert");
  1323. }
  1324. return false;
  1325. }
  1326. //static
  1327. void LLPanelWLSky::onNewPreset(void*)
  1328. {
  1329. gNotifications.add("NewSkyPreset", LLSD(), LLSD(), newPromptCallback);
  1330. }
  1331. //static
  1332. void LLPanelWLSky::onSavePreset(void* userdata)
  1333. {
  1334. LLPanelWLSky* self = (LLPanelWLSky*)userdata;
  1335. if (!self) return;
  1336. // Get the name
  1337. std::string name = self->mWLPresetsCombo->getSelectedItemLabel();
  1338. if (name.empty())
  1339. {
  1340. // Do not save with an empty name
  1341. return;
  1342. }
  1343. // Check to see if it is a default and should not be overwritten
  1344. if (sDefaultPresets.count(name) &&
  1345. !gSavedSettings.getBool("SkyEditPresets"))
  1346. {
  1347. gNotifications.add("PresetNoEditDefault");
  1348. return;
  1349. }
  1350. gWLSkyParamMgr.mCurParams.mName = name;
  1351. gNotifications.add("WLSavePresetAlert", LLSD(), LLSD(), saveAlertCallback);
  1352. }
  1353. //static
  1354. bool LLPanelWLSky::saveAlertCallback(const LLSD& notification,
  1355. const LLSD& response)
  1356. {
  1357. if (LLNotification::getSelectedOption(notification, response) == 0)
  1358. {
  1359. gWLSkyParamMgr.setParamSet(gWLSkyParamMgr.mCurParams.mName,
  1360. gWLSkyParamMgr.mCurParams);
  1361. gWLSkyParamMgr.savePreset(gWLSkyParamMgr.mCurParams.mName);
  1362. }
  1363. return false;
  1364. }
  1365. //static
  1366. void LLPanelWLSky::onDeletePreset(void* userdata)
  1367. {
  1368. LLPanelWLSky* self = (LLPanelWLSky*)userdata;
  1369. if (!self) return;
  1370. std::string name = self->mWLPresetsCombo->getSelectedValue().asString();
  1371. if (!name.empty())
  1372. {
  1373. LLSD args;
  1374. args["NAME"] = name;
  1375. gNotifications.add("WLDeletePresetAlert", args, LLSD(),
  1376. deleteAlertCallback);
  1377. }
  1378. }
  1379. //static
  1380. bool LLPanelWLSky::deleteAlertCallback(const LLSD& notification,
  1381. const LLSD& response)
  1382. {
  1383. LLPanelWLSky* self = getSelf();
  1384. if (!self || LLNotification::getSelectedOption(notification, response))
  1385. {
  1386. return false;
  1387. }
  1388. LLComboBox* combo = self->mWLPresetsCombo;
  1389. std::string name = combo->getSelectedValue().asString();
  1390. if (name.empty())
  1391. {
  1392. return false;
  1393. }
  1394. // Check to see if it is a default and should not be deleted
  1395. std::set<std::string>::iterator it = sDefaultPresets.find(name);
  1396. if (it != sDefaultPresets.end())
  1397. {
  1398. gNotifications.add("PresetNoEditDefault");
  1399. return false;
  1400. }
  1401. gWLSkyParamMgr.removeParamSet(name, true);
  1402. // Remove and choose another
  1403. S32 new_index = combo->getCurrentIndex();
  1404. LLFloaterWindlight* floaterp =
  1405. dynamic_cast<LLFloaterWindlight*>(self->getParentFloater());
  1406. if (floaterp)
  1407. {
  1408. floaterp->mPanelDayCycle->deletePreset(name);
  1409. }
  1410. // Pick the previously selected index after delete
  1411. if (new_index > 0)
  1412. {
  1413. --new_index;
  1414. }
  1415. if (combo->getItemCount() > 0)
  1416. {
  1417. combo->setCurrentByIndex(new_index);
  1418. }
  1419. return false;
  1420. }
  1421. //static
  1422. void LLPanelWLSky::onChangePresetName(LLUICtrl* ctrl, void* userdata)
  1423. {
  1424. LLPanelWLSky* self = (LLPanelWLSky*)userdata;
  1425. if (!self || !ctrl) return;
  1426. gWLSkyParamMgr.animate(false);
  1427. LLComboBox* combo = (LLComboBox*)ctrl;
  1428. std::string name = combo->getSelectedValue().asString();
  1429. if (!name.empty())
  1430. {
  1431. gWLSkyParamMgr.loadPreset(name);
  1432. self->refresh();
  1433. }
  1434. }
  1435. //static
  1436. void LLPanelWLSky::onCloudScrollXMoved(LLUICtrl* ctrl, void*)
  1437. {
  1438. if (!ctrl) return;
  1439. gWLSkyParamMgr.animate(false);
  1440. // BEWARE: Windlight cloud scrolling value is offset by 10.
  1441. LLSliderCtrl* slider = (LLSliderCtrl*)ctrl;
  1442. gWLSkyParamMgr.mCurParams.setCloudScrollX(slider->getValueF32() + 10.f);
  1443. }
  1444. //static
  1445. void LLPanelWLSky::onCloudScrollYMoved(LLUICtrl* ctrl, void*)
  1446. {
  1447. if (!ctrl) return;
  1448. gWLSkyParamMgr.animate(false);
  1449. // BEWARE: Windlight cloud scrolling value is offset by 10.
  1450. LLSliderCtrl* slider = (LLSliderCtrl*)ctrl;
  1451. gWLSkyParamMgr.mCurParams.setCloudScrollY(slider->getValueF32() + 10.f);
  1452. }
  1453. //static
  1454. void LLPanelWLSky::onCloudScrollXToggled(LLUICtrl* ctrl, void* userdata)
  1455. {
  1456. LLPanelWLSky* self = (LLPanelWLSky*)userdata;
  1457. if (!self || !ctrl) return;
  1458. LLCheckBoxCtrl* check = (LLCheckBoxCtrl*)ctrl;
  1459. bool lock = check->get();
  1460. self->mWLCloudScrollX->setEnabled(!lock);
  1461. gWLSkyParamMgr.animate(false);
  1462. gWLSkyParamMgr.mCurParams.setEnableCloudScrollX(!lock);
  1463. }
  1464. //static
  1465. void LLPanelWLSky::onCloudScrollYToggled(LLUICtrl* ctrl, void* userdata)
  1466. {
  1467. LLPanelWLSky* self = (LLPanelWLSky*)userdata;
  1468. if (!self || !ctrl) return;
  1469. LLCheckBoxCtrl* check = (LLCheckBoxCtrl*)ctrl;
  1470. bool lock = check->get();
  1471. self->mWLCloudScrollY->setEnabled(!lock);
  1472. gWLSkyParamMgr.animate(false);
  1473. gWLSkyParamMgr.mCurParams.setEnableCloudScrollY(!lock);
  1474. }
  1475. ///////////////////////////////////////////////////////////////////////////////
  1476. // LLPanelWLWater class (used to be a separate floater in LL's viewer)
  1477. ///////////////////////////////////////////////////////////////////////////////
  1478. class LLPanelWLWater final : public LLPanel
  1479. {
  1480. protected:
  1481. LOG_CLASS(LLPanelWLWater);
  1482. public:
  1483. LLPanelWLWater(const std::string& name)
  1484. : LLPanel(name)
  1485. {
  1486. }
  1487. ~LLPanelWLWater() override
  1488. {
  1489. }
  1490. bool postBuild() override;
  1491. void refresh() override;
  1492. private:
  1493. static LLPanelWLWater* getSelf();
  1494. static void onVector3ControlXMoved(LLUICtrl* ctrl, void* userdata);
  1495. static void onVector3ControlYMoved(LLUICtrl* ctrl, void* userdata);
  1496. static void onVector3ControlZMoved(LLUICtrl* ctrl, void* userdata);
  1497. static void onVector2ControlXMoved(LLUICtrl* ctrl, void* userdata);
  1498. static void onVector2ControlYMoved(LLUICtrl* ctrl, void* userdata);
  1499. static void onFloatControlMoved(LLUICtrl* ctrl, void* userdata);
  1500. static void onExpFloatControlMoved(LLUICtrl* ctrl, void* userdata);
  1501. static void onWaterFogColorMoved(LLUICtrl* ctrl, void* userdata);
  1502. static void onNormalMapPicked(LLUICtrl* ctrl, void*);
  1503. static void onNewPreset(void*);
  1504. static void onSavePreset(void* userdata);
  1505. static void onDeletePreset(void* userdata);
  1506. static void onChangePresetName(LLUICtrl* ctrl, void* userdata);
  1507. static bool newPromptCallback(const LLSD& notification,
  1508. const LLSD& response);
  1509. static bool saveAlertCallback(const LLSD& notification,
  1510. const LLSD& response);
  1511. static bool deleteAlertCallback(const LLSD& notification,
  1512. const LLSD& response);
  1513. private:
  1514. LLColorSwatchCtrl* mWaterFogColor;
  1515. LLComboBox* mWaterPresetsCombo;
  1516. LLSliderCtrl* mWaterFogDensity;
  1517. LLSliderCtrl* mWaterUnderWaterFogMod;
  1518. LLSliderCtrl* mWaterNormalScaleX;
  1519. LLSliderCtrl* mWaterNormalScaleY;
  1520. LLSliderCtrl* mWaterNormalScaleZ;
  1521. LLSliderCtrl* mWaterFresnelScale;
  1522. LLSliderCtrl* mWaterFresnelOffset;
  1523. LLSliderCtrl* mWaterScaleAbove;
  1524. LLSliderCtrl* mWaterScaleBelow;
  1525. LLSliderCtrl* mWaterBlurMult;
  1526. LLSliderCtrl* mWaterWave1DirX;
  1527. LLSliderCtrl* mWaterWave1DirY;
  1528. LLSliderCtrl* mWaterWave2DirX;
  1529. LLSliderCtrl* mWaterWave2DirY;
  1530. LLTextureCtrl* mWaterNormalMap;
  1531. typedef std::set<std::string> presets_list_t;
  1532. static presets_list_t sDefaultPresets;
  1533. };
  1534. LLPanelWLWater::presets_list_t LLPanelWLWater::sDefaultPresets;
  1535. //static
  1536. LLPanelWLWater* LLPanelWLWater::getSelf()
  1537. {
  1538. LLFloaterWindlight* wlp = LLFloaterWindlight::findInstance();
  1539. return wlp ? wlp->mPanelWater : NULL;
  1540. }
  1541. //virtual
  1542. bool LLPanelWLWater::postBuild()
  1543. {
  1544. // Presets
  1545. std::string def_water = getString("WLDefaultWaterNames");
  1546. // No editing or deleting of the blank string
  1547. sDefaultPresets.emplace("");
  1548. typedef boost::tokenizer<boost::char_separator<char> > boost_tokenizer;
  1549. boost_tokenizer tokens(def_water, boost::char_separator<char>(":"));
  1550. for (boost_tokenizer::iterator it = tokens.begin();
  1551. it != tokens.end(); ++it)
  1552. {
  1553. const std::string& tok = *it;
  1554. sDefaultPresets.emplace(tok);
  1555. }
  1556. mWaterPresetsCombo = getChild<LLComboBox>("WaterPresetsCombo");
  1557. for (LLWLWaterParamMgr::paramset_map_t::iterator
  1558. it = gWLWaterParamMgr.mParamList.begin(),
  1559. end = gWLWaterParamMgr.mParamList.end();
  1560. it != end; ++it)
  1561. {
  1562. mWaterPresetsCombo->add(it->first);
  1563. }
  1564. mWaterPresetsCombo->selectByValue(LLSD("Default"));
  1565. mWaterPresetsCombo->setCommitCallback(onChangePresetName);
  1566. mWaterPresetsCombo->setCallbackUserData(this);
  1567. // Fog color
  1568. mWaterFogColor = getChild<LLColorSwatchCtrl>("WaterFogColor");
  1569. mWaterFogColor->setCommitCallback(onWaterFogColorMoved);
  1570. mWaterFogColor->setCallbackUserData(&gWLWaterParamMgr.mFogColor);
  1571. // Fog density
  1572. mWaterFogDensity = getChild<LLSliderCtrl>("WaterFogDensity");
  1573. mWaterFogDensity->setCommitCallback(onExpFloatControlMoved);
  1574. mWaterFogDensity->setCallbackUserData(&gWLWaterParamMgr.mFogDensity);
  1575. mWaterUnderWaterFogMod = getChild<LLSliderCtrl>("WaterUnderWaterFogMod");
  1576. mWaterUnderWaterFogMod->setCommitCallback(onFloatControlMoved);
  1577. mWaterUnderWaterFogMod->setCallbackUserData(&gWLWaterParamMgr.mUnderWaterFogMod);
  1578. // Blue density
  1579. mWaterNormalScaleX = getChild<LLSliderCtrl>("WaterNormalScaleX");
  1580. mWaterNormalScaleX->setCommitCallback(onVector3ControlXMoved);
  1581. mWaterNormalScaleX->setCallbackUserData(&gWLWaterParamMgr.mNormalScale);
  1582. mWaterNormalScaleY = getChild<LLSliderCtrl>("WaterNormalScaleY");
  1583. mWaterNormalScaleY->setCommitCallback(onVector3ControlYMoved);
  1584. mWaterNormalScaleY->setCallbackUserData(&gWLWaterParamMgr.mNormalScale);
  1585. mWaterNormalScaleZ = getChild<LLSliderCtrl>("WaterNormalScaleZ");
  1586. mWaterNormalScaleZ->setCommitCallback(onVector3ControlZMoved);
  1587. mWaterNormalScaleZ->setCallbackUserData(&gWLWaterParamMgr.mNormalScale);
  1588. // Fresnel
  1589. mWaterFresnelScale = getChild<LLSliderCtrl>("WaterFresnelScale");
  1590. mWaterFresnelScale->setCommitCallback(onFloatControlMoved);
  1591. mWaterFresnelScale->setCallbackUserData(&gWLWaterParamMgr.mFresnelScale);
  1592. mWaterFresnelOffset = getChild<LLSliderCtrl>("WaterFresnelOffset");
  1593. mWaterFresnelOffset->setCommitCallback(onFloatControlMoved);
  1594. mWaterFresnelOffset->setCallbackUserData(&gWLWaterParamMgr.mFresnelOffset);
  1595. // Scale above/below
  1596. mWaterScaleAbove = getChild<LLSliderCtrl>("WaterScaleAbove");
  1597. mWaterScaleAbove->setCommitCallback(onFloatControlMoved);
  1598. mWaterScaleAbove->setCallbackUserData(&gWLWaterParamMgr.mScaleAbove);
  1599. mWaterScaleBelow = getChild<LLSliderCtrl>("WaterScaleBelow");
  1600. mWaterScaleBelow->setCommitCallback(onFloatControlMoved);
  1601. mWaterScaleBelow->setCallbackUserData(&gWLWaterParamMgr.mScaleBelow);
  1602. // Blur multiplier
  1603. mWaterBlurMult = getChild<LLSliderCtrl>("WaterBlurMult");
  1604. mWaterBlurMult->setCommitCallback(onFloatControlMoved);
  1605. mWaterBlurMult->setCallbackUserData(&gWLWaterParamMgr.mBlurMultiplier);
  1606. // Waves directions
  1607. mWaterWave1DirX = getChild<LLSliderCtrl>("WaterWave1DirX");
  1608. mWaterWave1DirX->setCommitCallback(onVector2ControlXMoved);
  1609. mWaterWave1DirX->setCallbackUserData(&gWLWaterParamMgr.mWave1Dir);
  1610. mWaterWave1DirY = getChild<LLSliderCtrl>("WaterWave1DirY");
  1611. mWaterWave1DirY->setCommitCallback(onVector2ControlYMoved);
  1612. mWaterWave1DirY->setCallbackUserData(&gWLWaterParamMgr.mWave1Dir);
  1613. mWaterWave2DirX = getChild<LLSliderCtrl>("WaterWave2DirX");
  1614. mWaterWave2DirX->setCommitCallback(onVector2ControlXMoved);
  1615. mWaterWave2DirX->setCallbackUserData(&gWLWaterParamMgr.mWave2Dir);
  1616. mWaterWave2DirY = getChild<LLSliderCtrl>("WaterWave2DirY");
  1617. mWaterWave2DirY->setCommitCallback(onVector2ControlYMoved);
  1618. mWaterWave2DirY->setCallbackUserData(&gWLWaterParamMgr.mWave2Dir);
  1619. // Water normal map texture
  1620. mWaterNormalMap = getChild<LLTextureCtrl>("WaterNormalMap");
  1621. mWaterNormalMap->setDefaultImageAssetID(DEFAULT_WATER_NORMAL);
  1622. mWaterNormalMap->setCommitCallback(onNormalMapPicked);
  1623. mWaterNormalMap->setCallbackUserData(this);
  1624. childSetAction("WaterNewPreset", onNewPreset, this);
  1625. childSetAction("WaterSavePreset", onSavePreset, this);
  1626. childSetAction("WaterDeletePreset", onDeletePreset, this);
  1627. refresh();
  1628. return true;
  1629. }
  1630. //virtual
  1631. void LLPanelWLWater::refresh()
  1632. {
  1633. LLWaterParamSet& cur_params = gWLWaterParamMgr.mCurParams;
  1634. bool err;
  1635. // Blue horizon
  1636. gWLWaterParamMgr.mFogColor =
  1637. cur_params.getVector4(gWLWaterParamMgr.mFogColor.mName, err);
  1638. LLColor4 col = gWLWaterParamMgr.getFogColor();
  1639. col.mV[3] = 1.f;
  1640. mWaterFogColor->set(col);
  1641. // Fog and wavelets
  1642. F32 value =
  1643. logf(cur_params.getFloat(gWLWaterParamMgr.mFogDensity.mName, err)) /
  1644. logf(gWLWaterParamMgr.mFogDensity.mBase);
  1645. gWLWaterParamMgr.mFogDensity.mExp = value;
  1646. gWLWaterParamMgr.setDensitySliderValue(value);
  1647. mWaterFogDensity->setValue(value);
  1648. value = cur_params.getFloat(gWLWaterParamMgr.mUnderWaterFogMod.mName, err);
  1649. gWLWaterParamMgr.mUnderWaterFogMod.mX = value;
  1650. mWaterUnderWaterFogMod->setValue(value);
  1651. gWLWaterParamMgr.mNormalScale =
  1652. cur_params.getVector3(gWLWaterParamMgr.mNormalScale.mName, err);
  1653. mWaterNormalScaleX->setValue(gWLWaterParamMgr.mNormalScale.mX);
  1654. mWaterNormalScaleY->setValue(gWLWaterParamMgr.mNormalScale.mY);
  1655. mWaterNormalScaleZ->setValue(gWLWaterParamMgr.mNormalScale.mZ);
  1656. // Fresnel
  1657. value = cur_params.getFloat(gWLWaterParamMgr.mFresnelScale.mName, err);
  1658. gWLWaterParamMgr.mFresnelScale.mX = value;
  1659. mWaterFresnelScale->setValue(value);
  1660. value = cur_params.getFloat(gWLWaterParamMgr.mFresnelOffset.mName, err);
  1661. gWLWaterParamMgr.mFresnelOffset.mX = value;
  1662. mWaterFresnelOffset->setValue(value);
  1663. // Scale Above/Below
  1664. value = cur_params.getFloat(gWLWaterParamMgr.mScaleAbove.mName, err);
  1665. gWLWaterParamMgr.mScaleAbove.mX = value;
  1666. mWaterScaleAbove->setValue(value);
  1667. value = cur_params.getFloat(gWLWaterParamMgr.mScaleBelow.mName, err);
  1668. gWLWaterParamMgr.mScaleBelow.mX = value;
  1669. mWaterScaleBelow->setValue(value);
  1670. // Blur multiplier
  1671. value = cur_params.getFloat(gWLWaterParamMgr.mBlurMultiplier.mName, err);
  1672. gWLWaterParamMgr.mBlurMultiplier.mX = value;
  1673. mWaterBlurMult->setValue(value);
  1674. // Waves directions
  1675. gWLWaterParamMgr.mWave1Dir =
  1676. cur_params.getVector2(gWLWaterParamMgr.mWave1Dir.mName, err);
  1677. mWaterWave1DirX->setValue(gWLWaterParamMgr.mWave1Dir.mX);
  1678. mWaterWave1DirY->setValue(gWLWaterParamMgr.mWave1Dir.mY);
  1679. gWLWaterParamMgr.mWave2Dir =
  1680. cur_params.getVector2(gWLWaterParamMgr.mWave2Dir.mName, err);
  1681. mWaterWave2DirX->setValue(gWLWaterParamMgr.mWave2Dir.mX);
  1682. mWaterWave2DirY->setValue(gWLWaterParamMgr.mWave2Dir.mY);
  1683. // Normal map texture
  1684. mWaterNormalMap->setImageAssetID(gWLWaterParamMgr.getNormalMapID());
  1685. }
  1686. //static
  1687. void LLPanelWLWater::onVector3ControlXMoved(LLUICtrl* ctrl, void* userdata)
  1688. {
  1689. if (ctrl && userdata)
  1690. {
  1691. LLSliderCtrl* slider = (LLSliderCtrl*)ctrl;
  1692. WaterVector3Control* vec_ctrl = (WaterVector3Control*)userdata;
  1693. vec_ctrl->mX = slider->getValueF32();
  1694. vec_ctrl->update(gWLWaterParamMgr.mCurParams);
  1695. gWLWaterParamMgr.propagateParameters();
  1696. }
  1697. }
  1698. //static
  1699. void LLPanelWLWater::onVector3ControlYMoved(LLUICtrl* ctrl, void* userdata)
  1700. {
  1701. if (ctrl && userdata)
  1702. {
  1703. LLSliderCtrl* slider = (LLSliderCtrl*)ctrl;
  1704. WaterVector3Control* vec_ctrl = (WaterVector3Control*)userdata;
  1705. vec_ctrl->mY = slider->getValueF32();
  1706. vec_ctrl->update(gWLWaterParamMgr.mCurParams);
  1707. gWLWaterParamMgr.propagateParameters();
  1708. }
  1709. }
  1710. //static
  1711. void LLPanelWLWater::onVector3ControlZMoved(LLUICtrl* ctrl, void* userdata)
  1712. {
  1713. if (ctrl && userdata)
  1714. {
  1715. LLSliderCtrl* slider = (LLSliderCtrl*)ctrl;
  1716. WaterVector3Control* vec_ctrl = (WaterVector3Control*)userdata;
  1717. vec_ctrl->mZ = slider->getValueF32();
  1718. vec_ctrl->update(gWLWaterParamMgr.mCurParams);
  1719. gWLWaterParamMgr.propagateParameters();
  1720. }
  1721. }
  1722. //static
  1723. void LLPanelWLWater::onVector2ControlXMoved(LLUICtrl* ctrl, void* userdata)
  1724. {
  1725. if (ctrl && userdata)
  1726. {
  1727. LLSliderCtrl* slider = (LLSliderCtrl*)ctrl;
  1728. WaterVector2Control* vec_ctrl = (WaterVector2Control*)userdata;
  1729. vec_ctrl->mX = slider->getValueF32();
  1730. vec_ctrl->update(gWLWaterParamMgr.mCurParams);
  1731. gWLWaterParamMgr.propagateParameters();
  1732. }
  1733. }
  1734. //static
  1735. void LLPanelWLWater::onVector2ControlYMoved(LLUICtrl* ctrl, void* userdata)
  1736. {
  1737. if (ctrl && userdata)
  1738. {
  1739. LLSliderCtrl* slider = (LLSliderCtrl*)ctrl;
  1740. WaterVector2Control* vec_ctrl = (WaterVector2Control*)userdata;
  1741. vec_ctrl->mY = slider->getValueF32();
  1742. vec_ctrl->update(gWLWaterParamMgr.mCurParams);
  1743. gWLWaterParamMgr.propagateParameters();
  1744. }
  1745. }
  1746. //static
  1747. void LLPanelWLWater::onExpFloatControlMoved(LLUICtrl* ctrl, void* userdata)
  1748. {
  1749. if (ctrl && userdata)
  1750. {
  1751. LLSliderCtrl* slider = (LLSliderCtrl*)ctrl;
  1752. WaterExpFloatControl* float_ctrl = (WaterExpFloatControl*)userdata;
  1753. F32 val = slider->getValueF32();
  1754. float_ctrl->mExp = val;
  1755. gWLWaterParamMgr.setDensitySliderValue(val);
  1756. float_ctrl->update(gWLWaterParamMgr.mCurParams);
  1757. gWLWaterParamMgr.propagateParameters();
  1758. }
  1759. }
  1760. //static
  1761. void LLPanelWLWater::onFloatControlMoved(LLUICtrl* ctrl, void* userdata)
  1762. {
  1763. if (ctrl && userdata)
  1764. {
  1765. LLSliderCtrl* slider = (LLSliderCtrl*)ctrl;
  1766. WaterFloatControl* float_ctrl = (WaterFloatControl*)userdata;
  1767. float_ctrl->mX = slider->getValueF32() / float_ctrl->mMult;
  1768. float_ctrl->update(gWLWaterParamMgr.mCurParams);
  1769. gWLWaterParamMgr.propagateParameters();
  1770. }
  1771. }
  1772. //static
  1773. void LLPanelWLWater::onWaterFogColorMoved(LLUICtrl* ctrl, void* userdata)
  1774. {
  1775. if (ctrl && userdata)
  1776. {
  1777. LLColorSwatchCtrl* swatch = (LLColorSwatchCtrl*)ctrl;
  1778. WaterColorControl* color_ctrl = (WaterColorControl*)userdata;
  1779. *color_ctrl = swatch->get();
  1780. color_ctrl->update(gWLWaterParamMgr.mCurParams);
  1781. gWLWaterParamMgr.propagateParameters();
  1782. }
  1783. }
  1784. //static
  1785. void LLPanelWLWater::onNormalMapPicked(LLUICtrl* ctrl, void*)
  1786. {
  1787. if (ctrl)
  1788. {
  1789. LLTextureCtrl* texture = (LLTextureCtrl*)ctrl;
  1790. const LLUUID& id = texture->getImageAssetID();
  1791. gWLWaterParamMgr.setNormalMapID(id);
  1792. }
  1793. }
  1794. //static
  1795. bool LLPanelWLWater::newPromptCallback(const LLSD& notification,
  1796. const LLSD& response)
  1797. {
  1798. LLPanelWLWater* self = getSelf();
  1799. if (!self) return false;
  1800. std::string text = response["message"].asString();
  1801. if (text.empty())
  1802. {
  1803. return false;
  1804. }
  1805. if (LLNotification::getSelectedOption(notification, response) == 0)
  1806. {
  1807. if (gWLWaterParamMgr.mParamList.find(text) ==
  1808. gWLWaterParamMgr.mParamList.end())
  1809. {
  1810. // Add the current parameters to the list see if it is there first
  1811. gWLWaterParamMgr.addParamSet(text, gWLWaterParamMgr.mCurParams);
  1812. LLComboBox* combo = self->mWaterPresetsCombo;
  1813. combo->add(text);
  1814. combo->sortByName();
  1815. combo->setSelectedByValue(text, true);
  1816. gWLWaterParamMgr.savePreset(text);
  1817. }
  1818. else
  1819. {
  1820. // Otherwise, send a message to the user
  1821. gNotifications.add("ExistsPresetAlert");
  1822. }
  1823. }
  1824. return false;
  1825. }
  1826. //static
  1827. void LLPanelWLWater::onNewPreset(void*)
  1828. {
  1829. gNotifications.add("NewWaterPreset", LLSD(), LLSD(), newPromptCallback);
  1830. }
  1831. //static
  1832. void LLPanelWLWater::onSavePreset(void* userdata)
  1833. {
  1834. LLPanelWLWater* self = (LLPanelWLWater*)userdata;
  1835. if (!self) return;
  1836. // Get the name
  1837. std::string name = self->mWaterPresetsCombo->getSelectedItemLabel();
  1838. if (name.empty())
  1839. {
  1840. // Do not save with an empty name
  1841. return;
  1842. }
  1843. // Check to see if it is a default and should not be overwritten
  1844. if (sDefaultPresets.find(name) != sDefaultPresets.end() &&
  1845. !gSavedSettings.getBool("WaterEditPresets"))
  1846. {
  1847. gNotifications.add("PresetNoEditDefault");
  1848. return;
  1849. }
  1850. gWLWaterParamMgr.mCurParams.mName = name;
  1851. gNotifications.add("WLSavePresetAlert", LLSD(), LLSD(), saveAlertCallback);
  1852. }
  1853. //static
  1854. bool LLPanelWLWater::saveAlertCallback(const LLSD& notification,
  1855. const LLSD& response)
  1856. {
  1857. // If user chose save, do it. Otherwise, do not do anything.
  1858. if (LLNotification::getSelectedOption(notification, response) == 0)
  1859. {
  1860. gWLWaterParamMgr.setParamSet(gWLWaterParamMgr.mCurParams.mName,
  1861. gWLWaterParamMgr.mCurParams);
  1862. gWLWaterParamMgr.savePreset(gWLWaterParamMgr.mCurParams.mName);
  1863. }
  1864. return false;
  1865. }
  1866. //static
  1867. void LLPanelWLWater::onDeletePreset(void* userdata)
  1868. {
  1869. LLPanelWLWater* self = (LLPanelWLWater*)userdata;
  1870. if (!self) return;
  1871. // Get the name
  1872. std::string name = self->mWaterPresetsCombo->getSelectedValue().asString();
  1873. if (name.empty())
  1874. {
  1875. // Do not save with an empty name
  1876. return;
  1877. }
  1878. LLSD args;
  1879. args["NAME"] = name;
  1880. gNotifications.add("WLDeletePresetAlert", args, LLSD(),
  1881. deleteAlertCallback);
  1882. }
  1883. //static
  1884. bool LLPanelWLWater::deleteAlertCallback(const LLSD& notification,
  1885. const LLSD& response)
  1886. {
  1887. LLPanelWLWater* self = getSelf();
  1888. if (!self || LLNotification::getSelectedOption(notification, response))
  1889. {
  1890. return false;
  1891. }
  1892. LLComboBox* combo = self->mWaterPresetsCombo;
  1893. std::string name = combo->getSelectedValue().asString();
  1894. if (name.empty())
  1895. {
  1896. return false;
  1897. }
  1898. // Check to see if it's a default and shouldn't be deleted
  1899. presets_list_t::iterator it = sDefaultPresets.find(name);
  1900. if (it != sDefaultPresets.end())
  1901. {
  1902. gNotifications.add("PresetNoEditDefault");
  1903. return false;
  1904. }
  1905. gWLWaterParamMgr.removeParamSet(name, true);
  1906. // Remove and choose another
  1907. S32 new_index = combo->getCurrentIndex();
  1908. combo->remove(name);
  1909. // Pick the previously selected index after delete
  1910. if (new_index > 0)
  1911. {
  1912. --new_index;
  1913. }
  1914. if (combo->getItemCount() > 0)
  1915. {
  1916. combo->setCurrentByIndex(new_index);
  1917. }
  1918. return false;
  1919. }
  1920. //static
  1921. void LLPanelWLWater::onChangePresetName(LLUICtrl* ctrl, void* userdata)
  1922. {
  1923. LLPanelWLWater* self = (LLPanelWLWater*)userdata;
  1924. if (!self || !ctrl) return;
  1925. LLComboBox* combo = (LLComboBox*)ctrl;
  1926. std::string name = combo->getSelectedValue().asString();
  1927. if (!name.empty())
  1928. {
  1929. gWLWaterParamMgr.loadPreset(name);
  1930. self->refresh();
  1931. }
  1932. }
  1933. ///////////////////////////////////////////////////////////////////////////////
  1934. // LLFloaterWindlight class proper
  1935. ///////////////////////////////////////////////////////////////////////////////
  1936. //static
  1937. void* LLFloaterWindlight::createPanelDayCycle(void* data)
  1938. {
  1939. LLFloaterWindlight* self = (LLFloaterWindlight*)data;
  1940. self->mPanelDayCycle = new LLPanelWLDayCycle("day_cycle");
  1941. return self->mPanelDayCycle;
  1942. }
  1943. //static
  1944. void* LLFloaterWindlight::createPanelSky(void* data)
  1945. {
  1946. LLFloaterWindlight* self = (LLFloaterWindlight*)data;
  1947. self->mPanelSky = new LLPanelWLSky("sky");
  1948. return self->mPanelSky;
  1949. }
  1950. //static
  1951. void* LLFloaterWindlight::createPanelWater(void* data)
  1952. {
  1953. LLFloaterWindlight* self = (LLFloaterWindlight*)data;
  1954. self->mPanelWater = new LLPanelWLWater("water");
  1955. return self->mPanelWater;
  1956. }
  1957. LLFloaterWindlight::LLFloaterWindlight(const LLSD&)
  1958. {
  1959. LLCallbackMap::map_t factory_map;
  1960. factory_map["day_cycle"] = LLCallbackMap(createPanelDayCycle, this);
  1961. factory_map["sky"] = LLCallbackMap(createPanelSky, this);
  1962. factory_map["water"] = LLCallbackMap(createPanelWater, this);
  1963. LLUICtrlFactory::getInstance()->buildFloater(this,
  1964. "floater_windlight.xml",
  1965. &factory_map);
  1966. }
  1967. //virtual
  1968. bool LLFloaterWindlight::postBuild()
  1969. {
  1970. mEnvTimeText = getChild<LLTextBox>("EnvTimeText");
  1971. mEnvWaterColorText = getChild<LLTextBox>("EnvWaterColorText");
  1972. mEnvTimeSlider = getChild<LLSliderCtrl>("EnvTimeSlider");
  1973. mEnvTimeSlider->setCommitCallback(onChangeDayTime);
  1974. mEnvTimeSlider->setCallbackUserData(this);
  1975. mEnvCloudSlider = getChild<LLSliderCtrl>("EnvCloudSlider");
  1976. mEnvCloudSlider->setCommitCallback(onChangeCloudCoverage);
  1977. mEnvCloudSlider->setCallbackUserData(this);
  1978. mEnvWaterColor = getChild<LLColorSwatchCtrl>("EnvWaterColor");
  1979. mEnvWaterColor->setCommitCallback(onChangeWaterColor);
  1980. mEnvWaterColor->setCallbackUserData(&gWLWaterParamMgr.mFogColor);
  1981. mEnvWaterFogSlider = getChild<LLSliderCtrl>("EnvWaterFogSlider");
  1982. mEnvWaterFogSlider->setCommitCallback(onChangeWaterFogDensity);
  1983. mEnvWaterFogSlider->setCallbackUserData(&gWLWaterParamMgr.mFogDensity);
  1984. mPreviewBtn = getChild<LLButton>("preview_btn");
  1985. mPreviewBtn->setClickedCallback(onPreviewAsEE, this);
  1986. refresh();
  1987. return true;
  1988. }
  1989. //virtual
  1990. void LLFloaterWindlight::refresh()
  1991. {
  1992. // Sync the clock
  1993. F32 val = (F32)gWLSkyParamMgr.mAnimator.getDayTime();
  1994. std::string time_str = timeToString(val);
  1995. mEnvTimeText->setValue(time_str);
  1996. // Sync time slider which starts at 06:00
  1997. val -= 0.25f;
  1998. if (val < 0.f)
  1999. {
  2000. val += 1.f;
  2001. }
  2002. mEnvTimeSlider->setValue(val);
  2003. // Sync cloud coverage
  2004. bool err;
  2005. mEnvCloudSlider->setValue(gWLSkyParamMgr.mCurParams.getFloat("cloud_shadow",
  2006. err));
  2007. // Sync water params
  2008. LLColor4 col = gWLWaterParamMgr.getFogColor();
  2009. col.mV[3] = 1.f;
  2010. mEnvWaterColor->set(col);
  2011. mEnvWaterFogSlider->setValue(gWLWaterParamMgr.mFogDensity.mExp);
  2012. gWLWaterParamMgr.setDensitySliderValue(gWLWaterParamMgr.mFogDensity.mExp);
  2013. // Only allow access to these if we are using vertex shaders
  2014. bool enable = gPipeline.shadersLoaded();
  2015. mEnvWaterColor->setEnabled(enable);
  2016. mEnvWaterColorText->setEnabled(enable);
  2017. // Only allow access to this if we are using Windlight
  2018. mEnvCloudSlider->setEnabled(gPipeline.canUseWindLightShaders());
  2019. // Show the "Preview frame" button. *TODO: make always visible.
  2020. mPreviewBtn->setVisible(true);
  2021. // Ask our panels to refresh themselves
  2022. mPanelDayCycle->refresh();
  2023. mPanelSky->refresh();
  2024. mPanelWater->refresh();
  2025. }
  2026. //virtual
  2027. void LLFloaterWindlight::draw()
  2028. {
  2029. //MK
  2030. if (gRLenabled && gRLInterface.mContainsSetenv)
  2031. {
  2032. close();
  2033. return;
  2034. }
  2035. //mk
  2036. LLFloater::draw();
  2037. }
  2038. //static
  2039. void LLFloaterWindlight::setDayTime(F32 time)
  2040. {
  2041. // Turn off animator...
  2042. gWLSkyParamMgr.animate(false);
  2043. // Set the new time...
  2044. gWLSkyParamMgr.mAnimator.setDayTime((F64)time);
  2045. // Then call update once.
  2046. gWLSkyParamMgr.mAnimator.update(gWLSkyParamMgr.mCurParams);
  2047. // Since we now always render in EE mode, the WL animator does not refresh
  2048. // our floater, so we must do it here in order to get the time of day
  2049. // sliders synced...
  2050. LLFloaterWindlight* self = LLFloaterWindlight::findInstance();
  2051. if (self)
  2052. {
  2053. self->refresh();
  2054. }
  2055. }
  2056. //static
  2057. void LLFloaterWindlight::onChangeDayTime(LLUICtrl* ctrl, void*)
  2058. {
  2059. if (!ctrl) return;
  2060. LLSliderCtrl* slider = (LLSliderCtrl*)ctrl;
  2061. F32 val = slider->getValueF32() + 0.25f;
  2062. if (val > 1.f)
  2063. {
  2064. --val;
  2065. }
  2066. setDayTime(val);
  2067. }
  2068. //static
  2069. void LLFloaterWindlight::onChangeCloudCoverage(LLUICtrl* ctrl, void*)
  2070. {
  2071. LLSliderCtrl* slider = (LLSliderCtrl*)ctrl;
  2072. if (!slider) return;
  2073. gWLSkyParamMgr.mCurParams.set("cloud_shadow", slider->getValueF32());
  2074. }
  2075. //static
  2076. void LLFloaterWindlight::onChangeWaterFogDensity(LLUICtrl* ctrl,
  2077. void* userdata)
  2078. {
  2079. if (!ctrl || !userdata) return;
  2080. LLSliderCtrl* slider = (LLSliderCtrl*)ctrl;
  2081. WaterExpFloatControl* exp_float_ctrl = (WaterExpFloatControl*)userdata;
  2082. F32 val = slider->getValueF32();
  2083. exp_float_ctrl->mExp = val;
  2084. gWLWaterParamMgr.setDensitySliderValue(val);
  2085. exp_float_ctrl->update(gWLWaterParamMgr.mCurParams);
  2086. gWLWaterParamMgr.propagateParameters();
  2087. }
  2088. //static
  2089. void LLFloaterWindlight::onChangeWaterColor(LLUICtrl* ctrl, void* userdata)
  2090. {
  2091. if (!ctrl || !userdata) return;
  2092. LLColorSwatchCtrl* swatch = (LLColorSwatchCtrl*)ctrl;
  2093. WaterColorControl* color_ctrl = (WaterColorControl*)userdata;
  2094. *color_ctrl = swatch->get();
  2095. color_ctrl->update(gWLWaterParamMgr.mCurParams);
  2096. gWLWaterParamMgr.propagateParameters();
  2097. }
  2098. //static
  2099. void LLFloaterWindlight::onPreviewAsEE(void*)
  2100. {
  2101. gWLSkyParamMgr.propagateParameters();
  2102. gWLWaterParamMgr.propagateParameters();
  2103. }
  2104. //static
  2105. std::string LLFloaterWindlight::timeToString(F32 cur_time)
  2106. {
  2107. // Get hours and minutes
  2108. S32 hours = (S32)(HOUR_PER_DAY * cur_time);
  2109. cur_time -= (F32)hours / HOUR_PER_DAY;
  2110. S32 min = ll_roundp(1440.f * cur_time);
  2111. // Handle case where it is 60
  2112. if (min == 60)
  2113. {
  2114. ++hours;
  2115. min = 0;
  2116. }
  2117. if (hours >= 24)
  2118. {
  2119. hours = 0;
  2120. }
  2121. // Make the string
  2122. std::stringstream new_time;
  2123. new_time << hours << ":";
  2124. // Double 0
  2125. if (min < 10)
  2126. {
  2127. new_time << 0;
  2128. }
  2129. // Finish it
  2130. new_time << min;
  2131. return new_time.str();
  2132. }