@@ -25,7 +25,7 @@ namespace microdata {
2525 * These sensors are passed to either the measurement screen or the live data view
2626 */
2727 export class SensorSelect extends CursorSceneWithPriorPage {
28- private btns : Button [ ]
28+ private btns : Button [ ] [ ]
2929 private selectedSensorAriaIDs : string [ ]
3030 private nextSceneEnum : CursorSceneEnum
3131 private jacdacSensorSelected : boolean
@@ -34,8 +34,9 @@ namespace microdata {
3434 super ( app , function ( ) {
3535 this . app . popScene ( ) ;
3636 this . app . pushScene ( new Home ( this . app ) )
37- } , new GridNavigator ( 4 , 5 ) ) ; // 4x5 grid
38- this . btns = [ ] ;
37+ } , new GridNavigator ( ) ) ;
38+
39+ this . btns = [ [ ] , [ ] , [ ] , [ ] ] ; // For our 4x5 grid
3940 this . selectedSensorAriaIDs = [ ] ;
4041 this . nextSceneEnum = nextSceneEnum ;
4142 this . jacdacSensorSelected = false ;
@@ -63,79 +64,93 @@ namespace microdata {
6364
6465 let x : number = - 60 ;
6566 let y : number = - 41
66- for ( let i = 0 ; i < icons . length ; i ++ ) {
67- this . btns . push ( new Button ( {
68- parent : null ,
69- style : ButtonStyles . Transparent ,
70- icon : icons [ i ] ,
71- ariaId : ariaIDs [ i ] ,
72- x : x ,
73- y : y ,
74- onClick : ( button : Button ) => {
75- // Deletion:
76- const index = this . selectedSensorAriaIDs . indexOf ( button . ariaId )
77- if ( index != - 1 ) {
78- this . cursor . setOutlineColour ( )
79- this . selectedSensorAriaIDs . splice ( index , 1 )
80-
81- if ( Sensor . getFromName ( button . ariaId ) . isJacdac ( ) ) {
82- this . jacdacSensorSelected = false
83- this . setOtherJacdacButtonsTo ( true )
84- }
67+ let iconIndex : number = 0 ;
68+
69+ const rowLengths = [ 5 , 5 , 5 , 4 ] // Last row has 'Done' button added after this loop:
70+ for ( let i = 0 ; i < 4 ; i ++ ) {
71+ for ( let j = 0 ; j < rowLengths [ i ] ; j ++ ) {
72+ this . btns [ i ] [ j ] = new Button ( {
73+ parent : null ,
74+ style : ButtonStyles . Transparent ,
75+ icon : icons [ iconIndex ] ,
76+ ariaId : ariaIDs [ iconIndex ] ,
77+ x : x ,
78+ y : y ,
79+ onClick : ( button : Button ) => {
80+ // Deletion:
81+ const index = this . selectedSensorAriaIDs . indexOf ( button . ariaId )
82+ if ( index != - 1 ) {
83+ this . cursor . setOutlineColour ( )
84+ this . selectedSensorAriaIDs . splice ( index , 1 )
85+
86+ if ( Sensor . getFromName ( button . ariaId ) . isJacdac ( ) ) {
87+ this . jacdacSensorSelected = false
88+ this . setOtherJacdacButtonsTo ( true )
89+ }
8590
86- // Renable all except the Jacdac buttons:
87- for ( let i = 0 ; i < START_OF_JACDAC_BUTTONS_INDEX ; i ++ ) {
88- this . btns [ i ] . pressable = true
91+ // Renable all except the Jacdac buttons:
92+ let currentIndex = 0 ;
93+ for ( let i = 0 ; i < this . btns . length ; i ++ ) {
94+ for ( let j = 0 ; j < rowLengths [ i ] ; j ++ ) {
95+ if ( currentIndex >= START_OF_JACDAC_BUTTONS_INDEX )
96+ break
97+ this . btns [ i ] [ j ] . pressable = true
98+ currentIndex ++ ;
99+ }
100+ }
89101 }
90- }
91102
92- // Addition:
93- else if ( this . selectedSensorAriaIDs . length < MAX_NUMBER_OF_SENSORS ) {
94- this . cursor . setOutlineColour ( 7 )
103+ // Addition:
104+ else if ( this . selectedSensorAriaIDs . length < MAX_NUMBER_OF_SENSORS ) {
105+ this . cursor . setOutlineColour ( 7 )
95106
96- if ( Sensor . getFromName ( button . ariaId ) . isJacdac ( ) ) {
97- if ( ! this . jacdacSensorSelected ) {
98- this . selectedSensorAriaIDs . push ( button . ariaId )
99- this . jacdacSensorSelected = true
107+ if ( Sensor . getFromName ( button . ariaId ) . isJacdac ( ) ) {
108+ if ( ! this . jacdacSensorSelected ) {
109+ this . selectedSensorAriaIDs . push ( button . ariaId )
110+ this . jacdacSensorSelected = true
100111
101- this . setOtherJacdacButtonsTo ( false , button )
112+ this . setOtherJacdacButtonsTo ( false , button )
113+ }
114+ }
115+
116+ else {
117+ this . selectedSensorAriaIDs . push ( button . ariaId )
118+ button . pressable = true
102119 }
103120 }
104-
105- else {
106- this . selectedSensorAriaIDs . push ( button . ariaId )
107- button . pressable = true
108- }
109- }
110-
111- // Prevention:
112- if ( this . selectedSensorAriaIDs . length >= MAX_NUMBER_OF_SENSORS ) {
113- for ( let i = 0 ; i < this . btns . length - 1 ; i ++ ) {
114- let buttonInUse = false
115- for ( let j = 0 ; j < this . selectedSensorAriaIDs . length ; j ++ ) {
116-
117- if ( this . btns [ i ] . ariaId == this . selectedSensorAriaIDs [ j ] ) {
118- buttonInUse = true
119- break
121+
122+ // Prevention:
123+ if ( this . selectedSensorAriaIDs . length >= MAX_NUMBER_OF_SENSORS ) {
124+ for ( let i = 0 ; i < this . btns . length ; i ++ ) {
125+ for ( let j = 0 ; j < rowLengths [ i ] ; j ++ ) {
126+ let buttonInUse = false
127+ for ( let k = 0 ; k < this . selectedSensorAriaIDs . length ; k ++ ) {
128+ if ( this . btns [ i ] [ j ] . ariaId == this . selectedSensorAriaIDs [ k ] ) {
129+ buttonInUse = true
130+ break
131+ }
132+ }
133+
134+ if ( ! buttonInUse )
135+ this . btns [ i ] [ j ] . pressable = false
120136 }
121137 }
122-
123- if ( ! buttonInUse )
124- this . btns [ i ] . pressable = false
125138 }
126- }
127- } ,
128- dynamicBoundaryColorsOn : true ,
129- } ) )
130-
131- x += 30
132- if ( x > 60 ) {
133- x = - 60
134- y += Screen . HEIGHT * 0.21875 // 28 on 128 pixel high Arcade Shield
139+ } ,
140+ dynamicBoundaryColorsOn : true ,
141+ } )
142+
143+ x += 30
144+ if ( x > 60 ) {
145+ x = - 60
146+ y += Screen . HEIGHT * 0.21875 // 28 on 128 pixel high Arcade Shield
147+ }
148+
149+ iconIndex ++ ;
135150 }
136151 }
137152
138- this . btns . push ( new Button ( {
153+ this . btns [ 3 ] . push ( new Button ( {
139154 parent : null ,
140155 style : ButtonStyles . Transparent ,
141156 icon : "green_tick" ,
@@ -160,7 +175,9 @@ namespace microdata {
160175 this . app . pushScene ( new RecordingConfigSelection ( this . app , sensors , CursorSceneEnum . DistributedLogging ) )
161176 }
162177 } ) )
163- this . navigator . addButtons ( this . btns )
178+
179+
180+ this . navigator . setBtns ( this . btns )
164181 }
165182
166183 /**
@@ -170,10 +187,17 @@ namespace microdata {
170187 * @param buttonToIgnore Optional case that ignores the pressableStatus
171188 */
172189 private setOtherJacdacButtonsTo ( pressableStatus : boolean , buttonToIgnore ?: Button ) {
173- for ( let i = START_OF_JACDAC_BUTTONS_INDEX ; i < this . btns . length - 1 ; i ++ )
174- this . btns [ i ] . pressable = pressableStatus
190+ let currentIndex = 0 ;
175191
176- if ( buttonToIgnore )
192+ for ( let i = 0 ; i < this . btns . length ; i ++ ) {
193+ for ( let j = 0 ; j < this . btns [ 0 ] . length ; j ++ ) {
194+ if ( currentIndex >= START_OF_JACDAC_BUTTONS_INDEX && currentIndex != ( 4 * 5 ) - 1 ) // Don't touch the last button ('Done')
195+ this . btns [ i ] [ j ] . pressable = pressableStatus
196+ currentIndex ++ ;
197+ }
198+ }
199+
200+ if ( buttonToIgnore )
177201 buttonToIgnore . pressable = ! pressableStatus
178202 }
179203
@@ -186,9 +210,7 @@ namespace microdata {
186210 0xc
187211 )
188212
189- for ( let i = 0 ; i < this . btns . length ; i ++ )
190- this . btns [ i ] . draw ( )
191-
213+ this . navigator . drawComponents ( ) ;
192214 super . draw ( )
193215 }
194216 }
0 commit comments