forked from mengxinzxz/decadeUI--mx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
component.js
117 lines (102 loc) · 3.48 KB
/
component.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
'use strict';
decadeModule.import(function(lib, game, ui, get, ai, _status){
decadeUI.component = {
slider:function(min, max, value){
var slider = document.createElement('input');
var onchange = function(){
var percent = ((slider.value - slider.min) / (slider.max - slider.min)) * 100;
slider.style.backgroundSize = percent + '% ' + '100%';
};
var valueProp = Object.getOwnPropertyDescriptor(slider.__proto__, 'value');
Object.defineProperties(slider, {
value: {
configurable: true,
get:function(){
return valueProp.get.call(this);
},
set:function(value){
valueProp.set.call(this, value);
onchange();
}
}
});
slider.className = 'slider';
slider.type = 'range';
slider.addEventListener('input', onchange);
slider.min = (typeof min == 'number') ? min : 0;
slider.max = (typeof max == 'number') ? max : 100;
slider.value = (typeof value == 'number') ? value : ((max - min) * 0.5);
return slider;
},
chatBox:function(){
var box = decadeUI.dialog.create('chat-box folded');
box.container = decadeUI.dialog.create('container', box);
box.operation = decadeUI.dialog.create('operation', box);
box.content = decadeUI.dialog.create('content', box.container);
box.operation.fold = decadeUI.dialog.create('fold-button', box.operation, 'button');
box.operation.input = decadeUI.dialog.create('chat-input', box.operation, 'input');
box.operation.sticker = decadeUI.dialog.create('sticker-button', box.operation, 'button');
box.operation.send = decadeUI.dialog.create('send-button', box.operation, 'button');
box.operation.fold.innerHTML = '…';
box.operation.sticker.innerHTML = '表情';
box.operation.send.innerHTML = '发送';
box.addEntry = function(info){
var text = decadeUI.dialog.create('chat-text', box.content);
text.innerHTML = '<span class="sender">' + info[0] + '</span>:' + '<span class="text">' + info[1] + '</span>';
if (box.overrideEntry) box.overrideEntry(info);
box.content.scrollTop = box.content.scrollHeight;
};
box.addEntry._origin = box;
box.sendInputText = function(){
if (input.value) {
var player = game.me;
var str = input.value;
if (!player) {
if (game.connectPlayers) {
if (game.online) {
for (var i = 0; i < game.connectPlayers.length; i++) {
if (game.connectPlayers[i].playerid == game.onlineID) {
player = game.connectPlayers[i];
break;
}
}
} else {
player = game.connectPlayers[0];
}
}
}
if (!player) return;
if (game.online) {
game.send('chat', game.onlineID, str);
} else {
lib.element.player.chat.call(player, str);
}
input.value = '';
_status.chatValue = '';
}
};
var input = box.operation.input;
box.operation.fold.addEventListener('click', function(){
if (box.classList.contains('folded')) {
box.operation.fold.innerHTML = '<<';
box.classList.remove('folded');
} else {
box.operation.fold.innerHTML = '…';
box.classList.add('folded');
}
});
box.operation.send.addEventListener('click', function(){
box.sendInputText();
input.focus();
});
input.addEventListener('change', function(e){
_status.chatValue = input.value;
});
input.addEventListener('keydown', function(e){
if (e.keyCode == 13) box.sendInputText();
e.stopPropagation();
});
return box;
},
};
});