From 07dcefabcbe3436ae6de09bc8c99120ab3f0a745 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Sun, 4 Sep 2022 14:45:09 +0200 Subject: feat: add texture pack parsing Signed-off-by: Sefa Eyeoglu --- launcher/ui/widgets/InfoFrame.cpp | 47 ++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 20 deletions(-) (limited to 'launcher/ui/widgets/InfoFrame.cpp') 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 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 tags - auto description = resource_pack.description(); - - QString description_parsed(""); + QString 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 += ""; + html += ""; - auto const& num = *(++desc_it); - description_parsed += QString("").arg(s_value_to_color.constFind(num).value()); + auto const& num = *(++it); + html += QString("").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 += ""; - description_parsed += ""; + html += ""; + html += ""; - description_parsed.replace("\n", "
"); + html.replace("\n", "
"); + 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(); -- cgit