From 87dd9515052661e622587cafcf972ea1beee8195 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Fri, 4 Nov 2016 01:17:28 +0100 Subject: [PATCH] NOISSUE add a badge for crashed instances Not persistent across MultiMC runs. --- api/logic/BaseInstance.cpp | 37 +----------- api/logic/BaseInstance.h | 57 +++++++++++++----- api/logic/NullInstance.h | 2 +- api/logic/launch/LaunchTask.cpp | 2 + api/logic/minecraft/MinecraftInstance.cpp | 8 +-- api/logic/minecraft/onesix/OneSixInstance.cpp | 10 +-- .../minecraft/onesix/update/LibrariesTask.cpp | 2 +- application/groupview/InstanceDelegate.cpp | 21 ++++--- application/resources/instances/instances.qrc | 1 + .../resources/instances/status-bad.png | Bin 0 -> 1102 bytes 10 files changed, 65 insertions(+), 75 deletions(-) create mode 100644 application/resources/instances/status-bad.png diff --git a/api/logic/BaseInstance.cpp b/api/logic/BaseInstance.cpp index b499c106..b7a7f9fd 100644 --- a/api/logic/BaseInstance.cpp +++ b/api/logic/BaseInstance.cpp @@ -172,44 +172,9 @@ SettingsObjectPtr BaseInstance::settings() const return m_settings; } -BaseInstance::InstanceFlags BaseInstance::flags() const -{ - return m_flags; -} - -void BaseInstance::setFlags(const InstanceFlags &flags) -{ - if (flags != m_flags) - { - m_flags = flags; - emit flagsChanged(); - emit propertiesChanged(this); - } -} - -void BaseInstance::setFlag(const BaseInstance::InstanceFlag flag) -{ - // nothing to set? - if(flag & m_flags) - return; - m_flags |= flag; - emit flagsChanged(); - emit propertiesChanged(this); -} - -void BaseInstance::unsetFlag(const BaseInstance::InstanceFlag flag) -{ - // nothing to unset? - if(!(flag & m_flags)) - return; - m_flags &= ~flag; - emit flagsChanged(); - emit propertiesChanged(this); -} - bool BaseInstance::canLaunch() const { - return (!(flags() & VersionBrokenFlag)) && (!isRunning()); + return (!hasVersionBroken() && !isRunning()); } bool BaseInstance::reload() diff --git a/api/logic/BaseInstance.h b/api/logic/BaseInstance.h index 669bad79..147dd703 100644 --- a/api/logic/BaseInstance.h +++ b/api/logic/BaseInstance.h @@ -218,16 +218,44 @@ public: virtual QString typeName() const = 0; - enum InstanceFlag + bool hasVersionBroken() const { - VersionBrokenFlag = 0x01, - UpdateAvailable = 0x02 - }; - Q_DECLARE_FLAGS(InstanceFlags, InstanceFlag) - InstanceFlags flags() const; - void setFlags(const InstanceFlags &flags); - void setFlag(const InstanceFlag flag); - void unsetFlag(const InstanceFlag flag); + return m_hasBrokenVersion; + } + void setVersionBroken(bool value) + { + if(m_hasBrokenVersion != value) + { + m_hasBrokenVersion = value; + emit propertiesChanged(this); + } + } + + bool hasUpdateAvailable() const + { + return m_hasUpdate; + } + void setUpdateAvailable(bool value) + { + if(m_hasUpdate != value) + { + m_hasUpdate = value; + emit propertiesChanged(this); + } + } + + bool hasCrashed() const + { + return m_crashed; + } + void setCrashed(bool value) + { + if(m_crashed != value) + { + m_crashed = value; + emit propertiesChanged(this); + } + } bool canLaunch() const; virtual bool canExport() const = 0; @@ -254,8 +282,6 @@ signals: */ void groupChanged(); - void flagsChanged(); - void launchTaskChanged(std::shared_ptr); void runningStatusChanged(bool running); @@ -269,7 +295,7 @@ protected: /* data */ QString m_rootDir; QString m_group; SettingsObjectPtr m_settings; - InstanceFlags m_flags; + // InstanceFlags m_flags; bool m_isRunning = false; std::shared_ptr m_launchProcess; QDateTime m_timeStarted; @@ -277,8 +303,11 @@ protected: /* data */ private: /* data */ Status m_status = Status::Present; + bool m_crashed = false; + bool m_hasUpdate = false; + bool m_hasBrokenVersion = false; }; Q_DECLARE_METATYPE(std::shared_ptr) -Q_DECLARE_METATYPE(BaseInstance::InstanceFlag) -Q_DECLARE_OPERATORS_FOR_FLAGS(BaseInstance::InstanceFlags) +//Q_DECLARE_METATYPE(BaseInstance::InstanceFlag) +//Q_DECLARE_OPERATORS_FOR_FLAGS(BaseInstance::InstanceFlags) diff --git a/api/logic/NullInstance.h b/api/logic/NullInstance.h index 4fb31854..5323d135 100644 --- a/api/logic/NullInstance.h +++ b/api/logic/NullInstance.h @@ -7,7 +7,7 @@ public: NullInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString& rootDir) :BaseInstance(globalSettings, settings, rootDir) { - setFlag(BaseInstance::VersionBrokenFlag); + setVersionBroken(true); } virtual ~NullInstance() {}; virtual bool setIntendedVersionId(QString) override diff --git a/api/logic/launch/LaunchTask.cpp b/api/logic/launch/LaunchTask.cpp index 9c09caf4..a006e519 100644 --- a/api/logic/launch/LaunchTask.cpp +++ b/api/logic/launch/LaunchTask.cpp @@ -56,6 +56,7 @@ void LaunchTask::prependStep(std::shared_ptr step) void LaunchTask::executeTask() { + m_instance->setCrashed(false); if(!m_steps.size()) { state = LaunchTask::Finished; @@ -217,6 +218,7 @@ void LaunchTask::emitFailed(QString reason) { m_instance->cleanupAfterRun(); m_instance->setRunning(false); + m_instance->setCrashed(true); Task::emitFailed(reason); } diff --git a/api/logic/minecraft/MinecraftInstance.cpp b/api/logic/minecraft/MinecraftInstance.cpp index d3af5011..f0d47733 100644 --- a/api/logic/minecraft/MinecraftInstance.cpp +++ b/api/logic/minecraft/MinecraftInstance.cpp @@ -369,7 +369,7 @@ QString MinecraftInstance::prettifyTimeDuration(int64_t duration) QString MinecraftInstance::getStatusbarDescription() { QStringList traits; - if (flags() & VersionBrokenFlag) + if (hasVersionBroken()) { traits.append(tr("broken")); } @@ -380,12 +380,10 @@ QString MinecraftInstance::getStatusbarDescription() { description.append(tr(", played for %1").arg(prettifyTimeDuration(totalTimePlayed()))); } - /* - if(traits.size()) + if(hasCrashed()) { - description.append(QString(" (%1)").arg(traits.join(", "))); + description.append(tr(", has crashed.")); } - */ return description; } diff --git a/api/logic/minecraft/onesix/OneSixInstance.cpp b/api/logic/minecraft/onesix/OneSixInstance.cpp index d89a7612..859e2e69 100644 --- a/api/logic/minecraft/onesix/OneSixInstance.cpp +++ b/api/logic/minecraft/onesix/OneSixInstance.cpp @@ -526,15 +526,7 @@ QString OneSixInstance::currentVersionId() const void OneSixInstance::reloadProfile() { m_profile->reload(); - auto severity = m_profile->getProblemSeverity(); - if(severity == ProblemSeverity::PROBLEM_ERROR) - { - setFlag(VersionBrokenFlag); - } - else - { - unsetFlag(VersionBrokenFlag); - } + setVersionBroken(m_profile->getProblemSeverity() == ProblemSeverity::PROBLEM_ERROR); emit versionReloaded(); } diff --git a/api/logic/minecraft/onesix/update/LibrariesTask.cpp b/api/logic/minecraft/onesix/update/LibrariesTask.cpp index 1efbc64c..f60c2b5e 100644 --- a/api/logic/minecraft/onesix/update/LibrariesTask.cpp +++ b/api/logic/minecraft/onesix/update/LibrariesTask.cpp @@ -13,7 +13,7 @@ void LibrariesTask::executeTask() qDebug() << m_inst->name() << ": downloading libraries"; OneSixInstance *inst = (OneSixInstance *)m_inst; inst->reloadProfile(); - if(inst->flags() & BaseInstance::VersionBrokenFlag) + if(inst->hasVersionBroken()) { emitFailed(tr("Failed to load the version description files - check the instance for errors.")); return; diff --git a/application/groupview/InstanceDelegate.cpp b/application/groupview/InstanceDelegate.cpp index 359dd3cf..b88f9a8a 100644 --- a/application/groupview/InstanceDelegate.cpp +++ b/application/groupview/InstanceDelegate.cpp @@ -113,19 +113,22 @@ void drawProgressOverlay(QPainter *painter, const QStyleOptionViewItemV4 &option void drawBadges(QPainter *painter, const QStyleOptionViewItemV4 &option, BaseInstance *instance) { QList pixmaps; - const BaseInstance::InstanceFlags flags = instance->flags(); - if (flags & BaseInstance::VersionBrokenFlag) - { - pixmaps.append("broken"); - } - if (flags & BaseInstance::UpdateAvailable) - { - pixmaps.append("updateavailable"); - } if (instance->isRunning()) { pixmaps.append("status-running"); } + else if (instance->hasCrashed()) + { + pixmaps.append("status-bad"); + } + if (instance->hasVersionBroken()) + { + pixmaps.append("broken"); + } + if (instance->hasUpdateAvailable()) + { + pixmaps.append("updateavailable"); + } // begin easter eggs if (instance->name().contains("btw", Qt::CaseInsensitive) || diff --git a/application/resources/instances/instances.qrc b/application/resources/instances/instances.qrc index b1f1bb4d..1f90762a 100644 --- a/application/resources/instances/instances.qrc +++ b/application/resources/instances/instances.qrc @@ -38,6 +38,7 @@ herobrine.png derp.png status-running.png + status-bad.png updateavailable.png diff --git a/application/resources/instances/status-bad.png b/application/resources/instances/status-bad.png new file mode 100644 index 0000000000000000000000000000000000000000..d1547a4744ae6b20201a74267c5ac1b71b364704 GIT binary patch literal 1102 zcmV-U1hM;xP)(^b8FWQhbW?9;ba!ELWdL_~cP?peYja~^ zaAhuUa%Y?FJQ@H11ItN7K~zYIwU%FKTXhu2KfjxM=XSNuR*W*H;vXDiNJ`V{47=J2 zKJD3;JV+hPE(%-07S{Gbq09uVEaH?lpcZ8c+d~oQQ&AkW+p=b^-4Lfv)G?>dtgF-& zm*34jKHQu1HcjSUJaD<;p5OU?&)?sP5)m57$4W&#=+Mw!g1Clu4Y*Kn;k1UrGR(dy za-|W5sz;Dh%4&fj7X~$0W#Bg8cAyLtgQo;&&>9Xb!W&~E`acP#lxn>J;~HYkz&(Hs zs2W2LSOm@k=X|31GISplnQKV!nNlxDAZvlO3215*ca8iCdpv$UYB}0(l8`MxKSF0iBPt z(ux*vxme`e_3PQ5NMM>K+Y<@SD8&ZHp>O|wOw+`5T@GclG#@!aLhGvi2H=z*?e~!` zcy%Lec{G$`1+;0+Og_&UrB;z7cI>Evk7P1jOQ-2sUar=zV*i8R1WS>p;jPWkw7I5B zjDTdihQu(8D)>Sj@QVBa{04U#Zcw=YOCnFfGr*RuHHvVzgmdnB-m03+wLZl7;0(uRIJQN&Q2ShJkWc1P{ zoX$=TWwX_8X%BVR)@|G9+q;+NCntF%l!4>GWzYunAtLO7*IxlS78;fxK@JB4*KgZ$ zA*8zi(r??+13u}4YY)0B+pTK*p~##Iz2AV&0YBFP zZ6v<{?*r$3@ZMZ#tF2j?FDlgvj4OzB0B!hdvtEk+1m=LR0fBj-J9o2{S&<&4tP%|2 z-|3bK+zV_9^uGgF@P|=A3mh