@@ -25,6 +25,13 @@ enum ItemTextAttribute {
2525 Description
2626}
2727
28+ enum ToolbarNumberAttribute {
29+ //% block="selected index"
30+ SelectedIndex ,
31+ //% block="max items"
32+ MaxItems
33+ }
34+
2835//% color="#7732B3"
2936//% group="['Item', 'Toolbar', 'Inventory']"
3037namespace Inventory {
@@ -59,6 +66,7 @@ namespace Inventory {
5966 * @param value: The new text of the item.
6067 */
6168 //% block="%Inventory(Item) set text of %attribute to %value"
69+ //% weight=20
6270 //% group="Item"
6371 set_text ( attribute : ItemTextAttribute , value : string ) {
6472 if ( attribute == ItemTextAttribute . Name ) {
@@ -68,16 +76,42 @@ namespace Inventory {
6876 }
6977 }
7078
79+ /**
80+ * Get the name of description of the item.
81+ */
82+ //% block="%Inventory(Item) get text of %attribute"
83+ //% weight=10
84+ //% group="Item"
85+ get_text ( attribute : ItemTextAttribute ) {
86+ if ( attribute == ItemTextAttribute . Name ) {
87+ return this . name ;
88+ } else if ( attribute == ItemTextAttribute . Description ) {
89+ return this . description ;
90+ }
91+ return "" ;
92+ }
93+
7194 /**
7295 * Set the image of the item.
7396 * @param new_image: The new image.
7497 */
7598 //% block="%Inventory(Item) set image to %new_image"
7699 //% new_image.shadow=screen_image_picker
100+ //% weight=40
77101 //% group="Item"
78102 set_image ( new_image : Image ) {
79103 this . image = new_image ;
80104 }
105+
106+ /**
107+ * Get the image of the item.
108+ */
109+ //% block="%Inventory(Item) get image"
110+ //% weight=30
111+ //% group="Item"
112+ get_image ( ) {
113+ return this . image ;
114+ }
81115 }
82116
83117 /**
@@ -89,6 +123,7 @@ namespace Inventory {
89123 //% image.shadow=screen_image_picker
90124 //% expandableArgumentMode="toggle"
91125 //% description.dfl="Description"
126+ //% weight=50
92127 //% group="Item"
93128 export function create_item ( name : string , image : Image , description : string = null ) {
94129 return new Item ( name , image , description )
@@ -142,6 +177,16 @@ namespace Inventory {
142177 return this . _items ;
143178 }
144179
180+ /**
181+ * Get the items in the toolbar. Only rewrapped for blocks.
182+ */
183+ //% block="%Inventory(toolbar) get items"
184+ //% weight=80
185+ //% group="Toolbar"
186+ public get_items ( ) {
187+ return this . items ;
188+ }
189+
145190 /**
146191 * Set the items in the toolbar.
147192 */
@@ -150,6 +195,17 @@ namespace Inventory {
150195 this . update ( ) ;
151196 }
152197
198+ /**
199+ * Set the items in the toolbar. Only rewrapped for blocks.
200+ */
201+ //% block="%Inventory(toolbar) set items to %new_items"
202+ //% new_items.shadow="lists_create_with"
203+ //% weight=90
204+ //% group="Toolbar"
205+ public set_items ( new_items : Item [ ] ) {
206+ this . items = new_items ;
207+ }
208+
153209 /**
154210 * Get the maximum amount of items in the toolbar.
155211 */
@@ -165,11 +221,44 @@ namespace Inventory {
165221 this . update ( ) ;
166222 }
167223
224+ /**
225+ * Set the selected index or max items. Only rewrapped for blocks.
226+ */
227+ //% block="%Inventory(toolbar) set %attribute to %value"
228+ //% weight=70
229+ //% group="Toolbar"
230+ public set_number ( attribute : ToolbarNumberAttribute , value : number ) {
231+ if ( attribute == ToolbarNumberAttribute . SelectedIndex ) {
232+ this . selected = value ;
233+ } else if ( attribute == ToolbarNumberAttribute . MaxItems ) {
234+ this . max_items = value ;
235+ }
236+ }
237+
238+ /**
239+ * Get the selected index or max items. Only rewrapped for blocks.
240+ */
241+ //% block="%Inventory(toolbar) get %attribute"
242+ //% weight=60
243+ //% group="Toolbar"
244+ public get_number ( attribute : ToolbarNumberAttribute ) {
245+ if ( attribute == ToolbarNumberAttribute . SelectedIndex ) {
246+ return this . selected ;
247+ } else if ( attribute == ToolbarNumberAttribute . MaxItems ) {
248+ return this . max_items ;
249+ }
250+ return - 1 ;
251+ }
252+
168253 /**
169254 * Set a specific part of the toolbar to a specific color.
170255 * @param attribute: A property of the ToolbarColorAttribute enum.
171256 * @param color: A number which should be the new color of the attribute.
172257 */
258+ //% block="%Inventory(toolbar) set color of %attribute to %color"
259+ //% color.shadow=colorindexpicker
260+ //% weight=50
261+ //% group="Toolbar"
173262 public set_color ( attribute : ToolbarColorAttribute , color : number ) {
174263 if ( attribute == ToolbarColorAttribute . BoxOutline ) {
175264 this . _box_outline_color = color ;
@@ -186,6 +275,9 @@ namespace Inventory {
186275 * @param attribute: A property of the ToolbarColorAttribute enum.
187276 * @return : The color (which is a number) of the attribute, otherwise -1.
188277 */
278+ //% block="%Inventory(toolbar) get color of %attribute"
279+ //% weight=40
280+ //% group="Toolbar"
189281 public get_color ( attribute : ToolbarColorAttribute ) {
190282 if ( attribute == ToolbarColorAttribute . BoxOutline ) {
191283 return this . _box_outline_color ;
@@ -200,7 +292,9 @@ namespace Inventory {
200292 /**
201293 * Update the image of the toolbar.
202294 */
203- protected update ( ) {
295+ //% block="%Inventory(toolbar) force redraw of toolbar"
296+ //% weight=30
297+ public update ( ) {
204298 let image_size : number = 16 ;
205299 let padding : number = 2 ;
206300 let box_size : number = image_size + ( padding * 2 ) ;
@@ -238,6 +332,19 @@ namespace Inventory {
238332 }
239333 }
240334
335+ /**
336+ * Create a new toolbar - for blocks.
337+ */
338+ //% block="create toolbar with items %items and max items %max_items"
339+ //% blockSetVariable=toolbar
340+ //% items.shadow="lists_create_with"
341+ //% max_items.dfl=3
342+ //% weight=100
343+ //% group="Toolbar"
344+ export function create_toolbar ( items : Item [ ] , max_items : number ) {
345+ return new Toolbar ( items , max_items ) ;
346+ }
347+
241348 /**
242349 * Create an inventory sprite which is just a regular sprite.
243350 */
@@ -365,7 +472,7 @@ namespace Inventory {
365472 /**
366473 * Update the image of the inventory.
367474 */
368- protected update ( ) {
475+ public update ( ) {
369476 let image_size : number = 16 ;
370477 let padding : number = 1 ;
371478 let box_size : number = image_size + ( padding * 2 ) ;
0 commit comments