Skip to content
Permalink
Browse files

ResourcePacks: Fix various bugs

  • Loading branch information...
spycrab committed Feb 7, 2019
1 parent 2987e83 commit f86b34ceb9958ebf64a82edebec30ac2a2a5c935
@@ -160,17 +160,27 @@ void ResourcePackManager::RepopulateTable()
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()
{
auto items = m_table_widget->selectedItems();

if (items.empty())
return;

if (ResourcePack::IsInstalled(ResourcePack::GetPacks()[items[0]->row()]))
if (ResourcePack::IsInstalled(ResourcePack::GetPacks()[GetResourcePackIndex(items[0])]))
{
Uninstall();
}
else
{
Install();
}
}

void ResourcePackManager::Install()
@@ -180,7 +190,7 @@ void ResourcePackManager::Install()
if (items.empty())
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));

@@ -201,7 +211,7 @@ void ResourcePackManager::Uninstall()
if (items.empty())
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));

@@ -232,8 +242,7 @@ void ResourcePackManager::Remove()
return;

Uninstall();
File::Delete(
ResourcePack::GetPacks()[m_table_widget->rowCount() - 1 - items[0]->row()].GetPath());
File::Delete(ResourcePack::GetPacks()[GetResourcePackIndex(items[0])].GetPath());
RepopulateTable();
}

@@ -244,7 +253,7 @@ void ResourcePackManager::PriorityDown()
if (items.empty())
return;

int row = m_table_widget->rowCount() - 1 - items[0]->row();
auto row = GetResourcePackIndex(items[0]);

if (items[0]->row() >= m_table_widget->rowCount())
return;
@@ -269,7 +278,7 @@ void ResourcePackManager::PriorityUp()
if (items.empty())
return;

int row = m_table_widget->rowCount() - 1 - items[0]->row();
auto row = GetResourcePackIndex(items[0]);

if (items[0]->row() == 0)
return;
@@ -301,9 +310,10 @@ void ResourcePackManager::SelectionChanged()

if (has_selection)
{
m_change_button->setText(ResourcePack::IsInstalled(ResourcePack::GetPacks()[items[0]->row()]) ?
tr("Uninstall") :
tr("Install"));
m_change_button->setText(
ResourcePack::IsInstalled(ResourcePack::GetPacks()[GetResourcePackIndex(items[0])]) ?
tr("Uninstall") :
tr("Install"));
}

for (auto* item : {m_change_button, m_remove_button})
@@ -31,6 +31,8 @@ class ResourcePackManager : public QDialog
void SelectionChanged();
void ItemDoubleClicked(QTableWidgetItem* item);

int GetResourcePackIndex(QTableWidgetItem* item) const;

QPushButton* m_open_directory_button;
QPushButton* m_change_button;
QPushButton* m_remove_button;
@@ -60,7 +60,8 @@ bool Init()
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);
@@ -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
for (const auto& pack : GetHigherPriorityPacks(*this))
{
if (std::find(pack->GetTextures().begin(), pack->GetTextures().end(), texture) !=
pack->GetTextures().end())
if (::ResourcePack::IsInstalled(*pack) &&
std::find(pack->GetTextures().begin(), pack->GetTextures().end(), texture) !=
pack->GetTextures().end())
{
provided_by_other_pack = true;
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.
for (auto& pack : lower)
{
if (std::find(pack->GetTextures().rbegin(), pack->GetTextures().rend(), texture) !=
pack->GetTextures().rend())
if (::ResourcePack::IsInstalled(*pack) &&
std::find(pack->GetTextures().rbegin(), pack->GetTextures().rend(), texture) !=
pack->GetTextures().rend())
{
pack->Install(path);

0 comments on commit f86b34c

Please sign in to comment.
You can’t perform that action at this time.