Instance flags. Currently used for marking instances as broken. Can later be used for badges.

This commit is contained in:
Jan Dalheimer 2014-02-17 20:31:50 +01:00
parent 4e8be668cb
commit 0b56b5efaf
10 changed files with 83 additions and 10 deletions

View File

@ -354,6 +354,7 @@ void MainWindow::showInstanceContextMenu(const QPoint &pos)
QMenu myMenu; QMenu myMenu;
myMenu.addActions(actions); myMenu.addActions(actions);
myMenu.setEnabled(m_selectedInstance->canLaunch());
myMenu.exec(view->mapToGlobal(pos)); myMenu.exec(view->mapToGlobal(pos));
} }
@ -1366,7 +1367,7 @@ void MainWindow::instanceChanged(const QModelIndex &current, const QModelIndex &
(BaseInstance *)current.data(InstanceList::InstancePointerRole) (BaseInstance *)current.data(InstanceList::InstancePointerRole)
.value<void *>())) .value<void *>()))
{ {
ui->instanceToolBar->setEnabled(true); ui->instanceToolBar->setEnabled(m_selectedInstance->canLaunch());
renameButton->setText(m_selectedInstance->name()); renameButton->setText(m_selectedInstance->name());
ui->actionChangeInstLWJGLVersion->setEnabled( ui->actionChangeInstLWJGLVersion->setEnabled(
m_selectedInstance->menuActionEnabled("actionChangeInstLWJGLVersion")); m_selectedInstance->menuActionEnabled("actionChangeInstLWJGLVersion"));

View File

@ -37,6 +37,7 @@ 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");
@ -146,6 +147,28 @@ SettingsObject &BaseInstance::settings() const
return *d->m_settings; return *d->m_settings;
} }
BaseInstance::InstanceFlags BaseInstance::flags() const
{
I_D(const BaseInstance);
return InstanceFlags(d->m_flags);
}
void BaseInstance::setFlags(const BaseInstance::InstanceFlags flags)
{
I_D(BaseInstance);
if (flags != d->m_flags)
{
d->m_flags = flags;
emit flagsChanged();
emit propertiesChanged(this);
}
}
bool BaseInstance::canLaunch() const
{
return !(flags() & VersionBrokenFlag);
}
QString BaseInstance::baseJar() const QString BaseInstance::baseJar() const
{ {
I_D(BaseInstance); I_D(BaseInstance);

View File

@ -175,6 +175,17 @@ public:
/// FIXME: this really should be elsewhere... /// FIXME: this really should be elsewhere...
virtual QString instanceConfigFolder() const = 0; virtual QString instanceConfigFolder() const = 0;
enum InstanceFlag
{
NoFlags = 0x00,
VersionBrokenFlag = 0x01
};
Q_DECLARE_FLAGS(InstanceFlags, InstanceFlag)
InstanceFlags flags() const;
void setFlags(const BaseInstance::InstanceFlags flags);
bool canLaunch() const;
signals: signals:
/*! /*!
* \brief Signal emitted when properties relevant to the instance view change * \brief Signal emitted when properties relevant to the instance view change
@ -189,6 +200,8 @@ signals:
*/ */
void nuked(BaseInstance *inst); void nuked(BaseInstance *inst);
void flagsChanged();
protected slots: protected slots:
void iconUpdated(QString key); void iconUpdated(QString key);
@ -198,3 +211,5 @@ 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)

View File

@ -26,4 +26,5 @@ struct BaseInstancePrivate
QString m_rootDir; QString m_rootDir;
QString m_group; QString m_group;
SettingsObject *m_settings; SettingsObject *m_settings;
int m_flags;
}; };

View File

