Added support for WResourceSelector to have multiple allowed file extensions (required for Prime 3)

This commit is contained in:
parax0 2015-07-27 16:17:22 -04:00
parent 8804c436ed
commit 0577c8a0fa
11 changed files with 366 additions and 180 deletions

View File

@ -108,3 +108,13 @@ bool CFourCC::operator<=(const CFourCC& other) const
{ {
return (ToLong() <= other.ToLong()); return (ToLong() <= other.ToLong());
} }
char CFourCC::operator[](int index)
{
return mFourCC[index];
}
const char CFourCC::operator[](int index) const
{
return mFourCC[index];
}

View File

@ -33,7 +33,8 @@ public:
bool operator>=(const CFourCC& other) const; bool operator>=(const CFourCC& other) const;
bool operator<(const CFourCC& other) const; bool operator<(const CFourCC& other) const;
bool operator<=(const CFourCC& other) const; bool operator<=(const CFourCC& other) const;
char operator[](int index);
const char operator[](int index) const;
}; };
#endif // CFOURCC_H #endif // CFOURCC_H

View File

@ -51,46 +51,65 @@ EResType CResource::ResTypeForExtension(CFourCC Extension)
{ {
Extension = Extension.ToUpper(); Extension = Extension.ToUpper();
if (Extension == "AFSM") return eStateMachine; if (Extension < "FONT")
if (Extension == "AGSC") return eAudioGrp; {
if (Extension == "ANCS") return eCharacter; if (Extension < "CSKR")
if (Extension == "ANIM") return eAnimation; {
if (Extension == "ATBL") return eAudioTable; if (Extension == "AFSM") return eStateMachine;
if (Extension == "CAUD") return eAudioData; if (Extension == "AGSC") return eAudioGrp;
if (Extension == "CINF") return eSkeleton; if (Extension == "ANCS") return eAnimSet;
if (Extension == "CMDL") return eModel; if (Extension == "ANIM") return eAnimation;
if (Extension == "CRSC") return eCollisionResponse; if (Extension == "ATBL") return eAudioTable;
if (Extension == "CSKR") return eSkin; if (Extension == "CAUD") return eAudioData;
if (Extension == "CSMP") return eAudioSample; if (Extension == "CHAR") return eAnimSet;
if (Extension == "CSNG") return eMidi; if (Extension == "CINF") return eSkeleton;
if (Extension == "CTWK") return eTweak; if (Extension == "CMDL") return eModel;
if (Extension == "DCLN") return eCollisionMesh; if (Extension == "CRSC") return eCollisionResponse;
if (Extension == "DGRP") return eDependencyGroup; }
if (Extension == "DSP ") return eMusicTrack; else
if (Extension == "DUMB") return eDataDump; {
if (Extension == "ELSC") return eParticleElectric; if (Extension == "CSKR") return eSkin;
if (Extension == "EVNT") return eAnimEventData; if (Extension == "CSMP") return eAudioSample;
if (Extension == "FONT") return eFont; if (Extension == "CSNG") return eMidi;
if (Extension == "FRME") return eGuiFrame; if (Extension == "CTWK") return eTweak;
if (Extension == "FSM2") return eStateMachine; if (Extension == "DCLN") return eCollisionMesh;
if (Extension == "HINT") return eHintSystem; if (Extension == "DGRP") return eDependencyGroup;
if (Extension == "MAPA") return eMapArea; if (Extension == "DSP ") return eMusicTrack;
if (Extension == "MAPW") return eMapWorld; if (Extension == "DUMB") return eDataDump;
if (Extension == "MAPU") return eMapUniverse; if (Extension == "ELSC") return eParticleElectric;
if (Extension == "MLVL") return eWorld; if (Extension == "EVNT") return eAnimEventData;
if (Extension == "MREA") return eArea; }
if (Extension == "NTWK") return eTweak; }
if (Extension == "PAK ") return ePackFile; else
if (Extension == "PART") return eParticle; {
if (Extension == "PATH") return eNavMesh; if (Extension < "PAK ")
if (Extension == "SAVW") return eSaveWorld; {
if (Extension == "SCAN") return eScan; if (Extension == "FONT") return eFont;
if (Extension == "STRG") return eStringTable; if (Extension == "FRME") return eGuiFrame;
if (Extension == "STRM") return eAudioStream; if (Extension == "FSM2") return eStateMachine;
if (Extension == "SWHC") return eParticleSwoosh; if (Extension == "HINT") return eHintSystem;
if (Extension == "THP ") return eVideo; if (Extension == "MAPA") return eMapArea;
if (Extension == "TXTR") return eTexture; if (Extension == "MAPW") return eMapWorld;
if (Extension == "WPSC") return eProjectile; if (Extension == "MAPU") return eMapUniverse;
if (Extension == "MLVL") return eWorld;
if (Extension == "MREA") return eArea;
if (Extension == "NTWK") return eTweak;
}
else
{
if (Extension == "PAK ") return ePackFile;
if (Extension == "PART") return eParticle;
if (Extension == "PATH") return eNavMesh;
if (Extension == "SAVW") return eSaveWorld;
if (Extension == "SCAN") return eScan;
if (Extension == "STRG") return eStringTable;
if (Extension == "STRM") return eAudioStream;
if (Extension == "SWHC") return eParticleSwoosh;
if (Extension == "THP ") return eVideo;
if (Extension == "TXTR") return eTexture;
if (Extension == "WPSC") return eProjectile;
}
}
return eInvalidResType; return eInvalidResType;
} }

