[Local Textures] These should persist through relogs, duh!

This commit is contained in:
Lirusaito
2019-02-09 19:53:30 -05:00
parent 136cffbab9
commit 1df39f81ee
4 changed files with 83 additions and 19 deletions

View File

@@ -64,6 +64,8 @@ this feature is still a work in progress.
#include "llviewermenufile.h"
#include "llfloaterimagepreview.h"
#include "llfile.h"
#include "llsdparam.h"
#include "llsdserialize.h"
/* including to force rebakes when needed */
#include "llvoavatarself.h"
@@ -93,18 +95,27 @@ bool LocalAssetBrowser::mSculptUpdated;
containing one loaded local texture.
*/
LocalBitmap::LocalBitmap(std::string fullpath)
LocalBitmap::Params::Params(const std::string& path)
: fullpath("path", path)
, keep_updating("update", gSavedSettings.getBOOL("LocalBitmapUpdate"))
, type("type", TYPE_TEXTURE)
, id("id", LLUUID::generateNewID())
{
}
LocalBitmap::LocalBitmap(const Params& p)
{
llassert(!p.fullpath.empty());
valid = false;
if ( gDirUtilp->fileExists(fullpath) )
if ( gDirUtilp->fileExists(p.fullpath) )
{
/* taking care of basic properties */
id.generate();
filename = fullpath;
keep_updating = gSavedSettings.getBOOL("LocalBitmapUpdate");
id = p.id;
filename = p.fullpath;
keep_updating = p.keep_updating;
linkstatus = keep_updating ? LINK_ON : LINK_OFF;
shortname = gDirUtilp->getBaseFileName(filename, true);
bitmap_type = TYPE_TEXTURE;
bitmap_type = p.type;
sculpt_dirty = false;
volume_dirty = false;
@@ -142,6 +153,7 @@ LocalBitmap::LocalBitmap(std::string fullpath)
/* filename is valid, bitmap is decoded and valid, i can haz liftoff! */
valid = true;
LocalAssetBrowser::add(*this);
}
}
}
@@ -428,6 +440,15 @@ void LocalBitmap::getDebugInfo() const
<< "==========================" << LL_ENDL;
}
LLSD LocalBitmap::asLLSD() const
{
return LLSD()
.with("path", filename)
.with("id", id)
.with("update", keep_updating)
.with("type", bitmap_type);
}
/*=======================================*/
/* LocalAssetBrowser: internal class */
/*=======================================*/
@@ -437,15 +458,47 @@ void LocalBitmap::getDebugInfo() const
Sits in memory until the viewer is closed.
*/
const std::string LocalAssetBrowser::getFileName() const
{
return gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "local_assets.xml");
}
LocalAssetBrowser::LocalAssetBrowser()
{
gLocalBrowser = this;
mLayerUpdated = false;
mSculptUpdated = false;
// Load bitmaps
llifstream file(getFileName());
if (!file) return;
LLSD saved_assets;
LLSDSerialize::fromXML(saved_assets, file);
file.close();
for (auto it = saved_assets.beginArray(), end = saved_assets.endArray(); it < end; ++it)
{
const auto&& p = LLSDParamAdapter<LocalBitmap::Params>(*it);
LocalBitmap bm(p); // Creating one adds it to the list
}
if (!loaded_bitmaps.empty()) PingTimer();
}
LocalAssetBrowser::~LocalAssetBrowser()
{
// Save bitmaps
llofstream file(getFileName());
if (!file)
{
LL_WARNS() << "Could not open file " << getFileName() << " for saving." << LL_ENDL;
return;
}
LLSD saved_assets(LLSD::emptyArray());
for (const auto& bitmap : loaded_bitmaps)
saved_assets.append(bitmap.asLLSD());
LLSDSerialize::toPrettyXML(saved_assets, file);
file.close();
gLocalBrowser = nullptr;
}
void LocalAssetBrowser::AddBitmap()
@@ -461,20 +514,13 @@ void LocalAssetBrowser::AddBitmap_continued(AIFilePicker* filepicker)
return;
bool change_happened = false;
std::vector<std::string> const& filenames(filepicker->getFilenames());
for(std::vector<std::string>::const_iterator filename = filenames.begin(); filename != filenames.end(); ++filename)
{
LocalBitmap unit(*filename);
if (unit.getIfValidBool())
{
loaded_bitmaps.push_back(unit);
for(const auto& filename : filepicker->getFilenames())
if (LocalBitmap(filename).getIfValidBool())
change_happened = true;
}
}
if (change_happened) onChangeHappened();
}
void LocalAssetBrowser::DelBitmap( std::vector<LLScrollListItem*> delete_vector, S32 column )
{
bool change_happened = false;

View File

@@ -97,7 +97,15 @@ struct affected_object
class LocalBitmap
{
public:
LocalBitmap(std::string filename);
struct Params : public LLInitParam::Block<Params>
{
Mandatory<std::string> fullpath;
Optional<bool> keep_updating;
Optional<S32> type;
Optional<LLUUID> id;
Params(const std::string& path = LLStringUtil::null);
};
LocalBitmap(const Params& p);
virtual ~LocalBitmap();
friend class LocalAssetBrowser;
@@ -138,6 +146,8 @@ class LocalBitmap
bool getIfValidBool() const;
S32 getType() const;
void getDebugInfo() const;
LLSD asLLSD() const;
private: /* [maintenence functions] */
void updateSelf();
@@ -174,9 +184,10 @@ class LocalBitmap
class AIFilePicker;
class LocalAssetBrowser
class LocalAssetBrowser : public LLSingleton<LocalAssetBrowser>
{
public:
const std::string getFileName() const;
LocalAssetBrowser();
virtual ~LocalAssetBrowser();
friend class FloaterLocalAssetBrowser;
@@ -184,6 +195,7 @@ class LocalAssetBrowser
static void UpdateTextureCtrlList(LLScrollListCtrl*);
static void setLayerUpdated(bool toggle) { mLayerUpdated = toggle; }
static void setSculptUpdated(bool toggle) { mSculptUpdated = toggle; }
static void add(const LocalBitmap& unit) { loaded_bitmaps.push_back(unit); }
static void AddBitmap();
static void AddBitmap_continued(AIFilePicker* filepicker);
static void DelBitmap( std::vector<LLScrollListItem*>, S32 column = BITMAPLIST_COL_ID );

View File

@@ -165,6 +165,7 @@
// in save_settings_to_globals()
#include "llbutton.h"
#include "llcombobox.h"
#include "floaterlocalassetbrowse.h"
#include "llstatusbar.h"
#include "llsurface.h"
#include "llvosky.h"
@@ -1723,6 +1724,8 @@ bool LLAppViewer::cleanup()
LLFloaterTeleportHistory::saveFile("teleport_history.xml");
LocalAssetBrowser::deleteSingleton(); // <edit/>
// save mute list. gMuteList used to also be deleted here too.
LLMuteList::getInstance()->cache(gAgent.getID());

View File

@@ -217,6 +217,7 @@
#include "generichandlers.h"
// <edit>
#include "floaterlocalassetbrowse.h"
#include "llpanellogin.h"
//#include "llfloateravatars.h"
//#include "llactivation.h"
@@ -890,6 +891,8 @@ bool idle_startup()
LLToolMgr::getInstance()->initTools();
display_startup();
// Load local textures now, maybe someone wants to use them in UI (why?)
LocalAssetBrowser::instance(); // <edit/>
// Quickly get something onscreen to look at.
gViewerWindow->initWorldUI();
display_startup();