mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Code review changes
This commit is contained in:
parent
700e957cdb
commit
bc84ffe8d6
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* CAnimation.cpp, part of VCMI engine
|
||||
* Animation.cpp, part of VCMI engine
|
||||
*
|
||||
* 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, IImage*> image_map;
|
||||
//typedef std::map<size_t, image_map > group_map;
|
||||
|
||||
/// Class for def loading
|
||||
/// After loading will store general info (palette and frame offsets) and pointer to file itself
|
||||
@ -102,11 +100,11 @@ public:
|
||||
{
|
||||
for(auto & file : cache)
|
||||
{
|
||||
if (file.name == rid)
|
||||
if(file.name == rid)
|
||||
return file.getCopy();
|
||||
}
|
||||
// Still here? Cache miss
|
||||
if (cache.size() > cacheSize)
|
||||
if(cache.size() > cacheSize)
|
||||
cache.pop_front();
|
||||
|
||||
auto data = CResourceHandler::get()->load(rid)->readAll();
|
||||
@ -173,12 +171,12 @@ DefFile::DefFile(std::string Name):
|
||||
int it = 0;
|
||||
|
||||
ui32 type = read_le_u32(data.get() + it);
|
||||
it+=4;
|
||||
it += 4;
|
||||
//int width = read_le_u32(data + it); it+=4;//not used
|
||||
//int height = read_le_u32(data + it); it+=4;
|
||||
it+=8;
|
||||
it += 8;
|
||||
ui32 totalBlocks = read_le_u32(data.get() + it);
|
||||
it+=4;
|
||||
it += 4;
|
||||
|
||||
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)
|
||||
{
|
||||
if (size)
|
||||
if(size)
|
||||
{
|
||||
memset((void *)position, color, size);
|
||||
position += size;
|
||||
@ -482,9 +480,6 @@ inline void ImageLoader::EndLine()
|
||||
|
||||
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)
|
||||
{
|
||||
size_t pos = filename.find(':');
|
||||
if (pos == -1)
|
||||
if(pos == -1)
|
||||
return nullptr;
|
||||
Animation anim(filename.substr(0, pos));
|
||||
pos++;
|
||||
size_t frame = atoi(filename.c_str()+pos);
|
||||
size_t group = 0;
|
||||
pos = filename.find(':', pos);
|
||||
if (pos != -1)
|
||||
if(pos != -1)
|
||||
{
|
||||
pos++;
|
||||
group = frame;
|
||||
@ -548,12 +543,7 @@ bool Animation::loadFrame(size_t frame, size_t group)
|
||||
}
|
||||
else //load from separate file
|
||||
{
|
||||
auto img = getFromExtraDef(source[group][frame]["file"].String());
|
||||
//if(!img)
|
||||
|
||||
//img = std::make_shared<QImage>(source[group][frame]);
|
||||
|
||||
images[group][frame] = img;
|
||||
images[group][frame] = getFromExtraDef(source[group][frame]["file"].String());;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -583,6 +573,7 @@ void Animation::init()
|
||||
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);
|
||||
|
||||
//if(vstd::contains(graphics->imageLists, resID.getName()))
|
||||
@ -600,6 +591,7 @@ void Animation::init()
|
||||
|
||||
//initFromJson(config);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Animation::printError(size_t frame, size_t group, std::string type) const
|
||||
@ -613,7 +605,7 @@ Animation::Animation(std::string Name):
|
||||
defFile()
|
||||
{
|
||||
size_t dotPos = name.find_last_of('.');
|
||||
if ( dotPos!=-1 )
|
||||
if( dotPos!=-1 )
|
||||
name.erase(dotPos);
|
||||
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)
|
||||
{
|
||||
if (source[group].size() <= frame)
|
||||
if(source[group].size() <= frame)
|
||||
source[group].resize(frame+1);
|
||||
source[group][frame]["file"].String() = filename;
|
||||
//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
|
||||
{
|
||||
auto groupIter = images.find(group);
|
||||
if (groupIter != images.end())
|
||||
if(groupIter != images.end())
|
||||
{
|
||||
auto imageIter = groupIter->second.find(frame);
|
||||
if (imageIter != groupIter->second.end())
|
||||
if(imageIter != groupIter->second.end())
|
||||
return imageIter->second;
|
||||
}
|
||||
if (verbose)
|
||||
if(verbose)
|
||||
printError(frame, group, "GetImage");
|
||||
return nullptr;
|
||||
}
|
||||
@ -717,14 +709,14 @@ void Animation::preload()
|
||||
|
||||
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++)
|
||||
loadFrame(image, 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++)
|
||||
unloadFrame(image, group);
|
||||
}
|
||||
@ -742,7 +734,7 @@ void Animation::unload(size_t frame, size_t group)
|
||||
size_t Animation::size(size_t group) const
|
||||
{
|
||||
auto iter = source.find(group);
|
||||
if (iter != source.end())
|
||||
if(iter != source.end())
|
||||
return iter->second.size();
|
||||
return 0;
|
||||
}
|
||||
@ -763,9 +755,11 @@ void Animation::verticalFlip()
|
||||
|
||||
void Animation::playerColored(PlayerColor player)
|
||||
{
|
||||
//for(auto & group : images)
|
||||
//for(auto & image : group.second)
|
||||
//image.second->playerColored(player);
|
||||
#if 0 //can be required in image preview?
|
||||
for(auto & group : images)
|
||||
for(auto & image : group.second)
|
||||
image.second->playerColored(player);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Animation::createFlippedGroup(const size_t sourceGroup, const size_t targetGroup)
|
||||
|
@ -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/GameConstants.h"
|
||||
@ -57,12 +65,12 @@ public:
|
||||
// adjust the color of the animation, used in battle spell effects, e.g. Cloned objects
|
||||
|
||||
//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
|
||||
void load ();
|
||||
void load();
|
||||
void unload();
|
||||
void preload();
|
||||
|
||||
@ -71,11 +79,11 @@ public:
|
||||
void unloadGroup(size_t group);
|
||||
|
||||
//single image
|
||||
void load (size_t frame, size_t group=0);
|
||||
void unload(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);
|
||||
|
||||
//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 verticalFlip();
|
||||
@ -83,5 +91,3 @@ public:
|
||||
|
||||
void createFlippedGroup(const size_t sourceGroup, const size_t targetGroup);
|
||||
};
|
||||
|
||||
#endif // ANIMATION_H
|
||||
|
@ -1,9 +1,12 @@
|
||||
//
|
||||
// BitmapHandler.cpp
|
||||
// vcmieditor
|
||||
//
|
||||
// Created by nordsoft on 29.08.2022.
|
||||
//
|
||||
/*
|
||||
* BitmapHandler.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 "BitmapHandler.h"
|
||||
|
||||
@ -17,14 +20,14 @@ namespace BitmapHandler
|
||||
{
|
||||
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 width = read_le_u32(header + 4);
|
||||
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
|
||||
@ -38,22 +41,22 @@ namespace BitmapHandler
|
||||
//SDL_Surface * ret;
|
||||
|
||||
Epcxformat format;
|
||||
int it=0;
|
||||
int it = 0;
|
||||
|
||||
ui32 fSize = 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 fSize = 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;
|
||||
|
||||
if (fSize==width*height*3)
|
||||
if(fSize==width*height*3)
|
||||
format=PCX24B;
|
||||
else if (fSize==width*height)
|
||||
else if(fSize==width*height)
|
||||
format=PCX8B;
|
||||
else
|
||||
return QImage();
|
||||
|
||||
QSize qsize(width, height);
|
||||
|
||||
if (format==PCX8B)
|
||||
if(format==PCX8B)
|
||||
{
|
||||
it = 0xC;
|
||||
//auto bitmap = QBitmap::fromData(qsize, pcx + it);
|
||||
@ -61,8 +64,8 @@ namespace BitmapHandler
|
||||
|
||||
//palette - last 256*3 bytes
|
||||
QVector<QRgb> colorTable;
|
||||
it = (int)size-256*3;
|
||||
for (int i=0;i<256;i++)
|
||||
it = (int)size - 256 * 3;
|
||||
for(int i = 0; i < 256; i++)
|
||||
{
|
||||
char bytes[3];
|
||||
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())
|
||||
{
|
||||
logGlobal->warn("Call to loadBitmap with void fname!");
|
||||
return QImage();
|
||||
}
|
||||
if (!CResourceHandler::get()->existsResource(ResourceID(path + fname, EResType::IMAGE)))
|
||||
if(!CResourceHandler::get()->existsResource(ResourceID(path + fname, EResType::IMAGE)))
|
||||
{
|
||||
return QImage();
|
||||
}
|
||||
@ -95,7 +98,7 @@ namespace BitmapHandler
|
||||
auto fullpath = CResourceHandler::get()->getResourceName(ResourceID(path + fname, EResType::IMAGE));
|
||||
auto readFile = CResourceHandler::get()->load(ResourceID(path + fname, EResType::IMAGE))->readAll();
|
||||
|
||||
if (isPCX(readFile.first.get()))
|
||||
if(isPCX(readFile.first.get()))
|
||||
{//H3-style PCX
|
||||
auto image = BitmapHandler::loadH3PCX(readFile.first.get(), readFile.second);
|
||||
if(!image.isNull())
|
||||
@ -134,26 +137,13 @@ namespace BitmapHandler
|
||||
}
|
||||
}
|
||||
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)
|
||||
// 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)
|
||||
/*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);
|
||||
if(image.isNull())
|
||||
|
@ -1,10 +1,12 @@
|
||||
//
|
||||
// BitmapHandler.hpp
|
||||
// vcmieditor
|
||||
//
|
||||
// Created by nordsoft on 29.08.2022.
|
||||
//
|
||||
|
||||
/*
|
||||
* BitmapHandler.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
|
||||
|
||||
#define read_le_u16(p) (* reinterpret_cast<const ui16 *>(p))
|
||||
@ -15,6 +17,6 @@
|
||||
namespace BitmapHandler
|
||||
{
|
||||
//Load file from /DATA or /SPRITES
|
||||
QImage loadBitmap(std::string fname, bool setKey=true);
|
||||
QImage loadBitmap(const std::string & fname, bool setKey = true);
|
||||
}
|
||||
|
||||
|
@ -4,16 +4,13 @@ set(editor_SRCS
|
||||
launcherdirs.cpp
|
||||
jsonutils.cpp
|
||||
mainwindow.cpp
|
||||
CGameInfo.cpp
|
||||
BitmapHandler.cpp
|
||||
maphandler.cpp
|
||||
Animation.cpp
|
||||
graphics.cpp
|
||||
spoiler.cpp
|
||||
windownewmap.cpp
|
||||
generatorprogress.cpp
|
||||
mapview.cpp
|
||||
radiopushbutton.cpp
|
||||
objectbrowser.cpp
|
||||
mapsettings.cpp
|
||||
playersettings.cpp
|
||||
@ -33,16 +30,13 @@ set(editor_HEADERS
|
||||
launcherdirs.h
|
||||
jsonutils.h
|
||||
mainwindow.h
|
||||
CGameInfo.h
|
||||
BitmapHandler.h
|
||||
maphandler.h
|
||||
Animation.h
|
||||
graphics.h
|
||||
spoiler.h
|
||||
windownewmap.h
|
||||
generatorprogress.h
|
||||
mapview.h
|
||||
radiopushbutton.h
|
||||
objectbrowser.h
|
||||
mapsettings.h
|
||||
playersettings.h
|
||||
|
@ -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 "generatorprogress.h"
|
||||
#include "ui_generatorprogress.h"
|
||||
|
@ -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 "../lib/LoadProgress.h"
|
||||
@ -22,5 +30,3 @@ private:
|
||||
Ui::GeneratorProgress *ui;
|
||||
Load::Progress & source;
|
||||
};
|
||||
|
||||
#endif // GENERATORPROGRESS_H
|
||||
|
@ -33,7 +33,6 @@
|
||||
#include "../lib/mapObjects/CObjectClassesHandler.h"
|
||||
#include "../lib/mapObjects/CObjectHandler.h"
|
||||
#include "../lib/CHeroHandler.h"
|
||||
#include "CGameInfo.h"
|
||||
|
||||
Graphics * graphics = nullptr;
|
||||
|
||||
@ -45,7 +44,7 @@ void Graphics::loadPaletteAndColors()
|
||||
playerColorPalette.resize(256);
|
||||
playerColors.resize(PlayerColor::PLAYER_LIMIT_I);
|
||||
int startPoint = 24; //beginning byte; used to read
|
||||
for(int i=0; i<256; ++i)
|
||||
for(int i = 0; i < 256; ++i)
|
||||
{
|
||||
QColor col;
|
||||
col.setRed(pals[startPoint++]);
|
||||
@ -61,7 +60,7 @@ void Graphics::loadPaletteAndColors()
|
||||
auto stream = CResourceHandler::get()->load(ResourceID("config/NEUTRAL.PAL"));
|
||||
CBinaryReader reader(stream.get());
|
||||
|
||||
for(int i=0; i<32; ++i)
|
||||
for(int i = 0; i < 32; ++i)
|
||||
{
|
||||
QColor col;
|
||||
col.setRed(reader.readUInt8());
|
||||
@ -95,7 +94,6 @@ void Graphics::loadPaletteAndColors()
|
||||
Graphics::Graphics()
|
||||
{
|
||||
#if 0
|
||||
|
||||
std::vector<Task> tasks; //preparing list of graphics to load
|
||||
tasks += std::bind(&Graphics::loadFonts,this);
|
||||
tasks += std::bind(&Graphics::loadPaletteAndColors,this);
|
||||
@ -125,11 +123,11 @@ void Graphics::load()
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -244,39 +242,6 @@ void Graphics::blueToPlayersAdv(QImage * sur, PlayerColor player)
|
||||
//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)
|
||||
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
|
||||
{
|
||||
@ -369,10 +334,10 @@ void Graphics::addImageListEntries(const EntityService * service)
|
||||
|
||||
void Graphics::initializeImageLists()
|
||||
{
|
||||
addImageListEntries(CGI->creatures());
|
||||
addImageListEntries(CGI->heroTypes());
|
||||
addImageListEntries(CGI->artifacts());
|
||||
addImageListEntries(CGI->factions());
|
||||
addImageListEntries(CGI->spells());
|
||||
addImageListEntries(CGI->skills());
|
||||
addImageListEntries(VLC->creatures());
|
||||
addImageListEntries(VLC->heroTypes());
|
||||
addImageListEntries(VLC->artifacts());
|
||||
addImageListEntries(VLC->factions());
|
||||
addImageListEntries(VLC->spells());
|
||||
addImageListEntries(VLC->skills());
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ ArmyWidget::ArmyWidget(CArmedInstance & a, QWidget *parent) :
|
||||
|
||||
for(int i = 0; i < TOTAL_SLOTS; ++i)
|
||||
{
|
||||
uiCounts[i]->setInputMask("d0000");
|
||||
uiCounts[i]->setText("1");
|
||||
uiSlots[i]->addItem("");
|
||||
uiSlots[i]->setItemData(0, -1);
|
||||
|
@ -100,6 +100,9 @@ void Initializer::initialize(CGHeroInstance * o)
|
||||
if(!o) return;
|
||||
|
||||
o->tempOwner = defaultPlayer;
|
||||
if(o->ID == Obj::PRISON)
|
||||
o->tempOwner = PlayerColor::NEUTRAL;
|
||||
|
||||
if(o->ID == Obj::HERO)
|
||||
{
|
||||
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("Remove after")
|
||||
if(key == "Remove after")
|
||||
o->removeAfterVisit = stringToBool(value.toString());
|
||||
|
||||
if("Human trigger")
|
||||
if(key == "Human trigger")
|
||||
o->humanActivate = stringToBool(value.toString());
|
||||
|
||||
if("Cpu trigger")
|
||||
if(key == "Cpu trigger")
|
||||
o->computerActivate = stringToBool(value.toString());
|
||||
}
|
||||
|
||||
|
@ -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 "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
@ -20,8 +30,6 @@
|
||||
#include "../lib/mapObjects/CObjectClassesHandler.h"
|
||||
#include "../lib/filesystem/CFilesystemLoader.h"
|
||||
|
||||
|
||||
#include "CGameInfo.h"
|
||||
#include "maphandler.h"
|
||||
#include "graphics.h"
|
||||
#include "windownewmap.h"
|
||||
@ -52,9 +60,7 @@ QPixmap pixmapFromJson(const QJsonValue &val)
|
||||
|
||||
void init()
|
||||
{
|
||||
|
||||
loadDLLClasses();
|
||||
const_cast<CGameInfo*>(CGI)->setFromLib();
|
||||
logGlobal->info("Initializing VCMI_Lib");
|
||||
}
|
||||
|
||||
@ -129,7 +135,6 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
conf.init();
|
||||
logGlobal->info("Loading settings");
|
||||
|
||||
CGI = new CGameInfo(); //contains all global informations about game (texts, lodHandlers, map handler etc.)
|
||||
init();
|
||||
|
||||
graphics = new Graphics(); // should be before curh->init()
|
||||
@ -141,9 +146,6 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
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->setController(&controller);
|
||||
ui->mapView->setOptimizationFlags(QGraphicsView::DontSavePainterState | QGraphicsView::DontAdjustForAntialiasing);
|
||||
@ -156,14 +158,12 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
scenePreview = new QGraphicsScene(this);
|
||||
ui->objectPreview->setScene(scenePreview);
|
||||
|
||||
//scenes[0]->addPixmap(QPixmap(QString::fromStdString(resPath.native())));
|
||||
|
||||
//loading objects
|
||||
loadObjectsTree();
|
||||
|
||||
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));});
|
||||
}
|
||||
@ -733,7 +733,7 @@ void MainWindow::on_actionGrid_triggered(bool checked)
|
||||
if(controller.map())
|
||||
{
|
||||
controller.scene(0)->gridView.show(checked);
|
||||
controller.scene(0)->gridView.show(checked);
|
||||
controller.scene(1)->gridView.show(checked);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
#pragma once
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QGraphicsScene>
|
||||
@ -131,7 +130,7 @@ private:
|
||||
void saveUserSettings();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
Ui::MainWindow * ui;
|
||||
ObjectBrowser * objectBrowser = nullptr;
|
||||
QGraphicsScene * scenePreview;
|
||||
|
||||
@ -144,5 +143,3 @@ private:
|
||||
|
||||
std::set<int> catalog;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
@ -109,6 +109,7 @@ void MapController::repairMap()
|
||||
dynamic_cast<CGTownInstance*>(obj.get()) ||
|
||||
dynamic_cast<CGGarrison*>(obj.get()) ||
|
||||
dynamic_cast<CGShipyard*>(obj.get()) ||
|
||||
dynamic_cast<CGLighthouse*>(obj.get()) ||
|
||||
dynamic_cast<CGHeroInstance*>(obj.get()))
|
||||
obj->tempOwner = PlayerColor::NEUTRAL;
|
||||
}
|
||||
@ -454,9 +455,6 @@ void MapController::commitObjectCreate(int level)
|
||||
|
||||
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
|
||||
int objCounter = 0;
|
||||
for(auto o : _map->objects)
|
||||
@ -467,30 +465,20 @@ bool MapController::canPlaceObject(int level, CGObjectInstance * newObj, QString
|
||||
}
|
||||
}
|
||||
|
||||
if((rmgInfo.mapLimit && objCounter >= rmgInfo.mapLimit)
|
||||
|| (newObj->ID == Obj::GRAIL && objCounter >= 1)) //special case for grail
|
||||
if(newObj->ID == Obj::GRAIL && objCounter >= 1) //special case for grail
|
||||
{
|
||||
auto typeName = QString::fromStdString(newObj->typeName);
|
||||
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
|
||||
}
|
||||
|
||||
if(defaultPlayer == PlayerColor::NEUTRAL && (newObj->ID == Obj::HERO || newObj->ID == Obj::RANDOM_HERO))
|
||||
{
|
||||
error = "Hero cannot be created as NEUTRAL";
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef MAPCONTROLLER_H
|
||||
#define MAPCONTROLLER_H
|
||||
#pragma once
|
||||
|
||||
#include "maphandler.h"
|
||||
#include "mapview.h"
|
||||
@ -58,5 +57,3 @@ private:
|
||||
|
||||
void connectScenes();
|
||||
};
|
||||
|
||||
#endif // MAPCONTROLLER_H
|
||||
|
@ -382,7 +382,6 @@ void MapHandler::drawObjectAt(QPainter & painter, const CGObjectInstance * obj,
|
||||
uint8_t animationFrame = 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())
|
||||
objData.flagBitmap = findFlagBitmap(dynamic_cast<const CGHeroInstance*>(obj), 0, obj->tempOwner, 4);
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef MAPHANDLER_H
|
||||
#define MAPHANDLER_H
|
||||
#pragma once
|
||||
|
||||
#include "StdInc.h"
|
||||
#include "../lib/mapping/CMap.h"
|
||||
@ -103,5 +102,3 @@ public:
|
||||
|
||||
static bool compareObjectBlitOrder(const CGObjectInstance * a, const CGObjectInstance * b);
|
||||
};
|
||||
|
||||
#endif // MAPHANDLER_H
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef MAPSETTINGS_H
|
||||
#define MAPSETTINGS_H
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
#include "mapcontroller.h"
|
||||
@ -23,5 +22,3 @@ private:
|
||||
Ui::MapSettings *ui;
|
||||
MapController & controller;
|
||||
};
|
||||
|
||||
#endif // MAPSETTINGS_H
|
||||
|
@ -81,7 +81,8 @@ void MapView::mouseMoveEvent(QMouseEvent *mouseEvent)
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef MAPVIEW_H
|
||||
#define MAPVIEW_H
|
||||
#pragma once
|
||||
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsView>
|
||||
@ -129,5 +128,3 @@ private:
|
||||
int displayWidth = 192;
|
||||
int displayHeight = 192;
|
||||
};
|
||||
|
||||
#endif // MAPVIEW_H
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef OBJECTBROWSER_H
|
||||
#define OBJECTBROWSER_H
|
||||
#pragma once
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
#include "../lib/Terrain.h"
|
||||
@ -16,5 +15,3 @@ protected:
|
||||
bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const override;
|
||||
bool filterAcceptsRowText(int source_row, const QModelIndex &source_parent) const;
|
||||
};
|
||||
|
||||
#endif // OBJECTBROWSER_H
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef PLAYERPARAMS_H
|
||||
#define PLAYERPARAMS_H
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include "../lib/mapping/CMap.h"
|
||||
@ -38,5 +37,3 @@ private:
|
||||
|
||||
MapController & controller;
|
||||
};
|
||||
|
||||
#endif // PLAYERPARAMS_H
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef PLAYERSETTINGS_H
|
||||
#define PLAYERSETTINGS_H
|
||||
#pragma once
|
||||
|
||||
#include "StdInc.h"
|
||||
#include <QDialog>
|
||||
@ -30,5 +29,3 @@ private:
|
||||
|
||||
MapController & controller;
|
||||
};
|
||||
|
||||
#endif // PLAYERSETTINGS_H
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef SCENELAYER_H
|
||||
#define SCENELAYER_H
|
||||
#pragma once
|
||||
|
||||
#include "../lib/int3.h"
|
||||
|
||||
@ -174,5 +173,3 @@ private:
|
||||
int x = 0, y = 0, w = 1, h = 1;
|
||||
|
||||
};
|
||||
|
||||
#endif // SCENELAYER_H
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef VALIDATOR_H
|
||||
#define VALIDATOR_H
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
#include "../lib/mapping/CMap.h"
|
||||
@ -29,5 +28,3 @@ public:
|
||||
private:
|
||||
Ui::Validator *ui;
|
||||
};
|
||||
|
||||
#endif // VALIDATOR_H
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef WINDOWNEWMAP_H
|
||||
#define WINDOWNEWMAP_H
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
#include "../lib/rmg/CMapGenOptions.h"
|
||||
@ -91,5 +90,3 @@ private:
|
||||
CMapGenOptions mapGenOptions;
|
||||
bool randomMap = false;
|
||||
};
|
||||
|
||||
#endif // WINDOWNEWMAP_H
|
||||
|
Loading…
Reference in New Issue
Block a user