Skip to content

Commit

Permalink
Merge branch 'master' into broadcast-vars
Browse files Browse the repository at this point in the history
  • Loading branch information
towerofnix committed Feb 18, 2017
2 parents d251d23 + b369b71 commit ed374ca
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/Scratch.as
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,8 @@ public class Scratch extends Sprite {
public function exportProjectToFile(fromJS:Boolean = false, saveCallback:Function = null):void {
function squeakSoundsConverted():void {
scriptsPane.saveScripts(false);
scriptsPane.restoreScriptPosition();
scriptsPane.viewScriptsFor(viewedObj());
var projectType:String = extensionManager.hasExperimentalExtensions() ? '.sbx' : '.sb2';
var defaultName:String = StringUtil.trim(projectName());
defaultName = ((defaultName.length > 0) ? defaultName : 'project') + projectType;
Expand Down
8 changes: 5 additions & 3 deletions src/blocks/Block.as
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,11 @@ public class Block extends Sprite {

labelsAndArgs = [];
argTypes = [];
var label:TextField = makeLabel(Translator.map('define'));

var b:Block = declarationBlock();
var label:TextField = makeLabel(Translator.map((warpProcFlag || b.warpProcFlag) ? 'define (no refresh)' : 'define'));
labelsAndArgs.push(label);
var b:Block;
labelsAndArgs.push(b = declarationBlock());
labelsAndArgs.push(b);
} else if (op == Specs.GET_VAR || op == Specs.GET_LIST) {
labelsAndArgs = [makeLabel(spec)];
} else {
Expand Down Expand Up @@ -600,6 +601,7 @@ public class Block extends Sprite {
dup.parameterNames = parameterNames;
dup.defaultArgValues = defaultArgValues;
dup.warpProcFlag = warpProcFlag;
dup.setSpec(newSpec);
if (forClone) {
dup.copyArgsForClone(args);
} else {
Expand Down
17 changes: 15 additions & 2 deletions src/blocks/BlockArg.as
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class BlockArg extends Sprite {
public var menuName:String;

private var menuIcon:Shape;
private var colorIcon:Shape;

// BlockArg types:
// b - boolean (pointed)
Expand All @@ -69,7 +70,7 @@ public class BlockArg extends Sprite {
// n - number (rounded)
// s - string (rectangular)
// none of the above - custom subclass of BlockArg
public function BlockArg(type:String, color:int, editable:Boolean = false, menuName:String = '') {
public function BlockArg(type:String, color:int, editable:Boolean = false, menuName:String = '', shouldHaveColorIcon:Boolean = false) {
this.type = type;

if (color == -1) { // copy for clone; omit graphics
Expand Down Expand Up @@ -127,6 +128,17 @@ public class BlockArg extends Sprite {
addChild(menuIcon);
}

if (shouldHaveColorIcon) { // add a color icon
colorIcon = new Shape();
var g:Graphics = colorIcon.graphics;
g.beginFill(0x632D99, 1);
g.drawRoundRect(0, 0, 5, 5, 5);
g.endFill();
colorIcon.x = 5;
colorIcon.y = 5;
addChild(colorIcon);
}

if (editable || numberType || (type == 'm')) { // add a string field
field = makeTextField();
if ((type == 'm') && !editable) field.textColor = 0xFFFFFF;
Expand Down Expand Up @@ -227,9 +239,10 @@ public class BlockArg extends Sprite {
// fix layout:
var padding:int = (type == 'n') ? 3 : 0;
if (type == 'b') padding = 8;
if (menuIcon != null) padding = (type == 'd') ? 10 : 13;
if (menuIcon != null || colorIcon != null) padding = (type == 'd') ? 10 : 13;
var w:int = Math.max(14, field.textWidth + 6 + padding);
if (menuIcon) menuIcon.x = w - menuIcon.width - 3;
if (colorIcon) colorIcon.x = w - colorIcon.width - 5;
base.setWidth(w);
base.redraw();
if (parent is Block) Block(parent).fixExpressionLayout();
Expand Down
16 changes: 16 additions & 0 deletions src/ui/ProcedureSpecEditor.as
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ package ui {
import uiwidgets.*;
import util.*;
import translation.Translator;
import util.Color;

public class ProcedureSpecEditor extends Sprite {

Expand Down Expand Up @@ -83,6 +84,7 @@ public class ProcedureSpecEditor extends Sprite {
'Add number input:',
'Add string input:',
'Add boolean input:',
'Add color input:',
'Add label text:',
'text',
];
Expand Down Expand Up @@ -117,6 +119,7 @@ public class ProcedureSpecEditor extends Sprite {
if (argSpec == 'b') arg = makeBooleanArg();
if (argSpec == 'n') arg = makeNumberArg();
if (argSpec == 's') arg = makeStringArg();
if (argSpec == 'c') arg = makeColorArg();
if (arg) {
arg.setArgValue(inputNames[i++]);
addElement(arg);
Expand Down Expand Up @@ -155,6 +158,7 @@ public class ProcedureSpecEditor extends Sprite {
if (arg.type == 'b') v = false;
if (arg.type == 'n') v = 1;
if (arg.type == 's') v = '';
if (arg.type == 'c') v = Color.random();
result.push(v);
}
}
Expand All @@ -179,12 +183,14 @@ public class ProcedureSpecEditor extends Sprite {
makeLabel('Add number input:', 14),
makeLabel('Add string input:', 14),
makeLabel('Add boolean input:', 14),
makeLabel('Add color input:', 14),
makeLabel('Add label text:', 14)
];
buttons = [
new Button('', function():void { appendObj(makeNumberArg()) }),
new Button('', function():void { appendObj(makeStringArg()) }),
new Button('', function():void { appendObj(makeBooleanArg()) }),
new Button('', function():void { appendObj(makeColorArg()) }),
new Button(Translator.map('text'), function():void { appendObj(makeTextField('')) })
];

Expand All @@ -202,6 +208,10 @@ public class ProcedureSpecEditor extends Sprite {
icon.setWidthAndTopHeight(25, 14, true);
buttons[2].setIcon(icon);

icon = new BlockShape(BlockShape.RectShape, lightGray);
icon.setWidthAndTopHeight(16, 16, true);
buttons[3].setIcon(icon);

for each (var label:TextField in buttonLabels) addChild(label);
for each (var b:Button in buttons) addChild(b);
}
Expand Down Expand Up @@ -280,6 +290,12 @@ public class ProcedureSpecEditor extends Sprite {
return result;
}

private function makeColorArg():BlockArg {
var result:BlockArg = new BlockArg('c', 0xFFFFFF, true, '', true);
result.setArgValue(unusedArgName('color'));
return result;
}

private function unusedArgName(prefix:String):String {
var usedNames:Array = [];
for each (var el:* in row) {
Expand Down
18 changes: 16 additions & 2 deletions src/uiwidgets/ScriptsPane.as
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ public class ScriptsPane extends ScrollFrameContents {
private const INSERT_SUB2:int = 3;
private const INSERT_WRAP:int = 4;

public var viewedScript:Block;
private var viewedScriptX:int;
private var viewedScriptY:int;

public var app:Scratch;
public var padding:int = 10;

public var viewedScript:Block;

private var viewedObj:ScratchObj;
private var commentLines:Shape;

Expand Down Expand Up @@ -88,6 +90,7 @@ public class ScriptsPane extends ScrollFrameContents {

public function viewScriptsFor(obj:ScratchObj):void {
// View the blocks for the given object.
restoreScriptPosition();
viewedScript = null;
saveScripts(false);
while (numChildren > 0) {
Expand All @@ -114,13 +117,17 @@ public class ScriptsPane extends ScrollFrameContents {
}

public function viewOneScript(block:Block):void {
restoreScriptPosition();

saveScripts(false);
while (numChildren > 0) {
var child:DisplayObject = removeChildAt(0);
child.cacheAsBitmap = false;
}

viewedScript = block;
viewedScriptX = block.x;
viewedScriptY = block.y;

// No comments for now

Expand Down Expand Up @@ -162,6 +169,13 @@ public class ScriptsPane extends ScrollFrameContents {
fixCommentLayout();
}

public function restoreScriptPosition():void {
if (viewedScript) {
viewedScript.x = viewedScriptX;
viewedScript.y = viewedScriptY;
}
}

public function prepareToDrag(b:Block):void {
findTargetsFor(b);
nearestTarget = null;
Expand Down

0 comments on commit ed374ca

Please sign in to comment.