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
*
@@ -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
@@ -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
}
/*************************************************************************
@@ -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
@@ -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)

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/GameConstants.h"
@@ -83,5 +91,3 @@ public:
void createFlippedGroup(const size_t sourceGroup, const size_t targetGroup);
};
#endif // ANIMATION_H

View File

@@ -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,7 +20,7 @@ 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
{
@@ -80,7 +83,7 @@ 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())
{
@@ -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())

View File

@@ -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);
}

View File

@@ -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

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

View File

@@ -33,7 +33,6 @@
#include "../lib/mapObjects/CObjectClassesHandler.h"
#include "../lib/mapObjects/CObjectHandler.h"
#include "../lib/CHeroHandler.h"
#include "CGameInfo.h"
Graphics * graphics = nullptr;
@@ -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,7 +123,7 @@ 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())
{
@@ -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());
}

View File

@@ -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);

View File

@@ -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());
}

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 "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);
}
}

View File

@@ -1,5 +1,4 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#pragma once
#include <QMainWindow>
#include <QGraphicsScene>
@@ -144,5 +143,3 @@ private:
std::set<int> catalog;
};
#endif // MAINWINDOW_H

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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);

View File

@@ -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

View File

@@ -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

View File

@@ -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)
{

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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