Пользователь
-
Автор темы
- #1
C++:
struct notifications_t
{
notifications_t( Color clr1, Color clr2, float time, std::string buffer )
: color( clr1 ), background_color( clr2 ), m_time( time ), buf( buffer ) { }
Color color;
Color background_color;
float m_time;
std::string buf;
};
C++:
class notifications : public singleton<notifications>
{
private:
float text_offset = 5.f;
std::deque< notifications_t > m_notifications;
public:
auto add( bool display, Color color, const std::string message, ... ) -> void;
auto clear( ) -> void;
auto draw( ) -> void;
};
C++:
auto notifications::add( bool display, Color color, const std::string message, ... ) -> void
{
if( message.empty( ) )
return;
va_list va;
std::string buf;
va_start( va, message );
const int str_len = std::vsnprintf( nullptr, 0, message.c_str( ), va );
if( str_len < 0 ) {
va_end( va );
return;
}
buf.resize( str_len );
std::vsnprintf( &buf[ 0 ], str_len + 1, message.c_str( ), va );
if( m_notifications.size( ) > 15 )
m_notifications.pop_front( );
g_sdk.convar->print_to_console( Color( 206, 115, 136 ), "[ur ware name there]" );
g_sdk.convar->print_to_console( Color( 255, 255, 255 ), " %s\n", buf.c_str( ) );
if( display )
m_notifications.emplace_back( color, Color(0, 0, 0,125 ), g_sdk.global_vars->cur_time, buf );
}
auto notifications::clear( ) -> void
{
m_notifications.clear( );
}
auto notifications::draw( ) -> void
{
int height = 5;
for( size_t i = 0; i < m_notifications.size( ); i++ ) {
auto ¬ification = m_notifications.at( i );
Color &color = notification.color;
Color &shadow_color = notification.background_color;
const float cur_time = notification.m_time;
std::string message = notification.buf;
if( g_sdk.global_vars->cur_time - cur_time > text_offset ) {
int alpha = static_cast< int >( color.a( ) * 255.f - 255 / 1.f * std::max( g_sdk.global_vars->frametime, 0.01f ) );
if( alpha > 255 )
alpha = 255;
if( alpha < 0 )
alpha = 0;
if( !alpha ) {
m_notifications.erase( m_notifications.begin( ) + i );
continue;
}
Color col = color;
color =Color( col.r( ) * 255.f, col.g( ) * 255.f, col.b( ) * 255.f,alpha);
Color shadow_col = shadow_color;
shadow_color = Color( shadow_col.r( ) * 255.f, shadow_col.g( ) * 255.f, shadow_col.b( ) * 255.f,alpha);
}
render::get().text( render::get().get_font( FONT_VERDANA), color, shadow_color, 8, height, DROPSHADOW, message );
height += render::get().get_font( FONT_VERDANA)->GetHeight( ) + 1;
}
}
C++:
notifications::get().draw( );
C++:
notifications::get().add( true, ctx.clr, "%s bought %s", info.player_name, event->get_string( "weapon" ) );
Последнее редактирование: