Exemplo n.º 1
0
Arquivo: HUD.cs Projeto: nemec/4Realms
            internal PlayerHUD(IHUDTheme theme, Player p, int xOffset, int yOffset)
            {
                #region Name
                Text name = new Text("player_name_" + p.Name, "Text", p.Name);
                name.DisplayColor = theme.TextColor;
                name.Pos          = new Vector2(xOffset, yOffset);
                name.Static       = true;
                #endregion

                #region HealthBar
                healthBar = new ProgressBar("Health_" + p.Name, p.MaxHealth,
                                            Color.DarkRed, Color.Firebrick, Color.Black, barSize);
                healthBar.Pos    = new Vector2(xOffset, name.Pos.Y + name.GetAnimation().Height);
                healthBar.Static = true;
                healthBar.Value  = p.MaxHealth;

                p.HealthChanged += delegate(object obj, int value)
                {
                    healthBar.Value = value;
                    if (value == 0)
                    {
                        name.DisplayColor = Color.Tomato;
                    }
                    else
                    {
                        name.DisplayColor = theme.TextColor;
                    }
                };
                #endregion

                #region ManaBar
                manaBar = new ProgressBar("Mana_" + p.Name, p.MaxMana,
                                          Color.MidnightBlue, Color.Blue, Color.Black, barSize);
                manaBar.Pos = new Vector2(xOffset,
                                          healthBar.Pos.Y + barSize.Y + barSpacing.Y);
                manaBar.Static = true;
                manaBar.Value  = p.MaxMana;

                p.ManaChanged += delegate(object obj, int value)
                {
                    manaBar.Value = value;
                };
                #endregion

                #region Spell Queue
                spellQueue     = new SpellQueue("Queue", theme, p);
                spellQueue.Pos = new Vector2(xOffset,
                                             healthBar.Pos.Y + barSize.Y + 2 * barSpacing.Y + barSize.Y);
                spellQueue.Static = true;

                #endregion
            }
Exemplo n.º 2
0
Arquivo: HUD.cs Projeto: nemec/4Realms
        internal void update()
        {
            tickCount = (tickCount + 1) % TicksPerScroll;
            if (onScreen.Count > 0 && tickCount == 0)
            {
                foreach (Text t in onScreen)
                {
                    t.Pos.Y -= 1;
                }

                Sprite fst = onScreen.First();
                if (fst.Pos.Y < Pos.Y)
                {
                    This.Game.CurrentLevel.RemoveSprite(fst);
                    onScreen.RemoveAt(0);
                }
            }
            if (buffer.Count != 0)
            {
                // We have room to scroll another line of text
                if (onScreen.Count == 0 ||
                    onScreen.Last().Pos.Y + onScreen.Last().GetAnimation().Height + TextSpacing <
                        Pos.Y + GetAnimation().Height - onScreen.Last().GetAnimation().Height)
                {
                    int width = GetAnimation().Width;
                    string toDisplay;

                    if (String.Join("", buffer.Take(2)) == "\n\n")
                    {
                        toDisplay = " ";
                        buffer.RemoveRange(0, 2);
                    }
                    else
                    {
                        buffer = buffer.SkipWhile(x => char.IsWhiteSpace(x)).ToList();
                        IEnumerable<char> pendingDisplay = buffer.TakeWhile((ch, ix) =>
                            theme.TextFont.MeasureString(
                                String.Join("", buffer.Take(ix + 1)).Trim()).X < width &&
                            ch != '\n');

                        if (SplitOnWhitespace &&
                            buffer.Count > pendingDisplay.Count() &&
                            buffer[pendingDisplay.Count()] != '\n')
                        {
                            // Find first instance of whitespace at end
                            pendingDisplay = pendingDisplay.Reverse().SkipWhile(x => !char.IsWhiteSpace(x)).Reverse();
                        }

                        toDisplay = String.Join("", pendingDisplay).Trim();
                        buffer.RemoveRange(0, pendingDisplay.Count());
                    }

                    Text line = new Text("text", theme.TextFont, toDisplay.ToString());
                    line.DisplayColor = theme.TextColor;
                    line.Pos = new Vector2(Pos.X, Pos.Y + GetAnimation().Height - line.GetAnimation().Height);
                    line.Static = true;
                    line.ZOrder = 101;
                    onScreen.Add(line);
                }
            }
        }
Exemplo n.º 3
0
Arquivo: HUD.cs Projeto: nemec/4Realms
            internal PlayerHUD(IHUDTheme theme, Player p, int xOffset, int yOffset)
            {
                #region Name
                Text name = new Text("player_name_" + p.Name, "Text", p.Name);
                name.DisplayColor = theme.TextColor;
                name.Pos = new Vector2(xOffset, yOffset);
                name.Static = true;
                #endregion

                #region HealthBar
                healthBar = new ProgressBar("Health_" + p.Name, p.MaxHealth,
                    Color.DarkRed, Color.Firebrick, Color.Black, barSize);
                healthBar.Pos = new Vector2(xOffset, name.Pos.Y + name.GetAnimation().Height);
                healthBar.Static = true;
                healthBar.Value = p.MaxHealth;

                p.HealthChanged += delegate(object obj, int value)
                {
                    healthBar.Value = value;
                    if (value == 0)
                    {
                        name.DisplayColor = Color.Tomato;
                    }
                    else
                    {
                        name.DisplayColor = theme.TextColor;
                    }
                };
                #endregion

                #region ManaBar
                manaBar = new ProgressBar("Mana_" + p.Name, p.MaxMana,
                    Color.MidnightBlue, Color.Blue, Color.Black, barSize);
                manaBar.Pos = new Vector2(xOffset,
                    healthBar.Pos.Y + barSize.Y + barSpacing.Y);
                manaBar.Static = true;
                manaBar.Value = p.MaxMana;

                p.ManaChanged += delegate(object obj, int value)
                {
                    manaBar.Value = value;
                };
                #endregion

                #region Spell Queue
                spellQueue = new SpellQueue("Queue", theme, p);
                spellQueue.Pos = new Vector2(xOffset,
                    healthBar.Pos.Y + barSize.Y + 2 * barSpacing.Y + barSize.Y);
                spellQueue.Static = true;

                #endregion
            }
