Merge pull request #1489 from Areloch/DirectImageFileOption

Direct image file option
This commit is contained in:
Brian Roberts 2025-05-31 07:18:24 -05:00 committed by GitHub
commit f709130e72
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 92 additions and 154 deletions

View file

@ -289,7 +289,7 @@ StringTableEntry ImageAsset::getAssetIdByFilename(StringTableEntry fileName)
Torque::Path temp1 = temp->getImageFile();
Torque::Path temp2 = fileName;
if (temp1.getFileName() == temp2.getFileName())
if (temp1.getPath() == temp2.getPath() && temp1.getFileName() == temp2.getFileName())
{
return imgAsset;
}

View file

@ -244,7 +244,8 @@ DefineEnumType(ImageAssetType);
#define DECLARE_IMAGEASSET(className, name, profile) \
private: \
AssetPtr<ImageAsset> m##name##Asset; \
AssetPtr<ImageAsset> m##name##Asset;\
String m##name##File;\
public: \
void _set##name(StringTableEntry _in){ \
if(m##name##Asset.getAssetId() == _in) \
@ -296,6 +297,7 @@ public:
#define DECLARE_IMAGEASSET_NET(className, name, profile, mask) \
private: \
AssetPtr<ImageAsset> m##name##Asset; \
String m##name##File;\
public: \
void _set##name(StringTableEntry _in){ \
if(m##name##Asset.getAssetId() == _in) \
@ -347,12 +349,14 @@ public:
#define INITPERSISTFIELD_IMAGEASSET(name, consoleClass, docs) \
addProtectedField(assetText(name, Asset), TypeImageAssetPtr, Offset(m##name##Asset, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, asset docs.));
addProtectedField(assetText(name, Asset), TypeImageAssetPtr, Offset(m##name##Asset, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, asset docs.)); \
addProtectedField(assetText(name, File), TypeFilename, Offset(m##name##File, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, file docs.));
#define DECLARE_IMAGEASSET_ARRAY(className, name, profile, max) \
private: \
AssetPtr<ImageAsset> m##name##Asset[max]; \
String m##name##File[max];\
public: \
void _set##name(StringTableEntry _in, const U32& index){ \
if(m##name##Asset[index].getAssetId() == _in) \
@ -405,6 +409,7 @@ public:
#define DECLARE_IMAGEASSET_ARRAY_NET(className, name, profile, max, mask) \
private: \
AssetPtr<ImageAsset> m##name##Asset[max]; \
String m##name##File[max];\
public: \
void _set##name(StringTableEntry _in, const U32& index){ \
if(m##name##Asset[index].getAssetId() == _in) \

View file

@ -626,28 +626,13 @@ const char* ShapeAsset::generateCachedPreviewImage(S32 resolution, String overri
delete imposterCap;
delete shape;
String dumpPath = String(mFilePath) + "_Preview.dds";
String dumpPath = String(mFilePath) + ".png";
char* returnBuffer = Con::getReturnBuffer(128);
dSprintf(returnBuffer, 128, "%s", dumpPath.c_str());
/*FileStream stream;
if (stream.open(dumpPath, Torque::FS::File::Write))
destBmp.writeBitmap("png", stream);
stream.close();*/
imposter->writeBitmap("png", dumpPath);
DDSFile* ddsDest = DDSFile::createDDSFileFromGBitmap(imposter);
ImageUtil::ddsCompress(ddsDest, GFXFormatBC2);
// Finally save the imposters to disk.
FileStream fs;
if (fs.open(returnBuffer, Torque::FS::File::Write))
{
ddsDest->write(fs);
fs.close();
}
delete ddsDest;
delete imposter;
delete imposterNrml;

View file

@ -132,6 +132,7 @@ GuiBitmapButtonCtrl::GuiBitmapButtonCtrl()
mBitmapName = StringTable->EmptyString();
mBitmap = NULL;
mBitmapAsset.registerRefreshNotify(this);
mBitmapFile = String::EmptyString;
}
//-----------------------------------------------------------------------------

View file

@ -118,7 +118,11 @@ class GuiBitmapButtonCtrl : public GuiButtonCtrl, protected AssetPtrCallback
///
BitmapMode mBitmapMode;
private: AssetPtr<ImageAsset> mBitmapAsset; public: void _setBitmap(StringTableEntry _in) {
private:
AssetPtr<ImageAsset> mBitmapAsset;
String mBitmapFile;
public:
void _setBitmap(StringTableEntry _in) {
if (mBitmapAsset.getAssetId() == _in) return; if (!AssetDatabase.isDeclaredAsset(_in)) {
StringTableEntry imageAssetId = ImageAsset::smNoImageAssetFallback; AssetQuery query; S32 foundAssetcount = AssetDatabase.findAssetLooseFile(&query, _in); if (foundAssetcount != 0) {
imageAssetId = query.mAssetList[0];

View file

@ -121,7 +121,7 @@ void GuiBitmapCtrl::setBitmap(const char* name, bool resize)
if (assetId != StringTable->EmptyString())
_setBitmap(assetId);
else
return;
_setBitmap(name);
}
mBitmap = mBitmapAsset->getTexture(&GFXDefaultGUIProfile);