View File

@ -5,45 +5,46 @@ enum EResType
{ {
eAnimation = 0, eAnimation = 0,
eAnimEventData = 1, eAnimEventData = 1,
eArea = 2, eAnimSet = 2,
eAudioData = 3, eArea = 3,
eAudioGrp = 4, eAudioData = 4,
eAudioSample = 5, eAudioGrp = 5,
eAudioStream = 6, eAudioSample = 6,
eAudioTable = 7, eAudioStream = 7,
eCharacter = 8, eAudioTable = 8,
eCollisionMesh = 9, eCharacter = 9,
eCollisionResponse = 10, eCollisionMesh = 10,
eDataDump = 11, eCollisionResponse = 11,
eDecal = 12, eDataDump = 12,
eDependencyGroup = 13, eDecal = 13,
eFont = 14, eDependencyGroup = 14,
eGuiFrame = 15, eFont = 15,
eHintSystem = 16, eGuiFrame = 16,
eInvalidResType = 17, eHintSystem = 17,
eMapArea = 18, eInvalidResType = 18,
eMapWorld = 19, eMapArea = 19,
eMapUniverse = 20, eMapWorld = 20,
eMidi = 21, eMapUniverse = 21,
eModel = 22, eMidi = 22,
eMusicTrack = 23, eModel = 23,
eNavMesh = 24, eMusicTrack = 24,
ePackFile = 25, eNavMesh = 25,
eParticle = 26, ePackFile = 26,
eParticleElectric = 27, eParticle = 27,
eParticleSwoosh = 28, eParticleElectric = 28,
eProjectile = 29, eParticleSwoosh = 29,
eResource = 30, eProjectile = 30,
eSaveWorld = 31, eResource = 31,
eScan = 32, eSaveWorld = 32,
eSkeleton = 33, eScan = 33,
eSkin = 34, eSkeleton = 34,
eStateMachine = 35, eSkin = 35,
eStringTable = 36, eStateMachine = 36,
eTexture = 37, eStringTable = 37,
eTweak = 38, eTexture = 38,
eVideo = 39, eTweak = 39,
eWorld = 40 eVideo = 40,
eWorld = 41
}; };
#endif // ERESTYPE #endif // ERESTYPE

View File

