There's something wrong with the shadow block.

98 views
Skip to first unread message

fu6...@gmail.com

unread,
Sep 11, 2021, 11:56:03 PM9/11/21
to Blockly
Hi,
When I drag the block to the workspace, the shadow block is not in the right place.
Thank you.



Blockly.Procedures.flyoutCategory=function(a){
function addCallBlock(f,g){

for(var h=0;h<f.length;h++){

var k=f[h][0];
var n = a.getAllBlocks(!1);
var p = "";
var q = "";
for(var d=0;d<n.length;d++) {
if ((n[d].type=="lists_create_with")&&n[d].parentBlock_) {
if (n[d].isShadow_)
var mutation = '<shadow type="lists_create_with"><mutation items="0"></mutation></shadow>';
else
var mutation = '<block type="lists_create_with"><mutation items="'+n[d].itemCount_+'"></mutation></block>';
if (g=="procedures_callnoreturn"&&n[d].parentBlock_.type=="procedures_defnoreturn") {
if (n[d].parentBlock_.inputList[0].fieldRow[1].value_==k)
p = mutation;
}
if (g=="procedures_callreturn"&&n[d].parentBlock_.type=="procedures_defreturn") {
if (n[d].parentBlock_.inputList[1].fieldRow[0].value_==k)
q = mutation;
}
}
}
if (g=="procedures_callnoreturn") {
c.push(Blockly.Xml.textToDom('<block type="procedures_callnoreturn" gap="16"><mutation name="'+k+'"></mutation><value name="VAR">'+p+'</value></block>'))
}
else if (g=="procedures_callreturn") {
c.push(Blockly.Xml.textToDom('<block type="procedures_callreturn" gap="16"><mutation name="'+k+'"></mutation><value name="VAR">'+q+'</value></block>'))
}
}
}
var c=[];
var v=a.getVariablesOfType("");
v.sort(Blockly.VariableModel.compareByName);
if(v.length>0) 
v=v[0].name;
else
v="";
Blockly.Blocks.procedures_defnoreturn&&c.push(Blockly.Xml.textToDom('<block type="procedures_defnoreturn" gap="16"><field name="NAME">func</field><value name="VAR"><shadow type="lists_create_with"><mutation items="0"></mutation></shadow></value></block>'))
Blockly.Blocks.procedures_defreturn&&c.push(Blockly.Xml.textToDom('<block type="procedures_defreturn" gap="16"><field name="TYPE">void</field><field name="NAME">func</field><value name="VAR"><shadow type="lists_create_with"><mutation items="0"></mutation></shadow></value></block>'))
Blockly.Blocks.procedures_return&&c.push(Blockly.Xml.textToDom('<block type="procedures_return" gap="16"></block>'))
Blockly.Blocks.lists_create_with&&c.push(Blockly.Xml.textToDom('<block type="lists_create_with"><mutation items="1"></mutation><value name="ADD0"><block type="variables_set2" gap="16"><field name="TYPE">int</field><field name="VAR">'+v+'</field></block></value></block>'))
Blockly.Blocks.variables_set2&&c.push(Blockly.Xml.textToDom('<block type="variables_set2" gap="16"><field name="TYPE">int</field><field name="VAR">'+v+'</field></block>'))
var t=Blockly.Procedures.allProcedures(a);
addCallBlock(t[0],"procedures_callnoreturn");
addCallBlock(t[1],"procedures_callreturn");

return c
};



