Merge pull request #7790 from spycrab/rp_fixes

ResourcePacks: Fix various bugs
This commit is contained in:
spycrab 2019-02-11 11:09:43 +01:00 committed by GitHub
commit eb11d045d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 15 deletions

View File

@ -160,6 +160,12 @@ void ResourcePackManager::RepopulateTable()
SelectionChanged(); SelectionChanged();
} }
// Revert the indicies as to be more intuitive for users
int ResourcePackManager::GetResourcePackIndex(QTableWidgetItem* item) const
{
return m_table_widget->rowCount() - 1 - item->row();
}
void ResourcePackManager::Change() void ResourcePackManager::Change()
{ {
auto items = m_table_widget->selectedItems(); auto items = m_table_widget->selectedItems();
@ -167,10 +173,14 @@ void ResourcePackManager::Change()
if (items.empty()) if (items.empty())
return; return;
if (ResourcePack::IsInstalled(ResourcePack::GetPacks()[items[0]->row()])) if (ResourcePack::IsInstalled(ResourcePack::GetPacks()[GetResourcePackIndex(items[0])]))
{
Uninstall(); Uninstall();
}
else else
{
Install(); Install();
}
} }
void ResourcePackManager::Install() void ResourcePackManager::Install()
@ -180,7 +190,7 @@ void ResourcePackManager::Install()
if (items.empty()) if (items.empty())
return; return;
auto& item = ResourcePack::GetPacks()[m_table_widget->rowCount() - 1 - items[0]->row()]; auto& item = ResourcePack::GetPacks()[GetResourcePackIndex(items[0])];
bool success = item.Install(File::GetUserPath(D_USER_IDX)); bool success = item.Install(File::GetUserPath(D_USER_IDX));
@ -201,7 +211,7 @@ void ResourcePackManager::Uninstall()
if (items.empty()) if (items.empty())
return; return;
auto& item = ResourcePack::GetPacks()[m_table_widget->rowCount() - 1 - items[0]->row()]; auto& item = ResourcePack::GetPacks()[GetResourcePackIndex(items[0])];
bool success = item.Uninstall(File::GetUserPath(D_USER_IDX)); bool success = item.Uninstall(File::GetUserPath(D_USER_IDX));
@ -232,8 +242,7 @@ void ResourcePackManager::Remove()
return; return;
Uninstall(); Uninstall();
File::Delete( File::Delete(ResourcePack::GetPacks()[GetResourcePackIndex(items[0])].GetPath());
ResourcePack::GetPacks()[m_table_widget->rowCount() - 1 - items[0]->row()].GetPath());
RepopulateTable(); RepopulateTable();
} }
@ -244,7 +253,7 @@ void ResourcePackManager::PriorityDown()
if (items.empty()) if (items.empty())
return; return;
int row = m_table_widget->rowCount() - 1 - items[0]->row(); auto row = GetResourcePackIndex(items[0]);
if (items[0]->row() >= m_table_widget->rowCount()) if (items[0]->row() >= m_table_widget->rowCount())
return; return;
@ -269,7 +278,7 @@ void ResourcePackManager::PriorityUp()
if (items.empty()) if (items.empty())
return; return;
int row = m_table_widget->rowCount() - 1 - items[0]->row(); auto row = GetResourcePackIndex(items[0]);
if (items[0]->row() == 0) if (items[0]->row() == 0)
return; return;
@ -301,9 +310,10 @@ void ResourcePackManager::SelectionChanged()
if (has_selection) if (has_selection)
{ {
m_change_button->setText(ResourcePack::IsInstalled(ResourcePack::GetPacks()[items[0]->row()]) ? m_change_button->setText(
tr("Uninstall") : ResourcePack::IsInstalled(ResourcePack::GetPacks()[GetResourcePackIndex(items[0])]) ?
tr("Install")); tr("Uninstall") :
tr("Install"));
} }
for (auto* item : {m_change_button, m_remove_button}) for (auto* item : {m_change_button, m_remove_button})

View File

@ -31,6 +31,8 @@ private:
void SelectionChanged(); void SelectionChanged();
void ItemDoubleClicked(QTableWidgetItem* item); void ItemDoubleClicked(QTableWidgetItem* item);
int GetResourcePackIndex(QTableWidgetItem* item) const;
QPushButton* m_open_directory_button; QPushButton* m_open_directory_button;
QPushButton* m_change_button; QPushButton* m_change_button;
QPushButton* m_remove_button; QPushButton* m_remove_button;

View File

@ -60,7 +60,8 @@ bool Init()
continue; continue;
} }
order->Set(packs[i].GetManifest()->GetID(), static_cast<u64>(i)); if (i < packs.size())
order->Set(packs[i].GetManifest()->GetID(), static_cast<u64>(i));
} }
file.Save(packs_path); file.Save(packs_path);

View File

@ -265,8 +265,9 @@ bool ResourcePack::Uninstall(const std::string& path)
// Check if a higher priority pack already provides a given texture, don't delete it // Check if a higher priority pack already provides a given texture, don't delete it
for (const auto& pack : GetHigherPriorityPacks(*this)) for (const auto& pack : GetHigherPriorityPacks(*this))
{ {
if (std::find(pack->GetTextures().begin(), pack->GetTextures().end(), texture) != if (::ResourcePack::IsInstalled(*pack) &&
pack->GetTextures().end()) std::find(pack->GetTextures().begin(), pack->GetTextures().end(), texture) !=
pack->GetTextures().end())
{ {
provided_by_other_pack = true; provided_by_other_pack = true;
break; break;
@ -279,8 +280,9 @@ bool ResourcePack::Uninstall(const std::string& path)
// Check if a lower priority pack provides a given texture - if so, install it. // Check if a lower priority pack provides a given texture - if so, install it.
for (auto& pack : lower) for (auto& pack : lower)
{ {
if (std::find(pack->GetTextures().rbegin(), pack->GetTextures().rend(), texture) != if (::ResourcePack::IsInstalled(*pack) &&
pack->GetTextures().rend()) std::find(pack->GetTextures().rbegin(), pack->GetTextures().rend(), texture) !=
pack->GetTextures().rend())
{ {
pack->Install(path); pack->Install(path);