From 044ac127da54bc51060eb64f3fba95f77a8c5968 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Wed, 6 Mar 2002 08:25:09 +0000 Subject: [PATCH] no message --- stepmania/src/Banner.cpp | 24 +++++-- stepmania/src/Banner.h | 4 +- stepmania/src/BitmapText.cpp | 8 +-- stepmania/src/MusicWheel.cpp | 20 +++++- stepmania/src/MusicWheel.h | 1 + stepmania/src/RageUtil.cpp | 63 +++++++--------- stepmania/src/RageUtil.h | 38 +++------- stepmania/src/Song.cpp | 4 -- stepmania/src/SongManager.cpp | 131 ++++++++++++++++++++++------------ stepmania/src/SongManager.h | 8 +++ stepmania/src/StepMania.RC | 67 +++++++++++++---- stepmania/src/StepMania.cpp | 19 ++--- stepmania/src/resource.h | 3 +- 13 files changed, 236 insertions(+), 154 deletions(-) diff --git a/stepmania/src/Banner.cpp b/stepmania/src/Banner.cpp index 4ad8b76592..35cf72a757 100644 --- a/stepmania/src/Banner.cpp +++ b/stepmania/src/Banner.cpp @@ -19,11 +19,24 @@ bool Banner::LoadFromSong( Song* pSong ) // NULL means no song { - if( pSong == NULL ) Sprite::Load( THEME->GetPathTo(GRAPHIC_FALLBACK_BANNER), HINT_NOMIPMAPS ); - else if( pSong->HasBanner() ) Sprite::Load( pSong->GetBannerPath(), HINT_NOMIPMAPS ); - else if( pSong->HasBackground() ) Sprite::Load( pSong->GetBackgroundPath(), HINT_NOMIPMAPS ); - else Sprite::Load( THEME->GetPathTo(GRAPHIC_FALLBACK_BANNER), HINT_NOMIPMAPS ); + if( pSong == NULL ) Banner::Load( THEME->GetPathTo(GRAPHIC_FALLBACK_BANNER), HINT_NOMIPMAPS ); + else if( pSong->HasBanner() ) Banner::Load( pSong->GetBannerPath(), HINT_NOMIPMAPS ); + else if( pSong->HasBackground() ) Banner::Load( pSong->GetBackgroundPath(), HINT_NOMIPMAPS ); + else Banner::Load( THEME->GetPathTo(GRAPHIC_FALLBACK_BANNER), HINT_NOMIPMAPS ); + return true; +} + +bool Banner::Load( CString sFilePath, DWORD dwHints, bool bForceReload ) +{ + Sprite::Load( sFilePath, dwHints, bForceReload ); + CropToRightSize(); + + return true; +} + +void Banner::CropToRightSize() +{ Sprite::TurnShadowOff(); int iImageWidth = m_pTexture->GetImageWidth(); @@ -93,7 +106,4 @@ bool Banner::LoadFromSong( Song* pSong ) // NULL means no song // restore original XY SetXY( fOriginalX, fOriginalY ); - - - return true; } diff --git a/stepmania/src/Banner.h b/stepmania/src/Banner.h index 8e7affaf04..4fa9061376 100644 --- a/stepmania/src/Banner.h +++ b/stepmania/src/Banner.h @@ -23,9 +23,11 @@ const float BANNER_HEIGHT = 86; class Banner : public Sprite { public: - bool LoadFromSong( Song* pSong ); // NULL means no Song + virtual bool Load( CString sFilePath, DWORD dwHints = 0, bool bForceReload = false ); +protected: + void CropToRightSize(); }; diff --git a/stepmania/src/BitmapText.cpp b/stepmania/src/BitmapText.cpp index 97bfd47118..f3196f59b0 100644 --- a/stepmania/src/BitmapText.cpp +++ b/stepmania/src/BitmapText.cpp @@ -213,12 +213,12 @@ void BitmapText::RebuildVertexBuffer() m_iNumV = 0; // the current vertex number float fHeight = GetUnzoomedHeight(); - float fY; + float fY; // the center of the first line switch( m_VertAlign ) { - case align_top: fY = -(m_sTextLines.GetSize()) * fHeight / 2; break; - case align_middle: fY = 0; break; - case align_bottom: fY = (m_sTextLines.GetSize()) * fHeight / 2; break; + case align_top: fY = -(m_sTextLines.GetSize()-1) * fHeight; break; + case align_middle: fY = -(m_sTextLines.GetSize()-1) * fHeight / 2; break; + case align_bottom: fY = 0; break; default: ASSERT( false ); } diff --git a/stepmania/src/MusicWheel.cpp b/stepmania/src/MusicWheel.cpp index e1dbe2f9c7..d9678468f7 100644 --- a/stepmania/src/MusicWheel.cpp +++ b/stepmania/src/MusicWheel.cpp @@ -89,8 +89,9 @@ WheelItemDisplay::WheelItemDisplay() m_textSectionName.Load( THEME->GetPathTo(FONT_OUTLINE) ); m_textSectionName.TurnShadowOff(); - m_textSectionName.SetHorizAlign( align_left ); - m_textSectionName.SetXY( -85, 0 ); + m_textSectionName.SetHorizAlign( align_center ); + m_textSectionName.SetVertAlign( align_middle ); + m_textSectionName.SetXY( m_sprSectionBackground.GetX(), 0 ); m_textSectionName.SetZoom( 1.5f ); m_textSectionName.SetDiffuseColor( COLOR_SECTION_LETTER ); } @@ -114,7 +115,20 @@ void WheelItemDisplay::LoadFromWheelItemData( WheelItemData* pWID ) { case TYPE_SECTION: - m_textSectionName.SetText( m_sSectionName ); + if( m_sSectionName.GetLength() > 15 && + -1 != m_sSectionName.Find(' ', m_sSectionName.GetLength()/3) ) // this is space in the name + { + int iIndexSplit = m_sSectionName.Find( ' ', m_sSectionName.GetLength()/3 ); + m_sSectionName.SetAt( iIndexSplit, '\n' ); + + m_textSectionName.SetZoom( 0.75f ); + m_textSectionName.SetText( m_sSectionName ); + } + else // this is a short name + { + m_textSectionName.SetZoom( 1.5f ); + m_textSectionName.SetText( m_sSectionName ); + } m_sprSectionBackground.SetDiffuseColor( m_colorTint ); break; case TYPE_MUSIC: diff --git a/stepmania/src/MusicWheel.h b/stepmania/src/MusicWheel.h index c8fce5aaac..77ae2c293d 100644 --- a/stepmania/src/MusicWheel.h +++ b/stepmania/src/MusicWheel.h @@ -107,6 +107,7 @@ public: bool Select(); // return true if the selected item is a music, otherwise false Song* GetSelectedSong() { return GetCurWheelItemDatas()[m_iSelection].m_pSong; }; + CString GetSelectedSection() { return GetCurWheelItemDatas()[m_iSelection].m_sSectionName; }; protected: diff --git a/stepmania/src/RageUtil.cpp b/stepmania/src/RageUtil.cpp index 6f9150b48f..f3dc0b9174 100644 --- a/stepmania/src/RageUtil.cpp +++ b/stepmania/src/RageUtil.cpp @@ -291,29 +291,28 @@ void splitrelpath( CString Path, CString& Dir, CString& FName, CString& Ext ) } -void GetDirListing( CString sPath, CStringArray &AddTo, BOOL bOnlyDirs ) +void GetDirListing( CString sPath, CStringArray &AddTo, bool bOnlyDirs ) { WIN32_FIND_DATA fd; HANDLE hFind = ::FindFirstFile( sPath, &fd ); - if( INVALID_HANDLE_VALUE != hFind ) + if( INVALID_HANDLE_VALUE == hFind ) // no files found + return; + + do { - do - { - if( bOnlyDirs && !(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ) - { - ; // do nothing - } - else - { - // add it - CString sDirName( fd.cFileName ); - if( sDirName != "." && sDirName != ".." ) - AddTo.Add( sDirName ); - } - } while( ::FindNextFile( hFind, &fd ) ); - ::FindClose( hFind ); - } + if( bOnlyDirs && !(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ) + continue; // skip + + CString sDirName( fd.cFileName ); + + if( sDirName == "." || sDirName == ".." ) + continue; + + AddTo.Add( sDirName ); + + } while( ::FindNextFile( hFind, &fd ) ); + ::FindClose( hFind ); } DWORD GetFileSizeInBytes( CString sFilePath ) @@ -363,34 +362,20 @@ void SortCStringArray( CStringArray &arrayCStrings, BOOL bSortAcsending ) VOID DisplayErrorAndDie( CString sError ) { - /* - //////////////////////// - // get a stack trace - //////////////////////// - AfxDumpStack( AFX_STACK_DUMP_TARGET_CLIPBOARD ); - - //open the clipboard - CString fromClipboard; - if( OpenClipboard(NULL) ) - { - HANDLE hData = GetClipboardData( CF_TEXT ); - char *buffer = (char*)GlobalLock( hData ); - fromClipboard = buffer; - GlobalUnlock( hData ); - CloseClipboard(); - } - sError += "\n\n" + fromClipboard; - */ -#ifdef DEBUG // don't use error handler in Release mode +#ifdef DEBUG + // display a message box, then break so we can see a stack trace in the debugger AfxMessageBox( sError ); AfxDebugBreak(); exit(1); -#else + +#else // RELEASE + // write the error to a file so our pretty error dialog can display what happened. FILE* fp = fopen( g_sErrorFileName, "w" ); fprintf( fp, sError ); fclose( fp ); // generate an exception so the error handler shows throw(1); + #endif } @@ -446,3 +431,5 @@ HINSTANCE GotoURL(LPCTSTR url) return result; } + + diff --git a/stepmania/src/RageUtil.h b/stepmania/src/RageUtil.h index a4d1ed12d7..8192cd507f 100644 --- a/stepmania/src/RageUtil.h +++ b/stepmania/src/RageUtil.h @@ -61,41 +61,21 @@ CString ssprintf( LPCTSTR fmt, ...); CString vssprintf( LPCTSTR fmt, va_list argList ); -/* - @FUNCTION: Splits a Path into 4 parts (Directory, Drive, Filename, Extention). - NOTE: Supports UNC path names. - @PARAM1: Whether the Supplied Path (PARAM2) contains a directory name only - or a file name (Reason: some directories will end with "xxx.xxx" - which is like a file name). - @PARAM2: Path to Split. - @PARAM3: (Referenced) Directory. - @PARAM4: (Referenced) Drive. - @PARAM5: (Referenced) Filename. - @PARAM6: (Referenced) Extention. -*/ +// Splits a Path into 4 parts (Directory, Drive, Filename, Extention). Supports UNC path names. +// param1: Whether the Supplied Path (PARAM2) contains a directory name only +// or a file name (Reason: some directories will end with "xxx.xxx" +// which is like a file name). void splitpath(BOOL UsingDirsOnly, CString Path, CString& Drive, CString& Dir, CString& FName, CString& Ext); - void splitrelpath( CString Path, CString& Dir, CString& FName, CString& Ext ); - -/* - @FUNCTION: Splits a CString into an CStringArray according the Deliminator. - NOTE: Supports UNC path names. - @PARAM1: Source string to be Split. - @PARAM2: Deliminator. - @PARAM3: (Referenced) CStringArray to Add to. -*/ +// Splits a CString into an CStringArray according the Deliminator. Supports UNC path names. void split(CString Source, CString Deliminator, CStringArray& AddIt, bool bIgnoreEmpty = true ); -/* - @FUNCTION: Joins a CStringArray to create a CString according the Deliminator. - @PARAM1: Deliminator. - @PARAM2: (Referenced) CStringArray to Add to. -*/ +// Joins a CStringArray to create a CString according the Deliminator. CString join(CString Deliminator, CStringArray& Source); -void GetDirListing( CString sPath, CStringArray &AddTo, BOOL bOnlyDirs=FALSE ); +void GetDirListing( CString sPath, CStringArray &AddTo, bool bOnlyDirs=false ); bool DoesFileExist( CString sPath ); DWORD GetFileSizeInBytes( CString sFilePath ); @@ -113,13 +93,13 @@ void RageLogHr( HRESULT hr, LPCTSTR fmt, ...); //----------------------------------------------------------------------------- // Error helpers //----------------------------------------------------------------------------- -VOID DisplayErrorAndDie( CString sError ); - +void DisplayErrorAndDie( CString sError ); #define RageError(str) DisplayErrorAndDie( ssprintf( "%s\n\n%s(%d)", str, __FILE__, (DWORD)__LINE__) ) #define RageErrorHr(str,hr) DisplayErrorAndDie( ssprintf("%s (%s)\n\n%s(%d)", str, DXGetErrorString8(hr), __FILE__, (DWORD)__LINE__) ) + LONG GetRegKey(HKEY key, LPCTSTR subkey, LPTSTR retdata); HINSTANCE GotoURL(LPCTSTR url); diff --git a/stepmania/src/Song.cpp b/stepmania/src/Song.cpp index 80da9a7ef3..31a635f795 100644 --- a/stepmania/src/Song.cpp +++ b/stepmania/src/Song.cpp @@ -190,11 +190,7 @@ bool Song::LoadFromSongDir( CString sDir ) RageError( ssprintf("Couldn't find any BMS or MSD files in '%s'", sDir) ); } - RageLog( "m_fOffsetInSeconds is %f", m_fOffsetInSeconds ); - - return TRUE; - } diff --git a/stepmania/src/SongManager.cpp b/stepmania/src/SongManager.cpp index feb329a106..a2b388860d 100644 --- a/stepmania/src/SongManager.cpp +++ b/stepmania/src/SongManager.cpp @@ -40,9 +40,75 @@ SongManager::~SongManager() void SongManager::InitSongArrayFromDisk() { - ///////////////////////////// - // Handle DWI support - ///////////////////////////// + LoadStepManiaSongDir( "Songs" ); + LoadDWISongDir( "DWI Support" ); + RageLog( "Found %d Songs.", m_pSongs.GetSize() ); +} + +void SongManager::LoadStepManiaSongDir( CString sDir ) +{ + // trim off the trailing slash if any + sDir.TrimRight( "/\\" ); + + // Find all group directories in "Songs" folder + CStringArray arrayGroupDirs; + GetDirListing( sDir+"\\*.*", arrayGroupDirs, true ); + SortCStringArray( arrayGroupDirs ); + + for( int i=0; i< arrayGroupDirs.GetSize(); i++ ) // for each dir in /Songs/ + { + CString sGroupDirName = arrayGroupDirs[i]; + + if( 0 == stricmp( sGroupDirName, "cvs" ) ) // the directory called "CVS" + continue; // ignore it + + // Check to see if they put a song directly inside of the group folder + CStringArray arrayFiles; + GetDirListing( ssprintf("%s\\%s\\*.mp3", sDir, sGroupDirName), arrayFiles ); + GetDirListing( ssprintf("%s\\%s\\*.wav", sDir, sGroupDirName), arrayFiles ); + if( arrayFiles.GetSize() > 0 ) + RageError( + ssprintf( "The song folder '%s' must be placed inside of a group folder.\n\n" + "All song folders must be placed below a group folder. For example, 'Songs\\DDR 4th Mix\\B4U'. See the StepMania readme for more info.", + ssprintf("%s\\%s", sDir, sGroupDirName ) ) + ); + + // Look for a group banner in this group folder + CStringArray arrayGroupBanners; + GetDirListing( ssprintf("%s\\%s\\*.png", sDir, sGroupDirName), arrayGroupBanners ); + GetDirListing( ssprintf("%s\\%s\\*.jpg", sDir, sGroupDirName), arrayGroupBanners ); + GetDirListing( ssprintf("%s\\%s\\*.gif", sDir, sGroupDirName), arrayGroupBanners ); + GetDirListing( ssprintf("%s\\%s\\*.bmp", sDir, sGroupDirName), arrayGroupBanners ); + if( arrayGroupBanners.GetSize() > 0 ) + { + m_mapGroupToBannerPath[sGroupDirName] = ssprintf("%s\\%s\\%s", sDir, sGroupDirName, arrayGroupBanners[0] ); + RageLog( ssprintf("Group banner for '%s' is '%s'.", sGroupDirName, m_mapGroupToBannerPath[sGroupDirName]) ); + } + + // Find all Song folders in this group directory + CStringArray arraySongDirs; + GetDirListing( ssprintf("%s\\%s\\*.*", sDir, sGroupDirName), arraySongDirs, true ); + SortCStringArray( arraySongDirs ); + + for( int j=0; j< arraySongDirs.GetSize(); j++ ) // for each song dir + { + CString sSongDirName = arraySongDirs[j]; + + if( 0 == stricmp( sSongDirName, "cvs" ) ) // the directory called "CVS" + continue; // ignore it + + // this is a song directory. Load a new song! + Song* pNewSong = new Song; + pNewSong->LoadFromSongDir( ssprintf("%s\\%s\\%s", sDir, sGroupDirName, sSongDirName) ); + m_pSongs.Add( pNewSong ); + } + } +} + +void SongManager::LoadDWISongDir( CString sDir ) +{ + // trim off the trailing slash if any + sDir.TrimRight( "/\\" ); // Find all directories in "DWIs" folder CStringArray arrayDirs; @@ -72,51 +138,10 @@ void SongManager::InitSongArrayFromDisk() m_pSongs.Add( pNewSong ); } } - - - ///////////////////////////// - // Load songs from StepMania's directory structure in Songs - ///////////////////////////// - - // Find all group directories in "Songs" folder - CStringArray arrayGroupDirs; - GetDirListing( "Songs\\*.*", arrayGroupDirs, true ); - SortCStringArray( arrayGroupDirs ); - - for( i=0; i< arrayGroupDirs.GetSize(); i++ ) // for each dir in /Songs/ - { - CString sGroupDirName = arrayGroupDirs[i]; - sGroupDirName.MakeLower(); - - if( sGroupDirName == "cvs" ) // ignore the directory called "CVS" - continue; - - // Find all Song folders in this group directory - CStringArray arraySongDirs; - GetDirListing( ssprintf("Songs\\%s\\*.*", sGroupDirName, true), arraySongDirs ); - SortCStringArray( arraySongDirs ); - - for( int j=0; j< arraySongDirs.GetSize(); j++ ) // for each song dir - { - CString sSongDirName = arraySongDirs[j]; - sSongDirName.MakeLower(); - - if( sSongDirName == "cvs" ) // ignore the directory called "CVS" - continue; - - // load DWIs from the sub dirs - Song* pNewSong = new Song; - pNewSong->LoadFromSongDir( ssprintf("Songs\\%s\\%s", sGroupDirName, sSongDirName) ); - m_pSongs.Add( pNewSong ); - } - } - - - - RageLog( "Found %d Songs.", m_pSongs.GetSize() ); } + void SongManager::CleanUpSongArray() { for( int i=0; i //----------------------------------------------------------------------------- // Links @@ -86,6 +87,7 @@ BOOL SwitchDisplayMode();// BOOL bWindowed, DWORD dwWidth, DWORD dwHeight, DWORD //----------------------------------------------------------------------------- int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow ) { + AfxEnableControlContainer(); #ifndef DEBUG // don't use error handler in Release mode try @@ -198,14 +200,17 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow ) UnregisterClass( g_sAppClassName, hInstance ); CoUninitialize(); // Uninitialize COM -#ifndef DEBUG // don't use error handler in Release mode - } + + +#ifndef DEBUG // only use pretty error handler in RELEASE build + } catch(...) // catch all exceptions { CloseHandle( g_hMutex ); DestroyObjects(); // deallocate our game objects and leave fullscreen ShowWindow( g_hWndMain, SW_HIDE ); + // throw up a pretty error dialog DialogBox( hInstance, MAKEINTRESOURCE(IDD_ERROR_DIALOG), @@ -213,13 +218,11 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow ) ErrorWndProc ); exit( 1 ); - - DestroyWindow( g_hWndMain ); - UnregisterClass( g_sAppClassName, hInstance ); - CoUninitialize(); // Uninitialize COM } #endif + + return 0L; } @@ -352,7 +355,7 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) case WM_SETCURSOR: // Turn off Windows cursor in fullscreen mode - if( !SCREEN->IsWindowed() ) + if( SCREEN && !SCREEN->IsWindowed() ) { SetCursor( NULL ); return TRUE; // prevent Windows from setting the cursor @@ -411,7 +414,7 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) } case WM_NCHITTEST: // Prevent the user from selecting the menu in fullscreen mode - if( !SCREEN->IsWindowed() ) + if( SCREEN && !SCREEN->IsWindowed() ) return HTCLIENT; break; diff --git a/stepmania/src/resource.h b/stepmania/src/resource.h index 7eca2d5a3a..5175e0de8b 100644 --- a/stepmania/src/resource.h +++ b/stepmania/src/resource.h @@ -4,6 +4,7 @@ // #define IDD_ERROR_DIALOG 111 #define BITMAP_ERROR 129 +#define IDC_SHOCKWAVEFLASH1 1000 #define IDR_MAIN_ACCEL 1001 #define IDC_BUTTON_RESTART 1001 #define IDM_TOGGLEFULLSCREEN 1002 @@ -22,7 +23,7 @@ // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 112 +#define _APS_NEXT_RESOURCE_VALUE 113 #define _APS_NEXT_COMMAND_VALUE 40009 #define _APS_NEXT_CONTROL_VALUE 1009 #define _APS_NEXT_SYMED_VALUE 101