Fix hiding the 'say' bubble WRT number formatting

When checking whether to hide the speech bubble, test if this block is the block that originally displayed the bubble rather than testing to see if the text matches. This avoids problems due to differences in text formatting or changes in a reporter's value.
This commit is contained in:
Chris Willis-Ford 2014-06-09 16:44:17 -07:00
parent 126e7cdf16
commit 549a9d25a7
6 changed files with 16 additions and 13 deletions

View file

@ -818,10 +818,10 @@ public class Scratch extends Sprite {
public function handleTool(tool:String, evt:MouseEvent):void { }
public function showBubble(text:String, x:* = null, y:* = null, width:Number = 0):void {
public function showBubble(text:String, source:Object, x:* = null, y:* = null, width:Number = 0):void {
if (x == null) x = stage.mouseX;
if (y == null) y = stage.mouseY;
gh.showBubble(text, Number(x), Number(y), width);
gh.showBubble(text, source, Number(x), Number(y), width);
}
// -----------------------------

View file

@ -120,7 +120,7 @@ public class Interpreter {
var oldThread:Thread = activeThread;
activeThread = new Thread(b, targetObj);
var p:Point = b.localToGlobal(new Point(0, 0));
app.showBubble(String(evalCmd(b)), p.x, p.y, b.getRect(app.stage).width);
app.showBubble(String(evalCmd(b)), b, p.x, p.y, b.getRect(app.stage).width);
activeThread = oldThread;
return;
}

View file

@ -157,13 +157,12 @@ public class LooksPrims {
if (interp.activeThread.firstTime) {
text = interp.arg(b, 0);
secs = interp.numarg(b, 1);
s.showBubble(text, type);
s.showBubble(text, type, b);
if (s.visible) interp.redraw();
interp.startTimer(secs);
} else {
if (interp.checkTimer()) {
text = interp.arg(b, 0);
if (s.bubble && (s.bubble.getText() == text)) s.hideBubble();
if (interp.checkTimer() && s.bubble && (s.bubble.getSource() == b)) {
s.hideBubble();
}
}
}
@ -178,7 +177,7 @@ public class LooksPrims {
} else { // talk or think command
text = interp.arg(b, 0);
}
s.showBubble(text, type);
s.showBubble(text, type, b);
if (s.visible) interp.redraw();
}

View file

@ -557,7 +557,7 @@ public class ScratchSprite extends ScratchObj {
/* talk/think bubble support */
public function showBubble(s:*, type:String, isAsk:Boolean = false):void {
public function showBubble(s:*, type:String, source:Object, isAsk:Boolean = false):void {
hideBubble();
if (s == null) s = 'NULL';
if (s is Number) {
@ -569,7 +569,7 @@ public class ScratchSprite extends ScratchObj {
}
if (!(s is String)) s = s.toString();
if (s.length == 0) return;
bubble = new TalkBubble(s, type, isAsk ? 'ask' : 'say');
bubble = new TalkBubble(s, type, isAsk ? 'ask' : 'say', source);
parent.addChild(bubble);
updateBubble();
}

View file

@ -29,6 +29,7 @@ public class TalkBubble extends Sprite {
private var style:String; // 'say' or 'ask' or 'result'
private var shape:Shape;
private var text:TextField;
private var source:Object;
private static var textFormat:TextFormat = new TextFormat(CSS.font, 14, 0, true, null, null, null, null, TextFormatAlign.CENTER);
private static var resultFormat:TextFormat = new TextFormat(CSS.font, 12, CSS.textColor, null, null, null, null, null, TextFormatAlign.CENTER);
private var outlineColor:int = 0xA0A0A0;
@ -42,9 +43,10 @@ public class TalkBubble extends Sprite {
private var pDropX:int = 8;
private var lineWidth:Number = 3;
public function TalkBubble(s:String, type:String, style:String) {
public function TalkBubble(s:String, type:String, style:String, source:Object) {
this.type = type;
this.style = style;
this.source = source;
if (style == 'ask') {
outlineColor = 0x4AADDE;
} else if (style == 'result') {
@ -77,6 +79,8 @@ public class TalkBubble extends Sprite {
public function getText():String { return text.text }
public function getSource():Object { return source; }
private function setText(s:String):void {
var desiredWidth:int = 135;
text.width = desiredWidth + 100; // wider than desiredWidth

View file

@ -504,9 +504,9 @@ public class GestureHandler {
o.filters = newFilters;
}
public function showBubble(text:String, x:Number, y:Number, width:Number = 0):void {
public function showBubble(text:String, source:Object, x:Number, y:Number, width:Number = 0):void {
hideBubble();
bubble = new TalkBubble(text || ' ', 'say', 'result');
bubble = new TalkBubble(text || ' ', 'say', 'result', source);
bubbleStartX = stage.mouseX;
bubbleStartY = stage.mouseY;
var bx:Number = x + width;