1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00
vcmi/mapeditor/mapsettings/abstractsettings.h

73 lines
1.7 KiB
C++
Raw Normal View History

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"
Q_DECLARE_METATYPE(int3)
2023-09-05 01:26:38 +02:00
//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 MapController;
2023-09-05 01:26:38 +02:00
class AbstractSettings : public QWidget
{
Q_OBJECT
public:
explicit AbstractSettings(QWidget *parent = nullptr);
virtual ~AbstractSettings() = default;
virtual void initialize(MapController & controller);
virtual void update() = 0;
2023-09-05 01:26:38 +02:00
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>
static std::vector<int> getObjectIndexes(const CMap & map)
2023-09-05 01:26:38 +02:00
{
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>
static int getObjectByPos(const CMap & map, const int3 & pos)
2023-09-05 01:26:38 +02:00
{
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;
}
protected:
MapController * controller = nullptr;
2023-09-05 01:26:38 +02:00
};