summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--indra/llinventory/lleconomy.cpp27
-rw-r--r--indra/llinventory/lleconomy.h16
-rw-r--r--indra/newview/llpanelsnapshotoptions.cpp16
3 files changed, 59 insertions, 0 deletions
diff --git a/indra/llinventory/lleconomy.cpp b/indra/llinventory/lleconomy.cpp
index c6eaa6d3e1..d643ea6ed9 100644
--- a/indra/llinventory/lleconomy.cpp
+++ b/indra/llinventory/lleconomy.cpp
@@ -48,6 +48,31 @@ LLGlobalEconomy::LLGlobalEconomy()
LLGlobalEconomy::~LLGlobalEconomy()
{ }
+void LLGlobalEconomy::addObserver(LLEconomyObserver* observer)
+{
+ mObservers.push_back(observer);
+}
+
+void LLGlobalEconomy::removeObserver(LLEconomyObserver* observer)
+{
+ std::list<LLEconomyObserver*>::iterator it =
+ std::find(mObservers.begin(), mObservers.end(), observer);
+ if (it != mObservers.end())
+ {
+ mObservers.erase(it);
+ }
+}
+
+void LLGlobalEconomy::notifyObservers()
+{
+ for (std::list<LLEconomyObserver*>::iterator it = mObservers.begin();
+ it != mObservers.end();
+ ++it)
+ {
+ (*it)->onEconomyDataChange();
+ }
+}
+
// static
void LLGlobalEconomy::processEconomyData(LLMessageSystem *msg, LLGlobalEconomy* econ_data)
{
@@ -88,6 +113,8 @@ void LLGlobalEconomy::processEconomyData(LLMessageSystem *msg, LLGlobalEconomy*
econ_data->setTeleportPriceExponent(f);
msg->getS32Fast(_PREHASH_Info, _PREHASH_PriceGroupCreate, i);
econ_data->setPriceGroupCreate(i);
+
+ econ_data->notifyObservers();
}
S32 LLGlobalEconomy::calculateTeleportCost(F32 distance) const
diff --git a/indra/llinventory/lleconomy.h b/indra/llinventory/lleconomy.h
index cc6643f955..eb2ecf71ba 100644
--- a/indra/llinventory/lleconomy.h
+++ b/indra/llinventory/lleconomy.h
@@ -31,6 +31,16 @@
class LLMessageSystem;
class LLVector3;
+/**
+ * Register an observer to be notified of economy data updates coming from server.
+ */
+class LLEconomyObserver
+{
+public:
+ virtual ~LLEconomyObserver() {}
+ virtual void onEconomyDataChange() = 0;
+};
+
class LLGlobalEconomy
{
public:
@@ -46,6 +56,10 @@ public:
virtual void print();
+ void addObserver(LLEconomyObserver* observer);
+ void removeObserver(LLEconomyObserver* observer);
+ void notifyObservers();
+
static void processEconomyData(LLMessageSystem *msg, LLGlobalEconomy* econ_data);
S32 calculateTeleportCost(F32 distance) const;
@@ -89,6 +103,8 @@ private:
S32 mTeleportMinPrice;
F32 mTeleportPriceExponent;
S32 mPriceGroupCreate;
+
+ std::list<LLEconomyObserver*> mObservers;
};
diff --git a/indra/newview/llpanelsnapshotoptions.cpp b/indra/newview/llpanelsnapshotoptions.cpp
index df904b6836..554fabe5b3 100644
--- a/indra/newview/llpanelsnapshotoptions.cpp
+++ b/indra/newview/llpanelsnapshotoptions.cpp
@@ -37,14 +37,18 @@
*/
class LLPanelSnapshotOptions
: public LLPanel
+, public LLEconomyObserver
{
LOG_CLASS(LLPanelSnapshotOptions);
public:
LLPanelSnapshotOptions();
+ ~LLPanelSnapshotOptions();
/*virtual*/ void onOpen(const LLSD& key);
+ /*virtual*/ void onEconomyDataChange() { updateUploadCost(); }
private:
+ void updateUploadCost();
void openPanel(const std::string& panel_name);
void onSaveToProfile();
void onSaveToEmail();
@@ -60,11 +64,23 @@ LLPanelSnapshotOptions::LLPanelSnapshotOptions()
mCommitCallbackRegistrar.add("Snapshot.SaveToEmail", boost::bind(&LLPanelSnapshotOptions::onSaveToEmail, this));
mCommitCallbackRegistrar.add("Snapshot.SaveToInventory", boost::bind(&LLPanelSnapshotOptions::onSaveToInventory, this));
mCommitCallbackRegistrar.add("Snapshot.SaveToComputer", boost::bind(&LLPanelSnapshotOptions::onSaveToComputer, this));
+
+ LLGlobalEconomy::Singleton::getInstance()->addObserver(this);
+}
+
+LLPanelSnapshotOptions::~LLPanelSnapshotOptions()
+{
+ LLGlobalEconomy::Singleton::getInstance()->removeObserver(this);
}
// virtual
void LLPanelSnapshotOptions::onOpen(const LLSD& key)
{
+ updateUploadCost();
+}
+
+void LLPanelSnapshotOptions::updateUploadCost()
+{
S32 upload_cost = LLGlobalEconomy::Singleton::getInstance()->getPriceUpload();
getChild<LLUICtrl>("save_to_inventory_btn")->setLabelArg("[AMOUNT]", llformat("%d", upload_cost));
}