Skip to content

Fix various issues with snapshot upload fee calculation #2688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions indra/newview/llpanelsnapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

// newview
#include "llsidetraypanelcontainer.h"
#include "llsnapshotlivepreview.h"
#include "llviewercontrol.h" // gSavedSettings

#include "llagentbenefits.h"
Expand Down Expand Up @@ -99,6 +100,17 @@ void LLPanelSnapshot::onOpen(const LLSD& key)
{
getParentByType<LLFloater>()->notify(LLSD().with("image-format-change", true));
}

// If resolution is set to "Current Window", force a snapshot update
// each time a snapshot panel is opened to determine the correct
// image size (and upload fee) depending on the snapshot type.
if (mSnapshotFloater && getChild<LLUICtrl>(getImageSizeComboName())->getValue().asString() == "[i0,i0]")
{
if (LLSnapshotLivePreview* preview = mSnapshotFloater->getPreviewView())
{
preview->mForceUpdateSnapshot = true;
}
}
}

LLSnapshotModel::ESnapshotFormat LLPanelSnapshot::getImageFormat() const
Expand Down
128 changes: 33 additions & 95 deletions indra/newview/llpanelsnapshotinventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,77 +42,35 @@
/**
* The panel provides UI for saving snapshot as an inventory texture.
*/
class LLPanelSnapshotInventoryBase
: public LLPanelSnapshot
{
LOG_CLASS(LLPanelSnapshotInventoryBase);

public:
LLPanelSnapshotInventoryBase();

/*virtual*/ bool postBuild();
protected:
void onSend();
/*virtual*/ LLSnapshotModel::ESnapshotType getSnapshotType();
};

class LLPanelSnapshotInventory
: public LLPanelSnapshotInventoryBase
: public LLPanelSnapshot
{
LOG_CLASS(LLPanelSnapshotInventory);

public:
LLPanelSnapshotInventory();
/*virtual*/ bool postBuild();
/*virtual*/ void onOpen(const LLSD& key);
bool postBuild() override;
void onOpen(const LLSD& key) override;

void onResolutionCommit(LLUICtrl* ctrl);

private:
/*virtual*/ std::string getWidthSpinnerName() const { return "inventory_snapshot_width"; }
/*virtual*/ std::string getHeightSpinnerName() const { return "inventory_snapshot_height"; }
/*virtual*/ std::string getAspectRatioCBName() const { return "inventory_keep_aspect_check"; }
/*virtual*/ std::string getImageSizeComboName() const { return "texture_size_combo"; }
/*virtual*/ std::string getImageSizePanelName() const { return LLStringUtil::null; }
/*virtual*/ void updateControls(const LLSD& info);

};

class LLPanelOutfitSnapshotInventory
: public LLPanelSnapshotInventoryBase
{
LOG_CLASS(LLPanelOutfitSnapshotInventory);

public:
LLPanelOutfitSnapshotInventory();
/*virtual*/ bool postBuild();
/*virtual*/ void onOpen(const LLSD& key);
std::string getWidthSpinnerName() const override { return "inventory_snapshot_width"; }
std::string getHeightSpinnerName() const override { return "inventory_snapshot_height"; }
std::string getAspectRatioCBName() const override { return "inventory_keep_aspect_check"; }
std::string getImageSizeComboName() const override { return "texture_size_combo"; }
std::string getImageSizePanelName() const override { return LLStringUtil::null; }
LLSnapshotModel::ESnapshotType getSnapshotType() override;
void updateControls(const LLSD& info) override;

private:
/*virtual*/ std::string getWidthSpinnerName() const { return ""; }
/*virtual*/ std::string getHeightSpinnerName() const { return ""; }
/*virtual*/ std::string getAspectRatioCBName() const { return ""; }
/*virtual*/ std::string getImageSizeComboName() const { return "texture_size_combo"; }
/*virtual*/ std::string getImageSizePanelName() const { return LLStringUtil::null; }
/*virtual*/ void updateControls(const LLSD& info);

/*virtual*/ void cancel();
void onSend();
void updateUploadCost();
S32 calculateUploadCost();
};

static LLPanelInjector<LLPanelSnapshotInventory> panel_class1("llpanelsnapshotinventory");

static LLPanelInjector<LLPanelOutfitSnapshotInventory> panel_class2("llpaneloutfitsnapshotinventory");

LLPanelSnapshotInventoryBase::LLPanelSnapshotInventoryBase()
{
}

bool LLPanelSnapshotInventoryBase::postBuild()
{
return LLPanelSnapshot::postBuild();
}

LLSnapshotModel::ESnapshotType LLPanelSnapshotInventoryBase::getSnapshotType()
LLSnapshotModel::ESnapshotType LLPanelSnapshotInventory::getSnapshotType()
{
return LLSnapshotModel::SNAPSHOT_TEXTURE;
}
Expand All @@ -130,12 +88,14 @@ bool LLPanelSnapshotInventory::postBuild()
getChild<LLSpinCtrl>(getHeightSpinnerName())->setAllowEdit(false);

getChild<LLUICtrl>(getImageSizeComboName())->setCommitCallback(boost::bind(&LLPanelSnapshotInventory::onResolutionCommit, this, _1));
return LLPanelSnapshotInventoryBase::postBuild();
return LLPanelSnapshot::postBuild();
}

// virtual
void LLPanelSnapshotInventory::onOpen(const LLSD& key)
{
updateUploadCost();

LLPanelSnapshot::onOpen(key);
}

Expand All @@ -144,6 +104,8 @@ void LLPanelSnapshotInventory::updateControls(const LLSD& info)
{
const bool have_snapshot = info.has("have-snapshot") ? info["have-snapshot"].asBoolean() : true;
getChild<LLUICtrl>("save_btn")->setEnabled(have_snapshot);

updateUploadCost();
}

void LLPanelSnapshotInventory::onResolutionCommit(LLUICtrl* ctrl)
Expand All @@ -153,21 +115,9 @@ void LLPanelSnapshotInventory::onResolutionCommit(LLUICtrl* ctrl)
getChild<LLSpinCtrl>(getHeightSpinnerName())->setVisible(!current_window_selected);
}

void LLPanelSnapshotInventoryBase::onSend()
void LLPanelSnapshotInventory::onSend()
{
S32 w = 0;
S32 h = 0;

if( mSnapshotFloater )
{
LLSnapshotLivePreview* preview = mSnapshotFloater->getPreviewView();
if( preview )
{
preview->getSize(w, h);
}
}

S32 expected_upload_cost = LLAgentBenefitsMgr::current().getTextureUploadCost(w, h);
S32 expected_upload_cost = calculateUploadCost();
if (can_afford_transaction(expected_upload_cost))
{
if (mSnapshotFloater)
Expand All @@ -188,36 +138,24 @@ void LLPanelSnapshotInventoryBase::onSend()
}
}

LLPanelOutfitSnapshotInventory::LLPanelOutfitSnapshotInventory()
void LLPanelSnapshotInventory::updateUploadCost()
{
mCommitCallbackRegistrar.add("Inventory.SaveOutfitPhoto", { boost::bind(&LLPanelOutfitSnapshotInventory::onSend, this), cb_info::UNTRUSTED_BLOCK });
mCommitCallbackRegistrar.add("Inventory.SaveOutfitCancel", { boost::bind(&LLPanelOutfitSnapshotInventory::cancel, this), cb_info::UNTRUSTED_BLOCK });
getChild<LLUICtrl>("hint_lbl")->setTextArg("[UPLOAD_COST]", llformat("%d", calculateUploadCost()));
}

// virtual
bool LLPanelOutfitSnapshotInventory::postBuild()
S32 LLPanelSnapshotInventory::calculateUploadCost()
{
return LLPanelSnapshotInventoryBase::postBuild();
}

// virtual
void LLPanelOutfitSnapshotInventory::onOpen(const LLSD& key)
{
getChild<LLUICtrl>("hint_lbl")->setTextArg("[UPLOAD_COST]", llformat("%d", LLAgentBenefitsMgr::current().getTextureUploadCost()));
LLPanelSnapshot::onOpen(key);
}

// virtual
void LLPanelOutfitSnapshotInventory::updateControls(const LLSD& info)
{
const bool have_snapshot = info.has("have-snapshot") ? info["have-snapshot"].asBoolean() : true;
getChild<LLUICtrl>("save_btn")->setEnabled(have_snapshot);
}
S32 w = 0;
S32 h = 0;

void LLPanelOutfitSnapshotInventory::cancel()
{
if (mSnapshotFloater)
{
mSnapshotFloater->closeFloater();
if (LLSnapshotLivePreview* preview = mSnapshotFloater->getPreviewView())
{
w = preview->getEncodedImageWidth();
h = preview->getEncodedImageHeight();
}
}

return LLAgentBenefitsMgr::current().getTextureUploadCost(w, h);
}
20 changes: 10 additions & 10 deletions indra/newview/llpanelsnapshotlocal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ class LLPanelSnapshotLocal

