aboutsummaryrefslogtreecommitdiff
path: root/launcher/ui
diff options
context:
space:
mode:
authorflow <flowlnlnln@gmail.com>2022-09-07 08:30:36 -0300
committerGitHub <noreply@github.com>2022-09-07 08:30:36 -0300
commit333dbca01ed15103b5a36a58a9faad7464ed1582 (patch)
tree744421e688d8772a9be967de4c3c6fe1cd5230cf /launcher/ui
parent1b0ca476824ad3d704de70720184d2f1e194d2f5 (diff)
parentbedd3c50b6d3c399ccb243c9ea1a62d9b786389f (diff)
downloadPrismLauncher-333dbca01ed15103b5a36a58a9faad7464ed1582.tar.gz
PrismLauncher-333dbca01ed15103b5a36a58a9faad7464ed1582.tar.bz2
PrismLauncher-333dbca01ed15103b5a36a58a9faad7464ed1582.zip
Merge pull request #1105 from flowln/better_resource_packs
Add basic resource pack parsing and fix issues
Diffstat (limited to 'launcher/ui')
-rw-r--r--launcher/ui/pages/instance/ModFolderPage.cpp10
-rw-r--r--launcher/ui/pages/instance/ModFolderPage.h2
-rw-r--r--launcher/ui/pages/instance/ResourcePackPage.h11
-rw-r--r--launcher/ui/widgets/InfoFrame.cpp119
-rw-r--r--launcher/ui/widgets/InfoFrame.h2
-rw-r--r--launcher/ui/widgets/InfoFrame.ui34
6 files changed, 157 insertions, 21 deletions
diff --git a/launcher/ui/pages/instance/ModFolderPage.cpp b/launcher/ui/pages/instance/ModFolderPage.cpp
index 75b40e77..28a874c2 100644
--- a/launcher/ui/pages/instance/ModFolderPage.cpp
+++ b/launcher/ui/pages/instance/ModFolderPage.cpp
@@ -135,6 +135,16 @@ bool ModFolderPage::onSelectionChanged(const QModelIndex& current, const QModelI
return true;
}
+void ModFolderPage::removeItem()
+{
+
+ if (!m_controlsEnabled)
+ return;
+
+ auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection());
+ m_model->deleteMods(selection.indexes());
+}
+
void ModFolderPage::installMods()
{
if (!m_controlsEnabled)
diff --git a/launcher/ui/pages/instance/ModFolderPage.h b/launcher/ui/pages/instance/ModFolderPage.h
index 7fc9d9a1..c9a55bde 100644
--- a/launcher/ui/pages/instance/ModFolderPage.h
+++ b/launcher/ui/pages/instance/ModFolderPage.h
@@ -59,6 +59,8 @@ class ModFolderPage : public ExternalResourcesPage {
bool onSelectionChanged(const QModelIndex& current, const QModelIndex& previous) override;
private slots:
+ void removeItem() override;
+
void installMods();
void updateMods();
diff --git a/launcher/ui/pages/instance/ResourcePackPage.h b/launcher/ui/pages/instance/ResourcePackPage.h
index 2eefc3d3..9633e3b4 100644
--- a/launcher/ui/pages/instance/ResourcePackPage.h
+++ b/launcher/ui/pages/instance/ResourcePackPage.h
@@ -61,4 +61,15 @@ public:
return !m_instance->traits().contains("no-texturepacks") &&
!m_instance->traits().contains("texturepacks");
}
+
+ public slots:
+ bool onSelectionChanged(const QModelIndex& current, const QModelIndex& previous) override
+ {
+ auto sourceCurrent = m_filterModel->mapToSource(current);
+ int row = sourceCurrent.row();
+ auto& rp = static_cast<ResourcePack&>(m_model->at(row));
+ ui->frame->updateWithResourcePack(rp);
+
+ return true;
+ }
};
diff --git a/launcher/ui/widgets/InfoFrame.cpp b/launcher/ui/widgets/InfoFrame.cpp
index 821e61a7..9e0553f8 100644
--- a/launcher/ui/widgets/InfoFrame.cpp
+++ b/launcher/ui/widgets/InfoFrame.cpp
@@ -1,17 +1,37 @@
-/* Copyright 2013-2021 MultiMC Contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+* PolyMC - Minecraft Launcher
+* Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, version 3.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see <https://www.gnu.org/licenses/>.
+*
+* This file incorporates work covered by the following copyright and
+* permission notice:
+*
+* Copyright 2013-2021 MultiMC Contributors
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
#include <QMessageBox>
@@ -67,17 +87,76 @@ void InfoFrame::updateWithMod(Mod const& m)
{
setDescription(m.description());
}
+
+ setImage();
}
void InfoFrame::updateWithResource(const Resource& resource)
{
setName(resource.name());
+ setImage();
+}
+
+// https://www.sportskeeda.com/minecraft-wiki/color-codes
+static const QMap<QChar, QString> s_value_to_color = {
+ {'0', "#000000"}, {'1', "#0000AA"}, {'2', "#00AA00"}, {'3', "#00AAAA"}, {'4', "#AA0000"},
+ {'5', "#AA00AA"}, {'6', "#FFAA00"}, {'7', "#AAAAAA"}, {'8', "#555555"}, {'9', "#5555FF"},
+ {'a', "#55FF55"}, {'b', "#55FFFF"}, {'c', "#FF5555"}, {'d', "#FF55FF"}, {'e', "#FFFF55"},
+ {'f', "#FFFFFF"}
+};
+
+void InfoFrame::updateWithResourcePack(ResourcePack& resource_pack)
+{
+ setName(resource_pack.name());
+
+ // We have to manually set the colors for use.
+ //
+ // A color is set using §x, with x = a hex number from 0 to f.
+ //
+ // We traverse the description and, when one of those is found, we create
+ // a span element with that color set.
+ //
+ // TODO: Make the same logic for font formatting too.
+ // TODO: Wrap links inside <a> tags
+
+ auto description = resource_pack.description();
+
+ QString description_parsed("<html>");
+ bool in_div = false;
+
+ auto desc_it = description.constBegin();
+ while (desc_it != description.constEnd()) {
+ if (*desc_it == u'§') {
+ if (in_div)
+ description_parsed += "</span>";
+
+ auto const& num = *(++desc_it);
+ description_parsed += QString("<span style=\"color: %1;\">").arg(s_value_to_color.constFind(num).value());
+
+ in_div = true;
+
+ desc_it++;
+ }
+
+ description_parsed += *desc_it;
+ desc_it++;
+ }
+
+ if (in_div)
+ description_parsed += "</span>";
+ description_parsed += "</html>";
+
+ description_parsed.replace("\n", "<br>");
+
+ setDescription(description_parsed);
+ setImage(resource_pack.image({64, 64}));
}
void InfoFrame::clear()
{
setName();
setDescription();
+ setImage();
}
void InfoFrame::updateHiddenState()
@@ -146,12 +225,22 @@ void InfoFrame::setDescription(QString text)
}
else
{
- ui->descriptionLabel->setTextFormat(Qt::TextFormat::PlainText);
+ ui->descriptionLabel->setTextFormat(Qt::TextFormat::AutoText);
labeltext.append(finaltext);
}
ui->descriptionLabel->setText(labeltext);
}
+void InfoFrame::setImage(QPixmap img)
+{
+ if (img.isNull()) {
+ ui->iconLabel->setHidden(true);
+ } else {
+ ui->iconLabel->setHidden(false);
+ ui->iconLabel->setPixmap(img);
+ }
+}
+
void InfoFrame::descriptionEllipsisHandler(QString link)
{
if(!m_current_box)
diff --git a/launcher/ui/widgets/InfoFrame.h b/launcher/ui/widgets/InfoFrame.h
index d69dc232..70d15b1e 100644
--- a/launcher/ui/widgets/InfoFrame.h
+++ b/launcher/ui/widgets/InfoFrame.h
@@ -34,11 +34,13 @@ class InfoFrame : public QFrame {
void setName(QString text = {});
void setDescription(QString text = {});
+ void setImage(QPixmap img = {});
void clear();
void updateWithMod(Mod const& m);
void updateWithResource(Resource const& resource);
+ void updateWithResourcePack(ResourcePack& rp);
public slots:
void descriptionEllipsisHandler(QString link);
diff --git a/launcher/ui/widgets/InfoFrame.ui b/launcher/ui/widgets/InfoFrame.ui
index 0d3772d7..9e407ce9 100644
--- a/launcher/ui/widgets/InfoFrame.ui
+++ b/launcher/ui/widgets/InfoFrame.ui
@@ -22,10 +22,7 @@
<height>120</height>
</size>
</property>
- <layout class="QVBoxLayout" name="verticalLayout_2">
- <property name="spacing">
- <number>6</number>
- </property>
+ <layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>0</number>
</property>
@@ -38,7 +35,7 @@
<property name="bottomMargin">
<number>0</number>
</property>
- <item>
+ <item row="0" column="1">
<widget class="QLabel" name="nameLabel">
<property name="text">
<string notr="true"/>
@@ -60,7 +57,7 @@
</property>
</widget>
</item>
- <item>
+ <item row="1" column="1">
<widget class="QLabel" name="descriptionLabel">
<property name="toolTip">
<string notr="true"/>
@@ -85,6 +82,31 @@
</property>
</widget>
</item>
+ <item row="0" column="0" rowspan="2">
+ <widget class="QLabel" name="iconLabel">
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>64</width>
+ <height>64</height>
+ </size>
+ </property>
+ <property name="text">
+ <string notr="true"/>
+ </property>
+ <property name="scaledContents">
+ <bool>false</bool>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
<resources/>