-
Notifications
You must be signed in to change notification settings - Fork 10
/
ui.js
101 lines (85 loc) · 2.15 KB
/
ui.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
showInterface = true;
autoRotateCamera = false;
function
hex2rgb(hex) {
let r = parseInt(hex.slice(1, 3), 16);
let g = parseInt(hex.slice(3, 5), 16);
let b = parseInt(hex.slice(5, 7), 16);
return [r, g, b];
}
function
updateVehicleCustomColors() {
let colors = [];
for(let i = 0; i < 4; i++) {
let cStr = document.getElementById("custom-color" + i).value;
let c = hex2rgb(cStr);
c[3] = 255;
colors[i] = c;
}
setVehicleColors(modelinfo, colors[0], colors[1], colors[2], colors[3]);
}
for(let i = 0; i < 4; i++) {
document.getElementById("custom-color" + i).addEventListener("input", updateVehicleCustomColors, false);
}
document.addEventListener("keypress",
function(e) {
if(e.key === "i") {
showInterface = !showInterface;
document.querySelectorAll(".ui").forEach((v) => {
v.style.visibility = showInterface ? "unset" : "hidden";
});
}
else if(e.key === "r") {
autoRotateCamera = !autoRotateCamera;
}
},
false);
document.getElementById("objects").addEventListener("keypress",
function(e) {
e.preventDefault();
return false;
},
false);
var lastModelChangeViaKey = 0;
document.getElementById("objects").addEventListener("keydown",
function(e) {
if(e.keyCode !== 38 && e.keyCode !== 40) {
return true;
}
if(Date.now() - lastModelChangeViaKey < 750) {
e.preventDefault();
return false;
}
lastModelChangeViaKey = Date.now();
},
false);
document.getElementById("objects").addEventListener("keyup",
function(e) {
if(e.keyCode !== 38 && e.keyCode !== 40) {
return true;
}
lastModelChangeViaKey -= 400;
let model = document.getElementById("objects").value;
if(model !== CurrentModel.model) {
SelectModel(model);
}
},
false);
function
uiSetCurrentGame(game) {
document.querySelectorAll("#control a").forEach((v) => {
v.classList.remove("active");
});
let gameSelect = document.getElementById("game-select-" + game);
gameSelect.classList.add("active");
}
function
uiSetCurrentModel(model) {
let l = document.querySelectorAll("#objects option");
for(let i = 0; i < l.length; i++) {
if(l[i].value === model) {
l[i].selected = 'selected';
break;
}
}
}