diff --git a/src/Editor/Icons.qrc b/src/Editor/Icons.qrc index bc472903..8a969d67 100644 --- a/src/Editor/Icons.qrc +++ b/src/Editor/Icons.qrc @@ -77,5 +77,6 @@ icons/Tree_24px.png icons/Gear_16px.png icons/Gear_24px.png + icons/ToParentFolder_16px.png diff --git a/src/Editor/ResourceBrowser/CResourceBrowser.cpp b/src/Editor/ResourceBrowser/CResourceBrowser.cpp index 74021df2..137f8cd1 100644 --- a/src/Editor/ResourceBrowser/CResourceBrowser.cpp +++ b/src/Editor/ResourceBrowser/CResourceBrowser.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -110,9 +111,10 @@ CResourceBrowser::CResourceBrowser(QWidget *pParent) QAction *pDisplayAssetIDsAction = new QAction("Display Asset IDs", this); pDisplayAssetIDsAction->setCheckable(true); - connect(pDisplayAssetIDsAction, SIGNAL(toggled(bool)), this, SLOT(SetAssetIdDisplayEnabled(bool))); + connect(pDisplayAssetIDsAction, SIGNAL(toggled(bool)), this, SLOT(SetAssetIDDisplayEnabled(bool))); pOptionsMenu->addAction(pDisplayAssetIDsAction); + pOptionsMenu->addAction("Find Asset by ID", this, SLOT(FindAssetByID())); pOptionsMenu->addAction("Rebuild Database", this, SLOT(RebuildResourceDB())); mpUI->OptionsToolButton->setMenu(pOptionsMenu); @@ -177,7 +179,7 @@ void CResourceBrowser::SetActiveDirectory(CVirtualDirectory *pDir) } } -void CResourceBrowser::SelectResource(CResourceEntry *pEntry) +void CResourceBrowser::SelectResource(CResourceEntry *pEntry, bool ClearFiltersIfNecessary /*= false*/) { ASSERT(pEntry); @@ -191,6 +193,12 @@ void CResourceBrowser::SelectResource(CResourceEntry *pEntry) UpdateFilter(); } + // Change filter + if (ClearFiltersIfNecessary && !mpProxyModel->IsTypeAccepted(pEntry->TypeInfo())) + { + ResetTypeFilter(); + } + // Select resource QModelIndex SourceIndex = mpModel->GetIndexForEntry(pEntry); QModelIndex ProxyIndex = mpProxyModel->mapFromSource(SourceIndex); @@ -416,8 +424,10 @@ void CResourceBrowser::UpdateDescriptionLabel() mpUI->TableDescriptionLabel->setText(Desc); // Update clear button status - bool EnableClearButton = (!mpUI->SearchBar->text().isEmpty() || mpModel->IsDisplayingUserEntryList() || (mpSelectedDir && !mpSelectedDir->IsRoot())); - mpUI->ClearButton->setEnabled(EnableClearButton); + bool CanGoUp = (mpSelectedDir && !mpSelectedDir->IsRoot()); + bool CanClear = (!mpUI->SearchBar->text().isEmpty() || mpModel->IsDisplayingUserEntryList()); + mpUI->ClearButton->setEnabled(CanGoUp || CanClear); + mpUI->ClearButton->setIcon( CanClear ? QIcon(":/icons/X_16px.png") : QIcon(":/icons/ToParentFolder_16px.png") ); } void CResourceBrowser::SetResourceTreeView() @@ -581,10 +591,48 @@ void CResourceBrowser::OnResourceSelectionChanged(const QModelIndex& rkNewIndex) emit SelectedResourceChanged(mpSelectedEntry); } -void CResourceBrowser::SetAssetIdDisplayEnabled(bool Enable) +void CResourceBrowser::FindAssetByID() +{ + if (!mpStore) + return; + + QString QStringAssetID = QInputDialog::getText(this, "Enter Asset ID", "Enter asset ID:"); + TString StringAssetID = TO_TSTRING(QStringAssetID); + + if (!StringAssetID.IsEmpty()) + { + EGame Game = mpStore->Game(); + EIDLength IDLength = CAssetID::GameIDLength(Game); + + if (StringAssetID.IsHexString(false, IDLength * 2)) + { + if (StringAssetID.StartsWith("0x", false)) + StringAssetID = StringAssetID.ChopFront(2); + + // Find the resource entry + CAssetID ID = (IDLength == e32Bit ? StringAssetID.ToInt32(16) : StringAssetID.ToInt64(16)); + CResourceEntry *pEntry = mpStore->FindEntry(ID); + + if (pEntry) + SelectResource(pEntry, true); + + // User entered unrecognized ID + else + UICommon::ErrorMsg(this, QString("Couldn't find any asset with ID %1").arg(QStringAssetID)); + } + + // User entered invalid string + else + UICommon::ErrorMsg(this, "The entered string is not a valid asset ID!"); + } + + // User entered nothing, don't do anything +} + +void CResourceBrowser::SetAssetIDDisplayEnabled(bool Enable) { mpDelegate->SetDisplayAssetIDs(Enable); - mpUI->ResourceTableView->repaint(); + mpModel->RefreshAllIndices(); } void CResourceBrowser::UpdateStore() diff --git a/src/Editor/ResourceBrowser/CResourceBrowser.h b/src/Editor/ResourceBrowser/CResourceBrowser.h index 00130f2c..322470da 100644 --- a/src/Editor/ResourceBrowser/CResourceBrowser.h +++ b/src/Editor/ResourceBrowser/CResourceBrowser.h @@ -56,7 +56,7 @@ public: ~CResourceBrowser(); void SetActiveDirectory(CVirtualDirectory *pDir); - void SelectResource(CResourceEntry *pEntry); + void SelectResource(CResourceEntry *pEntry, bool ClearFiltersIfNecessary = false); void SelectDirectory(CVirtualDirectory *pDir); void CreateFilterCheckboxes(); @@ -88,7 +88,8 @@ public slots: void OnDirectorySelectionChanged(const QModelIndex& rkNewIndex); void OnDoubleClickTable(QModelIndex Index); void OnResourceSelectionChanged(const QModelIndex& rkNewIndex); - void SetAssetIdDisplayEnabled(bool Enable); + void FindAssetByID(); + void SetAssetIDDisplayEnabled(bool Enable); void UpdateStore(); void SetProjectStore(); diff --git a/src/Editor/ResourceBrowser/CResourceBrowser.ui b/src/Editor/ResourceBrowser/CResourceBrowser.ui index 61d0cdc6..9def5819 100644 --- a/src/Editor/ResourceBrowser/CResourceBrowser.ui +++ b/src/Editor/ResourceBrowser/CResourceBrowser.ui @@ -212,7 +212,7 @@ - :/icons/X_16px.png:/icons/X_16px.png + :/icons/ToParentFolder_16px.png:/icons/ToParentFolder_16px.png diff --git a/src/Editor/ResourceBrowser/CResourceProxyModel.h b/src/Editor/ResourceBrowser/CResourceProxyModel.h index 55476c6c..8b3c3b2b 100644 --- a/src/Editor/ResourceBrowser/CResourceProxyModel.h +++ b/src/Editor/ResourceBrowser/CResourceProxyModel.h @@ -77,7 +77,7 @@ public: CVirtualDirectory *pDir = mpModel->IndexDirectory(Index); CResourceEntry *pEntry = mpModel->IndexEntry(Index); - if (pEntry && HasTypeFilter() && !mTypeFilter.contains(pEntry->TypeInfo())) + if (pEntry && !IsTypeAccepted(pEntry->TypeInfo())) return false; if (!mSearchString.IsEmpty()) @@ -109,6 +109,11 @@ public: return !mTypeFilter.isEmpty(); } + inline bool IsTypeAccepted(CResTypeInfo *pTypeInfo) const + { + return mTypeFilter.isEmpty() || mTypeFilter.contains(pTypeInfo); + } + inline void SetSortMode(ESortMode Mode) { if (mSortMode != Mode) diff --git a/src/Editor/ResourceBrowser/CResourceTableModel.cpp b/src/Editor/ResourceBrowser/CResourceTableModel.cpp index df05c7b4..ac722076 100644 --- a/src/Editor/ResourceBrowser/CResourceTableModel.cpp +++ b/src/Editor/ResourceBrowser/CResourceTableModel.cpp @@ -274,6 +274,17 @@ int CResourceTableModel::EntryListIndex(CResourceEntry *pEntry) return qLowerBound(mEntries, pEntry) - mEntries.constBegin(); } +void CResourceTableModel::RefreshAllIndices() +{ + int NumRows = rowCount(QModelIndex()); + int NumCols = columnCount(QModelIndex()); + + if (NumRows > 0 && NumCols > 0) + { + emit dataChanged( index(0,0), index(NumRows-1, NumCols-1) ); + } +} + void CResourceTableModel::CheckAddDirectory(CVirtualDirectory *pDir) { if (pDir->Parent() == mpCurrentDir) diff --git a/src/Editor/ResourceBrowser/CResourceTableModel.h b/src/Editor/ResourceBrowser/CResourceTableModel.h index ff5d2e3f..c7b16de5 100644 --- a/src/Editor/ResourceBrowser/CResourceTableModel.h +++ b/src/Editor/ResourceBrowser/CResourceTableModel.h @@ -58,6 +58,7 @@ public: inline QString ModelDescription() const { return mModelDescription; } public slots: + void RefreshAllIndices(); void CheckAddDirectory(CVirtualDirectory *pDir); void CheckRemoveDirectory(CVirtualDirectory *pDir); void OnResourceMoved(CResourceEntry *pEntry, CVirtualDirectory *pOldDir, TString OldName); diff --git a/src/Editor/Widgets/CResourceSelector.cpp b/src/Editor/Widgets/CResourceSelector.cpp index a50816d3..ad9864a9 100644 --- a/src/Editor/Widgets/CResourceSelector.cpp +++ b/src/Editor/Widgets/CResourceSelector.cpp @@ -276,7 +276,7 @@ void CResourceSelector::Find() if (mpResEntry) { CResourceBrowser *pBrowser = gpEdApp->ResourceBrowser(); - pBrowser->SelectResource(mpResEntry); + pBrowser->SelectResource(mpResEntry, true); } } diff --git a/src/Editor/icons/ToParentFolder_16px.png b/src/Editor/icons/ToParentFolder_16px.png new file mode 100644 index 00000000..60785be5 Binary files /dev/null and b/src/Editor/icons/ToParentFolder_16px.png differ