diff --git a/mapeditor/CMakeLists.txt b/mapeditor/CMakeLists.txt index 54e395b21..f397a8789 100644 --- a/mapeditor/CMakeLists.txt +++ b/mapeditor/CMakeLists.txt @@ -84,6 +84,7 @@ set(editor_HEADERS inspector/herospellwidget.h inspector/PickObjectDelegate.h inspector/portraitwidget.h + inspector/baseinspectoritemdelegate.h resourceExtractor/ResourceConverter.h mapeditorroles.h ) diff --git a/mapeditor/inspector/PickObjectDelegate.h b/mapeditor/inspector/PickObjectDelegate.h index f1a0089ac..446797366 100644 --- a/mapeditor/inspector/PickObjectDelegate.h +++ b/mapeditor/inspector/PickObjectDelegate.h @@ -11,6 +11,7 @@ #pragma once #include +#include "baseinspectoritemdelegate.h" class MapController; @@ -20,7 +21,7 @@ class CGObjectInstance; VCMI_LIB_NAMESPACE_END -class PickObjectDelegate : public QItemDelegate +class PickObjectDelegate : public BaseInspectorItemDelegate { Q_OBJECT public: diff --git a/mapeditor/inspector/armywidget.cpp b/mapeditor/inspector/armywidget.cpp index efaf0adbc..8a0932870 100644 --- a/mapeditor/inspector/armywidget.cpp +++ b/mapeditor/inspector/armywidget.cpp @@ -115,7 +115,7 @@ ArmyWidget::~ArmyWidget() -ArmyDelegate::ArmyDelegate(CArmedInstance & t): army(t), QStyledItemDelegate() +ArmyDelegate::ArmyDelegate(CArmedInstance & t): army(t), BaseInspectorItemDelegate() { } @@ -141,9 +141,27 @@ void ArmyDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, cons if(auto * ed = qobject_cast(editor)) { ed->commitChanges(); + updateModelData(model, index); } else { QStyledItemDelegate::setModelData(editor, model, index); } } + +void ArmyDelegate::updateModelData(QAbstractItemModel * model, const QModelIndex & index) const +{ + QStringList textList; + for(auto i = army.stacks.begin(); i != army.stacks.end(); i++) + { + auto stack = i->second; + if(stack->count != 0 && stack->getCreature() != nullptr) + textList += QString::number(stack->count) + " " + QString::fromStdString(stack->getCreature()->getNamePluralTranslated()); + } + + QString text = textList.join("\n"); + QMap data; + data[Qt::DisplayRole] = QVariant(text); + data[Qt::ToolTipRole] = QVariant(text); + model->setItemData(index, data); +} diff --git a/mapeditor/inspector/armywidget.h b/mapeditor/inspector/armywidget.h index c4eaabe32..f127f25c8 100644 --- a/mapeditor/inspector/armywidget.h +++ b/mapeditor/inspector/armywidget.h @@ -11,6 +11,7 @@ #include "../StdInc.h" #include +#include "baseinspectoritemdelegate.h" #include "../lib/mapObjects/CArmedInstance.h" const int TOTAL_SLOTS = 7; @@ -39,17 +40,18 @@ private: std::array uiSlots; }; -class ArmyDelegate : public QStyledItemDelegate +class ArmyDelegate : public BaseInspectorItemDelegate { Q_OBJECT public: - using QStyledItemDelegate::QStyledItemDelegate; + using BaseInspectorItemDelegate::BaseInspectorItemDelegate; ArmyDelegate(CArmedInstance &); QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; void setEditorData(QWidget *editor, const QModelIndex &index) const override; void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override; + void updateModelData(QAbstractItemModel * model, const QModelIndex & index) const override; private: CArmedInstance & army; diff --git a/mapeditor/inspector/baseinspectoritemdelegate.h b/mapeditor/inspector/baseinspectoritemdelegate.h new file mode 100644 index 000000000..1d4c46ad6 --- /dev/null +++ b/mapeditor/inspector/baseinspectoritemdelegate.h @@ -0,0 +1,22 @@ +/* + * baseinspectoritemdelegate.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ +#pragma once + +#include +#include + +class BaseInspectorItemDelegate : public QStyledItemDelegate +{ + Q_OBJECT +public: + using QStyledItemDelegate::QStyledItemDelegate; + + virtual void updateModelData(QAbstractItemModel * model, const QModelIndex & index) const {}; +}; diff --git a/mapeditor/inspector/heroartifactswidget.cpp b/mapeditor/inspector/heroartifactswidget.cpp index 2c1c9d687..0d0a638e4 100644 --- a/mapeditor/inspector/heroartifactswidget.cpp +++ b/mapeditor/inspector/heroartifactswidget.cpp @@ -110,7 +110,7 @@ void HeroArtifactsWidget::commitChanges() } } -HeroArtifactsDelegate::HeroArtifactsDelegate(CGHeroInstance & h) : QStyledItemDelegate(), hero(h) +HeroArtifactsDelegate::HeroArtifactsDelegate(CGHeroInstance & h) : BaseInspectorItemDelegate(), hero(h) { } @@ -136,9 +136,30 @@ void HeroArtifactsDelegate::setModelData(QWidget * editor, QAbstractItemModel * if (auto * ed = qobject_cast(editor)) { ed->commitChanges(); + updateModelData(model, index); } else { QStyledItemDelegate::setModelData(editor, model, index); } } + +void HeroArtifactsDelegate::updateModelData(QAbstractItemModel * model, const QModelIndex & index) const +{ + QStringList textList; + for(const auto & [artPosition, artSlotInfo] : hero.artifactsWorn) + { + auto slotText = NArtifactPosition::namesHero[artPosition.num]; + textList += QString::fromStdString(slotText) + ": " + QString::fromStdString(artSlotInfo.artifact->getType()->getNameTranslated()); + } + textList += QString::fromStdString(NArtifactPosition::backpack) + ":"; + for(const auto & art : hero.artifactsInBackpack) + { + textList += QString::fromStdString(art.artifact->getType()->getNameTranslated()); + } + QString text = textList.join("\n"); + QMap data; + data[Qt::DisplayRole] = QVariant(text); + data[Qt::ToolTipRole] = QVariant(text); + model->setItemData(index, data); +} diff --git a/mapeditor/inspector/heroartifactswidget.h b/mapeditor/inspector/heroartifactswidget.h index 807a37ce5..73429db6a 100644 --- a/mapeditor/inspector/heroartifactswidget.h +++ b/mapeditor/inspector/heroartifactswidget.h @@ -10,6 +10,7 @@ #pragma once #include +#include "baseinspectoritemdelegate.h" #include "../../lib/mapObjects/CGHeroInstance.h" namespace Ui { @@ -48,17 +49,18 @@ private: }; -class HeroArtifactsDelegate : public QStyledItemDelegate +class HeroArtifactsDelegate : public BaseInspectorItemDelegate { Q_OBJECT public: - using QStyledItemDelegate::QStyledItemDelegate; + using BaseInspectorItemDelegate::BaseInspectorItemDelegate; HeroArtifactsDelegate(CGHeroInstance &); QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const override; void setEditorData(QWidget * editor, const QModelIndex & index) const override; void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const override; + void updateModelData(QAbstractItemModel * model, const QModelIndex & index) const override; private: CGHeroInstance & hero; diff --git a/mapeditor/inspector/heroskillswidget.cpp b/mapeditor/inspector/heroskillswidget.cpp index 79b7fd2e5..e0f685516 100644 --- a/mapeditor/inspector/heroskillswidget.cpp +++ b/mapeditor/inspector/heroskillswidget.cpp @@ -11,6 +11,7 @@ #include "heroskillswidget.h" #include "ui_heroskillswidget.h" #include "../../lib/constants/StringConstants.h" +#include "../../lib/entities/hero/CHeroHandler.h" #include "../../lib/CSkillHandler.h" #include "inspector.h" @@ -115,7 +116,7 @@ void HeroSkillsWidget::commitChanges() } } -HeroSkillsDelegate::HeroSkillsDelegate(CGHeroInstance & h): hero(h), QStyledItemDelegate() +HeroSkillsDelegate::HeroSkillsDelegate(CGHeroInstance & h): hero(h), BaseInspectorItemDelegate() { } @@ -141,9 +142,38 @@ void HeroSkillsDelegate::setModelData(QWidget *editor, QAbstractItemModel *model if(auto * ed = qobject_cast(editor)) { ed->commitChanges(); + updateModelData(model, index); } else { QStyledItemDelegate::setModelData(editor, model, index); } } + +void HeroSkillsDelegate::updateModelData(QAbstractItemModel * model, const QModelIndex & index) const +{ + QStringList textList; + textList += QString::fromStdString(VLC->generaltexth->primarySkillNames[PrimarySkill::ATTACK]) + ": " + QString::number(hero.getBasePrimarySkillValue(PrimarySkill::ATTACK)); + textList += QString::fromStdString(VLC->generaltexth->primarySkillNames[PrimarySkill::DEFENSE]) + ": " + QString::number(hero.getBasePrimarySkillValue(PrimarySkill::DEFENSE)); + textList += QString::fromStdString(VLC->generaltexth->primarySkillNames[PrimarySkill::SPELL_POWER]) + ": " + QString::number(hero.getBasePrimarySkillValue(PrimarySkill::SPELL_POWER)); + textList += QString::fromStdString(VLC->generaltexth->primarySkillNames[PrimarySkill::KNOWLEDGE]) + ": " + QString::number(hero.getBasePrimarySkillValue(PrimarySkill::KNOWLEDGE)); +; + auto heroSecondarySkills = hero.secSkills; + if(heroSecondarySkills.size() == 1 && heroSecondarySkills[0].first == SecondarySkill::NONE) + { + textList += QObject::tr("Default secondary skills:"); + heroSecondarySkills = hero.getHeroType()->secSkillsInit; + } + else + { + textList += QObject::tr("Secondary skills:"); + } + for(auto & [skill, skillLevel] : heroSecondarySkills) + textList += QString::fromStdString(VLC->skillh->getById(skill)->getNameTranslated()) + " " + LevelIdentifiers[skillLevel - 1].first; + + QString text = textList.join("\n"); + QMap data; + data[Qt::DisplayRole] = QVariant(text); + data[Qt::ToolTipRole] = QVariant(text); + model->setItemData(index, data); +} diff --git a/mapeditor/inspector/heroskillswidget.h b/mapeditor/inspector/heroskillswidget.h index 110988767..afbdcff29 100644 --- a/mapeditor/inspector/heroskillswidget.h +++ b/mapeditor/inspector/heroskillswidget.h @@ -10,6 +10,7 @@ #pragma once #include +#include "baseinspectoritemdelegate.h" #include "../../lib/mapObjects/CGHeroInstance.h" namespace Ui { @@ -42,17 +43,18 @@ private: std::set occupiedSkills; }; -class HeroSkillsDelegate : public QStyledItemDelegate +class HeroSkillsDelegate : public BaseInspectorItemDelegate { Q_OBJECT public: - using QStyledItemDelegate::QStyledItemDelegate; + using BaseInspectorItemDelegate::BaseInspectorItemDelegate; HeroSkillsDelegate(CGHeroInstance &); QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; void setEditorData(QWidget *editor, const QModelIndex &index) const override; void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override; + void updateModelData(QAbstractItemModel * model, const QModelIndex & index) const override; private: CGHeroInstance & hero; diff --git a/mapeditor/inspector/herospellwidget.cpp b/mapeditor/inspector/herospellwidget.cpp index 6fe3a49ef..f571b4e66 100644 --- a/mapeditor/inspector/herospellwidget.cpp +++ b/mapeditor/inspector/herospellwidget.cpp @@ -101,7 +101,7 @@ void HeroSpellWidget::on_customizeSpells_toggled(bool checked) initSpellLists(); } -HeroSpellDelegate::HeroSpellDelegate(CGHeroInstance & h) : hero(h), QStyledItemDelegate() +HeroSpellDelegate::HeroSpellDelegate(CGHeroInstance & h) : hero(h), BaseInspectorItemDelegate() { } @@ -127,9 +127,34 @@ void HeroSpellDelegate::setModelData(QWidget * editor, QAbstractItemModel * mode if (auto * ed = qobject_cast(editor)) { ed->commitChanges(); + updateModelData(model, index); } else { QStyledItemDelegate::setModelData(editor, model, index); } } + +void HeroSpellDelegate::updateModelData(QAbstractItemModel * model, const QModelIndex & index) const +{ + QMap data; + if(hero.spellbookContainsSpell(SpellID::PRESET)) + { + QStringList textList; + textList += QObject::tr("Custom Spells:"); + for(auto const & spellID : hero.getSpellsInSpellbook()) + { + if(spellID != SpellID::PRESET) + textList += QString::fromStdString(spellID.toSpell()->getNameTranslated()); + } + QString text = textList.join("\n"); + data[Qt::DisplayRole] = QVariant(text); + data[Qt::ToolTipRole] = QVariant(text); + } + else + { + data[Qt::DisplayRole] = QObject::tr("Default Spells"); + data[Qt::ToolTipRole] = QObject::tr("Default Spells"); + } + model->setItemData(index, data); +} diff --git a/mapeditor/inspector/herospellwidget.h b/mapeditor/inspector/herospellwidget.h index 83864eb12..3fb88700d 100644 --- a/mapeditor/inspector/herospellwidget.h +++ b/mapeditor/inspector/herospellwidget.h @@ -10,6 +10,7 @@ #pragma once #include +#include "baseinspectoritemdelegate.h" #include "../../lib/mapObjects/CGHeroInstance.h" namespace Ui { @@ -39,17 +40,18 @@ private: void initSpellLists(); }; -class HeroSpellDelegate : public QStyledItemDelegate +class HeroSpellDelegate : public BaseInspectorItemDelegate { Q_OBJECT public: - using QStyledItemDelegate::QStyledItemDelegate; + using BaseInspectorItemDelegate::BaseInspectorItemDelegate; HeroSpellDelegate(CGHeroInstance &); QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex& index) const override; void setEditorData(QWidget * editor, const QModelIndex & index) const override; void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const override; + void updateModelData(QAbstractItemModel * model, const QModelIndex & index) const override; private: CGHeroInstance & hero; diff --git a/mapeditor/inspector/inspector.cpp b/mapeditor/inspector/inspector.cpp index 3b9584ca8..c4bf24f11 100644 --- a/mapeditor/inspector/inspector.cpp +++ b/mapeditor/inspector/inspector.cpp @@ -20,6 +20,7 @@ #include "../lib/mapObjects/ObjectTemplate.h" #include "../lib/mapping/CMap.h" #include "../lib/constants/StringConstants.h" +#include "../lib/CPlayerState.h" #include "../lib/texts/CGeneralTextHandler.h" #include "townbuildingswidget.h" @@ -249,7 +250,7 @@ void Inspector::updateProperties(CGDwelling * o) if (o->ID == Obj::RANDOM_DWELLING || o->ID == Obj::RANDOM_DWELLING_LVL) { auto * delegate = new PickObjectDelegate(controller, PickObjectDelegate::typedFilter); - addProperty(QObject::tr("Same as town"), PropertyEditorPlaceholder(), delegate, false); + addProperty(QObject::tr("Same as town"), o->randomizationInfo, delegate, false); } } @@ -850,6 +851,7 @@ QTableWidgetItem * Inspector::addProperty(const QString & value) { auto * item = new QTableWidgetItem(value); item->setFlags(Qt::NoItemFlags); + item->setToolTip(value); return item; } @@ -905,6 +907,17 @@ QTableWidgetItem * Inspector::addProperty(CGCreature::Character value) return item; } +QTableWidgetItem * Inspector::addProperty(const std::optional & value) +{ + QString text = QObject::tr("Select town"); + if(value.has_value() && !value->instanceId.empty()) + text = QString::fromStdString(value->instanceId); + + auto * item = new QTableWidgetItem(text); + item->setFlags(Qt::NoItemFlags); + return item; +} + //======================================================================== Inspector::Inspector(MapController & c, CGObjectInstance * o, QTableWidget * t): obj(o), table(t), controller(c) diff --git a/mapeditor/inspector/inspector.h b/mapeditor/inspector/inspector.h index a7939dd56..66c6a768a 100644 --- a/mapeditor/inspector/inspector.h +++ b/mapeditor/inspector/inspector.h @@ -13,6 +13,7 @@ #include #include #include +#include "baseinspectoritemdelegate.h" #include "../lib/int3.h" #include "../lib/GameConstants.h" #include "../lib/mapObjects/CGCreature.h" @@ -101,6 +102,7 @@ protected: QTableWidgetItem * addProperty(bool value); QTableWidgetItem * addProperty(CGObjectInstance * value); QTableWidgetItem * addProperty(CGCreature::Character value); + QTableWidgetItem * addProperty(const std::optional & value); QTableWidgetItem * addProperty(PropertyEditorPlaceholder value); //===============END OF DECLARATION======================================= @@ -117,7 +119,7 @@ public: protected: template - void addProperty(const QString & key, const T & value, QAbstractItemDelegate * delegate, bool restricted) + void addProperty(const QString & key, const T & value, BaseInspectorItemDelegate * delegate, bool restricted) { auto * itemValue = addProperty(value); if(!restricted) @@ -144,6 +146,11 @@ protected: ++row; } itemKey->setFlags(restricted ? Qt::NoItemFlags : Qt::ItemIsEnabled); + if(delegate != nullptr) + { + QModelIndex index = table->model()->index(itemValue->row(), itemValue->column()); + delegate->updateModelData(table->model(), index); + } } template @@ -161,11 +168,11 @@ protected: }; -class InspectorDelegate : public QStyledItemDelegate +class InspectorDelegate : public BaseInspectorItemDelegate { Q_OBJECT public: - using QStyledItemDelegate::QStyledItemDelegate; + using BaseInspectorItemDelegate::BaseInspectorItemDelegate; QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; void setEditorData(QWidget *editor, const QModelIndex &index) const override; diff --git a/mapeditor/inspector/messagewidget.h b/mapeditor/inspector/messagewidget.h index d74664ebf..968363031 100644 --- a/mapeditor/inspector/messagewidget.h +++ b/mapeditor/inspector/messagewidget.h @@ -9,6 +9,7 @@ */ #pragma once #include "../StdInc.h" +#include "baseinspectoritemdelegate.h" #include namespace Ui { @@ -31,11 +32,11 @@ private: }; -class MessageDelegate : public QStyledItemDelegate +class MessageDelegate : public BaseInspectorItemDelegate { Q_OBJECT public: - using QStyledItemDelegate::QStyledItemDelegate; + using BaseInspectorItemDelegate::BaseInspectorItemDelegate; QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; void setEditorData(QWidget *editor, const QModelIndex &index) const override; diff --git a/mapeditor/inspector/portraitwidget.cpp b/mapeditor/inspector/portraitwidget.cpp index af113be2e..6f5a89a81 100644 --- a/mapeditor/inspector/portraitwidget.cpp +++ b/mapeditor/inspector/portraitwidget.cpp @@ -102,7 +102,7 @@ void PortraitWidget::on_buttonPrev_clicked() drawPortrait(); } -PortraitDelegate::PortraitDelegate(CGHeroInstance & h): hero(h), QStyledItemDelegate() +PortraitDelegate::PortraitDelegate(CGHeroInstance & h): hero(h), BaseInspectorItemDelegate() { } @@ -128,9 +128,21 @@ void PortraitDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, if(auto * ed = qobject_cast(editor)) { ed->commitChanges(); + updateModelData(model, index); } else { QStyledItemDelegate::setModelData(editor, model, index); } } + +void PortraitDelegate::updateModelData(QAbstractItemModel * model, const QModelIndex & index) const +{ + QMap data; + if(hero.customPortraitSource == HeroTypeID::NONE) + data[Qt::DisplayRole] = QObject::tr("Default"); + else + data[Qt::DisplayRole] = QString::fromStdString(hero.customPortraitSource.toHeroType()->getNameTranslated()); + + model->setItemData(index, data); +} diff --git a/mapeditor/inspector/portraitwidget.h b/mapeditor/inspector/portraitwidget.h index 2ca79e801..41abf9140 100644 --- a/mapeditor/inspector/portraitwidget.h +++ b/mapeditor/inspector/portraitwidget.h @@ -10,6 +10,7 @@ #pragma once #include +#include "baseinspectoritemdelegate.h" #include "../../lib/mapObjects/CGHeroInstance.h" namespace Ui { @@ -47,17 +48,18 @@ private: int portraitIndex; }; -class PortraitDelegate : public QStyledItemDelegate +class PortraitDelegate : public BaseInspectorItemDelegate { Q_OBJECT public: - using QStyledItemDelegate::QStyledItemDelegate; + using BaseInspectorItemDelegate::BaseInspectorItemDelegate; PortraitDelegate(CGHeroInstance &); QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; void setEditorData(QWidget *editor, const QModelIndex &index) const override; void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override; + void updateModelData(QAbstractItemModel * model, const QModelIndex & index) const override; private: CGHeroInstance & hero; diff --git a/mapeditor/inspector/questwidget.cpp b/mapeditor/inspector/questwidget.cpp index ff84f8ea7..5da5d520c 100644 --- a/mapeditor/inspector/questwidget.cpp +++ b/mapeditor/inspector/questwidget.cpp @@ -391,7 +391,7 @@ void QuestWidget::on_lCreatureRemove_clicked() ui->lCreatures->removeRow(i); } -QuestDelegate::QuestDelegate(MapController & c, CQuest & t): controller(c), quest(t), QStyledItemDelegate() +QuestDelegate::QuestDelegate(MapController & c, CQuest & t): controller(c), quest(t), BaseInspectorItemDelegate() { } @@ -417,6 +417,7 @@ void QuestDelegate::setModelData(QWidget * editor, QAbstractItemModel * model, c if(auto *ed = qobject_cast(editor)) { ed->commitChanges(); + updateModelData(model, index); } else { @@ -439,3 +440,86 @@ bool QuestDelegate::eventFilter(QObject * object, QEvent * event) } return QStyledItemDelegate::eventFilter(object, event); } + +void QuestDelegate::updateModelData(QAbstractItemModel * model, const QModelIndex & index) const +{ + QStringList textList; + textList += QObject::tr("Quest:"); + textList += QObject::tr("Day of Week: %1").arg(quest.mission.dayOfWeek); + textList += QObject::tr("Days Passed: %1").arg(quest.mission.daysPassed); + textList += QObject::tr("Hero Level: %1").arg(quest.mission.heroLevel); + textList += QObject::tr("Hero Experience: %1").arg(quest.mission.heroExperience); + textList += QObject::tr("Mana Points: %1").arg(quest.mission.manaPoints); + textList += QObject::tr("Mana Percentage: %1").arg(quest.mission.manaPercentage); + textList += QObject::tr("Primary Skills: %1/%2/%3/%4").arg(quest.mission.primary[0]).arg(quest.mission.primary[1]).arg(quest.mission.primary[2]).arg(quest.mission.primary[3]); + + QStringList resourcesList; + for(GameResID resource = GameResID::WOOD; resource < GameResID::COUNT ; resource++) + { + if(resource == GameResID::MITHRIL) + continue; + if(quest.mission.resources[resource] == 0) + continue; + MetaString str; + str.appendName(resource); + resourcesList += QString::fromStdString(str.toString()) + ": " + QString::number(quest.mission.resources[resource]); + } + textList += QObject::tr("Resources: ") + resourcesList.join(", "); + + QStringList artifactsList; + for(auto artifact : quest.mission.artifacts) + { + artifactsList += QString::fromStdString(VLC->artifacts()->getById(artifact)->getNameTranslated()); + } + textList += QObject::tr("Artifacts: ") + artifactsList.join(", "); + + QStringList spellsList; + for(auto spell : quest.mission.spells) + { + spellsList += QString::fromStdString(VLC->spells()->getById(spell)->getNameTranslated()); + } + textList += QObject::tr("Spells: ") + spellsList.join(", "); + + QStringList secondarySkillsList; + for(auto & [skill, skillLevel] : quest.mission.secondary) + { + secondarySkillsList += QString::fromStdString(VLC->skills()->getById(skill)->getNameTranslated()) + " (" + QString::number(skillLevel) + ")"; + } + textList += QObject::tr("Secondary Skills: ") + secondarySkillsList.join(", "); + + QStringList creaturesList; + for(auto & creature : quest.mission.creatures) + { + creaturesList += QString::number(creature.count) + " " + QString::fromStdString(creature.getType()->getNamePluralTranslated()); + } + textList += QObject::tr("Creatures: ") + creaturesList.join(", "); + + QStringList heroesList; + for(auto & hero : quest.mission.heroes) + { + heroesList += QString::fromStdString(VLC->heroTypes()->getById(hero)->getNameTranslated()); + } + textList += QObject::tr("Heroes: ") + heroesList.join(", "); + + QStringList heroClassesList; + for(auto & heroClass : quest.mission.heroClasses) + { + heroClassesList += QString::fromStdString(VLC->heroClasses()->getById(heroClass)->getNameTranslated()); + } + textList += QObject::tr("Hero Classes: ") + heroClassesList.join(", "); + + QStringList playersList; + for(auto & player : quest.mission.players) + { + MetaString str; + str.appendName(player); + playersList += QString::fromStdString(str.toString()); + } + textList += QObject::tr("Players: ") + playersList.join(", "); + + QString text = textList.join("\n"); + QMap data; + data[Qt::DisplayRole] = QVariant(text); + data[Qt::ToolTipRole] = QVariant(text); + model->setItemData(index, data); +} diff --git a/mapeditor/inspector/questwidget.h b/mapeditor/inspector/questwidget.h index 3237c0b65..59e5b677e 100644 --- a/mapeditor/inspector/questwidget.h +++ b/mapeditor/inspector/questwidget.h @@ -10,6 +10,7 @@ #pragma once #include "../StdInc.h" #include +#include "baseinspectoritemdelegate.h" #include "../lib/mapObjects/CQuest.h" namespace Ui { @@ -46,17 +47,18 @@ private: Ui::QuestWidget *ui; }; -class QuestDelegate : public QStyledItemDelegate +class QuestDelegate : public BaseInspectorItemDelegate { Q_OBJECT public: - using QStyledItemDelegate::QStyledItemDelegate; + using BaseInspectorItemDelegate::BaseInspectorItemDelegate; QuestDelegate(MapController &, CQuest &); QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const override; void setEditorData(QWidget * editor, const QModelIndex & index) const override; void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const override; + void updateModelData(QAbstractItemModel * model, const QModelIndex & index) const override; protected: bool eventFilter(QObject * object, QEvent * event) override; diff --git a/mapeditor/inspector/rewardswidget.cpp b/mapeditor/inspector/rewardswidget.cpp index 0e3e5bb4f..dc3f5f67c 100644 --- a/mapeditor/inspector/rewardswidget.cpp +++ b/mapeditor/inspector/rewardswidget.cpp @@ -742,6 +742,7 @@ void RewardsDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, c if(auto * ed = qobject_cast(editor)) { ed->commitChanges(); + updateModelData(model, index); } else { @@ -757,3 +758,71 @@ QWidget * RewardsDelegate::createEditor(QWidget *parent, const QStyleOptionViewI { return new RewardsWidget(map, object, parent); } + +void RewardsDelegate::updateModelData(QAbstractItemModel * model, const QModelIndex & index) const +{ + QStringList textList; + textList += QObject::tr("Rewards:"); + for (const auto & vinfo : object.configuration.info) + { + textList += QObject::tr("Reward Message: %1").arg(QString::fromStdString(vinfo.message.toString())); + textList += QObject::tr("Hero Level: %1").arg(vinfo.reward.heroLevel); + textList += QObject::tr("Hero Experience: %1").arg(vinfo.reward.heroExperience); + textList += QObject::tr("Mana Diff: %1").arg(vinfo.reward.manaDiff); + textList += QObject::tr("Mana Percentage: %1").arg(vinfo.reward.manaPercentage); + textList += QObject::tr("Move Points: %1").arg(vinfo.reward.movePoints); + textList += QObject::tr("Move Percentage: %1").arg(vinfo.reward.movePercentage); + textList += QObject::tr("Primary Skills: %1/%2/%3/%4").arg(vinfo.reward.primary[0]).arg(vinfo.reward.primary[1]).arg(vinfo.reward.primary[2]).arg(vinfo.reward.primary[3]); + QStringList resourcesList; + for(GameResID resource = GameResID::WOOD; resource < GameResID::COUNT ; resource++) + { + if(resource == GameResID::MITHRIL) + continue; // translated as "Abandoned"? + if(vinfo.reward.resources[resource] == 0) + continue; + MetaString str; + str.appendName(resource); + resourcesList += QString::fromStdString(str.toString()) + ": " + QString::number(vinfo.reward.resources[resource]); + } + textList += QObject::tr("Resources: ") + resourcesList.join(", "); + QStringList artifactsList; + for (auto artifact : vinfo.reward.artifacts) + { + artifactsList += QString::fromStdString(VLC->artifacts()->getById(artifact)->getNameTranslated()); + } + textList += QObject::tr("Artifacts: ") + artifactsList.join(", "); + QStringList spellsList; + for (auto spell : vinfo.reward.spells) + { + spellsList += QString::fromStdString(VLC->spells()->getById(spell)->getNameTranslated()); + } + textList += QObject::tr("Spells: ") + spellsList.join(", "); + QStringList secondarySkillsList; + for(auto & [skill, skillLevel] : vinfo.reward.secondary) + { + secondarySkillsList += QString::fromStdString(VLC->skills()->getById(skill)->getNameTranslated()) + " (" + QString::number(skillLevel) + ")"; + } + textList += QObject::tr("Secondary Skills: ") + secondarySkillsList.join(", "); + QStringList creaturesList; + for (auto & creature : vinfo.reward.creatures) + { + creaturesList += QString::number(creature.count) + " " + QString::fromStdString(creature.getType()->getNamePluralTranslated()); + } + textList += QObject::tr("Creatures: ") + creaturesList.join(", "); + if (vinfo.reward.spellCast.first != SpellID::NONE) + { + textList += QObject::tr("Spell Cast: ") + QString::fromStdString(VLC->spells()->getById(vinfo.reward.spellCast.first)->getNameTranslated()) + " (" + QString::number(vinfo.reward.spellCast.second) + ")"; + } + QStringList bonusesList; + for (auto & bonus : vinfo.reward.bonuses) + { + bonusesList += QString::fromStdString(vstd::findKey(bonusDurationMap, bonus.duration)) + " " + QString::fromStdString(vstd::findKey(bonusNameMap, bonus.type)) + " (" + QString::number(bonus.val) + ")"; + } + textList += QObject::tr("Bonuses: ") + bonusesList.join(", "); + } + QString text = textList.join("\n"); + QMap data; + data[Qt::DisplayRole] = QVariant(text); + data[Qt::ToolTipRole] = QVariant(text); + model->setItemData(index, data); +} diff --git a/mapeditor/inspector/rewardswidget.h b/mapeditor/inspector/rewardswidget.h index aeffe17e2..c2d1d64d8 100644 --- a/mapeditor/inspector/rewardswidget.h +++ b/mapeditor/inspector/rewardswidget.h @@ -10,6 +10,7 @@ #pragma once #include "../StdInc.h" #include +#include "baseinspectoritemdelegate.h" #include "../lib/mapObjects/CRewardableObject.h" namespace Ui { @@ -67,18 +68,19 @@ private: CMap & map; }; -class RewardsDelegate : public QStyledItemDelegate +class RewardsDelegate : public BaseInspectorItemDelegate { Q_OBJECT public: RewardsDelegate(CMap &, CRewardableObject &); - using QStyledItemDelegate::QStyledItemDelegate; + using BaseInspectorItemDelegate::BaseInspectorItemDelegate; void setEditorData(QWidget *editor, const QModelIndex &index) const override; void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override; QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; + void updateModelData(QAbstractItemModel * model, const QModelIndex & index) const override; private: CRewardableObject & object; diff --git a/mapeditor/inspector/townbuildingswidget.cpp b/mapeditor/inspector/townbuildingswidget.cpp index 4bf95c5c8..708928741 100644 --- a/mapeditor/inspector/townbuildingswidget.cpp +++ b/mapeditor/inspector/townbuildingswidget.cpp @@ -318,7 +318,7 @@ void TownBuildingsWidget::onItemChanged(const QStandardItem * item) { connect(&model, &QStandardItemModel::itemChanged, this, &TownBuildingsWidget::onItemChanged); } -TownBuildingsDelegate::TownBuildingsDelegate(CGTownInstance & t): town(t), QStyledItemDelegate() +TownBuildingsDelegate::TownBuildingsDelegate(CGTownInstance & t): town(t), BaseInspectorItemDelegate() { } @@ -353,6 +353,7 @@ void TownBuildingsDelegate::setModelData(QWidget *editor, QAbstractItemModel *mo town.removeAllBuildings(); for(const auto & building : ed->getBuiltBuildings()) town.addBuilding(building); + updateModelData(model, index); } else { @@ -360,4 +361,33 @@ void TownBuildingsDelegate::setModelData(QWidget *editor, QAbstractItemModel *mo } } - +void TownBuildingsDelegate::updateModelData(QAbstractItemModel * model, const QModelIndex & index) const +{ + QStringList textList; + textList += QObject::tr("Built buildings:"); + auto * ctown = town.getTown(); + if(!ctown) + ctown = VLC->townh->randomTown; + for(const auto & buildingID : town.getBuildings()) + { + if(buildingID == BuildingID::DEFAULT) + continue; + auto name = QString::fromStdString(ctown->buildings.at(buildingID)->getNameTranslated()); + if(name.isEmpty()) + name = QString::fromStdString(defaultBuildingIdConversion(buildingID)); + textList += name; + } + textList += QObject::tr("Forbidden buildings:"); + for(const auto & buildingID : town.forbiddenBuildings) + { + auto name = QString::fromStdString(ctown->buildings.at(buildingID)->getNameTranslated()); + if(name.isEmpty()) + name = QString::fromStdString(defaultBuildingIdConversion(buildingID)); + textList += name; + } + QString text = textList.join("\n"); + QMap data; + data[Qt::DisplayRole] = QVariant(text); + data[Qt::ToolTipRole] = QVariant(text); + model->setItemData(index, data); +} diff --git a/mapeditor/inspector/townbuildingswidget.h b/mapeditor/inspector/townbuildingswidget.h index 2b3cf1dd2..96c03cf05 100644 --- a/mapeditor/inspector/townbuildingswidget.h +++ b/mapeditor/inspector/townbuildingswidget.h @@ -11,6 +11,7 @@ #include "../StdInc.h" #include +#include "baseinspectoritemdelegate.h" #include "../lib/mapObjects/CGTownInstance.h" namespace Ui { @@ -66,17 +67,18 @@ private: mutable QStandardItemModel model; }; -class TownBuildingsDelegate : public QStyledItemDelegate +class TownBuildingsDelegate : public BaseInspectorItemDelegate { Q_OBJECT public: - using QStyledItemDelegate::QStyledItemDelegate; + using BaseInspectorItemDelegate::BaseInspectorItemDelegate; TownBuildingsDelegate(CGTownInstance &); QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; void setEditorData(QWidget *editor, const QModelIndex &index) const override; void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override; + void updateModelData(QAbstractItemModel * model, const QModelIndex & index) const override; private: CGTownInstance & town; diff --git a/mapeditor/inspector/towneventswidget.cpp b/mapeditor/inspector/towneventswidget.cpp index 963a893f1..3585cf2f2 100644 --- a/mapeditor/inspector/towneventswidget.cpp +++ b/mapeditor/inspector/towneventswidget.cpp @@ -143,7 +143,7 @@ void TownEventsWidget::on_eventsList_itemActivated(QListWidgetItem* item) } -TownEventsDelegate::TownEventsDelegate(CGTownInstance & town, MapController & c) : QStyledItemDelegate(), town(town), controller(c) +TownEventsDelegate::TownEventsDelegate(CGTownInstance & town, MapController & c) : BaseInspectorItemDelegate(), town(town), controller(c) { } @@ -169,9 +169,25 @@ void TownEventsDelegate::setModelData(QWidget * editor, QAbstractItemModel * mod if (auto * ed = qobject_cast(editor)) { ed->commitChanges(controller); + updateModelData(model, index); } else { QStyledItemDelegate::setModelData(editor, model, index); } } + +void TownEventsDelegate::updateModelData(QAbstractItemModel * model, const QModelIndex & index) const +{ + QStringList eventLists; + for (const auto & event : town.events) + { + auto eventName = QString::fromStdString(event.name); + eventLists += tr("Day %1 - %2").arg(event.firstOccurrence + 1, 3).arg(eventName); + } + QString text = QObject::tr("Town Events:\n") + eventLists.join(",\n"); + QMap data; + data[Qt::DisplayRole] = QVariant(text); + data[Qt::ToolTipRole] = QVariant(text); + model->setItemData(index, data); +} diff --git a/mapeditor/inspector/towneventswidget.h b/mapeditor/inspector/towneventswidget.h index 7bc85f6ca..54e7e17b3 100644 --- a/mapeditor/inspector/towneventswidget.h +++ b/mapeditor/inspector/towneventswidget.h @@ -11,6 +11,7 @@ #include "../StdInc.h" #include +#include "baseinspectoritemdelegate.h" #include "../lib/mapping/CMapDefines.h" #include "../lib/mapObjects/CGTownInstance.h" #include "../mapcontroller.h" @@ -40,17 +41,18 @@ private: CGTownInstance & town; }; -class TownEventsDelegate : public QStyledItemDelegate +class TownEventsDelegate : public BaseInspectorItemDelegate { Q_OBJECT public: - using QStyledItemDelegate::QStyledItemDelegate; + using BaseInspectorItemDelegate::BaseInspectorItemDelegate; TownEventsDelegate(CGTownInstance &, MapController &); QWidget* createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const override; void setEditorData(QWidget * editor, const QModelIndex & index) const override; void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const override; + void updateModelData(QAbstractItemModel * model, const QModelIndex & index) const override; private: CGTownInstance & town; diff --git a/mapeditor/inspector/townspellswidget.cpp b/mapeditor/inspector/townspellswidget.cpp index abfd4def2..3d901dd8b 100644 --- a/mapeditor/inspector/townspellswidget.cpp +++ b/mapeditor/inspector/townspellswidget.cpp @@ -132,7 +132,7 @@ void TownSpellsWidget::on_customizeSpells_toggled(bool checked) initSpellLists(); } -TownSpellsDelegate::TownSpellsDelegate(CGTownInstance & town) : QStyledItemDelegate(), town(town) +TownSpellsDelegate::TownSpellsDelegate(CGTownInstance & town) : BaseInspectorItemDelegate(), town(town) { } @@ -158,9 +158,46 @@ void TownSpellsDelegate::setModelData(QWidget * editor, QAbstractItemModel * mod if (auto * ed = qobject_cast(editor)) { ed->commitChanges(); + updateModelData(model, index); } else { QStyledItemDelegate::setModelData(editor, model, index); } } + +void TownSpellsDelegate::updateModelData(QAbstractItemModel * model, const QModelIndex & index) const +{ + QStringList textList; + QStringList requiredSpellsList; + QStringList possibleSpellsList; + if(vstd::contains(town.possibleSpells, SpellID::PRESET)) { + textList += QObject::tr("Custom Spells:"); + textList += QObject::tr("Required:"); + QStringList requiredSpellsList; + for(auto spellID : town.obligatorySpells) + { + auto spell = spellID.toEntity(VLC); + requiredSpellsList += QString::fromStdString(spell->getNameTranslated()); + } + textList += requiredSpellsList.join(","); + textList += QObject::tr("Possible:"); + for(auto spellID : town.possibleSpells) + { + if(spellID == SpellID::PRESET) + continue; + auto spell = spellID.toEntity(VLC); + possibleSpellsList += QString::fromStdString(spell->getNameTranslated()); + } + textList += possibleSpellsList.join(","); + } + else + { + textList += QObject::tr("Default Spells"); + } + QString text = textList.join("\n"); + QMap data; + data[Qt::DisplayRole] = QVariant(text); + data[Qt::ToolTipRole] = QVariant(text); + model->setItemData(index, data); +} diff --git a/mapeditor/inspector/townspellswidget.h b/mapeditor/inspector/townspellswidget.h index 1548c25f7..f34ecc8c7 100644 --- a/mapeditor/inspector/townspellswidget.h +++ b/mapeditor/inspector/townspellswidget.h @@ -10,6 +10,7 @@ #pragma once #include +#include "baseinspectoritemdelegate.h" #include "../../lib/mapObjects/CGTownInstance.h" namespace Ui { @@ -43,17 +44,18 @@ private: void initSpellLists(); }; -class TownSpellsDelegate : public QStyledItemDelegate +class TownSpellsDelegate : public BaseInspectorItemDelegate { Q_OBJECT public: - using QStyledItemDelegate::QStyledItemDelegate; + using BaseInspectorItemDelegate::BaseInspectorItemDelegate; TownSpellsDelegate(CGTownInstance&); QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex& index) const override; void setEditorData(QWidget * editor, const QModelIndex & index) const override; void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const override; + void updateModelData(QAbstractItemModel * model, const QModelIndex & index) const override; private: CGTownInstance& town;