@ -7,6 +7,10 @@ LegacyFTBInstance::LegacyFTBInstance(const QString &rootDir, SettingsObject *set
QString LegacyFTBInstance::getStatusbarDescription() QString LegacyFTBInstance::getStatusbarDescription()
{ {
if (flags() & VersionBrokenFlag)
{
return "Legacy FTB: " + intendedVersionId() + " (broken)";
}
return "Legacy FTB: " + intendedVersionId(); return "Legacy FTB: " + intendedVersionId();
} }

View File

@ -268,13 +268,23 @@ QString LegacyInstance::defaultCustomBaseJar() const
bool LegacyInstance::menuActionEnabled(QString action_name) const bool LegacyInstance::menuActionEnabled(QString action_name) const
{ {
if (action_name == "actionChangeInstMCVersion") if (flags() & VersionBrokenFlag)
{
return false; return false;
}
if (action_name == "actionChangeInstMCVersion")
{
return false;
}
return true; return true;
} }
QString LegacyInstance::getStatusbarDescription() QString LegacyInstance::getStatusbarDescription()
{ {
if (flags() & VersionBrokenFlag)
{
return "Legacy : " + intendedVersionId() + " (broken)";
}
if (shouldUpdate()) if (shouldUpdate())
return "Legacy : " + currentVersionId() + " -> " + intendedVersionId(); return "Legacy : " + currentVersionId() + " -> " + intendedVersionId();
else else

View File

@ -23,6 +23,10 @@ NostalgiaInstance::NostalgiaInstance(const QString &rootDir, SettingsObject *set
QString NostalgiaInstance::getStatusbarDescription() QString NostalgiaInstance::getStatusbarDescription()
{ {
if (flags() & VersionBrokenFlag)
{
return "Nostalgia : " + intendedVersionId() + " (broken)";
}
return "Nostalgia : " + intendedVersionId(); return "Nostalgia : " + intendedVersionId();
} }

View File

@ -97,6 +97,10 @@ QString OneSixFTBInstance::id() const
QString OneSixFTBInstance::getStatusbarDescription() QString OneSixFTBInstance::getStatusbarDescription()
{ {
if (flags() & VersionBrokenFlag)
{
return "OneSix FTB: " + intendedVersionId() + " (broken)";
}
return "OneSix FTB: " + intendedVersionId(); return "OneSix FTB: " + intendedVersionId();
} }
bool OneSixFTBInstance::menuActionEnabled(QString action_name) const bool OneSixFTBInstance::menuActionEnabled(QString action_name) const

View File

@ -325,11 +325,12 @@ bool OneSixInstance::reloadVersion(QWidget *widgetParent)
} }
if (ret) if (ret)
{ {
setFlags(flags() & ~VersionBrokenFlag);
emit versionReloaded(); emit versionReloaded();
} }
else else
{ {
nuke(); setFlags(flags() | VersionBrokenFlag);
} }
return ret; return ret;
} }
@ -366,8 +367,14 @@ QString OneSixInstance::defaultCustomBaseJar() const
bool OneSixInstance::menuActionEnabled(QString action_name) const bool OneSixInstance::menuActionEnabled(QString action_name) const
{ {
if (action_name == "actionChangeInstLWJGLVersion") if (flags() & VersionBrokenFlag)
{
return false; return false;
}
if (action_name == "actionChangeInstLWJGLVersion")
{
return false;
}
return true; return true;
} }
@ -376,7 +383,11 @@ QString OneSixInstance::getStatusbarDescription()
QString descr = "OneSix : " + intendedVersionId(); QString descr = "OneSix : " + intendedVersionId();
if (versionIsCustom()) if (versionIsCustom())
{ {
descr + " (custom)"; descr += " (custom)";
}
if (flags() & VersionBrokenFlag)
{
descr += " (broken)";
} }
return descr; return descr;
} }

View File

@ -846,7 +846,7 @@ bool OneSixVersionBuilder::build(const bool onlyVanilla)
{ {
QMessageBox::critical( QMessageBox::critical(
m_widgetParent, QObject::tr("Error"), m_widgetParent, QObject::tr("Error"),
QObject::tr("The version descriptors of this instance are now compatible with the current version of MultiMC")); QObject::tr("The version descriptors of this instance are not compatible with the current version of MultiMC"));
return false; return false;
} }
} }
@ -880,7 +880,7 @@ bool OneSixVersionBuilder::build(const bool onlyVanilla)
{ {
QMessageBox::critical( QMessageBox::critical(
m_widgetParent, QObject::tr("Error"), m_widgetParent, QObject::tr("Error"),
QObject::tr("The version descriptors of this instance are now compatible with the current version of MultiMC")); QObject::tr("The version descriptors of this instance are not compatible with the current version of MultiMC"));
return false; return false;
} }
} }
@ -931,7 +931,7 @@ bool OneSixVersionBuilder::build(const bool onlyVanilla)
{ {
QMessageBox::critical( QMessageBox::critical(
m_widgetParent, QObject::tr("Error"), m_widgetParent, QObject::tr("Error"),
QObject::tr("The version descriptors of this instance are now compatible with the current version of MultiMC")); QObject::tr("The version descriptors of this instance are not compatible with the current version of MultiMC"));
return false; return false;
} }
} }
@ -1024,7 +1024,7 @@ bool OneSixVersionBuilder::read(const QJsonObject &obj)
{ {
QMessageBox::critical( QMessageBox::critical(
m_widgetParent, QObject::tr("Error"), m_widgetParent, QObject::tr("Error"),
QObject::tr("The version descriptors of this instance are now compatible with the current version of MultiMC")); QObject::tr("The version descriptors of this instance are not compatible with the current version of MultiMC"));
return false; return false;
} }