Skip to content

Commit e34e1aa

Browse files
committed
#6092 'Save As' button in personal lighting floater
1 parent a3c380a commit e34e1aa

5 files changed

Lines changed: 158 additions & 2 deletions

File tree

indra/newview/llfloatereditenvironmentbase.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,9 @@ void LLFloaterEditEnvironmentBase::onSaveAsCommit(const LLSD& notification, cons
281281
else
282282
{
283283
LL_WARNS() << "Failed to copy fixed env setting" << LL_ENDL;
284+
LLSD args;
285+
args["SETTINGS_NAME"] = settings_name;
286+
LLNotificationsUtil::add("SettingsSaveAsFailure", args);
284287
}
285288
}
286289
}

indra/newview/llfloaterenvironmentadjust.cpp

Lines changed: 114 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,20 @@
2828

2929
#include "llfloaterenvironmentadjust.h"
3030

31+
#include "llcolorswatch.h"
32+
#include "llenvironment.h"
33+
#include "llinventorymodel.h"
34+
#include "llinventorypanel.h" // For opening after saving
3135
#include "llnotificationsutil.h"
36+
#include "llsettingsvo.h"
3237
#include "llslider.h"
3338
#include "llsliderctrl.h"
34-
#include "llcolorswatch.h"
3539
#include "lltexturectrl.h"
3640
#include "llvirtualtrackball.h"
37-
#include "llenvironment.h"
3841
#include "llviewercontrol.h"
3942
#include "pipeline.h"
4043

44+
4145
//=========================================================================
4246
namespace
4347
{
@@ -65,6 +69,7 @@ namespace
6569
const std::string FIELD_SKY_MOON_ELEVATION("moon_elevation");
6670
const std::string FIELD_REFLECTION_PROBE_AMBIANCE("probe_ambiance");
6771
const std::string BTN_RESET("btn_reset");
72+
const std::string BTN_SAVE_AS("btn_save_as");
6873

6974
const F32 SLIDER_SCALE_SUN_AMBIENT(3.0f);
7075
const F32 SLIDER_SCALE_BLUE_HORIZON_DENSITY(2.0f);
@@ -110,6 +115,7 @@ bool LLFloaterEnvironmentAdjust::postBuild()
110115
getChild<LLUICtrl>(FIELD_SKY_MOON_AZIMUTH)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onMoonAzimElevChanged(); });
111116
getChild<LLUICtrl>(FIELD_SKY_MOON_ELEVATION)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onMoonAzimElevChanged(); });
112117
getChild<LLUICtrl>(BTN_RESET)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onButtonReset(); });
118+
getChild<LLUICtrl>(BTN_SAVE_AS)->setCommitCallback([this](LLUICtrl*, const LLSD&) { onButtonSaveAs(); });
113119

