示例#1
0
        }   // end of c'tor

        public static void Update(Camera camera)
        {
            // Loop through the list backwards in case we remove one.
            for (int i = activeBalloons.Count - 1; i >= 0; i--)
            {
                ThoughtBalloon balloon = activeBalloons[i];
                bool           alive   = balloon.Update(camera);
                if (!alive)
                {
                    // Before removing balloon, let the SaidStringManager know.
                    SaidStringManager.AddEntry(balloon.Thinker as GameActor, balloon.RawText, false);

                    activeBalloons.RemoveAt(i);
                    spareBalloons.Add(balloon);
                }
            } // end of loop over list.
        }     // end of ThoughtBalloonManager Update()
示例#2
0
        /// <summary>
        /// Creates a thought balloon over a bot.  This version is mostly for edit mode
        /// where you don't want the bot to play its speach sound.  Note that this version
        /// also kills off any previous thought balloons since we only want one bot at a
        /// time to identify itself.
        /// </summary>
        /// <param name="thinker">The bot with the thought.</param>
        /// <param name="text">What he's thinking.</param>
        /// <param name="color">Color for balloon outline.</param>
        /// <param name="editMode">If true, don't play a bot speach sound.</param>
        /// <returns>True if acted upon, false if ignored.</returns>
        public static bool CreateThoughtBalloon(GameThing thinker, string text, Vector4 color, bool editMode)
        {
            //Debug.Print(text);

            // Early out if we have nothing to say.
            if (text == null || text == "")
            {
                return(true);
            }

            // The thought string may have text substitutions in in (eg <score red>) so
            // process those first so we can do vaild text string comparisons.
            string newText      = TextHelper.ApplyStringSubstitutions(text, thinker as GameActor);
            string rawText      = text; // Text before substitution.
            bool   substitution = newText != text;

            text = newText;

            // If the current bot is already thinking this same thought then just
            // extend the time for the thought rather than creating a duplicate.
            // If the bot is already thinking another thought then ignore the new
            // thought.  Always replace the string just in case a substitution
            // has take place.
            // Also use this opportunity to kill off thoughts from other bots if
            // we're in edit mode.
            for (int i = 0; i < activeBalloons.Count; i++)
            {
                ThoughtBalloon balloon = activeBalloons[i];
                if (balloon.Thinker == thinker)
                {
                    // Remove tags.  Need to do this _before_ setting the text
                    // on the balloon otherwise the tags can show up on screen.
                    text = TextHelper.RemoveTags(text).Trim();

                    // If just thinking the same thought again, extend the time.
                    if (balloon.RawText == rawText)
                    {
                        balloon.RestartTime();
                        balloon.Text = text;    // Update the text in case of a substitution, eg a score changed.
                    }

                    // Check for message being sent.  If so, don't return yet.
                    if (text.Length > 0)
                    {
                        // Current thought has priority, so don't act on new changes.
                        return(false);
                    }
                }
                else
                {
                    if (editMode)
                    {
                        balloon.Kill();
                    }
                }
            }


            int count = spareBalloons.Count;

            if (count > 0)
            {
                // Search the existing spares for one that already matches the string.
                ThoughtBalloon balloon = null;
                for (int i = 0; i < spareBalloons.Count; i++)
                {
                    if (spareBalloons[i].Text == text)
                    {
                        // Found a match.
                        balloon = spareBalloons[i];
                        spareBalloons.RemoveAt(i);
                        break;
                    }
                }

                if (InGame.inGame.CurrentUpdateMode == InGame.UpdateMode.RunSim)
                {
                    SaidStringManager.AddEntry(thinker as GameActor, rawText, true);
                }
                string txt = TextHelper.RemoveTags(rawText).Trim();
                if (txt == null || txt == string.Empty)
                {
                    // Must have been just a pure (tag only) message.  In that case,
                    // also send it with atBeginning set to false.  This lets the
                    // user be a bit sloppy with the triggering.
                    SaidStringManager.AddEntry(thinker as GameActor, rawText, false);

                    return(true);
                }

                // If no match found, just grab one.
                if (balloon == null)
                {
                    balloon = spareBalloons[0];
                    spareBalloons.RemoveAt(0);
                }

                // Also remove tags for non-raw text.
                text = TextHelper.RemoveTags(text);

                balloon.Activate(thinker, text, rawText, color);

                activeBalloons.Add(balloon);

                // Call update to set up the balloon for the
                // rendering of its first frame.
                balloon.Update(InGame.inGame.shared.camera);

                if (!editMode)
                {
                    Foley.PlaySay(thinker);
                }

                return(true);
            }

            return(false);
        }   // end of CreateThoughtBalloon()