-
Notifications
You must be signed in to change notification settings - Fork 0
/
editor.cpp
97 lines (75 loc) · 1.36 KB
/
editor.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
91
92
93
94
95
96
97
#include "editor.h"
#include "common.h"
void editor::ChangeMode(int newMode)
{
prev = c->highlightVertex = -1;
mode = newMode;
c->drawSBuilding = (mode == 3);
c->drawRoutes = (mode == 4);
}
void editor::Init(city *ct)
{
c = ct;
mode = 0;
prev = -1;
}
void editor::Progress(point3 pos, double time)
{
pressedDown += time;
if (mode == 3)
{
point p(pos.x, pos.z);
c->SetSampleBuilding(p);
//c->sampleBuilding = p;
}
}
void editor::MouseLeftDown(point3 pos)
{
pressedDown = 0;
}
void editor::MouseLeftUp(point3 pos)
{
if (pressedDown < 200)
{
if (mode == 2)
{
point now;
double height;
now.x = pos.x;
now.y = pos.z;
height = pos.y;
int nowNr = c->ClosestVertex(now);
if (prev != -1)
{
if (prev == nowNr)
prev = c->highlightVertex = -1;
else
{
if (nowNr != -1)
{
c->AddRoad(prev, nowNr);
prev = c->highlightVertex = -1;
}
else
{
//make new vertex
int newP = c->AddVertex(now);
c->AddRoad(prev, newP);
prev = c->highlightVertex = newP;
}
c->Generate();
}
}
else
{
if (nowNr != -1)
prev = c->highlightVertex = nowNr;
}
}
else if (mode == 3)
{
//build a building
c->BuildSampleBuilding();
}
}
}