114120
getChild<LLTextureCtrl>(FIELD_SKY_CLOUD_MAP)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onCloudMapChanged(); });
115121
getChild<LLTextureCtrl>(FIELD_SKY_CLOUD_MAP)->setDefaultImageAssetID(LLSettingsSky::GetDefaultCloudNoiseTextureId());
@@ -258,8 +264,114 @@ void LLFloaterEnvironmentAdjust::onButtonReset()
258264
LLEnvironment::instance().setSelectedEnvironment(LLEnvironment::ENV_LOCAL);
259265
}
260266
});
267+
}
268+
269+
void LLFloaterEnvironmentAdjust::onButtonSaveAs()
270+
{
271+
// Note that this saves only the sky, not water.
272+
// Water is represented as a single texture here, for now
273+
// might be not worth saving. Consider saving water as well
274+
// or alternatively generating a day cycle (fixed ones are
275+
// easier to export/import).
276+
if (!mLiveSky)
277+
return;
278+
279+
// Verify every texture embedded in the sky settings is either
280+
// a sky default, a predefined/library texture, or a copy-permitted
281+
// inventory item owned by the agent. Collect all failing textures
282+
// into one list and show a single notification.
283+
struct TexEntry { LLUUID id; std::string name; };
284+
const std::vector<TexEntry> textures_to_check =
285+
{
286+
{ mLiveSky->getCloudNoiseTextureId(), "cloud_map" },
287+
{ mLiveSky->getSunTextureId(), "sun_texture" },
288+
{ mLiveSky->getMoonTextureId(), "moon_texture" },
289+
{ mLiveSky->getBloomTextureId(), "bloom_texture"},
290+
{ mLiveSky->getRainbowTextureId(), "rainbow_texture"},
291+
{ mLiveSky->getHaloTextureId(), "halo_texture" },
292+
};
293+
294+
// Helper: a null UUID is "no texture" and is always allowed.
295+
// A texture is safe when it is one of the sky defaults,
296+
// a general predefined texture, or is present in inventory.
297+
auto is_safe_texture = [](const LLUUID& tex_id) -> bool
298+
{
299+
if (tex_id.isNull())
300+
return true;
301+
// TODO: find a graceful way to move these ids (and water ones) into get_can_copy_texture
302+
// as pickers should permit these textures by default to be able to work well with settings.
303+
if (tex_id == LLSettingsSky::GetDefaultSunTextureId()
304+
|| tex_id == LLSettingsSky::GetBlankSunTextureId()
305+
|| tex_id == LLSettingsSky::GetDefaultMoonTextureId()
306+
|| tex_id == LLSettingsSky::GetDefaultCloudNoiseTextureId()
307+
|| tex_id == LLSettingsSky::GetDefaultBloomTextureId()
308+
|| tex_id == LLSettingsSky::GetDefaultRainbowTextureId()
309+
|| tex_id == LLSettingsSky::GetDefaultHaloTextureId())
310+
{
311+
return true;
312+
}
313+
return get_can_copy_texture(tex_id);
314+
};
315+
316+
std::string bad_textures;
317+
for (const TexEntry& entry : textures_to_check)
318+
{
319+
if (!is_safe_texture(entry.id))
320+
{
321+
if (!bad_textures.empty())
322+
bad_textures += "\n";
323+
std::string label = getString(entry.name);
324+
bad_textures += " - " + label;
325+
}
326+
}
261327

328+
if (!bad_textures.empty())
329+
{
330+
LLSD args;
331+
args["TEXTURES"] = bad_textures;
332+
LLNotificationsUtil::add("PersonalSettingsTexPermFail", args);
333+
return;
334+
}
335+
336+
LLSettingsSky::ptr_t sky_clone = mLiveSky->buildClone();
337+
LLSD args;
338+
args["DESC"] = getString("new_sky"); // note that notification adds (new) at the end
339+
340+
LLNotificationsUtil::add("SaveSettingAs", args, LLSD(),
341+
[sky_clone](const LLSD& notification, const LLSD& response)
342+
{
343+
S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
344+
if (option != 0)
345+
return;
346+
347+
std::string settings_name = response["message"].asString();
348+
LLInventoryObject::correctInventoryName(settings_name);
349+
if (settings_name.empty())
350+
{
351+
settings_name = "Unnamed";
352+
}
353+
354+
sky_clone->setName(settings_name);
355+
356+
LLUUID parent_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_SETTINGS);
357+
LLSettingsVOBase::createInventoryItem(sky_clone, parent_id, settings_name,
358+
[settings_name](LLUUID /*asset_id*/, LLUUID inventory_id, LLUUID, LLSD results)
359+
{
360+
if (inventory_id.notNull())
361+
{
362+
LLInventoryPanel::openInventoryPanelAndSetSelection(true, inventory_id, true);
363+
}
364+
else
365+
{
366+
LL_WARNS("ENVIRONMENT") << "Failed to create sky settings inventory item. Results: " << results << LL_ENDL;
367+
LLSD args;
368+
args["SETTINGS_NAME"] = settings_name;
369+
LLNotificationsUtil::add("SettingsSaveAsFailure", args);
370+
}
371+
});
372+
});
262373
}
374+
263375
//-------------------------------------------------------------------------
264376
void LLFloaterEnvironmentAdjust::onAmbientLightChanged()
265377
{

indra/newview/llfloaterenvironmentadjust.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class LLFloaterEnvironmentAdjust : public LLFloater
8585
void onReflectionProbeAmbianceChanged();
8686
void updateGammaLabel();
8787
void onButtonReset();
88+
void onButtonSaveAs();
8889

8990
void onEnvironmentUpdated(LLEnvironment::EnvSelection_t env, S32 version);
9091

indra/newview/skins/default/xui/en/floater_adjust_environment.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
<string name="hdr_string">HDR Scale:</string>
1414
<string name="brightness_string">Brightness:</string>
1515
<string name="hdr_tooltip">Intensity of lighting effects such as realistically bright skies and dynamic exposure. 1.0 is the default, 0 is off, values between 0 and 1 are mixing Ambient with HDR.</string>
16+
<string name="cloud_map">Cloud map</string>
17+
<string name="sun_texture">Sun texture</string>
18+
<string name="moon_texture">Moon texture</string>
19+
<string name="bloom_texture">Bloom texture</string>
20+
<string name="rainbow_texture">Rainbow texture</string>
21+
<string name="halo_texture">Halo texture</string>
22+
<string name="new_sky">Sky</string>
1623
<layout_stack name="outer_stack"
1724
width="845"
1825
height="275"
@@ -101,6 +108,16 @@
101108
left_delta="-2"
102109
top_pad="10"
103110
width="100"/>
111+
<button
112+
follows="left|top"
113+
height="23"
114+
label="Save As"
115+
tool_tip="Save these settings as a fixed sky environment"
116+
layout="topleft"
117+
name="btn_save_as"
118+
left_delta="0"
119+
top_pad="4"
120+
width="100"/>
104121
<text follows="right|top"
105122
name="sun_color_lbl"
106123
height="10"

indra/newview/skins/default/xui/en/notifications.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12450,6 +12450,17 @@ Are you sure you want to continue?
1245012450
yestext="Yes"/>
1245112451
</notification>
1245212452

12453+
<notification
12454+
icon="alertmodal.tga"
12455+
name="SettingsSaveAsFailure"
12456+
type="alertmodal">
12457+
Failed to create settings inventory item [SETTINGS_NAME].
12458+
<tag>fail</tag>
12459+
<usetemplate
12460+
name="okbutton"
12461+
yestext="OK"/>
12462+
</notification>
12463+
1245312464
<notification
1245412465
icon="alertmodal.tga"
1245512466
name="PersonalSettingsConfirmReset"
@@ -12463,6 +12474,18 @@ Are you sure you want to continue?
1246312474
yestext="Yes"/>
1246412475
</notification>
1246512476

12477+
<notification
12478+
icon="alertmodal.tga"
12479+
name="PersonalSettingsTexPermFail"
12480+
type="alertmodal">
12481+
Cannot save as sky settings because the following textures are not owned by you or are not copyable:
12482+
[TEXTURES]
12483+
<tag>fail</tag>
12484+
<usetemplate
12485+
name="okbutton"
12486+
yestext="OK"/>
12487+
</notification>
12488+
1246612489
<notification
1246712490
icon="alertmodal.tga"
1246812491
name="SettingsMakeNoTrans"

0 commit comments

Comments
 (0)