@@ -38,6 +38,7 @@ export function registerListeners(){
3838}
3939
4040type MenuConfirmProps = {
41+ /** This message is sent to the user (prefixed with /!\) if they cancel. */
4142 cancelOutput ?: string ;
4243 title ?: string ;
4344 confirmText ?: string ;
@@ -69,7 +70,7 @@ export const Menu = {
6970 } :{
7071 optionStringifier ?:( opt :TOption ) => string ;
7172 /**
72- * Specifies the behavior when the player cancels the menu (by clicking Cancel, or by pressing Escape).
73+ * Specifies the behavior when the player cancels the menu (by clicking Cancel, or by pressing Escape).
7374 * @default "ignore"
7475 */
7576 onCancel ?: TCancelBehavior ;
@@ -114,7 +115,13 @@ export const Menu = {
114115 }
115116 } } ) ;
116117
117- Call . menu ( target . con , registeredListeners . generic , title , description , arrangedOptions . map ( r => r . map ( optionStringifier ) ) ) ;
118+ let i = 0 ;
119+ const stringifiedOptions = arrangedOptions . map ( r => r . map ( item => {
120+ if ( i === cancelOptionId ) return item as string ;
121+ i ++ ;
122+ return optionStringifier ( item ) ;
123+ } ) ) ;
124+ Call . menu ( target . con , registeredListeners . generic , title , description , stringifiedOptions ) ;
118125 return promise ;
119126 } ,
120127 /** Displays a menu to a player, returning a Promise. Arranges options into a 2D array, and can add a Cancel option. */
@@ -133,7 +140,7 @@ export const Menu = {
133140 const arrangedOptions = ( options . length == 0 && ! includeCancel ) ? [ ] : to2DArray ( options , columns ) ;
134141
135142 if ( includeCancel ) {
136- arrangedOptions . push ( [ "Cancel" as never ] ) ;
143+ arrangedOptions . push ( [ "[red] Cancel[] " as never ] ) ;
137144 //This is safe because cancelOptionId is set,
138145 //so the handler will never get called with "Cancel".
139146 cancelOptionId = options . length ;
@@ -174,7 +181,7 @@ export const Menu = {
174181 return Menu . raw ( title , description , options , target , {
175182 ...cfg ,
176183 optionStringifier : o => o . text ,
177- } ) . then ( o => o ?. data ) ;
184+ } ) . then ( o => o ?. data as TButtonData | ( TCancelBehavior extends "null" ? null : never ) ) ;
178185 } ,
179186 pages < TOption extends unknown , TCancelBehavior extends MenuCancelOption > (
180187 this :void , target :FishPlayer , title :string , description :string ,
@@ -209,7 +216,7 @@ export const Menu = {
209216 showPage ( 0 ) ;
210217 return promise ;
211218 } ,
212- pagedListButtons < TButtonData extends unknown , MenuCancelBehavior extends MenuCancelOption > (
219+ pagedListButtons < TButtonData extends unknown , MenuCancelBehavior extends MenuCancelOption = "ignore" > (
213220 this :void , target :FishPlayer , title :string , description :string ,
214221 options :{ data : TButtonData ; text : string ; } [ ] ,
215222 { rowsPerPage = 10 , columns = 3 , ...cfg } : Pick < MenuOptions < TButtonData , MenuCancelBehavior > , "columns" | "onCancel" > & {
@@ -219,23 +226,22 @@ export const Menu = {
219226 ) {
220227 //Generate pages
221228 const pages = to2DArray ( to2DArray ( options , columns ) , rowsPerPage ) ;
222- if ( pages . length == 1 ) return Menu . buttons ( target , title , description , pages [ 0 ] , cfg ) ;
229+ if ( pages . length <= 1 ) return Menu . buttons ( target , title , description , pages [ 0 ] ?? [ ] , cfg ) ;
223230 return Menu . pages ( target , title , description , pages , cfg ) ;
224231 } ,
225- pagedList < TButtonData extends unknown , MenuCancelBehavior extends MenuCancelOption > (
232+ pagedList < TButtonData extends unknown , MenuCancelBehavior extends MenuCancelOption = "ignore" > (
226233 this :void , target :FishPlayer , title :string , description :string ,
227234 options :TButtonData [ ] ,
228- { rowsPerPage = 10 , columns = 3 , optionStringifier, ...cfg } : Pick < MenuOptions < TButtonData , MenuCancelBehavior > , "columns" | "onCancel" | "optionStringifier" > & {
235+ { rowsPerPage = 10 , columns = 3 , optionStringifier = String , ...cfg } : Pick < MenuOptions < TButtonData , MenuCancelBehavior > , "columns" | "onCancel" | "optionStringifier" > & {
229236 /** @default 10 */
230237 rowsPerPage ?:number ;
231- optionStringifier : { } ;
232- } ,
238+ } = { } ,
233239 ) {
234240 //Generate pages
235241 const pages = to2DArray ( to2DArray ( options . map (
236242 o => ( { data : o , get text ( ) { return optionStringifier ( o ) ; } } )
237243 ) , columns ) , rowsPerPage ) ;
238- if ( pages . length == 1 ) return Menu . buttons ( target , title , description , pages [ 0 ] , cfg ) ;
244+ if ( pages . length <= 1 ) return Menu . buttons ( target , title , description , pages [ 0 ] ?? [ ] , cfg ) ;
239245 return Menu . pages ( target , title , description , pages , cfg ) ;
240246 }
241247}
0 commit comments