-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpath_operation.cpp
90 lines (70 loc) · 2.21 KB
/
path_operation.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <cstdio>
#include "libtcod.hpp"
#include "gui/gui.hpp"
#include "app.h"
#include "brush.h"
#include "path_operation.h"
PathOperation::PathOperation() {
}
PathOperation::~PathOperation() {
}
void PathOperation::start() {
app->gui->pathLengthLabel->setVisible(true);
app->gui->pathDiagonalToggleButton->setVisible(true);
map = new TCODMap(app->canvasWidth, app->canvasHeight);
for(int x = 0; x < app->canvasWidth; x++) {
for(int y = 0; y < app->canvasHeight; y++) {
if(app->solidCon->getCharBackground(x, y) == TCODColor(255, 255, 255)) // No Solid
map->setProperties(x, y, true, true);
else
map->setProperties(x, y, false, false);
}
}
allowDiagonal = app->gui->pathDiagonalToggleButton->isPressed();
path = new TCODPath(map, allowDiagonal);
pointX = -1;
pointY = -1;
app->setOverlayFade(0.25);
}
void PathOperation::update() {
TCOD_mouse_t mouse = app->mouse;
int mouseX = app->canvasMouseX;
int mouseY = app->canvasMouseY;
// If the mouse is inside the canvas area...
if(mouseX >= 0 && mouseX < app->canvasWidth &&
mouseY >= 0 && mouseY < app->canvasHeight) {
if(mouse.lbutton_pressed) {
pointX = mouseX;
pointY = mouseY;
}
// If allowDiagonal was changed then make a new path
if(allowDiagonal != app->gui->pathDiagonalToggleButton->isPressed()) {
allowDiagonal = app->gui->pathDiagonalToggleButton->isPressed();
delete path;
path = new TCODPath(map, allowDiagonal);
}
if(pointX != -1 && pointY != -1) {
path->compute(pointX, pointY, mouseX, mouseY);
}
app->clearOverlay();
Brush pathBrush;
pathBrush.fore = TCODColor(0, 0, 0);
pathBrush.back = TCODColor(255, 255, 0);
pathBrush.symbol = ' ';
static char* pathLengthLabelString = new char[20];
sprintf(pathLengthLabelString, "Length: %i", path->size());
app->gui->pathLengthLabel->setValue(pathLengthLabelString);
for(int i = 0; i < path->size(); i++) {
int x, y;
path->get(i, &x, &y);
app->applyBrushToOverlayCell(x, y, &pathBrush);
}
pathBrush.back = TCODColor(128, 128, 0);
//app->applyBrushToOverlayCell(mouseX, mouseY, &pathBrush);
}
}
void PathOperation::end() {
delete map;
delete path;
app->setOverlayFade(1.0);
}