更新blockly到最新;修复复制粘贴问题

This commit is contained in:
ckcz123 2020-06-15 17:22:40 +08:00
parent 0a14502d94
commit 176e5a9798
8 changed files with 175 additions and 268 deletions

View File

@ -202,13 +202,6 @@ textarea[disabled] {
/** ======== blockly 相关 ======== */ /** ======== blockly 相关 ======== */
/**
blockly图块的的黑暗程度用opacity表示0到1之间
0表示表示纯亮色1表示纯黑色
*/
#blocklyDarkScale {
opacity: 0;
}
/*魔改*/ /*魔改*/
.blocklyTreeLabel { .blocklyTreeLabel {

View File

@ -166,8 +166,8 @@ select {
background-color: #33333c; background-color: #33333c;
} }
.gameCanvas, img { .gameCanvas, img, svg {
filter: brightness(0.75); filter: brightness(0.65);
} }
/** 搜索事件块的输入框 */ /** 搜索事件块的输入框 */
@ -298,11 +298,6 @@ blockly图块的的黑暗程度用opacity表示0到1之间
0表示表示纯亮色1表示纯黑色 0表示表示纯亮色1表示纯黑色
*/ */
#blocklyDarkScale {
opacity: 0.3;
}
/** 如果需要blockly深色模式请有选择性视情况取消注释下面几条具体功能自行研究 */ /** 如果需要blockly深色模式请有选择性视情况取消注释下面几条具体功能自行研究 */
/*somethingSOMETHING*/ /*somethingSOMETHING*/
@ -372,7 +367,6 @@ input.blocklyHtmlInput {
background-color: black; background-color: black;
} }
/** ======== Blockly中自动补全相关 ======== */ /** ======== Blockly中自动补全相关 ======== */
.awesomplete > ul { .awesomplete > ul {
background: #33333c; background: #33333c;

View File

@ -689,156 +689,7 @@ editor_blockly = function () {
editor_blockly.completeItems = []; editor_blockly.completeItems = [];
Blockly.BlockSvg.prototype.updateColour_origin = Blockly.BlockSvg.prototype.updateColour; editor_blockly.onTextFieldCreate = function (self, htmlInput) {
Blockly.BlockSvg.prototype.setShadowColour__origin = Blockly.BlockSvg.prototype.setShadowColour_;
Blockly.BlockSvg.prototype.setBorderColour__origin = Blockly.BlockSvg.prototype.setBorderColour_;
editor_blockly.setDarkScale=function () {
var computedStyle = window.getComputedStyle(document.getElementById('blocklyDarkScale')) || {};
var globalScale = parseFloat(computedStyle.opacity) || 0;
if (globalScale > 0) {
// todo: fix to suit the new blockly version
// ref https://github.com/google/blockly/tree/52b818ed67c5bfa7fd73edf2b067649b8b1f447b
Blockly.BlockSvg.prototype.updateColour = function() {
if (this.disabled) {
// Disabled blocks don't have colour.
return;
}
var hexColour = this.getColour();
var colourSecondary = this.getColourSecondary();
var colourTertiary = this.getColourTertiary();
var rgb = goog.color.darken(goog.color.hexToRgb(hexColour),globalScale);
hexColour = goog.color.rgbArrayToHex(rgb);
if (this.isShadow()) {
hexColour = this.setShadowColour_(rgb, colourSecondary);
} else {
this.setBorderColour_(rgb, colourTertiary);
}
this.svgPath_.setAttribute('fill', hexColour);
var icons = this.getIcons();
for (var i = 0; i < icons.length; i++) {
icons[i].updateColour();
}
// Bump every dropdown to change its colour.
// TODO (#1456)
for (var x = 0, input; input = this.inputList[x]; x++) {
for (var y = 0, field; field = input.fieldRow[y]; y++) {
field.forceRerender();
}
}
}
// todo: fix to suit the new blockly version
// ref https://github.com/google/blockly/tree/52b818ed67c5bfa7fd73edf2b067649b8b1f447b
Blockly.BlockSvg.prototype.setShadowColour_ = function(a, b) {
if (b) {
this.svgPathLight_.style.display = "none";
this.svgPathDark_.style.display = "none";
this.svgPath_.setAttribute("fill", b);
var c = b
} else
a = goog.color.darken(a, .4),
c = goog.color.rgbArrayToHex(a),
this.svgPathLight_.style.display = "none",
this.svgPathDark_.setAttribute("fill", c);
return c
}
// todo: fix to suit the new blockly version
// ref https://github.com/google/blockly/tree/52b818ed67c5bfa7fd73edf2b067649b8b1f447b
Blockly.BlockSvg.prototype.setBorderColour_ = function(a, b) {
if (b)
this.svgPathLight_.setAttribute("stroke", "none"),
this.svgPathDark_.setAttribute("fill", "none"),
this.svgPath_.setAttribute("stroke", b);
else {
this.svgPathLight_.style.display = "";
var c = goog.color.rgbArrayToHex(goog.color.darken(a, .2))
, d = goog.color.rgbArrayToHex(goog.color.lighten(a, .3));
this.svgPathLight_.setAttribute("stroke", c);
this.svgPathDark_.setAttribute("fill", d);
this.svgPath_.setAttribute("stroke", "none")
}
}
} else {
Blockly.BlockSvg.prototype.updateColour = Blockly.BlockSvg.prototype.updateColour_origin;
Blockly.BlockSvg.prototype.setShadowColour_ = Blockly.BlockSvg.prototype.setShadowColour__origin;
Blockly.BlockSvg.prototype.setBorderColour_ = Blockly.BlockSvg.prototype.setBorderColour__origin;
}
}
editor_blockly.setDarkScale();
return editor_blockly;
}
// --- modify Blockly
// todo: fix to suit the new blockly version
// ref https://github.com/google/blockly/tree/52b818ed67c5bfa7fd73edf2b067649b8b1f447b
Blockly.FieldColour.prototype.createWidget_ = function() {
Blockly.WidgetDiv.hide();
// console.log('here')
var self=this;
var pb=self.sourceBlock_
var args = MotaActionBlocks[pb.type].args
var targetf=args[args.indexOf(self.name)-1]
var getValue=function(){
// return self.getValue() // css颜色
var f = pb.getFieldValue(targetf);
if (/^[0-9 ]+,[0-9 ]+,[0-9 ]+(,[0-9. ]+)?$/.test(f)) {
return f;
}
return "";
// 也可以用 pb.getFieldValue(targetf) 获得颜色块左边的域的内容
}
var setValue=function(newValue){ // css颜色
self.setValue(newValue)
var c=new Colors();
c.setColor(newValue)
var rgbatext = [c.colors.webSmart.r,c.colors.webSmart.g,c.colors.webSmart.b,c.colors.alpha].join(",");
pb.setFieldValue(rgbatext, targetf) // 放在颜色块左边的域中
}
setTimeout(function () {
document.getElementById("colorPicker").value = getValue();
// 设置位置
openColorPicker(Blockly.WidgetDiv.DIV.style.left.replace(/[^\d.]/g, ''), Blockly.WidgetDiv.DIV.style.top.replace(/[^\d.]/g, ''), setValue);
});
return document.createElement('table');
};
// todo: fix to suit the new blockly version
// ref https://github.com/google/blockly/tree/52b818ed67c5bfa7fd73edf2b067649b8b1f447b
Blockly.FieldTextInput.prototype.showInlineEditor_ = function(quietInput) {
Blockly.WidgetDiv.show(this, this.sourceBlock_.RTL, this.widgetDispose_());
var div = Blockly.WidgetDiv.DIV;
// Create the input.
var htmlInput =
goog.dom.createDom(goog.dom.TagName.INPUT, 'blocklyHtmlInput');
htmlInput.setAttribute('spellcheck', this.spellcheck_);
var fontSize =
(Blockly.FieldTextInput.FONTSIZE * this.workspace_.scale) + 'pt';
div.style.fontSize = fontSize;
htmlInput.style.fontSize = fontSize;
Blockly.FieldTextInput.htmlInput_ = htmlInput;
div.appendChild(htmlInput);
htmlInput.value = htmlInput.defaultValue = this.text_;
htmlInput.oldValue_ = null;
// console.log('here')
var self=this;
var pb=self.sourceBlock_ var pb=self.sourceBlock_
var args = MotaActionBlocks[pb.type].args var args = MotaActionBlocks[pb.type].args
var targetf=args[args.indexOf(self.name)+1] var targetf=args[args.indexOf(self.name)+1]
@ -888,6 +739,8 @@ Blockly.FieldTextInput.prototype.showInlineEditor_ = function(quietInput) {
var str = value.substring(0, index - awesomplete.prefix.length) + text + value.substring(index); var str = value.substring(0, index - awesomplete.prefix.length) + text + value.substring(index);
this.input.value = str; this.input.value = str;
pb.setFieldValue(str, self.name); pb.setFieldValue(str, self.name);
self.forceRerender();
self.resizeEditor_();
index += text.length - awesomplete.prefix.length; index += text.length - awesomplete.prefix.length;
this.input.setSelectionRange(index, index); this.input.setSelectionRange(index, index);
@ -943,15 +796,79 @@ Blockly.FieldTextInput.prototype.showInlineEditor_ = function(quietInput) {
window.awesomplete = awesomplete; window.awesomplete = awesomplete;
} }
}
return editor_blockly;
}
// --- modify Blockly
Blockly.FieldColour.prototype.showEditor_ = function() {
Blockly.WidgetDiv.hide();
// console.log('here')
var self=this;
var pb=self.sourceBlock_
var args = MotaActionBlocks[pb.type].args
var targetf=args[args.indexOf(self.name)-1]
var getValue=function(){
// return self.getValue() // css颜色
var f = pb.getFieldValue(targetf);
if (/^[0-9 ]+,[0-9 ]+,[0-9 ]+(,[0-9. ]+)?$/.test(f)) {
return f;
}
return "";
// 也可以用 pb.getFieldValue(targetf) 获得颜色块左边的域的内容
}
var setValue=function(newValue){ // css颜色
self.setValue(newValue)
pb.setFieldValue(newValue.replace("rgba(","").replace(")",""), targetf) // 放在颜色块左边的域中
}
setTimeout(function () {
document.getElementById("colorPicker").value = getValue();
// 设置位置
var scaledBBox = self.getScaledBBox();
openColorPicker(scaledBBox.left, scaledBBox.bottom, setValue);
});
return document.createElement('table');
};
Blockly.FieldColour.prototype.setValue = function (colour) {
this.doValueUpdate_(colour);
}
Blockly.FieldTextInput.prototype.showInlineEditor_ = function(quietInput) {
Blockly.WidgetDiv.show(
this, this.sourceBlock_.RTL, this.widgetDispose_.bind(this));
this.htmlInput_ = this.widgetCreate_();
this.isBeingEdited_ = true;
editor_blockly.onTextFieldCreate(this, this.htmlInput_);
if (!quietInput) { if (!quietInput) {
htmlInput.focus(); this.htmlInput_.focus({preventScroll:true});
htmlInput.select(); this.htmlInput_.select();
} }
this.validate_(); };
this.resizeEditor_();
this.bindEvents_(htmlInput); Blockly.FieldTextInput.prototype.onHtmlInputKeyDown_ = function(e) {
if (e.keyCode == Blockly.utils.KeyCodes.ENTER && !(window.awesomplete && window.awesomplete.opened)) {
Blockly.WidgetDiv.hide();
Blockly.DropDownDiv.hideWithoutAnimation();
} else if (e.keyCode == Blockly.utils.KeyCodes.ESC) {
this.htmlInput_.value = this.htmlInput_.defaultValue;
Blockly.WidgetDiv.hide();
Blockly.DropDownDiv.hideWithoutAnimation();
} else if (e.keyCode == Blockly.utils.KeyCodes.TAB) {
Blockly.WidgetDiv.hide();
Blockly.DropDownDiv.hideWithoutAnimation();
this.sourceBlock_.tab(this, !e.shiftKey);
e.preventDefault();
}
}; };
Blockly.copy_ = function(toCopy) { Blockly.copy_ = function(toCopy) {
@ -964,27 +881,33 @@ Blockly.copy_ = function(toCopy) {
// Encode start position in XML. // Encode start position in XML.
var xy = toCopy.getRelativeToSurfaceXY(); var xy = toCopy.getRelativeToSurfaceXY();
xml.setAttribute('x', toCopy.RTL ? -xy.x : xy.x); xml.setAttribute('x', toCopy.RTL ? -xy.x : xy.x);
xml.setAttribute('y', xy.y); xml.setAttribute('oy', xy.y);
xml.setAttribute('sy', toCopy.workspace.scrollY);
} }
Blockly.clipboardXml_ = xml; Blockly.clipboardXml_ = xml;
Blockly.clipboardSource_ = toCopy.workspace; Blockly.clipboardSource_ = toCopy.workspace;
Blockly.clipboardTypeCounts_ = toCopy.isComment ? null : Blockly.clipboardTypeCounts_ = toCopy.isComment ? null :
Blockly.utils.getBlockTypeCounts(toCopy, true); Blockly.utils.getBlockTypeCounts(toCopy, true);
setTimeout(function(){Blockly.clipboardSource_.paste(Blockly.clipboardXml_)});
}; };
Blockly.duplicate = function(toDuplicate) { /**
// Save the clipboard. * Paste the provided block onto the workspace.
var clipboardXml = Blockly.clipboardXml_; * @param {!Element} xmlBlock XML block element.
var clipboardSource = Blockly.clipboardSource_; */
Blockly.WorkspaceSvg.prototype.paste = function(xmlBlock) {
// Create a duplicate via a copy/paste operation. if (!this.rendered || xmlBlock.getElementsByTagName('block').length >=
Blockly.copy_(toDuplicate); this.remainingCapacity()) {
return;
}
// Restore the clipboard. if (this.currentGesture_) {
Blockly.clipboardXml_ = clipboardXml; this.currentGesture_.cancel(); // Dragging while pasting? No.
Blockly.clipboardSource_ = clipboardSource; }
if (xmlBlock.tagName.toLowerCase() == 'comment') {
this.pasteWorkspaceComment_(xmlBlock);
} else {
if (xmlBlock.hasAttribute('oy') && xmlBlock.hasAttribute('sy')) {
xmlBlock.setAttribute('y', parseFloat(xmlBlock.getAttribute('oy')) + parseFloat(xmlBlock.getAttribute('sy')) - this.scrollY);
}
this.pasteBlock_(xmlBlock);
}
}; };
Blockly.utils.KeyCodes.V=99999

