1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +02:00

New terrain support - part 1 (#755)

Initial support of new terrains
This commit is contained in:
Nordsoft91
2022-06-20 17:39:50 +03:00
committed by Andrii Danylchenko
parent 205bb09880
commit aaa07e4d2e
103 changed files with 1066 additions and 1472 deletions

View File

@@ -42,6 +42,7 @@
#include "../../lib/CHeroHandler.h"
#include "../../lib/CModHandler.h"
#include "../../lib/CTownHandler.h"
#include "../../lib/Terrain.h"
#include "../../lib/filesystem/Filesystem.h"
#include "../../lib/JsonNode.h"
#include "../../lib/mapObjects/CGHeroInstance.h"
@@ -494,41 +495,30 @@ void CMinimapInstance::showAll(SDL_Surface * to)
}
}
std::map<int, std::pair<SDL_Color, SDL_Color> > CMinimap::loadColors(std::string from)
std::map<Terrain, std::pair<SDL_Color, SDL_Color> > CMinimap::loadColors()
{
std::map<int, std::pair<SDL_Color, SDL_Color> > ret;
std::map<Terrain, std::pair<SDL_Color, SDL_Color> > ret;
const JsonNode config(ResourceID(from, EResType::TEXT));
for(auto &m : config.Struct())
for(auto & terrain : Terrain::Manager::terrains())
{
auto index = boost::find(GameConstants::TERRAIN_NAMES, m.first);
if (index == std::end(GameConstants::TERRAIN_NAMES))
{
logGlobal->error("Error: unknown terrain in terrains.json: %s", m.first);
continue;
}
int terrainID = static_cast<int>(index - std::begin(GameConstants::TERRAIN_NAMES));
const JsonVector &unblockedVec = m.second["minimapUnblocked"].Vector();
auto & m = Terrain::Manager::getInfo(terrain);
SDL_Color normal =
{
ui8(unblockedVec[0].Float()),
ui8(unblockedVec[1].Float()),
ui8(unblockedVec[2].Float()),
ui8(m.minimapUnblocked[0]),
ui8(m.minimapUnblocked[1]),
ui8(m.minimapUnblocked[2]),
ui8(255)
};
const JsonVector &blockedVec = m.second["minimapBlocked"].Vector();
SDL_Color blocked =
{
ui8(blockedVec[0].Float()),
ui8(blockedVec[1].Float()),
ui8(blockedVec[2].Float()),
ui8(m.minimapBlocked[0]),
ui8(m.minimapBlocked[1]),
ui8(m.minimapBlocked[2]),
ui8(255)
};
ret.insert(std::make_pair(terrainID, std::make_pair(normal, blocked)));
ret[terrain] = std::make_pair(normal, blocked);
}
return ret;
}
@@ -536,7 +526,7 @@ std::map<int, std::pair<SDL_Color, SDL_Color> > CMinimap::loadColors(std::string
CMinimap::CMinimap(const Rect & position)
: CIntObject(LCLICK | RCLICK | HOVER | MOVE, position.topLeft()),
level(0),
colors(loadColors("config/terrains.json"))
colors(loadColors())
{
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
pos.w = position.w;

View File

@@ -30,6 +30,7 @@ struct InfoAboutTown;
class CHeroTooltip;
class CTownTooltip;
class CTextBox;
class Terrain;
/// Base UI Element for hero\town lists
class CList : public CIntObject
@@ -216,7 +217,7 @@ protected:
int level;
//to initialize colors
std::map<int, std::pair<SDL_Color, SDL_Color> > loadColors(std::string from);
std::map<Terrain, std::pair<SDL_Color, SDL_Color> > loadColors();
void clickLeft(tribool down, bool previousState) override;
void clickRight(tribool down, bool previousState) override;
@@ -227,7 +228,7 @@ protected:
public:
// terrainID -> (normal color, blocked color)
const std::map<int, std::pair<SDL_Color, SDL_Color> > colors;
const std::map<Terrain, std::pair<SDL_Color, SDL_Color> > colors;
CMinimap(const Rect & position);