2017-07-13 10:26:03 +02:00
|
|
|
/*
|
|
|
|
* Graphics.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
|
|
|
|
*
|
|
|
|
*/
|
2011-12-14 00:23:17 +03:00
|
|
|
#include "StdInc.h"
|
2008-06-13 11:16:51 +03:00
|
|
|
#include "Graphics.h"
|
2011-12-14 00:23:17 +03:00
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
#include <vcmi/Entity.h>
|
|
|
|
#include <vcmi/ArtifactService.h>
|
|
|
|
#include <vcmi/CreatureService.h>
|
|
|
|
#include <vcmi/FactionService.h>
|
|
|
|
#include <vcmi/HeroTypeService.h>
|
|
|
|
#include <vcmi/SkillService.h>
|
|
|
|
#include <vcmi/spells/Service.h>
|
|
|
|
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "../renderSDL/SDL_Extensions.h"
|
|
|
|
#include "../renderSDL/CBitmapFont.h"
|
|
|
|
#include "../renderSDL/CBitmapHanFont.h"
|
|
|
|
#include "../renderSDL/CTrueTypeFont.h"
|
|
|
|
#include "../render/CAnimation.h"
|
|
|
|
#include "../render/IImage.h"
|
|
|
|
|
2013-07-28 17:49:50 +03:00
|
|
|
#include "../lib/filesystem/Filesystem.h"
|
2013-07-08 23:55:22 +03:00
|
|
|
#include "../lib/filesystem/CBinaryReader.h"
|
2022-06-22 10:41:02 +02:00
|
|
|
#include "../lib/CModHandler.h"
|
2009-05-21 03:55:30 +03:00
|
|
|
#include "CGameInfo.h"
|
2009-05-09 19:18:27 +03:00
|
|
|
#include "../lib/VCMI_Lib.h"
|
2009-07-20 04:47:49 +03:00
|
|
|
#include "../CCallback.h"
|
2010-12-20 23:22:53 +02:00
|
|
|
#include "../lib/CGeneralTextHandler.h"
|
2011-05-10 01:20:47 +03:00
|
|
|
#include "../lib/CGameState.h"
|
2011-08-20 21:46:52 +03:00
|
|
|
#include "../lib/JsonNode.h"
|
2011-10-08 04:23:46 +03:00
|
|
|
#include "../lib/vcmi_endian.h"
|
2011-12-17 21:59:59 +03:00
|
|
|
#include "../lib/CStopWatch.h"
|
2014-06-16 19:27:26 +03:00
|
|
|
#include "../lib/mapObjects/CObjectClassesHandler.h"
|
2015-12-02 21:05:10 +02:00
|
|
|
#include "../lib/mapObjects/CObjectHandler.h"
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
#include "../lib/CHeroHandler.h"
|
2009-10-26 17:01:12 +02:00
|
|
|
|
2023-01-31 01:28:11 +02:00
|
|
|
#include <SDL_surface.h>
|
|
|
|
|
2013-06-26 14:18:27 +03:00
|
|
|
Graphics * graphics = nullptr;
|
2009-04-15 17:03:31 +03:00
|
|
|
|
2008-06-30 03:06:41 +03:00
|
|
|
void Graphics::loadPaletteAndColors()
|
|
|
|
{
|
2013-07-28 17:49:50 +03:00
|
|
|
auto textFile = CResourceHandler::get()->load(ResourceID("DATA/PLAYERS.PAL"))->readAll();
|
2012-08-01 15:02:54 +03:00
|
|
|
std::string pals((char*)textFile.first.get(), textFile.second);
|
|
|
|
|
2008-06-30 03:06:41 +03:00
|
|
|
playerColorPalette = new SDL_Color[256];
|
|
|
|
neutralColor = new SDL_Color;
|
2013-03-03 20:06:03 +03:00
|
|
|
playerColors = new SDL_Color[PlayerColor::PLAYER_LIMIT_I];
|
2008-06-30 03:06:41 +03:00
|
|
|
int startPoint = 24; //beginning byte; used to read
|
|
|
|
for(int i=0; i<256; ++i)
|
|
|
|
{
|
|
|
|
SDL_Color col;
|
|
|
|
col.r = pals[startPoint++];
|
|
|
|
col.g = pals[startPoint++];
|
|
|
|
col.b = pals[startPoint++];
|
2015-09-02 17:49:29 +02:00
|
|
|
col.a = SDL_ALPHA_OPAQUE;
|
2012-08-29 17:55:31 +03:00
|
|
|
startPoint++;
|
2008-06-30 03:06:41 +03:00
|
|
|
playerColorPalette[i] = col;
|
|
|
|
}
|
2009-06-30 18:36:12 +03:00
|
|
|
|
|
|
|
neutralColorPalette = new SDL_Color[32];
|
2013-07-08 23:55:22 +03:00
|
|
|
|
|
|
|
auto stream = CResourceHandler::get()->load(ResourceID("config/NEUTRAL.PAL"));
|
|
|
|
CBinaryReader reader(stream.get());
|
|
|
|
|
2009-06-30 18:36:12 +03:00
|
|
|
for(int i=0; i<32; ++i)
|
|
|
|
{
|
2013-07-08 23:55:22 +03:00
|
|
|
neutralColorPalette[i].r = reader.readUInt8();
|
|
|
|
neutralColorPalette[i].g = reader.readUInt8();
|
|
|
|
neutralColorPalette[i].b = reader.readUInt8();
|
2014-08-07 19:52:40 +03:00
|
|
|
reader.readUInt8(); // this is "flags" entry, not alpha
|
2015-09-02 17:49:29 +02:00
|
|
|
neutralColorPalette[i].a = SDL_ALPHA_OPAQUE;
|
2009-06-30 18:36:12 +03:00
|
|
|
}
|
2008-06-30 03:06:41 +03:00
|
|
|
//colors initialization
|
2016-10-16 01:47:03 +02:00
|
|
|
SDL_Color colors[] = {
|
|
|
|
{0xff,0, 0, SDL_ALPHA_OPAQUE},
|
2014-07-02 19:12:15 +03:00
|
|
|
{0x31,0x52,0xff,SDL_ALPHA_OPAQUE},
|
|
|
|
{0x9c,0x73,0x52,SDL_ALPHA_OPAQUE},
|
|
|
|
{0x42,0x94,0x29,SDL_ALPHA_OPAQUE},
|
2016-10-16 01:47:03 +02:00
|
|
|
|
2014-07-02 19:12:15 +03:00
|
|
|
{0xff,0x84,0, SDL_ALPHA_OPAQUE},
|
|
|
|
{0x8c,0x29,0xa5,SDL_ALPHA_OPAQUE},
|
|
|
|
{0x09,0x9c,0xa5,SDL_ALPHA_OPAQUE},
|
2016-10-16 01:47:03 +02:00
|
|
|
{0xc6,0x7b,0x8c,SDL_ALPHA_OPAQUE}};
|
|
|
|
|
2014-05-21 19:04:34 +03:00
|
|
|
for(int i=0;i<8;i++)
|
|
|
|
{
|
2014-07-02 19:12:15 +03:00
|
|
|
playerColors[i] = colors[i];
|
2014-05-21 19:04:34 +03:00
|
|
|
}
|
2015-09-02 17:49:29 +02:00
|
|
|
//gray
|
|
|
|
neutralColor->r = 0x84;
|
|
|
|
neutralColor->g = 0x84;
|
|
|
|
neutralColor->b = 0x84;
|
|
|
|
neutralColor->a = SDL_ALPHA_OPAQUE;
|
2008-12-23 15:59:03 +02:00
|
|
|
}
|
|
|
|
|
2008-07-02 11:39:56 +03:00
|
|
|
void Graphics::initializeBattleGraphics()
|
|
|
|
{
|
2022-06-22 10:41:02 +02:00
|
|
|
auto allConfigs = VLC->modh->getActiveMods();
|
2022-12-07 15:18:19 +02:00
|
|
|
allConfigs.insert(allConfigs.begin(), CModHandler::scopeBuiltin());
|
2022-06-22 10:41:02 +02:00
|
|
|
for(auto & mod : allConfigs)
|
|
|
|
{
|
|
|
|
if(!CResourceHandler::get(mod)->existsResource(ResourceID("config/battles_graphics.json")))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const JsonNode config(mod, ResourceID("config/battles_graphics.json"));
|
|
|
|
|
|
|
|
//initialization of AC->def name mapping
|
|
|
|
if(!config["ac_mapping"].isNull())
|
|
|
|
for(const JsonNode &ac : config["ac_mapping"].Vector())
|
|
|
|
{
|
|
|
|
int ACid = static_cast<int>(ac["id"].Float());
|
|
|
|
std::vector< std::string > toAdd;
|
2011-08-31 04:11:41 +03:00
|
|
|
|
2022-06-22 10:41:02 +02:00
|
|
|
for(const JsonNode &defname : ac["defnames"].Vector())
|
|
|
|
{
|
|
|
|
toAdd.push_back(defname.String());
|
|
|
|
}
|
2008-07-02 11:39:56 +03:00
|
|
|
|
2022-06-22 10:41:02 +02:00
|
|
|
battleACToDef[ACid] = toAdd;
|
2008-10-19 18:41:18 +03:00
|
|
|
}
|
2016-10-16 01:47:03 +02:00
|
|
|
}
|
2008-06-30 03:06:41 +03:00
|
|
|
}
|
2008-06-13 11:16:51 +03:00
|
|
|
Graphics::Graphics()
|
|
|
|
{
|
2014-05-21 21:43:44 +03:00
|
|
|
#if 0
|
2016-10-16 01:47:03 +02:00
|
|
|
|
2008-06-16 17:56:48 +03:00
|
|
|
std::vector<Task> tasks; //preparing list of graphics to load
|
2014-08-04 21:33:59 +03:00
|
|
|
tasks += std::bind(&Graphics::loadFonts,this);
|
|
|
|
tasks += std::bind(&Graphics::loadPaletteAndColors,this);
|
|
|
|
tasks += std::bind(&Graphics::initializeBattleGraphics,this);
|
|
|
|
tasks += std::bind(&Graphics::loadErmuToPicture,this);
|
|
|
|
tasks += std::bind(&Graphics::initializeImageLists,this);
|
2008-06-16 17:56:48 +03:00
|
|
|
|
2011-12-14 00:23:17 +03:00
|
|
|
CThreadHelper th(&tasks,std::max((ui32)1,boost::thread::hardware_concurrency()));
|
2008-06-16 17:56:48 +03:00
|
|
|
th.run();
|
2014-05-21 21:43:44 +03:00
|
|
|
#else
|
|
|
|
loadFonts();
|
|
|
|
loadPaletteAndColors();
|
|
|
|
initializeBattleGraphics();
|
|
|
|
loadErmuToPicture();
|
|
|
|
initializeImageLists();
|
|
|
|
#endif
|
2008-06-16 17:56:48 +03:00
|
|
|
|
2016-10-18 09:31:31 +02:00
|
|
|
//(!) do not load any CAnimation here
|
|
|
|
}
|
|
|
|
|
2016-11-25 14:45:09 +02:00
|
|
|
Graphics::~Graphics()
|
|
|
|
{
|
|
|
|
delete[] playerColors;
|
|
|
|
delete neutralColor;
|
|
|
|
delete[] playerColorPalette;
|
|
|
|
delete[] neutralColorPalette;
|
|
|
|
}
|
|
|
|
|
2016-10-18 09:31:31 +02:00
|
|
|
void Graphics::load()
|
|
|
|
{
|
|
|
|
heroMoveArrows = std::make_shared<CAnimation>("ADAG");
|
|
|
|
heroMoveArrows->preload();
|
|
|
|
|
2016-11-07 23:19:53 +02:00
|
|
|
loadHeroAnimations();
|
|
|
|
loadHeroFlagAnimations();
|
|
|
|
loadFogOfWar();
|
2008-06-16 17:56:48 +03:00
|
|
|
}
|
2010-08-16 12:54:09 +03:00
|
|
|
|
2016-11-07 23:19:53 +02:00
|
|
|
void Graphics::loadHeroAnimations()
|
2016-11-04 16:05:56 +02:00
|
|
|
{
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
for(auto & elem : CGI->heroh->classes.objects)
|
2016-11-04 16:05:56 +02:00
|
|
|
{
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
for (auto & templ : VLC->objtypeh->getHandlerFor(Obj::HERO, elem->getIndex())->getTemplates())
|
2016-11-04 16:05:56 +02:00
|
|
|
{
|
2022-09-11 15:12:35 +02:00
|
|
|
if (!heroAnimations.count(templ->animationFile))
|
|
|
|
heroAnimations[templ->animationFile] = loadHeroAnimation(templ->animationFile);
|
2016-11-04 16:05:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-07 23:19:53 +02:00
|
|
|
boatAnimations[0] = loadHeroAnimation("AB01_.DEF");
|
|
|
|
boatAnimations[1] = loadHeroAnimation("AB02_.DEF");
|
|
|
|
boatAnimations[2] = loadHeroAnimation("AB03_.DEF");
|
2016-11-04 16:05:56 +02:00
|
|
|
|
2016-11-07 23:19:53 +02:00
|
|
|
|
|
|
|
mapObjectAnimations["AB01_.DEF"] = boatAnimations[0];
|
|
|
|
mapObjectAnimations["AB02_.DEF"] = boatAnimations[1];
|
|
|
|
mapObjectAnimations["AB03_.DEF"] = boatAnimations[2];
|
|
|
|
}
|
|
|
|
void Graphics::loadHeroFlagAnimations()
|
2016-11-07 23:15:46 +02:00
|
|
|
{
|
2016-11-07 23:19:53 +02:00
|
|
|
static const std::vector<std::string> HERO_FLAG_ANIMATIONS =
|
2016-11-04 16:05:56 +02:00
|
|
|
{
|
2016-11-07 23:19:53 +02:00
|
|
|
"AF00", "AF01","AF02","AF03",
|
|
|
|
"AF04", "AF05","AF06","AF07"
|
|
|
|
};
|
|
|
|
|
|
|
|
static const std::vector< std::vector<std::string> > BOAT_FLAG_ANIMATIONS =
|
|
|
|
{
|
|
|
|
{
|
|
|
|
"ABF01L", "ABF01G", "ABF01R", "ABF01D",
|
|
|
|
"ABF01B", "ABF01P", "ABF01W", "ABF01K"
|
|
|
|
},
|
2016-11-04 16:05:56 +02:00
|
|
|
{
|
2016-11-07 23:19:53 +02:00
|
|
|
"ABF02L", "ABF02G", "ABF02R", "ABF02D",
|
|
|
|
"ABF02B", "ABF02P", "ABF02W", "ABF02K"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"ABF03L", "ABF03G", "ABF03R", "ABF03D",
|
|
|
|
"ABF03B", "ABF03P", "ABF03W", "ABF03K"
|
2016-11-04 16:05:56 +02:00
|
|
|
}
|
2016-11-07 23:19:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
for(const auto & name : HERO_FLAG_ANIMATIONS)
|
|
|
|
heroFlagAnimations.push_back(loadHeroFlagAnimation(name));
|
|
|
|
|
|
|
|
for(int i = 0; i < BOAT_FLAG_ANIMATIONS.size(); i++)
|
|
|
|
for(const auto & name : BOAT_FLAG_ANIMATIONS[i])
|
|
|
|
boatFlagAnimations[i].push_back(loadHeroFlagAnimation(name));
|
2016-11-04 16:05:56 +02:00
|
|
|
}
|
|
|
|
|
2016-11-07 23:19:53 +02:00
|
|
|
std::shared_ptr<CAnimation> Graphics::loadHeroFlagAnimation(const std::string & name)
|
2016-11-04 16:05:56 +02:00
|
|
|
{
|
2016-11-07 23:19:53 +02:00
|
|
|
//first - group number to be rotated, second - group number after rotation
|
|
|
|
static const std::vector<std::pair<int,int> > rotations =
|
2016-11-04 16:05:56 +02:00
|
|
|
{
|
2016-11-07 23:19:53 +02:00
|
|
|
{6,10}, {7,11}, {8,12}, {1,13},
|
|
|
|
{2,14}, {3,15}
|
2016-11-04 16:05:56 +02:00
|
|
|
};
|
|
|
|
|
2016-11-07 23:19:53 +02:00
|
|
|
std::shared_ptr<CAnimation> anim = std::make_shared<CAnimation>(name);
|
|
|
|
anim->preload();
|
|
|
|
|
|
|
|
for(const auto & rotation : rotations)
|
2016-11-04 16:05:56 +02:00
|
|
|
{
|
2017-09-05 19:04:17 +02:00
|
|
|
const int sourceGroup = rotation.first;
|
|
|
|
const int targetGroup = rotation.second;
|
2016-11-07 23:19:53 +02:00
|
|
|
|
2017-09-05 19:04:17 +02:00
|
|
|
anim->createFlippedGroup(sourceGroup, targetGroup);
|
2016-11-04 16:05:56 +02:00
|
|
|
}
|
2016-11-07 23:19:53 +02:00
|
|
|
|
|
|
|
return anim;
|
2016-11-04 16:05:56 +02:00
|
|
|
}
|
|
|
|
|
2016-11-07 23:19:53 +02:00
|
|
|
std::shared_ptr<CAnimation> Graphics::loadHeroAnimation(const std::string &name)
|
2016-11-04 16:05:56 +02:00
|
|
|
{
|
2016-11-07 23:19:53 +02:00
|
|
|
//first - group number to be rotated, second - group number after rotation
|
|
|
|
static const std::vector<std::pair<int,int> > rotations =
|
2016-11-04 16:05:56 +02:00
|
|
|
{
|
2016-11-07 23:19:53 +02:00
|
|
|
{6,10}, {7,11}, {8,12}, {1,13},
|
|
|
|
{2,14}, {3,15}
|
2016-11-07 23:15:46 +02:00
|
|
|
};
|
2016-11-04 16:05:56 +02:00
|
|
|
|
2016-11-07 23:19:53 +02:00
|
|
|
std::shared_ptr<CAnimation> anim = std::make_shared<CAnimation>(name);
|
|
|
|
anim->preload();
|
|
|
|
|
|
|
|
|
|
|
|
for(const auto & rotation : rotations)
|
2016-11-07 23:15:46 +02:00
|
|
|
{
|
2017-09-05 19:04:17 +02:00
|
|
|
const int sourceGroup = rotation.first;
|
|
|
|
const int targetGroup = rotation.second;
|
2016-11-07 23:19:53 +02:00
|
|
|
|
2017-09-05 19:04:17 +02:00
|
|
|
anim->createFlippedGroup(sourceGroup, targetGroup);
|
2016-11-07 23:15:46 +02:00
|
|
|
}
|
2016-11-07 23:19:53 +02:00
|
|
|
|
|
|
|
return anim;
|
2016-11-04 16:05:56 +02:00
|
|
|
}
|
|
|
|
|
2013-03-03 20:06:03 +03:00
|
|
|
void Graphics::blueToPlayersAdv(SDL_Surface * sur, PlayerColor player)
|
2008-06-30 03:06:41 +03:00
|
|
|
{
|
2013-09-08 16:02:34 +03:00
|
|
|
if(sur->format->palette)
|
2008-06-30 03:06:41 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
SDL_Color * palette = nullptr;
|
2013-03-03 20:06:03 +03:00
|
|
|
if(player < PlayerColor::PLAYER_LIMIT)
|
2009-06-30 18:36:12 +03:00
|
|
|
{
|
2013-03-03 20:06:03 +03:00
|
|
|
palette = playerColorPalette + 32*player.getNum();
|
2009-06-30 18:36:12 +03:00
|
|
|
}
|
2013-03-03 20:06:03 +03:00
|
|
|
else if(player == PlayerColor::NEUTRAL)
|
2009-06-30 18:36:12 +03:00
|
|
|
{
|
|
|
|
palette = neutralColorPalette;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-12 13:36:04 +02:00
|
|
|
logGlobal->error("Wrong player id in blueToPlayersAdv (%s)!", player.getStr());
|
2009-06-30 18:36:12 +03:00
|
|
|
return;
|
|
|
|
}
|
2018-04-07 13:34:11 +02:00
|
|
|
//FIXME: not all player colored images have player palette at last 32 indexes
|
|
|
|
//NOTE: following code is much more correct but still not perfect (bugged with status bar)
|
|
|
|
|
2023-01-17 22:01:35 +02:00
|
|
|
CSDL_Ext::setColors(sur, palette, 224, 32);
|
2018-04-07 13:34:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
|
|
|
SDL_Color * bluePalette = playerColorPalette + 32;
|
|
|
|
|
|
|
|
SDL_Palette * oldPalette = sur->format->palette;
|
|
|
|
|
|
|
|
SDL_Palette * newPalette = SDL_AllocPalette(256);
|
|
|
|
|
|
|
|
for(size_t destIndex = 0; destIndex < 256; destIndex++)
|
|
|
|
{
|
|
|
|
SDL_Color old = oldPalette->colors[destIndex];
|
|
|
|
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
for(size_t srcIndex = 0; srcIndex < 32; srcIndex++)
|
|
|
|
{
|
|
|
|
if(old.b == bluePalette[srcIndex].b && old.g == bluePalette[srcIndex].g && old.r == bluePalette[srcIndex].r)
|
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
newPalette->colors[destIndex] = palette[srcIndex];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!found)
|
|
|
|
newPalette->colors[destIndex] = old;
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_SetSurfacePalette(sur, newPalette);
|
|
|
|
|
|
|
|
SDL_FreePalette(newPalette);
|
|
|
|
|
|
|
|
#endif // 0
|
2008-06-30 03:06:41 +03:00
|
|
|
}
|
2013-09-08 16:02:34 +03:00
|
|
|
else
|
2008-06-30 03:06:41 +03:00
|
|
|
{
|
2013-09-08 16:02:34 +03:00
|
|
|
//TODO: implement. H3 method works only for images with palettes.
|
|
|
|
// Add some kind of player-colored overlay?
|
|
|
|
// Or keep palette approach here and replace only colors of specific value(s)
|
|
|
|
// Or just wait for OpenGL support?
|
2017-08-10 18:39:27 +02:00
|
|
|
logGlobal->warn("Image must have palette to be player-colored!");
|
2008-06-30 03:06:41 +03:00
|
|
|
}
|
2008-08-04 12:05:52 +03:00
|
|
|
}
|
2009-08-17 11:50:31 +03:00
|
|
|
|
2016-11-07 23:19:53 +02:00
|
|
|
void Graphics::loadFogOfWar()
|
|
|
|
{
|
|
|
|
fogOfWarFullHide = std::make_shared<CAnimation>("TSHRC");
|
|
|
|
fogOfWarFullHide->preload();
|
|
|
|
fogOfWarPartialHide = std::make_shared<CAnimation>("TSHRE");
|
|
|
|
fogOfWarPartialHide->preload();
|
|
|
|
|
|
|
|
static const int rotations [] = {22, 15, 2, 13, 12, 16, 28, 17, 20, 19, 7, 24, 26, 25, 30, 32, 27};
|
|
|
|
|
|
|
|
size_t size = fogOfWarPartialHide->size(0);//group size after next rotation
|
|
|
|
|
|
|
|
for(const int rotation : rotations)
|
|
|
|
{
|
|
|
|
fogOfWarPartialHide->duplicateImage(0, rotation, 0);
|
2018-03-30 13:02:04 +02:00
|
|
|
auto image = fogOfWarPartialHide->getImage(size, 0);
|
2016-11-07 23:19:53 +02:00
|
|
|
image->verticalFlip();
|
|
|
|
size++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-19 20:24:53 +03:00
|
|
|
void Graphics::loadFonts()
|
2009-08-17 11:50:31 +03:00
|
|
|
{
|
2012-12-19 20:24:53 +03:00
|
|
|
const JsonNode config(ResourceID("config/fonts.json"));
|
2010-11-05 22:48:54 +02:00
|
|
|
|
2012-12-19 20:24:53 +03:00
|
|
|
const JsonVector & bmpConf = config["bitmap"].Vector();
|
|
|
|
const JsonNode & ttfConf = config["trueType"];
|
2013-09-08 19:49:23 +03:00
|
|
|
const JsonNode & hanConf = config["bitmapHan"];
|
2010-11-05 22:48:54 +02:00
|
|
|
|
2012-12-19 20:24:53 +03:00
|
|
|
assert(bmpConf.size() == FONTS_NUMBER);
|
2009-08-17 11:50:31 +03:00
|
|
|
|
2012-12-19 20:24:53 +03:00
|
|
|
for (size_t i=0; i<FONTS_NUMBER; i++)
|
|
|
|
{
|
|
|
|
std::string filename = bmpConf[i].String();
|
2009-08-17 11:50:31 +03:00
|
|
|
|
2013-09-08 19:49:23 +03:00
|
|
|
if (!hanConf[filename].isNull())
|
2016-11-07 23:19:53 +02:00
|
|
|
fonts[i] = std::make_shared<CBitmapHanFont>(hanConf[filename]);
|
2013-09-08 19:49:23 +03:00
|
|
|
else if (!ttfConf[filename].isNull()) // no ttf override
|
2016-11-07 23:19:53 +02:00
|
|
|
fonts[i] = std::make_shared<CTrueTypeFont>(ttfConf[filename]);
|
2013-09-08 16:02:34 +03:00
|
|
|
else
|
2016-11-07 23:19:53 +02:00
|
|
|
fonts[i] = std::make_shared<CBitmapFont>(filename);
|
2012-12-19 20:24:53 +03:00
|
|
|
}
|
2009-08-17 11:50:31 +03:00
|
|
|
}
|
|
|
|
|
2016-11-07 23:19:53 +02:00
|
|
|
std::shared_ptr<CAnimation> Graphics::getAnimation(const CGObjectInstance* obj)
|
2016-11-04 16:05:56 +02:00
|
|
|
{
|
2016-11-07 23:19:53 +02:00
|
|
|
return getAnimation(obj->appearance);
|
2016-11-07 23:15:46 +02:00
|
|
|
}
|
2016-11-04 16:05:56 +02:00
|
|
|
|
2022-09-11 15:12:35 +02:00
|
|
|
std::shared_ptr<CAnimation> Graphics::getAnimation(std::shared_ptr<const ObjectTemplate> info)
|
2016-11-07 23:15:46 +02:00
|
|
|
{
|
2016-11-07 23:19:53 +02:00
|
|
|
//the only(?) invisible object
|
2022-09-11 15:12:35 +02:00
|
|
|
if(info->id == Obj::EVENT)
|
2016-11-07 23:19:53 +02:00
|
|
|
{
|
|
|
|
return std::shared_ptr<CAnimation>();
|
|
|
|
}
|
|
|
|
|
2022-09-11 15:12:35 +02:00
|
|
|
if(info->animationFile.empty())
|
2016-11-04 16:05:56 +02:00
|
|
|
{
|
2022-09-11 15:12:35 +02:00
|
|
|
logGlobal->warn("Def name for obj (%d,%d) is empty!", info->id, info->subid);
|
2016-11-07 23:19:53 +02:00
|
|
|
return std::shared_ptr<CAnimation>();
|
2016-11-04 16:05:56 +02:00
|
|
|
}
|
2016-11-07 23:19:53 +02:00
|
|
|
|
2022-09-11 15:12:35 +02:00
|
|
|
std::shared_ptr<CAnimation> ret = mapObjectAnimations[info->animationFile];
|
2016-11-07 23:19:53 +02:00
|
|
|
|
|
|
|
//already loaded
|
|
|
|
if(ret)
|
|
|
|
{
|
|
|
|
ret->preload();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-09-11 15:12:35 +02:00
|
|
|
ret = std::make_shared<CAnimation>(info->animationFile);
|
|
|
|
mapObjectAnimations[info->animationFile] = ret;
|
2016-11-07 23:19:53 +02:00
|
|
|
|
|
|
|
ret->preload();
|
|
|
|
return ret;
|
2016-11-04 16:05:56 +02:00
|
|
|
}
|
|
|
|
|
2010-12-20 23:22:53 +02:00
|
|
|
void Graphics::loadErmuToPicture()
|
|
|
|
{
|
|
|
|
//loading ERMU to picture
|
2012-08-02 14:03:26 +03:00
|
|
|
const JsonNode config(ResourceID("config/ERMU_to_picture.json"));
|
2011-09-01 02:27:33 +03:00
|
|
|
int etp_idx = 0;
|
2013-06-29 16:05:48 +03:00
|
|
|
for(const JsonNode &etp : config["ERMU_to_picture"].Vector()) {
|
2011-09-01 02:27:33 +03:00
|
|
|
int idx = 0;
|
2013-06-29 16:05:48 +03:00
|
|
|
for(const JsonNode &n : etp.Vector()) {
|
2011-09-01 02:27:33 +03:00
|
|
|
ERMUtoPicture[idx][etp_idx] = n.String();
|
|
|
|
idx ++;
|
2010-12-20 23:22:53 +02:00
|
|
|
}
|
2011-09-01 02:27:33 +03:00
|
|
|
assert (idx == ARRAY_COUNT(ERMUtoPicture));
|
2010-12-20 23:22:53 +02:00
|
|
|
|
2011-09-01 02:27:33 +03:00
|
|
|
etp_idx ++;
|
|
|
|
}
|
|
|
|
assert (etp_idx == 44);
|
2010-12-20 23:22:53 +02:00
|
|
|
}
|
2013-04-22 22:51:22 +03:00
|
|
|
|
2022-11-29 14:47:51 +02:00
|
|
|
void Graphics::addImageListEntry(size_t index, size_t group, const std::string & listName, const std::string & imageName)
|
2013-04-22 22:51:22 +03:00
|
|
|
{
|
|
|
|
if (!imageName.empty())
|
|
|
|
{
|
|
|
|
JsonNode entry;
|
2022-11-29 14:47:51 +02:00
|
|
|
if (group != 0)
|
|
|
|
entry["group"].Integer() = group;
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
entry["frame"].Integer() = index;
|
2013-04-22 22:51:22 +03:00
|
|
|
entry["file"].String() = imageName;
|
|
|
|
|
|
|
|
imageLists["SPRITES/" + listName]["images"].Vector().push_back(entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
void Graphics::addImageListEntries(const EntityService * service)
|
2013-04-22 22:51:22 +03:00
|
|
|
{
|
2022-11-29 14:47:51 +02:00
|
|
|
auto cb = std::bind(&Graphics::addImageListEntry, this, _1, _2, _3, _4);
|
2013-04-22 22:51:22 +03:00
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
auto loopCb = [&](const Entity * entity, bool & stop)
|
2013-04-22 22:51:22 +03:00
|
|
|
{
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
entity->registerIcons(cb);
|
|
|
|
};
|
2016-10-16 01:47:03 +02:00
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
service->forEachBase(loopCb);
|
|
|
|
}
|
2018-03-31 07:56:40 +02:00
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
void Graphics::initializeImageLists()
|
|
|
|
{
|
|
|
|
addImageListEntries(CGI->creatures());
|
|
|
|
addImageListEntries(CGI->heroTypes());
|
|
|
|
addImageListEntries(CGI->artifacts());
|
|
|
|
addImageListEntries(CGI->factions());
|
|
|
|
addImageListEntries(CGI->spells());
|
|
|
|
addImageListEntries(CGI->skills());
|
2013-04-22 22:51:22 +03:00
|
|
|
}
|