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
function _controller_panel(div, view, callback) { var btn; var spn_next; var sel_next; var b_show_next = true; var panel = document.createElement("div"); panel.className = "controller-panel"; for (var i = 1; i <= 3; i++) { if (i == 2) { var pain = document.createElement("div"); spn_next = document.createElement("span"); pain.appendChild(spn_next); sel_next = document.createElement("select"); sel_next.addEventListener("change", function() { var index = this.selectedIndex; if (!b_show_next) index--; setTimeout(update, 0, next_sasite[index]); }); pain.appendChild(sel_next); panel.appendChild(pain); continue; } btn = _util.create_element("button", _label.PLAYER[i]); btn.addEventListener(_pointer.PRESSED, mouse_down); btn.addEventListener(_pointer.RELEASED, mouse_up); panel.appendChild(btn); } var ta_comment = document.createElement("textarea"); ta_comment.addEventListener("change", function() { view.get_kyokumen().sasite.comment = ta_comment.value; }); panel.appendChild(ta_comment); div.appendChild(panel); var kyokumen_changed = callback; var kyokumen_stack = new Array(); var sasite_tree = new _sasite_tree(); this.get_sasite_tree = function() { return sasite_tree; } this.set_sasite_tree = function(tree) { sasite_tree = tree; kyokumen_stack.length = 0; update(); } var repeat_timer = null; function stop_repeat_timer() { stop_long_timer(); step = 0; if (repeat_timer == null) return; clearInterval(repeat_timer); repeat_timer = null; } this.stop_repeat_timer = stop_repeat_timer; var long_timer = null; function stop_long_timer() { if (long_timer == null) return; clearTimeout(long_timer); long_timer = null; } var step = 0; function mouse_down(e) { stop_repeat_timer(); var index = _label.PLAYER.indexOf(_util.get_text(e.target)); step = index - 2; long_timer = setTimeout(repeat_start, 500); setTimeout(update, 0); } function mouse_up(e) { stop_repeat_timer(); } var speed = 400; function repeat_start() { long_timer = null; repeat_timer = setInterval(update, speed); update(); } var next_sasite = null; function update(sasite) { var kyokumen; if (sasite != undefined || step > 0) { if (sasite == undefined) { if (next_sasite == null) { stop_repeat_timer(); return; } sasite = next_sasite[0]; } kyokumen = view.get_kyokumen(); kyokumen_stack.push(kyokumen); sasite = sasite_tree.move_sasite(sasite); kyokumen = kyokumen.get_next_kyokumen(sasite); } else if (step == 0) { kyokumen = view.get_kyokumen(); sasite = kyokumen.sasite; } else if (step < 0) { if (kyokumen_stack.length == 0) { stop_repeat_timer(); return; } kyokumen = kyokumen_stack.pop(); sasite_tree.back_sasite(); sasite = kyokumen.sasite; } ta_comment.value = sasite.comment; kyokumen_changed(kyokumen_stack.length, kyokumen, sasite); set_next_sasite(); } this.update = update; function set_next_sasite() { next_sasite = sasite_tree.get_next_sasite(); if (next_sasite == null || next_sasite.length == 1) { sel_next.style.display = "none"; _util.set_text(spn_next, (next_sasite == null) ? "" : (b_show_next) ? next_sasite[0].to_string() : "?"); spn_next.style.display = "inline"; } else { spn_next.style.display = "none"; _util.set_options(sel_next, next_sasite, b_show_next); sel_next.style.display = "inline"; } } this.set_speed = function(val) { speed = val; stop_long_timer(); if (repeat_timer == null) return; clearInterval(repeat_timer); repeat_timer = setInterval(update, speed); } this.get_start_kyokumen = function() { return (kyokumen_stack.length != 0) ? kyokumen_stack[0] : view.get_kyokumen(); } this.can_remove = function() { return kyokumen_stack.length != 0; } this.remove_after = function() { if (!this.can_remove()) return; sasite_tree.remove_after(); view.set_kyokumen(kyokumen_stack.pop()); update(); } this.remove_before = function() { if (!this.can_remove()) return; sasite_tree.remove_before(); kyokumen_stack.length = 0; update(); } this.get_sasite_path = function() { var path = new Array(); for (var i = 1; i < kyokumen_stack.length; i++) path.push(kyokumen_stack[i].sasite); path.push(view.get_kyokumen().sasite); return path; } this.move_to_start = function() { view.set_kyokumen(this.get_start_kyokumen()); sasite_tree.move_to_start(); kyokumen_stack.length = 0; update(); } this.back = function() { if (kyokumen_stack.length == 0) return; set_kyokumen(kyokumen_stack.pop()); } this.next = function(sasite) { var kyokumen = view.get_kyokumen(); kyokumen_stack.push(kyokumen); set_kyokumen(kyokumen.get_next_kyokumen(sasite)); } function set_kyokumen(kyokumen) { kyokumen_changed(kyokumen_stack.length, kyokumen, kyokumen.sasite); } this.set_show_next = function(b) { b_show_next = b; set_next_sasite(); } }