Skip to content

Commit e192b48

Browse files
committed
Update for v0.27.4
1 parent 2e9344d commit e192b48

File tree

6 files changed

+176
-36
lines changed

6 files changed

+176
-36
lines changed

MMD.js/MMD_SA.js

Lines changed: 113 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// MMD for System Animator
2-
// (2024-08-18)
2+
// (2024-09-15)
33

44
var use_full_spectrum = true
55

@@ -2913,18 +2913,45 @@ if ((msg.length > column_max) && ((para.auto_wrap || b.auto_wrap) || (msg.indexO
29132913
else
29142914
msg_line = msg.split("\n")
29152915

2916-
this.msg_line = msg_line
2916+
this.msg_line = msg_line;
29172917

2918+
const msg_obj_old = this.msg_obj;
29182919
this.msg_obj = msg_line.map(msg=>{
29192920
return {};
29202921
});
29212922

29222923
var w_max = 0, h_max = font_size
2923-
for (var i = 0, i_length = msg_line.length; i < i_length; i++) {
2924-
const m = context.measureText(msg_line[i]);
2924+
for (let i = 0, i_length = msg_line.length; i < i_length; i++) {
2925+
const _msg = msg_line[i];
2926+
const m = context.measureText(_msg);
29252927
this.msg_obj[i].w = m.width;
29262928
if (w_max < m.width)
29272929
w_max = m.width;
2930+
2931+
let b_length;
2932+
if (_msg.indexOf('➕➖') == _msg.length-2) {
2933+
b_length = 2;
2934+
}
2935+
else if (_msg.indexOf('⬅️➡️') == _msg.length-4) {
2936+
b_length = 4;
2937+
}
2938+
2939+
if (b_length) {
2940+
const msg_width = context.measureText(_msg.substring(0, _msg.length-b_length)).width;
2941+
const button_width = context.measureText(_msg.substring(_msg.length-b_length)).width;
2942+
2943+
const ev = (b_length == 2) ? [{ key:'+' }, { key:'-' }] : [{ code:'ArrowLeft' }, { code:'ArrowRight' }];
2944+
2945+
const id = _msg.replace(/\:.+$/, '');
2946+
const b_list_old = msg_obj_old?.[i]?.b_list;
2947+
const msg_identical = id == b_list_old?.[0].id;
2948+
2949+
this.msg_obj[i].b_list = [
2950+
{ id:id, w:msg_width, _mouse_:(msg_identical)?b_list_old[0]._mouse_:{} },
2951+
{ w:msg_width+button_width/2, event:ev[0], _mouse_:(msg_identical)?b_list_old[1]._mouse_:{}, b:_msg.substring(_msg.length-b_length, _msg.length-b_length/2) },
2952+
{ w:msg_width+button_width, event:ev[1], _mouse_:(msg_identical)?b_list_old[2]._mouse_:{}, b:_msg.substring(_msg.length-b_length/2, _msg.length) },
2953+
];
2954+
}
29282955
}
29292956

29302957
var w = w_max
@@ -3285,6 +3312,8 @@ window.addEventListener('MMDStarted', ()=>{
32853312
}
32863313
}
32873314

3315+
ignore_click = false;
3316+
32883317
let is_pointer = false;
32893318
bb_list.forEach(sb=>{
32903319
if (!sb.visible || (mouse_x == null)) {
@@ -3339,16 +3368,20 @@ window.addEventListener('MMDStarted', ()=>{
33393368
return;
33403369
}
33413370

3342-
let msg_obj;
3371+
let msg_obj, msg_obj_index;
33433372
for (let i = sb.msg_obj.length-1; i >= 0; i--) {
33443373
const obj = sb.msg_obj[i];
33453374
if ((pos.x > obj.x) && (pos.y > obj.y)) {
3346-
if ((pos.x-obj.x < obj.w*1.2) && ((i < sb.msg_obj.length-1) || (pos.y-obj.y < obj.h*1.2)))
3375+
if ((pos.x-obj.x < obj.w*1.2) && ((i < sb.msg_obj.length-1) || (pos.y-obj.y < obj.h*1.2))) {
33473376
msg_obj = sb.msg_obj[i];
3377+
msg_obj_index = i;
3378+
}
33483379
break;
33493380
}
33503381
}
33513382

3383+
let is_no_click_zone;
3384+
33523385
let mouseover = msg_obj?.branch_key != null;
33533386
if ((msg_obj?.branch_key != null) ? sb._branch_key_ != msg_obj.branch_key : sb._branch_key_ != null) {
33543387
sb._branch_key_ = (msg_obj?.branch_key != null) ? msg_obj.branch_key : null;
@@ -3357,17 +3390,52 @@ window.addEventListener('MMDStarted', ()=>{
33573390
const branch = get_target_branch(sb, sb._branch_key_);
33583391
if (branch) {
33593392
mouseover = branch.onmouseover;
3360-
mouseover?.({ clientX:mouse_x, clientY:mouse_y });
3393+
branch.onmouseover?.({ clientX:mouse_x, clientY:mouse_y });
33613394
}
33623395
//DEBUG_show(sb._branch_key_+'/'+Date.now())
33633396
}
3397+
else if (msg_obj?.b_list) {
3398+
const x = pos.x - msg_obj.x;
3399+
const b = msg_obj.b_list.find(b=>b._mouse_.down) || msg_obj.b_list.find((b,i)=>{
3400+
return (b.b && (x > (msg_obj.b_list[i-1]?.w||0)) && (x < b.w));
3401+
});
3402+
3403+
is_no_click_zone = !b;
3404+
3405+
if (b && mouse_down) {
3406+
ignore_click = true;
3407+
3408+
let b_clicked;
3409+
if (!b._mouse_.down) {
3410+
b._mouse_.down = mouse_down;
3411+
b_clicked = true;
3412+
}
3413+
else {
3414+
b._mouse_.down += RAF_timestamp_delta;
3415+
if (mouse_down + 500 < b._mouse_.down) {
3416+
b._mouse_.click_interval += RAF_timestamp_delta;
3417+
b_clicked = b._mouse_.click_interval > 1000/15;
3418+
}
3419+
}
3420+
3421+
if (b_clicked) {
3422+
b._mouse_.click_interval = 0;
3423+
document.dispatchEvent(new KeyboardEvent('keydown', b.event));
3424+
//DEBUG_show(msg_obj_index+'/'+(b?.b||'')+'/'+JSON.stringify(b.event)+'/'+Date.now())
3425+
}
3426+
//DEBUG_show(msg_obj_index+'/'+(b?.b||'')+'/'+Date.now())
3427+
}
3428+
else {
3429+
msg_obj.b_list.forEach(b=>{ b._mouse_.down=null; });
3430+
}
3431+
}
33643432

33653433
if (!mouseover) {
33663434
document.getElementById('SB_tooltip').style.visibility = 'hidden';
33673435
//MMD_SA_options.Dungeon.inventory._item_updated?.update_info(null, true);
33683436
}
33693437

3370-
is_pointer = is_pointer || (sb._branch_key_ != null);
3438+
is_pointer = is_pointer || (!is_no_click_zone && (sb._branch_key_ != null));
33713439
// DEBUG_show(pos.toArray().join('\n')+'\n\n'+((msg_obj)?msg_obj.branch_index:-1));
33723440
});
33733441

@@ -3416,7 +3484,8 @@ window.addEventListener('MMDStarted', ()=>{
34163484
MMD_SA._trackball_camera.enabled = false;
34173485
}
34183486
else {
3419-
cursor = 'not-allowed';
3487+
if (!ignore_click)
3488+
cursor = 'not-allowed';
34203489
}
34213490
}
34223491
}
@@ -3487,9 +3556,18 @@ window.addEventListener('MMDStarted', ()=>{
34873556
drag_target = [sb, sb._branch_key_];
34883557
});
34893558

3559+
let ignore_click;
3560+
let ignore_dblclick;
34903561
const ev_mouse_up = (!is_mobile) ? 'click' : 'touchend';
34913562
d_target.addEventListener(ev_mouse_up, (e)=>{
34923563
mouse_down = null;
3564+
if (ignore_click) {
3565+
ignore_click = false;
3566+
ignore_dblclick = true;
3567+
System._browser.on_animation_update.add(()=>{ ignore_dblclick=false; }, 0,0);
3568+
return;
3569+
}
3570+
34933571
cursor = null;
34943572
drag_target = null;
34953573

@@ -3552,6 +3630,13 @@ window.addEventListener('MMDStarted', ()=>{
35523630
SA_OnKeyDown(ev);
35533631
});
35543632

3633+
d_target.addEventListener('dblclick', (e)=>{
3634+
if (ignore_dblclick) {
3635+
ignore_dblclick = false;
3636+
e.stopPropagation();
3637+
}
3638+
});
3639+
35553640
// https://stackoverflow.com/questions/11586527/converting-world-coordinates-to-screen-coordinates-in-three-js-using-projection
35563641

35573642
System._browser.on_animation_update.add(highlight, 0,0,-1);
@@ -9662,6 +9747,21 @@ obj_pos.x*sign, obj_pos.y, -obj_pos.z*sign,
96629747
-obj_rot.x*sign, -obj_rot.y, obj_rot.z*sign, obj_rot.w,
96639748
]);
96649749

9750+
if ((x_object._tracker_scale_ != obj.scale.x) || !x_object._tracker_scale_counter_) {
9751+
x_object._tracker_scale_ = obj.scale.x;
9752+
x_object._tracker_scale_counter_ = 60;
9753+
9754+
const _tracker_index = ((x_object.VMC_tracker_index != null) ? x_object.VMC_tracker_index : tracker_index);
9755+
if (warudo_mode) {
9756+
const msg = 'XRAnimator|set_tracker_scale|' + (_tracker_index + ((_tracker_index < 10) ? ' ' : '')) + '|' + (x_object._tracker_scale_ * model_pos_scale);
9757+
System._browser.WebSocket.send_message('ws://localhost:19190', msg);
9758+
//console.log(msg)
9759+
}
9760+
}
9761+
else if (x_object._tracker_scale_counter_) {
9762+
x_object._tracker_scale_counter_--;
9763+
}
9764+
96659765
tracker_index++;
96669766
}
96679767
});
@@ -13959,7 +14059,7 @@ switch (command) {
1395914059
break;
1396014060
}
1396114061

13962-
let keyCode;
14062+
let key, keyCode;
1396314063
if (/^[A-Z]$/.test(code)) {
1396414064
code = 'Key' + code;
1396514065
}
@@ -13983,9 +14083,12 @@ else if (/Arrow(Up|Down|Left|Right)/.test(code)) {
1398314083
}
1398414084
}
1398514085
else if (code == 'NumpadAdd') {
14086+
key = '+';
1398614087
keyCode = 107;
14088+
1398714089
}
1398814090
else if (code == 'NumpadSubtract') {
14091+
key = '-';
1398914092
keyCode = 109;
1399014093
}
1399114094
else if (code == 'Space') {

0 commit comments

Comments
 (0)