Message and Event Log

The log symbol, located in the log layer of Scene 1 of the HUDKit.fla, is the container for the message and event log at the bottom-left side of the HUD. In this demo, the log displays text messages related to recent events including kills, power-ups, flag captures, and level-ups. New messages are added at the bottom of the log, forcing older messages upward. A log message will fade-out after ~3 seconds of being displayed.

Figure 13: log and logMessage symbols

Log messages are instances of the logMessage symbol. Messages added to the log will display for approximately 3 seconds before beginning a fade-out animation. This animation is defined on the timeline of the logMessage symbol. The text for the messages is sent from C++ and is displayed in the textField using htmlText.

The following code is from FxHUDMessage::Movieclip* FxHUDLog::GetUnusedMessageMovieclip() which creates a new LogMessage MovieClip and attaches it to the Log MovieClip, the canvas for all log messages.

FxHUDMessage::Movieclip* FxHUDLog::GetUnusedMessageMovieclip()
{
    if (MessageMCs.IsEmpty())
    {
        // Request a new line in the SWF
        Value logline;
        LogMC.AttachMovie(&logline, "LogMessage", "logMessage"+NumMessages);
        FxHUDMessage::Movieclip* pmc = new FxHUDMessage::Movieclip(logline);
        MessageMCs.PushBack(pmc);  // Add new Message MC to list of unused message movieClips.
    }
    FxHUDMessage::Movieclip* pmc = MessageMCs.GetFirst();  // Use an unused Message movieClip.
    pmc->SetVisible(true);
    MessageMCs.Remove(pmc);
    return pmc;
}

The content for the message is set from C++ based on the event type. The following is the C++ code to process a Level Up event and set the htmlText for a new message that will display “You are now a [Rank Icon] [Rank Name]” in the log.

voidFxHUDLog::Process(FxHUDEvent *pevent)
{
    String msg;
    switch (pevent->GetType())
    {
        case FxHUDEvent::EVT_LevelUp:
        {
            FxHUDLevelUpEvent* e = (FxHUDLevelUpEvent*)pevent;
            Format(msg, "You are now a <img src='rank{1}'/> {0}!",
            e->GetNewRankName(), e->GetNewRank());
        }
        break;
    }

    FxHUDMessage::Movieclip* pmc = GetUnusedMessageMovieclip();
    FxHUDMessage* m = new FxHUDMessage(msg, pmc); // 3 seconds
    Log.PushBack(m);
    NumMessages++;

The following is the HUD Update logic used to manage the log. It updates the layout and animation for log message references.

voidFxHUDLog::Update()
{
    SF_ASSERT(LogMC.IsDisplayObject());

    Double rowHeight = 30.f;

    // Tick the message lifetimes
    Double yoff = 0;
    FxHUDMessage* data = Log.GetFirst();
    while (!Log.IsNull(data))
    {
        FxHUDMessage* next = Log.GetNext(data);
        if (data->IsAlive())
        {
            // Layout mgmt and animation
            Value::DisplayInfo info;
            info.SetY(yoff);
            data->GetMovieclip()->GetRef().SetDisplayInfo(info);
        }
        data = next;
        yoff += rowHeight;
    }

    // Layout management and animation
    Value::DisplayInfo info;
    info.SetY(LogOriginalY - (NumMessages * rowHeight));
    LogMC.SetDisplayInfo(info);

    // Remove dead messages
    data = Log.GetFirst();
    while (!Log.IsNull(data))
    {
        FxHUDMessage* next = Log.GetNext(data);
        if (!data->IsAlive())
        {
            Log.Remove(data);
            NumMessages--;

            FxHUDMessage::Movieclip* pmc = data->GetMovieclip();
            pmc->SetVisible(false);
            MessageMCs.PushBack(pmc);

            delete data;
        }
        data = next;
    }
}

The update logic for the Log checks to see whether any FxHUDMessage is currently displayed in the log by checking whether its Alpha is set to 0. If it is not displayed, it is removed from the Log and added back to the MessageMCs list of unused FxHUDMessage MovieClips. If a new FxHUDMessage has been added, all MessageMC are shifted up appropriately using GFx::Value::DisplayInfo.SetY() and GFx::Value::SetDisplayInfo().