@@ -224,7 +224,9 @@ modmanager.gui.OptionsOptionButton = ig.GuiElementBase.extend({
224224
225225 this . button = new sc . ButtonGui ( option . name )
226226 if ( option . onPress ) {
227- this . button . onButtonPress = option . onPress . bind ( option )
227+ this . button . onButtonPress = ( ) => {
228+ option . onPress . call ( option )
229+ }
228230 }
229231
230232 // this.button.setPos(5, 8)
@@ -269,11 +271,12 @@ declare global {
269271 interface OptionsOptionInputField extends ig . GuiElementBase {
270272 option : GuiOption
271273 inputField : nax . ccuilib . InputField
274+ isValidText ?: sc . TextGui
272275 }
273- interface OptionsOptionInputFieldConstructor extends ImpactClass < OptionsOptionInputField > {
276+ interface OptionsOptionInputFieldValidationConstructor extends ImpactClass < OptionsOptionInputField > {
274277 new ( option : GuiOption , y : number , rowGroup : sc . RowButtonGroup , width : number ) : OptionsOptionInputField
275278 }
276- var OptionsOptionInputField : OptionsOptionInputFieldConstructor
279+ var OptionsOptionInputField : OptionsOptionInputFieldValidationConstructor
277280 }
278281}
279282
@@ -283,22 +286,44 @@ modmanager.gui.OptionsOptionInputField = ig.GuiElementBase.extend({
283286 this . option = option
284287 if ( option . type != 'INPUT_FIELD' ) throw new Error ( 'how' )
285288
286- const height = option . height ?? 20
287- this . inputField = new nax . ccuilib . InputField ( width , height )
289+ this . inputField = new nax . ccuilib . InputField ( width - 30 , 20 )
288290
289291 const text = optGet ( option ) as string
290292 this . inputField . setText ?.( text )
291293
294+ const revalidate = async ( text : string ) => {
295+ if ( ! option . isValid ) throw new Error ( 'how' )
296+
297+ this . isValidText ! . setText ( '\\i[lore-others]' )
298+ const isValid = await option . isValid ( text )
299+
300+ if ( this . inputField . getValueAsString ( ) == text ) {
301+ this . isValidText ! . setText ( isValid ? '\\i[quest-solve]' : '\\i[quest-elite]' )
302+ return isValid
303+ } else return false
304+ }
305+
306+ if ( option . isValid ) {
307+ this . inputField . setPos ( 20 + 4 , 0 )
308+ this . isValidText = new sc . TextGui ( '' )
309+ this . isValidText . setPos ( 3 , 2 )
310+ this . addChildGui ( this . isValidText )
311+ revalidate ( text )
312+ }
313+
292314 this . inputField . onCharacterInput = str => {
293- optSet ( option , str )
294- if ( option . changeEvent ) option . changeEvent ( )
315+ if ( option . isValid ) {
316+ revalidate ( str ) . then ( isValid => {
317+ if ( isValid ) optSet ( option , str )
318+ } )
319+ } else {
320+ optSet ( option , str )
321+ }
295322 }
296323
297- // this.button.setPos(5, 8)
298324 this . inputField . setAlign ( ig . GUI_ALIGN . X_LEFT , ig . GUI_ALIGN . Y_CENTER )
299325
300326 const backup = this . inputField . focusGained . bind ( this . inputField )
301- // this.inputField.data = option.description
302327 this . inputField . focusGained = function ( this : nax . ccuilib . InputField ) {
303328 backup ( )
304329 sc . menu . setInfoText ( option . description as string )
0 commit comments