Esempio n. 1
0
        void UpdateBlockInfoString(Block block)
        {
            if (normalNames == null)
            {
                MakeNormalNames();
            }

            int index = 0;

            buffer.Clear();
            buffer.Append(ref index, "&f");
            string value = game.BlockInfo.Name[(byte)block];

            if ((byte)block < BlockInfo.CpeBlocksCount && value == "Invalid")
            {
                buffer.Append(ref index, normalNames[(byte)block]);
            }
            else
            {
                buffer.Append(ref index, value);
            }
            buffer.Append(ref index, " (ID: ");
            buffer.AppendNum(ref index, (byte)block);
            buffer.Append(ref index, ", place: ");
            buffer.Append(ref index, game.Inventory.CanPlace[(int)block] ? "&aYes" : "&cNo");
            buffer.Append(ref index, "&f, delete: ");
            buffer.Append(ref index, game.Inventory.CanDelete[(int)block] ? "&aYes" : "&cNo");
            buffer.Append(ref index, "&f)");
        }
        void TabKey()
        {
            int pos   = caretPos == -1 ? chatInputText.Length - 1 : caretPos;
            int start = pos;

            char[] value = chatInputText.value;

            while (start >= 0 && Char.IsLetterOrDigit(value[start]))
            {
                start--;
            }
            start++;
            if (pos < 0 || start > pos)
            {
                return;
            }

            string        part    = new String(value, start, pos + 1 - start);
            List <string> matches = new List <string>();

            game.Chat.Add(null, MessageType.ClientStatus5);

            bool extList = game.Network.UsingExtPlayerList;

            CpeListInfo[] info    = game.CpePlayersList;
            Player[]      players = game.Players.Players;
            for (int i = 0; i < EntityList.MaxCount; i++)
            {
                if (extList && info[i] == null)
                {
                    continue;
                }
                if (!extList && players[i] == null)
                {
                    continue;
                }

                string rawName = extList ? info[i].PlayerName : players[i].DisplayName;
                string name    = Utils.StripColours(rawName);
                if (name.StartsWith(part, StringComparison.OrdinalIgnoreCase))
                {
                    matches.Add(name);
                }
            }

            if (matches.Count == 1)
            {
                if (caretPos == -1)
                {
                    pos++;
                }
                int len = pos - start;
                for (int i = 0; i < len; i++)
                {
                    chatInputText.DeleteAt(start);
                }
                if (caretPos != -1)
                {
                    caretPos -= len;
                }
                AppendText(matches[0]);
            }
            else if (matches.Count > 1)
            {
                StringBuffer buffer = new StringBuffer(64);
                int          index  = 0;
                buffer.Append(ref index, "&e");
                buffer.AppendNum(ref index, matches.Count);
                buffer.Append(ref index, " matching names: ");

                foreach (string match in matches)
                {
                    if ((match.Length + 1 + buffer.Length) > 64)
                    {
                        break;
                    }
                    buffer.Append(ref index, match);
                    buffer.Append(ref index, ' ');
                }
                game.Chat.Add(buffer.ToString(), MessageType.ClientStatus5);
            }
        }