aboutsummaryrefslogtreecommitdiff
path: root/launcher/ui
diff options
context:
space:
mode:
authorSefa Eyeoglu <contact@scrumplex.net>2022-09-04 14:45:09 +0200
committerSefa Eyeoglu <contact@scrumplex.net>2022-09-20 10:26:15 +0200
commit07dcefabcbe3436ae6de09bc8c99120ab3f0a745 (patch)
treee46b72d7236054a3689958b882806f1a899dcafa /launcher/ui
parent40c68595d7d5eccd1f264b2dc1e768b3faad6f16 (diff)
downloadPrismLauncher-07dcefabcbe3436ae6de09bc8c99120ab3f0a745.tar.gz
PrismLauncher-07dcefabcbe3436ae6de09bc8c99120ab3f0a745.tar.bz2
PrismLauncher-07dcefabcbe3436ae6de09bc8c99120ab3f0a745.zip
feat: add texture pack parsing
Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
Diffstat (limited to 'launcher/ui')
-rw-r--r--launcher/ui/pages/instance/TexturePackPage.h12
-rw-r--r--launcher/ui/widgets/InfoFrame.cpp47
-rw-r--r--launcher/ui/widgets/InfoFrame.h4
3 files changed, 43 insertions, 20 deletions
diff --git a/launcher/ui/pages/instance/TexturePackPage.h b/launcher/ui/pages/instance/TexturePackPage.h
index fa219eda..69b836ca 100644
--- a/launcher/ui/pages/instance/TexturePackPage.h
+++ b/launcher/ui/pages/instance/TexturePackPage.h
@@ -39,6 +39,7 @@
#include "ui_ExternalResourcesPage.h"
#include "minecraft/mod/TexturePackFolderModel.h"
+#include "minecraft/mod/TexturePack.h"
class TexturePackPage : public ExternalResourcesPage
{
@@ -60,4 +61,15 @@ public:
{
return 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<TexturePack&>(m_model->at(row));
+ ui->frame->updateWithTexturePack(rp);
+
+ return true;
+ }
};
diff --git a/launcher/ui/widgets/InfoFrame.cpp b/launcher/ui/widgets/InfoFrame.cpp
index 9e0553f8..bb895c9b 100644
--- a/launcher/ui/widgets/InfoFrame.cpp
+++ b/launcher/ui/widgets/InfoFrame.cpp
@@ -105,10 +105,7 @@ static const QMap<QChar, QString> s_value_to_color = {
{'f', "#FFFFFF"}
};
-void InfoFrame::updateWithResourcePack(ResourcePack& resource_pack)
-{
- setName(resource_pack.name());
-
+QString InfoFrame::renderColorCodes(QString input) {
// We have to manually set the colors for use.
//
// A color is set using §x, with x = a hex number from 0 to f.
@@ -119,39 +116,49 @@ void InfoFrame::updateWithResourcePack(ResourcePack& resource_pack)
// TODO: Make the same logic for font formatting too.
// TODO: Wrap links inside <a> tags
- auto description = resource_pack.description();
-
- QString description_parsed("<html>");
+ QString html("<html>");
bool in_div = false;
- auto desc_it = description.constBegin();
- while (desc_it != description.constEnd()) {
- if (*desc_it == u'§') {
+ auto it = input.constBegin();
+ while (it != input.constEnd()) {
+ if (*it == u'§') {
if (in_div)
- description_parsed += "</span>";
+ html += "</span>";
- auto const& num = *(++desc_it);
- description_parsed += QString("<span style=\"color: %1;\">").arg(s_value_to_color.constFind(num).value());
+ auto const& num = *(++it);
+ html += QString("<span style=\"color: %1;\">").arg(s_value_to_color.constFind(num).value());
in_div = true;
- desc_it++;
+ it++;
}
- description_parsed += *desc_it;
- desc_it++;
+ html += *it;
+ it++;
}
if (in_div)
- description_parsed += "</span>";
- description_parsed += "</html>";
+ html += "</span>";
+ html += "</html>";
- description_parsed.replace("\n", "<br>");
+ html.replace("\n", "<br>");
+ return html;
+}
- setDescription(description_parsed);
+void InfoFrame::updateWithResourcePack(ResourcePack& resource_pack)
+{
+ setName(resource_pack.name());
+ setDescription(renderColorCodes(resource_pack.description()));
setImage(resource_pack.image({64, 64}));
}
+void InfoFrame::updateWithTexturePack(TexturePack& texture_pack)
+{
+ setName(texture_pack.name());
+ setDescription(texture_pack.description());
+ setImage(texture_pack.image({64, 64}));
+}
+
void InfoFrame::clear()
{
setName();
diff --git a/launcher/ui/widgets/InfoFrame.h b/launcher/ui/widgets/InfoFrame.h
index 70d15b1e..84523e28 100644
--- a/launcher/ui/widgets/InfoFrame.h
+++ b/launcher/ui/widgets/InfoFrame.h
@@ -19,6 +19,7 @@
#include "minecraft/mod/Mod.h"
#include "minecraft/mod/ResourcePack.h"
+#include "minecraft/mod/TexturePack.h"
namespace Ui
{
@@ -41,6 +42,9 @@ class InfoFrame : public QFrame {
void updateWithMod(Mod const& m);
void updateWithResource(Resource const& resource);
void updateWithResourcePack(ResourcePack& rp);
+ void updateWithTexturePack(TexturePack& tp);
+
+ static QString renderColorCodes(QString input);
public slots:
void descriptionEllipsisHandler(QString link);