CString Character::GetStageIconPath() const { CStringArray as; // first try and find an icon specific to the select music screen // so you can have different icons for music select / char select GetDirListing( m_sCharDir+"stageicon.png", as, false, true ); GetDirListing( m_sCharDir+"stageicon.jpg", as, false, true ); GetDirListing( m_sCharDir+"stageicon.gif", as, false, true ); GetDirListing( m_sCharDir+"stageicon.bmp", as, false, true ); if( as.empty() ) { // if that failed, try using the regular icon GetDirListing( m_sCharDir+"card.png", as, false, true ); GetDirListing( m_sCharDir+"card.jpg", as, false, true ); GetDirListing( m_sCharDir+"card.gif", as, false, true ); GetDirListing( m_sCharDir+"card.bmp", as, false, true ); if( as.empty() ) return ""; else return as[0]; } else return as[0]; }
bool KSFLoader::LoadFromDir( CString sDir, Song &out ) { LOG->Trace( "Song::LoadFromKSFDir(%s)", sDir.c_str() ); CStringArray arrayKSFFileNames; GetDirListing( sDir + CString("*.ksf"), arrayKSFFileNames ); /* We shouldn't have been called to begin with if there were no KSFs. */ if( arrayKSFFileNames.empty() ) RageException::Throw( "Couldn't find any KSF files in '%s'", sDir.c_str() ); if(!LoadGlobalData(out.GetSongDir() + arrayKSFFileNames[0], out)) return false; // load the Steps from the rest of the KSF files for( unsigned i=0; i<arrayKSFFileNames.size(); i++ ) { Steps* pNewNotes = new Steps; if(!LoadFromKSFFile( out.GetSongDir() + arrayKSFFileNames[i], *pNewNotes, out )) { delete pNewNotes; continue; } out.AddSteps( pNewNotes ); } return true; }
CString GetRandomFileInDir( CString sDir ) { CStringArray asFiles; GetDirListing( sDir, asFiles, false, true ); if( asFiles.empty() ) return ""; else return asFiles[rand()%asFiles.size()]; }
CString Character::GetTakingABreakPath() const { CStringArray as; GetDirListing( m_sCharDir+"break.png", as, false, true ); GetDirListing( m_sCharDir+"break.jpg", as, false, true ); GetDirListing( m_sCharDir+"break.gif", as, false, true ); GetDirListing( m_sCharDir+"break.bmp", as, false, true ); if( as.empty() ) return ""; else return as[0]; }
CString Character::GetIconPath() const { CStringArray as; GetDirListing( m_sCharDir+"icon.png", as, false, true ); GetDirListing( m_sCharDir+"icon.jpg", as, false, true ); GetDirListing( m_sCharDir+"icon.gif", as, false, true ); GetDirListing( m_sCharDir+"icon.bmp", as, false, true ); if( as.empty() ) return ""; else return as[0]; }
CString join( const CString &Deliminator, const CStringArray& Source) { if( Source.empty() ) return ""; CString csTmp; // Loop through the Array and Append the Deliminator for( unsigned iNum = 0; iNum < Source.size()-1; iNum++ ) { csTmp += Source[iNum]; csTmp += Deliminator; } csTmp += Source.back(); return csTmp; }
static void DoPlayOnceFromDir( CString sPath ) { if( sPath == "" ) return; // make sure there's a slash at the end of this path if( sPath.Right(1) != "/" ) sPath += "/"; CStringArray arraySoundFiles; GetDirListing( sPath + "*.mp3", arraySoundFiles ); GetDirListing( sPath + "*.wav", arraySoundFiles ); GetDirListing( sPath + "*.ogg", arraySoundFiles ); if( arraySoundFiles.empty() ) return; int index = rand() % arraySoundFiles.size(); SOUNDMAN->PlayOnce( sPath + arraySoundFiles[index] ); }
void ScreenOptionsMaster::Init() { ScreenOptions::Init(); // make sure volume is set to full in options, and menu lights are on ScreenAttract::SetAttractVolume( false ); LIGHTSMAN->SetLightsMode( LIGHTSMODE_MENU ); CStringArray asLineNames; split( LINE_NAMES, ",", asLineNames ); if( asLineNames.empty() ) RageException::Throw( "%s::LineNames is empty.", m_sName.c_str() ); CStringArray Flags; split( OPTION_MENU_FLAGS, ";", Flags, true ); InputMode im = INPUTMODE_INDIVIDUAL; for( unsigned i = 0; i < Flags.size(); ++i ) { CString sFlag = Flags[i]; sFlag.MakeLower(); if( sFlag == "together" ) im = INPUTMODE_SHARE_CURSOR; else if( sFlag == "explanations" ) ; else if( sFlag == "forceallplayers" ) { FOREACH_PlayerNumber( pn ) GAMESTATE->m_bSideIsJoined[pn] = true; GAMESTATE->m_MasterPlayerNumber = PlayerNumber(0); } else if( sFlag == "smnavigation" ) SetNavigation( NAV_THREE_KEY_MENU ); else if( sFlag == "toggle" || sFlag == "firstchoicegoesdown" ) SetNavigation( PREFSMAN->m_bArcadeOptionsNavigation? NAV_TOGGLE_THREE_KEY:NAV_TOGGLE_FIVE_KEY ); else RageException::Throw( "Unknown flag \"%s\"", sFlag.c_str() ); } vector<OptionRowDefinition> OptionRowDefs; OptionRowDefs.resize( asLineNames.size() ); OptionRowHandlers.resize( asLineNames.size() ); for( unsigned i = 0; i < asLineNames.size(); ++i ) { CString sLineName = asLineNames[i]; OptionRowDefinition &def = OptionRowDefs[i]; CString sRowCommands = LINE(sLineName); OptionRowHandler* &pHand = OptionRowHandlers[i]; pHand = NULL; Commands vCommands; ParseCommands( sRowCommands, vCommands ); if( vCommands.v.size() != 1 ) RageException::Throw( "Parse error in %s::Line%s", m_sName.c_str(), sLineName.c_str() ); Command& command = vCommands.v[0]; pHand = OptionRowHandlerUtil::Make( command, def ); if( pHand == NULL ) RageException::Throw( "Invalid OptionRowHandler '%s' in %s::%s", command.GetOriginalCommandString().c_str(), m_sName.c_str(), sLineName.c_str() ); } ASSERT( OptionRowHandlers.size() == asLineNames.size() ); InitMenu( im, OptionRowDefs, OptionRowHandlers ); }
RageDisplay *CreateDisplay() { /* We never want to bother users with having to decide which API to use. * * Some cards simply are too troublesome with OpenGL to ever use it, eg. Voodoos. * If D3D8 isn't installed on those, complain and refuse to run (by default). * For others, always use OpenGL. Allow forcing to D3D as an advanced option. * * If we're missing acceleration when we load D3D8 due to a card being in the * D3D list, it means we need drivers and that they do exist. * * If we try to load OpenGL and we're missing acceleration, it may mean: * 1. We're missing drivers, and they just need upgrading. * 2. The card doesn't have drivers, and it should be using D3D8. In other words, * it needs an entry in this table. * 3. The card doesn't have drivers for either. (Sorry, no S3 868s.) Can't play. * * In this case, fail to load; don't silently fall back on D3D. We don't want * people unknowingly using D3D8 with old drivers (and reporting obscure bugs * due to driver problems). We'll probably get bug reports for all three types. * #2 is the only case that's actually a bug. * * Actually, right now we're falling back. I'm not sure which behavior is better. */ CheckVideoDefaultSettings(); RageDisplay::VideoModeParams params(GetCurVideoModeParams()); CString error = "There was an error while initializing your video card.\n\n" " PLEASE DO NOT FILE THIS ERROR AS A BUG!\n\n" "Video Driver: "+GetVideoDriverName()+"\n\n"; CStringArray asRenderers; split( PREFSMAN->m_sVideoRenderers, ",", asRenderers, true ); if( asRenderers.empty() ) RageException::Throw("No video renderers attempted."); for( unsigned i=0; i<asRenderers.size(); i++ ) { CString sRenderer = asRenderers[i]; if( sRenderer.CompareNoCase("opengl")==0 ) { #if defined(SUPPORT_OPENGL) error += "Initializing OpenGL...\n"; try { return new RageDisplay_OGL( params, PREFSMAN->m_bAllowUnacceleratedRenderer ); } catch(RageException e) { error += CString(e.what()) + "\n"; continue; }; #endif } else if( sRenderer.CompareNoCase("d3d")==0 ) { #if defined(SUPPORT_D3D) error += "Initializing Direct3D...\n"; try { return new RageDisplay_D3D( params ); } catch( const exception &e ) { error += CString(e.what()) + "\n"; }; #endif } else if( sRenderer.CompareNoCase("null")==0 ) return new RageDisplay_Null( params ); else RageException::Throw("Unknown video renderer value: %s", sRenderer.c_str() ); } RageException::Throw( error ); }
bool KSFLoader::LoadGlobalData( const CString &sPath, Song &out ) { MsdFile msd; if( !msd.ReadFile( sPath ) ) RageException::Throw( "Error opening file \"%s\": %s", sPath.c_str(), msd.GetError().c_str() ); float BPMPos2 = -1, BPM2 = -1, BPMPos3 = -1, BPM3 = -1;; for( unsigned i=0; i < msd.GetNumValues(); i++ ) { const MsdFile::value_t &sParams = msd.GetValue(i); CString sValueName = sParams[0]; // handle the data if( 0==stricmp(sValueName,"TITLE") ) LoadTags(sParams[1], out); else if( 0==stricmp(sValueName,"BPM") ) out.AddBPMSegment( BPMSegment(0, strtof(sParams[1], NULL)) ); else if( 0==stricmp(sValueName,"BPM2") ) BPM2 = strtof( sParams[1], NULL ); else if( 0==stricmp(sValueName,"BPM3") ) BPM3 = strtof( sParams[1], NULL ); else if( 0==stricmp(sValueName,"BUNKI") ) BPMPos2 = strtof( sParams[1], NULL ) / 100.0f; else if( 0==stricmp(sValueName,"BUNKI2") ) BPMPos3 = strtof( sParams[1], NULL ) / 100.0f; else if( 0==stricmp(sValueName,"STARTTIME") ) out.m_Timing.m_fBeat0OffsetInSeconds = -strtof( sParams[1], NULL )/100; else if( 0==stricmp(sValueName,"TICKCOUNT") || 0==stricmp(sValueName,"STEP") || 0==stricmp(sValueName,"DIFFICULTY")) ; /* Handled in LoadFromKSFFile; don't warn. */ else LOG->Trace( "Unexpected value named '%s'", sValueName.c_str() ); } /* This doesn't work yet: we also need to move the data around, I think, and * we should handle more than one BPM change. */ if( BPM2 > 0 && BPMPos2 > 0 ) { const float BeatsPerSecond = out.GetBPMAtBeat(0) / 60.0f; const float beat = BPMPos2 * BeatsPerSecond; LOG->Trace("BPM %f, BPS %f, BPMPos2 %f, beat %f", out.GetBPMAtBeat(0), BeatsPerSecond, BPMPos2, beat); out.AddBPMSegment( BPMSegment(beat, BPM2) ); } if( BPM3 > 0 && BPMPos3 > 0 ) { const float BeatsPerSecond = out.GetBPMAtBeat(0) / 60.0f; const float beat = BPMPos3 * BeatsPerSecond; LOG->Trace("BPM %f, BPS %f, BPMPos3 %f, beat %f", out.GetBPMAtBeat(0), BeatsPerSecond, BPMPos3, beat); out.AddBPMSegment( BPMSegment(beat, BPM3) ); } /* Try to fill in missing bits of information from the pathname. */ { CStringArray asBits; split( sPath, "/", asBits, true); ASSERT(asBits.size() > 1); LoadTags(asBits[asBits.size()-2], out); } // search for music with song in the file name CStringArray arrayPossibleMusic; GetDirListing( out.GetSongDir() + CString("song.mp3"), arrayPossibleMusic ); GetDirListing( out.GetSongDir() + CString("song.ogg"), arrayPossibleMusic ); GetDirListing( out.GetSongDir() + CString("song.wav"), arrayPossibleMusic ); if( !arrayPossibleMusic.empty() ) // we found a match out.m_sMusicFile = arrayPossibleMusic[0]; return true; }
bool NotesLoader::Loadable( CString sPath ) { CStringArray list; GetApplicableFiles( sPath, list ); return !list.empty(); }
ScreenOptionsMaster::ScreenOptionsMaster( const CString &sClassName ): ScreenOptions( sClassName ) { LOG->Trace("ScreenOptionsMaster::ScreenOptionsMaster(%s)", m_sName.c_str() ); /* If this file doesn't exist, leave the music alone (eg. ScreenPlayerOptions music sample * left over from ScreenSelectMusic). If you really want to play no music, add a redir * to _silent. */ CString MusicPath = THEME->GetPathToS( ssprintf("%s music", m_sName.c_str()), true ); if( MusicPath != "" ) SOUND->PlayMusic( MusicPath ); CStringArray asLineNames; split( LINE_NAMES, ",", asLineNames ); if( asLineNames.empty() ) RageException::Throw( "%s::LineNames is empty.", m_sName.c_str() ); CStringArray Flags; split( OPTION_MENU_FLAGS, ";", Flags, true ); InputMode im = INPUTMODE_INDIVIDUAL; bool Explanations = false; unsigned i; for( i = 0; i < Flags.size(); ++i ) { CString &flag = Flags[i]; flag.MakeLower(); if( flag == "together" ) im = INPUTMODE_SHARE_CURSOR; else if( flag == "explanations" ) Explanations = true; else if( flag == "forceallplayers" ) { FOREACH_PlayerNumber( pn ) GAMESTATE->m_bSideIsJoined[pn] = true; GAMESTATE->m_MasterPlayerNumber = PlayerNumber(0); } else if( flag == "smnavigation" ) SetNavigation( NAV_THREE_KEY_MENU ); else if( flag == "toggle" || flag == "firstchoicegoesdown" ) SetNavigation( PREFSMAN->m_bArcadeOptionsNavigation? NAV_TOGGLE_THREE_KEY:NAV_TOGGLE_FIVE_KEY ); } m_OptionRowAlloc = new OptionRowData[asLineNames.size()]; for( i = 0; i < asLineNames.size(); ++i ) { OptionRowData &row = m_OptionRowAlloc[i]; vector<ParsedCommand> vCommands; ParseCommands( LINE(asLineNames[i]), vCommands ); if( vCommands.size() < 1 ) RageException::Throw( "Parse error in %s::Line%i", m_sName.c_str(), i+1 ); OptionRowHandler hand; for( unsigned part = 0; part < vCommands.size(); ++part) { ParsedCommand& command = vCommands[part]; HandleParams; const CString name = sParam(0); if( !name.CompareNoCase("list") ) { SetList( row, hand, sParam(1), row.name ); } else if( !name.CompareNoCase("steps") ) { SetStep( row, hand ); row.name = "Steps"; } else if( !name.CompareNoCase("conf") ) { SetConf( row, hand, sParam(1), row.name ); } else if( !name.CompareNoCase("characters") ) { SetCharacter( row, hand ); row.name = "Characters"; } else RageException::Throw( "Unexpected type '%s' in %s::Line%i", name.c_str(), m_sName.c_str(), i ); CheckHandledParams; } // TRICKY: Insert a down arrow as the first choice in the row. if( m_OptionsNavigation == NAV_TOGGLE_THREE_KEY ) { row.choices.insert( row.choices.begin(), ENTRY_NAME("NextRow") ); hand.ListEntries.insert( hand.ListEntries.begin(), ModeChoice() ); } OptionRowHandlers.push_back( hand ); } ASSERT( OptionRowHandlers.size() == asLineNames.size() ); Init( im, m_OptionRowAlloc, asLineNames.size() ); }
void ConditionalBGA::Load(const CString &szScreenName) { RageFile file; CString szConditionalBGAFile = THEME->GetCurThemeDir() + szScreenName + " ConditionalBGA.ini"; // char filepath[512]; // strcpy(filepath,""); // empty the path first // strcpy(filepath,szConditionalBGAFile.c_str()); LOG->Trace("ConditionalBGA Load:%s",szConditionalBGAFile.c_str()); bool loaded = file.Open(szConditionalBGAFile,RageFile::READ); // FILE* fp = NULL; // fp = fopen(filepath,"r"); if(!loaded) { LOG->Trace("ConditionalBGA File Not Found"); return; } else { CString currentline; int bgano=0; while(!file.AtEOF()) { file.GetLine(currentline); // get the current line // kill any possible comments CStringArray asKillComments; asKillComments.clear(); // get rid of anything in there split(currentline, "#",asKillComments); // A comment starting with # if(!asKillComments.empty()) { currentline = asKillComments[0]; // there was some commentstuff here, take the first bit to be the actual data } asKillComments.clear(); // get rid of anything in there split(currentline, "/",asKillComments); // A comment starting with // or /* if(!asKillComments.empty()) { currentline = asKillComments[0]; // there was some commentstuff here, take the first bit to be the actual data } TrimRight(currentline); // nuke trailing whitespace // start parsing the data if(currentline.c_str()[0] == '[') // we found a new bganimation { if(!m_bgainfo.empty()) // last one wasnt empty { CheckBgaRequirements(m_bgainfo[bgano]); bgano++; } BgaCondInfo temp; m_bgainfo.push_back(temp); ClearINFO(bgano); // wipe out the old info structure. CStringArray asSplitLine; split(currentline,"[",asSplitLine); split(asSplitLine[0],"]",asSplitLine); if(!asSplitLine.empty() && asSplitLine.size() >= 1) m_bgainfo[bgano].bganame = asSplitLine[asSplitLine.size() - 1]; } else { CStringArray asSplitLine; split(currentline,":",asSplitLine); if(asSplitLine.empty()) continue; if(!asSplitLine[0].CompareNoCase("clear") && asSplitLine.size() > 1) { if(!asSplitLine[1].CompareNoCase("true") || !asSplitLine[1].CompareNoCase("cleared") || !asSplitLine[1].CompareNoCase("clear")) // true / clear (any clear condition) m_bgainfo[bgano].cleared = CBGA_CSCLEARED; else if(!asSplitLine[1].CompareNoCase("false") || !asSplitLine[1].CompareNoCase("failed")) // false / failed m_bgainfo[bgano].cleared = CBGA_CSFAILED; else if(!asSplitLine[1].CompareNoCase("maxcombo") || !asSplitLine[1].CompareNoCase("fullcombo")) // passed with maxcombo m_bgainfo[bgano].cleared = CBGA_CSMAXCOMBO; else if(!asSplitLine[1].CompareNoCase("brokencombo")) // passed with a broken combo m_bgainfo[bgano].cleared = CBGA_CSBROKECOMBO; // LOG->Trace("Clear Conditon: %d",info.cleared); } if(!asSplitLine[0].CompareNoCase("songtitle") && asSplitLine.size() > 1) { m_bgainfo[bgano].songtitle = asSplitLine[1]; // LOG->Trace("SongTitle: %s",info.songtitle.c_str()); } if(!asSplitLine[0].CompareNoCase("songartist") && asSplitLine.size() > 1) { m_bgainfo[bgano].songartist = asSplitLine[1]; // LOG->Trace("SongArtist: %s",info.songartist.c_str()); } if(!asSplitLine[0].CompareNoCase("songday") && asSplitLine.size() > 1) { CStringArray asDays; split( asSplitLine[1], ",", asDays ); for( unsigned d=0; d<asDays.size(); d++ ) { int dn = atoi(asDays[d].c_str()); if(!(dn < 1 || dn > 32)) // ignore if date is out of range { m_bgainfo[bgano].songdays.push_back(dn); } } // for(d=0; d<info.songdays.size(); d++) // { // LOG->Trace("SongDay: %d",info.songdays[d]); // } } if(!asSplitLine[0].CompareNoCase("songmonth") && asSplitLine.size() > 1) { CStringArray asMonths; split( asSplitLine[1], ",", asMonths ); for( unsigned d=0; d<asMonths.size(); d++ ) { int dn = atoi(asMonths[d].c_str()); if(!(dn < 1 || dn > 12)) // ignore if date is out of range { m_bgainfo[bgano].songmonths.push_back(dn); } } // for(d=0; d<info.songmonths.size(); d++) // { // LOG->Trace("SongMonth: %d",info.songmonths[d]); // } } // foot meter ratings if(!asSplitLine[0].CompareNoCase("songdifficulty") && asSplitLine.size() > 1) { CStringArray asDifficulties; split( asSplitLine[1], ",", asDifficulties ); for(unsigned d=0;d<asDifficulties.size();d++) { // check to see if the last character is a + bool bHandled = false; if(asDifficulties[d].c_str()[strlen(asDifficulties[d].c_str())-1] == '+') { bHandled = true; CStringArray asVal; split(asDifficulties[d],"+",asVal); int temp=0; temp = 0 - atoi(asVal[0].c_str()); // negative numbers will indicate 'greater than' for this system m_bgainfo[bgano].songmeters.push_back(temp); } if(!bHandled) // didnt find the + (gt) so find a - (range) { bool isarange=false; for(unsigned b=0; b<strlen(asDifficulties[d].c_str());b++) { if(asDifficulties[d].c_str()[b] == '-') { bHandled = isarange = true; break; } } if(isarange) { CStringArray asVal; split(asDifficulties[d],"-",asVal); int imin=0,imax=0,itmp=0; imin=atoi(asVal[0].c_str()); imax=atoi(asVal[1].c_str()); itmp=imin; while(itmp<=imax) // fill in the values between the min and max range inclusive { m_bgainfo[bgano].songmeters.push_back(itmp); itmp++; } } } if(!bHandled) // its not a range so must be a value on its own { int tmp = atoi(asDifficulties[d].c_str()); m_bgainfo[bgano].songmeters.push_back(tmp); } } } // mods that mustn't be present if(!asSplitLine[0].CompareNoCase("moddisallow") && asSplitLine.size() > 1) { m_bgainfo[bgano].dpoused = true; m_bgainfo[bgano].disallowedpo.FromString(asSplitLine[1]); } // heavy, light e.t.c. if(!asSplitLine[0].CompareNoCase("songrating") && asSplitLine.size() > 1) { CStringArray asDifficulties; split( asSplitLine[1], ",", asDifficulties ); for( unsigned d=0; d<asDifficulties.size(); d++ ) { m_bgainfo[bgano].difficulties.push_back(StringToDifficulty(asDifficulties[d])); } // for(d=0; d<info.difficulties.size(); d++) // { // LOG->Trace("Difficulty: %d",info.difficulties[d]); // } } if(!asSplitLine[0].CompareNoCase("grade") && asSplitLine.size() > 1) { CStringArray asGrades; split( asSplitLine[1], ",", asGrades ); for( unsigned d=0; d<asGrades.size(); d++ ) { m_bgainfo[bgano].grades.push_back(StringToGrade(asGrades[d])); } } if(!asSplitLine[0].CompareNoCase("style") && asSplitLine.size() > 1) { LOG->Info("Comparing Styles"); CStringArray asStyles; split( asSplitLine[1], ",", asStyles ); for( unsigned d=0; d<asStyles.size(); d++ ) { LOG->Info( "Style:%s", asStyles[d].c_str() ); m_bgainfo[bgano].styles.push_back(GAMEMAN->GameAndStringToStyle(GAMESTATE->m_pCurGame,asStyles[d])); } } } } if(bganimtouse.CompareNoCase("")!=0) { LOG->Info("Best Match BGA Was: %s",bganimtouse.c_str()); bganim.LoadFromAniDir( THEME->GetPathToB(bganimtouse) ); } } file.Close(); }