public:
LLPanelSnapshotLocal();
/*virtual*/ bool postBuild();
/*virtual*/ void onOpen(const LLSD& key);
bool postBuild() override;
void onOpen(const LLSD& key) override;

private:
/*virtual*/ std::string getWidthSpinnerName() const { return "local_snapshot_width"; }
/*virtual*/ std::string getHeightSpinnerName() const { return "local_snapshot_height"; }
/*virtual*/ std::string getAspectRatioCBName() const { return "local_keep_aspect_check"; }
/*virtual*/ std::string getImageSizeComboName() const { return "local_size_combo"; }
/*virtual*/ std::string getImageSizePanelName() const { return "local_image_size_lp"; }
/*virtual*/ LLSnapshotModel::ESnapshotFormat getImageFormat() const;
/*virtual*/ LLSnapshotModel::ESnapshotType getSnapshotType();
/*virtual*/ void updateControls(const LLSD& info);
std::string getWidthSpinnerName() const override { return "local_snapshot_width"; }
std::string getHeightSpinnerName() const override { return "local_snapshot_height"; }
std::string getAspectRatioCBName() const override { return "local_keep_aspect_check"; }
std::string getImageSizeComboName() const override { return "local_size_combo"; }
std::string getImageSizePanelName() const override { return "local_image_size_lp"; }
LLSnapshotModel::ESnapshotFormat getImageFormat() const override;
LLSnapshotModel::ESnapshotType getSnapshotType() override;
void updateControls(const LLSD& info) override;

S32 mLocalFormat;

Expand Down
37 changes: 1 addition & 36 deletions indra/newview/llpanelsnapshotoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,8 @@
#include "llsidetraypanelcontainer.h"

#include "llfloatersnapshot.h" // FIXME: create a snapshot model
#include "llsnapshotlivepreview.h"
#include "llfloaterreg.h"

#include "llagentbenefits.h"


/**
* Provides several ways to save a snapshot.
*/
Expand All @@ -46,12 +42,9 @@ class LLPanelSnapshotOptions

public:
LLPanelSnapshotOptions();
~LLPanelSnapshotOptions();
/*virtual*/ bool postBuild();
/*virtual*/ void onOpen(const LLSD& key);
bool postBuild() override;

private:
void updateUploadCost();
void openPanel(const std::string& panel_name);
void onSaveToProfile();
void onSaveToEmail();
Expand All @@ -71,41 +64,13 @@ LLPanelSnapshotOptions::LLPanelSnapshotOptions()
mCommitCallbackRegistrar.add("Snapshot.SaveToComputer", { boost::bind(&LLPanelSnapshotOptions::onSaveToComputer, this) });
}

LLPanelSnapshotOptions::~LLPanelSnapshotOptions()
{
}

// virtual
bool LLPanelSnapshotOptions::postBuild()
{
mSnapshotFloater = getParentByType<LLFloaterSnapshotBase>();
return LLPanel::postBuild();
}

// virtual
void LLPanelSnapshotOptions::onOpen(const LLSD& key)
{
updateUploadCost();
}

void LLPanelSnapshotOptions::updateUploadCost()
{
S32 w = 0;
S32 h = 0;

if( mSnapshotFloater )
{
LLSnapshotLivePreview* preview = mSnapshotFloater->getPreviewView();
if( preview )
{
preview->getSize(w, h);
}
}

S32 upload_cost = LLAgentBenefitsMgr::current().getTextureUploadCost(w, h);
getChild<LLUICtrl>("save_to_inventory_btn")->setLabelArg("[AMOUNT]", llformat("%d", upload_cost));
}

