mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Add seerhut rewards
This commit is contained in:
parent
36b87689f9
commit
dd463ca95a
@ -39,6 +39,8 @@ Initializer::Initializer(CGObjectInstance * o, const PlayerColor & pl) : default
|
||||
INIT_OBJ_TYPE(CGSignBottle);
|
||||
INIT_OBJ_TYPE(CGLighthouse);
|
||||
//INIT_OBJ_TYPE(CGPandoraBox);
|
||||
//INIT_OBJ_TYPE(CGEvent);
|
||||
//INIT_OBJ_TYPE(CGSeerHut);
|
||||
}
|
||||
|
||||
bool stringToBool(const QString & s)
|
||||
@ -235,7 +237,7 @@ void Inspector::updateProperties(CGHeroInstance * o)
|
||||
addProperty<int>("Experience", o->exp, false);
|
||||
addProperty("Hero class", o->type->heroClass->getName(), true);
|
||||
|
||||
{
|
||||
{ //Sex
|
||||
auto * delegate = new InspectorDelegate;
|
||||
delegate->options << "MALE" << "FEMALE";
|
||||
addProperty<std::string>("Sex", (o->sex ? "FEMALE" : "MALE"), delegate , false);
|
||||
@ -244,7 +246,7 @@ void Inspector::updateProperties(CGHeroInstance * o)
|
||||
addProperty("Biography", o->biography, new MessageDelegate, false);
|
||||
addProperty("Portrait", o->portrait, false);
|
||||
|
||||
{
|
||||
{ //Hero type
|
||||
auto * delegate = new InspectorDelegate;
|
||||
for(int i = 0; i < VLC->heroh->objects.size(); ++i)
|
||||
{
|
||||
@ -320,7 +322,7 @@ void Inspector::updateProperties(CGCreature * o)
|
||||
if(!o) return;
|
||||
|
||||
addProperty("Message", o->message, false);
|
||||
{
|
||||
{ //Character
|
||||
auto * delegate = new InspectorDelegate;
|
||||
delegate->options << "COMPLIANT" << "FRIENDLY" << "AGRESSIVE" << "HOSTILE" << "SAVAGE";
|
||||
addProperty<CGCreature::Character>("Character", (CGCreature::Character)o->character, delegate, false);
|
||||
@ -353,6 +355,23 @@ void Inspector::updateProperties(CGEvent * o)
|
||||
//ui8 availableFor; //players whom this event is available for
|
||||
}
|
||||
|
||||
void Inspector::updateProperties(CGSeerHut * o)
|
||||
{
|
||||
if(!o) return;
|
||||
|
||||
{ //Mission type
|
||||
auto * delegate = new InspectorDelegate;
|
||||
delegate->options << "Reach level" << "Stats" << "Kill hero" << "Kill creature" << "Artifact" << "Army" << "Resources" << "Hero" << "Player";
|
||||
addProperty<CQuest::Emission>("Mission type", o->quest->missionType, delegate, false);
|
||||
}
|
||||
|
||||
addProperty("First visit text", o->quest->firstVisitText, new MessageDelegate, false);
|
||||
addProperty("Next visit text", o->quest->nextVisitText, new MessageDelegate, false);
|
||||
addProperty("Completed text", o->quest->completedText, new MessageDelegate, false);
|
||||
|
||||
auto * delegate = new RewardsSeerhutDelegate(*map, *o);
|
||||
addProperty("Reward", PropertyEditorPlaceholder(), delegate, false);
|
||||
}
|
||||
|
||||
void Inspector::updateProperties()
|
||||
{
|
||||
@ -394,6 +413,7 @@ void Inspector::updateProperties()
|
||||
UPDATE_OBJ_PROPERTIES(CGLighthouse);
|
||||
UPDATE_OBJ_PROPERTIES(CGPandoraBox);
|
||||
UPDATE_OBJ_PROPERTIES(CGEvent);
|
||||
UPDATE_OBJ_PROPERTIES(CGSeerHut);
|
||||
|
||||
table->show();
|
||||
}
|
||||
@ -428,6 +448,7 @@ void Inspector::setProperty(const QString & key, const QVariant & value)
|
||||
SET_PROPERTIES(CGLighthouse);
|
||||
SET_PROPERTIES(CGPandoraBox);
|
||||
SET_PROPERTIES(CGEvent);
|
||||
SET_PROPERTIES(CGSeerHut);
|
||||
}
|
||||
|
||||
void Inspector::setProperty(CArmedInstance * o, const QString & key, const QVariant & value)
|
||||
@ -583,6 +604,40 @@ void Inspector::setProperty(CGCreature * o, const QString & key, const QVariant
|
||||
o->stacks[SlotID(0)]->count = value.toString().toInt();
|
||||
}
|
||||
|
||||
void Inspector::setProperty(CGSeerHut * o, const QString & key, const QVariant & value)
|
||||
{
|
||||
if(!o) return;
|
||||
|
||||
if(key == "Mission type")
|
||||
{
|
||||
if(value == "Reach level")
|
||||
o->quest->missionType = CQuest::Emission::MISSION_LEVEL;
|
||||
if(value == "Stats")
|
||||
o->quest->missionType = CQuest::Emission::MISSION_PRIMARY_STAT;
|
||||
if(value == "Kill hero")
|
||||
o->quest->missionType = CQuest::Emission::MISSION_KILL_HERO;
|
||||
if(value == "Kill creature")
|
||||
o->quest->missionType = CQuest::Emission::MISSION_KILL_CREATURE;
|
||||
if(value == "Artifact")
|
||||
o->quest->missionType = CQuest::Emission::MISSION_ART;
|
||||
if(value == "Army")
|
||||
o->quest->missionType = CQuest::Emission::MISSION_ARMY;
|
||||
if(value == "Resources")
|
||||
o->quest->missionType = CQuest::Emission::MISSION_RESOURCES;
|
||||
if(value == "Hero")
|
||||
o->quest->missionType = CQuest::Emission::MISSION_HERO;
|
||||
if(value == "Player")
|
||||
o->quest->missionType = CQuest::Emission::MISSION_PLAYER;
|
||||
}
|
||||
|
||||
if(key == "First visit text")
|
||||
o->quest->firstVisitText = value.toString().toStdString();
|
||||
if(key == "Next visit text")
|
||||
o->quest->nextVisitText = value.toString().toStdString();
|
||||
if(key == "Completed text")
|
||||
o->quest->completedText = value.toString().toStdString();
|
||||
}
|
||||
|
||||
|
||||
//===============IMPLEMENT PROPERTY VALUE TYPE============================
|
||||
QTableWidgetItem * Inspector::addProperty(CGObjectInstance * value)
|
||||
@ -693,6 +748,46 @@ QTableWidgetItem * Inspector::addProperty(CGCreature::Character value)
|
||||
return new QTableWidgetItem(str);
|
||||
}
|
||||
|
||||
QTableWidgetItem * Inspector::addProperty(CQuest::Emission value)
|
||||
{
|
||||
QString str;
|
||||
switch (value) {
|
||||
case CQuest::Emission::MISSION_LEVEL:
|
||||
str = "Reach level";
|
||||
break;
|
||||
case CQuest::Emission::MISSION_PRIMARY_STAT:
|
||||
str = "Stats";
|
||||
break;
|
||||
case CQuest::Emission::MISSION_KILL_HERO:
|
||||
str = "Kill hero";
|
||||
break;
|
||||
case CQuest::Emission::MISSION_KILL_CREATURE:
|
||||
str = "Kill creature";
|
||||
break;
|
||||
case CQuest::Emission::MISSION_ART:
|
||||
str = "Artifact";
|
||||
break;
|
||||
case CQuest::Emission::MISSION_ARMY:
|
||||
str = "Army";
|
||||
break;
|
||||
case CQuest::Emission::MISSION_RESOURCES:
|
||||
str = "Resources";
|
||||
break;
|
||||
case CQuest::Emission::MISSION_HERO:
|
||||
str = "Hero";
|
||||
break;
|
||||
case CQuest::Emission::MISSION_PLAYER:
|
||||
str = "Player";
|
||||
break;
|
||||
case CQuest::Emission::MISSION_KEYMASTER:
|
||||
str = "Key master";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return new QTableWidgetItem(str);
|
||||
}
|
||||
|
||||
//========================================================================
|
||||
|
||||
Inspector::Inspector(CMap * m, CGObjectInstance * o, QTableWidget * t): obj(o), table(t), map(m)
|
||||
|
@ -45,7 +45,7 @@ public:
|
||||
DECLARE_OBJ_TYPE(CGLighthouse);
|
||||
//DECLARE_OBJ_TYPE(CGEvent);
|
||||
//DECLARE_OBJ_TYPE(CGPandoraBox);
|
||||
|
||||
//DECLARE_OBJ_TYPE(CGSeerHut);
|
||||
|
||||
Initializer(CGObjectInstance *, const PlayerColor &);
|
||||
|
||||
@ -73,6 +73,7 @@ protected:
|
||||
DECLARE_OBJ_PROPERTY_METHODS(CGLighthouse);
|
||||
DECLARE_OBJ_PROPERTY_METHODS(CGPandoraBox);
|
||||
DECLARE_OBJ_PROPERTY_METHODS(CGEvent);
|
||||
DECLARE_OBJ_PROPERTY_METHODS(CGSeerHut);
|
||||
|
||||
//===============DECLARE PROPERTY VALUE TYPE==============================
|
||||
QTableWidgetItem * addProperty(unsigned int value);
|
||||
@ -85,6 +86,7 @@ protected:
|
||||
QTableWidgetItem * addProperty(bool value);
|
||||
QTableWidgetItem * addProperty(CGObjectInstance * value);
|
||||
QTableWidgetItem * addProperty(CGCreature::Character value);
|
||||
QTableWidgetItem * addProperty(CQuest::Emission value);
|
||||
QTableWidgetItem * addProperty(PropertyEditorPlaceholder value);
|
||||
|
||||
//===============END OF DECLARATION=======================================
|
||||
|
@ -28,6 +28,18 @@ RewardsWidget::RewardsWidget(const CMap & m, CGPandoraBox & p, QWidget *parent)
|
||||
ui->rewardType->addItem(QString::fromStdString(type));
|
||||
}
|
||||
|
||||
RewardsWidget::RewardsWidget(const CMap & m, CGSeerHut & p, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
map(m),
|
||||
seerhut(&p),
|
||||
ui(new Ui::RewardsWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
for(auto & type : rewardTypes)
|
||||
ui->rewardType->addItem(QString::fromStdString(type));
|
||||
}
|
||||
|
||||
RewardsWidget::~RewardsWidget()
|
||||
{
|
||||
delete ui;
|
||||
@ -144,6 +156,55 @@ void RewardsWidget::obtainData()
|
||||
addReward(RewardType::CREATURE, c->getId(), pandora->creatures.getStackCount(SlotID(i)));
|
||||
}
|
||||
}
|
||||
|
||||
if(seerhut)
|
||||
{
|
||||
switch(seerhut->rewardType)
|
||||
{
|
||||
case CGSeerHut::ERewardType::EXPERIENCE:
|
||||
addReward(RewardType::EXPERIENCE, 0, seerhut->rVal);
|
||||
break;
|
||||
|
||||
case CGSeerHut::ERewardType::MANA_POINTS:
|
||||
addReward(RewardType::MANA, 0, seerhut->rVal);
|
||||
break;
|
||||
|
||||
case CGSeerHut::ERewardType::MORALE_BONUS:
|
||||
addReward(RewardType::MORALE, 0, seerhut->rVal);
|
||||
break;
|
||||
|
||||
case CGSeerHut::ERewardType::LUCK_BONUS:
|
||||
addReward(RewardType::LUCK, 0, seerhut->rVal);
|
||||
break;
|
||||
|
||||
case CGSeerHut::ERewardType::RESOURCES:
|
||||
addReward(RewardType::RESOURCE, seerhut->rID, seerhut->rVal);
|
||||
break;
|
||||
|
||||
case CGSeerHut::ERewardType::PRIMARY_SKILL:
|
||||
addReward(RewardType::PRIMARY_SKILL, seerhut->rID, seerhut->rVal);
|
||||
break;
|
||||
|
||||
case CGSeerHut::ERewardType::SECONDARY_SKILL:
|
||||
addReward(RewardType::SECONDARY_SKILL, seerhut->rID, seerhut->rVal);
|
||||
break;
|
||||
|
||||
case CGSeerHut::ERewardType::ARTIFACT:
|
||||
addReward(RewardType::ARTIFACT, seerhut->rID, seerhut->rVal);
|
||||
break;
|
||||
|
||||
case CGSeerHut::ERewardType::SPELL:
|
||||
addReward(RewardType::SPELL, seerhut->rID, seerhut->rVal);
|
||||
break;
|
||||
|
||||
case CGSeerHut::ERewardType::CREATURE:
|
||||
addReward(RewardType::CREATURE, seerhut->rID, seerhut->rVal);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool RewardsWidget::commitChanges()
|
||||
@ -212,6 +273,19 @@ bool RewardsWidget::commitChanges()
|
||||
}
|
||||
}
|
||||
}
|
||||
if(seerhut)
|
||||
{
|
||||
for(int row = 0; row < rewards; ++row)
|
||||
{
|
||||
haveRewards = true;
|
||||
int typeId = ui->rewardsTable->item(row, 0)->data(Qt::UserRole).toInt();
|
||||
int listId = ui->rewardsTable->item(row, 1) ? ui->rewardsTable->item(row, 1)->data(Qt::UserRole).toInt() : 0;
|
||||
int amount = ui->rewardsTable->item(row, 2)->data(Qt::UserRole).toInt();
|
||||
seerhut->rewardType = CGSeerHut::ERewardType(typeId + 1);
|
||||
seerhut->rID = listId;
|
||||
seerhut->rVal = amount;
|
||||
}
|
||||
}
|
||||
return haveRewards;
|
||||
}
|
||||
|
||||
@ -222,6 +296,10 @@ void RewardsWidget::on_rewardList_activated(int index)
|
||||
|
||||
void RewardsWidget::addReward(RewardsWidget::RewardType typeId, int listId, int amount)
|
||||
{
|
||||
//for seerhut there could be the only one reward
|
||||
if(!pandora && seerhut && rewards)
|
||||
return;
|
||||
|
||||
ui->rewardsTable->setRowCount(++rewards);
|
||||
|
||||
auto itemType = new QTableWidgetItem(QString::fromStdString(rewardTypes[typeId]));
|
||||
@ -294,17 +372,7 @@ void RewardsWidget::on_rewardsTable_itemSelectionChanged()
|
||||
ui->rewardAmount->setText(QString::number(type->data(Qt::UserRole).toInt()));*/
|
||||
}
|
||||
|
||||
|
||||
RewardsPandoraDelegate::RewardsPandoraDelegate(const CMap & m, CGPandoraBox & t): map(m), pandora(t), QStyledItemDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
QWidget * RewardsPandoraDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
return new RewardsWidget(map, pandora, parent);
|
||||
}
|
||||
|
||||
void RewardsPandoraDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
|
||||
void RewardsDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
|
||||
{
|
||||
if(auto * ed = qobject_cast<RewardsWidget *>(editor))
|
||||
{
|
||||
@ -316,7 +384,7 @@ void RewardsPandoraDelegate::setEditorData(QWidget *editor, const QModelIndex &i
|
||||
}
|
||||
}
|
||||
|
||||
void RewardsPandoraDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
|
||||
void RewardsDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
|
||||
{
|
||||
if(auto * ed = qobject_cast<RewardsWidget *>(editor))
|
||||
{
|
||||
@ -332,3 +400,21 @@ void RewardsPandoraDelegate::setModelData(QWidget *editor, QAbstractItemModel *m
|
||||
QStyledItemDelegate::setModelData(editor, model, index);
|
||||
}
|
||||
}
|
||||
|
||||
RewardsPandoraDelegate::RewardsPandoraDelegate(const CMap & m, CGPandoraBox & t): map(m), pandora(t), RewardsDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
QWidget * RewardsPandoraDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
return new RewardsWidget(map, pandora, parent);
|
||||
}
|
||||
|
||||
RewardsSeerhutDelegate::RewardsSeerhutDelegate(const CMap & m, CGSeerHut & t): map(m), seerhut(t), RewardsDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
QWidget * RewardsSeerhutDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
return new RewardsWidget(map, seerhut, parent);
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
#pragma once
|
||||
#include <QDialog>
|
||||
#include "../lib/mapObjects/CGPandoraBox.h"
|
||||
#include "../lib/mapObjects/CQuest.h"
|
||||
#include "../lib/mapping/CMap.h"
|
||||
|
||||
namespace Ui {
|
||||
@ -29,6 +30,7 @@ public:
|
||||
};
|
||||
|
||||
explicit RewardsWidget(const CMap &, CGPandoraBox &, QWidget *parent = nullptr);
|
||||
explicit RewardsWidget(const CMap &, CGSeerHut &, QWidget *parent = nullptr);
|
||||
~RewardsWidget();
|
||||
|
||||
void obtainData();
|
||||
@ -53,23 +55,43 @@ private:
|
||||
|
||||
Ui::RewardsWidget *ui;
|
||||
CGPandoraBox * pandora;
|
||||
CGSeerHut * seerhut;
|
||||
const CMap & map;
|
||||
int rewards = 0;
|
||||
};
|
||||
|
||||
class RewardsPandoraDelegate : public QStyledItemDelegate
|
||||
class RewardsDelegate : public QStyledItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
using QStyledItemDelegate::QStyledItemDelegate;
|
||||
|
||||
void setEditorData(QWidget *editor, const QModelIndex &index) const override;
|
||||
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
|
||||
};
|
||||
|
||||
class RewardsPandoraDelegate : public RewardsDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
RewardsPandoraDelegate(const CMap &, CGPandoraBox &);
|
||||
|
||||
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;
|
||||
|
||||
private:
|
||||
CGPandoraBox & pandora;
|
||||
const CMap & map;
|
||||
};
|
||||
|
||||
class RewardsSeerhutDelegate : public RewardsDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
RewardsSeerhutDelegate(const CMap &, CGSeerHut &);
|
||||
|
||||
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||
|
||||
private:
|
||||
CGSeerHut & seerhut;
|
||||
const CMap & map;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user