-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGui.Warning.js
executable file
·101 lines (88 loc) · 3.29 KB
/
Gui.Warning.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
Gui.Warning = function(guiConfig){
this.guiConfig = guiConfig;
this.createContainer();
this.regenerate();
};
Gui.Warning.prototype = {
guiConfig: null,
container: null,
createContainer: function(){
this.container = document.createElement('div');
Gui.css(this.container, {position:'absolute', width: '1025px', top:'50px', left:'50px', zIndex:500, backgroundColor:'white', color:'black',fontSize:'12px', padding: '5px', border:'1px solid green', WebkitBorderRadius:'5px', borderRadius:'5px'});
this.guiConfig.gui.layerContainer.appendChild(this.container);
},
regenerate: function(){
this.container.innerHTML = '';
this.addHeader();
this.addCloseButton();
var config = this.guiConfig.gui.config;
var notWarning = this.guiConfig.used;
var n = 0;
for (var key in config) if (config.hasOwnProperty(key) && !notWarning[key]) this.createOption(key, !(++n%5));
this.addCloseButton();
},
addHeader: function(){
var top = document.createElement('div');
Gui.css(top, {height: '1px', backgroundColor: 'black', position: 'relative', top: '-2px', cursor: 'move', userSelect: 'none', WebkitUserSelect: 'none', MozUserSelect: 'none', border: '2px solid black', WebkitBorderRadius:'3px', borderRadius:'3px'});
this.container.appendChild(top);
top.onmousedown = this.dragStart.bind(this);
var head = document.createElement('div');
head.innerHTML = '<b>Warning toggles</b><br/>';
this.container.appendChild(head);
},
createOption: function(desc, cl){
var config = this.guiConfig.gui.config;
var e = document.createElement('div');
Gui.css(e, {cursor: 'pointer', width: '200px', height: '20px',marginRight: '5px', cssFloat: 'left', clear:cl?'left':'none', overflow:'hidden', 'white-space':'pre'});
e.innerHTML = '<input type="checkbox" '+(config[desc]?'checked ':'')+'/> '+desc;
e.onclick = function(){
config[desc] = !config[desc];
// element we defined above should only have one input...
e.getElementsByTagName('input')[0].checked = config[desc];
if (window.localStorage) {
window.localStorage.setItem('zeon-config', JSON.stringify(config));
}
}.bind(this);
this.container.appendChild(e);
},
addCloseButton: function(){
var e = document.createElement('div');
Gui.css(e, {cursor: 'pointer', clear:'left'});
e.innerHTML = 'close';
e.onclick = function(){
this.close();
}.bind(this);
this.container.appendChild(e);
},
close: function(){
this.container.parentNode.removeChild(this.container);
this.guiConfig.guiWarning = null;
this.guiConfig = null;
},
dragStart: function(e){
this.dragStartMouse = {x:e.clientX, y:e.clientY};
this.dragStartPos = this.getContainerPosition();
document.body.onmousemove = this.dragMove.bind(this);
document.body.onmouseup = this.dragStop.bind(this);
},
dragMove: function(e){
if (this.dragStartMouse) {
Gui.css(this.container, {
left: this.dragStartPos.x + (e.clientX - this.dragStartMouse.x) + 'px',
top: this.dragStartPos.y + (e.clientY - this.dragStartMouse.y) + 'px'
});
}
},
dragStop: function(){
document.body.onmousemove = null;
document.body.onmouseup = null;
this.dragStartMouse = null;
this.dragStartPos = null;
},
getContainerPosition: function(){
return {
x:parseInt(Gui.css(this.container,'left'),10),
y:parseInt(Gui.css(this.container,'top'), 10)
};
},
0:0};