View File

@ -422,7 +422,7 @@ function omitedcheckUpdateFunction(event) {
if(event.type==='create'){ if(event.type==='create'){
editor_blockly.addIntoLastUsedType(event.blockId); editor_blockly.addIntoLastUsedType(event.blockId);
} }
if(event.type==='ui'){ if(event.type==='ui' && event.element == 'click'){
var newClick = [new Date().getTime(),event.blockId]; var newClick = [new Date().getTime(),event.blockId];
var lastClick = doubleClickCheck.shift(); var lastClick = doubleClickCheck.shift();
doubleClickCheck.push(newClick); doubleClickCheck.push(newClick);
@ -432,6 +432,8 @@ function omitedcheckUpdateFunction(event) {
} }
} }
} }
// Only handle these events
if (["create", "move", "change", "delete"].indexOf(event.type) < 0) return;
if(editor_blockly.workspace.topBlocks_.length>=2){ if(editor_blockly.workspace.topBlocks_.length>=2){
editor_blockly.setValue('入口方块只能有一个'); editor_blockly.setValue('入口方块只能有一个');
return; return;

View File

@ -396,10 +396,6 @@ editor_mappanel_wrapper = function (editor) {
var theme = editor.dom.editorTheme.value; var theme = editor.dom.editorTheme.value;
editor.config.set('theme', theme); editor.config.set('theme', theme);
document.getElementById('color_css').href = '_server/css/' + theme + '.css'; document.getElementById('color_css').href = '_server/css/' + theme + '.css';
// 等新的css加载完毕再设置blockly亮度
setTimeout(function () {
editor_blockly.setDarkScale();
}, 1500);
} }
/** /**

View File

@ -225,7 +225,6 @@
</xml> </xml>
</h3> </h3>
<div style="position: relative;height: 100%"> <div style="position: relative;height: 100%">
<div id="blocklyDarkScale" style="display: none;"></div>
<div id="blocklyArea"> <div id="blocklyArea">
<div id="blocklyDiv"></div> <div id="blocklyDiv"></div>
</div> </div>

View File

@ -221,7 +221,6 @@
</xml> </xml>
</h3> </h3>
<div style="position: relative;height: 100%"> <div style="position: relative;height: 100%">
<div id="blocklyDarkScale" style="display: none;"></div>
<div id="blocklyArea"> <div id="blocklyArea">
<div id="blocklyDiv"></div> <div id="blocklyDiv"></div>
</div> </div>

View File

@ -93,19 +93,20 @@ main.floors.sample3=
"\t[杰克,thief]没错,我就是这一切的背后主谋。", "\t[杰克,thief]没错,我就是这一切的背后主谋。",
{ {
"type": "move", "type": "move",
"time": 1000,
"steps": [ "steps": [
{ "up",
"direction": "up", "up",
"value": 3 "up"
} ]
],
"time": 1000
}, },
{ {
"type": "show", "type": "show",
"loc": [ "loc": [
[
6, 6,
4 4
]
], ],
"time": 1000 "time": 1000
}, },