2023-09-07 20:19:31 +02:00
|
|
|
/*
|
|
|
|
* abstractsettings.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
|
|
|
|
*
|
|
|
|
*/
|
2023-09-09 11:03:19 +02:00
|
|
|
#pragma once
|
2023-09-05 01:26:38 +02:00
|
|
|
|
|
|
|
#include <QWidget>
|
|
|
|
#include "../../lib/mapping/CMap.h"
|
|
|
|
#include "../../lib/mapObjects/CGTownInstance.h"
|
|
|
|
#include "../../lib/mapObjects/CGHeroInstance.h"
|
|
|
|
|
|
|
|
//parses date for lose condition (1m 1w 1d)
|
|
|
|
int expiredDate(const QString & date);
|
|
|
|
QString expiredDate(int date);
|
|
|
|
int3 posFromJson(const JsonNode & json);
|
|
|
|
std::vector<JsonNode> linearJsonArray(const JsonNode & json);
|
|
|
|
|
|
|
|
class AbstractSettings : public QWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit AbstractSettings(QWidget *parent = nullptr);
|
|
|
|
virtual ~AbstractSettings() = default;
|
|
|
|
|
|
|
|
virtual void initialize(const CMap & map) = 0;
|
|
|
|
virtual void update(CMap & map) = 0;
|
|
|
|
|
2023-09-11 18:01:53 +02:00
|
|
|
static std::string getTownName(const CMap & map, int objectIdx);
|
|
|
|
static std::string getHeroName(const CMap & map, int objectIdx);
|
|
|
|
static std::string getMonsterName(const CMap & map, int objectIdx);
|
2023-09-05 01:26:38 +02:00
|
|
|
|
|
|
|
static JsonNode conditionToJson(const EventCondition & event);
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
std::vector<int> getObjectIndexes(const CMap & map) const
|
|
|
|
{
|
|
|
|
std::vector<int> result;
|
|
|
|
for(int i = 0; i < map.objects.size(); ++i)
|
|
|
|
{
|
|
|
|
if(auto obj = dynamic_cast<T*>(map.objects[i].get()))
|
|
|
|
result.push_back(i);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
int getObjectByPos(const CMap & map, const int3 & pos)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < map.objects.size(); ++i)
|
|
|
|
{
|
|
|
|
if(auto obj = dynamic_cast<T*>(map.objects[i].get()))
|
|
|
|
{
|
|
|
|
if(obj->pos == pos)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
|
|
|
};
|