Exemplo n.º 4
0
Arquivo: HUD.cs Projeto: nemec/4Realms
        internal void update()
        {
            tickCount = (tickCount + 1) % TicksPerScroll;
            if (onScreen.Count > 0 && tickCount == 0)
            {
                foreach (Text t in onScreen)
                {
                    t.Pos.Y -= 1;
                }

                Sprite fst = onScreen.First();
                if (fst.Pos.Y < Pos.Y)
                {
                    This.Game.CurrentLevel.RemoveSprite(fst);
                    onScreen.RemoveAt(0);
                }
            }
            if (buffer.Count != 0)
            {
                // We have room to scroll another line of text
                if (onScreen.Count == 0 ||
                    onScreen.Last().Pos.Y + onScreen.Last().GetAnimation().Height + TextSpacing <
                    Pos.Y + GetAnimation().Height - onScreen.Last().GetAnimation().Height)
                {
                    int    width = GetAnimation().Width;
                    string toDisplay;

                    if (String.Join("", buffer.Take(2)) == "\n\n")
                    {
                        toDisplay = " ";
                        buffer.RemoveRange(0, 2);
                    }
                    else
                    {
                        buffer = buffer.SkipWhile(x => char.IsWhiteSpace(x)).ToList();
                        IEnumerable <char> pendingDisplay = buffer.TakeWhile((ch, ix) =>
                                                                             theme.TextFont.MeasureString(
                                                                                 String.Join("", buffer.Take(ix + 1)).Trim()).X < width &&
                                                                             ch != '\n');

                        if (SplitOnWhitespace &&
                            buffer.Count > pendingDisplay.Count() &&
                            buffer[pendingDisplay.Count()] != '\n')
                        {
                            // Find first instance of whitespace at end
                            pendingDisplay = pendingDisplay.Reverse().SkipWhile(x => !char.IsWhiteSpace(x)).Reverse();
                        }

                        toDisplay = String.Join("", pendingDisplay).Trim();
                        buffer.RemoveRange(0, pendingDisplay.Count());
                    }

                    Text line = new Text("text", theme.TextFont, toDisplay.ToString());
                    line.DisplayColor = theme.TextColor;
                    line.Pos          = new Vector2(Pos.X, Pos.Y + GetAnimation().Height - line.GetAnimation().Height);
                    line.Static       = true;
                    line.ZOrder       = 101;
                    onScreen.Add(line);
                }
            }
        }
Exemplo n.º 5
0
Arquivo: HUD.cs Projeto: nemec/4Realms
        private IEnumerable States()
        {
            while (true)
            {
                if (pendingText.Count > 0)
                {
                    toDisplay.Content = pendingText.Dequeue();
                    Vector2 displayPos = new Vector2();

                    #region X values
                    switch (Anchor)
                    {
                    case Orientations.Right:
                        displayPos.X = Pos.X - toDisplay.GetAnimation().Width;
                        break;

                    case Orientations.Up_Right:
                        goto case Orientations.Right;

                    case Orientations.Down_Right:
                        goto case Orientations.Right;

                    case Orientations.Left:
                        goto default;

                    case Orientations.Up_Left:
                        goto case Orientations.Left;

                    case Orientations.Down_Left:
                        goto case Orientations.Left;

                    default:
                        displayPos.X = Pos.X;
                        break;
                    }
                    #endregion

                    #region Y values
                    switch (Anchor)
                    {
                    case Orientations.Down:
                        displayPos.Y = Pos.Y - toDisplay.GetAnimation().Height;
                        break;

                    case Orientations.Down_Left:
                        goto case Orientations.Down;

                    case Orientations.Down_Right:
                        goto case Orientations.Down;

                    case Orientations.Up:
                        goto default;

                    case Orientations.Up_Left:
                        goto case Orientations.Up;

                    case Orientations.Up_Right:
                        goto case Orientations.Up;

                    default:
                        displayPos.Y = Pos.Y;
                        break;
                    }
                    #endregion
                    toDisplay.Pos     = displayPos;
                    toDisplay.Visible = true;

                    mAlpha = 0;
                    toDisplay.DisplayColor = (theme.TextColor * mAlpha);

                    foreach (string type in new string[] { "in", "out" })
                    {
                        // Leave faded in (or out) for mFadeDelay time
                        TimeSpan endTime = This.gameTime.TotalGameTime + mFadeDelay;
                        while (This.gameTime.TotalGameTime < endTime)
                        {
                            yield return(null);
                        }

                        while (mAlpha >= 0 && mAlpha <= 1)
                        {
                            toDisplay.DisplayColor = (theme.TextColor * mAlpha);
                            mAlpha += mFadeIncrement;
                            yield return(null);
                        }

                        mAlpha         -= mFadeIncrement; // Put it back within alpha range
                        mFadeIncrement *= -1;             // Reverse fade direction
                    }
                    toDisplay.Visible = false;
                }

                yield return(null);
            }
        }