From 549a9d25a731d07d3d62b233571c43bcc2103c61 Mon Sep 17 00:00:00 2001 From: Chris Willis-Ford Date: Mon, 9 Jun 2014 16:44:17 -0700 Subject: [PATCH 1/2] 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. --- src/Scratch.as | 4 ++-- src/interpreter/Interpreter.as | 2 +- src/primitives/LooksPrims.as | 9 ++++----- src/scratch/ScratchSprite.as | 4 ++-- src/scratch/TalkBubble.as | 6 +++++- src/util/GestureHandler.as | 4 ++-- 6 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/Scratch.as b/src/Scratch.as index 6f570e5..5da8eed 100644 --- a/src/Scratch.as +++ b/src/Scratch.as @@ -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); } // ----------------------------- diff --git a/src/interpreter/Interpreter.as b/src/interpreter/Interpreter.as index b98d406..22c2ac2 100644 --- a/src/interpreter/Interpreter.as +++ b/src/interpreter/Interpreter.as @@ -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; } diff --git a/src/primitives/LooksPrims.as b/src/primitives/LooksPrims.as index de25edd..5d79701 100644 --- a/src/primitives/LooksPrims.as +++ b/src/primitives/LooksPrims.as @@ -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(); } diff --git a/src/scratch/ScratchSprite.as b/src/scratch/ScratchSprite.as index 5135d33..edf7627 100644 --- a/src/scratch/ScratchSprite.as +++ b/src/scratch/ScratchSprite.as @@ -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(); } diff --git a/src/scratch/TalkBubble.as b/src/scratch/TalkBubble.as index bfe77c4..0227f0f 100644 --- a/src/scratch/TalkBubble.as +++ b/src/scratch/TalkBubble.as @@ -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 diff --git a/src/util/GestureHandler.as b/src/util/GestureHandler.as index 63b606a..6be1b61 100644 --- a/src/util/GestureHandler.as +++ b/src/util/GestureHandler.as @@ -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; From 904d56ae5555e08c75aac1a0bc5b786aeb43c187 Mon Sep 17 00:00:00 2001 From: Chris Willis-Ford Date: Tue, 10 Jun 2014 14:37:43 -0700 Subject: [PATCH 2/2] Use GestureHandler as source for bubbles it creates Shane explained that it would make more sense to use the GestureHandler as the source for these particular TalkBubble instances. --- src/Scratch.as | 4 ++-- src/interpreter/Interpreter.as | 2 +- src/util/GestureHandler.as | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Scratch.as b/src/Scratch.as index 5da8eed..6f570e5 100644 --- a/src/Scratch.as +++ b/src/Scratch.as @@ -818,10 +818,10 @@ public class Scratch extends Sprite { public function handleTool(tool:String, evt:MouseEvent):void { } - public function showBubble(text:String, source:Object, x:* = null, y:* = null, width:Number = 0):void { + public function showBubble(text:String, x:* = null, y:* = null, width:Number = 0):void { if (x == null) x = stage.mouseX; if (y == null) y = stage.mouseY; - gh.showBubble(text, source, Number(x), Number(y), width); + gh.showBubble(text, Number(x), Number(y), width); } // ----------------------------- diff --git a/src/interpreter/Interpreter.as b/src/interpreter/Interpreter.as index 22c2ac2..b98d406 100644 --- a/src/interpreter/Interpreter.as +++ b/src/interpreter/Interpreter.as @@ -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)), b, p.x, p.y, b.getRect(app.stage).width); + app.showBubble(String(evalCmd(b)), p.x, p.y, b.getRect(app.stage).width); activeThread = oldThread; return; } diff --git a/src/util/GestureHandler.as b/src/util/GestureHandler.as index 6be1b61..2c08f5e 100644 --- a/src/util/GestureHandler.as +++ b/src/util/GestureHandler.as @@ -504,9 +504,9 @@ public class GestureHandler { o.filters = newFilters; } - public function showBubble(text:String, source:Object, x:Number, y:Number, width:Number = 0):void { + public function showBubble(text:String, x:Number, y:Number, width:Number = 0):void { hideBubble(); - bubble = new TalkBubble(text || ' ', 'say', 'result', source); + bubble = new TalkBubble(text || ' ', 'say', 'result', this); bubbleStartX = stage.mouseX; bubbleStartY = stage.mouseY; var bx:Number = x + width;