此角色积木块拖动到其他角色上以共享积木块

自己大改了,与源码交互逻辑不同,不具备参考作用!
0.先设置一个字段,用于判断是否悬浮在非源角色上

componentWillReceiveProps (nextProps) {
        const {
            hoveredTarget,
            editingTarget,
            sprites,
            stage
        } = nextProps;

        // @zpt20190214角色间共享代码

        Blocks.isSpriteArea = (hoveredTarget.sprite &&
            hoveredTarget.sprite !== editingTarget);

1.scratch-vm/src/engine/blocks中:
**角色间共享代码,屏蔽掉isOutside区域,是因为只有在isOutside区域内,才会触发共享的积木块,因为我自己左右调换了,所以把此条件屏蔽,以实现在删除区也可以实现共享积木块。
20190318更新,后发现不用屏蔽此处也能正常获取共享积木块 **

case 'endDrag':
            // console.log(optRuntime.zptIsDragOverOnReceivedSprite)
            if (optRuntime) {
                optRuntime.emitBlockDragUpdate(false /* areBlocksOverGui */);

                // Drag blocks onto another sprite
                // if (e.isOutside) {
                //     const newBlocks = adapter(e);
                //     optRuntime.emitBlockEndDrag(newBlocks);
                // }
                // 角色间共享代码,屏蔽掉isOutside区域,是因为只有在isOutside区域内,才会触发共享的积木块,因为我自己左右调换了,所以把此条件屏蔽,以实现在删除区也可以实现共享积木块。
               **20190318更新,后发现不用屏蔽此处也能正常获取共享积木块**
                // if (e.isOutside) {
                    const newBlocks = adapter(e);
                    optRuntime.emitBlockEndDrag(newBlocks);
                // }
            }
            break;

2.scratch-blocks/blockly_compressed_vertical.js
在blockly_compressed_vertical.js文件中添加关键字Blockly.isSpriteArea,表示是否悬浮在非源角色的其他角色上面。
源码表示只有在isOutside区域内才会提取需要共享的积木块,由于我的修改,所以添加一个判断条件,如果悬浮在其他角色上面也会触发提取积木块事件。

Blockly.Events.EndBlockDrag = function(a, b) {
    if (a) {
        Blockly.Events.EndBlockDrag.superClass_.constructor.call(this, a);
        // if (this.isOutside = b) this.xml = Blockly.Xml.blockToDom(a, !0);
        // @zpt20190214角色间共享代码
        if (this.isOutside = b||Blockly.isSpriteArea) this.xml = Blockly.Xml.blockToDom(a, !0)
        this.recordUndo = !1
    }
};

3.scratch-blocks/blockly_compressed_vertical.js
添加条件如果悬浮在其他角色上,不删除积木块

(!Blockly.isSpriteArea)&&this.maybeDeleteBlock_() || ( this.draggingBlock_.moveConnections_(c.x, c.y),
    this.draggingBlock_.setDragging(!1),
    this.draggedConnectionManager_.applyConnections(),
    this.draggingBlock_.render(),
    this.fireMoveEvent_(),
    this.draggingBlock_.scheduleSnapAndBump());

4.src/xx-containers/xx-target-pane,jsx
这里原来有一个bug,就是复制后未删除的积木块弹回来的位置很乱,有时会到不可见区域,所以添加两个方法。
对workspace上的所有积木块进行整理排序;

this.ScratchBlocks.getMainWorkspace().cleanUp();

所有计算所有积木块的边界,然后居中,如果不排序的画会出现一左一右离得很远,强制居中后,啥都看不见。

 this.ScratchBlocks.getMainWorkspace().scrollCenter();

至此解决bug

  handleBlockDragEnd (blocks) {

        if (this.props.hoveredTarget.sprite && this.props.hoveredTarget.sprite !== this.props.editingTarget) {
            this.props.vm.shareBlocksToTarget(blocks, this.props.hoveredTarget.sprite, this.props.editingTarget);
            this.props.onReceivedBlocks(true);
            // console.log(this.ScratchBlocks);
          
            // 对积木块进行排序
            this.ScratchBlocks.getMainWorkspace().cleanUp();
            this.ScratchBlocks.getMainWorkspace().scrollCenter();
        }
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值