Merge pull request #251 from LLK/bubble_hide_fix

Fix hiding the 'say' bubble WRT number formatting
This commit is contained in:
Shane M. Clements 2014-06-18 12:27:25 +02:00
commit 9b83662450
4 changed files with 12 additions and 9 deletions

View file

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

View file

@ -557,7 +557,7 @@ public class ScratchSprite extends ScratchObj {
/* talk/think bubble support */ /* 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(); hideBubble();
if (s == null) s = 'NULL'; if (s == null) s = 'NULL';
if (s is Number) { if (s is Number) {
@ -569,7 +569,7 @@ public class ScratchSprite extends ScratchObj {
} }
if (!(s is String)) s = s.toString(); if (!(s is String)) s = s.toString();
if (s.length == 0) return; 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); parent.addChild(bubble);
updateBubble(); updateBubble();
} }

View file

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

View file

@ -506,7 +506,7 @@ public class GestureHandler {
public function showBubble(text:String, x:Number, y:Number, width:Number = 0):void { public function showBubble(text:String, x:Number, y:Number, width:Number = 0):void {
hideBubble(); hideBubble();
bubble = new TalkBubble(text || ' ', 'say', 'result'); bubble = new TalkBubble(text || ' ', 'say', 'result', this);
bubbleStartX = stage.mouseX; bubbleStartX = stage.mouseX;
bubbleStartY = stage.mouseY; bubbleStartY = stage.mouseY;
var bx:Number = x + width; var bx:Number = x + width;