Hey guys!
I'm here to teach you a few things about Squeak.
Creating new menus
So, in this tutorial, we will be making one called "Dev" (short for developer, meant to access developer mode)
First, either shift-click-r or shift-click-file (scratch or source) then click in the grey space at the bottom.
Then, click "open..." and then "browser".
Then, go to Scratch-UI-Panes>ScratchFrameMorph>menu/button actions
And then, you will create your very own developer menu by simply copying and pasting:(Must press alt+v in the Squeak editor to paste)
developerMenu: t1
| t2 |
t2 _ CustomMenu new.
t2 add: 'turn fill screen on' action: #fillScreenOn.
t2 add: 'turn fill screen off' action: #fillScreenOff.
t2 addLine.
t2 add: 'toggle error catching' action: #toggleErrorCatcher.
t2 addLine.
t2 add: 'save image for end user' action: #saveImageForEndUser.
t2 localize.
#(1 2 3 ) do: [:t3 | t2 labels at: t3 put: ((t2 labels at: t3)
copyFrom: 1 to: (t2 labels at: t3) size - 1)
, ScratchTranslator ellipsesSuffix].
t2 invokeOn: self at: t1 bottomLeft + (0 @ 10)Then go to Scratch-UI-Panes>ScratchFrameMorph>initialization>createMenuPanel.
It should look like:
createMenuPanel
| t1 t2 |
menuPanel _ AlignmentMorph new color: Color transparent;
centering: #center;
inset: 0;
height: 0.
self addShortcutButtonsTo: menuPanel.
t1 _ #((#File #fileMenu:) (#Edit #editMenu:) (#Help #helpMenu:) ).
t1 do:
[:t3 |
t2 _ ScratchMenuTitleMorph new contents: (t3 at: 1) localized;
target: self selector: (t3 at: 2).
menuPanel addMorphBack: t2.
#helpMenu: = (t3 at: 2) ifFalse: [menuPanel addMorphBack: (Morph new color: Color transparent;
extent: 12 @ 5)]].
topPane addMorph: menuPanelNow, in between "(#Edit #editMenu:)" and "(#Help #helpMenu:)" insert:
(#Dev #developerMenu:)
Then right click and click accept, save image for end user, and open your mod or the version of Scratch you just edited.
Creating new drop-downs
So, in this tutorial, we will be replacing the hide and show blocks with a drop-down.
First, either shift-click-r or shift-click-file (scratch or source) then click in the grey space at the bottom.
Next, click "open..." and then "browser".
Now, go to Scratch-Objects>ScratchSpriteMorph>looks ops.
Now to insert the list of options:
hideShowOptions
^ #('hide' 'show')We will use that later, for now, let's move on to the action.
hideShow: t1
| t2 |
t1 = 'show' ifTrue: [t2 _ true].
t1 = 'hide' ifTrue: [t2 _ false].
self isHidden: t2That is the action that will be used in the block spec.
Now let's define the drop-down. Go to: Scratch-Blocks>CommandBlockMorph>-- all -->uncoloredArgMorphFor:
It should look something like (slightly edited to my pleasure)
uncoloredArgMorphFor: t1
| t2 |
t2 _ t1 at: 2.
$a = t2 ifTrue: [^ AttributeArgMorph new choice: 'volume'].
$A = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #arithmeticFunctions].
$b = t2 ifTrue: [^ BooleanArgMorph new].
$B = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #hideShowOptions].
$c = t2 ifTrue: [^ ColorArgMorph new showPalette: true].
$C = t2 ifTrue: [^ ColorArgMorph new showPalette: false].
$d = t2 ifTrue: [^ ExpressionArgMorphWithMenu new numExpression: '0';
menuSelector: #directionMenu].
$D = t2 ifTrue: [^ ExpressionArgMorphWithMenu new numExpression: '48';
menuSelector: #midiDrumMenu].
$e = t2 ifTrue: [^ EventTitleMorph new].
$E = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #mixingNames].
$f = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #mathFunctionNames;
choice: 'sqrt'].
$g = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #graphicEffectNames;
choice: 'color'].
$H = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #hookupSensorNames].
$h = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #hookupBooleanSensorNames].
$I = t2 ifTrue: [^ ExpressionArgMorphWithMenu new numExpression: '1';
menuSelector: #midiInstrumentMenu].
$i = t2 ifTrue: [^ ExpressionArgMorphWithMenu new numExpression: '1';
menuSelector: #listIndexMenu].
$k = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #keyNames;
choice: 'space'].
$L = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #listVarMenu].
$l = t2 ifTrue: [^ ChoiceOrExpressionArgMorph new getOptionsSelector: #costumeNames;
choice: 'costume1'].
$m = t2 ifTrue: [^ SpriteArgMorph new].
$M = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #motorNames].
$n = t2 ifTrue: [^ ExpressionArgMorph new numExpression: '10'].
$N = t2 ifTrue: [^ ExpressionArgMorphWithMenu new numExpression: '60';
menuSelector: #noteSelector].
$o = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #trueFalse].
$r = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #directionSteps].
$s = t2 ifTrue: [^ ExpressionArgMorph new stringExpression: ''].
$S = t2 ifTrue: [^ ChoiceOrExpressionArgMorph new getOptionsSelector: #soundNames;
choice: 'pop'].
$v = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #varNamesMenu;
choice: ''].
$W = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #motorDirection].
$x = t2 ifTrue: [^ ChoiceOrExpressionArgMorph new getOptionsSelector: #sceneNames;
choice: ''].
$y = t2 ifTrue: [^ ExpressionArgMorphWithMenu new numExpression: '1';
menuSelector: #listIndexForDeleteMenu].
^ ExpressionArgMorph new numExpression: '10'Copy&paste:
$z = t2 ifTrue: [^ ChoiceOrExpressionArgMorph new getOptionsSelector: #hideShowOptions].
after the y ($y = t2 ifTrue: [^ ExpressionArgMorphWithMenu new numExpression: '1'; menuSelector: #listIndexForDeleteMenu].)
Now right-click and press accept.
Now go to (make sure you are under class, not instance): Scratch-Objects>ScratchSpriteMorph>block specs>blockSpecs
Look for the looks section and copy&paste:
('%z self' #- #hideShow: 'show')and now you have a hide/show drop-down!
Last edited by chanmanpartyman (2012-05-30 12:53:10)
Offline
Thanks! Can you make one on how to add a button like "Make a List" if you know how to?

Offline
Scratch-UI-Support>ResizableToggleButton2>-- all -->helpScreenName is where it's located.
Last edited by chanmanpartyman (2012-05-12 17:32:01)
Offline