Merge remote-tracking branch 'origin/feature_badges' into develop
This commit is contained in:
commit
26b485d82f
@ -18,9 +18,13 @@
|
|||||||
#include <QTextOption>
|
#include <QTextOption>
|
||||||
#include <QTextLayout>
|
#include <QTextLayout>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QtCore/qmath.h>
|
#include <QtMath>
|
||||||
|
|
||||||
#include "GroupView.h"
|
#include "GroupView.h"
|
||||||
|
#include "logic/BaseInstance.h"
|
||||||
|
#include "logic/lists/InstanceList.h"
|
||||||
|
|
||||||
|
QCache<QString, QPixmap> ListViewDelegate::m_pixmapCache;
|
||||||
|
|
||||||
// Origin: Qt
|
// Origin: Qt
|
||||||
static void viewItemTextLayout(QTextLayout &textLayout, int lineWidth, qreal &height,
|
static void viewItemTextLayout(QTextLayout &textLayout, int lineWidth, qreal &height,
|
||||||
@ -45,8 +49,6 @@ static void viewItemTextLayout(QTextLayout &textLayout, int lineWidth, qreal &he
|
|||||||
textLayout.endLayout();
|
textLayout.endLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
#define QFIXED_MAX (INT_MAX / 256)
|
|
||||||
|
|
||||||
ListViewDelegate::ListViewDelegate(QObject *parent) : QStyledItemDelegate(parent)
|
ListViewDelegate::ListViewDelegate(QObject *parent) : QStyledItemDelegate(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -108,6 +110,64 @@ void drawProgressOverlay(QPainter *painter, const QStyleOptionViewItemV4 &option
|
|||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void drawBadges(QPainter *painter, const QStyleOptionViewItemV4 &option, BaseInstance *instance)
|
||||||
|
{
|
||||||
|
QList<QString> pixmaps;
|
||||||
|
for (auto flag : instance->flags())
|
||||||
|
{
|
||||||
|
switch (flag)
|
||||||
|
{
|
||||||
|
case BaseInstance::VersionBrokenFlag:
|
||||||
|
pixmaps.append("broken");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// begin easter eggs
|
||||||
|
if (instance->name().contains("btw", Qt::CaseInsensitive) ||
|
||||||
|
instance->name().contains("better then wolves", Qt::CaseInsensitive) ||
|
||||||
|
instance->name().contains("better than wolves", Qt::CaseInsensitive))
|
||||||
|
{
|
||||||
|
pixmaps.append("herobrine");
|
||||||
|
}
|
||||||
|
if (instance->name().contains("direwolf", Qt::CaseInsensitive))
|
||||||
|
{
|
||||||
|
pixmaps.append("enderman");
|
||||||
|
}
|
||||||
|
if (instance->name().contains("kitten", Qt::CaseInsensitive))
|
||||||
|
{
|
||||||
|
pixmaps.append("kitten");
|
||||||
|
}
|
||||||
|
if (instance->name().contains("derp", Qt::CaseInsensitive))
|
||||||
|
{
|
||||||
|
pixmaps.append("derp");
|
||||||
|
}
|
||||||
|
// end easter eggs
|
||||||
|
|
||||||
|
static const int itemSide = 24;
|
||||||
|
static const int spacing = 1;
|
||||||
|
const int itemsPerRow = qMax(1, qFloor(double(option.rect.width() + spacing) / double(itemSide + spacing)));
|
||||||
|
const int rows = qCeil((double)pixmaps.size() / (double)itemsPerRow);
|
||||||
|
QListIterator<QString> it(pixmaps);
|
||||||
|
painter->translate(option.rect.topLeft());
|
||||||
|
for (int y = 0; y < rows; ++y)
|
||||||
|
{
|
||||||
|
for (int x = 0; x < itemsPerRow; ++x)
|
||||||
|
{
|
||||||
|
if (!it.hasNext())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const QPixmap pixmap = ListViewDelegate::requestPixmap(it.next()).scaled(
|
||||||
|
itemSide, itemSide, Qt::KeepAspectRatio, Qt::FastTransformation);
|
||||||
|
painter->drawPixmap(option.rect.width() - x * itemSide + qMax(x - 1, 0) * spacing - itemSide,
|
||||||
|
y * itemSide + qMax(y - 1, 0) * spacing, itemSide, itemSide,
|
||||||
|
pixmap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
painter->translate(-option.rect.topLeft());
|
||||||
|
}
|
||||||
|
|
||||||
static QSize viewItemTextSize(const QStyleOptionViewItemV4 *option)
|
static QSize viewItemTextSize(const QStyleOptionViewItemV4 *option)
|
||||||
{
|
{
|
||||||
QStyle *style = option->widget ? option->widget->style() : QApplication::style();
|
QStyle *style = option->widget ? option->widget->style() : QApplication::style();
|
||||||
@ -257,8 +317,14 @@ void ListViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
|
|||||||
line.draw(painter, position);
|
line.draw(painter, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
drawProgressOverlay(painter, opt,
|
auto instance = (BaseInstance*)index.data(InstanceList::InstancePointerRole)
|
||||||
index.data(GroupViewRoles::ProgressValueRole).toInt(),
|
.value<void *>();
|
||||||
|
if (instance)
|
||||||
|
{
|
||||||
|
drawBadges(painter, opt, instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
drawProgressOverlay(painter, opt, index.data(GroupViewRoles::ProgressValueRole).toInt(),
|
||||||
index.data(GroupViewRoles::ProgressMaximumRole).toInt());
|
index.data(GroupViewRoles::ProgressMaximumRole).toInt());
|
||||||
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
@ -284,3 +350,12 @@ QSize ListViewDelegate::sizeHint(const QStyleOptionViewItem &option,
|
|||||||
QSize sz(100, height);
|
QSize sz(100, height);
|
||||||
return sz;
|
return sz;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPixmap ListViewDelegate::requestPixmap(const QString &key)
|
||||||
|
{
|
||||||
|
if (!m_pixmapCache.contains(key))
|
||||||
|
{
|
||||||
|
m_pixmapCache.insert(key, new QPixmap(":/icons/badges/" + key + ".png"));
|
||||||
|
}
|
||||||
|
return *m_pixmapCache.object(key);
|
||||||
|
}
|
||||||
|
@ -16,14 +16,20 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QStyledItemDelegate>
|
#include <QStyledItemDelegate>
|
||||||
|
#include <QCache>
|
||||||
|
|
||||||
class ListViewDelegate : public QStyledItemDelegate
|
class ListViewDelegate : public QStyledItemDelegate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit ListViewDelegate(QObject *parent = 0);
|
explicit ListViewDelegate(QObject *parent = 0);
|
||||||
|
|
||||||
|
static QPixmap requestPixmap(const QString &key);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||||
const QModelIndex &index) const;
|
const QModelIndex &index) const;
|
||||||
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static QCache<QString, QPixmap> m_pixmapCache;
|
||||||
};
|
};
|
||||||
|
@ -37,7 +37,6 @@ BaseInstance::BaseInstance(BaseInstancePrivate *d_in, const QString &rootDir,
|
|||||||
I_D(BaseInstance);
|
I_D(BaseInstance);
|
||||||
d->m_settings = settings_obj;
|
d->m_settings = settings_obj;
|
||||||
d->m_rootDir = rootDir;
|
d->m_rootDir = rootDir;
|
||||||
d->m_flags = 0;
|
|
||||||
|
|
||||||
settings().registerSetting("name", "Unnamed Instance");
|
settings().registerSetting("name", "Unnamed Instance");
|
||||||
settings().registerSetting("iconKey", "default");
|
settings().registerSetting("iconKey", "default");
|
||||||
@ -147,13 +146,13 @@ SettingsObject &BaseInstance::settings() const
|
|||||||
return *d->m_settings;
|
return *d->m_settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseInstance::InstanceFlags BaseInstance::flags() const
|
QSet<BaseInstance::InstanceFlag> BaseInstance::flags() const
|
||||||
{
|
{
|
||||||
I_D(const BaseInstance);
|
I_D(const BaseInstance);
|
||||||
return InstanceFlags(d->m_flags);
|
return QSet<InstanceFlag>(d->m_flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseInstance::setFlags(const BaseInstance::InstanceFlags flags)
|
void BaseInstance::setFlags(const QSet<InstanceFlag> &flags)
|
||||||
{
|
{
|
||||||
I_D(BaseInstance);
|
I_D(BaseInstance);
|
||||||
if (flags != d->m_flags)
|
if (flags != d->m_flags)
|
||||||
@ -166,7 +165,7 @@ void BaseInstance::setFlags(const BaseInstance::InstanceFlags flags)
|
|||||||
|
|
||||||
bool BaseInstance::canLaunch() const
|
bool BaseInstance::canLaunch() const
|
||||||
{
|
{
|
||||||
return !(flags() & VersionBrokenFlag);
|
return !flags().contains(VersionBrokenFlag);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseInstance::reload()
|
bool BaseInstance::reload()
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QSet>
|
||||||
|
|
||||||
#include <settingsobject.h>
|
#include <settingsobject.h>
|
||||||
|
|
||||||
@ -184,9 +185,8 @@ public:
|
|||||||
NoFlags = 0x00,
|
NoFlags = 0x00,
|
||||||
VersionBrokenFlag = 0x01
|
VersionBrokenFlag = 0x01
|
||||||
};
|
};
|
||||||
Q_DECLARE_FLAGS(InstanceFlags, InstanceFlag)
|
QSet<InstanceFlag> flags() const;
|
||||||
InstanceFlags flags() const;
|
void setFlags(const QSet<InstanceFlag> &flags);
|
||||||
void setFlags(const BaseInstance::InstanceFlags flags);
|
|
||||||
|
|
||||||
bool canLaunch() const;
|
bool canLaunch() const;
|
||||||
|
|
||||||
@ -218,4 +218,4 @@ protected:
|
|||||||
// pointer for lazy people
|
// pointer for lazy people
|
||||||
typedef std::shared_ptr<BaseInstance> InstancePtr;
|
typedef std::shared_ptr<BaseInstance> InstancePtr;
|
||||||
|
|
||||||
Q_DECLARE_OPERATORS_FOR_FLAGS(BaseInstance::InstanceFlags)
|
Q_DECLARE_METATYPE(BaseInstance::InstanceFlag)
|
||||||
|
@ -14,10 +14,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QSet>
|
||||||
|
|
||||||
#include <settingsobject.h>
|
#include <settingsobject.h>
|
||||||
|
|
||||||
class BaseInstance;
|
#include "BaseInstance.h"
|
||||||
|
|
||||||
#define I_D(Class) Class##Private *const d = (Class##Private * const)inst_d.get()
|
#define I_D(Class) Class##Private *const d = (Class##Private * const)inst_d.get()
|
||||||
|
|
||||||
@ -26,5 +29,5 @@ struct BaseInstancePrivate
|
|||||||
QString m_rootDir;
|
QString m_rootDir;
|
||||||
QString m_group;
|
QString m_group;
|
||||||
SettingsObject *m_settings;
|
SettingsObject *m_settings;
|
||||||
int m_flags;
|
QSet<BaseInstance::InstanceFlag> m_flags;
|
||||||
};
|
};
|
||||||
|
@ -7,7 +7,7 @@ LegacyFTBInstance::LegacyFTBInstance(const QString &rootDir, SettingsObject *set
|
|||||||
|
|
||||||
QString LegacyFTBInstance::getStatusbarDescription()
|
QString LegacyFTBInstance::getStatusbarDescription()
|
||||||
{
|
{
|
||||||
if (flags() & VersionBrokenFlag)
|
if (flags().contains(VersionBrokenFlag))
|
||||||
{
|
{
|
||||||
return "Legacy FTB: " + intendedVersionId() + " (broken)";
|
return "Legacy FTB: " + intendedVersionId() + " (broken)";
|
||||||
}
|
}
|
||||||
|
@ -268,7 +268,7 @@ QString LegacyInstance::defaultCustomBaseJar() const
|
|||||||
|
|
||||||
bool LegacyInstance::menuActionEnabled(QString action_name) const
|
bool LegacyInstance::menuActionEnabled(QString action_name) const
|
||||||
{
|
{
|
||||||
if (flags() & VersionBrokenFlag)
|
if (flags().contains(VersionBrokenFlag))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -281,7 +281,7 @@ bool LegacyInstance::menuActionEnabled(QString action_name) const
|
|||||||
|
|
||||||
QString LegacyInstance::getStatusbarDescription()
|
QString LegacyInstance::getStatusbarDescription()
|
||||||
{
|
{
|
||||||
if (flags() & VersionBrokenFlag)
|
if (flags().contains(VersionBrokenFlag))
|
||||||
{
|
{
|
||||||
return "Legacy : " + intendedVersionId() + " (broken)";
|
return "Legacy : " + intendedVersionId() + " (broken)";
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ NostalgiaInstance::NostalgiaInstance(const QString &rootDir, SettingsObject *set
|
|||||||
|
|
||||||
QString NostalgiaInstance::getStatusbarDescription()
|
QString NostalgiaInstance::getStatusbarDescription()
|
||||||
{
|
{
|
||||||
if (flags() & VersionBrokenFlag)
|
if (flags().contains(VersionBrokenFlag))
|
||||||
{
|
{
|
||||||
return "Nostalgia : " + intendedVersionId() + " (broken)";
|
return "Nostalgia : " + intendedVersionId() + " (broken)";
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ bool OneSixFTBInstance::providesVersionFile() const
|
|||||||
|
|
||||||
QString OneSixFTBInstance::getStatusbarDescription()
|
QString OneSixFTBInstance::getStatusbarDescription()
|
||||||
{
|
{
|
||||||
if (flags() & VersionBrokenFlag)
|
if (flags().contains(VersionBrokenFlag))
|
||||||
{
|
{
|
||||||
return "OneSix FTB: " + intendedVersionId() + " (broken)";
|
return "OneSix FTB: " + intendedVersionId() + " (broken)";
|
||||||
}
|
}
|
||||||
|
@ -333,14 +333,14 @@ void OneSixInstance::reloadVersion()
|
|||||||
{
|
{
|
||||||
d->version->reload(false, externalPatches());
|
d->version->reload(false, externalPatches());
|
||||||
d->vanillaVersion->reload(true, externalPatches());
|
d->vanillaVersion->reload(true, externalPatches());
|
||||||
setFlags(flags() & ~VersionBrokenFlag);
|
d->m_flags.remove(VersionBrokenFlag);
|
||||||
emit versionReloaded();
|
emit versionReloaded();
|
||||||
}
|
}
|
||||||
catch(MMCError & error)
|
catch(MMCError & error)
|
||||||
{
|
{
|
||||||
d->version->clear();
|
d->version->clear();
|
||||||
d->vanillaVersion->clear();
|
d->vanillaVersion->clear();
|
||||||
setFlags(flags() | VersionBrokenFlag);
|
d->m_flags.insert(VersionBrokenFlag);
|
||||||
//TODO: rethrow to show some error message(s)?
|
//TODO: rethrow to show some error message(s)?
|
||||||
emit versionReloaded();
|
emit versionReloaded();
|
||||||
throw;
|
throw;
|
||||||
@ -379,7 +379,7 @@ QString OneSixInstance::defaultCustomBaseJar() const
|
|||||||
|
|
||||||
bool OneSixInstance::menuActionEnabled(QString action_name) const
|
bool OneSixInstance::menuActionEnabled(QString action_name) const
|
||||||
{
|
{
|
||||||
if (flags() & VersionBrokenFlag)
|
if (flags().contains(VersionBrokenFlag))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -397,7 +397,7 @@ QString OneSixInstance::getStatusbarDescription()
|
|||||||
{
|
{
|
||||||
descr += " (custom)";
|
descr += " (custom)";
|
||||||
}
|
}
|
||||||
if (flags() & VersionBrokenFlag)
|
if (flags().contains(VersionBrokenFlag))
|
||||||
{
|
{
|
||||||
descr += " (broken)";
|
descr += " (broken)";
|
||||||
}
|
}
|
||||||
|
BIN
resources/instances/broken.png
Normal file
BIN
resources/instances/broken.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
@ -32,4 +32,15 @@
|
|||||||
<file alias="squarecreeper">squarecreeper128.png</file>
|
<file alias="squarecreeper">squarecreeper128.png</file>
|
||||||
<file alias="steve">steve128.png</file>
|
<file alias="steve">steve128.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
|
<qresource prefix="/icons/badges">
|
||||||
|
<!-- Source: see above -->
|
||||||
|
<file>enderman.png</file>
|
||||||
|
<file>herobrine.png</file>
|
||||||
|
<file>derp.png</file>
|
||||||
|
|
||||||
|
<!-- Source: http://www.iconarchive.com/show/cat-icons-by-fasticon/Cat-Brown-icon.html -->
|
||||||
|
<file>kitten.png</file>
|
||||||
|
<!-- Source: http://www.iconarchive.com/show/crystal-clear-icons-by-everaldo/Filesystem-file-broken-icon.html -->
|
||||||
|
<file>broken.png</file>
|
||||||
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
BIN
resources/instances/kitten.png
Normal file
BIN
resources/instances/kitten.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
Loading…
Reference in New Issue
Block a user