@ -4,6 +4,7 @@
/* /*
* This header file declares some classes used to track script object properties * This header file declares some classes used to track script object properties
* CPropertyBase, __CProperty (and typedefs), CPropertyStruct * CPropertyBase, __CProperty (and typedefs), CPropertyStruct
* It's a bit hard to read, should be reorganized at some point
*/ */
#include "../CResource.h" #include "../CResource.h"
#include "CScriptTemplate.h" #include "CScriptTemplate.h"
@ -91,6 +92,10 @@ public:
mToken = CToken(v); mToken = CToken(v);
} }
} }
const CStringList& AllowedExtensions()
{
return static_cast<CFileTemplate*>(Template())->Extensions();
}
}; };
/* /*

View File

@ -41,9 +41,9 @@ CModelEditorWindow::CModelEditorWindow(QWidget *parent) :
// UI initialization // UI initialization
UpdateAnimParamUI(-1); UpdateAnimParamUI(-1);
ui->IndTextureResSelector->SetResType(eTexture); ui->IndTextureResSelector->SetAllowedExtensions("TXTR");
ui->IndTextureResSelector->SetPreviewPanelEnabled(true); ui->IndTextureResSelector->SetPreviewPanelEnabled(true);
ui->PassTextureResSelector->SetResType(eTexture); ui->PassTextureResSelector->SetAllowedExtensions("TXTR");
ui->PassTextureResSelector->SetPreviewPanelEnabled(true); ui->PassTextureResSelector->SetPreviewPanelEnabled(true);
ui->PassTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); ui->PassTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
ui->PassTable->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents); ui->PassTable->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);

View File

@ -1,46 +1,153 @@
#include "UICommon.h" #include "UICommon.h"
// This array is intended to be used with the EResType enum namespace UICommon
const QString gskResourceFilters[] = { {
"Animation (*.ANIM)", // eAnimation
"Animation Event Data (*.EVNT)", // eAnimEventData QMap<QString,QString> FilterMap = {
"Area (*.MREA)", // eArea { "AFSM", "AI Finite State Machine (*.AFSM)" },
"Audio Metadata (*.CAUD)", // eAudioData { "ANIM", "Animation (*.ANIM)" },
"Audio Group (*.AGSC)", // eAudioGrp { "ANCS", "Animation Character Set (*.ANCS)" },
"Audio Sample (*.CSMP)", // eAudioSample { "AGSC", "Audio Group (*.AGSC)" },
"Audio Stream (*.STRM)", // eAudioStream { "ATBL", "Audio Lookup Table (*.ATBL)" },
"Audio Lookup Table (*.ATBL)", // eAudioTable { "CAUD", "Audio Metadata (*.CAUD)" },
"Character (*.ANCS *.CHAR)", // eCharacter { "CHAR", "Character (*.CHAR)" },
"Collision Mesh (*.DCLN)", // eCollisionMesh { "CINF", "Skeleton (*.CINF)" },
"Collision Response Data (*.CRSC)", // eCollisionResponse { "CMDL", "Model (*.CMDL)" },
"Data Dump (*.DUMB)", // eDataDump { "CRSC", "Collision Response Data (*.CRSC)" },
"Decal (*.DPSC)", // eDecal { "CSKR", "Skin Rules (*.CSKR)" },
"Dependency Group (*.DGRP)", // eDependencyGroup { "CSMP", "Audio Sample (*.CSMP)" },
"Font (*.FONT)", // eFont { "CSNG", "MIDI Data (*.CSNG)" },
"GUI Frame (*.FRME)", // eGuiFrame { "CTWK", "Tweaks (*.CTWK)" },
"Hint System Data (*.HINT)", // eHintSystem { "DCLN", "Collision Mesh (*.DCLN)" },
"Invalid resource type", // eInvalid { "DGRP", "Dependency Group (*.DGRP)" },
"Area Map (*.MAPA)", // eMapArea { "DPSC", "Decal (*.DPSC)" },
"World Map (*.MAPW)", // eMapWorld { "DSP", "Music Track (*.DSP)" },
"Universe Map (*.MAPU)", // eMapUniverse { "DUMB", "Binary Data Dump (*.DUMB)" },
"MIDI Data (*.CSNG)", // eMidi { "ELSC", "Electric Particle (*.ELSC)" },
"Model (*.CMDL)", // eModel { "EVNT", "Animation Event Data (*.EVNT)" },
"Music Track (*.DSP)", // eMusicTrack { "FRME", "GUI Frame (*.FRME)" },
"Navigation Mesh (*.PATH)", // eNavMesh { "FSM2", "AI Finite State Machine (*.FSM2)" },
"Pack File (*.pak)", // ePackFile { "FONT", "Font (*.FONT)" },
"Particle (*.PART)", // eParticle { "HINT", "Hint System Data (*.HINT)" },
"Electricity Particle (*.ELSC)", // eParticleElectric { "MAPA", "Area Map (*.MAPA)" },
"Swoosh Particle (*.SWHC)", // eParticleSwoosh { "MAPW", "World Map (*.MAPW)" },
"Projectile (*.WPSC)", // eProjectile { "MAPU", "Universe Map (*.MAPU)" },
"Invalid resource type", // eResource { "MLVL", "World (*.MLVL)" },
"World Save Data (*.SAVW)", // eSaveWorld { "MREA", "Area (*.MREA)" },
"Scannable Object Info (*.SCAN)", // eScan { "NTWK", "Tweaks (*.NTWK)" },
"Skeleton (*.CINF)", // eSkeleton { "PATH", "AI Navigation Mesh (*.PATH)" },
"Skin (*.CSKR)", // eSkin { "PAK", "Pack File (*.pak)" },
"State Machine (*.AFSM *.FSM2)", // eStateMachine { "PART", "Particle (*.PART)" },
"String Table (*.STRG)", // eStringTable { "SAVW", "World Save Data (*.SAVW)" },
"Texture (*.TXTR)", // eTexture { "SCAN", "Scannable Object Info (*.SCAN)" },
"Tweak (*.CTWK *.ntwk)", // eTweak { "STRG", "String Table (*.STRG)" },
"Video (*.thp)", // eVideo { "STRM", "Audio Stream (*.STRM)" },
"World (*.MLVL)" // eWorld { "SWHC", "Swoosh Particle (*.SWHC)" },
{ "THP", "Video (*.thp)" },
{ "TXTR", "Texture (*.TXTR)" },
{ "WPSC", "Projectile (*.WPSC)" }
}; };
QString ExtensionFilterString(const QString& extension)
{
QMap<QString,QString>::const_iterator it = FilterMap.find(extension);
if (it != FilterMap.end())
return it.value();
else
return "Unknown Extension (*." + extension + ")";
/*if (extension.isEmpty()) return gskInvalidFilterString;
extension = extension.toUpper();
switch (extension[0])
{
case 'A':
if (extension == "AFSM") return "AI Finite State Machine (*.AFSM)";
if (extension == "ANIM") return "Animation (*.ANIM)";
if (extension == "ANCS") return "Animation Character Set (*.ANCS)";
if (extension == "AGSC") return "Audio Group (*.AGSC)";
if (extension == "ATBL") return "Audio Lookup Table (*.ATBL)";
break;
case 'C':
if (extension[1] <= 'R')
{
if (extension == "CAUD") return "Audio Metadata (*.CAUD)";
if (extension == "CHAR") return "Character (*.CHAR)";
if (extension == "CINF") return "Skeleton (*.CINF)";
if (extension == "CMDL") return "Model (*.CMDL)";
if (extension == "CRSC") return "Collision Response Data (*.CRSC)";
}
else
{
if (extension == "CSKR") return "Skin Rules (*.CSKR)";
if (extension == "CSMP") return "Audio Sample (*.CSMP)";
if (extension == "CSNG") return "MIDI Data (*.CSNG)";
if (extension == "CTWK") return "Tweaks (*.CTWK)";
}
break;
case 'D':
if (extension == "DCLN") return "Collision Mesh (*.DCLN)";
if (extension == "DGRP") return "Dependency Group (*.DGRP)";
if (extension == "DPSC") return "Decal (*.DPSC)";
if (extension == "DSP") return "Music Track (*.DSP)";
if (extension == "DUMB") return "Binary Data Dump (*.DUMB)";
break;
case 'E':
if (extension == "ELSC") return "Electric Particle (*.ELSC)";
if (extension == "EVNT") return "Animation Event Data (*.EVNT)";
break;
case 'F':
if (extension == "FRME") return "GUI Frame (*.FRME)";
if (extension == "FSM2") return "AI Finite State Machine (*.FSM2)";
if (extension == "FONT") return "Font (*.FONT)";
break;
case 'H':
if (extension == "HINT") return "Hint System Data (*.HINT)";
break;
case 'M':
if (extension == "MAPA") return "Area Map (*.MAPA)";
if (extension == "MAPW") return "World Map (*.MAPW)";
if (extension == "MAPU") return "Universe Map (*.MAPU)";
if (extension == "MLVL") return "World (*.MLVL)";
if (extension == "MREA") return "Area (*.MREA)";
break;
case 'N':
if (extension == "NTWK") return "Tweaks (*.ntwk)";
break;
case 'P':
if (extension == "PATH") return "AI Navigation Mesh (*.PATH)";
if (extension == "PAK") return "Pack File (*.pak)";
if (extension == "PART") return "Particle (*.PART)";
break;
case 'S':
if (extension == "SAVW") return "World Save Data (*.SAVW)";
if (extension == "SCAN") return "Scannable Object Info (*.SCAN)";
if (extension == "STRG") return "String Table (*.STRG)";
if (extension == "STRM") return "Audio Stream (*.STRM)";
if (extension == "SWHC") return "Swoosh Particle (*.SWHC)";
break;
case 'T':
if (extension == "THP") return "Video (*.thp)";
if (extension == "TXTR") return "Texture (*.TXTR)";
break;
case 'W':
if (extension == "WPSC") return "Projectile (*.WPSC)";
break;
}
return gskInvalidFilterString;*/
}
}

