From bcf4d2f6040c84b6757cc7315bb9ff51a3ef5903 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 11 Feb 2003 23:52:18 +0000 Subject: [PATCH] Rename title accessors in Song. Add a preference to prefer transliterations. Press F9 in the music select screen to toggle it ("what's that kanji again?"); appearance options entry forthcoming. Hopefully fix wheel sections; we were assuming that sections were always sorted the same as the songs in them, but this isn't true with "OTHER". --- stepmania/src/MusicList.cpp | 2 +- stepmania/src/MusicWheel.cpp | 22 +++++++++++++-- stepmania/src/MusicWheel.h | 8 ++++-- stepmania/src/NotesWriterDWI.cpp | 11 ++------ stepmania/src/PrefsManager.cpp | 3 ++ stepmania/src/PrefsManager.h | 1 + stepmania/src/ScreenGameplay.cpp | 2 +- stepmania/src/ScreenMusicScroll.cpp | 2 +- stepmania/src/ScreenSelectMusic.cpp | 8 ++++++ stepmania/src/Song.cpp | 43 +++++++++++++++++++++-------- stepmania/src/TextBanner.cpp | 6 ++-- stepmania/src/TransitionOniFade.cpp | 2 +- stepmania/src/song.h | 28 +++++++++++++------ 13 files changed, 98 insertions(+), 40 deletions(-) diff --git a/stepmania/src/MusicList.cpp b/stepmania/src/MusicList.cpp index a22d040535..65cdb67e66 100644 --- a/stepmania/src/MusicList.cpp +++ b/stepmania/src/MusicList.cpp @@ -56,7 +56,7 @@ void MusicList::AddSongsToGroup(const vector &Songs) continue; } - CString sTitle = Songs[iIndex]->GetFullTitle(); + CString sTitle = Songs[iIndex]->GetFullDisplayTitle(); // TODO: Move this crop threshold into a theme metric or make automatic based on column width if( sTitle.GetLength() > 40 ) { diff --git a/stepmania/src/MusicWheel.cpp b/stepmania/src/MusicWheel.cpp index e9032a5f1e..669b8cf3c2 100644 --- a/stepmania/src/MusicWheel.cpp +++ b/stepmania/src/MusicWheel.cpp @@ -269,6 +269,17 @@ void MusicWheel::GetSongList(vector &arraySongs, bool bRoulette ) } } +struct CompareSongPointerArrayBySectionName +{ + SongSortOrder so; + CompareSongPointerArrayBySectionName( SongSortOrder so_ ): so(so_) { } + bool operator() (const Song *p1, const Song *p2) const + { + return MusicWheel::GetSectionNameFromSongAndSort( p1, so ) < + MusicWheel::GetSectionNameFromSongAndSort( p2, so ); + } +}; + void MusicWheel::BuildWheelItemDatas( vector &arrayWheelItemDatas, SongSortOrder so ) { unsigned i; @@ -322,7 +333,6 @@ void MusicWheel::BuildWheelItemDatas( vector &arrayWheelItemDatas bool bUseSections = false; switch( so ) { -// case SORT_GROUP_NOHEADER: bUseSections = false; break; case SORT_MOST_PLAYED: bUseSections = false; break; case SORT_BPM: bUseSections = false; break; case SORT_GROUP: bUseSections = GAMESTATE->m_sPreferredGroup == "ALL MUSIC"; break; @@ -336,6 +346,11 @@ void MusicWheel::BuildWheelItemDatas( vector &arrayWheelItemDatas if( bUseSections ) { + /* We're using sections, so use the section name as the top-levle + * sort. */ + stable_sort(arraySongs.begin(), arraySongs.end(), + CompareSongPointerArrayBySectionName(so)); + // make WheelItemDatas with sections CString sLastSection = ""; RageColor colorSection; @@ -347,6 +362,7 @@ void MusicWheel::BuildWheelItemDatas( vector &arrayWheelItemDatas if( GAMESTATE->m_sPreferredGroup != "ALL MUSIC" && pSong->m_sGroupName != GAMESTATE->m_sPreferredGroup ) continue; + if( sThisSection != sLastSection) // new section, make a section item { colorSection = (so==SORT_GROUP) ? SONGMAN->GetGroupColor(pSong->m_sGroupName) : SECTION_COLORS(iSectionColorIndex); @@ -1073,7 +1089,7 @@ void MusicWheel::TweenOffScreen(bool changing_sort) m_fTimeLeftInState = TweenTime() + 0.100f; } -CString MusicWheel::GetSectionNameFromSongAndSort( Song* pSong, SongSortOrder so ) +CString MusicWheel::GetSectionNameFromSongAndSort( const Song* pSong, SongSortOrder so ) { if( pSong == NULL ) return ""; @@ -1093,7 +1109,7 @@ CString MusicWheel::GetSectionNameFromSongAndSort( Song* pSong, SongSortOrder so // sTemp = "NUM"; // return sTemp; case SORT_TITLE: - sTemp = pSong->GetSortTitle(); + sTemp = pSong->GetTranslitSubTitle(); sTemp.MakeUpper(); if(sTemp.empty()) return ""; diff --git a/stepmania/src/MusicWheel.h b/stepmania/src/MusicWheel.h index abc444a1c2..70271337d3 100644 --- a/stepmania/src/MusicWheel.h +++ b/stepmania/src/MusicWheel.h @@ -41,8 +41,12 @@ const ScreenMessage SM_SortOrderChanged = ScreenMessage(SM_User+48); enum { SORT_ROULETTE = NUM_SORT_ORDERS+1 }; +struct CompareSongPointerArrayBySectionName; + class MusicWheel : public ActorFrame { + friend struct CompareSongPointerArrayBySectionName; + public: MusicWheel(); ~MusicWheel(); @@ -76,11 +80,11 @@ public: CString GetSelectedSection(){ return m_CurWheelItemData[m_iSelection]->m_sSectionName; }; bool WheelIsLocked() { return (m_WheelState == STATE_LOCKED ? true : false); } + void RebuildWheelItemDisplays(); protected: void GetSongList(vector &arraySongs, bool bRoulette ); void BuildWheelItemDatas( vector &arrayWheelItems, SongSortOrder so ); - void RebuildWheelItemDisplays(); void SetOpenGroup(CString group, SongSortOrder so = NUM_SORT_ORDERS); bool SelectSong(const Song *p); bool SelectCourse(const Course *p); @@ -128,7 +132,7 @@ protected: RageSound m_soundStart; RageSound m_soundLocked; - CString GetSectionNameFromSongAndSort( Song* pSong, SongSortOrder so ); + static CString GetSectionNameFromSongAndSort( const Song* pSong, SongSortOrder so ); bool WheelItemIsVisible(int n); void UpdateScrollbar(); }; diff --git a/stepmania/src/NotesWriterDWI.cpp b/stepmania/src/NotesWriterDWI.cpp index 0ca9a85271..172c61761a 100644 --- a/stepmania/src/NotesWriterDWI.cpp +++ b/stepmania/src/NotesWriterDWI.cpp @@ -219,14 +219,9 @@ bool NotesWriterDWI::Write( CString sPath, const Song &out ) if( fp == NULL ) RageException::Throw( "Error opening song file '%s' for writing.", sPath.GetString() ); - /* If we have transliterations, write them instead of the real title, since - * DWI doesn't support UTF-8. */ - if(!out.GetSortTitle().empty()) - fprintf( fp, "#TITLE:%s;\n", out.GetSortTitle().GetString() ); - if(!out.m_sArtistTranslit.empty()) - fprintf( fp, "#ARTIST:%s;\n", out.m_sArtistTranslit.GetString() ); - else if(!out.m_sArtist.empty()) - fprintf( fp, "#ARTIST:%s;\n", out.m_sArtist.GetString() ); + /* Write transliterations, if we have them, since DWI doesn't support UTF-8. */ + fprintf( fp, "#TITLE:%s;\n", out.GetTranslitMainTitle().GetString() ); + fprintf( fp, "#ARTIST:%s;\n", out.GetTranslitArtist().GetString() ); ASSERT( out.m_BPMSegments[0].m_fStartBeat == 0 ); fprintf( fp, "#BPM:%.3f;\n", out.m_BPMSegments[0].m_fBPM ); fprintf( fp, "#GAP:%d;\n", int(-roundf( out.m_fBeat0OffsetInSeconds*1000 )) ); diff --git a/stepmania/src/PrefsManager.cpp b/stepmania/src/PrefsManager.cpp index 300a2c7c1f..c4281590a6 100644 --- a/stepmania/src/PrefsManager.cpp +++ b/stepmania/src/PrefsManager.cpp @@ -68,6 +68,7 @@ PrefsManager::PrefsManager() m_bInstructions = true; m_bShowDontDie = true; m_bShowSelectGroup = true; + m_bShowTranslations = true; m_bArcadeOptionsNavigation = false; m_iUnloadTextureDelaySeconds = 0; // disabled 60*30; // 30 mins m_bCoinOpMode = false; @@ -144,6 +145,7 @@ void PrefsManager::ReadGlobalPrefsFromDisk( bool bSwitchToLastPlayedGame ) ini.GetValueB( "Options", "HowToPlay", m_bInstructions ); ini.GetValueB( "Options", "Caution", m_bShowDontDie ); ini.GetValueB( "Options", "SelectGroup", m_bShowSelectGroup ); + ini.GetValueB( "Options", "ShowTranslations", m_bShowTranslations ); ini.GetValueB( "Options", "ArcadeOptionsNavigation", m_bArcadeOptionsNavigation ); ini.GetValue ( "Options", "DWIPath", m_DWIPath ); ini.GetValueI( "Options", "UnloadTextureDelaySeconds", m_iUnloadTextureDelaySeconds ); @@ -216,6 +218,7 @@ void PrefsManager::SaveGlobalPrefsToDisk() ini.SetValueB( "Options", "HowToPlay", m_bInstructions ); ini.SetValueB( "Options", "Caution", m_bShowDontDie ); ini.SetValueB( "Options", "SelectGroup", m_bShowSelectGroup ); + ini.SetValueB( "Options", "ShowTranslations", m_bShowTranslations ); ini.SetValueB( "Options", "ArcadeOptionsNavigation", m_bArcadeOptionsNavigation ); ini.SetValue ( "Options", "DWIPath", m_DWIPath ); ini.SetValueI( "Options", "UnloadTextureDelaySeconds", m_iUnloadTextureDelaySeconds ); diff --git a/stepmania/src/PrefsManager.h b/stepmania/src/PrefsManager.h index 33904f131f..aaf3d766e2 100644 --- a/stepmania/src/PrefsManager.h +++ b/stepmania/src/PrefsManager.h @@ -52,6 +52,7 @@ public: bool m_bAutoPlay; bool m_bDelayedEscape; bool m_bInstructions, m_bShowDontDie, m_bShowSelectGroup; + bool m_bShowTranslations; bool m_bArcadeOptionsNavigation; bool m_bCoinOpMode; enum { NEVER, ALWAYS, ABC_ONLY } m_MusicWheelUsesSections; diff --git a/stepmania/src/ScreenGameplay.cpp b/stepmania/src/ScreenGameplay.cpp index 932dad84a3..db6f892ea0 100644 --- a/stepmania/src/ScreenGameplay.cpp +++ b/stepmania/src/ScreenGameplay.cpp @@ -1129,7 +1129,7 @@ void ShowSavePrompt( ScreenMessage SM_SendWhenDone ) "Would you like to save these changes back\n" "to the song file?\n" "Choosing NO will discard your changes.", - GAMESTATE->m_pCurSong->GetFullTitle().GetString() ); + GAMESTATE->m_pCurSong->GetFullDisplayTitle().GetString() ); break; case PLAY_MODE_NONSTOP: case PLAY_MODE_ONI: diff --git a/stepmania/src/ScreenMusicScroll.cpp b/stepmania/src/ScreenMusicScroll.cpp index 56a712cad6..902b822e56 100644 --- a/stepmania/src/ScreenMusicScroll.cpp +++ b/stepmania/src/ScreenMusicScroll.cpp @@ -159,7 +159,7 @@ ScreenMusicScroll::ScreenMusicScroll() { Song* pSong = arraySongs[i]; m_textLines[m_iNumLines].LoadFromFont( THEME->GetPathTo("Fonts","music scroll") ); - m_textLines[m_iNumLines].SetText( pSong->GetFullTitle() ); + m_textLines[m_iNumLines].SetText( pSong->GetFullDisplayTitle() ); m_textLines[m_iNumLines].SetDiffuse( SONGMAN->GetSongColor(pSong) ); m_textLines[m_iNumLines].SetZoom( TEXT_ZOOM ); diff --git a/stepmania/src/ScreenSelectMusic.cpp b/stepmania/src/ScreenSelectMusic.cpp index e79f6b8c0f..e605cdb78b 100644 --- a/stepmania/src/ScreenSelectMusic.cpp +++ b/stepmania/src/ScreenSelectMusic.cpp @@ -410,6 +410,14 @@ void ScreenSelectMusic::Input( const DeviceInput& DeviceI, InputEventType type, { LOG->Trace( "ScreenSelectMusic::Input()" ); + if( DeviceI.device == DEVICE_KEYBOARD && DeviceI.button == SDLK_F9 ) + { + if( type != IET_FIRST_PRESS ) return; + PREFSMAN->m_bShowTranslations ^= 1; + m_MusicWheel.RebuildWheelItemDisplays(); + return; + } + if( MenuI.button == MENU_BUTTON_RIGHT || MenuI.button == MENU_BUTTON_LEFT ) { if( !MenuI.IsValid() ) return; diff --git a/stepmania/src/Song.cpp b/stepmania/src/Song.cpp index e75371c938..ecdcf2a6fd 100644 --- a/stepmania/src/Song.cpp +++ b/stepmania/src/Song.cpp @@ -857,8 +857,8 @@ bool Song::HasEdits( NotesType nt ) const int CompareSongPointersByTitle(const Song *pSong1, const Song *pSong2) { //Prefer transliterations to full titles - CString sTitle1 = pSong1->GetSortTitle(); - CString sTitle2 = pSong2->GetSortTitle(); + CString sTitle1 = pSong1->GetFullTranslitTitle(); + CString sTitle2 = pSong2->GetFullTranslitTitle(); int ret = sTitle1.CompareNoCase(sTitle2); if(ret < 0) return true; @@ -1078,19 +1078,40 @@ CString Song::GetBackgroundPath() const return m_sSongDir+m_sBackgroundFile; } -CString Song::GetSortTitle() const +CString Song::GetDisplayMainTitle() const { - CString Title = m_sMainTitleTranslit.empty()? - m_sMainTitle: m_sMainTitleTranslit; + if(!PREFSMAN->m_bShowTranslations) return GetTranslitMainTitle(); + return m_sMainTitle; +} - CString SubTitle = m_sSubTitleTranslit.empty()? - m_sSubTitle:m_sSubTitleTranslit; +CString Song::GetDisplaySubTitle() const +{ + if(!PREFSMAN->m_bShowTranslations) return GetTranslitSubTitle(); + return m_sSubTitle; +} - if(!SubTitle.empty()) - { - Title += " " + SubTitle; - } +CString Song::GetDisplayArtist() const +{ + if(!PREFSMAN->m_bShowTranslations) return GetTranslitArtist(); + return m_sArtist; +} + +CString Song::GetFullDisplayTitle() const +{ + CString Title = GetDisplayMainTitle(); + CString SubTitle = GetDisplaySubTitle(); + + if(!SubTitle.empty()) Title += " " + SubTitle; + return Title; +} + +CString Song::GetFullTranslitTitle() const +{ + CString Title = GetTranslitMainTitle(); + CString SubTitle = GetTranslitSubTitle(); + + if(!SubTitle.empty()) Title += " " + SubTitle; return Title; } diff --git a/stepmania/src/TextBanner.cpp b/stepmania/src/TextBanner.cpp index e12d063ba5..eb6f9dfd37 100644 --- a/stepmania/src/TextBanner.cpp +++ b/stepmania/src/TextBanner.cpp @@ -99,9 +99,9 @@ bool TextBanner::LoadFromSong( const Song* pSong ) return true; } - m_textTitle.SetText( pSong->m_sMainTitle ); - m_textSubTitle.SetText( pSong->m_sSubTitle ); - m_textArtist.SetText( g_sArtistPrependString + pSong->m_sArtist ); + m_textTitle.SetText( pSong->GetDisplayMainTitle() ); + m_textSubTitle.SetText( pSong->GetDisplaySubTitle() ); + m_textArtist.SetText( g_sArtistPrependString + pSong->GetDisplayArtist() ); bool bTwoLines = pSong->m_sSubTitle.length() == 0; diff --git a/stepmania/src/TransitionOniFade.cpp b/stepmania/src/TransitionOniFade.cpp index 164230ba84..f0df4d0a75 100644 --- a/stepmania/src/TransitionOniFade.cpp +++ b/stepmania/src/TransitionOniFade.cpp @@ -104,6 +104,6 @@ void TransitionOniFade::UpdateSongText() { Song* pSong = GAMESTATE->m_pCurSong; ASSERT( pSong ); - m_textSongInfo.SetText( pSong->GetFullTitle() + "\n" + pSong->m_sArtist + "\n"); + m_textSongInfo.SetText( pSong->GetFullDisplayTitle() + "\n" + pSong->m_sArtist + "\n"); m_Banner.LoadFromSong( pSong ); } diff --git a/stepmania/src/song.h b/stepmania/src/song.h index ac883fb8e6..2f47f495e7 100644 --- a/stepmania/src/song.h +++ b/stepmania/src/song.h @@ -94,17 +94,27 @@ public: bool m_bChangedSinceSave; - CString m_sMainTitle; - CString m_sSubTitle; - CString m_sArtist; - CString m_sMainTitleTranslit; - CString m_sSubTitleTranslit; - CString m_sArtistTranslit; + CString m_sMainTitle, m_sSubTitle, m_sArtist; + CString m_sMainTitleTranslit, m_sSubTitleTranslit, m_sArtistTranslit; + + /* If PREFSMAN->m_bShowTranslations is off, these are the same as GetTranslit* below. + * Otherwise, they return the main titles. */ + CString GetDisplayMainTitle() const; + CString GetDisplaySubTitle() const; + CString GetDisplayArtist() const; + + /* Returns the transliterated titles, if any; otherwise returns the main titles. */ + CString GetTranslitMainTitle() const { return m_sMainTitleTranslit.size()? m_sMainTitleTranslit: m_sMainTitle; } + CString GetTranslitSubTitle() const { return m_sSubTitleTranslit.size()? m_sSubTitleTranslit: m_sSubTitle; } + CString GetTranslitArtist() const { return m_sArtistTranslit.size()? m_sArtistTranslit:m_sArtist; } + + /* "title subtitle" */ + CString GetFullDisplayTitle() const; + CString GetFullTranslitTitle() const; + + /* This is read and saved, but never actually used. */ CString m_sCredit; - CString GetFullTitle() const { return m_sMainTitle + (m_sSubTitle.GetLength()? (" " + m_sSubTitle):""); } - CString GetSortTitle() const; - CString m_sMusicFile; unsigned m_iMusicBytes; float m_fBeat0OffsetInSeconds;