void cHud_Manager::Load(void) { if (!m_loaded && !objects.empty()) { Unload(); } else if (m_loaded) { Update_Text(); return; } Add(static_cast<cHudSprite*>(new cMenuBackground())); pHud_Points = new cPlayerPoints(); Add(static_cast<cHudSprite*>(pHud_Points)); pHud_Time = new cTimeDisplay(); Add(static_cast<cHudSprite*>(pHud_Time)); pHud_Lives = new cLiveDisplay(); Add(static_cast<cHudSprite*>(pHud_Lives)); pHud_Goldpieces = new cGoldDisplay(); Add(static_cast<cHudSprite*>(pHud_Goldpieces)); pHud_Itembox = new cItemBox(); Add(static_cast<cHudSprite*>(pHud_Itembox)); pHud_Debug = new cDebugDisplay(); Add(static_cast<cHudSprite*>(pHud_Debug)); m_loaded = 1; }
void cDialog :: SetColors( SDL_Color outer, SDL_Color inner, SDL_Color text_area, SDL_Color text ) { boarder_out_color = outer; boarder_in_color = inner; text_area_color = text_area; text_color = text; Update_Text(); }
cDialog :: cDialog( double nposx, double nposy, string nidentifier, string ntext, DialogType dialogtype, Uint8 nmax_length /* = 20 */, unsigned int nmin_width ) : cSprite( NULL, nposx, nposy ) { stext = NULL; if( is_valid_number( ntext.c_str() ) ) { text_number = string_to_int( ntext ); } else { text_number = 0; } identifier.reserve( nidentifier.length() ); identifier = nidentifier; text = ntext; type = dialogtype; boarder_in = 2; boarder_out = 2; text_area = 1; min_width = nmin_width; if( type != DIALOG_ONLY_NUMBERS ) { if( nmax_length < ntext.length() ) { max_length = ntext.length(); } else { max_length = nmax_length; } text.reserve( max_length ); } else { if( nmax_length < text_number ) { max_length = text_number; } else { max_length = nmax_length; } text.reserve( 20 ); } SetColors( colorDarkBlue, colorBlue, colorWhite, colorBlack ); Update_Boarders(); Update_Text(); }
void cDialog :: Get_Focus( void ) { bool focus = 1; string text_old = text; int minwidth_old = min_width; pDialogManager->Update(); boxRGBA( screen, 0, 0, screen->w, screen->h , 0, 0, 0, 32 ); SDL_EnableUNICODE( 1 ); SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY, 50 ); while( focus ) { Update(); if( rect.w < min_width ) { rect.w = min_width; } else if( rect.w > min_width ) { min_width = rect.w; } SDL_Flip( screen ); while( SDL_PollEvent( &event ) ) { keys = SDL_GetKeyState( NULL ); if( KeyPressed( KEY_ESC) && event.key.keysym.sym != SDLK_BACKSPACE ) { text = text_old; focus = 0; } else if ( KeyPressed( KEY_ENTER ) ) { focus = 0; } else if( event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_BACKSPACE ) { if( text.length() && type != DIALOG_ONLY_NUMBERS ) { text.erase( text.length() - 1, 1 ); Update_Text(); } } else if( event.type == SDL_KEYDOWN && event.key.keysym.sym != SDLK_ESCAPE ) { if( type != DIALOG_ONLY_NUMBERS ) { if( event.key.keysym.unicode && text.length() < max_length ) { if( type == DIALOG_ONLY_LETTERS ) { string s; s.insert( (string::size_type)0, (string::size_type)1, (char)event.key.keysym.unicode ); if( !is_valid_number( s ) ) { text.insert( text.length(), s ); } } else { text.insert( text.length(), 1, (char)event.key.keysym.unicode ); } Update_Text(); } } else { if( KeyPressed( KEY_UP ) ) { text_number += 1; } else if( KeyPressed( KEY_DOWN ) ) { text_number -= 1; } else if( KeyPressed( KEY_LEFT ) ) { text_number -= 10; } else if( KeyPressed( KEY_RIGHT ) ) { text_number += 10; } else if( event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_PLUS ) { text_number += 1; } else if( event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_MINUS ) { text_number -= 1; } else if( event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_PAGEUP ) { text_number += 10; } else if( event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_PAGEDOWN ) { text_number -= 10; } if( text_number > max_length ) { text_number = max_length; } else if( text_number < 0 ) { text_number = 0; } Update_Text(); } } } Framerate.Update(); } SDL_EnableUNICODE( 0 ); SDL_EnableKeyRepeat( 0, 0 ); if( text.compare( text_old ) != 0 ) { changed = 1; } min_width = minwidth_old; Update_Text(); Framerate.Reset(); }