Blockly.Blocks.lists_create_with={
init:function(){
this.setHelpUrl(Blockly.Msg.LISTS_CREATE_WITH_HELPURL);
this.setStyle("list_blocks");
this.itemCount_=3;
this.updateShape_();
this.setOutput(!0,"Array");
this.setMutator(new Blockly.Mutator(["lists_create_with_item"]));
this.setTooltip(Blockly.Msg.LISTS_CREATE_WITH_TOOLTIP)
}
,mutationToDom:function(){
var a=Blockly.utils.xml.createElement("mutation");
a.setAttribute("items",this.itemCount_);
return a
}
,domToMutation:function(a){
this.itemCount_=parseInt(a.getAttribute("items"),10);
this.updateShape_()
}
,decompose:function(a){
var b=a.newBlock("lists_create_with_container");
b.initSvg();
for(var c=b.getInput("STACK").connection,d=0;d<this.itemCount_;d++){
var e=a.newBlock("lists_create_with_item");
e.initSvg();
c.connect(e.previousConnection);
c=e.nextConnection}
return b
}
,compose:function(a){
var b=a.getInputTargetBlock("STACK");
for(a=[];b&&!b.isInsertionMarker();)
a.push(b.valueConnection_),b=b.nextConnection&&b.nextConnection.targetBlock();
for(b=0;b<this.itemCount_;b++){
var c=this.getInput("ADD"+b).connection.targetConnection;
c&&-1==a.indexOf(c)&&c.disconnect()
}
this.itemCount_=a.length;
this.updateShape_();
for(b=0;b<this.itemCount_;b++)
Blockly.Mutator.reconnect(a[b],this,"ADD"+b)
}
,saveConnections:function(a){
a=a.getInputTargetBlock("STACK");
for(var b=0;a;){
var c=this.getInput("ADD"+b);
a.valueConnection_=c&&c.connection.targetConnection;
b++;
a=a.nextConnection&&a.nextConnection.targetBlock()
}
}
,updateShape_:function(){
this.itemCount_&&this.getInput("EMPTY")?this.removeInput("EMPTY"):this.itemCount_||this.getInput("EMPTY")||this.appendDummyInput("EMPTY").appendField(Blockly.Msg.LISTS_CREATE_EMPTY_TITLE,"TITLE");
for(var a=0;a<this.itemCount_;a++)
if(!this.getInput("ADD"+a)){
var b=this.appendValueInput("ADD"+a).setAlign(Blockly.ALIGN_RIGHT);
0==a&&b.appendField(Blockly.Msg.LISTS_CREATE_WITH_INPUT_WITH,"TITLE")
}
for(;this.getInput("ADD"+a);)
this.removeInput("ADD"+a),a++
}
,onchange: function(event) {
if (!this.workspace) {
  // Block is deleted.
  return;
}
if (!event.recordUndo) {
  // Events not generated by user. Skip handling.
  return;
}
if (this.mutator.block_.parentBlock_) {
if (this.mutator.block_.parentBlock_.type=="procedures_callnoreturn") {
this.getField("TITLE").setValue(Blockly.Msg["LISTS_CREATE_WITH_INPUT_WITH_PROCEDURE_VALUE"]);
this.getField("TITLE").isDirty_=true;
return;
}
else if (this.mutator.block_.parentBlock_.type=="procedures_callreturn") {
this.getField("TITLE").setValue(Blockly.Msg["LISTS_CREATE_WITH_INPUT_WITH_PROCEDURE_VALUE"]);
this.getField("TITLE").isDirty_=true;
return;
}
else if (this.mutator.block_.parentBlock_.type=="procedures_defnoreturn"||this.mutator.block_.parentBlock_.type=="procedures_defreturn") {
if (this.itemCount_) {
for (var i=0;i<this.itemCount_;i++) {
var targetBlock = this.getInputTargetBlock('ADD'+i);
if (targetBlock) { 
if (targetBlock.type!="variables_set2") {
targetBlock.unplug();
}
}
}
}
this.getField("TITLE").setValue(Blockly.Msg.LISTS_CREATE_WITH_INPUT_WITH_PROCEDURE);
this.getField("TITLE").isDirty_=true;
//this.setInputsInline(!0);
return;
}
}
if (this.itemCount_) {
for (var i=0;i<this.itemCount_;i++) {
var targetBlock = this.getInputTargetBlock('ADD'+i);
if (targetBlock) { 
if (targetBlock.type=="variables_set2") {
this.getField("TITLE").setValue(Blockly.Msg.LISTS_CREATE_WITH_INPUT_WITH_PROCEDURE);
this.getField("TITLE").isDirty_=true;
return;
}
}
}
this.getField("TITLE").setValue(Blockly.Msg.LISTS_CREATE_WITH_INPUT_WITH);
}
else
this.getField("TITLE").setValue(Blockly.Msg.LISTS_CREATE_EMPTY_TITLE);
this.getField("TITLE").isDirty_=true;
this.setInputsInline(0);
};
2.PNG
1.mp4

fu6...@gmail.com

unread,
Sep 12, 2021, 2:10:07 AM9/12/21
to Blockly
I found the solution to the problem.

this.getField("TITLE").isDirty_=true;
this.workspace.render();    //add the line of code
return;

But the shadow block can't allow to connect to the output block. How to solve it? Thank you.

1.mp4

fu6...@gmail.com

unread,
Sep 12, 2021, 3:16:43 AM9/12/21
to Blockly
I found the solution to the problem.
else if (this.mutator.block_.parentBlock_.type=="procedures_defnoreturn"||this.mutator.block_.parentBlock_.type=="procedures_defreturn") {
    if (this.inputList[0].name!="EMPTY")
        this.setShadow(false);
    else
        this.setShadow(true);

    //etc...
end if

fu6...@gmail.com 在 2021年9月12日 星期日下午2:10:07 [UTC+8] 的信中寫道:
1.mp4
Reply all
Reply to author
Forward
0 new messages