/
WorldCreatorResourcesWidget.cpp
66 lines (54 loc) · 2.22 KB
/
WorldCreatorResourcesWidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <QFileDialog>
#include <QDir>
#include "World.h"
#include "SaveManager.h"
#include "WorldCreatorResourcesWidget.h"
#include "ui_WorldCreatorResourcesWidget.h"
WorldCreatorResourcesWidget::WorldCreatorResourcesWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::WorldCreatorResourcesWidget)
{
ui->setupUi(this);
editorWidget.setResourcesList(&resources);
ui->horizontalLayout_editor->addWidget(&editorWidget);
ui->dockWidget->setWidget(&toolBox);
QObject::connect(ui->bt_loadWorld,SIGNAL(clicked(bool)),this,SLOT(loadWorld()));
QObject::connect(&toolBox, SIGNAL(brushSizeChanged(int)),&editorWidget, SLOT(setCurrantRadius(int)));
QObject::connect(&toolBox,SIGNAL(brushTypeChanged(WorldEditor::Tools)),&editorWidget,SLOT(setCurrantTool(WorldEditor::Tools)));
QObject::connect(&toolBox, SIGNAL(worldSizeChanged()),&editorWidget, SLOT(onWorldSizeChanged()));
QObject::connect(&toolBox, SIGNAL(brushQuantityChanged(int)),&editorWidget, SLOT(setCurrantMaxQuantity(int)));
}
WorldCreatorResourcesWidget::~WorldCreatorResourcesWidget()
{
delete ui;
}
void WorldCreatorResourcesWidget::loadWorld()
{
World world = World();
QString filter = "XML files (*.xml);;All files (*.*)";
QString defaultFilter = "XML files (*.xml)";
QString filePath = QFileDialog::getOpenFileName(this,tr("Load the world of your dreams"),"../save",
filter,&defaultFilter);
SaveManager saveManager;
saveManager.loadWorld(filePath, &world);
//delete old animals
std::list<std::shared_ptr<Entity>> entities = world.getEntities();
for(std::list<std::shared_ptr<Entity>>::iterator e=entities.begin() ; e!=entities.end() ; ++e)
{
if(std::shared_ptr<Resource> resource = std::dynamic_pointer_cast<Resource>(*e))
{
resources.push_back(resource);
}
}
ui->lb_loadedWorld->setText(filePath);
editorWidget.updateScene();
toolBox.setWorldSize(config::WORLD_SIZE_X,config::WORLD_SIZE_Y);
}
void WorldCreatorResourcesWidget::setRadius(int radius)
{
editorWidget.setCurrantRadius(radius);
}
void WorldCreatorResourcesWidget::setQuantity(int quantity)
{
editorWidget.setCurrantMaxQuantity(quantity);
}