mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-15 20:03:15 +02:00
Partially implement seerhuts
This commit is contained in:
@@ -23,6 +23,7 @@ set(editor_SRCS
|
|||||||
inspector/armywidget.cpp
|
inspector/armywidget.cpp
|
||||||
inspector/messagewidget.cpp
|
inspector/messagewidget.cpp
|
||||||
inspector/rewardswidget.cpp
|
inspector/rewardswidget.cpp
|
||||||
|
inspector/questwidget.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(editor_HEADERS
|
set(editor_HEADERS
|
||||||
@@ -49,6 +50,7 @@ set(editor_HEADERS
|
|||||||
inspector/armywidget.h
|
inspector/armywidget.h
|
||||||
inspector/messagewidget.h
|
inspector/messagewidget.h
|
||||||
inspector/rewardswidget.h
|
inspector/rewardswidget.h
|
||||||
|
inspector/questwidget.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set(editor_FORMS
|
set(editor_FORMS
|
||||||
@@ -63,6 +65,7 @@ set(editor_FORMS
|
|||||||
inspector/armywidget.ui
|
inspector/armywidget.ui
|
||||||
inspector/messagewidget.ui
|
inspector/messagewidget.ui
|
||||||
inspector/rewardswidget.ui
|
inspector/rewardswidget.ui
|
||||||
|
inspector/questwidget.ui
|
||||||
)
|
)
|
||||||
|
|
||||||
assign_source_group(${editor_SRCS} ${editor_HEADERS} mapeditor.rc)
|
assign_source_group(${editor_SRCS} ${editor_HEADERS} mapeditor.rc)
|
||||||
|
@@ -20,6 +20,7 @@
|
|||||||
#include "armywidget.h"
|
#include "armywidget.h"
|
||||||
#include "messagewidget.h"
|
#include "messagewidget.h"
|
||||||
#include "rewardswidget.h"
|
#include "rewardswidget.h"
|
||||||
|
#include "questwidget.h"
|
||||||
|
|
||||||
//===============IMPLEMENT OBJECT INITIALIZATION FUNCTIONS================
|
//===============IMPLEMENT OBJECT INITIALIZATION FUNCTIONS================
|
||||||
Initializer::Initializer(CGObjectInstance * o, const PlayerColor & pl) : defaultPlayer(pl)
|
Initializer::Initializer(CGObjectInstance * o, const PlayerColor & pl) : defaultPlayer(pl)
|
||||||
@@ -369,8 +370,15 @@ void Inspector::updateProperties(CGSeerHut * o)
|
|||||||
addProperty("Next visit text", o->quest->nextVisitText, new MessageDelegate, false);
|
addProperty("Next visit text", o->quest->nextVisitText, new MessageDelegate, false);
|
||||||
addProperty("Completed text", o->quest->completedText, new MessageDelegate, false);
|
addProperty("Completed text", o->quest->completedText, new MessageDelegate, false);
|
||||||
|
|
||||||
auto * delegate = new RewardsSeerhutDelegate(*map, *o);
|
{ //Quest
|
||||||
addProperty("Reward", PropertyEditorPlaceholder(), delegate, false);
|
auto * delegate = new QuestDelegate(*map, *o);
|
||||||
|
addProperty("Quest", PropertyEditorPlaceholder(), delegate, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
{ //Reward
|
||||||
|
auto * delegate = new RewardsSeerhutDelegate(*map, *o);
|
||||||
|
addProperty("Reward", PropertyEditorPlaceholder(), delegate, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Inspector::updateProperties()
|
void Inspector::updateProperties()
|
||||||
|
@@ -33,12 +33,12 @@ QString MessageWidget::getMessage() const
|
|||||||
return ui->messageEdit->toPlainText();
|
return ui->messageEdit->toPlainText();
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget * MessageDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
QWidget * MessageDelegate::createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const
|
||||||
{
|
{
|
||||||
return new MessageWidget(parent);
|
return new MessageWidget(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
|
void MessageDelegate::setEditorData(QWidget * editor, const QModelIndex & index) const
|
||||||
{
|
{
|
||||||
if(auto *ed = qobject_cast<MessageWidget *>(editor))
|
if(auto *ed = qobject_cast<MessageWidget *>(editor))
|
||||||
{
|
{
|
||||||
@@ -50,7 +50,7 @@ void MessageDelegate::setEditorData(QWidget *editor, const QModelIndex &index) c
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
|
void MessageDelegate::setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const
|
||||||
{
|
{
|
||||||
if(auto *ed = qobject_cast<MessageWidget *>(editor))
|
if(auto *ed = qobject_cast<MessageWidget *>(editor))
|
||||||
{
|
{
|
||||||
|
193
mapeditor/inspector/questwidget.cpp
Normal file
193
mapeditor/inspector/questwidget.cpp
Normal file
@@ -0,0 +1,193 @@
|
|||||||
|
/*
|
||||||
|
* questwidget.cpp, 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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include "StdInc.h"
|
||||||
|
#include "questwidget.h"
|
||||||
|
#include "ui_questwidget.h"
|
||||||
|
#include "../lib/VCMI_Lib.h"
|
||||||
|
#include "../lib/CSkillHandler.h"
|
||||||
|
#include "../lib/CArtHandler.h"
|
||||||
|
#include "../lib/CCreatureHandler.h"
|
||||||
|
#include "../lib/CHeroHandler.h"
|
||||||
|
#include "../lib/StringConstants.h"
|
||||||
|
|
||||||
|
QuestWidget::QuestWidget(const CMap & _map, CGSeerHut & _sh, QWidget *parent) :
|
||||||
|
QDialog(parent),
|
||||||
|
map(_map),
|
||||||
|
seerhut(_sh),
|
||||||
|
ui(new Ui::QuestWidget)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
QuestWidget::~QuestWidget()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QuestWidget::obtainData()
|
||||||
|
{
|
||||||
|
assert(seerhut.quest);
|
||||||
|
bool activeId = false;
|
||||||
|
bool activeAmount = false;
|
||||||
|
switch(seerhut.quest->missionType) {
|
||||||
|
case CQuest::Emission::MISSION_LEVEL:
|
||||||
|
activeAmount = true;
|
||||||
|
ui->targetId->addItem("Reach level");
|
||||||
|
ui->targetAmount->setText(QString::number(seerhut.quest->m13489val));
|
||||||
|
break;
|
||||||
|
case CQuest::Emission::MISSION_PRIMARY_STAT:
|
||||||
|
activeId = true;
|
||||||
|
activeAmount = true;
|
||||||
|
for(auto s : PrimarySkill::names)
|
||||||
|
ui->targetId->addItem(QString::fromStdString(s));
|
||||||
|
for(int i = 0; i < seerhut.quest->m2stats.size(); ++i)
|
||||||
|
{
|
||||||
|
if(seerhut.quest->m2stats[i] > 0)
|
||||||
|
{
|
||||||
|
ui->targetId->setCurrentIndex(i);
|
||||||
|
ui->targetAmount->setText(QString::number(seerhut.quest->m2stats[i]));
|
||||||
|
break; //TODO: support multiple stats
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case CQuest::Emission::MISSION_KILL_HERO:
|
||||||
|
activeId = true;
|
||||||
|
//TODO: implement
|
||||||
|
break;
|
||||||
|
case CQuest::Emission::MISSION_KILL_CREATURE:
|
||||||
|
activeId = true;
|
||||||
|
//TODO: implement
|
||||||
|
break;
|
||||||
|
case CQuest::Emission::MISSION_ART:
|
||||||
|
activeId = true;
|
||||||
|
for(int i = 0; i < map.allowedArtifact.size(); ++i)
|
||||||
|
ui->targetId->addItem(QString::fromStdString(VLC->arth->objects.at(i)->getName()));
|
||||||
|
if(!seerhut.quest->m5arts.empty())
|
||||||
|
ui->targetId->setCurrentIndex(seerhut.quest->m5arts.front());
|
||||||
|
//TODO: support multiple artifacts
|
||||||
|
break;
|
||||||
|
case CQuest::Emission::MISSION_ARMY:
|
||||||
|
activeId = true;
|
||||||
|
activeAmount = true;
|
||||||
|
break;
|
||||||
|
case CQuest::Emission::MISSION_RESOURCES:
|
||||||
|
activeId = true;
|
||||||
|
activeAmount = true;
|
||||||
|
for(auto s : GameConstants::RESOURCE_NAMES)
|
||||||
|
ui->targetId->addItem(QString::fromStdString(s));
|
||||||
|
for(int i = 0; i < seerhut.quest->m7resources.size(); ++i)
|
||||||
|
{
|
||||||
|
if(seerhut.quest->m7resources[i] > 0)
|
||||||
|
{
|
||||||
|
ui->targetId->setCurrentIndex(i);
|
||||||
|
ui->targetAmount->setText(QString::number(seerhut.quest->m7resources[i]));
|
||||||
|
break; //TODO: support multiple resources
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case CQuest::Emission::MISSION_HERO:
|
||||||
|
activeId = true;
|
||||||
|
for(int i = 0; i < map.allowedHeroes.size(); ++i)
|
||||||
|
ui->targetId->addItem(QString::fromStdString(VLC->heroh->objects.at(i)->getName()));
|
||||||
|
ui->targetId->setCurrentIndex(seerhut.quest->m13489val);
|
||||||
|
break;
|
||||||
|
case CQuest::Emission::MISSION_PLAYER:
|
||||||
|
activeId = true;
|
||||||
|
for(auto s : GameConstants::PLAYER_COLOR_NAMES)
|
||||||
|
ui->targetId->addItem(QString::fromStdString(s));
|
||||||
|
ui->targetId->setCurrentIndex(seerhut.quest->m13489val);
|
||||||
|
break;
|
||||||
|
case CQuest::Emission::MISSION_KEYMASTER:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->targetId->setEnabled(activeId);
|
||||||
|
ui->targetAmount->setEnabled(activeAmount);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString QuestWidget::commitChanges()
|
||||||
|
{
|
||||||
|
assert(seerhut.quest);
|
||||||
|
switch(seerhut.quest->missionType) {
|
||||||
|
case CQuest::Emission::MISSION_LEVEL:
|
||||||
|
seerhut.quest->m13489val = ui->targetAmount->text().toInt();
|
||||||
|
return QString("Reach lvl ").append(ui->targetAmount->text());
|
||||||
|
case CQuest::Emission::MISSION_PRIMARY_STAT:
|
||||||
|
seerhut.quest->m2stats.resize(sizeof(PrimarySkill::names), 0);
|
||||||
|
seerhut.quest->m2stats[ui->targetId->currentIndex()] = ui->targetAmount->text().toInt();
|
||||||
|
//TODO: support multiple stats
|
||||||
|
return ui->targetId->currentText().append(ui->targetAmount->text());
|
||||||
|
case CQuest::Emission::MISSION_KILL_HERO:
|
||||||
|
//TODO: implement
|
||||||
|
return QString("N/A");
|
||||||
|
case CQuest::Emission::MISSION_KILL_CREATURE:
|
||||||
|
//TODO: implement
|
||||||
|
return QString("N/A");
|
||||||
|
case CQuest::Emission::MISSION_ART:
|
||||||
|
seerhut.quest->m5arts.clear();
|
||||||
|
seerhut.quest->m5arts.push_back(ui->targetId->currentIndex());
|
||||||
|
//TODO: support multiple artifacts
|
||||||
|
return ui->targetId->currentText();
|
||||||
|
case CQuest::Emission::MISSION_ARMY:
|
||||||
|
//TODO: implement
|
||||||
|
return QString("N/A");
|
||||||
|
case CQuest::Emission::MISSION_RESOURCES:
|
||||||
|
seerhut.quest->m7resources.resize(sizeof(GameConstants::RESOURCE_NAMES), 0);
|
||||||
|
seerhut.quest->m7resources[ui->targetId->currentIndex()] = ui->targetAmount->text().toInt();
|
||||||
|
//TODO: support resources
|
||||||
|
return ui->targetId->currentText().append(ui->targetAmount->text());
|
||||||
|
case CQuest::Emission::MISSION_HERO:
|
||||||
|
seerhut.quest->m13489val = ui->targetId->currentIndex();
|
||||||
|
return ui->targetId->currentText();
|
||||||
|
case CQuest::Emission::MISSION_PLAYER:
|
||||||
|
seerhut.quest->m13489val = ui->targetId->currentIndex();
|
||||||
|
return ui->targetId->currentText();
|
||||||
|
case CQuest::Emission::MISSION_KEYMASTER:
|
||||||
|
return QString("N/A");
|
||||||
|
default:
|
||||||
|
return QString("N/A");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QuestDelegate::QuestDelegate(const CMap & m, CGSeerHut & t): map(m), seerhut(t), QStyledItemDelegate()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget * QuestDelegate::createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const
|
||||||
|
{
|
||||||
|
return new QuestWidget(map, seerhut, parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
void QuestDelegate::setEditorData(QWidget * editor, const QModelIndex & index) const
|
||||||
|
{
|
||||||
|
if(auto *ed = qobject_cast<QuestWidget *>(editor))
|
||||||
|
{
|
||||||
|
ed->obtainData();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QStyledItemDelegate::setEditorData(editor, index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void QuestDelegate::setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const
|
||||||
|
{
|
||||||
|
if(auto *ed = qobject_cast<QuestWidget *>(editor))
|
||||||
|
{
|
||||||
|
auto quest = ed->commitChanges();
|
||||||
|
model->setData(index, quest);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QStyledItemDelegate::setModelData(editor, model, index);
|
||||||
|
}
|
||||||
|
}
|
52
mapeditor/inspector/questwidget.h
Normal file
52
mapeditor/inspector/questwidget.h
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* questwidget.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 "../StdInc.h"
|
||||||
|
#include <QDialog>
|
||||||
|
#include "../lib/mapObjects/CQuest.h"
|
||||||
|
#include "../lib/mapping/CMap.h"
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class QuestWidget;
|
||||||
|
}
|
||||||
|
|
||||||
|
class QuestWidget : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit QuestWidget(const CMap &, CGSeerHut &, QWidget *parent = nullptr);
|
||||||
|
~QuestWidget();
|
||||||
|
|
||||||
|
void obtainData();
|
||||||
|
QString commitChanges();
|
||||||
|
|
||||||
|
private:
|
||||||
|
CGSeerHut & seerhut;
|
||||||
|
const CMap & map;
|
||||||
|
Ui::QuestWidget *ui;
|
||||||
|
};
|
||||||
|
|
||||||
|
class QuestDelegate : public QStyledItemDelegate
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
using QStyledItemDelegate::QStyledItemDelegate;
|
||||||
|
|
||||||
|
QuestDelegate(const CMap &, CGSeerHut &);
|
||||||
|
|
||||||
|
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:
|
||||||
|
CGSeerHut & seerhut;
|
||||||
|
const CMap & map;
|
||||||
|
};
|
50
mapeditor/inspector/questwidget.ui
Normal file
50
mapeditor/inspector/questwidget.ui
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>QuestWidget</class>
|
||||||
|
<widget class="QDialog" name="QuestWidget">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>429</width>
|
||||||
|
<height>89</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Mission goal</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="targetId">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="targetAmount">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>60</width>
|
||||||
|
<height>16777215</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="inputMethodHints">
|
||||||
|
<set>Qt::ImhDigitsOnly</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
@@ -395,9 +395,9 @@ void RewardsDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, c
|
|||||||
{
|
{
|
||||||
if(auto * ed = qobject_cast<RewardsWidget *>(editor))
|
if(auto * ed = qobject_cast<RewardsWidget *>(editor))
|
||||||
{
|
{
|
||||||
auto isArmed = ed->commitChanges();
|
auto hasReward = ed->commitChanges();
|
||||||
model->setData(index, "dummy");
|
model->setData(index, "dummy");
|
||||||
if(isArmed)
|
if(hasReward)
|
||||||
model->setData(index, "HAS REWARD");
|
model->setData(index, "HAS REWARD");
|
||||||
else
|
else
|
||||||
model->setData(index, "");
|
model->setData(index, "");
|
||||||
|
Reference in New Issue
Block a user