11package options ;
22
3- import objects .AttachedText ;
4- import objects .CheckboxThingie ;
5- import options .GameplayChangersSubstate .GameplayOption ;
6-
7- import archipelago .APEntryState ;
8- import objects .AttachedText ;
9- import objects .CheckboxThingie ;
10- import objects .Note ;
11-
12- import options .Option .OptionType ;
13-
14- class CategoriesSubstate extends MusicBeatSubstate
3+ class CategoriesSubstate extends LightBaseOptionsMenu
154{
16- private var curSelected : Int = 0 ;
17- private var optionsArray : Array <Dynamic > = [];
18-
19- private var checkboxGroup : FlxTypedGroup <CheckboxThingie >;
20-
21-
22- private var grpOptions : FlxTypedGroup <Alphabet >;
23- private var grpTexts : FlxTypedGroup <AttachedText >;
24-
25- private var curOption (get , never ): GameplayOption ;
26- function get_curOption () return optionsArray [curSelected ];
27-
28- function getOptions ()
5+ public function new ()
296 {
30- var option : GameplayOption = new GameplayOption (' Show Mods as Categories' , ' showMods' , BOOL , false );
31-
32- option .setValue (ClientPrefs .data .showMods );
33-
34- // option.description = 'Show mods as categories in the mod menu.';
7+ title = ' Category Settings.' ;
8+ rpcTitle = ' Category Settings' ; // for Discord Rich Presence
359
10+ var option : Option = new Option (' Show Mods as Categories' ,
11+ " Show mods as categories in the mod menu." ,
12+ ' showMods' ,
13+ BOOL );
3614 option .onChange = function actuallyChangeFucker ()
3715 {
38- ClientPrefs .data .showMods = option .getValue ();
3916 FlxG .sound .play (Paths .sound (' scrollMenu' ));
40- }; // Because for some unknonw reason, this isn't changing it automatically...
41-
42-
43- optionsArray .push (option );
44- }
45-
46- public function getOptionByName (name : String )
47- {
48- for (i in optionsArray )
49- {
50- var opt : GameplayOption = i ;
51- if (opt .name == name )
52- return opt ;
53- }
54- return null ;
55- }
56-
57- public function new ()
58- {
59- super ();
60-
61- var bg : FlxSprite = new FlxSprite ().makeGraphic (FlxG .width , FlxG .height , FlxColor .BLACK );
62- bg .alpha = 0.6 ;
63- add (bg );
64-
65- // avoids lagspikes while scrolling through menus!
66- grpOptions = new FlxTypedGroup <Alphabet >();
67- add (grpOptions );
68-
69- grpTexts = new FlxTypedGroup <AttachedText >();
70- add (grpTexts );
71-
72- checkboxGroup = new FlxTypedGroup <CheckboxThingie >();
73- add (checkboxGroup );
74-
75- getOptions ();
76-
77- for (i in 0 ... optionsArray .length )
78- {
79- var optionText : Alphabet = new Alphabet (150 , 360 , optionsArray [i ].name , true );
80- optionText .isMenuItem = true ;
81- optionText .setScale (0.8 );
82- optionText .targetY = i ;
83- grpOptions .add (optionText );
84-
85- if (optionsArray [i ].type == BOOL )
86- {
87- optionText .x + = 60 ;
88- optionText .startPosition .x + = 60 ;
89- optionText .snapToPosition ();
90- var checkbox : CheckboxThingie = new CheckboxThingie (optionText .x - 105 , optionText .y , optionsArray [i ].getValue () == true );
91- checkbox .sprTracker = optionText ;
92- checkbox .offsetX - = 20 ;
93- checkbox .offsetY = - 52 ;
94- checkbox. ID = i ;
95- checkboxGroup .add (checkbox );
96- }
97- else
98- {
99- optionText .snapToPosition ();
100- var valueText : AttachedText = new AttachedText (Std .string (optionsArray [i ].getValue ()), optionText .width + 40 , 0 , true , 0.8 );
101- valueText .sprTracker = optionText ;
102- valueText .copyAlpha = true ;
103- valueText. ID = i ;
104- grpTexts .add (valueText );
105- optionsArray [i ].setChild (valueText );
106- }
107- updateTextFrom (optionsArray [i ]);
108- }
109-
110- changeSelection ();
111- reloadCheckboxes ();
112- }
113-
114- var nextAccept : Int = 5 ;
115- var holdTime : Float = 0 ;
116- var holdValue : Float = 0 ;
117- override function update (elapsed : Float )
118- {
119- if (controls. UI_UP_P )
120- changeSelection (- 1 );
121-
122- if (controls. UI_DOWN_P )
123- changeSelection (1 );
124-
125- if (controls. BACK )
126- {
127- close ();
128- ClientPrefs .saveSettings ();
129- FlxG .sound .play (Paths .sound (' cancelMenu' ));
130- }
131-
132- if (nextAccept <= 0 )
133- {
134- var usesCheckbox : Bool = (curOption .type == BOOL );
135- if (usesCheckbox )
136- {
137- if (controls. ACCEPT )
138- {
139- FlxG .sound .play (Paths .sound (' scrollMenu' ));
140- curOption .setValue ((curOption .getValue () == true ) ? false : true );
141- curOption .change ();
142- reloadCheckboxes ();
143- }
144- }
145- else
146- {
147- if (controls. UI_LEFT || controls. UI_RIGHT )
148- {
149- var pressed = (controls. UI_LEFT_P || controls. UI_RIGHT_P );
150- if (holdTime > 0.5 || pressed )
151- {
152- if (pressed )
153- {
154- var add : Dynamic = null ;
155- if (curOption .type != STRING )
156- add = controls. UI_LEFT ? - curOption .changeValue : curOption .changeValue ;
157-
158- switch (curOption .type )
159- {
160- case INT , FLOAT , PERCENT :
161- holdValue = curOption .getValue () + add ;
162- if (holdValue < curOption .minValue ) holdValue = curOption .minValue ;
163- else if (holdValue > curOption .maxValue ) holdValue = curOption .maxValue ;
164-
165- switch (curOption .type )
166- {
167- case INT :
168- holdValue = Math .round (holdValue );
169- curOption .setValue (holdValue );
170-
171- case FLOAT , PERCENT :
172- holdValue = FlxMath .roundDecimal (holdValue , curOption .decimals );
173- curOption .setValue (holdValue );
174-
175- default :
176- }
177-
178- case STRING :
179- var num : Int = curOption .curOption ; // lol
180- if (controls. UI_LEFT_P ) -- num ;
181- else num ++ ;
182-
183- if (num < 0 )
184- num = curOption .options .length - 1 ;
185- else if (num >= curOption .options .length )
186- num = 0 ;
187-
188- curOption .curOption = num ;
189- curOption .setValue (curOption .options [num ]); // lol
190-
191- if (curOption .name == " Scroll Type" )
192- {
193- var oOption : GameplayOption = getOptionByName (" Scroll Speed" );
194- if (oOption != null )
195- {
196- if (curOption .getValue () == " constant" )
197- {
198- oOption .displayFormat = " %v" ;
199- oOption .maxValue = 6 ;
200- }
201- else
202- {
203- oOption .displayFormat = " %vX" ;
204- oOption .maxValue = 3 ;
205- if (oOption .getValue () > 3 ) oOption .setValue (3 );
206- }
207- updateTextFrom (oOption );
208- }
209- }
210- // trace(curOption.options[num]);
211-
212- default :
213- }
214- updateTextFrom (curOption );
215- curOption .change ();
216- FlxG .sound .play (Paths .sound (' scrollMenu' ));
217- }
218- else if (curOption .type != STRING )
219- {
220- holdValue = Math .max (curOption .minValue , Math .min (curOption .maxValue , holdValue + curOption .scrollSpeed * elapsed * (controls. UI_LEFT ? - 1 : 1 )));
221-
222- switch (curOption .type )
223- {
224- case INT :
225- curOption .setValue (Math .round (holdValue ));
226-
227- case FLOAT , PERCENT :
228- var blah : Float = Math .max (curOption .minValue , Math .min (curOption .maxValue , holdValue + curOption .changeValue - (holdValue % curOption .changeValue )));
229- curOption .setValue (FlxMath .roundDecimal (blah , curOption .decimals ));
230-
231- default :
232- }
233- updateTextFrom (curOption );
234- curOption .change ();
235- }
236- }
237-
238- if (curOption .type != STRING )
239- holdTime + = elapsed ;
240- }
241- else if (controls. UI_LEFT_R || controls. UI_RIGHT_R )
242- clearHold ();
243- }
244-
245- if (controls. RESET )
246- {
247- for (i in 0 ... optionsArray .length )
248- {
249- var leOption : GameplayOption = optionsArray [i ];
250- leOption .setValue (leOption .defaultValue );
251- if (leOption .type != BOOL )
252- {
253- if (leOption .type == STRING )
254- leOption .curOption = leOption .options .indexOf (leOption .getValue ());
255-
256- updateTextFrom (leOption );
257- }
258-
259- if (leOption .name == ' Scroll Speed' )
260- {
261- leOption .displayFormat = " %vX" ;
262- leOption .maxValue = 3 ;
263- if (leOption .getValue () > 3 )
264- leOption .setValue (3 );
265-
266- updateTextFrom (leOption );
267- }
268- leOption .change ();
269- }
270- FlxG .sound .play (Paths .sound (' cancelMenu' ));
271- reloadCheckboxes ();
272- }
273- }
274-
275- if (nextAccept > 0 ) {
276- nextAccept - = 1 ;
277- }
278- super .update (elapsed );
279- }
280-
281- function updateTextFrom (option : GameplayOption ) {
282- var text : String = option .displayFormat ;
283- var val : Dynamic = option .getValue ();
284- if (option .type == PERCENT ) val * = 100 ;
285- var def : Dynamic = option .defaultValue ;
286- option .text = text .replace (' %v' , val ).replace (' %d' , def );
287- }
288-
289- function clearHold ()
290- {
291- if (holdTime > 0.5 )
292- FlxG .sound .play (Paths .sound (' scrollMenu' ));
293-
294- holdTime = 0 ;
295- }
296-
297- function changeSelection (change : Int = 0 )
298- {
299- curSelected = FlxMath .wrap (curSelected + change , 0 , optionsArray .length - 1 );
300- for (num => item in grpOptions .members )
301- {
302- item .targetY = num - curSelected ;
303- item .alpha = 0.6 ;
304- if (item .targetY == 0 )
305- item .alpha = 1 ;
306- }
307- for (text in grpTexts )
308- {
309- text .alpha = 0.6 ;
310- if (text. ID == curSelected )
311- text .alpha = 1 ;
312- }
313- FlxG .sound .play (Paths .sound (' scrollMenu' ));
314- }
315-
316- function reloadCheckboxes () {
317- for (checkbox in checkboxGroup ) {
318- checkbox .daValue = (optionsArray [checkbox. ID ].getValue () == true );
319- }
32017 }
18+ addOption (option );
19+
20+ super ();
32121 }
22+ }
32223
0 commit comments