From 682873673b6170e02b69cf686bd64bcc74543943 Mon Sep 17 00:00:00 2001 From: YouWei Zhao Date: Wed, 12 Dec 2018 18:27:34 -0500 Subject: [PATCH 1/3] lastusedblocks --- _server/editor_blockly.js | 50 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/_server/editor_blockly.js b/_server/editor_blockly.js index 864fb7fd..4d4af6a0 100644 --- a/_server/editor_blockly.js +++ b/_server/editor_blockly.js @@ -4,12 +4,13 @@ editor_blockly = function () { initscript = String.raw` (function(){ - var getCategory = function(name){ + var getCategory = function(name,custom){ for(var node of document.getElementById('toolbox').children) { if(node.getAttribute('name')==name) return node; } var node = document.createElement('category'); node.setAttribute('name',name); + if(custom)node.setAttribute('custom',custom); document.getElementById('toolbox').appendChild(node); return node; } @@ -243,15 +244,19 @@ editor_blockly = function () { } ] },'event'), - ], + '最近使用':[ + '', + ] } var toolboxgap = '' //xml_text = MotaActionFunctions.actionParser.parse(obj,type||'event') //MotaActionBlocks['idString_e'].xmlText() for (var name in toolboxObj){ - getCategory(name).innerHTML = toolboxObj[name].join(toolboxgap); + var custom = null; + if(name=='最近使用')custom='searchBlockCategory'; + getCategory(name,custom).innerHTML = toolboxObj[name].join(toolboxgap); } var blocklyArea = document.getElementById('blocklyArea'); @@ -269,6 +274,24 @@ var workspace = Blockly.inject(blocklyDiv,{ }, trashcan: false, }); + +editor_blockly.searchBlockCategoryCallback = function(workspace) { + //var colourList = ['#4286f4', '#ef0447']; + var xmlList = []; + if (Blockly.Blocks['colour_picker']) { + for (var i = 0; i < editor_blockly.lastUsedType.length; i++) { + var blockText = '' + + MotaActionBlocks[editor_blockly.lastUsedType[i]].xmlText() + + ''; + var block = Blockly.Xml.textToDom(blockText).firstChild; + xmlList.push(block); + } + } + return xmlList; +}; + +workspace.registerToolboxCategoryCallback( + 'searchBlockCategory', editor_blockly.searchBlockCategoryCallback); var onresize = function(e) { blocklyDiv.style.width = blocklyArea.offsetWidth + 'px'; @@ -291,6 +314,12 @@ document.getElementById('blocklyDiv').onmousewheel = function(e){ var doubleClickCheck=[[0,'abc']]; function omitedcheckUpdateFunction(event) { + console.log(event) + console.log(event.type) + + if(event.type==='ui'||event.type==='move'){ + editor_blockly.addIntoLastUsedType(event.blockId); + } if(event.type==='ui'){ var newClick = [new Date().getTime(),event.blockId]; var lastClick = doubleClickCheck.shift(); @@ -511,6 +540,21 @@ document.getElementById('blocklyDiv').onmousewheel = function(e){ } } + editor_blockly.lastUsedType=['comment_s']//初始空着比较难看 + editor_blockly.lastUsedTypeNum=15 + + editor_blockly.addIntoLastUsedType=function(blockId){ + var b = editor_blockly.workspace.getBlockById(blockId); + if(!b)return; + var blockType = b.type; + if(!blockType || ['pass_s','emptyshop'].indexOf(blockType)!==-1)return; + if(editor_blockly.lastUsedType.indexOf(blockType)!==-1){ + editor_blockly.lastUsedType.splice(editor_blockly.lastUsedType.indexOf(blockType),1) + } + editor_blockly.lastUsedType.unshift(blockType) + editor_blockly.lastUsedType=editor_blockly.lastUsedType.slice(0,editor_blockly.lastUsedTypeNum) + } + return editor_blockly; } //editor_blockly=editor_blockly(); \ No newline at end of file From 556dd15dc2bf36c6461ac3b5187a829c1122eb50 Mon Sep 17 00:00:00 2001 From: YouWei Zhao Date: Wed, 12 Dec 2018 18:31:59 -0500 Subject: [PATCH 2/3] delete console.log(...) --- _server/editor_blockly.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/_server/editor_blockly.js b/_server/editor_blockly.js index 4d4af6a0..c8ff17ff 100644 --- a/_server/editor_blockly.js +++ b/_server/editor_blockly.js @@ -276,7 +276,6 @@ var workspace = Blockly.inject(blocklyDiv,{ }); editor_blockly.searchBlockCategoryCallback = function(workspace) { - //var colourList = ['#4286f4', '#ef0447']; var xmlList = []; if (Blockly.Blocks['colour_picker']) { for (var i = 0; i < editor_blockly.lastUsedType.length; i++) { @@ -314,9 +313,6 @@ document.getElementById('blocklyDiv').onmousewheel = function(e){ var doubleClickCheck=[[0,'abc']]; function omitedcheckUpdateFunction(event) { - console.log(event) - console.log(event.type) - if(event.type==='ui'||event.type==='move'){ editor_blockly.addIntoLastUsedType(event.blockId); } From 560c6136f7de463c183c6ee5ddd027316f4c5385 Mon Sep 17 00:00:00 2001 From: YouWei Zhao Date: Wed, 12 Dec 2018 18:33:57 -0500 Subject: [PATCH 3/3] fix --- _server/editor_blockly.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/_server/editor_blockly.js b/_server/editor_blockly.js index c8ff17ff..dd449a91 100644 --- a/_server/editor_blockly.js +++ b/_server/editor_blockly.js @@ -277,14 +277,12 @@ var workspace = Blockly.inject(blocklyDiv,{ editor_blockly.searchBlockCategoryCallback = function(workspace) { var xmlList = []; - if (Blockly.Blocks['colour_picker']) { - for (var i = 0; i < editor_blockly.lastUsedType.length; i++) { - var blockText = '' + - MotaActionBlocks[editor_blockly.lastUsedType[i]].xmlText() + - ''; - var block = Blockly.Xml.textToDom(blockText).firstChild; - xmlList.push(block); - } + for (var i = 0; i < editor_blockly.lastUsedType.length; i++) { + var blockText = '' + + MotaActionBlocks[editor_blockly.lastUsedType[i]].xmlText() + + ''; + var block = Blockly.Xml.textToDom(blockText).firstChild; + xmlList.push(block); } return xmlList; };