void LLPanelSnapshotOptions::openPanel(const std::string& panel_name)
{
LLSideTrayPanelContainer* parent = dynamic_cast<LLSideTrayPanelContainer*>(getParent());
Expand Down
20 changes: 10 additions & 10 deletions indra/newview/llpanelsnapshotpostcard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ class LLPanelSnapshotPostcard

public:
LLPanelSnapshotPostcard();
/*virtual*/ bool postBuild();
/*virtual*/ void onOpen(const LLSD& key);
bool postBuild() override;
void onOpen(const LLSD& key) override;

private:
/*virtual*/ std::string getWidthSpinnerName() const { return "postcard_snapshot_width"; }
/*virtual*/ std::string getHeightSpinnerName() const { return "postcard_snapshot_height"; }
/*virtual*/ std::string getAspectRatioCBName() const { return "postcard_keep_aspect_check"; }
/*virtual*/ std::string getImageSizeComboName() const { return "postcard_size_combo"; }
/*virtual*/ std::string getImageSizePanelName() const { return "postcard_image_size_lp"; }
/*virtual*/ LLSnapshotModel::ESnapshotFormat getImageFormat() const { return LLSnapshotModel::SNAPSHOT_FORMAT_JPEG; }
/*virtual*/ LLSnapshotModel::ESnapshotType getSnapshotType();
/*virtual*/ void updateControls(const LLSD& info);
std::string getWidthSpinnerName() const override { return "postcard_snapshot_width"; }
std::string getHeightSpinnerName() const override { return "postcard_snapshot_height"; }
std::string getAspectRatioCBName() const override { return "postcard_keep_aspect_check"; }
std::string getImageSizeComboName() const override { return "postcard_size_combo"; }
std::string getImageSizePanelName() const override { return "postcard_image_size_lp"; }
LLSnapshotModel::ESnapshotFormat getImageFormat() const override { return LLSnapshotModel::SNAPSHOT_FORMAT_JPEG; }
LLSnapshotModel::ESnapshotType getSnapshotType() override;
void updateControls(const LLSD& info) override;

bool missingSubjMsgAlertCallback(const LLSD& notification, const LLSD& response);
static void sendPostcardFinished(LLSD result);
Expand Down
18 changes: 9 additions & 9 deletions indra/newview/llpanelsnapshotprofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ class LLPanelSnapshotProfile
public:
LLPanelSnapshotProfile();

/*virtual*/ bool postBuild();
/*virtual*/ void onOpen(const LLSD& key);
bool postBuild() override;
void onOpen(const LLSD& key) override;

private:
/*virtual*/ std::string getWidthSpinnerName() const { return "profile_snapshot_width"; }
/*virtual*/ std::string getHeightSpinnerName() const { return "profile_snapshot_height"; }
/*virtual*/ std::string getAspectRatioCBName() const { return "profile_keep_aspect_check"; }
/*virtual*/ std::string getImageSizeComboName() const { return "profile_size_combo"; }
/*virtual*/ std::string getImageSizePanelName() const { return "profile_image_size_lp"; }
/*virtual*/ LLSnapshotModel::ESnapshotFormat getImageFormat() const { return LLSnapshotModel::SNAPSHOT_FORMAT_PNG; }
/*virtual*/ void updateControls(const LLSD& info);
std::string getWidthSpinnerName() const override { return "profile_snapshot_width"; }
std::string getHeightSpinnerName() const override { return "profile_snapshot_height"; }
std::string getAspectRatioCBName() const override { return "profile_keep_aspect_check"; }
std::string getImageSizeComboName() const override { return "profile_size_combo"; }
std::string getImageSizePanelName() const override { return "profile_image_size_lp"; }
LLSnapshotModel::ESnapshotFormat getImageFormat() const override { return LLSnapshotModel::SNAPSHOT_FORMAT_PNG; }
void updateControls(const LLSD& info) override;

void onSend();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<combo_box.item label="Klein (128x128)" name="Small(128x128)"/>
<combo_box.item label="Mittel (256x256)" name="Medium(256x256)"/>
<combo_box.item label="Groß (512x512)" name="Large(512x512)"/>
<combo_box.item label="Aktuelles Fenster (512x512)" name="CurrentWindow"/>
<combo_box.item label="Aktuelles Fenster" name="CurrentWindow"/>
<combo_box.item label="Benutzerdefiniert" name="Custom"/>
</combo_box>
<spinner label="Breite x Höhe" name="inventory_snapshot_width"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<panel name="panel_snapshot_options">
<button label="Auf Datenträger speichern" name="save_to_computer_btn"/>
<button label="In Inventar speichern ([AMOUNT] L$)" name="save_to_inventory_btn"/>
<button label="In Inventar speichern" name="save_to_inventory_btn"/>
<button label="Im Profil-Feed teilen" name="save_to_profile_btn"/>
<button label="Auf Facebook teilen" name="send_to_facebook_btn"/>
<button label="Auf Twitter teilen" name="send_to_twitter_btn"/>
Expand Down
Loading
Loading