private void changeSong() { if (background != null) { Game.M.setSong(ref songNameList[index].Info); currentSong = Game.M.CurrentSong; targetVolume = Config.Volume / 100.0f; Music.stop(); string bgString = ""; if (currentSong.FileVersion == 0) { bgString = currentSong.BgName; } else { bgString = currentSong.Charts[0].BgName; } background.useTexture("songs\\" + currentSong.Dir + "\\" + bgString); updateScoreLabels(0); music = AudioManager.loadFromFile("songs\\" + currentSong.Dir + "\\" + currentSong.FileName); Music.Volume = 0.0f; Music.PositionAsMilli = (long)currentSong.Preview; Music.play(false, true); changed = true; transitioning = true; difficultyTexts.Clear(); updateDiffs(); } for (int x = 0; x < songNameList.Count; x++) { songNameList[x].select.moveY(new Point(songNameList[x].select.Bounds.X, 246 + ((x - index) * 90)), 0.3); } if (currentlySelected != null) { currentlySelected.selected = false; } songNameList[index].select.selected = true; currentlySelected = songNameList[index].select; }
private void refresh() { //todo show some animation during this transitioning = true; songNameList.Clear(); SongLibrary.cacheSongInfo(); //prob should make separate method since searching forces cache refresh lol. we are good coders dont worry foreach (var pair in SongLibrary.songInfos) { Text temp = new Text(Config.ClientSize, new Size(550, 35), new Point(0, 0)); /*SizeF temp1 = temp.getStringSize(pair.Value.Artist + " - " + pair.Value.SongName); temp.TextureSize = new Size((int)temp1.Width, (int)temp1.Height);*/ temp.Update(pair.Value.Artist + " - " + pair.Value.SongName); temp.Shadow = true; SelectComponent sc = new SelectComponent(game, new Rectangle(-50, 0, 550, 90), pair.Value.Artist, pair.Value.SongName); sc.clickEvent += new Action<int, SelectComponent>(sc_clickEvent); SongPair sp = new SongPair(sc, pair.Value); songNameList.Add(sp); sc.index = songNameList.IndexOf(sp); } songNameList.Sort(new Comparison<SongPair>(delegate(SongPair f, SongPair j) { return -f.Info.SongName.CompareTo(j.Info.SongName); })); foreach (SongPair sp in songNameList) { sp.select.index = songNameList.IndexOf(sp); } }
void sc_clickEvent(int obj, SelectComponent obj2) { // Console.WriteLine(obj); if (doIt && !pickDiff && !Game.pbox.expanded) //stupid but required { if (obj2.selected) { pickDiffs(); } else { notPickDiffs(); index = obj; changeSong(); /* if (currentlySelected != null) { currentlySelected.selected = false; } obj2.selected = true; currentlySelected = obj2;*/ } doIt = false; } }
//This class was to prevent a bug with songs that occured when adding a new song for the first time - SongLibrary.Songs has new songs appended to the end of the list; however, since songInfos is a sorted dictionary it is sorted based on key, and the new song is not added to the end of the list. Song labels are added based on songInfos, while selection is based on the Song, causing a conflict public SongPair(SelectComponent t, SongInfo s) { select = t; Info = s; }