Исходник Animated keybinds list

купить дизайн: yougame.biz/threads/155999
Дизайнер
Статус
Оффлайн
Регистрация
19 Сен 2018
Сообщения
793
Реакции[?]
1,380
Поинты[?]
9K


C++:
namespace input {
    enum struct e_act {
        hold,
        toggle
    };

    struct hotkey_t {
        bool            m_state{};
        e_act            m_act{};
        std::size_t    m_key{};
        std::string    m_name{}, m_mode{};
        float            m_time{};

        hotkey_t( std::string name, std::size_t key, e_act act ) : m_name( name ), m_key( key ), m_act( act ),
            m_mode( act == e_act::hold ? str::xor( "hold" ) : str::xor( "toggled" ) ) {};

        __forceinline void process( float time ) {
            switch ( m_act ) {
            case e_act::hold:
                /* GetAsyncKeyState( m_key ) */
                m_state = get_keyboard_button( m_key ).down( );

                break;
            case e_act::toggle:
                /* LOWORD( GetKeyState( m_key ) ) */
                m_state = get_keyboard_button( m_key ).odd_clicks( );

                break;
            }

            if ( m_state ) {
                m_time = time;
            }
        };
    };

    std::unordered_map< std::size_t, hotkey_t > m_hotkeys{};

    /*
    *    can be called anywhere once:
    *    input::add( "double tap", 0x4e, input::e_act::toggle );
    */
    __forceinline void add( std::string name, std::size_t key, e_act act ) {
        m_hotkeys.insert( std::make_pair( str::hash( name ), hotkey_t( name, key, act ) ) );
    }

    /*
    *    can be called anywhere:
    *    if ( input::get( str::hash( "double tap" ) ) ) {
    *       double_tap( );
    *    }
    */
    __forceinline bool get( std::size_t hash ) {
        return m_hotkeys.at( hash ).m_state;
    }

    __forceinline void process( float time ) {
        for ( auto& hotkey : m_hotkeys ) {
            auto& data = std::get< hotkey_t >( hotkey );

            data.process( time );
        }
    }
}

void draw_hotkeys( ) {
    /*
    *    inlined here, call on init( )
    *    rage bot - left mouse button
    *    double tap - n key
    *    hide shots - i key
    */
    if ( input::m_hotkeys.empty( ) ) {
        input::add( "rage bot", 0x01, input::e_act::hold );
        input::add( "double tap", 0x4e, input::e_act::toggle );
        input::add( "hide shots", 0x49, input::e_act::hold );
    }

    const auto time = interfaces::m_global_vars->m_real_time;

    /*
    *    inlined here, call where do you want
    *    since this hotkey system is written in microsoft word
    *    it can be designed more better
    *    but because most people use roughly the same code,
    *    only less centralized, i decided to leave it as is
    */
    input::process( time );

    constexpr auto anim_speed = 0.2f;

    /* initial position of list */
    constexpr auto pos = math::vec2_t( 600.f, 200.f );

    /* size of header + width of list */
    constexpr auto size = math::vec2_t( 140.f, 20.f );

    constexpr auto padding = 4.f;
    constexpr auto spacing = 4.f;
    constexpr auto line_size = 2.f;

    constexpr auto back_color = math::rgba_t( 0.f, 0.f, 0.f, 0.95f );
    constexpr auto text_color = math::rgba_t( 1.f, 1.f, 1.f, 0.95f );
    constexpr auto line_color = math::rgba_t( 0.6f, 0.8f, 1.f );

    auto active_hotkeys = std::vector< std::pair< input::hotkey_t, float > >{};

    auto last_expiration = 0.f;

    for ( const auto& hotkey : input::m_hotkeys ) {
        const auto& data = std::get< input::hotkey_t >( hotkey );

        const auto expiration = 1.f - ( time - data.m_time ) / anim_speed;

        last_expiration = std::max( last_expiration, expiration );

        if ( expiration <= 0.f )
            continue;

        active_hotkeys.emplace_back( std::make_pair( data, expiration ) );
    }

    if ( active_hotkeys.empty( ) )
        return;

    draw::rect_filled( pos, math::vec2_t( size.x( ), line_size ), line_color.override_alpha( last_expiration ) );

    draw::rect_filled( pos + math::vec2_t( 0.f, line_size ),
        math::vec2_t( size.x( ), size.y( ) - line_size ), back_color.override_alpha( last_expiration ) );

    draw::text( draw::m_verdana, str::xor( "keybindings" ), pos + ( size / 2.f ), text_color.override_alpha( last_expiration ), draw::e_flags::shadow | draw::e_flags::center );

    auto draw_pos = math::vec2_t( padding, size.y( ) + spacing );
    auto draw_size = math::vec2_t( size.x( ) - ( padding * 2.f ), 0.f );

    for ( const auto& hotkey : active_hotkeys ) {
        const auto& data = std::get< input::hotkey_t >( hotkey );

        const auto text_size = draw::text_size( draw::m_verdana, data.m_mode );

        draw::text( draw::m_verdana, data.m_name, pos + draw_pos, text_color.override_alpha( std::get< float >( hotkey ) ), draw::e_flags::shadow );
        draw::text( draw::m_verdana, data.m_mode, pos + draw_pos + draw_size - math::vec2_t( text_size.x( ), 0.f ),
            text_color.override_alpha( std::get< float >( hotkey ) ), draw::e_flags::shadow );

        draw_pos.y( ) += text_size.y( ) + spacing;
    }
}

анимированные кейбинды, кАк в СкИтЕ
по сути можно заменить свою кейбинд систему на данную тут. она, конечно же, не идеальная, но лучше того, что я видел.....

 
Забаненный
Статус
Оффлайн
Регистрация
3 Дек 2018
Сообщения
151
Реакции[?]
20
Поинты[?]
0
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
хороший пост
собираюсь сразу вставить в мой supremacy
 
Сверху Снизу