forked from robx/pzprjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToolArea.js
More file actions
384 lines (362 loc) · 11.4 KB
/
Copy pathToolArea.js
File metadata and controls
384 lines (362 loc) · 11.4 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
// ToolArea.js v3.4.0
/* global getEL:readonly */
// メニュー描画/取得/html表示系
// toolareaオブジェクト
ui.toolarea = {
items: null, // ツールパネルのエレメント等を保持する
captions: [], // 言語指定を切り替えた際のキャプションを保持する
//---------------------------------------------------------------------------
// toolarea.reset() ツールパネル・ボタン領域の初期設定を行う
//---------------------------------------------------------------------------
reset: function() {
if (this.items === null) {
this.items = {};
this.walkElement(getEL("usepanel"));
this.walkElement(getEL("checkpanel"));
this.walkElement(getEL("variantpanel"));
this.walkElement(getEL("btnarea"));
}
ui.misc.displayByPid(getEL("checkpanel"));
ui.misc.displayByPid(getEL("btnarea"));
this.display();
},
//---------------------------------------------------------------------------
// toolarea.walkElement() エレメントを探索して領域の初期設定を行う
//---------------------------------------------------------------------------
walkElement: function(parent) {
var toolarea = this;
function btnfactory(role) {
return function(e) {
toolarea[role](e);
if (e.type !== "click") {
e.stopPropagation();
}
};
}
function addbtnevent(el, type, role) {
pzpr.util.addEvent(el, type, toolarea, btnfactory(role));
}
ui.misc.walker(parent, function(el) {
if (el.nodeType === 1) {
/* ツールパネル領域 */
var parent, idname;
if (el.className === "config") {
toolarea.items[ui.customAttr(el, "config")] = { el: el };
} else if (el.className.match(/child/)) {
(parent = el.parentNode.parentNode),
(idname = ui.customAttr(parent, "config"));
var item = toolarea.items[idname];
if (!item.children) {
item.children = [];
}
item.children.push(el);
addbtnevent(el, "mousedown", "toolclick");
} else if (el.nodeName === "INPUT" && el.type === "checkbox") {
(parent = el.parentNode), (idname = ui.customAttr(parent, "config"));
if (!idname) {
(parent = parent.parentNode),
(idname = ui.customAttr(parent, "config"));
}
if (!idname) {
return;
}
toolarea.items[idname].checkbox = el;
addbtnevent(el, "click", "toolclick");
}
/* ボタン領域 */
var role = ui.customAttr(el, "buttonExec");
if (!!role) {
addbtnevent(
el,
!pzpr.env.API.touchevent ? "click" : "mousedown",
role
);
}
role = ui.customAttr(el, "pressExec");
if (!!role) {
var roles = role.split(/,/);
addbtnevent(el, "mousedown", roles[0]);
if (!!roles[1]) {
addbtnevent(el, "mouseup", roles[1]);
addbtnevent(el, "mouseleave", roles[1]);
addbtnevent(el, "touchcancel", roles[1]);
}
}
} else if (el.nodeType === 3) {
if (el.data.match(/^__(.+)__$/)) {
var str_key = RegExp.$1;
toolarea.captions.push({
textnode: el,
str_key: str_key
});
parent = el.parentNode;
if (parent.className.match(/child/)) {
toolarea.captions.push({
datanode: parent,
str_key: str_key
});
}
}
}
});
},
//---------------------------------------------------------------------------
// toolarea.display() 全てのラベルに対して文字列を設定する
// toolarea.displayVariantPanel() display the variant panel
// toolarea.setdisplay() 管理パネルに表示する文字列を個別に設定する
//---------------------------------------------------------------------------
display: function() {
/* ツールパネル領域 */
/* -------------- */
var mandisp = ui.menuconfig.get("toolarea") ? "block" : "none";
getEL("usepanel").style.display = mandisp;
getEL("checkpanel").style.display = mandisp;
/* 経過時間の表示/非表示設定 */
var hasTimer = ui.puzzle.playeronly && ui.menuconfig.get("timer");
getEL("separator2").style.display =
hasTimer && ui.menuconfig.get("toolarea") ? "" : "none";
getEL("timerpanel").style.display = hasTimer ? "block" : "none";
this.displayVariantPanel();
for (var idname in this.items) {
this.setdisplay(idname);
}
/* ボタン領域 */
/* --------- */
getEL("btnarea").style.display = "";
pzpr.util.unselectable(getEL("btnarea"));
this.setdisplay("operation");
getEL("btnclear2").style.display = !ui.puzzle.board.disable_subclear
? ""
: "none";
getEL("btncolor").style.display =
ui.puzzle.pid === "tentaisho" ? "" : "none";
getEL("btnflush").style.display =
ui.puzzle.board.hasflush && !ui.puzzle.playeronly ? "" : "none";
getEL("btnpresets").style.display =
ui.puzzle.board.bank &&
ui.puzzle.board.bank.presets.length &&
!ui.puzzle.playeronly
? ""
: "none";
/* ボタンエリアの色分けボタンは、ツールパネル領域が消えている時に表示 */
getEL("btnirowake").style.display =
ui.puzzle.painter.irowake && !ui.menuconfig.get("toolarea") ? "" : "none";
getEL("btnirowakeblk").style.display =
ui.puzzle.painter.irowakeblk && !ui.menuconfig.get("toolarea")
? ""
: "none";
this.setdisplay("trialmode");
this.setdisplay("network");
/* 共通:キャプションの設定 */
/* --------------------- */
for (var i = 0; i < this.captions.length; i++) {
var obj = this.captions[i];
if (!!obj.textnode) {
obj.textnode.data = ui.i18n(obj.str_key);
}
if (!!obj.datanode) {
obj.datanode.setAttribute("data-text", ui.i18n(obj.str_key));
}
}
},
displayVariantPanel: function() {
// display if the type has variants, and we're in edit mode or some
// variants are enabled
var shouldDisplay = (function() {
if (!ui.menuconfig.get("toolarea")) {
return false;
}
var variants = ui.puzzle.config.getVariants();
if (Object.keys(variants).length <= 0) {
return false;
}
if (!ui.puzzle.playeronly) {
return true;
}
for (var key in variants) {
if (variants[key]) {
return true;
}
}
})();
var vardisp = shouldDisplay ? "block" : "none";
getEL("separator1").style.display = vardisp;
getEL("variantpanel").style.display = vardisp;
if (ui.puzzle.playeronly) {
getEL("variantpanel").classList.add("playeronly");
}
},
setdisplay: function(idname) {
if (idname === "variant") {
var str;
if (ui.menuconfig.get("variant")) {
str = ui.i18n("check.variant");
} else {
str = ui.i18n("check");
}
getEL("btncheck").textContent = str;
}
var trial = ui.puzzle.board.trialstage > 0;
var net = ui.network.mode !== "";
if (idname === "operation") {
var opemgr = ui.puzzle.opemgr;
getEL("btnundo").disabled = !opemgr.enableUndo;
getEL("btnredo").disabled = !opemgr.enableRedo;
getEL("btntriale").disabled = opemgr.atStartOfTrial();
} else if (idname === "trialmode") {
getEL("btnclear").disabled = trial;
getEL("btntrial").disabled = trial;
getEL("btntrialarea").style.display = trial && !net ? "block" : "none";
} else if (idname === "network") {
getEL("btnundo").style.display = net ? "none" : "inline";
getEL("btnredo").style.display = net ? "none" : "inline";
getEL("btntrial").style.display = net ? "none" : "inline";
getEL("btntrialarea").style.display = trial && !net ? "block" : "none";
} else if (this.items === null || !this.items[idname]) {
/* DO NOTHING */
} else if (ui.menuconfig.valid(idname)) {
var toolitem = this.items[idname];
toolitem.el.style.display = "";
if (idname === "mode") {
this.displayVariantPanel();
}
var disabled = null;
/* 子要素の設定を行う */
if (!!toolitem.children) {
var children = toolitem.children;
var validval =
idname === "inputmode"
? ui.puzzle.mouse.getInputModeList()
: idname === "auxeditor_inputmode"
? ui.auxeditor.puzzle.mouse.getInputModeList()
: null;
for (var i = 0; i < children.length; i++) {
var child = children[i],
value = ui.customAttr(child, "value"),
selected = value === "" + ui.menuconfig.get(idname);
child.className = selected ? "child childsel" : "child";
child.style.display =
validval === null || validval.indexOf(value) >= 0 ? "" : "none";
}
if (idname === "inputmode") {
disabled = validval.length === 1;
}
if (disabled !== null) {
toolitem.el.className = !disabled ? "" : "disabled";
}
} else if (!!toolitem.checkbox) {
/* チェックボックスの表記の設定 */
var check = toolitem.checkbox;
if (!!check) {
check.checked = ui.menuconfig.get(idname);
}
if (idname === "keypopup") {
disabled = !ui.keypopup.paneltype[ui.puzzle.editmode ? 1 : 3];
}
if (idname === "bgcolor") {
disabled = ui.puzzle.editmode;
}
if (idname === "mouseonly") {
disabled = ui.puzzle.editmode && ui.puzzle.pid === "magnets";
}
if (ui.puzzle.config.getvariant(idname)) {
disabled = !ui.puzzle.editmode;
}
if (disabled !== null) {
toolitem.checkbox.disabled = !disabled ? "" : "true";
}
}
} else if (!!this.items[idname]) {
this.items[idname].el.style.display = "none";
}
},
//---------------------------------------------------------------------------
// toolarea.toolclick() ツールパネルの入力があった時、設定を変更する
//---------------------------------------------------------------------------
toolclick: function(e) {
var el = e.target,
parent = el.parentNode;
var idname =
ui.customAttr(parent, "config") ||
ui.customAttr(parent.parentNode, "config"),
value;
if (!!this.items[idname].checkbox) {
value = !!el.checked;
} else {
value = ui.customAttr(el, "value");
}
ui.menuconfig.set(idname, value);
},
//---------------------------------------------------------------------------
// Canvas下にあるボタンが押された/放された時の動作
//---------------------------------------------------------------------------
answercheck: function() {
ui.menuarea.answercheck();
},
undo: function() {
ui.auxeditor.close(true);
ui.undotimer.startUndo();
},
undostop: function() {
ui.undotimer.stopUndo();
},
redo: function() {
ui.auxeditor.close(true);
ui.undotimer.startRedo();
},
redostop: function() {
ui.undotimer.stopRedo();
},
ansclear: function() {
ui.menuarea.answerclear();
},
subclear: function() {
ui.menuarea.submarkclear();
},
irowake: function() {
ui.puzzle.irowake();
},
encolorall: function() {
ui.puzzle.board.encolorall();
} /* 天体ショーのボタン */,
dropblocks: function() {
ui.puzzle.board.operate("drop");
},
resetblocks: function() {
ui.puzzle.board.operate("resetpos");
},
outlineshaded: function() {
ui.puzzle.board.operate("outlineshaded");
},
flushexcell: function() {
ui.puzzle.board.flushexcell();
},
traceroute: function() {
ui.puzzle.board.operate("traceroute");
},
applypreset: function(e) {
ui.auxeditor.close();
ui.popupmgr.open("applypreset", 0, 0);
var rect = pzpr.util.getRect(getEL("btnarea"));
var bounds = pzpr.util.getRect(getEL("popapplypreset"));
ui.popupmgr.open(
"applypreset",
rect.left + (rect.width - bounds.width) / 2,
Math.max(16, rect.top - bounds.height - 16)
);
},
enterTrial: function() {
if (ui.puzzle.board.trialstage === 0) {
ui.puzzle.enterTrial();
}
},
enterFurtherTrial: function() {
ui.puzzle.enterTrial();
},
acceptTrial: function() {
ui.puzzle.acceptTrial();
},
rejectTrial: function() {
ui.puzzle.rejectCurrentTrial();
}
};