-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcommunicationbar.js
128 lines (111 loc) · 3.35 KB
/
communicationbar.js
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
function CommunicationBar() {
this.Container_constructor();
this.lines = [];
this.width = 400;
this.x = 0;
this.y = 5;
}
createjs.extend(CommunicationBar, createjs.Container);
createjs.promote(CommunicationBar, "Container");
CommunicationBar.prototype.setX = function ( x ) {
this.x = x;
}
CommunicationBar.prototype.setY = function ( y ) {
this.y = y;
}
CommunicationBar.prototype.setWidth = function ( w ) {
this.width = w;
for (var line=0; line < this.lines.length; line++) {
this.lines[line].setWidth(w);
}
}
CommunicationBar.prototype.showMessage = function ( msg, type ) {
var color;
switch (type) {
case MSG_TO_PLANE:
color = MSG_BAR_COLOR_1;
break;
case MSG_FROM_PLANE:
color = MSG_BAR_COLOR_2;
break;
case MSG_FROM_TWR:
case MSG_TO_TWR:
msg = 'TWR: ' + msg;
color = MSG_BAR_COLOR_3;
break;
case MSG_FROM_ATC:
case MSG_TO_ATC:
msg = 'ATC: ' + msg;
color = MSG_BAR_COLOR_4;
break;
case MSG_ERROR:
msg = 'ERROR: ' + msg;
color = MSG_BAR_COLOR_ERR;
break;
default:
color = MSG_BAR_COLOR;
break;
}
this.pushMessage(msg, color);
}
CommunicationBar.prototype.pushMessage = function ( msg, color ) {
var line = this.lines.length;
var o_message = new Message(msg, this.width, color);
o_message.setStackPosition(line);
this.lines[line] = o_message;
this.addChild(o_message);
}
CommunicationBar.prototype.checkMessagesAge = function() {
for (var line=0; line < this.lines.length; line++) {
var o_message = this.lines[line];
if (o_message.getAge() > MSG_BAR_DELAY) {
// Delete expired message
this.removeChild(o_message);
// Shift following messages
for (var v = line+1; v < this.lines.length; v++) {
if (v <= this.lines.length) {
this.lines[v].setStackPosition(v - 1);
}
}
// Delete from array
this.lines.splice(line,1);
return;
}
}
}
function Message(msg, width, color) {
this.Container_constructor();
this.color = color;
this.gBox = new createjs.Shape();
this.gBox.graphics.setStrokeStyle(1).beginStroke(color).beginFill(color).dr(0,0,width,18);
this.gBox.x = 0;
this.gBox.y = 5;
this.gMsg = new createjs.Text("", "normal 15px Courier", MSG_COLOR);
this.gMsg.text = msg;
this.gMsg.lineHeight = 14;
this.gMsg.x = 5;
this.gMsg.y = 0;
this.stackPosition = -1;
this.timeDisplay = new Date().getTime();
this.addChild(this.gBox, this.gMsg);
}
createjs.extend(Message, createjs.Container);
createjs.promote(Message, "Container");
Message.prototype.setX = function(x) {
this.x = x;
}
Message.prototype.setY = function(y) {
this.y = y;
}
Message.prototype.setWidth = function(w) {
this.gBox.graphics.clear();
this.gBox.graphics.setStrokeStyle(1).beginStroke(this.color).beginFill(this.color).dr(0,0,w,18);
}
Message.prototype.setStackPosition = function(p) {
this.stackPosition = p;
this.gBox.y = p * 20;
this.gMsg.y = p * 20;
}
Message.prototype.getAge = function() {
return ((new Date().getTime()) - this.timeDisplay) / 1000;
}