-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdialog.js
75 lines (58 loc) · 1.99 KB
/
dialog.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
var dialog = document.getElementById("dialog");
dialog.buttons = [];
function create_button(textContent, x, y, func) {
var btn = clone_to("dialog-button-model", dialog)
var rect = btn.children[0];
var text = btn.children[1];
btn.addEventListener("click", function(){exec_and_close(func)});
rect.setAttribute("x", x);
rect.setAttribute("y", y);
text.setAttribute("x", 300/2+x);
text.setAttribute("y", y+20);
text.textContent = textContent;
return btn;
}
function show_fear_dialog() {
var fears =
[[jerry.fears.water , "Agua" ,
function(){
jerry.fears.water =false
}],
[jerry.fears.forest, "Bosque" ,
function(){jerry.fears.forest=false}],
[jerry.fears.hill , "Alturas" ,
function(){jerry.fears.hill =false}],
[jerry.fears.lava , "Lava" ,
function(){jerry.fears.lava =false}],
[jerry.fears.shadow, "Oscuridad",
function(){jerry.fears.shadow=false}],
[jerry.fears.spider, "Araña" ,
function(){jerry.fears.spider=false}],];
var col1 = 50 + (700-600)/3;
var col2 = col1 + 300 + (700-600)/3;
var row = 130;
var row_offset = 60;
var toggle = 0;
var i;
for (i in fears) {
if (fears[i][0])
dialog.buttons.push(create_button(fears[i][1],
toggle?col2:col1, row,
fears[i][2]));
row += toggle ? row_offset : 0;
toggle = (++toggle)%2;
}
dialog.setAttribute("visibility", "visible");
}
jerry.gem_event = show_fear_dialog;
function exec_and_close(func) {
func();
close_fear_dialog();
}
function close_fear_dialog() {
var i;
for (i in dialog.buttons)
remove_from_dom(dialog.buttons[i]);
dialog.buttons = [];
dialog.setAttribute("visibility", "hidden");
}