mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-07-29 07:29:12 -04:00
Merge pull request #1070 from paulkaplan/fix-bubbles
Fix drag and empty costume bugs with say bubbles
This commit is contained in:
commit
0f16e2fe65
2 changed files with 36 additions and 5 deletions
src
|
@ -20,7 +20,7 @@ class Scratch3LooksBlocks {
|
||||||
*/
|
*/
|
||||||
this.runtime = runtime;
|
this.runtime = runtime;
|
||||||
|
|
||||||
this._onTargetMoved = this._onTargetMoved.bind(this);
|
this._onTargetChanged = this._onTargetChanged.bind(this);
|
||||||
this._onResetBubbles = this._onResetBubbles.bind(this);
|
this._onResetBubbles = this._onResetBubbles.bind(this);
|
||||||
this._onTargetWillExit = this._onTargetWillExit.bind(this);
|
this._onTargetWillExit = this._onTargetWillExit.bind(this);
|
||||||
this._updateBubble = this._updateBubble.bind(this);
|
this._updateBubble = this._updateBubble.bind(this);
|
||||||
|
@ -75,7 +75,7 @@ class Scratch3LooksBlocks {
|
||||||
* @param {RenderedTarget} target - the target which has moved.
|
* @param {RenderedTarget} target - the target which has moved.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_onTargetMoved (target) {
|
_onTargetChanged (target) {
|
||||||
const bubbleState = this._getBubbleState(target);
|
const bubbleState = this._getBubbleState(target);
|
||||||
if (bubbleState.drawableId) {
|
if (bubbleState.drawableId) {
|
||||||
this._positionBubble(target);
|
this._positionBubble(target);
|
||||||
|
@ -97,7 +97,7 @@ class Scratch3LooksBlocks {
|
||||||
bubbleState.drawableVisible = true; // Reset back to default value
|
bubbleState.drawableVisible = true; // Reset back to default value
|
||||||
this.runtime.requestRedraw();
|
this.runtime.requestRedraw();
|
||||||
}
|
}
|
||||||
target.removeListener(RenderedTarget.EVENT_TARGET_MOVED, this._onTargetMoved);
|
target.removeListener(RenderedTarget.EVENT_TARGET_VISUAL_CHANGE, this._onTargetChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -117,9 +117,22 @@ class Scratch3LooksBlocks {
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_positionBubble (target) {
|
_positionBubble (target) {
|
||||||
|
if (!target.visible) return;
|
||||||
const bubbleState = this._getBubbleState(target);
|
const bubbleState = this._getBubbleState(target);
|
||||||
const [bubbleWidth, bubbleHeight] = this.runtime.renderer.getCurrentSkinSize(bubbleState.drawableId);
|
const [bubbleWidth, bubbleHeight] = this.runtime.renderer.getCurrentSkinSize(bubbleState.drawableId);
|
||||||
const targetBounds = target.getBoundsForBubble();
|
let targetBounds;
|
||||||
|
try {
|
||||||
|
targetBounds = target.getBoundsForBubble();
|
||||||
|
} catch (error_) {
|
||||||
|
// Bounds calculation could fail (e.g. on empty costumes), in that case
|
||||||
|
// use the x/y position of the target.
|
||||||
|
targetBounds = {
|
||||||
|
left: target.x,
|
||||||
|
right: target.x,
|
||||||
|
top: target.y,
|
||||||
|
bottom: target.y
|
||||||
|
};
|
||||||
|
}
|
||||||
const stageBounds = this.runtime.getTargetForStage().getBounds();
|
const stageBounds = this.runtime.getTargetForStage().getBounds();
|
||||||
if (bubbleState.onSpriteRight && bubbleWidth + targetBounds.right > stageBounds.right &&
|
if (bubbleState.onSpriteRight && bubbleWidth + targetBounds.right > stageBounds.right &&
|
||||||
(targetBounds.left - bubbleWidth > stageBounds.left)) { // Only flip if it would fit
|
(targetBounds.left - bubbleWidth > stageBounds.left)) { // Only flip if it would fit
|
||||||
|
@ -178,7 +191,7 @@ class Scratch3LooksBlocks {
|
||||||
this.runtime.renderer.updateTextSkin(bubbleState.skinId, type, text, onSpriteRight, [0, 0]);
|
this.runtime.renderer.updateTextSkin(bubbleState.skinId, type, text, onSpriteRight, [0, 0]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
target.addListener(RenderedTarget.EVENT_TARGET_MOVED, this._onTargetMoved);
|
target.addListener(RenderedTarget.EVENT_TARGET_VISUAL_CHANGE, this._onTargetChanged);
|
||||||
|
|
||||||
// TODO is there a way to figure out before rendering whether to default left or right?
|
// TODO is there a way to figure out before rendering whether to default left or right?
|
||||||
const targetBounds = target.getBounds();
|
const targetBounds = target.getBounds();
|
||||||
|
|
|
@ -193,6 +193,14 @@ class RenderedTarget extends Target {
|
||||||
return 'TARGET_MOVED';
|
return 'TARGET_MOVED';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event which fires when a target changes visually, for updating say bubbles.
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
static get EVENT_TARGET_VISUAL_CHANGE () {
|
||||||
|
return 'EVENT_TARGET_VISUAL_CHANGE';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rotation style for "all around"/spinning.
|
* Rotation style for "all around"/spinning.
|
||||||
* @type {string}
|
* @type {string}
|
||||||
|
@ -249,6 +257,7 @@ class RenderedTarget extends Target {
|
||||||
position: position
|
position: position
|
||||||
});
|
});
|
||||||
if (this.visible) {
|
if (this.visible) {
|
||||||
|
this.emit(RenderedTarget.EVENT_TARGET_VISUAL_CHANGE, this);
|
||||||
this.runtime.requestRedraw();
|
this.runtime.requestRedraw();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -299,6 +308,7 @@ class RenderedTarget extends Target {
|
||||||
scale: renderedDirectionScale.scale
|
scale: renderedDirectionScale.scale
|
||||||
});
|
});
|
||||||
if (this.visible) {
|
if (this.visible) {
|
||||||
|
this.emit(RenderedTarget.EVENT_TARGET_VISUAL_CHANGE, this);
|
||||||
this.runtime.requestRedraw();
|
this.runtime.requestRedraw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -346,6 +356,7 @@ class RenderedTarget extends Target {
|
||||||
visible: this.visible
|
visible: this.visible
|
||||||
});
|
});
|
||||||
if (this.visible) {
|
if (this.visible) {
|
||||||
|
this.emit(RenderedTarget.EVENT_TARGET_VISUAL_CHANGE, this);
|
||||||
this.runtime.requestRedraw();
|
this.runtime.requestRedraw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -378,6 +389,7 @@ class RenderedTarget extends Target {
|
||||||
scale: renderedDirectionScale.scale
|
scale: renderedDirectionScale.scale
|
||||||
});
|
});
|
||||||
if (this.visible) {
|
if (this.visible) {
|
||||||
|
this.emit(RenderedTarget.EVENT_TARGET_VISUAL_CHANGE, this);
|
||||||
this.runtime.requestRedraw();
|
this.runtime.requestRedraw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -397,6 +409,7 @@ class RenderedTarget extends Target {
|
||||||
props[effectName] = this.effects[effectName];
|
props[effectName] = this.effects[effectName];
|
||||||
this.renderer.updateDrawableProperties(this.drawableID, props);
|
this.renderer.updateDrawableProperties(this.drawableID, props);
|
||||||
if (this.visible) {
|
if (this.visible) {
|
||||||
|
this.emit(RenderedTarget.EVENT_TARGET_VISUAL_CHANGE, this);
|
||||||
this.runtime.requestRedraw();
|
this.runtime.requestRedraw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -413,6 +426,7 @@ class RenderedTarget extends Target {
|
||||||
if (this.renderer) {
|
if (this.renderer) {
|
||||||
this.renderer.updateDrawableProperties(this.drawableID, this.effects);
|
this.renderer.updateDrawableProperties(this.drawableID, this.effects);
|
||||||
if (this.visible) {
|
if (this.visible) {
|
||||||
|
this.emit(RenderedTarget.EVENT_TARGET_VISUAL_CHANGE, this);
|
||||||
this.runtime.requestRedraw();
|
this.runtime.requestRedraw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -446,6 +460,7 @@ class RenderedTarget extends Target {
|
||||||
}
|
}
|
||||||
this.renderer.updateDrawableProperties(this.drawableID, drawableProperties);
|
this.renderer.updateDrawableProperties(this.drawableID, drawableProperties);
|
||||||
if (this.visible) {
|
if (this.visible) {
|
||||||
|
this.emit(RenderedTarget.EVENT_TARGET_VISUAL_CHANGE, this);
|
||||||
this.runtime.requestRedraw();
|
this.runtime.requestRedraw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -573,6 +588,7 @@ class RenderedTarget extends Target {
|
||||||
scale: renderedDirectionScale.scale
|
scale: renderedDirectionScale.scale
|
||||||
});
|
});
|
||||||
if (this.visible) {
|
if (this.visible) {
|
||||||
|
this.emit(RenderedTarget.EVENT_TARGET_VISUAL_CHANGE, this);
|
||||||
this.runtime.requestRedraw();
|
this.runtime.requestRedraw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -645,6 +661,7 @@ class RenderedTarget extends Target {
|
||||||
}
|
}
|
||||||
this.renderer.updateDrawableProperties(this.drawableID, props);
|
this.renderer.updateDrawableProperties(this.drawableID, props);
|
||||||
if (this.visible) {
|
if (this.visible) {
|
||||||
|
this.emit(RenderedTarget.EVENT_TARGET_VISUAL_CHANGE, this);
|
||||||
this.runtime.requestRedraw();
|
this.runtime.requestRedraw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1034,6 +1051,7 @@ class RenderedTarget extends Target {
|
||||||
if (this.renderer && this.drawableID !== null) {
|
if (this.renderer && this.drawableID !== null) {
|
||||||
this.renderer.destroyDrawable(this.drawableID);
|
this.renderer.destroyDrawable(this.drawableID);
|
||||||
if (this.visible) {
|
if (this.visible) {
|
||||||
|
this.emit(RenderedTarget.EVENT_TARGET_VISUAL_CHANGE, this);
|
||||||
this.runtime.requestRedraw();
|
this.runtime.requestRedraw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue