#include "online_emotes.h" #include "log.h" #include "manager.h" #include "menu_manager.h" #include #include constexpr std::array EMOTE_ANIMATIONS = { "Up", "Down", "Left", "Right", "Happy", "Sad", "ThumbsUp", "ThumbsDown", "Heart", "Bomb", "Coin", "Key", "TintedRock", "Angel", "Devil", "Poop", "RaiseHand", "QuestionMark", "D6", "D20", "Reset"}; constexpr const char* ANIMATION_BUBBLE = "Bubble"; constexpr const char* ANIMATION_D6_ROLL = "D6Roll"; constexpr const char* ANIMATION_D6_RESULT = "D6Result"; constexpr const char* ANIMATION_D20_ROLL = "D20Roll"; constexpr const char* ANIMATION_D20_RESULT = "D20Result"; constexpr const char* ANIMATION_NICALIS = "Nicalis"; constexpr const char* TYPING_DOTS[] = {".", "..", "..."}; constexpr int TYPING_CYCLE = 60; constexpr int TYPING_DOT_FRAMES = 20; constexpr float TYPING_OFFSET_X = -12; constexpr uint32_t TYPING_ARGB = 0xffffffff; constexpr int WHEEL_SET_COUNT = 2; constexpr float FULL_TURN = 360; // The animation an emote plays, none while typing. static std::string_view emote_animation(Emote emote) { if (emote < EMOTE_TYPING) return EMOTE_ANIMATIONS[emote]; if (emote == EMOTE_TYPING) return {}; if (emote < EMOTE_D20_ROLL) return ANIMATION_D6_ROLL; if (emote < EMOTE_NICALIS) return ANIMATION_D20_ROLL; return ANIMATION_NICALIS; } // 0042fba0 Loads both sprites on the emotes sheet and floats the bubble. // The original also fills a table of animation names here, which emote_animation holds. void OnlineEmotes::Load() { emoteSprite.Load(ONLINE_EMOTES_ANM2, GRAPHICS_LOAD); bubbleSprite.Load(ONLINE_EMOTES_ANM2, GRAPHICS_LOAD); bubbleSprite.Play(ANIMATION_BUBBLE); } // 00430750 Shows an emote for some frames, playing it from the start unless it is already shown. void OnlineEmotes::Play(Emote shown, int frames) { duration = frames; isActive = true; if (emote == shown) return; emote = shown; timer = 0; if (shown == EMOTE_TYPING) return; emoteSprite.Play(emote_animation(shown)); emoteSprite.Update(); } // 004303e0 Steps the sprites, turns a finished die roll into its result held on the face rolled, and hides the emote // once its duration has passed. void OnlineEmotes::Update() { if (!isActive) return; if (emote != EMOTE_TYPING) { emoteSprite.Update(); bubbleSprite.Update(); int frame = -1; auto roll_settle = [&](std::string_view roll, std::string_view result, Emote first) { if (emoteSprite.IsFinished(roll)) emoteSprite.Play(result); if (emoteSprite.IsPlaying(result)) frame = emote - first; }; if (emote >= EMOTE_D6_ROLL && emote < EMOTE_D20_ROLL) roll_settle(ANIMATION_D6_ROLL, ANIMATION_D6_RESULT, EMOTE_D6_ROLL); else if (emote >= EMOTE_D20_ROLL && emote < EMOTE_NICALIS) roll_settle(ANIMATION_D20_ROLL, ANIMATION_D20_RESULT, EMOTE_D20_ROLL); else if (emote >= EMOTE_NICALIS && emote < EMOTE_COUNT && emoteSprite.animState.animData) frame = emote - EMOTE_NICALIS; if (frame >= 0) emoteSprite.animState.SetFrameFloat((float)frame); } timer++; if (duration == 0 || timer <= duration) return; isActive = false; emote = EMOTE_NONE; timer = 0; duration = 0; } // 004305c0 Draws the bubble and the emote at a position, or dots counting up while its player types. void OnlineEmotes::Render(Vector position) { if (!isActive) return; if (emote != EMOTE_TYPING) { if (isBubbleShown) bubbleSprite.Render({position}); emoteSprite.Render({position}); return; } FontSettings settings; std::string_view dots = TYPING_DOTS[timer % TYPING_CYCLE / TYPING_DOT_FRAMES]; Vector textPosition = vector_make(position.x + TYPING_OFFSET_X, position.y); g_manager->font2_TeamMeatEx12.DrawString(dots, textPosition, vector_make(1, 1), kcolor_argb(TYPING_ARGB), settings); } // 008d1d60 Closes the wheel and fills its two sets, the game's emotes and the Nicalis frames, adding to any already // there as the original does. Loads the wheel's emote without its bubble. void EmoteWheel::Init() { ringRadius = openProgress; selectionRadius = maxRadius; isInitialized = true; state = EMOTE_WHEEL_CLOSED; selection = -1; emoteSets.resize(WHEEL_SET_COUNT); for (int emote = EMOTE_UP; emote <= EMOTE_D20; emote++) emoteSets[0].push_back((Emote)emote); for (int emote = EMOTE_NICALIS; emote < EMOTE_COUNT; emote++) emoteSets[1].push_back((Emote)emote); emoteSetIndex = 0; angle_step_update(); emote.Load(); emote.isBubbleShown = false; } // 008d26c0 Switches to another set of emotes, keeping the selection at about the same angle. void EmoteWheel::SetEmoteSet(int index) { if (index == emoteSetIndex) return; if (index < 0 || index >= (int)emoteSets.size()) { log_printf(LOG_ERROR, "Invalid set index %d \n", index); return; } emoteSetIndex = index; angle_step_update(); } // Spreads the current set's emotes evenly around the ring, rounding the selection to the same angle. void EmoteWheel::angle_step_update() { float previousStep = angleStep; angleStep = FULL_TURN / (float)emoteSets[emoteSetIndex].size(); selection = (int)((float)selection * previousStep / angleStep + 0.5f); } void EmoteWheel::Update() { reconstruction_missing("EmoteWheel::Update 008d1f20 (netplay only)"); } // The closed wheel draws nothing. The open one only opens in netplay. void EmoteWheel::Render() { if (state != EMOTE_WHEEL_CLOSED) reconstruction_missing("EmoteWheel::Render 008d2450 (netplay only open wheel)"); }