#include "stdafx.h" #include "TipManager.h" #include "UINode.h" cTipManager* cTipManager::mpSingleton = 0; cTipManager::cTipManager() : mLastAccumTime(0) { mpSingleton = this; } cTipManager::~cTipManager() { for( unsigned int i = 0; i < MAX_TIPCOUNT; ++i ) { mTipArr[i].Clear(); } for( unsigned int i = 0; i < mLoadTipArr.GetSize(); ++i ) { delete (sLoadTipData*)mLoadTipArr[i]; } mLoadTipArr.Clear(); mpSingleton = 0; } bool cTipManager::Init() { if( LoadGameTip( "./Script/Resource/Tip_Game.txt" ) == false ) { assert( 0 && "failed to load tip_game" ); cString msg; msg.Format("[./Script/Resource/Tip_Game.txt]" ); MessageBoxA( NULL, msg.Cstr(), "failed to load tip_game", MB_OK | MB_ICONERROR ); return false; } if( LoadLoadTip( "./Script/Resource/Tip_LoadingMap.txt" ) == false ) { assert( 0 && "failed to load tip_loadingMap" ); cString msg; msg.Format( "./Script/Resource/Tip_LoadingMap.txt" ); MessageBoxA( NULL, msg.Cstr(), "failed to load tip_loadingMap", MB_OK | MB_ICONERROR ); return false; } return true; } /// ÆÁ µ¥ÀÌÅÍ ·Îµå bool cTipManager::LoadGameTip( const cString& pathname ) { cFileLoader loader; if( loader.Open( pathname, true ) == false ) { assert( 0 && "failed to load game tip" ); cString msg; msg.Format("[%s]", pathname.Cstr() ); MessageBoxA( NULL, msg.Cstr(), "failed to load game tip", MB_OK | MB_ICONERROR ); return false; } cTokenizer tokenizer( loader.GetBufferPtr(), loader.GetSize(), " \t\r\n", pathname.Cstr() ); cString str; while( tokenizer.IsEnd() == false ) { /// ´ë»ç À妽º if( tokenizer.GetNext( &str ) == false ) return false; long index = str.ToInt(); /// ÃÖ¼Ò ·¹º§ if( tokenizer.GetNext( &str ) == false ) return false; long minLevel = str.ToInt(); /// ÃÖ´ë ·¹º§ if( tokenizer.GetNext( &str ) == false ) return false; long maxLevel = str.ToInt(); if( maxLevel > MAX_TIPCOUNT ) { assert(0); return false; } /// µ¥ÀÌÅÍ »ðÀÔ for( long i = minLevel; i <= maxLevel; ++i ) { mTipArr[i-1].PushBack( index ); } } return true; } /// ·Îµù ÆÁ µ¥ÀÌÅÍ bool cTipManager::LoadLoadTip( const cString& pathname ) { cFileLoader loader; if( loader.Open( pathname, true ) == false ) { assert( 0 && "failed to load load tip" ); cString msg; msg.Format("[%s]", pathname.Cstr() ); MessageBoxA( NULL, msg.Cstr(), "failed to load tip", MB_OK | MB_ICONERROR ); return false; } cTokenizer tokenizer( loader.GetBufferPtr(), loader.GetSize(), " \t\r\n", pathname.Cstr() ); cString str; while( tokenizer.IsEnd() == false ) { /// ÆÁ À妽º if( tokenizer.GetNext( &str ) == false ) return false; // long index = (long)str.ToInt(); (long)str.ToInt(); /// ÅØ½ºÃÄ ¸í if( tokenizer.GetNext( &str ) == false ) return false; cString name = str; /// ÅØ½ºÃ³ ÁÂÇ¥ X if( tokenizer.GetNext( &str ) == false ) return false; unsigned int texX = (unsigned int)str.ToInt(); /// ÅØ½ºÃ³ ÁÂÇ¥ Y if( tokenizer.GetNext( &str ) == false ) return false; unsigned int texY = (unsigned int)str.ToInt(); /// sLoadTipData* p = new sLoadTipData; p->mTexName = name; p->mTexX = texX; p->mTexY = texY; mLoadTipArr.PushBack( p ); } return true; } sLoadTipData* cTipManager::GetLoadTipData() { int size = mLoadTipArr.GetSize(); if( size > 0 ) { int key = rand() % size; return (sLoadTipData*)mLoadTipArr[key]; } return 0; }