View File

@ -1,9 +1,14 @@
#ifndef UICOMMON #ifndef UICOMMON
#define UICOMMON #define UICOMMON
#include <QMap>
#include <QString> #include <QString>
extern const QString gskResourceFilters[]; namespace UICommon
{
extern QMap<QString,QString> FilterMap;
QString ExtensionFilterString(const QString& extension);
}
#endif // UICOMMON #endif // UICOMMON

View File

@ -190,6 +190,7 @@ void WPropertyEditor::CreateEditor()
WResourceSelector *pResourceSelector = new WResourceSelector(this); WResourceSelector *pResourceSelector = new WResourceSelector(this);
pResourceSelector->AdjustPreviewToParent(true); pResourceSelector->AdjustPreviewToParent(true);
pResourceSelector->SetAllowedExtensions(pFileCast->AllowedExtensions());
pResourceSelector->SetResource(pFileCast->Get()); pResourceSelector->SetResource(pFileCast->Get());
mUI.EditorWidget = pResourceSelector; mUI.EditorWidget = pResourceSelector;
@ -316,6 +317,7 @@ void WPropertyEditor::UpdateEditor()
{ {
CFileProperty *pFileCast = static_cast<CFileProperty*>(mpProperty); CFileProperty *pFileCast = static_cast<CFileProperty*>(mpProperty);
WResourceSelector *pResourceSelector = static_cast<WResourceSelector*>(mUI.EditorWidget); WResourceSelector *pResourceSelector = static_cast<WResourceSelector*>(mUI.EditorWidget);
pResourceSelector->SetAllowedExtensions(pFileCast->AllowedExtensions());
pResourceSelector->SetResource(pFileCast->Get()); pResourceSelector->SetResource(pFileCast->Get());
break; break;
} }

