@@ -191,7 +191,7 @@ def get_selected_idx(menu: WillowGFxMenu) -> int | None:
191191 return None
192192
193193
194- slider_spinner_next_tick_info : tuple [WeakPointer , str , Populator , int ] | None = None
194+ slider_next_tick_info : tuple [WeakPointer , str , Populator , int ] | None = None
195195
196196
197197# Similarly to the lobby menu, we need to use sounds to detect when you click an option/adjust a
@@ -217,42 +217,52 @@ def play_sound(
217217 populator .on_activate (obj , idx )
218218 return
219219
220+ # The same sound is used for both sliders and spinners.
221+ # This variable is only defined on spinners, so should be NaN if we've selected a slider.
222+ choice : float = obj .GetVariableNumber ((focused := find_focused_item (obj )) + ".mChoice" )
223+ if math .isfinite (choice ):
224+ # It's a spinner
225+ populator .on_spinner_change (obj , idx , int (choice ))
226+ return
227+
228+ # It's a slider.
220229 # Sliders have the same problem as in the lobby movie, for kb input they plays the sound after
221230 # updating the value, and we could run our callbacks here, but for mouse input they play the
222- # sound before. Wait for next tick before updating.
231+ # sound before.
232+ # Save a bunch of data we already have, then wait for next tick.
223233
224- # Save a bunch of data we already have
225- global slider_spinner_next_tick_info
226- slider_spinner_next_tick_info = (
234+ global slider_next_tick_info
235+ slider_next_tick_info = (
227236 WeakPointer (obj ),
228- find_focused_item ( obj ) + ".mValue" ,
237+ focused + ".mValue" ,
229238 populator ,
230239 idx ,
231240 )
232241
233- slider_spinner_next_tick .enable ()
242+ slider_next_tick .enable ()
234243
235244
236245@hook ("WillowGame.WillowUIInteraction:TickImp" )
237- def slider_spinner_next_tick (* _ : Any ) -> None :
238- slider_spinner_next_tick .disable ()
246+ def slider_next_tick (* _ : Any ) -> None :
247+ slider_next_tick .disable ()
239248
240- global slider_spinner_next_tick_info
241- if slider_spinner_next_tick_info is None :
249+ global slider_next_tick_info
250+ if slider_next_tick_info is None :
242251 return
243- weak_menu , path , populator , idx = slider_spinner_next_tick_info
244- slider_spinner_next_tick_info = None
252+ weak_menu , path , populator , idx = slider_next_tick_info
253+ slider_next_tick_info = None
245254
246255 if (menu := weak_menu ()) is None :
247256 return
248257 value = menu .GetVariableNumber (path )
249258
250- if math .isnan (value ):
251- # We really don't want to set an option's value to NaN since it becomes essentially
252- # unrecoverable without manually editing settings
253- logging .error ("Got NaN after changing spinner/slide!" )
259+ if not math .isfinite (value ):
260+ # If something's become invalid, we'll have gotten a NaN back. We really don't want to set
261+ # an option's value to NaN or inf, since it becomes essentially unrecoverable without
262+ # manually editing settings
263+ logging .error (f"Got { value } after changing spinner/slider!" )
254264 else :
255- populator .on_slider_spinner_change (menu , idx , value )
265+ populator .on_slider_change (menu , idx , value )
256266
257267
258268@hook ("WillowGame.WillowGFxMenuScreenGeneric:Screen_Deactivate" , immediately_enable = True )
0 commit comments