1/* 2 * Copyright (c) 2022-2023 Shenzhen Kaihong Digital Industry Development Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16const { XMessage } = require('./message/XMessage'); 17const { Lexer } = require('./hcs/lexer'); 18const { Generator } = require('./hcs/Generator'); 19const { Scr } = require('./engine/XDefine'); 20const { XButton } = require('./engine/control/XButton'); 21const { AttrEditor } = require('./AttrEditor'); 22const { NapiLog } = require('./hcs/NapiLog'); 23const { XSelect } = require('./engine/control/XSelect'); 24const { NodeTools, DataType, NodeType } = require('./hcs/NodeTools'); 25const { ModifyNode } = require('./hcs/ModifyNode'); 26const { CanvasInput } = require('./hcs/CanvasInput'); 27const { RightMenu } = require('./engine/RightMenu'); 28const { XTexture } = require('./engine/graphics/XTexture'); 29const { XTools } = require('./engine/XTools'); 30 31const { ObjectType } = require('./hcs/ast'); 32var DISPLAY_TEXT_MAX = 30; 33var ELLIPSIS_LEN = 3; 34var EQUAL_SIGN_LEN = 3; 35 36function rgba(colorArr) { 37 return 0xff000000 | (colorArr[0] << 16) | (colorArr[1] << 8) | colorArr[2]; 38} 39 40function getDarker(colorArr) { 41 for (let i = 0; i < colorArr.length; ++i) { 42 if (colorArr[i] - 0 > 10) { 43 colorArr[i] = colorArr[i] - 10; 44 } 45 } 46 return rgba(colorArr); 47} 48 49function isDarkColor(colorArr) { 50 let grayLevel = 51 colorArr[0] * 0.299 + colorArr[1] * 0.587 + colorArr[2] * 0.114; 52 return grayLevel < 192; 53} 54 55function getVsCodeTheme() { 56 MainEditor.CANVAS_BG = 0xff272727; 57 MainEditor.CANVAS_LINE = 0xff000000; 58 MainEditor.NODE_TEXT_COLOR = 0xffffffff; 59 let canvasBg = document.getElementById('canvas_bg'); 60 var bgStyle = document.defaultView.getComputedStyle(canvasBg, null); 61 var bgColor = bgStyle.getPropertyValue('background-color').match(/\d{1,3}/g); 62 if (bgColor) { 63 MainEditor.CANVAS_BG = rgba(bgColor); 64 MainEditor.CANVAS_LINE = getDarker(bgColor); 65 MainEditor.IS_DARK_BG = isDarkColor(bgColor); 66 RightMenu.isDarkBackground_ = MainEditor.IS_DARK_BG; 67 } 68 69 var txtColor = bgStyle.getPropertyValue('color').match(/\d{1,3}/g); 70 if (txtColor) { 71 MainEditor.NODE_TEXT_COLOR = rgba(txtColor); 72 } 73} 74 75class MainEditor { 76 constructor() { 77 this.files_ = {}; 78 this.nodeCount_ = {}; 79 this.filePoint_ = null; 80 this.rootPoint_ = null; 81 this.nodePoint_ = null; 82 this.offX_ = 100; 83 this.offY_ = 100; 84 this.searchKey = null; 85 this.touchQueue_ = []; 86 this.keyQueue_ = []; 87 this.dropAll_ = { 88 locked: false, 89 oldx: -1, 90 oldy: -1, 91 }; 92 getVsCodeTheme(); 93 this.nodeBtns = []; 94 this.nodeMoreBtns = []; 95 this.nodeBtnPoint_ = 0; 96 this.nodeMoreBtnPoint_ = 0; 97 XMessage.gi().registRecvCallback(this.onReceive); 98 XMessage.gi().send('inited', ''); 99 AttrEditor.gi().freshEditor(); 100 101 this.sltInclude = new XSelect(['a', 'b', 'c'], 'b'); 102 this.sltInclude.registCallback(this.onSelectInclude); 103 NapiLog.registError(this.onError); 104 this.errorMsg_ = []; 105 this.cutImgDict_ = {}; 106 this.whiteImg_ = -1; 107 this.whiteCut_ = -1; 108 this.cicleImg_ = -1; 109 this.circleCut_ = -1; 110 this.cicleOpenImg_ = -1; 111 this.circleOpenCut_ = -1; 112 this.rectangleFocusImg_ = -1; 113 this.rectangleFocusCut_ = -1; 114 this.nodeIconImg_ = -1; 115 this.nodeIconCut_ = -1; 116 this.attrIconImg_ = -1; 117 this.attrIconCut_ = -1; 118 this.rootIconImg_ = -1; 119 this.rootIconCut_ = -1; 120 this.rootIconFocusImg_ = -1; 121 this.rootIconFocusCut_ = -1; 122 RightMenu.backgroundImg_ = -1; 123 RightMenu.backgroundCut_ = -1; 124 RightMenu.popItemFocusImg_ = -1; 125 RightMenu.popItemFocusCut_ = -1; 126 this.leftRectCicleCut_ = -1; 127 this.centerRectCut_ = -1; 128 this.rightRectCicleCut_ = -1; 129 this.leftRectFocusCicleCut_ = -1; 130 this.centerFocusCut_ = -1; 131 this.rightRectFocusCicleCut_ = -1; 132 this.delay_ = 0; 133 this.searchBgImg_ = -1; 134 this.searchBgCut_ = -1; 135 this.upImg_ = -1; 136 this.upCut_ = -1; 137 this.downImg_ = -1; 138 this.downCut_ = -1; 139 this.closeImg_ = -1; 140 this.closeCut_ = -1; 141 this.searchImg_ = -1; 142 this.searchCut_ = -1; 143 this.isSearchResult_ = false; 144 this.searchRectFocusCicleImg_ = -1; 145 this.leftSearchFocusCicleCut_ = -1; 146 this.centerSearchCut_ = -1; 147 this.rightSearchFocusCicleCut_ = -1; 148 149 this.searchAttrCicleImg_ = -1; 150 this.leftSearchAttrCicleCut_ = -1; 151 this.centerSearchAttrCut_ = -1; 152 this.rightSearchAttrCicleCut_ = -1; 153 154 this.selectNode_ = { 155 type: null, 156 pnode: null, 157 }; 158 this.btnCancelSelect_ = new XButton(); 159 160 AttrEditor.gi().registCallback(this.onAttributeChange); 161 162 this.mousePos_ = { 163 x: 0, 164 y: 0, 165 }; 166 167 this.whiteImg_ = XTexture.gi().loadTextureFromImage( 168 '../images/rectangle.png' 169 ); 170 this.whiteCut_ = XTexture.gi().makeCut( 171 this.whiteImg_, 172 0, 173 0, 174 132, 175 32, 176 132, 177 32 178 ); 179 this.cutImgDict_['whiteCut'] = 'rectangle.png'; 180 181 this.cicleImg_ = XTexture.gi().loadTextureFromImage('../images/circle.png'); 182 this.circleCut_ = XTexture.gi().makeCut( 183 this.cicleImg_, 184 0, 185 0, 186 20, 187 20, 188 20, 189 20 190 ); 191 this.cutImgDict_['circleCut'] = 'circle.png'; 192 193 this.cicleOpenImg_ = XTexture.gi().loadTextureFromImage( 194 '../images/circle_open.png' 195 ); 196 this.circleOpenCut_ = XTexture.gi().makeCut( 197 this.cicleOpenImg_, 198 0, 199 0, 200 20, 201 20, 202 20, 203 20 204 ); 205 this.cutImgDict_['circleOpenCut'] = 'circle_open.png'; 206 207 this.rectangleFocusImg_ = XTexture.gi().loadTextureFromImage( 208 '../images/rectangle_focus.png' 209 ); 210 this.rectangleFocusCut_ = XTexture.gi().makeCut( 211 this.rectangleFocusImg_, 212 0, 213 0, 214 132, 215 32, 216 132, 217 32 218 ); 219 this.cutImgDict_['rectangleFocusCut'] = 'rectangle_focus.png'; 220 221 this.nodeIconImg_ = XTexture.gi().loadTextureFromImage( 222 '../images/node_icon.png' 223 ); 224 this.nodeIconCut_ = XTexture.gi().makeCut( 225 this.nodeIconImg_, 226 0, 227 0, 228 8, 229 8, 230 8, 231 8 232 ); 233 this.cutImgDict_['nodeIconCut'] = 'node_icon.png'; 234 235 this.attrIconImg_ = XTexture.gi().loadTextureFromImage( 236 '../images/attribute_icon.png' 237 ); 238 this.attrIconCut_ = XTexture.gi().makeCut( 239 this.attrIconImg_, 240 0, 241 0, 242 8, 243 8, 244 8, 245 8 246 ); 247 this.cutImgDict_['attrIconCut'] = 'attribute_icon.png'; 248 249 this.rootIconImg_ = XTexture.gi().loadTextureFromImage( 250 '../images/root_btn.png' 251 ); 252 this.rootIconCut_ = XTexture.gi().makeCut( 253 this.rootIconImg_, 254 0, 255 0, 256 132, 257 32, 258 132, 259 32 260 ); 261 this.cutImgDict_['rootIconCut'] = 'root_btn.png'; 262 263 this.rootIconFocusImg_ = XTexture.gi().loadTextureFromImage( 264 '../images/root_btn_focus.png' 265 ); 266 this.rootIconFocusCut_ = XTexture.gi().makeCut( 267 this.rootIconFocusImg_, 268 0, 269 0, 270 132, 271 32, 272 132, 273 32 274 ); 275 this.cutImgDict_['rootIconFocusCut'] = 'root_btn_focus.png'; 276 277 this.leftRectCicleImg_ = XTexture.gi().loadTextureFromImage( 278 '../images/rectangle.png' 279 ); 280 this.leftRectCicleCut_ = XTexture.gi().makeCut( 281 this.leftRectCicleImg_, 282 0, 283 0, 284 8, 285 32, 286 132, 287 32 288 ); 289 this.centerRectImg_ = XTexture.gi().loadTextureFromImage( 290 '../images/rectangle.png' 291 ); 292 this.centerRectCut_ = XTexture.gi().makeCut( 293 this.centerRectImg_, 294 8, 295 0, 296 116, 297 32, 298 132, 299 32 300 ); 301 this.rightRectCicleImg_ = XTexture.gi().loadTextureFromImage( 302 '../images/rectangle.png' 303 ); 304 this.rightRectCicleCut_ = XTexture.gi().makeCut( 305 this.rightRectCicleImg_, 306 124, 307 0, 308 8, 309 32, 310 132, 311 32 312 ); 313 314 this.leftRectFocusCicleImg_ = XTexture.gi().loadTextureFromImage( 315 '../images/rectangle_focus.png' 316 ); 317 this.leftRectFocusCicleCut_ = XTexture.gi().makeCut( 318 this.leftRectFocusCicleImg_, 319 0, 320 0, 321 8, 322 32, 323 132, 324 32 325 ); 326 this.centerFocusImg_ = XTexture.gi().loadTextureFromImage( 327 '../images/rectangle_focus.png' 328 ); 329 this.centerFocusCut_ = XTexture.gi().makeCut( 330 this.centerFocusImg_, 331 8, 332 0, 333 116, 334 32, 335 132, 336 32 337 ); 338 this.rightRectFocusCicleImg_ = XTexture.gi().loadTextureFromImage( 339 '../images/rectangle_focus.png' 340 ); 341 this.rightRectFocusCicleCut_ = XTexture.gi().makeCut( 342 this.rightRectFocusCicleImg_, 343 124, 344 0, 345 8, 346 32, 347 132, 348 32 349 ); 350 351 let bgPic = RightMenu.isDarkBackground_ ? 'pop_background.png' : 'pop_background_light.png'; 352 let bgPicPath = '../images/' + bgPic; 353 RightMenu.backgroundImg_ = XTexture.gi().loadTextureFromImage(bgPicPath); 354 RightMenu.backgroundCut_ = XTexture.gi().makeCut( 355 RightMenu.backgroundImg_, 356 0, 357 0, 358 156, 359 112, 360 156, 361 112 362 ); 363 this.cutImgDict_['backgroundCut'] = bgPic; 364 365 RightMenu.popItemFocusImg_ = XTexture.gi().loadTextureFromImage( 366 '../images/pop_item_focus.png' 367 ); 368 RightMenu.popItemFocusCut_ = XTexture.gi().makeCut( 369 RightMenu.popItemFocusImg_, 370 0, 371 0, 372 148, 373 32, 374 148, 375 32 376 ); 377 this.cutImgDict_['popItemFocusCut'] = 'pop_item_focus.png'; 378 379 this.searchBgImg_ = XTexture.gi().loadTextureFromImage( 380 '../images/search_bg.png' 381 ); 382 this.searchBgCut_ = XTexture.gi().makeCut( 383 this.searchBgImg_, 384 0, 385 0, 386 494, 387 56, 388 494, 389 56 390 ); 391 this.cutImgDict_['searchBgCut'] = 'search_bg.png'; 392 393 this.upImg_ = XTexture.gi().loadTextureFromImage( 394 '../images/chevron-up.png' 395 ); 396 this.upCut_ = XTexture.gi().makeCut(this.upImg_, 0, 0, 16, 16, 16, 16); 397 this.cutImgDict_['upCut'] = 'chevron-up.png'; 398 399 this.downImg_ = XTexture.gi().loadTextureFromImage( 400 '../images/chevron-down.png' 401 ); 402 this.downCut_ = XTexture.gi().makeCut(this.downImg_, 0, 0, 16, 16, 16, 16); 403 this.cutImgDict_['downCut'] = 'chevron-down.png'; 404 405 this.closeImg_ = XTexture.gi().loadTextureFromImage('../images/close.png'); 406 this.closeCut_ = XTexture.gi().makeCut( 407 this.closeImg_, 408 0, 409 0, 410 16, 411 16, 412 16, 413 16 414 ); 415 this.cutImgDict_['closeCut'] = 'close.png'; 416 417 this.searchImg_ = XTexture.gi().loadTextureFromImage( 418 '../images/search.png' 419 ); 420 this.searchCut_ = XTexture.gi().makeCut( 421 this.searchImg_, 422 0, 423 0, 424 16, 425 16, 426 16, 427 16 428 ); 429 this.cutImgDict_['searchCut'] = 'search.png'; 430 431 this.searchRectFocusCicleImg_ = XTexture.gi().loadTextureFromImage( 432 '../images/search_nood_rect.png' 433 ); 434 this.leftSearchFocusCicleCut_ = XTexture.gi().makeCut( 435 this.searchRectFocusCicleImg_, 436 0, 437 0, 438 8, 439 32, 440 132, 441 32 442 ); 443 this.centerSearchCut_ = XTexture.gi().makeCut( 444 this.searchRectFocusCicleImg_, 445 8, 446 0, 447 116, 448 32, 449 132, 450 32 451 ); 452 this.rightSearchFocusCicleCut_ = XTexture.gi().makeCut( 453 this.searchRectFocusCicleImg_, 454 124, 455 0, 456 8, 457 32, 458 132, 459 32 460 ); 461 this.cutImgDict_['searchNoodRectImg'] = 'search_nood_rect.png'; 462 463 this.searchAttrCicleImg_ = XTexture.gi().loadTextureFromImage( 464 '../images/search_attr_rect.png' 465 ); 466 this.leftSearchAttrCicleCut_ = XTexture.gi().makeCut( 467 this.searchAttrCicleImg_, 468 0, 469 0, 470 8, 471 32, 472 132, 473 32 474 ); 475 this.centerSearchAttrCut_ = XTexture.gi().makeCut( 476 this.searchAttrCicleImg_, 477 8, 478 0, 479 116, 480 32, 481 132, 482 32 483 ); 484 this.rightSearchAttrCicleCut_ = XTexture.gi().makeCut( 485 this.searchAttrCicleImg_, 486 124, 487 0, 488 8, 489 32, 490 132, 491 32 492 ); 493 this.cutImgDict_['searchAttrRectImg'] = 'search_attr_rect.png'; 494 495 XMessage.gi().send('cutImgDict', { 496 data: this.cutImgDict_, 497 }); 498 this.modifyPos_ = null; 499 this.isFirstDraw = true; 500 this.lenHierarchy = 0; 501 502 this.searchInput = null; 503 this.historyZ = []; 504 this.historyBase = {}; 505 this.historyPushed = false; 506 } 507 508 reloadMenuBgPic() { 509 let bgPic = RightMenu.isDarkBackground_ ? 'pop_background.png' : 'pop_background_light.png'; 510 let bgPicPath = '../images/' + bgPic; 511 RightMenu.backgroundImg_ = XTexture.gi().loadTextureFromImage(bgPicPath); 512 RightMenu.backgroundCut_ = XTexture.gi().makeCut( 513 RightMenu.backgroundImg_, 514 0, 515 0, 516 156, 517 112, 518 156, 519 112 520 ); 521 this.cutImgDict_['backgroundCut'] = bgPic; 522 XMessage.gi().send('reloadMenuBg', { 523 data: bgPic, 524 }); 525 } 526 527 calcPostionY(data, y) { 528 data.posY = y; 529 let ty = y; 530 switch (data.type_) { 531 case 1: 532 case 2: 533 case 3: 534 case 4: 535 y += MainEditor.LINE_HEIGHT; 536 break; 537 case 5: 538 y += MainEditor.LINE_HEIGHT; 539 break; 540 case 6: 541 if (!data.isOpen_) { 542 y += MainEditor.LINE_HEIGHT; 543 } else { 544 for (let i in data.value_) { 545 y = this.calcPostionY(data.value_[i], y); 546 } 547 } 548 break; 549 case 7: 550 y = this.calcPostionY(data.value_, y); 551 break; 552 case 8: 553 y += MainEditor.LINE_HEIGHT; 554 break; 555 case 9: 556 y += MainEditor.LINE_HEIGHT; 557 break; 558 case 10: 559 y += MainEditor.LINE_HEIGHT; 560 break; 561 case 11: 562 y += MainEditor.LINE_HEIGHT; 563 break; 564 default: 565 NapiLog.logError('unknow' + data.type_); 566 break; 567 } 568 if (y > ty) { 569 data.posY = (ty + y - MainEditor.LINE_HEIGHT) / 2; 570 } 571 return y > ty + MainEditor.LINE_HEIGHT ? y : ty + MainEditor.LINE_HEIGHT; 572 } 573 574 getNodeText(data) { 575 switch (data.nodeType_) { 576 case 0: 577 return data.name_; 578 case 3: 579 return data.name_ + ' : delete'; 580 case 4: 581 return 'templete ' + data.name_; 582 case 5: 583 if (data.ref_ == 'unknow') { 584 return data.name_; 585 } 586 return data.name_ + ' :: ' + data.ref_; 587 case 1: 588 if (data.ref_ == 'unknow') { 589 return data.name_; 590 } 591 return data.name_ + ' : ' + data.ref_; 592 case 2: 593 if (data.ref_ == 'unknow') { 594 return data.name_; 595 } 596 return data.name_ + ' : &' + data.ref_; 597 default: 598 return 'unknow node type'; 599 } 600 } 601 602 drawNode(pm2f, s, size, x, y, type, data) { 603 let w = pm2f.getTextWidth(type == DataType.ATTR ? s + ' = ' : s, size); 604 if (data.parent_ == undefined) { 605 return w; 606 } 607 608 if (type == DataType.ATTR) { 609 let lenDisplay = DISPLAY_TEXT_MAX - EQUAL_SIGN_LEN; 610 if (s.length < 25) { 611 pm2f.drawText(s, size, x - (data.parent_ != undefined ? MainEditor.NODE_RECT_WIDTH - data.parent_.nodeWidth_ : 0) + 612 MainEditor.LOGO_LEFT_PADDING + MainEditor.LOGO_SIZE * 2, 613 y + MainEditor.NODE_RECT_HEIGHT / 2 - MainEditor.NODE_TEXT_SIZE / 2, 1, 1, 0, 1, 1, MainEditor.NODE_TEXT_COLOR); 614 pm2f.drawText(' = ', size, x - (data.parent_ != undefined ? MainEditor.NODE_RECT_WIDTH - data.parent_.nodeWidth_ : 0) + 615 MainEditor.LOGO_LEFT_PADDING + MainEditor.LOGO_SIZE * 2 + pm2f.getTextWidth(s, size), 616 y + MainEditor.NODE_RECT_HEIGHT / 2 - MainEditor.NODE_TEXT_SIZE / 2, 1, 1, 0, 0, 0, 0xffa9a9a9); 617 } else if (s.length == 25) { 618 pm2f.drawText(s, size, x - (data.parent_ != undefined ? MainEditor.NODE_RECT_WIDTH - data.parent_.nodeWidth_ : 0) + 619 MainEditor.LOGO_LEFT_PADDING + MainEditor.LOGO_SIZE * 2, 620 y + MainEditor.NODE_RECT_HEIGHT / 2 - MainEditor.NODE_TEXT_SIZE / 2, 1, 1, 0, 1, 1, MainEditor.NODE_TEXT_COLOR); 621 pm2f.drawText(' =', size, x - (data.parent_ != undefined ? MainEditor.NODE_RECT_WIDTH - data.parent_.nodeWidth_ : 0) + 622 MainEditor.LOGO_LEFT_PADDING + MainEditor.LOGO_SIZE * 2 + pm2f.getTextWidth(s, size), 623 y + MainEditor.NODE_RECT_HEIGHT / 2 - MainEditor.NODE_TEXT_SIZE / 2, 1, 1, 0, 0, 0, 0xffa9a9a9); 624 } else if (s.length == 26) { 625 pm2f.drawText(s, size, x - (data.parent_ != undefined ? MainEditor.NODE_RECT_WIDTH - data.parent_.nodeWidth_ : 0) + 626 MainEditor.LOGO_LEFT_PADDING + MainEditor.LOGO_SIZE * 2, 627 y + MainEditor.NODE_RECT_HEIGHT / 2 - MainEditor.NODE_TEXT_SIZE / 2, 1, 1, 0, 1, 1, MainEditor.NODE_TEXT_COLOR); 628 pm2f.drawText('=', size, x - (data.parent_ != undefined ? MainEditor.NODE_RECT_WIDTH - data.parent_.nodeWidth_ : 0) + 629 MainEditor.LOGO_LEFT_PADDING + MainEditor.LOGO_SIZE * 2 + pm2f.getTextWidth(s, size), 630 y + MainEditor.NODE_RECT_HEIGHT / 2 - MainEditor.NODE_TEXT_SIZE / 2, 1, 1, 0, 0, 0, 0xffa9a9a9); 631 } else if (s.length > 26) { 632 s = s.substring(0, lenDisplay) + '...'; 633 pm2f.drawText(s, size, x - (data.parent_ != undefined ? MainEditor.NODE_RECT_WIDTH - data.parent_.nodeWidth_ : 0) + 634 MainEditor.LOGO_LEFT_PADDING + MainEditor.LOGO_SIZE * 2, 635 y + MainEditor.NODE_RECT_HEIGHT / 2 - MainEditor.NODE_TEXT_SIZE / 2, 1, 1, 0, 1, 1, MainEditor.NODE_TEXT_COLOR); 636 } 637 } else { 638 pm2f.drawText( s.length > DISPLAY_TEXT_MAX ? s.substring(0, 27) + '...' : s, size, x - (MainEditor.NODE_RECT_WIDTH - data.parent_.nodeWidth_) + 639 MainEditor.LOGO_LEFT_PADDING + MainEditor.LOGO_SIZE * 2, 640 y + MainEditor.NODE_RECT_HEIGHT / 2 - MainEditor.NODE_TEXT_SIZE / 2, 1, 1, 0, 1, 1, MainEditor.NODE_TEXT_COLOR); 641 } 642 return w; 643 } 644 645 drawBrokenLine(pm2f, data, offy, i) { 646 let dis = 647 data.parent_ != undefined ? MainEditor.NODE_RECT_WIDTH - data.parent_.nodeWidth_ : 0; 648 let baseX_ = 649 data.posX + 650 MainEditor.NODE_RECT_WIDTH - 651 (MainEditor.NODE_RECT_WIDTH - data.nodeWidth_) + 652 MainEditor.NODE_TEXT_OFFX + 653 MainEditor.NODE_MORE_CHILD - 654 dis; 655 pm2f.drawLine( 656 baseX_, 657 offy + data.posY + MainEditor.NODE_RECT_HEIGHT / 2, 658 baseX_ + MainEditor.LINE_WIDTH, 659 offy + data.posY + MainEditor.NODE_RECT_HEIGHT / 2, 660 MainEditor.NODE_LINE_COLOR, 661 0.5 662 ); 663 664 pm2f.drawLine( 665 baseX_ + MainEditor.LINE_WIDTH, 666 offy + data.posY + MainEditor.NODE_RECT_HEIGHT / 2, 667 baseX_ + MainEditor.LINE_WIDTH, 668 offy + data.value_[i].posY + MainEditor.NODE_RECT_HEIGHT / 2, 669 MainEditor.NODE_LINE_COLOR, 670 0.5 671 ); 672 673 pm2f.drawLine( 674 baseX_ + MainEditor.LINE_WIDTH, 675 offy + data.value_[i].posY + MainEditor.NODE_RECT_HEIGHT / 2, 676 baseX_ + MainEditor.LINE_WIDTH * 2, 677 offy + data.value_[i].posY + MainEditor.NODE_RECT_HEIGHT / 2, 678 MainEditor.NODE_LINE_COLOR, 679 0.5 680 ); 681 } 682 683 arrayNodeProc(w, pm2f, data, offx, offy) { 684 let ss = '[' + data.value_.length + ']' + NodeTools.arrayToString(data); 685 let keyAndValue = data.parent_.name_ + ' = '; 686 if (keyAndValue.length >= 30) { 687 return; 688 } else if (keyAndValue.length == 29) { 689 w = pm2f.drawText('.', 14, offx, offy + data.posY + MainEditor.NODE_RECT_HEIGHT / 2 - MainEditor.NODE_TEXT_SIZE / 2, 1, 1, 0, 1, 1, MainEditor.NODE_TEXT_COLOR); 690 } else if (keyAndValue.length == 28) { 691 w = pm2f.drawText('..', 14, offx, offy + data.posY + MainEditor.NODE_RECT_HEIGHT / 2 - MainEditor.NODE_TEXT_SIZE / 2, 1, 1, 0, 1, 1, MainEditor.NODE_TEXT_COLOR); 692 } else if (keyAndValue.length == 27) { 693 w = pm2f.drawText('...', 14, offx, offy + data.posY + MainEditor.NODE_RECT_HEIGHT / 2 - MainEditor.NODE_TEXT_SIZE / 2, 1, 1, 0, 1, 1, MainEditor.NODE_TEXT_COLOR); 694 } else if (keyAndValue.length < 27) { 695 let displayValueLen = DISPLAY_TEXT_MAX - keyAndValue.length; 696 if (ss.length > displayValueLen) { 697 ss = ss.substring(0, displayValueLen - 3) + '...'; 698 } 699 w = pm2f.drawText(ss, 14, offx, offy + data.posY + MainEditor.NODE_RECT_HEIGHT / 2 - MainEditor.NODE_TEXT_SIZE / 2, 1, 1, 0, 1, 1, MainEditor.NODE_TEXT_COLOR); 700 } 701 } 702 703 configNodeProc(w, pm2f, data, offx, offy, path) { 704 let dis = data.parent_ != undefined ? MainEditor.NODE_RECT_WIDTH - data.parent_.nodeWidth_ : 0; 705 this.setNodeButton(pm2f, offx, offy + data.posY, w, MainEditor.NODE_TEXT_SIZE, path, data); 706 if (data.value_.length > 0) { 707 this.setNodeMoreButton(pm2f, offx - dis, offy + data.posY, MainEditor.NODE_MORE_CHILD, MainEditor.NODE_MORE_CHILD, data); 708 } 709 let drawNodeX_ = offx + MainEditor.NODE_RECT_WIDTH + MainEditor.NODE_SIZE_BG_OFFX + MainEditor.NODE_MORE_CHILD + MainEditor.LINE_WIDTH * 2 - dis; 710 if (data.type_ == DataType.NODE) { 711 for (let i in data.value_) { 712 if ( 713 data.value_[i].parent_.type_ == 6 && 714 data.value_[i].parent_.isOpen_ 715 ) { 716 this.drawObj(pm2f, data.value_[i], drawNodeX_, offy, path + '.'); 717 this.drawBrokenLine(pm2f, data, offy, i); 718 } else if (data.value_[i].parent_.type_ == DataType.ATTR) { 719 this.drawObj(pm2f, data.value_[i], drawNodeX_, offy, path + '.'); 720 pm2f.drawLine(data.posX + w, offy + data.posY + 10, 721 data.value_[i].posX, offy + data.value_[i].posY + 10, MainEditor.NODE_TEXT_COLOR, 1); 722 } else { 723 NapiLog.logInfo('Node collapse does not need to draw child node'); 724 } 725 } 726 } else { 727 for (let i in data.value_) { 728 this.drawObj(pm2f, data.value_[i], drawNodeX_, offy, path + '.'); 729 pm2f.drawLine(data.posX + w, offy + data.posY + 10, 730 data.value_[i].posX, offy + data.value_[i].posY + 10, MainEditor.NODE_TEXT_COLOR, 1); 731 } 732 } 733 } 734 735 drawObj(pm2f, data, offx, offy, path) { 736 let w; 737 path += data.name_; 738 data.posX = offx; 739 if (this.maxX < offx) { 740 this.maxX = offx; 741 } 742 let parentTextWidth = pm2f.getTextWidth(' = ', MainEditor.NODE_TEXT_SIZE); 743 let drawTextX_ = offx + MainEditor.LOGO_LEFT_PADDING + MainEditor.LOGO_SIZE + parentTextWidth; 744 let drawTextY_ = offy + data.posY + MainEditor.NODE_RECT_HEIGHT / 2 - MainEditor.NODE_TEXT_SIZE / 2; 745 switch (data.type_) { 746 case 1: 747 case 2: 748 case 3: 749 case 4: 750 w = pm2f.drawText(NodeTools.jinZhi10ToX(data.value_, data.jinzhi_), MainEditor.NODE_TEXT_SIZE, 751 drawTextX_ - (MainEditor.NODE_RECT_WIDTH - data.parent_.parent_.nodeWidth_), drawTextY_, 1, 1, 0, 1, 1, MainEditor.NODE_TEXT_COLOR); 752 break; 753 case 5: 754 let value = data.value_; 755 let keyAndValue = data.parent_.name_ + ' = ' + data.value_; 756 if (keyAndValue.length > DISPLAY_TEXT_MAX) { 757 value = keyAndValue.substring((data.parent_.name_ + ' = ').length, 27) + '...'; 758 } 759 w = pm2f.drawText('"' + value + '"', MainEditor.NODE_TEXT_SIZE, drawTextX_ - (MainEditor.NODE_RECT_WIDTH - data.parent_.parent_.nodeWidth_), drawTextY_, 760 1, 1, 0, 1, 1, MainEditor.NODE_TEXT_COLOR); 761 break; 762 case 6: 763 w = this.drawNode(pm2f, this.getNodeText(data), MainEditor.NODE_TEXT_SIZE, offx, offy + data.posY, data.type_, data); 764 this.configNodeProc(w, pm2f, data, offx, offy, path); 765 if (data.parent_ != undefined) { 766 pm2f.drawCut(this.nodeIconCut_, offx + MainEditor.LOGO_LEFT_PADDING - (MainEditor.NODE_RECT_WIDTH - data.parent_.nodeWidth_), 767 offy + data.posY + MainEditor.NODE_RECT_HEIGHT / 2 - MainEditor.LOGO_SIZE / 2); 768 } 769 break; 770 case 7: 771 w = this.drawNode(pm2f, data.name_, MainEditor.NODE_TEXT_SIZE, offx, offy + data.posY, data.type_, data); 772 this.setNodeButton(pm2f, offx, offy + data.posY, w, MainEditor.NODE_TEXT_SIZE, path, data); 773 this.drawObj(pm2f, data.value_, offx + w, offy, path); 774 pm2f.drawCut(this.attrIconCut_, offx + MainEditor.LOGO_LEFT_PADDING - (MainEditor.NODE_RECT_WIDTH - data.parent_.nodeWidth_), 775 offy + data.posY + MainEditor.NODE_RECT_HEIGHT / 2 - MainEditor.LOGO_SIZE / 2); 776 break; 777 case 8: 778 this.arrayNodeProc(w, pm2f, data, drawTextX_ - (MainEditor.NODE_RECT_WIDTH - data.parent_.parent_.nodeWidth_), offy); 779 break; 780 case 9: 781 let content = data.parent_.name_ + ' = '; 782 if (content.length > DISPLAY_TEXT_MAX) { 783 content = ''; 784 } else if ((content + data.value_).length > DISPLAY_TEXT_MAX) { 785 content = data.value_.substring((data.parent_.name_ + ' = ').length, 27) + '...'; 786 } else { 787 content = data.value_; 788 } 789 w = pm2f.drawText('&' + content, MainEditor.NODE_TEXT_SIZE, drawTextX_ - (MainEditor.NODE_RECT_WIDTH - data.parent_.parent_.nodeWidth_), drawTextY_, 790 1, 1, 0, 1, 1, MainEditor.NODE_TEXT_COLOR); 791 break; 792 case 10: 793 w = pm2f.drawText('delete', MainEditor.NODE_TEXT_SIZE, drawTextX_ - (MainEditor.NODE_RECT_WIDTH - data.parent_.parent_.nodeWidth_), drawTextY_, 794 1, 1, 0, 1, 1, MainEditor.NODE_TEXT_COLOR); 795 break; 796 case 11: 797 if (data.value_) { 798 w = pm2f.drawText('true', MainEditor.NODE_TEXT_SIZE, drawTextX_ - (MainEditor.NODE_RECT_WIDTH - data.parent_.parent_.nodeWidth_), drawTextY_, 799 1, 1, 0, 1, 1, MainEditor.NODE_TEXT_COLOR); 800 } else { 801 w = pm2f.drawText('false', MainEditor.NODE_TEXT_SIZE, drawTextX_ - (MainEditor.NODE_RECT_WIDTH - data.parent_.parent_.nodeWidth_), drawTextY_, 802 1, 1, 0, 1, 1, MainEditor.NODE_TEXT_COLOR); 803 } 804 break; 805 default: 806 NapiLog.logError('unknow' + data.type_); 807 break; 808 } 809 if (data.errMsg_ != null) { 810 if (parseInt(this.delay_ / 10) % 2 == 0) { 811 pm2f.drawRect(offx - (MainEditor.NODE_RECT_WIDTH - data.parent_.nodeWidth_), offy + data.posY, 812 data.nodeWidth_, MainEditor.NODE_RECT_HEIGHT, 0xffff0000, 1); 813 } 814 pm2f.drawText(data.errMsg_, MainEditor.NODE_TEXT_SIZE, offx - (MainEditor.NODE_RECT_WIDTH - data.parent_.nodeWidth_), 815 offy + data.posY + 5, 1, 1, 0, -1, -3, 0xffff0000); 816 } 817 } 818 819 setNodeButton(pm2f, x, y, w, h, path, node) { 820 let rectWidth = MainEditor.NODE_RECT_WIDTH; 821 if (node.parent_ == undefined) { 822 if (this.nodePoint_ == node) { 823 pm2f.drawCut(this.rootIconFocusCut_, x, y); 824 } else { 825 pm2f.drawCut(this.rootIconCut_, x, y); 826 } 827 node.nodeWidth_ = MainEditor.NODE_RECT_WIDTH; 828 pm2f.drawText( 829 node.name_, 830 MainEditor.NODE_TEXT_SIZE, 831 x + MainEditor.NODE_RECT_WIDTH / 2 - w / 2, 832 y + MainEditor.NODE_RECT_HEIGHT / 2 - h / 2, 833 1, 834 1, 835 0, 836 1, 837 1, 838 MainEditor.NODE_TEXT_COLOR 839 ); 840 } else { 841 if (node.type_ == DataType.ATTR) { 842 let displayValue; 843 if (node.value_.type_ == ObjectType.PARSEROP_ARRAY) { 844 let arrayValue = NodeTools.arrayToString(node.value_); 845 displayValue = '[' + node.value_.value_.length + ']' + arrayValue; 846 } else if ( 847 node.value_.type_ == ObjectType.PARSEROP_UINT8 || 848 node.value_.type_ == ObjectType.PARSEROP_UINT16 || 849 node.value_.type_ == ObjectType.PARSEROP_UINT32 || 850 node.value_.type_ == ObjectType.PARSEROP_UINT64 851 ) { 852 displayValue = NodeTools.jinZhi10ToX( 853 node.value_.value_, 854 node.value_.jinzhi_ 855 ); 856 } else if (node.value_.type_ == ObjectType.PARSEROP_DELETE) { 857 displayValue = 'delete'; 858 } else if (node.value_.type_ == ObjectType.PARSEROP_BOOL) { 859 if (node.value_) { 860 displayValue = 'true'; 861 } else { 862 displayValue = 'false'; 863 } 864 } else { 865 displayValue = node.value_.value_; 866 } 867 868 let keyAndValue; 869 let lenDisplay = 27; 870 if (node.name_.length <= lenDisplay) { 871 keyAndValue = node.name_ + ' = ' + displayValue; 872 } else if (node.name_.length == lenDisplay + 1) { 873 keyAndValue = node.name_ + ' ='; 874 } else if (node.name_.length == lenDisplay + 2) { 875 keyAndValue = node.name_ + '='; 876 } else if (node.name_.length >= DISPLAY_TEXT_MAX) { 877 keyAndValue = node.name_; 878 } 879 880 if (keyAndValue.length >= DISPLAY_TEXT_MAX) { 881 keyAndValue = keyAndValue.substring(0, 27) + '...'; 882 } 883 rectWidth = pm2f.getTextWidth(keyAndValue, MainEditor.NODE_TEXT_SIZE); 884 } else { 885 rectWidth = pm2f.getTextWidth( 886 this.getNodeText(node).length > DISPLAY_TEXT_MAX ? this.getNodeText(node).substring(0, 27) + '...' : this.getNodeText(node), 887 MainEditor.NODE_TEXT_SIZE 888 ); 889 } 890 this.drawNodeRectButton(pm2f, x, y, rectWidth, node); 891 } 892 if (this.nodeBtnPoint_ >= this.nodeBtns.length) { 893 this.nodeBtns.push(new XButton()); 894 } 895 let pbtn = this.nodeBtns[this.nodeBtnPoint_]; 896 pbtn.move( 897 x - (node.parent_ == undefined ? 0 : MainEditor.NODE_RECT_WIDTH - node.parent_.nodeWidth_), 898 y, node.parent_ == undefined ? MainEditor.NODE_RECT_WIDTH : rectWidth + 6 * 2 + MainEditor.LOGO_SIZE + 8, MainEditor.NODE_RECT_HEIGHT 899 ); 900 pbtn.name_ = path; 901 pbtn.node_ = node; 902 this.nodeBtnPoint_ += 1; 903 } 904 905 drawNodeRectButton(pm2f, x, y, rectWidth, node) { 906 let width = rectWidth + 6 * 2 + MainEditor.LOGO_SIZE + 8; 907 if (node.type_ == DataType.ATTR) { 908 switch (node.value_.type_) { 909 case 1: 910 case 2: 911 case 3: 912 case 4: 913 case 8: 914 width = width; 915 break; 916 default: 917 width = width + 14; 918 break; 919 } 920 } 921 if (this.nodePoint_ == node) { 922 if (this.isSearchResult_) { 923 pm2f.drawCut(this.leftSearchAttrCicleCut_, x - (MainEditor.NODE_RECT_WIDTH - node.parent_.nodeWidth_), y); 924 pm2f.drawCut(this.centerSearchAttrCut_, x + 8 - (MainEditor.NODE_RECT_WIDTH - node.parent_.nodeWidth_), y, width / 116); 925 pm2f.drawCut(this.rightSearchAttrCicleCut_, x + 8 + width - (MainEditor.NODE_RECT_WIDTH - node.parent_.nodeWidth_), y); 926 } else { 927 pm2f.drawCut(this.leftRectFocusCicleCut_, x - (MainEditor.NODE_RECT_WIDTH - node.parent_.nodeWidth_), y); 928 pm2f.drawCut(this.centerFocusCut_, x + 8 - (MainEditor.NODE_RECT_WIDTH - node.parent_.nodeWidth_), y, width / 116); 929 pm2f.drawCut(this.rightRectFocusCicleCut_, x + 8 + width - (MainEditor.NODE_RECT_WIDTH - node.parent_.nodeWidth_), y); 930 } 931 } else { 932 if (this.searchKey != null && node.name_.indexOf(this.searchKey) > -1 && this.isSearchResult_) { 933 pm2f.drawCut( this.leftSearchFocusCicleCut_, x - (MainEditor.NODE_RECT_WIDTH - node.parent_.nodeWidth_), y); 934 pm2f.drawCut(this.centerSearchCut_, x + 8 - (MainEditor.NODE_RECT_WIDTH - node.parent_.nodeWidth_), y, width / 116); 935 pm2f.drawCut( this.rightSearchFocusCicleCut_, x + 8 + width - (MainEditor.NODE_RECT_WIDTH - node.parent_.nodeWidth_), y); 936 } else { 937 pm2f.drawCut( this.leftRectCicleCut_, x - (MainEditor.NODE_RECT_WIDTH - node.parent_.nodeWidth_), y); 938 pm2f.drawCut( this.centerRectCut_, x + 8 - (MainEditor.NODE_RECT_WIDTH - node.parent_.nodeWidth_), y, width / 116); 939 pm2f.drawCut(this.rightRectCicleCut_, x + 8 + width - (MainEditor.NODE_RECT_WIDTH - node.parent_.nodeWidth_), y); 940 } 941 } 942 node.nodeWidth_ = 8 * 2 + width; 943 let tx = x + 8 + width - (MainEditor.NODE_RECT_WIDTH - node.parent_.nodeWidth_) + 8; 944 if (this.maxX < tx) { 945 this.maxX = tx; 946 } 947 } 948 949 /** 950 * 绘制节点数 951 * @param {} pm2f X2DFast 952 * @param {*} x 起始x坐标 953 * @param {*} y 起始y坐标 954 * @param {*} h 节点高度 955 * @param {*} node 节点 956 */ 957 setNodeMoreButton(pm2f, x, y, w, h, node) { 958 if (this.nodeMoreBtnPoint_ >= this.nodeMoreBtns.length) { 959 this.nodeMoreBtns.push(new XButton()); 960 } 961 let pbtn = this.nodeMoreBtns[this.nodeMoreBtnPoint_]; 962 if (node.parent_ == undefined) { 963 pbtn.move(x + MainEditor.NODE_RECT_WIDTH + MainEditor.NODE_SIZE_BG_OFFX, 964 y + (MainEditor.NODE_RECT_HEIGHT - MainEditor.NODE_MORE_CHILD) / 2, w, h); 965 } else { 966 if (node.isOpen_) { 967 pbtn.move(x + node.nodeWidth_ + MainEditor.NODE_SIZE_BG_OFFX, 968 y + (MainEditor.NODE_RECT_HEIGHT - MainEditor.NODE_MORE_CHILD) / 2, w, h); 969 } else { 970 pbtn.move(x + node.nodeWidth_ + MainEditor.NODE_SIZE_BG_OFFX, 971 y + (MainEditor.NODE_RECT_HEIGHT - MainEditor.NODE_MORE_CHILD) / 2, w, h); 972 } 973 } 974 if (node.isOpen_) { 975 pm2f.drawCut(this.circleOpenCut_, x + node.nodeWidth_ + MainEditor.NODE_SIZE_BG_OFFX, 976 y + (MainEditor.NODE_RECT_HEIGHT - MainEditor.NODE_MORE_CHILD) / 2); 977 } else { 978 pm2f.drawCut(this.circleCut_, x + node.nodeWidth_ + MainEditor.NODE_SIZE_BG_OFFX, 979 y + (MainEditor.NODE_RECT_HEIGHT - MainEditor.NODE_MORE_CHILD) / 2); 980 let textWidth = pm2f.getTextWidth(node.value_.length, 10); 981 pm2f.drawText(node.value_.length, 10, x + node.nodeWidth_ + MainEditor.NODE_SIZE_BG_OFFX + MainEditor.NODE_MORE_CHILD / 2 - textWidth / 2, 982 y + MainEditor.NODE_RECT_HEIGHT / 2 - 4, 1, 1, 0, 1, 1, 0xffffffff); 983 } 984 pbtn.node_ = node; 985 this.nodeMoreBtnPoint_ += 1; 986 } 987 988 draw(pm2f) { 989 getVsCodeTheme(); 990 pm2f.fillRect(0, 0, Scr.logicw, Scr.logich, MainEditor.CANVAS_BG); 991 if (this.filePoint_ != null && this.filePoint_ in this.files_) { 992 let data = this.files_[this.filePoint_]; 993 this.calcPostionY(data, 0); 994 if (this.modifyPos_) { 995 this.offX_ -= this.modifyPos_.node.posX - this.modifyPos_.x; 996 this.offY_ -= this.modifyPos_.node.posY - this.modifyPos_.y; 997 this.modifyPos_ = null; 998 } else if (this.isFirstDraw) { 999 this.offX_ = 0; 1000 this.offY_ = -data.posY + Scr.logich / 2; 1001 this.maxX = 0; 1002 this.drawObj(pm2f, data, this.offX_, this.offY_, ''); 1003 pm2f.fillRect(0, 0, Scr.logicw, Scr.logich, MainEditor.CANVAS_BG); 1004 this.offX_ = (Scr.logicw - this.maxX) / 2; 1005 this.isFirstDraw = false; 1006 } 1007 this.nodeBtnPoint_ = 0; 1008 this.nodeMoreBtnPoint_ = 0; 1009 this.drawObj(pm2f, data, this.offX_, this.offY_, ''); 1010 } 1011 pm2f.fillRect(0, 0, window.innerWidth, 4, MainEditor.CANVAS_LINE); 1012 pm2f.fillRect( 1013 window.innerWidth - 420 - 4, 1014 0, 1015 4, 1016 window.innerHeight, 1017 MainEditor.CANVAS_LINE 1018 ); 1019 pm2f.fillRect(0, 4, window.innerWidth - 420 - 4, 48, MainEditor.CANVAS_BG); 1020 pm2f.fillRect( 1021 0, 1022 52, 1023 window.innerWidth - 420 - 4, 1024 4, 1025 MainEditor.CANVAS_LINE 1026 ); 1027 this.sltInclude.setColor(MainEditor.CANVAS_BG, MainEditor.NODE_TEXT_COLOR); 1028 this.sltInclude.move(16, 20, window.innerWidth - 420 - 4 - 16, 20).draw(); 1029 1030 if (this.selectNode_.type != null) { 1031 if (this.selectNode_.type == 'change_target') { 1032 pm2f.drawText( 1033 '点击选择目标', 1034 14, 1035 this.mousePos_.x, 1036 this.mousePos_.y, 1037 1, 1038 1, 1039 0, 1040 -3, 1041 -3, 1042 MainEditor.NODE_TEXT_COLOR 1043 ); 1044 this.btnCancelSelect_.name_ = '取消选择'; 1045 } else if (this.selectNode_.type == 'copy_node') { 1046 pm2f.drawText( 1047 '已复制' + this.selectNode_.pnode.name_, 1048 14, 1049 this.mousePos_.x, 1050 this.mousePos_.y, 1051 1, 1052 1, 1053 0, 1054 -3, 1055 -3, 1056 MainEditor.NODE_TEXT_COLOR 1057 ); 1058 this.btnCancelSelect_.name_ = '取消复制'; 1059 } else if (this.selectNode_.type == 'cut_node') { 1060 pm2f.drawText( 1061 '已剪切' + this.selectNode_.pnode.name_, 1062 18, 1063 this.mousePos_.x, 1064 this.mousePos_.y, 1065 1, 1066 1, 1067 0, 1068 -3, 1069 -3, 1070 MainEditor.NODE_TEXT_COLOR 1071 ); 1072 this.btnCancelSelect_.name_ = '取消剪切'; 1073 } 1074 this.btnCancelSelect_.move(Scr.logicw - 250, Scr.logich - 30, 100, 20); 1075 } 1076 1077 if (this.errorMsg_.length > 0) { 1078 let ts = new Date().getTime(); 1079 while (this.errorMsg_.length > 0 && this.errorMsg_[0][0] < ts) { 1080 this.errorMsg_.shift(); 1081 } 1082 for (let i in this.errorMsg_) { 1083 let y = Scr.logich / 2 - this.errorMsg_.length * 20 + i * 20; 1084 let a = parseInt((this.errorMsg_[i][0] - ts) / 2); 1085 if (a > 255) { 1086 a = 255; 1087 } 1088 NapiLog.logError(a); 1089 a = a << 24; 1090 pm2f.fillRect(0, y, Scr.logicw, 20, 0xff0000 | a); 1091 pm2f.drawText( 1092 this.errorMsg_[i][1], 1093 14, 1094 Scr.logicw / 2, 1095 y, 1096 1, 1097 1, 1098 0, 1099 -2, 1100 -1, 1101 MainEditor.NODE_TEXT_COLOR 1102 ); 1103 } 1104 } 1105 this.delay_ += 1; 1106 RightMenu.Draw(); 1107 if (this.searchInput) { 1108 let x = this.searchInput.pos[0]; 1109 let y = this.searchInput.pos[1]; 1110 let w = this.searchInput.pos[2]; 1111 let h = this.searchInput.pos[3]; 1112 pm2f.drawCut(this.searchBgCut_, x, y); 1113 pm2f.drawCut(this.searchCut_, x + 28, y + 56 / 2 - 8); 1114 x = x + 16 + 290 + 16; 1115 1116 let searchResultTxt = 1117 this.searchInput.result.length == 0 ? 'No result' : this.searchInput.point + 1 + '/' + this.searchInput.result.length; 1118 x += pm2f.drawText( 1119 searchResultTxt, 1120 MainEditor.NODE_TEXT_SIZE, 1121 x, 1122 y + 56 / 2 + 3, 1123 1, 1124 1, 1125 0, 1126 -1, 1127 -2, 1128 0xffffffff 1129 ); 1130 x += 74 - pm2f.getTextWidth(searchResultTxt, MainEditor.NODE_TEXT_SIZE); 1131 pm2f.drawCut(this.upCut_, x, y + 56 / 2 - 8); 1132 this.searchInput.btnUp.move(x, y + 56 / 2 - 8, 16, 16); 1133 x += 16 + 16; 1134 pm2f.drawCut(this.downCut_, x, y + 56 / 2 - 8); 1135 this.searchInput.btnDown.move(x, y + 56 / 2 - 8, 16, 16); 1136 x += 16 + 16; 1137 pm2f.drawCut(this.closeCut_, x, y + 56 / 2 - 8); 1138 this.searchInput.btnClose.move(x, y + 56 / 2 - 8, 16, 16); 1139 } 1140 this.procAll(); 1141 } 1142 1143 buttonClickedProc(nodeBtns) { 1144 if ( 1145 this.selectNode_.type == null || 1146 this.selectNode_.type == 'copy_node' || 1147 this.selectNode_.type == 'cut_node' 1148 ) { 1149 this.nodePoint_ = nodeBtns.node_; 1150 AttrEditor.gi().freshEditor(this.filePoint_, this.nodePoint_); 1151 return true; 1152 } 1153 if (this.selectNode_.type == 'change_target') { 1154 let pn = nodeBtns.node_; 1155 if (pn.type_ == DataType.NODE) { 1156 if (this.selectNode_.pnode.type_ == DataType.NODE) { 1157 if ( 1158 NodeTools.getPathByNode(this.selectNode_.pnode.parent_) == 1159 NodeTools.getPathByNode(pn.parent_) 1160 ) { 1161 this.selectNode_.pnode.ref_ = pn.name_; 1162 } else { 1163 this.selectNode_.pnode.ref_ = NodeTools.getPathByNode(pn); 1164 } 1165 } else if (this.selectNode_.pnode.type_ == DataType.REFERENCE) { 1166 if ( 1167 NodeTools.getPathByNode(this.selectNode_.pnode.parent_.parent_) == 1168 NodeTools.getPathByNode(pn.parent_) 1169 ) { 1170 this.selectNode_.pnode.value_ = pn.name_; 1171 } else { 1172 this.selectNode_.pnode.value_ = NodeTools.getPathByNode(pn); 1173 } 1174 } 1175 1176 this.selectNode_.type = null; 1177 AttrEditor.gi().freshEditor(this.filePoint_, this.nodePoint_); 1178 this.onAttributeChange('writefile'); 1179 } else { 1180 XMessage.gi().send('WrongNode', ''); 1181 } 1182 } 1183 return true; 1184 } 1185 1186 dropAllLocked(msg, x, y) { 1187 if (msg == 2) { 1188 this.offX_ += x - this.dropAll_.oldx; 1189 this.offY_ += y - this.dropAll_.oldy; 1190 this.dropAll_.oldx = x; 1191 this.dropAll_.oldy = y; 1192 } 1193 if (msg == 3) { 1194 this.dropAll_.locked = false; 1195 } 1196 } 1197 1198 procTouch(msg, x, y) { 1199 if (this.searchInput) { 1200 if (XTools.InRect(x, y, ...this.searchInput.pos)) { 1201 if (this.searchInput.btnUp.procTouch(msg, x, y)) { 1202 if (this.searchInput.btnUp.isClicked()) { 1203 this.searchInput.point -= 1; 1204 if (this.searchInput.point < 0) { 1205 this.searchInput.point = this.searchInput.result.length - 1; 1206 } 1207 this.locateNode(this.searchInput.result[this.searchInput.point]); 1208 } 1209 } 1210 if (this.searchInput.btnDown.procTouch(msg, x, y)) { 1211 if (this.searchInput.btnDown.isClicked()) { 1212 this.searchInput.point += 1; 1213 if (this.searchInput.point >= this.searchInput.result.length) { 1214 this.searchInput.point = 0; 1215 } 1216 this.locateNode(this.searchInput.result[this.searchInput.point]); 1217 } 1218 } 1219 return true; 1220 } else { 1221 if (msg == 1) { 1222 this.searchInput = null; 1223 this.isSearchResult_ = false; 1224 } 1225 return true; 1226 } 1227 } 1228 1229 if (RightMenu.Touch(msg, x, y)) { 1230 return true; 1231 } 1232 this.mousePos_.x = x; 1233 this.mousePos_.y = y; 1234 if (this.dropAll_.locked) { 1235 this.dropAllLocked(msg, x, y); 1236 return true; 1237 } 1238 1239 if (this.sltInclude.procTouch(msg, x, y)) { 1240 return true; 1241 } 1242 1243 if (this.selectNode_.type != null) { 1244 if (this.btnCancelSelect_.procTouch(msg, x, y)) { 1245 if (this.btnCancelSelect_.isClicked()) { 1246 this.selectNode_.type = null; 1247 } 1248 return true; 1249 } 1250 } 1251 1252 for (let i = 0; i < this.nodeBtnPoint_; i++) { 1253 if (this.nodeBtns[i].procTouch(msg, x, y)) { 1254 let nodeBtns = this.nodeBtns[i]; 1255 if (nodeBtns.isClicked()) { 1256 this.buttonClickedProc(nodeBtns); 1257 } else if (nodeBtns.isRightClicked()) { 1258 this.onAttributeChange('change_current_select', nodeBtns.node_); 1259 switch (nodeBtns.node_.type_) { 1260 case 6: 1261 RightMenu.Reset( 1262 [ 1263 RightMenu.Button(null, 'Add Child Node', null, () => { 1264 this.procAddNodeAction(); 1265 this.onAttributeChange('writefile'); 1266 }), 1267 RightMenu.Button(null, 'Add Sub Property', null, () => { 1268 this.procAddAttAction(); 1269 this.onAttributeChange('writefile'); 1270 }), 1271 RightMenu.Button(null, 'Delete', null, () => { 1272 this.procDeleteAction(); 1273 this.onAttributeChange('writefile'); 1274 }), 1275 ], 1276 nodeBtns.posX_, 1277 nodeBtns.posY_ + MainEditor.NODE_RECT_HEIGHT 1278 ); 1279 break; 1280 case 7: 1281 RightMenu.Reset( 1282 [ 1283 RightMenu.Button(null, 'Delete', null, () => { 1284 this.procDeleteAction(); 1285 this.onAttributeChange('writefile'); 1286 }), 1287 ], 1288 nodeBtns.posX_, 1289 nodeBtns.posY_ + +MainEditor.NODE_RECT_HEIGHT 1290 ); 1291 break; 1292 } 1293 } 1294 1295 return true; 1296 } 1297 } 1298 1299 for (let i = 0; i < this.nodeMoreBtnPoint_; i++) { 1300 if (this.nodeMoreBtns[i].procTouch(msg, x, y)) { 1301 let nodeMoreBtn = this.nodeMoreBtns[i]; 1302 if (nodeMoreBtn.isClicked()) { 1303 this.buttonClickedProc(nodeMoreBtn); 1304 this.nodeMoreBtns[i].node_.isOpen_ = 1305 !this.nodeMoreBtns[i].node_.isOpen_; 1306 this.modifyPos_ = { 1307 node: this.nodeMoreBtns[i].node_, 1308 x: this.nodeMoreBtns[i].node_.posX, 1309 y: this.nodeMoreBtns[i].node_.posY, 1310 }; 1311 } 1312 return true; 1313 } 1314 } 1315 1316 if (msg == 1 && !this.dropAll_.locked) { 1317 this.dropAll_.locked = true; 1318 this.dropAll_.oldx = x; 1319 this.dropAll_.oldy = y; 1320 return true; 1321 } 1322 return false; 1323 } 1324 1325 procAddNodeAction() { 1326 let pattr = AttrEditor.gi(); 1327 pattr.changeDataNodeNotInherit('add_child_node', 'button', ''); 1328 } 1329 1330 procAddAttAction() { 1331 let pattr = AttrEditor.gi(); 1332 pattr.changeDataNodeNotInherit('add_child_attr', 'button', ''); 1333 } 1334 1335 procDeleteAction() { 1336 let pattr = AttrEditor.gi(); 1337 pattr.changeDataNodeNotInherit('delete', 'button', ''); 1338 } 1339 searchNodeByName(data, name, out) { 1340 this.searchKey = name; 1341 if (data.name_.indexOf(name) >= 0) { 1342 out.push(data); 1343 } 1344 switch (data.type_) { 1345 case 6: 1346 for (let i in data.value_) { 1347 this.searchNodeByName(data.value_[i], name, out); 1348 } 1349 break; 1350 case 7: 1351 this.searchNodeByName(data.value_, name, out); 1352 break; 1353 } 1354 } 1355 expandAllParents(curNdoe) { 1356 if (curNdoe.parent_) { 1357 curNdoe.parent_.isOpen_ = true; 1358 this.expandAllParents(curNdoe.parent_); 1359 } 1360 } 1361 locateNode(node) { 1362 if (!node) { 1363 return; 1364 } 1365 this.expandAllParents(node); 1366 this.isSearchResult_ = true; 1367 this.offX_ -= node.posX - Scr.logicw / 2; 1368 this.offY_ -= this.offY_ + node.posY - Scr.logich / 2; 1369 this.nodePoint_ = node; 1370 AttrEditor.gi().freshEditor(); 1371 } 1372 procKey(k) { 1373 if (k == 'ctrl+z') { 1374 if (this.selectNode_.type != null) { 1375 this.selectNode_.type = null; 1376 } 1377 1378 console.log('!!! popHistory ', this.historyZ.length); 1379 let h; 1380 if (this.historyZ.length <= 0) { 1381 h = this.historyBase[this.filePoint_]; 1382 } else { 1383 if (this.historyZ.length > 1 && this.historyPushed) { 1384 this.historyZ.pop(); 1385 this.historyPushed = false; 1386 } 1387 h = this.historyZ.pop(); 1388 } 1389 1390 this.filePoint_ = h.fn; 1391 this.rootPoint_ = h.fn; 1392 Lexer.FILE_AND_DATA[this.filePoint_] = h.data; 1393 this.parse(this.filePoint_); 1394 if (h.sel) { 1395 this.nodePoint_ = NodeTools.getNodeByPath( 1396 this.files_[this.filePoint_], 1397 h.sel 1398 ); 1399 } else { 1400 this.nodePoint_ = null; 1401 } 1402 AttrEditor.gi().freshEditor(this.filePoint_, this.nodePoint_); 1403 } else if (k == 'ctrl+f') { 1404 this.searchInput = { 1405 pos: [(Scr.logicw - 300) / 2, Scr.logich / 4, 450, 40], 1406 result: [], 1407 point: 0, 1408 btnUp: new XButton(0, 0, 0, 0, '上一个'), 1409 btnDown: new XButton(0, 0, 0, 0, '下一个'), 1410 btnClose: new XButton(0, 0, 0, 0, '关闭'), 1411 }; 1412 let x = this.searchInput.pos[0]; 1413 let y = this.searchInput.pos[1]; 1414 let w = this.searchInput.pos[2]; 1415 let h = this.searchInput.pos[3]; 1416 CanvasInput.Reset(x, y + (h - 20) / 2, 258, 32, '', null, (v) => { 1417 this.searchInput.result = []; 1418 if (v.length > 0) { 1419 this.searchNodeByName( 1420 this.files_[this.filePoint_], 1421 v, 1422 this.searchInput.result 1423 ); 1424 if (this.searchInput.result.length > 0) { 1425 this.locateNode(this.searchInput.result[0]); 1426 this.searchInput.point = 0; 1427 } 1428 } 1429 }); 1430 CanvasInput.SetSafeArea(...this.searchInput.pos); 1431 } else if (k == 'ctrl+c') { 1432 if (this.nodePoint_ != null) { 1433 this.selectNode_ = { 1434 type: 'copy_node', 1435 pnode: this.nodePoint_, 1436 }; 1437 } 1438 } else if (k == 'ctrl+x') { 1439 if (this.nodePoint_ != null) { 1440 this.selectNode_ = { 1441 type: 'cut_node', 1442 pnode: this.nodePoint_, 1443 }; 1444 } 1445 } else if (k == 'ctrl+v') { 1446 if (this.selectNode_.type != null && this.nodePoint_ != null) { 1447 let parent = this.nodePoint_; 1448 if (this.nodePoint_.type_ != DataType.NODE) { 1449 parent = this.nodePoint_.parent_; 1450 } 1451 parent.value_.push(NodeTools.copyNode(this.selectNode_.pnode, parent)); 1452 if (this.selectNode_.type == 'cut_node') { 1453 ModifyNode.deleteNode(this.selectNode_.pnode); 1454 this.selectNode_.type = null; 1455 } 1456 this.checkAllError(); 1457 } 1458 } else if (k == 'Delete') { 1459 if (this.nodePoint_ != null) { 1460 ModifyNode.deleteNode(this.nodePoint_); 1461 AttrEditor.gi().freshEditor(); 1462 } 1463 } 1464 } 1465 1466 procAll() { 1467 while (this.touchQueue_.length > 0) { 1468 let touch = this.touchQueue_.shift(); 1469 this.procTouch(touch[0], touch[1], touch[2]); 1470 } 1471 1472 while (this.keyQueue_.length > 0) { 1473 let k = this.keyQueue_.shift(); 1474 this.procKey(k); 1475 } 1476 } 1477 onSelectInclude(sel) { 1478 MainEditor.gi().filePoint_ = sel; 1479 MainEditor.gi().rootPoint_ = sel; 1480 AttrEditor.gi().freshEditor(); 1481 } 1482 1483 nodeCount(data) { 1484 let ret = 1; 1485 switch (data.type_) { 1486 case 1: 1487 case 2: 1488 case 3: 1489 case 4: 1490 case 5: 1491 break; 1492 case 6: 1493 for (let i in data.value_) { 1494 ret += this.nodeCount(data.value_[i]); 1495 } 1496 break; 1497 case 7: 1498 ret += this.nodeCount(data.value_); 1499 break; 1500 case 8: 1501 case 9: 1502 case 10: 1503 case 11: 1504 break; 1505 default: 1506 NapiLog.logError('unknow' + data.type_); 1507 break; 1508 } 1509 return ret; 1510 } 1511 isNodeCountChanged(fn, bset = true) { 1512 if (!(fn in this.nodeCount_)) { 1513 this.nodeCount_[fn] = -1; 1514 } 1515 let newcount = this.nodeCount(this.files_[fn]); 1516 if (this.nodeCount_[fn] != newcount) { 1517 if (bset) { 1518 this.nodeCount_[fn] = newcount; 1519 } 1520 return true; 1521 } 1522 return false; 1523 } 1524 saveHistory(fn, data2, pth, pos = null) { 1525 console.log('!!! save History ', this.historyZ.length, pos); 1526 if (fn in this.historyBase) { 1527 this.historyZ.push({ 1528 fn: fn, 1529 data: data2, 1530 sel: pth, 1531 }); 1532 this.historyPushed = true; 1533 } else { 1534 this.historyBase[fn] = { 1535 fn: fn, 1536 data: data2, 1537 sel: pth, 1538 }; 1539 } 1540 } 1541 onAttributeChange(type, value) { 1542 let pme = MainEditor.gi(); 1543 if (type == 'writefile') { 1544 let data1 = Generator.gi().makeHcs(pme.filePoint_, pme.files_[pme.filePoint_]); 1545 let data2 = []; 1546 for (let j in data1) { 1547 data2.push(data1.charCodeAt(j)); 1548 } 1549 if (pme.isNodeCountChanged(pme.filePoint_)) { 1550 Lexer.FILE_AND_DATA[pme.filePoint_] = data2; 1551 pme.parse(pme.filePoint_); 1552 let t = NodeTools.getPathByNode(pme.nodePoint_, false); 1553 if (t) { 1554 pme.nodePoint_ = NodeTools.getNodeByPath(pme.files_[pme.filePoint_], t); 1555 } else { 1556 pme.nodePoint_ = null; 1557 } 1558 if (pme.selectNode_.pnode) { 1559 let t = NodeTools.getPathByNode(pme.selectNode_.pnode, false); 1560 if (t) { 1561 pme.selectNode_.pnode = NodeTools.getNodeByPath(pme.files_[pme.filePoint_], t); 1562 } else { 1563 pme.selectNode_.pnode = null; 1564 } 1565 } 1566 AttrEditor.gi().freshEditor(pme.filePoint_, pme.nodePoint_); 1567 } 1568 pme.checkAllError(); 1569 XMessage.gi().send('writefile', { 1570 fn: pme.filePoint_, 1571 data: data1, 1572 }); 1573 pme.saveHistory(pme.filePoint_, data2, NodeTools.getPathByNode(pme.nodePoint_), 1); 1574 } else if (type.substring(0, 13) == 'change_target') { 1575 pme.selectNode_.type = type; 1576 pme.selectNode_.pnode = value; 1577 } else if (type.startsWith('cancel_change_target')) { 1578 pme.selectNode_.type = null; 1579 } else if (type == 'change_current_select') { 1580 pme.nodePoint_ = value; 1581 AttrEditor.gi().freshEditor(pme.filePoint_, pme.nodePoint_); 1582 } 1583 } 1584 onError(msg) {} 1585 onTouch(msg, x, y) { 1586 this.touchQueue_.push([msg, x, y]); 1587 } 1588 onKey(k) { 1589 this.keyQueue_.push(k); 1590 } 1591 onReceive(type, data) { 1592 console.log('onReceive type=' + type); 1593 NapiLog.logError(type); 1594 let me = MainEditor.gi(); 1595 if (type == 'parse') { 1596 me.parse(data); 1597 } else if (type == 'filedata') { 1598 me.saveHistory(data.fn, data.data, null, 2); 1599 Lexer.FILE_AND_DATA[data.fn] = data.data; 1600 me.parse(data.fn); 1601 } else if (type == 'freshfiledata') { 1602 me.saveHistory(data.fn, data.data, null, 3); 1603 Lexer.FILE_AND_DATA[data.fn] = data.data; 1604 } else if (type == 'whiteCutImg') { 1605 let u8arr = new Uint8Array(data.data); 1606 let imgobj = new Blob([u8arr], { type: 'image/png' }); 1607 let wurl = window.URL.createObjectURL(imgobj); 1608 me.initCutData(wurl); 1609 } else if (type == 'circleImg') { 1610 let u8arr = new Uint8Array(data.data); 1611 let imgobj = new Blob([u8arr], { type: 'image/png' }); 1612 let wurl = window.URL.createObjectURL(imgobj); 1613 me.initCicleImgData(wurl); 1614 } else if (type == 'cicleOpenImg') { 1615 let u8arr = new Uint8Array(data.data); 1616 let imgobj = new Blob([u8arr], { type: 'image/png' }); 1617 let wurl = window.URL.createObjectURL(imgobj); 1618 me.initcicleOpenImgData(wurl); 1619 } else if (type == 'rectangleFocusImg') { 1620 let u8arr = new Uint8Array(data.data); 1621 let imgobj = new Blob([u8arr], { type: 'image/png' }); 1622 let wurl = window.URL.createObjectURL(imgobj); 1623 me.initRectangleFocusImgData(wurl); 1624 } else if (type == 'nodeIconImg') { 1625 let u8arr = new Uint8Array(data.data); 1626 let imgobj = new Blob([u8arr], { type: 'image/png' }); 1627 let wurl = window.URL.createObjectURL(imgobj); 1628 me.initNodeIconImgData(wurl); 1629 } else if (type == 'attrIconImg') { 1630 let u8arr = new Uint8Array(data.data); 1631 let imgobj = new Blob([u8arr], { type: 'image/png' }); 1632 let wurl = window.URL.createObjectURL(imgobj); 1633 me.initAttrIconImgData(wurl); 1634 } else if (type == 'rootIconImg') { 1635 let u8arr = new Uint8Array(data.data); 1636 let imgobj = new Blob([u8arr], { type: 'image/png' }); 1637 let wurl = window.URL.createObjectURL(imgobj); 1638 me.initRootIconImgData(wurl); 1639 } else if (type == 'rootIconFocusImg') { 1640 let u8arr = new Uint8Array(data.data); 1641 let imgobj = new Blob([u8arr], { type: 'image/png' }); 1642 let wurl = window.URL.createObjectURL(imgobj); 1643 me.initRootIconFocusImgData(wurl); 1644 } else if (type == 'backgroundImg') { 1645 let u8arr = new Uint8Array(data.data); 1646 let imgobj = new Blob([u8arr], { type: 'image/png' }); 1647 let wurl = window.URL.createObjectURL(imgobj); 1648 me.initBackgroundImgData(wurl); 1649 } else if (type == 'popItemFocusImg') { 1650 let u8arr = new Uint8Array(data.data); 1651 let imgobj = new Blob([u8arr], { type: 'image/png' }); 1652 let wurl = window.URL.createObjectURL(imgobj); 1653 me.initPopItemFocusImgData(wurl); 1654 } else if (type == 'colorThemeChanged') { 1655 me.reloadMenuBgPic(); 1656 } else if (type == 'searchBgImg') { 1657 let u8arr = new Uint8Array(data.data); 1658 let imgobj = new Blob([u8arr], { type: 'image/png' }); 1659 let wurl = window.URL.createObjectURL(imgobj); 1660 me.initSearchBgImgData(wurl); 1661 } else if (type == 'upCutImg') { 1662 let u8arr = new Uint8Array(data.data); 1663 let imgobj = new Blob([u8arr], { type: 'image/png' }); 1664 let wurl = window.URL.createObjectURL(imgobj); 1665 me.initUpImgData(wurl); 1666 } else if (type == 'downCut') { 1667 let u8arr = new Uint8Array(data.data); 1668 let imgobj = new Blob([u8arr], { type: 'image/png' }); 1669 let wurl = window.URL.createObjectURL(imgobj); 1670 me.initDownImgData(wurl); 1671 } else if (type == 'closeCutImg') { 1672 let u8arr = new Uint8Array(data.data); 1673 let imgobj = new Blob([u8arr], { type: 'image/png' }); 1674 let wurl = window.URL.createObjectURL(imgobj); 1675 me.initCloseImgData(wurl); 1676 } else if (type == 'searchCutImg') { 1677 let u8arr = new Uint8Array(data.data); 1678 let imgobj = new Blob([u8arr], { type: 'image/png' }); 1679 let wurl = window.URL.createObjectURL(imgobj); 1680 me.initSearchImgData(wurl); 1681 } else if (type == 'searchNoodRectImg') { 1682 let u8arr = new Uint8Array(data.data); 1683 let imgobj = new Blob([u8arr], { type: 'image/png' }); 1684 let wurl = window.URL.createObjectURL(imgobj); 1685 me.initSearchNoodRectImgData(wurl); 1686 } else if (type == 'searchAttrRectImg') { 1687 let u8arr = new Uint8Array(data.data); 1688 let imgobj = new Blob([u8arr], { type: 'image/png' }); 1689 let wurl = window.URL.createObjectURL(imgobj); 1690 me.initSearchAttrRectImgData(wurl); 1691 } else { 1692 NapiLog.logError('onReceive is not need'); 1693 } 1694 } 1695 1696 initSearchAttrRectImgData(wurl) { 1697 this.searchAttrCicleImg_ = XTexture.gi().loadTextureFromImage(wurl); 1698 this.leftSearchAttrCicleCut_ = XTexture.gi().makeCut( 1699 this.searchAttrCicleImg_, 1700 0, 1701 0, 1702 8, 1703 32, 1704 132, 1705 32 1706 ); 1707 this.centerSearchAttrCut_ = XTexture.gi().makeCut( 1708 this.searchAttrCicleImg_, 1709 8, 1710 0, 1711 116, 1712 32, 1713 132, 1714 32 1715 ); 1716 this.rightSearchAttrCicleCut_ = XTexture.gi().makeCut( 1717 this.searchAttrCicleImg_, 1718 124, 1719 0, 1720 8, 1721 32, 1722 132, 1723 32 1724 ); 1725 } 1726 1727 initSearchNoodRectImgData(wurl) { 1728 this.searchRectFocusCicleImg_ = XTexture.gi().loadTextureFromImage(wurl); 1729 this.leftSearchFocusCicleCut_ = XTexture.gi().makeCut( 1730 this.searchRectFocusCicleImg_, 1731 0, 1732 0, 1733 8, 1734 32, 1735 132, 1736 32 1737 ); 1738 this.centerSearchCut_ = XTexture.gi().makeCut( 1739 this.searchRectFocusCicleImg_, 1740 8, 1741 0, 1742 116, 1743 32, 1744 132, 1745 32 1746 ); 1747 this.rightSearchFocusCicleCut_ = XTexture.gi().makeCut( 1748 this.searchRectFocusCicleImg_, 1749 124, 1750 0, 1751 8, 1752 32, 1753 132, 1754 32 1755 ); 1756 } 1757 1758 initSearchImgData(wurl) { 1759 this.searchImg_ = XTexture.gi().loadTextureFromImage(wurl); 1760 this.searchCut_ = XTexture.gi().makeCut( 1761 this.searchImg_, 1762 0, 1763 0, 1764 16, 1765 16, 1766 16, 1767 16 1768 ); 1769 } 1770 1771 initCloseImgData(wurl) { 1772 this.closeImg_ = XTexture.gi().loadTextureFromImage(wurl); 1773 this.closeCut_ = XTexture.gi().makeCut( 1774 this.closeImg_, 1775 0, 1776 0, 1777 16, 1778 16, 1779 16, 1780 16 1781 ); 1782 } 1783 1784 initDownImgData(wurl) { 1785 this.downImg_ = XTexture.gi().loadTextureFromImage(wurl); 1786 this.downCut_ = XTexture.gi().makeCut(this.downImg_, 0, 0, 16, 16, 16, 16); 1787 } 1788 1789 initUpImgData(wurl) { 1790 this.upImg_ = XTexture.gi().loadTextureFromImage(wurl); 1791 this.upCut_ = XTexture.gi().makeCut(this.upImg_, 0, 0, 16, 16, 16, 16); 1792 } 1793 1794 initSearchBgImgData(wurl) { 1795 this.searchBgImg_ = XTexture.gi().loadTextureFromImage(wurl); 1796 this.searchBgCut_ = XTexture.gi().makeCut( 1797 this.searchBgImg_, 1798 0, 1799 0, 1800 494, 1801 56, 1802 494, 1803 56 1804 ); 1805 } 1806 1807 initPopItemFocusImgData(wurl) { 1808 RightMenu.popItemFocusImg_ = XTexture.gi().loadTextureFromImage(wurl); 1809 RightMenu.popItemFocusCut_ = XTexture.gi().makeCut( 1810 RightMenu.popItemFocusImg_, 1811 0, 1812 0, 1813 148, 1814 32, 1815 148, 1816 32 1817 ); 1818 } 1819 1820 initBackgroundImgData(wurl) { 1821 RightMenu.backgroundImg_ = XTexture.gi().loadTextureFromImage(wurl); 1822 RightMenu.backgroundCut_ = XTexture.gi().makeCut( 1823 RightMenu.backgroundImg_, 1824 0, 1825 0, 1826 156, 1827 112, 1828 156, 1829 112 1830 ); 1831 } 1832 1833 initRootIconFocusImgData(wurl) { 1834 this.rootIconFocusImg_ = XTexture.gi().loadTextureFromImage(wurl); 1835 this.rootIconFocusCut_ = XTexture.gi().makeCut( 1836 this.rootIconFocusImg_, 1837 0, 1838 0, 1839 132, 1840 32, 1841 132, 1842 32 1843 ); 1844 } 1845 1846 initRootIconImgData(wurl) { 1847 this.rootIconImg_ = XTexture.gi().loadTextureFromImage(wurl); 1848 this.rootIconCut_ = XTexture.gi().makeCut( 1849 this.rootIconImg_, 1850 0, 1851 0, 1852 132, 1853 32, 1854 132, 1855 32 1856 ); 1857 } 1858 1859 initAttrIconImgData(wurl) { 1860 this.attrIconImg_ = XTexture.gi().loadTextureFromImage(wurl); 1861 this.attrIconCut_ = XTexture.gi().makeCut( 1862 this.attrIconImg_, 1863 0, 1864 0, 1865 8, 1866 8, 1867 8, 1868 8 1869 ); 1870 } 1871 1872 initNodeIconImgData(wurl) { 1873 this.nodeIconImg_ = XTexture.gi().loadTextureFromImage(wurl); 1874 this.nodeIconCut_ = XTexture.gi().makeCut( 1875 this.nodeIconImg_, 1876 0, 1877 0, 1878 8, 1879 8, 1880 8, 1881 8 1882 ); 1883 } 1884 1885 initcicleOpenImgData(wurl) { 1886 this.cicleOpenImg_ = XTexture.gi().loadTextureFromImage(wurl); 1887 this.circleOpenCut_ = XTexture.gi().makeCut( 1888 this.cicleOpenImg_, 1889 0, 1890 0, 1891 20, 1892 20, 1893 20, 1894 20 1895 ); 1896 } 1897 1898 initRectangleFocusImgData(wurl) { 1899 this.rectangleFocusImg_ = XTexture.gi().loadTextureFromImage(wurl); 1900 this.rectangleFocusCut_ = XTexture.gi().makeCut( 1901 this.rectangleFocusImg_, 1902 0, 1903 0, 1904 132, 1905 32, 1906 132, 1907 32 1908 ); 1909 this.leftRectFocusCicleCut_ = XTexture.gi().makeCut( 1910 this.rectangleFocusImg_, 1911 0, 1912 0, 1913 8, 1914 32, 1915 132, 1916 32 1917 ); 1918 this.centerFocusCut_ = XTexture.gi().makeCut( 1919 this.rectangleFocusImg_, 1920 8, 1921 0, 1922 116, 1923 32, 1924 132, 1925 32 1926 ); 1927 this.rightRectFocusCicleCut_ = XTexture.gi().makeCut( 1928 this.rectangleFocusImg_, 1929 124, 1930 0, 1931 8, 1932 32, 1933 132, 1934 32 1935 ); 1936 } 1937 1938 initCicleImgData(wurl) { 1939 this.cicleImg_ = XTexture.gi().loadTextureFromImage(wurl); 1940 this.circleCut_ = XTexture.gi().makeCut( 1941 this.cicleImg_, 1942 0, 1943 0, 1944 20, 1945 20, 1946 20, 1947 20 1948 ); 1949 } 1950 1951 initCutData(wurl) { 1952 this.whiteImg_ = XTexture.gi().loadTextureFromImage(wurl); 1953 this.whiteCut_ = XTexture.gi().makeCut( 1954 this.whiteImg_, 1955 0, 1956 0, 1957 132, 1958 32, 1959 132, 1960 32 1961 ); 1962 this.leftRectCicleCut_ = XTexture.gi().makeCut( 1963 this.whiteImg_, 1964 0, 1965 0, 1966 8, 1967 32, 1968 132, 1969 32 1970 ); 1971 this.centerRectCut_ = XTexture.gi().makeCut( 1972 this.whiteImg_, 1973 8, 1974 0, 1975 116, 1976 32, 1977 132, 1978 32 1979 ); 1980 this.rightRectCicleCut_ = XTexture.gi().makeCut( 1981 this.whiteImg_, 1982 124, 1983 0, 1984 8, 1985 32, 1986 132, 1987 32 1988 ); 1989 } 1990 1991 syncOpenStatus(newNode, oldParentNode) { 1992 let oldNode = null; 1993 for (let i = 0; i < oldParentNode.value_.length; ++i) { 1994 if (newNode.name_ === oldParentNode.value_[i].name_) { 1995 oldNode = oldParentNode.value_[i]; 1996 } 1997 } 1998 if (oldNode == null) { 1999 return; 2000 } 2001 newNode.isOpen_ = oldNode.isOpen_; 2002 2003 for (let j = 0; j < newNode.value_.length; ++j) { 2004 this.syncOpenStatus(newNode.value_[j], oldNode); 2005 } 2006 } 2007 2008 syncRootStatus(newRoot, oldRoot) { 2009 newRoot.isOpen_ = oldRoot.isOpen_; 2010 for (let i = 0; i < newRoot.value_.length; ++i) { 2011 this.syncOpenStatus(newRoot.value_[i], oldRoot); 2012 } 2013 } 2014 2015 parse(fn) { 2016 if (this.rootPoint_ == null) { 2017 this.rootPoint_ = fn; 2018 } 2019 let t = Generator.gi().hcsToAst(fn); 2020 if (!t) { 2021 return; 2022 } 2023 2024 let fs = []; 2025 for (let i in t) { 2026 let newRoot = Generator.gi().astToObj(t[i].ast.astRoot_); 2027 2028 if (this.files_[i]) { 2029 this.syncRootStatus(newRoot, this.files_[i]); 2030 } 2031 2032 this.files_[i] = newRoot; 2033 fs.push(i); 2034 } 2035 this.filePoint_ = this.rootPoint_; 2036 this.sltInclude.resetList(fs, this.filePoint_); 2037 AttrEditor.gi().setFiles(this.files_); 2038 2039 this.checkAllError(); 2040 } 2041 2042 checkAllError() { 2043 NapiLog.clearError(); 2044 let n1 = Generator.gi().mergeObj(this.files_); 2045 if (n1) { 2046 n1 = Generator.gi().expandObj(n1); 2047 if (NapiLog.getResult()[0]) { 2048 return true; 2049 } 2050 } 2051 return false; 2052 } 2053} 2054MainEditor.LINE_HEIGHT = 50; 2055MainEditor.NODE_RECT_HEIGHT = 32; 2056MainEditor.NODE_RECT_WIDTH = 132; 2057MainEditor.NODE_TEXT_COLOR = 0xffffffff; 2058MainEditor.NODE_TEXT_SIZE = 14; 2059MainEditor.BTN_CONTENT_OFFY = 4; 2060MainEditor.NODE_TEXT_OFFX = 5; 2061MainEditor.NODE_LINE_COLOR = 0xff979797; 2062MainEditor.NODE_SIZE_BG_OFFX = 4; 2063MainEditor.NODE_MORE_CHILD = 20; 2064MainEditor.LINE_WIDTH = 30; 2065MainEditor.LOGO_LEFT_PADDING = 14; 2066MainEditor.LOGO_SIZE = 8; 2067 2068MainEditor.pInstance_ = null; 2069MainEditor.gi = function () { 2070 if (MainEditor.pInstance_ == null) { 2071 MainEditor.pInstance_ = new MainEditor(); 2072 } 2073 return MainEditor.pInstance_; 2074}; 2075 2076module.exports = { 2077 MainEditor, 2078}; 2079