View File

@ -13,19 +13,20 @@
WResourceSelector::WResourceSelector(QWidget *parent) : QWidget(parent) WResourceSelector::WResourceSelector(QWidget *parent) : QWidget(parent)
{ {
// Initialize Members // Initialize Selector Members
mHasMultipleExtensions = false;
mShowEditButton = false; mShowEditButton = false;
mShowExportButton = false; mShowExportButton = false;
// Initialize Preview Panel Members
mpPreviewPanel = nullptr; mpPreviewPanel = nullptr;
mEnablePreviewPanel = true; mEnablePreviewPanel = true;
mPreviewPanelValid = false; mPreviewPanelValid = false;
mShowingPreviewPanel = false; mShowingPreviewPanel = false;
mAdjustPreviewToParent = false; mAdjustPreviewToParent = false;
// Initialize Resource Members
mpResource = nullptr; mpResource = nullptr;
mResType = eInvalidResType; mResourceValid = false;
// Create Widgets // Create Widgets
mUI.LineEdit = new QLineEdit(this); mUI.LineEdit = new QLineEdit(this);
@ -94,12 +95,20 @@ bool WResourceSelector::eventFilter(QObject *pObj, QEvent *pEvent)
return false; return false;
} }
// ************ GETTERS ************ bool WResourceSelector::IsSupportedExtension(const QString& extension)
EResType WResourceSelector::GetResType()
{ {
return mResType; foreach(const QString& str, mSupportedExtensions)
if (str == extension) return true;
return false;
} }
bool WResourceSelector::HasSupportedExtension(CResource* pRes)
{
return IsSupportedExtension( QString::fromStdString( StringUtil::GetExtension(pRes->FullSource()) ) );
}
// ************ GETTERS ************
QString WResourceSelector::GetText() QString WResourceSelector::GetText()
{ {
return mUI.LineEdit->text(); return mUI.LineEdit->text();
@ -129,14 +138,13 @@ void WResourceSelector::SetResource(CResource *pRes)
if (pRes) if (pRes)
{ {
CFourCC ext = StringUtil::GetExtension(pRes->Source()); mResourceValid = HasSupportedExtension(pRes);
mResType = CResource::ResTypeForExtension(ext);
mUI.LineEdit->setText(QString::fromStdString(pRes->Source())); mUI.LineEdit->setText(QString::fromStdString(pRes->Source()));
} }
else else
{ {
mResType = eInvalidResType; mResourceValid = false;
mUI.LineEdit->clear(); mUI.LineEdit->clear();
} }
@ -144,18 +152,17 @@ void WResourceSelector::SetResource(CResource *pRes)
SetButtonsBasedOnResType(); SetButtonsBasedOnResType();
} }
void WResourceSelector::SetResType(EResType Type) void WResourceSelector::SetAllowedExtensions(const QString& extension)
{ {
mResType = Type; mSupportedExtensions.clear();
mpResource = nullptr; mSupportedExtensions << extension;
mResToken.Unlock();
mUI.LineEdit->clear();
CreatePreviewPanel();
SetButtonsBasedOnResType();
} }
void WResourceSelector::SetResTypes(const CStringList &ExtensionList) void WResourceSelector::SetAllowedExtensions(const CStringList& extensions)
{ {
mSupportedExtensions.clear();
for (auto it = extensions.begin(); it != extensions.end(); it++)
mSupportedExtensions << QString::fromStdString(*it);
} }
void WResourceSelector::SetText(const QString& ResPath) void WResourceSelector::SetText(const QString& ResPath)
@ -197,14 +204,29 @@ void WResourceSelector::OnLineEditTextEdited()
void WResourceSelector::OnBrowseButtonClicked() void WResourceSelector::OnBrowseButtonClicked()
{ {
QString Filter = gskResourceFilters[mResType]; // Construct filter string
QString filter;
std::string ResTypeStr = Filter.toStdString(); if (mSupportedExtensions.size() > 1)
size_t EndName = ResTypeStr.find_last_of("(") - 1; {
ResTypeStr = ResTypeStr.substr(0, EndName); QString all = "All supported extensions (";
QString ResType = QString::fromStdString(ResTypeStr);
QString NewRes = QFileDialog::getOpenFileName(this, "Select " + ResType, "", Filter); for (u32 iExt = 0; iExt < mSupportedExtensions.size(); iExt++)
{
if (iExt > 0) all += " ";
all += "*." + mSupportedExtensions[iExt];
}
all += ")";
filter += all + ";;";
}
for (u32 iExt = 0; iExt < mSupportedExtensions.size(); iExt++)
{
if (iExt > 0) filter += ";;";
filter += UICommon::ExtensionFilterString(mSupportedExtensions[iExt]);
}
QString NewRes = QFileDialog::getOpenFileName(this, "Select resource", "", filter);
if (!NewRes.isEmpty()) if (!NewRes.isEmpty())
{ {
@ -236,10 +258,38 @@ void WResourceSelector::Export()
emit ExportResource(mpResource); emit ExportResource(mpResource);
} }
void WResourceSelector::LoadResource(const QString& ResPath)
{
mpResource = nullptr;
mResToken.Unlock();
std::string pathStr = ResPath.toStdString();
std::string ext = StringUtil::GetExtension(pathStr);
if (IsSupportedExtension( QString::fromStdString(ext) ))
{
if ((ext != "MREA") && (ext != "MLVL"))
{
mpResource = gResCache.GetResource(pathStr);
mResToken = CToken(mpResource);
if (mPreviewPanelValid) mpPreviewPanel->SetResource(mpResource);
}
else mResourceValid = false;
}
else mResourceValid = false;
SetButtonsBasedOnResType();
CreatePreviewPanel();
emit ResourceChanged(ResPath);
}
void WResourceSelector::CreatePreviewPanel() void WResourceSelector::CreatePreviewPanel()
{ {
delete mpPreviewPanel; delete mpPreviewPanel;
mpPreviewPanel = IPreviewPanel::CreatePanel(mResType, this);
if (mResourceValid)
mpPreviewPanel = IPreviewPanel::CreatePanel(mpResource->Type(), this);
if (!mpPreviewPanel) mPreviewPanelValid = false; if (!mpPreviewPanel) mPreviewPanelValid = false;
@ -253,7 +303,7 @@ void WResourceSelector::CreatePreviewPanel()
void WResourceSelector::ShowPreviewPanel() void WResourceSelector::ShowPreviewPanel()
{ {
if ((mPreviewPanelValid) && (mpResource != nullptr)) if (mPreviewPanelValid)
{ {
// Preferred panel point is lower-right, but can move if there's not enough room // Preferred panel point is lower-right, but can move if there's not enough room
QPoint Position = parentWidget()->mapToGlobal(pos()); QPoint Position = parentWidget()->mapToGlobal(pos());
@ -293,33 +343,17 @@ void WResourceSelector::HidePreviewPanel()
} }
} }
void WResourceSelector::LoadResource(const QString& ResPath)
{
mpResource = nullptr;
mResToken.Unlock();
if ((mResType != eArea) && (mResType != eWorld))
{
std::string PathStr = ResPath.toStdString();
CFourCC ResExt = StringUtil::GetExtension(PathStr).c_str();
if (CResource::ResTypeForExtension(ResExt) == mResType)
{
mpResource = gResCache.GetResource(PathStr);
mResToken = CToken(mpResource);
if (mPreviewPanelValid) mpPreviewPanel->SetResource(mpResource);
}
}
emit ResourceChanged(ResPath);
}
void WResourceSelector::SetButtonsBasedOnResType() void WResourceSelector::SetButtonsBasedOnResType()
{ {
// Basically this function sets whether the "Export" and "Edit" // Basically this function sets whether the "Export" and "Edit"
// buttons are present based on the resource type. // buttons are present based on the resource type.
switch (mResType) if (!mpResource)
{
SetEditButtonEnabled(false);
SetExportButtonEnabled(false);
}
else switch (mpResource->Type())
{ {
// Export button should be enabled here because CTexture already has a DDS export function // Export button should be enabled here because CTexture already has a DDS export function
// However, need to figure out what sort of interface to create to do it. Disabling until then. // However, need to figure out what sort of interface to create to do it. Disabling until then.

View File

@ -18,7 +18,6 @@ class WResourceSelector : public QWidget
// Selector // Selector
QStringList mSupportedExtensions; QStringList mSupportedExtensions;
bool mHasMultipleExtensions;
bool mShowEditButton; bool mShowEditButton;
bool mShowExportButton; bool mShowExportButton;
@ -32,7 +31,7 @@ class WResourceSelector : public QWidget
// Resource // Resource
CResource *mpResource; CResource *mpResource;
CToken mResToken; CToken mResToken;
EResType mResType; bool mResourceValid;
// UI // UI
struct { struct {
@ -43,6 +42,7 @@ class WResourceSelector : public QWidget
QHBoxLayout *Layout; QHBoxLayout *Layout;
} mUI; } mUI;
// Functions
signals: signals:
void ResourceChanged(const QString& NewResPath); void ResourceChanged(const QString& NewResPath);
void EditResource(CResource *pRes); void EditResource(CResource *pRes);
@ -53,9 +53,10 @@ public:
~WResourceSelector(); ~WResourceSelector();
bool event(QEvent *); bool event(QEvent *);
bool eventFilter(QObject *, QEvent *); bool eventFilter(QObject *, QEvent *);
bool IsSupportedExtension(const QString& extension);
bool HasSupportedExtension(CResource* pRes);
// Getters // Getters
EResType GetResType();
QString GetText(); QString GetText();
bool IsEditButtonEnabled(); bool IsEditButtonEnabled();
bool IsExportButtonEnabled(); bool IsExportButtonEnabled();
@ -63,8 +64,9 @@ public:
// Setters // Setters
void SetResource(CResource *pRes); void SetResource(CResource *pRes);
void SetResType(EResType Type); void SetAllowedExtensions(const QString& extension);
void SetResTypes(const CStringList& ExtensionList); void SetAllowedExtensions(const QStringList& extensions);
void SetAllowedExtensions(const CStringList& extensions);
void SetText(const QString& ResPath); void SetText(const QString& ResPath);
void SetEditButtonEnabled(bool Enabled); void SetEditButtonEnabled(bool Enabled);
void SetExportButtonEnabled(bool Enabled); void SetExportButtonEnabled(bool Enabled);
@ -81,10 +83,10 @@ public slots:
private: private:
void Edit(); void Edit();
void Export(); void Export();
void LoadResource(const QString& ResPath);
void CreatePreviewPanel(); void CreatePreviewPanel();
void ShowPreviewPanel(); void ShowPreviewPanel();
void HidePreviewPanel(); void HidePreviewPanel();
void LoadResource(const QString& ResPath);
void SetButtonsBasedOnResType(); void SetButtonsBasedOnResType();
}; };