示例#1
0
        public void AddLine(string text)
        {
            int textHeight = console.GetVarInt(string.Format("{0}.profile.fontSize", this)) + console.GetVarInt(string.Format("{0}.lineSpacing", this));

            if (textHeight <= 0)
            {
                textHeight = 12;
            }

            string scrollBox = getGroup();
            //See if the two are eqaul, and if they are use the split instead of the getword.
            //int chatScrollHeight = Util.getWord(con.GetVarString(string.Format("{0}.extent", scrollBox)), 1).AsInt() -
            //                       2 * con.GetVarInt(string.Format("{0}.profile.borderThickness", scrollBox));

            int chatScrollHeight = console.GetVarString(string.Format("{0}.extent", scrollBox)).Split(' ')[1].AsInt() - 2 * console.GetVarInt(string.Format("{0}.profile.borderThickness", scrollBox));

            int chatPosition = Util.getWord(console.GetVarString(string.Format("{0}.extent", this)), 1).AsInt() - chatScrollHeight + Util.getWord(console.GetVarString(string.Format("{0}.position", this)), 1).AsInt() - console.GetVarInt(string.Format("{0}.profile.borderThickness", scrollBox));

            int linesToScroll = (int)Math.Floor(((chatPosition) / ((double)textHeight) + .5));

            string origPosition = "";

            if (linesToScroll > 0)
            {
                origPosition = console.GetVarString(string.Format("{0}.position", this));
            }

            GuiButtonCtrl chatPageDown     = "chatPageDown";
            MessageVector HudMessageVector = "HudMessageVector";

            //remove old messages from the top only if scrolled down all the way
            while (!chatPageDown.isVisible() && HudMessageVector.getNumLines() > 0 && HudMessageVector.getNumLines() >= iGlobal["$pref::HudMessageLogSize"])
            {
                string tag = ((MessageVector)"HudMessageVector").getLineTag(0).AsString();
                if (tag.AsInt() != 0)
                {
                    tag.delete();
                }
                ((MessageVector)"HudMessageVector").popFrontLine();
            }
            //add the message...
            ((MessageVector)"HudMessageVector").pushBackLine(text, console.GetVarInt("$LastHudTarget"));
            console.SetVar("$LastHudTarget", 0);
            //now that we've added the message, see if we need to reset the position
            if (linesToScroll > 0)
            {
                ((GuiControl)"ChatPageDown").setVisible(true);
                console.SetVar(this + ".position", origPosition);
            }
            else
            {
                ((GuiControl)"ChatPageDown").setVisible(false);
            }
        }