1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

Code review changes

This commit is contained in:
nordsoft
2022-09-25 00:55:05 +04:00
parent 700e957cdb
commit bc84ffe8d6
25 changed files with 143 additions and 220 deletions

View File

@@ -1,5 +1,5 @@
/* /*
* CAnimation.cpp, part of VCMI engine * Animation.cpp, part of VCMI engine
* *
* Authors: listed in file AUTHORS in main folder * Authors: listed in file AUTHORS in main folder
* *
@@ -19,8 +19,6 @@
typedef std::map<size_t, std::vector<JsonNode>> source_map; typedef std::map<size_t, std::vector<JsonNode>> source_map;
//typedef std::map<size_t, IImage*> image_map;
//typedef std::map<size_t, image_map > group_map;
/// Class for def loading /// Class for def loading
/// After loading will store general info (palette and frame offsets) and pointer to file itself /// After loading will store general info (palette and frame offsets) and pointer to file itself
@@ -102,11 +100,11 @@ public:
{ {
for(auto & file : cache) for(auto & file : cache)
{ {
if (file.name == rid) if(file.name == rid)
return file.getCopy(); return file.getCopy();
} }
// Still here? Cache miss // Still here? Cache miss
if (cache.size() > cacheSize) if(cache.size() > cacheSize)
cache.pop_front(); cache.pop_front();
auto data = CResourceHandler::get()->load(rid)->readAll(); auto data = CResourceHandler::get()->load(rid)->readAll();
@@ -173,12 +171,12 @@ DefFile::DefFile(std::string Name):
int it = 0; int it = 0;
ui32 type = read_le_u32(data.get() + it); ui32 type = read_le_u32(data.get() + it);
it+=4; it += 4;
//int width = read_le_u32(data + it); it+=4;//not used //int width = read_le_u32(data + it); it+=4;//not used
//int height = read_le_u32(data + it); it+=4; //int height = read_le_u32(data + it); it+=4;
it+=8; it += 8;
ui32 totalBlocks = read_le_u32(data.get() + it); ui32 totalBlocks = read_le_u32(data.get() + it);
it+=4; it += 4;
for (ui32 i= 0; i<256; i++) for (ui32 i= 0; i<256; i++)
{ {
@@ -467,7 +465,7 @@ inline void ImageLoader::Load(size_t size, const ui8 * data)
inline void ImageLoader::Load(size_t size, ui8 color) inline void ImageLoader::Load(size_t size, ui8 color)
{ {
if (size) if(size)
{ {
memset((void *)position, color, size); memset((void *)position, color, size);
position += size; position += size;
@@ -482,9 +480,6 @@ inline void ImageLoader::EndLine()
ImageLoader::~ImageLoader() ImageLoader::~ImageLoader()
{ {
//SDL_UnlockSurface(image->surf);
//SDL_SetColorKey(image->surf, SDL_TRUE, 0);
//TODO: RLE if compressed and bpp>1
} }
/************************************************************************* /*************************************************************************
@@ -494,14 +489,14 @@ ImageLoader::~ImageLoader()
std::shared_ptr<QImage> Animation::getFromExtraDef(std::string filename) std::shared_ptr<QImage> Animation::getFromExtraDef(std::string filename)
{ {
size_t pos = filename.find(':'); size_t pos = filename.find(':');
if (pos == -1) if(pos == -1)
return nullptr; return nullptr;
Animation anim(filename.substr(0, pos)); Animation anim(filename.substr(0, pos));
pos++; pos++;
size_t frame = atoi(filename.c_str()+pos); size_t frame = atoi(filename.c_str()+pos);
size_t group = 0; size_t group = 0;
pos = filename.find(':', pos); pos = filename.find(':', pos);
if (pos != -1) if(pos != -1)
{ {
pos++; pos++;
group = frame; group = frame;
@@ -548,12 +543,7 @@ bool Animation::loadFrame(size_t frame, size_t group)
} }
else //load from separate file else //load from separate file
{ {
auto img = getFromExtraDef(source[group][frame]["file"].String()); images[group][frame] = getFromExtraDef(source[group][frame]["file"].String());;
//if(!img)
//img = std::make_shared<QImage>(source[group][frame]);
images[group][frame] = img;
return true; return true;
} }
return false; return false;
@@ -583,6 +573,7 @@ void Animation::init()
source[defEntry.first].resize(defEntry.second); source[defEntry.first].resize(defEntry.second);
} }
#if 0 //this code is not used but maybe requred if there will be configurable sprites
ResourceID resID(std::string("SPRITES/") + name, EResType::TEXT); ResourceID resID(std::string("SPRITES/") + name, EResType::TEXT);
//if(vstd::contains(graphics->imageLists, resID.getName())) //if(vstd::contains(graphics->imageLists, resID.getName()))
@@ -600,6 +591,7 @@ void Animation::init()
//initFromJson(config); //initFromJson(config);
} }
#endif
} }
void Animation::printError(size_t frame, size_t group, std::string type) const void Animation::printError(size_t frame, size_t group, std::string type) const
@@ -613,7 +605,7 @@ Animation::Animation(std::string Name):
defFile() defFile()
{ {
size_t dotPos = name.find_last_of('.'); size_t dotPos = name.find_last_of('.');
if ( dotPos!=-1 ) if( dotPos!=-1 )
name.erase(dotPos); name.erase(dotPos);
std::transform(name.begin(), name.end(), name.begin(), toupper); std::transform(name.begin(), name.end(), name.begin(), toupper);
@@ -671,7 +663,7 @@ void Animation::duplicateImage(const size_t sourceGroup, const size_t sourceFram
void Animation::setCustom(std::string filename, size_t frame, size_t group) void Animation::setCustom(std::string filename, size_t frame, size_t group)
{ {
if (source[group].size() <= frame) if(source[group].size() <= frame)
source[group].resize(frame+1); source[group].resize(frame+1);
source[group][frame]["file"].String() = filename; source[group][frame]["file"].String() = filename;
//FIXME: update image if already loaded //FIXME: update image if already loaded
@@ -680,13 +672,13 @@ void Animation::setCustom(std::string filename, size_t frame, size_t group)
std::shared_ptr<QImage> Animation::getImage(size_t frame, size_t group, bool verbose) const std::shared_ptr<QImage> Animation::getImage(size_t frame, size_t group, bool verbose) const
{ {
auto groupIter = images.find(group); auto groupIter = images.find(group);
if (groupIter != images.end()) if(groupIter != images.end())
{ {
auto imageIter = groupIter->second.find(frame); auto imageIter = groupIter->second.find(frame);
if (imageIter != groupIter->second.end()) if(imageIter != groupIter->second.end())
return imageIter->second; return imageIter->second;
} }
if (verbose) if(verbose)
printError(frame, group, "GetImage"); printError(frame, group, "GetImage");
return nullptr; return nullptr;
} }
@@ -717,14 +709,14 @@ void Animation::preload()
void Animation::loadGroup(size_t group) void Animation::loadGroup(size_t group)
{ {
if (vstd::contains(source, group)) if(vstd::contains(source, group))
for (size_t image=0; image < source[group].size(); image++) for (size_t image=0; image < source[group].size(); image++)
loadFrame(image, group); loadFrame(image, group);
} }
void Animation::unloadGroup(size_t group) void Animation::unloadGroup(size_t group)
{ {
if (vstd::contains(source, group)) if(vstd::contains(source, group))
for (size_t image=0; image < source[group].size(); image++) for (size_t image=0; image < source[group].size(); image++)
unloadFrame(image, group); unloadFrame(image, group);
} }
@@ -742,7 +734,7 @@ void Animation::unload(size_t frame, size_t group)
size_t Animation::size(size_t group) const size_t Animation::size(size_t group) const
{ {
auto iter = source.find(group); auto iter = source.find(group);
if (iter != source.end()) if(iter != source.end())
return iter->second.size(); return iter->second.size();
return 0; return 0;
} }
@@ -763,9 +755,11 @@ void Animation::verticalFlip()
void Animation::playerColored(PlayerColor player) void Animation::playerColored(PlayerColor player)
{ {
//for(auto & group : images) #if 0 //can be required in image preview?
//for(auto & image : group.second) for(auto & group : images)
//image.second->playerColored(player); for(auto & image : group.second)
image.second->playerColored(player);
#endif
} }
void Animation::createFlippedGroup(const size_t sourceGroup, const size_t targetGroup) void Animation::createFlippedGroup(const size_t sourceGroup, const size_t targetGroup)

View File

@@ -1,5 +1,13 @@
#ifndef ANIMATION_H /*
#define ANIMATION_H * Animation.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 "../lib/JsonNode.h" #include "../lib/JsonNode.h"
#include "../lib/GameConstants.h" #include "../lib/GameConstants.h"
@@ -57,12 +65,12 @@ public:
// adjust the color of the animation, used in battle spell effects, e.g. Cloned objects // adjust the color of the animation, used in battle spell effects, e.g. Cloned objects
//add custom surface to the selected position. //add custom surface to the selected position.
void setCustom(std::string filename, size_t frame, size_t group=0); void setCustom(std::string filename, size_t frame, size_t group = 0);
std::shared_ptr<QImage> getImage(size_t frame, size_t group=0, bool verbose=true) const; std::shared_ptr<QImage> getImage(size_t frame, size_t group = 0, bool verbose = true) const;
//all available frames //all available frames
void load (); void load();
void unload(); void unload();
void preload(); void preload();
@@ -71,11 +79,11 @@ public:
void unloadGroup(size_t group); void unloadGroup(size_t group);
//single image //single image
void load (size_t frame, size_t group=0); void load (size_t frame, size_t group = 0);
void unload(size_t frame, size_t group=0); void unload(size_t frame, size_t group = 0);
//total count of frames in group (including not loaded) //total count of frames in group (including not loaded)
size_t size(size_t group=0) const; size_t size(size_t group = 0) const;
void horizontalFlip(); void horizontalFlip();
void verticalFlip(); void verticalFlip();
@@ -83,5 +91,3 @@ public:
void createFlippedGroup(const size_t sourceGroup, const size_t targetGroup); void createFlippedGroup(const size_t sourceGroup, const size_t targetGroup);
}; };
#endif // ANIMATION_H

View File

@@ -1,9 +1,12 @@
// /*
// BitmapHandler.cpp * BitmapHandler.cpp, part of VCMI engine
// vcmieditor *
// * Authors: listed in file AUTHORS in main folder
// Created by nordsoft on 29.08.2022. *
// * 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 "StdInc.h"
#include "BitmapHandler.h" #include "BitmapHandler.h"
@@ -17,14 +20,14 @@ namespace BitmapHandler
{ {
QImage loadH3PCX(ui8 * data, size_t size); QImage loadH3PCX(ui8 * data, size_t size);
QImage loadBitmapFromDir(std::string path, std::string fname, bool setKey=true); QImage loadBitmapFromDir(const std::string & path, const std::string & fname, bool setKey=true);
bool isPCX(const ui8 *header)//check whether file can be PCX according to header bool isPCX(const ui8 * header)//check whether file can be PCX according to header
{ {
ui32 fSize = read_le_u32(header + 0); ui32 fSize = read_le_u32(header + 0);
ui32 width = read_le_u32(header + 4); ui32 width = read_le_u32(header + 4);
ui32 height = read_le_u32(header + 8); ui32 height = read_le_u32(header + 8);
return fSize == width*height || fSize == width*height*3; return fSize == width * height || fSize == width * height * 3;
} }
enum Epcxformat enum Epcxformat
@@ -38,22 +41,22 @@ namespace BitmapHandler
//SDL_Surface * ret; //SDL_Surface * ret;
Epcxformat format; Epcxformat format;
int it=0; int it = 0;
ui32 fSize = read_le_u32(pcx + it); it+=4; ui32 fSize = read_le_u32(pcx + it); it += 4;
ui32 width = read_le_u32(pcx + it); it+=4; ui32 width = read_le_u32(pcx + it); it += 4;
ui32 height = read_le_u32(pcx + it); it+=4; ui32 height = read_le_u32(pcx + it); it += 4;
if (fSize==width*height*3) if(fSize==width*height*3)
format=PCX24B; format=PCX24B;
else if (fSize==width*height) else if(fSize==width*height)
format=PCX8B; format=PCX8B;
else else
return QImage(); return QImage();
QSize qsize(width, height); QSize qsize(width, height);
if (format==PCX8B) if(format==PCX8B)
{ {
it = 0xC; it = 0xC;
//auto bitmap = QBitmap::fromData(qsize, pcx + it); //auto bitmap = QBitmap::fromData(qsize, pcx + it);
@@ -61,8 +64,8 @@ namespace BitmapHandler
//palette - last 256*3 bytes //palette - last 256*3 bytes
QVector<QRgb> colorTable; QVector<QRgb> colorTable;
it = (int)size-256*3; it = (int)size - 256 * 3;
for (int i=0;i<256;i++) for(int i = 0; i < 256; i++)
{ {
char bytes[3]; char bytes[3];
bytes[0] = pcx[it++]; bytes[0] = pcx[it++];
@@ -80,14 +83,14 @@ namespace BitmapHandler
} }
} }
QImage loadBitmapFromDir(std::string path, std::string fname, bool setKey) QImage loadBitmapFromDir(const std::string & path, const std::string & fname, bool setKey)
{ {
if(!fname.size()) if(!fname.size())
{ {
logGlobal->warn("Call to loadBitmap with void fname!"); logGlobal->warn("Call to loadBitmap with void fname!");
return QImage(); return QImage();
} }
if (!CResourceHandler::get()->existsResource(ResourceID(path + fname, EResType::IMAGE))) if(!CResourceHandler::get()->existsResource(ResourceID(path + fname, EResType::IMAGE)))
{ {
return QImage(); return QImage();
} }
@@ -95,7 +98,7 @@ namespace BitmapHandler
auto fullpath = CResourceHandler::get()->getResourceName(ResourceID(path + fname, EResType::IMAGE)); auto fullpath = CResourceHandler::get()->getResourceName(ResourceID(path + fname, EResType::IMAGE));
auto readFile = CResourceHandler::get()->load(ResourceID(path + fname, EResType::IMAGE))->readAll(); auto readFile = CResourceHandler::get()->load(ResourceID(path + fname, EResType::IMAGE))->readAll();
if (isPCX(readFile.first.get())) if(isPCX(readFile.first.get()))
{//H3-style PCX {//H3-style PCX
auto image = BitmapHandler::loadH3PCX(readFile.first.get(), readFile.second); auto image = BitmapHandler::loadH3PCX(readFile.first.get(), readFile.second);
if(!image.isNull()) if(!image.isNull())
@@ -134,26 +137,13 @@ namespace BitmapHandler
} }
} }
return QImage(); return QImage();
// When modifying anything here please check two use cases: // When modifying anything here please check use cases:
// 1) Vampire mansion in Necropolis (not 1st color is transparent) // 1) Vampire mansion in Necropolis (not 1st color is transparent)
// 2) Battle background when fighting on grass/dirt, topmost sky part (NO transparent color) // 2) Battle background when fighting on grass/dirt, topmost sky part (NO transparent color)
// 3) New objects that may use 24-bit images for icons (e.g. witchking arts) // 3) New objects that may use 24-bit images for icons (e.g. witchking arts)
/*if (ret->format->palette)
{
CSDL_Ext::setDefaultColorKeyPresize(ret);
}
else if (ret->format->Amask)
{
SDL_SetSurfaceBlendMode(ret, SDL_BLENDMODE_BLEND);
}
else // always set
{
CSDL_Ext::setDefaultColorKey(ret);
}
return ret;*/
} }
QImage loadBitmap(std::string fname, bool setKey) QImage loadBitmap(const std::string & fname, bool setKey)
{ {
QImage image = loadBitmapFromDir("DATA/", fname, setKey); QImage image = loadBitmapFromDir("DATA/", fname, setKey);
if(image.isNull()) if(image.isNull())

View File

@@ -1,10 +1,12 @@
// /*
// BitmapHandler.hpp * BitmapHandler.h, part of VCMI engine
// vcmieditor *
// * Authors: listed in file AUTHORS in main folder
// Created by nordsoft on 29.08.2022. *
// * License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once #pragma once
#define read_le_u16(p) (* reinterpret_cast<const ui16 *>(p)) #define read_le_u16(p) (* reinterpret_cast<const ui16 *>(p))
@@ -15,6 +17,6 @@
namespace BitmapHandler namespace BitmapHandler
{ {
//Load file from /DATA or /SPRITES //Load file from /DATA or /SPRITES
QImage loadBitmap(std::string fname, bool setKey=true); QImage loadBitmap(const std::string & fname, bool setKey = true);
} }

View File

@@ -4,16 +4,13 @@ set(editor_SRCS
launcherdirs.cpp launcherdirs.cpp
jsonutils.cpp jsonutils.cpp
mainwindow.cpp mainwindow.cpp
CGameInfo.cpp
BitmapHandler.cpp BitmapHandler.cpp
maphandler.cpp maphandler.cpp
Animation.cpp Animation.cpp
graphics.cpp graphics.cpp
spoiler.cpp
windownewmap.cpp windownewmap.cpp
generatorprogress.cpp generatorprogress.cpp
mapview.cpp mapview.cpp
radiopushbutton.cpp
objectbrowser.cpp objectbrowser.cpp
mapsettings.cpp mapsettings.cpp
playersettings.cpp playersettings.cpp
@@ -33,16 +30,13 @@ set(editor_HEADERS
launcherdirs.h launcherdirs.h
jsonutils.h jsonutils.h
mainwindow.h mainwindow.h
CGameInfo.h
BitmapHandler.h BitmapHandler.h
maphandler.h maphandler.h
Animation.h Animation.h
graphics.h graphics.h
spoiler.h
windownewmap.h windownewmap.h
generatorprogress.h generatorprogress.h
mapview.h mapview.h
radiopushbutton.h
objectbrowser.h objectbrowser.h
mapsettings.h mapsettings.h
playersettings.h playersettings.h

View File

@@ -1,3 +1,12 @@
/*
* generatorprogress.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 "StdInc.h"
#include "generatorprogress.h" #include "generatorprogress.h"
#include "ui_generatorprogress.h" #include "ui_generatorprogress.h"

View File

@@ -1,5 +1,13 @@
#ifndef GENERATORPROGRESS_H /*
#define GENERATORPROGRESS_H * generatorprogress.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 <QDialog> #include <QDialog>
#include "../lib/LoadProgress.h" #include "../lib/LoadProgress.h"
@@ -22,5 +30,3 @@ private:
Ui::GeneratorProgress *ui; Ui::GeneratorProgress *ui;
Load::Progress & source; Load::Progress & source;
}; };
#endif // GENERATORPROGRESS_H

View File

@@ -33,7 +33,6 @@
#include "../lib/mapObjects/CObjectClassesHandler.h" #include "../lib/mapObjects/CObjectClassesHandler.h"
#include "../lib/mapObjects/CObjectHandler.h" #include "../lib/mapObjects/CObjectHandler.h"
#include "../lib/CHeroHandler.h" #include "../lib/CHeroHandler.h"
#include "CGameInfo.h"
Graphics * graphics = nullptr; Graphics * graphics = nullptr;
@@ -45,7 +44,7 @@ void Graphics::loadPaletteAndColors()
playerColorPalette.resize(256); playerColorPalette.resize(256);
playerColors.resize(PlayerColor::PLAYER_LIMIT_I); playerColors.resize(PlayerColor::PLAYER_LIMIT_I);
int startPoint = 24; //beginning byte; used to read int startPoint = 24; //beginning byte; used to read
for(int i=0; i<256; ++i) for(int i = 0; i < 256; ++i)
{ {
QColor col; QColor col;
col.setRed(pals[startPoint++]); col.setRed(pals[startPoint++]);
@@ -61,7 +60,7 @@ void Graphics::loadPaletteAndColors()
auto stream = CResourceHandler::get()->load(ResourceID("config/NEUTRAL.PAL")); auto stream = CResourceHandler::get()->load(ResourceID("config/NEUTRAL.PAL"));
CBinaryReader reader(stream.get()); CBinaryReader reader(stream.get());
for(int i=0; i<32; ++i) for(int i = 0; i < 32; ++i)
{ {
QColor col; QColor col;
col.setRed(reader.readUInt8()); col.setRed(reader.readUInt8());
@@ -95,7 +94,6 @@ void Graphics::loadPaletteAndColors()
Graphics::Graphics() Graphics::Graphics()
{ {
#if 0 #if 0
std::vector<Task> tasks; //preparing list of graphics to load std::vector<Task> tasks; //preparing list of graphics to load
tasks += std::bind(&Graphics::loadFonts,this); tasks += std::bind(&Graphics::loadFonts,this);
tasks += std::bind(&Graphics::loadPaletteAndColors,this); tasks += std::bind(&Graphics::loadPaletteAndColors,this);
@@ -125,11 +123,11 @@ void Graphics::load()
void Graphics::loadHeroAnimations() void Graphics::loadHeroAnimations()
{ {
for(auto & elem : CGI->heroh->classes.objects) for(auto & elem : VLC->heroh->classes.objects)
{ {
for (auto templ : VLC->objtypeh->getHandlerFor(Obj::HERO, elem->getIndex())->getTemplates()) for(auto templ : VLC->objtypeh->getHandlerFor(Obj::HERO, elem->getIndex())->getTemplates())
{ {
if (!heroAnimations.count(templ->animationFile)) if(!heroAnimations.count(templ->animationFile))
heroAnimations[templ->animationFile] = loadHeroAnimation(templ->animationFile); heroAnimations[templ->animationFile] = loadHeroAnimation(templ->animationFile);
} }
} }
@@ -244,39 +242,6 @@ void Graphics::blueToPlayersAdv(QImage * sur, PlayerColor player)
//FIXME: not all player colored images have player palette at last 32 indexes //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) //NOTE: following code is much more correct but still not perfect (bugged with status bar)
sur->setColorTable(palette); sur->setColorTable(palette);
#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
} }
else else
{ {
@@ -369,10 +334,10 @@ void Graphics::addImageListEntries(const EntityService * service)
void Graphics::initializeImageLists() void Graphics::initializeImageLists()
{ {
addImageListEntries(CGI->creatures()); addImageListEntries(VLC->creatures());
addImageListEntries(CGI->heroTypes()); addImageListEntries(VLC->heroTypes());
addImageListEntries(CGI->artifacts()); addImageListEntries(VLC->artifacts());
addImageListEntries(CGI->factions()); addImageListEntries(VLC->factions());
addImageListEntries(CGI->spells()); addImageListEntries(VLC->spells());
addImageListEntries(CGI->skills()); addImageListEntries(VLC->skills());
} }

View File

@@ -20,7 +20,6 @@ ArmyWidget::ArmyWidget(CArmedInstance & a, QWidget *parent) :
for(int i = 0; i < TOTAL_SLOTS; ++i) for(int i = 0; i < TOTAL_SLOTS; ++i)
{ {
uiCounts[i]->setInputMask("d0000");
uiCounts[i]->setText("1"); uiCounts[i]->setText("1");
uiSlots[i]->addItem(""); uiSlots[i]->addItem("");
uiSlots[i]->setItemData(0, -1); uiSlots[i]->setItemData(0, -1);

View File

@@ -100,6 +100,9 @@ void Initializer::initialize(CGHeroInstance * o)
if(!o) return; if(!o) return;
o->tempOwner = defaultPlayer; o->tempOwner = defaultPlayer;
if(o->ID == Obj::PRISON)
o->tempOwner = PlayerColor::NEUTRAL;
if(o->ID == Obj::HERO) if(o->ID == Obj::HERO)
{ {
for(auto t : VLC->heroh->objects) for(auto t : VLC->heroh->objects)
@@ -437,13 +440,13 @@ void Inspector::setProperty(CGEvent * o, const QString & key, const QVariant & v
{ {
if(!o) return; if(!o) return;
if("Remove after") if(key == "Remove after")
o->removeAfterVisit = stringToBool(value.toString()); o->removeAfterVisit = stringToBool(value.toString());
if("Human trigger") if(key == "Human trigger")
o->humanActivate = stringToBool(value.toString()); o->humanActivate = stringToBool(value.toString());
if("Cpu trigger") if(key == "Cpu trigger")
o->computerActivate = stringToBool(value.toString()); o->computerActivate = stringToBool(value.toString());
} }

View File

@@ -1,3 +1,13 @@
/*
* mainwindow.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 "StdInc.h"
#include "mainwindow.h" #include "mainwindow.h"
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
@@ -20,8 +30,6 @@
#include "../lib/mapObjects/CObjectClassesHandler.h" #include "../lib/mapObjects/CObjectClassesHandler.h"
#include "../lib/filesystem/CFilesystemLoader.h" #include "../lib/filesystem/CFilesystemLoader.h"
#include "CGameInfo.h"
#include "maphandler.h" #include "maphandler.h"
#include "graphics.h" #include "graphics.h"
#include "windownewmap.h" #include "windownewmap.h"
@@ -52,9 +60,7 @@ QPixmap pixmapFromJson(const QJsonValue &val)
void init() void init()
{ {
loadDLLClasses(); loadDLLClasses();
const_cast<CGameInfo*>(CGI)->setFromLib();
logGlobal->info("Initializing VCMI_Lib"); logGlobal->info("Initializing VCMI_Lib");
} }
@@ -129,7 +135,6 @@ MainWindow::MainWindow(QWidget *parent) :
conf.init(); conf.init();
logGlobal->info("Loading settings"); logGlobal->info("Loading settings");
CGI = new CGameInfo(); //contains all global informations about game (texts, lodHandlers, map handler etc.)
init(); init();
graphics = new Graphics(); // should be before curh->init() graphics = new Graphics(); // should be before curh->init()
@@ -141,9 +146,6 @@ MainWindow::MainWindow(QWidget *parent) :
QApplication::quit(); QApplication::quit();
} }
//now let's try to draw
//auto resPath = *CResourceHandler::get()->getResourceName(ResourceID("DATA/new-menu/Background.png"));
ui->mapView->setScene(controller.scene(0)); ui->mapView->setScene(controller.scene(0));
ui->mapView->setController(&controller); ui->mapView->setController(&controller);
ui->mapView->setOptimizationFlags(QGraphicsView::DontSavePainterState | QGraphicsView::DontAdjustForAntialiasing); ui->mapView->setOptimizationFlags(QGraphicsView::DontSavePainterState | QGraphicsView::DontAdjustForAntialiasing);
@@ -156,14 +158,12 @@ MainWindow::MainWindow(QWidget *parent) :
scenePreview = new QGraphicsScene(this); scenePreview = new QGraphicsScene(this);
ui->objectPreview->setScene(scenePreview); ui->objectPreview->setScene(scenePreview);
//scenes[0]->addPixmap(QPixmap(QString::fromStdString(resPath.native())));
//loading objects //loading objects
loadObjectsTree(); loadObjectsTree();
ui->tabWidget->setCurrentIndex(0); ui->tabWidget->setCurrentIndex(0);
for(int i = 0; i < 8; ++i) for(int i = 0; i < PlayerColor::PLAYER_LIMIT.getNum(); ++i)
{ {
connect(getActionPlayer(PlayerColor(i)), &QAction::toggled, this, [&, i](){switchDefaultPlayer(PlayerColor(i));}); connect(getActionPlayer(PlayerColor(i)), &QAction::toggled, this, [&, i](){switchDefaultPlayer(PlayerColor(i));});
} }
@@ -733,7 +733,7 @@ void MainWindow::on_actionGrid_triggered(bool checked)
if(controller.map()) if(controller.map())
{ {
controller.scene(0)->gridView.show(checked); controller.scene(0)->gridView.show(checked);
controller.scene(0)->gridView.show(checked); controller.scene(1)->gridView.show(checked);
} }
} }

View File

@@ -1,5 +1,4 @@
#ifndef MAINWINDOW_H #pragma once
#define MAINWINDOW_H
#include <QMainWindow> #include <QMainWindow>
#include <QGraphicsScene> #include <QGraphicsScene>
@@ -131,7 +130,7 @@ private:
void saveUserSettings(); void saveUserSettings();
private: private:
Ui::MainWindow *ui; Ui::MainWindow * ui;
ObjectBrowser * objectBrowser = nullptr; ObjectBrowser * objectBrowser = nullptr;
QGraphicsScene * scenePreview; QGraphicsScene * scenePreview;
@@ -144,5 +143,3 @@ private:
std::set<int> catalog; std::set<int> catalog;
}; };
#endif // MAINWINDOW_H

View File

@@ -109,6 +109,7 @@ void MapController::repairMap()
dynamic_cast<CGTownInstance*>(obj.get()) || dynamic_cast<CGTownInstance*>(obj.get()) ||
dynamic_cast<CGGarrison*>(obj.get()) || dynamic_cast<CGGarrison*>(obj.get()) ||
dynamic_cast<CGShipyard*>(obj.get()) || dynamic_cast<CGShipyard*>(obj.get()) ||
dynamic_cast<CGLighthouse*>(obj.get()) ||
dynamic_cast<CGHeroInstance*>(obj.get())) dynamic_cast<CGHeroInstance*>(obj.get()))
obj->tempOwner = PlayerColor::NEUTRAL; obj->tempOwner = PlayerColor::NEUTRAL;
} }
@@ -454,9 +455,6 @@ void MapController::commitObjectCreate(int level)
bool MapController::canPlaceObject(int level, CGObjectInstance * newObj, QString & error) const bool MapController::canPlaceObject(int level, CGObjectInstance * newObj, QString & error) const
{ {
//need this because of possible limits
auto rmgInfo = VLC->objtypeh->getHandlerFor(newObj->ID, newObj->subID)->getRMGInfo();
//find all objects of such type //find all objects of such type
int objCounter = 0; int objCounter = 0;
for(auto o : _map->objects) for(auto o : _map->objects)
@@ -467,30 +465,20 @@ bool MapController::canPlaceObject(int level, CGObjectInstance * newObj, QString
} }
} }
if((rmgInfo.mapLimit && objCounter >= rmgInfo.mapLimit) if(newObj->ID == Obj::GRAIL && objCounter >= 1) //special case for grail
|| (newObj->ID == Obj::GRAIL && objCounter >= 1)) //special case for grail
{ {
auto typeName = QString::fromStdString(newObj->typeName); auto typeName = QString::fromStdString(newObj->typeName);
auto subTypeName = QString::fromStdString(newObj->subTypeName); auto subTypeName = QString::fromStdString(newObj->subTypeName);
error = QString("Reached map limit for object %1 - %2").arg(typeName, subTypeName); error = QString("There can be only one grail object on the map");
return false; //maplimit reached return false; //maplimit reached
} }
if(defaultPlayer == PlayerColor::NEUTRAL && (newObj->ID == Obj::HERO || newObj->ID == Obj::RANDOM_HERO)) if(defaultPlayer == PlayerColor::NEUTRAL && (newObj->ID == Obj::HERO || newObj->ID == Obj::RANDOM_HERO))
{ {
error = "Hero cannot be created as NEUTRAL"; error = "Hero cannot be created as NEUTRAL";
return false; return false;
} }
if(defaultPlayer != PlayerColor::NEUTRAL && newObj->ID == Obj::PRISON)
{
error = "Prison must be a NEUTRAL";
return false;
}
if(newObj->ID == Obj::ARTIFACT && !_map->allowedArtifact.at(newObj->subID))
{
error = "Artifact is not allowed. Check map settings.";
return false;
}
return true; return true;
} }

View File

@@ -1,5 +1,4 @@
#ifndef MAPCONTROLLER_H #pragma once
#define MAPCONTROLLER_H
#include "maphandler.h" #include "maphandler.h"
#include "mapview.h" #include "mapview.h"
@@ -58,5 +57,3 @@ private:
void connectScenes(); void connectScenes();
}; };
#endif // MAPCONTROLLER_H

View File

@@ -382,7 +382,6 @@ void MapHandler::drawObjectAt(QPainter & painter, const CGObjectInstance * obj,
uint8_t animationFrame = 0; uint8_t animationFrame = 0;
auto objData = findObjectBitmap(obj, animationFrame, obj->ID == Obj::HERO ? 2 : 0); auto objData = findObjectBitmap(obj, animationFrame, obj->ID == Obj::HERO ? 2 : 0);
std::vector<std::shared_ptr<QImage>> debugFlagImages;
if(obj->ID == Obj::HERO && obj->tempOwner.isValidPlayer()) if(obj->ID == Obj::HERO && obj->tempOwner.isValidPlayer())
objData.flagBitmap = findFlagBitmap(dynamic_cast<const CGHeroInstance*>(obj), 0, obj->tempOwner, 4); objData.flagBitmap = findFlagBitmap(dynamic_cast<const CGHeroInstance*>(obj), 0, obj->tempOwner, 4);

View File

@@ -1,5 +1,4 @@
#ifndef MAPHANDLER_H #pragma once
#define MAPHANDLER_H
#include "StdInc.h" #include "StdInc.h"
#include "../lib/mapping/CMap.h" #include "../lib/mapping/CMap.h"
@@ -103,5 +102,3 @@ public:
static bool compareObjectBlitOrder(const CGObjectInstance * a, const CGObjectInstance * b); static bool compareObjectBlitOrder(const CGObjectInstance * a, const CGObjectInstance * b);
}; };
#endif // MAPHANDLER_H

View File

@@ -1,5 +1,4 @@
#ifndef MAPSETTINGS_H #pragma once
#define MAPSETTINGS_H
#include <QDialog> #include <QDialog>
#include "mapcontroller.h" #include "mapcontroller.h"
@@ -23,5 +22,3 @@ private:
Ui::MapSettings *ui; Ui::MapSettings *ui;
MapController & controller; MapController & controller;
}; };
#endif // MAPSETTINGS_H

View File

@@ -81,7 +81,8 @@ void MapView::mouseMoveEvent(QMouseEvent *mouseEvent)
tilePrev = tile; tilePrev = tile;
//main->setStatusMessage(QString("x: %1 y: %2").arg(QString::number(pos.x()), QString::number(pos.y()))); //TODO: cast parent->parent to MainWindow in order to show coordinates or another way to do it?
//main->setStatusMessage(QString("x: %1 y: %2").arg(tile.x, tile.y));
switch(selectionTool) switch(selectionTool)
{ {

View File

@@ -1,5 +1,4 @@
#ifndef MAPVIEW_H #pragma once
#define MAPVIEW_H
#include <QGraphicsScene> #include <QGraphicsScene>
#include <QGraphicsView> #include <QGraphicsView>
@@ -129,5 +128,3 @@ private:
int displayWidth = 192; int displayWidth = 192;
int displayHeight = 192; int displayHeight = 192;
}; };
#endif // MAPVIEW_H

View File

@@ -1,5 +1,4 @@
#ifndef OBJECTBROWSER_H #pragma once
#define OBJECTBROWSER_H
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include "../lib/Terrain.h" #include "../lib/Terrain.h"
@@ -16,5 +15,3 @@ protected:
bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const override; bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const override;
bool filterAcceptsRowText(int source_row, const QModelIndex &source_parent) const; bool filterAcceptsRowText(int source_row, const QModelIndex &source_parent) const;
}; };
#endif // OBJECTBROWSER_H

View File

@@ -1,5 +1,4 @@
#ifndef PLAYERPARAMS_H #pragma once
#define PLAYERPARAMS_H
#include <QWidget> #include <QWidget>
#include "../lib/mapping/CMap.h" #include "../lib/mapping/CMap.h"
@@ -38,5 +37,3 @@ private:
MapController & controller; MapController & controller;
}; };
#endif // PLAYERPARAMS_H

View File

@@ -1,5 +1,4 @@
#ifndef PLAYERSETTINGS_H #pragma once
#define PLAYERSETTINGS_H
#include "StdInc.h" #include "StdInc.h"
#include <QDialog> #include <QDialog>
@@ -30,5 +29,3 @@ private:
MapController & controller; MapController & controller;
}; };
#endif // PLAYERSETTINGS_H

View File

@@ -1,5 +1,4 @@
#ifndef SCENELAYER_H #pragma once
#define SCENELAYER_H
#include "../lib/int3.h" #include "../lib/int3.h"
@@ -174,5 +173,3 @@ private:
int x = 0, y = 0, w = 1, h = 1; int x = 0, y = 0, w = 1, h = 1;
}; };
#endif // SCENELAYER_H

View File

@@ -1,5 +1,4 @@
#ifndef VALIDATOR_H #pragma once
#define VALIDATOR_H
#include <QDialog> #include <QDialog>
#include "../lib/mapping/CMap.h" #include "../lib/mapping/CMap.h"
@@ -29,5 +28,3 @@ public:
private: private:
Ui::Validator *ui; Ui::Validator *ui;
}; };
#endif // VALIDATOR_H

View File

@@ -1,5 +1,4 @@
#ifndef WINDOWNEWMAP_H #pragma once
#define WINDOWNEWMAP_H
#include <QDialog> #include <QDialog>
#include "../lib/rmg/CMapGenOptions.h" #include "../lib/rmg/CMapGenOptions.h"
@@ -91,5 +90,3 @@ private:
CMapGenOptions mapGenOptions; CMapGenOptions mapGenOptions;
bool randomMap = false; bool randomMap = false;
}; };
#endif // WINDOWNEWMAP_H