-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
140 lines (113 loc) · 5.39 KB
/
mainwindow.cpp
File metadata and controls
140 lines (113 loc) · 5.39 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include <QGraphicsPixmapItem>
#include <QMessageBox>
#include <QPixmap>
#include <QTimer>
#include <QtCore>
#include <QtGui>
#include "instructionsdialog.h"
#include "ui_mainwindow.h"
#include "aboutdialog.h"
#include "mainwindow.h"
#include "robotgraphicsitem.h" /** Contains RobotGraphicsItem & RobotGraphicObject */
#include "robotgridmatrix.h" /** Contains RobotGridMatrix */
#include "robotgriditem.h" /** Contains RobotGridItem */
#include "robotpath.h" /** Contains RobotPath */
#include "robotmap.h" /** Contains RobotPathMap & RobotMap */
#include "map.h" /** Contains Map */
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow) {
ui->setupUi(this);
}
MainWindow::~MainWindow() {
delete ui;
}
void MainWindow::on_actionRun_triggered() {
QGraphicsScene *scene = new QGraphicsScene(this); /** Create new scene */
QList<RobotGridItem*> grid; /** List holding the grid (graphical representation)*/
QList<QPoint> path_1, path_2; /** Lists holding paths vectors */
RobotGridMatrix Matrix(grid); /** Class for operating with grid */
RobotMapPath one(1); /** Generation of path for 1 robot */
RobotMapPath two(0); /** Generation of path for 2 robot */
Map Maze; /** Class to hold maze for algorithms */
ui->areaPlot->setScene(scene); /* Set scene */
ui->areaPlot->setRenderHint(QPainter::Antialiasing); /* Add antialiasing */
ui->areaPlot->setBackgroundBrush(QPixmap(":/terrain/background.png"));
one.CreatePath(); /* Create 1. path */
two.CreatePath(); /* Create 2. path */
one.common_map(two); /* Merge paths together */
Maze.mapFromArray(one.common); /** Convert commnon map to condinate format */
Matrix.MapToScene(Maze); /** Calculate positions of tiles in scene */
Matrix.AttachToScene(scene); /** Attach tiles to scene (create graphic maze) */
qDebug("CORNER::[0][0] => %d", Maze.popValue(QPoint(0,0)));
qDebug("CORNER::[0][7] => %d", Maze.popValue(QPoint(0,7)));
qDebug("CORNER::[9][7] => %d", Maze.popValue(QPoint(9,7)));
qDebug("CORNER::[9][0] => %d", Maze.popValue(QPoint(9,0)));
RobotPath(Maze, &path_1, &path_2); /** Generate the paths vectors */
qDebug("HIRE: %d", path_1.isEmpty());
RobotGraphicsObject *bot = new RobotGraphicsObject(QPixmap(":/terrain/captain.png"),0, path_1, QPoint(0,7));
RobotGraphicsObject *bot2 = new RobotGraphicsObject(QPixmap(":/terrain/monolith3.png"),0, path_2, QPoint(0,7));
scene->addItem(bot);
scene->addItem(bot2);
QSequentialAnimationGroup *group1 = new QSequentialAnimationGroup;
QListIterator<QPoint> PathIteration(path_1);
PathIteration.next();
while(PathIteration.hasNext()) {
QPropertyAnimation *animation = new QPropertyAnimation(bot,"pos",this);
animation->setStartValue(PathIteration.peekPrevious());
animation->setEndValue(PathIteration.next());
group1->addAnimation(animation);
}
QListIterator<QPoint> PathIteration2(path_2);
PathIteration2.next();
while(PathIteration2.hasNext()) {
QPropertyAnimation *animation = new QPropertyAnimation(bot2,"pos",this);
animation->setStartValue(PathIteration2.peekPrevious());
animation->setEndValue(PathIteration2.next());
group1->addAnimation(animation);
}
group1->start();
scene->update();
/*QPropertyAnimation animation(bot,"pos");
animation.setDuration(10000);
animation.setStartValue(QPoint(0,0));
animation.setEndValue(QPoint(300,500));
animation.start();*/
qDebug() << "Action->run";
/** IDEA BOX - STUFF TESTED, TESTING, DEPRE., UNUSED */
//QListIterator<QPoint> i(path_1); while(i.hasNext()) qDebug() << i.next();
//QSequentialAnimationGroup *Bot1Path1 = new QSequentialAnimationGroup;
//bot->animation(Bot1Path1);
/*
int tmp[8][10] = {{2,2,2,2,2,0,0,0,0,1},
{0,0,0,0,2,0,0,0,1,1},
{0,0,1,1,3,1,1,1,1,0},
{1,1,1,0,2,0,0,0,0,0},
{1,0,0,0,2,2,2,0,0,0},
{1,0,0,0,0,0,2,0,0,0},
{1,0,0,0,0,0,2,2,2,0},
{1,0,0,0,0,0,0,0,2,2}};
*/
}
void MainWindow::on_actionReset_triggered() {
ui->areaPlot->repaint();
qDebug() << "Action->reset";
}
void MainWindow::on_actionGenerate_triggered() {qDebug() << "Action->generate";}
void MainWindow::on_actionImportAll_triggered() {qDebug() << "Action->ImportAll";}
void MainWindow::on_actionImportMap_triggered() {qDebug() << "Action->ImportMap";}
void MainWindow::on_actionExportCriticalPlaces_triggered() {qDebug() << "Action->ExportCriticalPlaces";}
void MainWindow::on_actionExportMap_triggered() {qDebug() << "Action->ExportMap";}
void MainWindow::on_actionExportMovements_triggered() {qDebug() << "Action->ExportMovements";}
void MainWindow::on_actionHelpAbout_triggered() {
AboutDialog *about = new AboutDialog;
about->setWindowTitle("About");
about->show();
qDebug() << "Action->HelpAbout";
}
void MainWindow::on_actionHelpInstructions_triggered(){
InstructionsDialog *inst = new InstructionsDialog;
inst->setWindowTitle("Instructions");
inst->show();
qDebug() << "Action->HelpInstructions";
}