@@ -77,11 +77,11 @@ private void WireUpEvents()
7777 btn_mapTypeFB . Click += ( s , e ) => FilterAvailableMaps ( 8 ) ;
7878
7979 // Playlist selection
80- btn_loadPlaylist1 . Click += ( s , e ) => LoadPlaylist ( 1 ) ;
81- btn_loadPlaylist2 . Click += ( s , e ) => LoadPlaylist ( 2 ) ;
82- btn_loadPlaylist3 . Click += ( s , e ) => LoadPlaylist ( 3 ) ;
83- btn_loadPlaylist4 . Click += ( s , e ) => LoadPlaylist ( 4 ) ;
84- btn_loadPlaylist5 . Click += ( s , e ) => LoadPlaylist ( 5 ) ;
80+ btn_loadPlaylist1 . Click += ( s , e ) => actionClick_loadMapPlaylist1 ( ) ;
81+ btn_loadPlaylist2 . Click += ( s , e ) => actionClick_loadMapPlaylist2 ( ) ;
82+ btn_loadPlaylist3 . Click += ( s , e ) => actionClick_loadMapPlaylist3 ( ) ;
83+ btn_loadPlaylist4 . Click += ( s , e ) => actionClick_loadMapPlaylist4 ( ) ;
84+ btn_loadPlaylist5 . Click += ( s , e ) => actionClick_loadMapPlaylist5 ( ) ;
8585
8686 // Playlist editing
8787 dataGridView_availableMaps . CellDoubleClick += ( s , e ) => AddMapToPlaylist ( e . RowIndex ) ;
@@ -184,8 +184,23 @@ private void RandomizePlaylist()
184184 MessageBox . Show ( "Cannot randomize an empty playlist." , "Empty Playlist" , MessageBoxButtons . OK , MessageBoxIcon . Warning ) ;
185185 return ;
186186 }
187- var rnd = new Random ( ) ;
188- _currentPlaylist = _currentPlaylist . OrderBy ( x => rnd . Next ( ) ) . ToList ( ) ;
187+
188+ // Fisher-Yates shuffle
189+ var random = new Random ( ) ;
190+ for ( int i = _currentPlaylist . Count - 1 ; i > 0 ; i -- )
191+ {
192+ int j = random . Next ( i + 1 ) ;
193+ var temp = _currentPlaylist [ i ] ;
194+ _currentPlaylist [ i ] = _currentPlaylist [ j ] ;
195+ _currentPlaylist [ j ] = temp ;
196+ }
197+
198+ // Renumber MapIDs sequentially (1-based)
199+ for ( int i = 0 ; i < _currentPlaylist . Count ; i ++ )
200+ {
201+ _currentPlaylist [ i ] . MapID = i + 1 ;
202+ }
203+
189204 RefreshCurrentPlaylistGrid ( ) ;
190205 MessageBox . Show ( "Playlist randomized. Remember to save to apply changes." , "Randomized" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
191206 }
@@ -200,6 +215,43 @@ private void RefreshCurrentPlaylistGrid()
200215 id ++ , map . MapName , map . MapFile , map . ModType , map . MapType , GetShortType ( map . MapType ) ) ;
201216 }
202217 }
218+
219+ /// <summary>
220+ /// Playlist selection button handlers
221+ /// </summary>
222+ private void actionClick_loadMapPlaylist1 ( ) => methodFunction_selectPlaylist ( 1 ) ;
223+ private void actionClick_loadMapPlaylist2 ( ) => methodFunction_selectPlaylist ( 2 ) ;
224+ private void actionClick_loadMapPlaylist3 ( ) => methodFunction_selectPlaylist ( 3 ) ;
225+ private void actionClick_loadMapPlaylist4 ( ) => methodFunction_selectPlaylist ( 4 ) ;
226+ private void actionClick_loadMapPlaylist5 ( ) => methodFunction_selectPlaylist ( 5 ) ;
227+
228+ /// <summary>
229+ /// Select and load a specific playlist
230+ /// </summary>
231+ private void methodFunction_selectPlaylist ( int playlistID )
232+ {
233+ Color selected = SystemColors . ActiveBorder ;
234+ Color notSelected = Button . DefaultBackColor ;
235+
236+ // Set selected playlist
237+ mapInstance ! . SelectedPlaylist = playlistID ;
238+
239+ // Update button colors
240+ btn_loadPlaylist1 . BackColor = playlistID == 1 ? selected : notSelected ;
241+ btn_loadPlaylist2 . BackColor = playlistID == 2 ? selected : notSelected ;
242+ btn_loadPlaylist3 . BackColor = playlistID == 3 ? selected : notSelected ;
243+ btn_loadPlaylist4 . BackColor = playlistID == 4 ? selected : notSelected ;
244+ btn_loadPlaylist5 . BackColor = playlistID == 5 ? selected : notSelected ;
245+
246+ // Update active playlist display
247+ btn_activePlaylist . Text = $ "P{ mapInstance . ActivePlaylist } ";
248+
249+ // Update map controls
250+ methodFunction_UpdateMapControls ( ) ;
251+
252+ // Load playlist
253+ _ = LoadPlaylist ( playlistID ) ;
254+ }
203255
204256 private string GetShortType ( int mapType )
205257 {
0 commit comments