예제 #1
0
        private IMenuItem CreateUserBlock(string username, ChatObj chat)
        {
            MenuItemGrid item          = new MenuItemGrid(username, 5, 3);
            MenuItemText usernameBlock = new MenuItemText("username");

            item.AddChild(0, 0, 4, 1, usernameBlock);
            usernameBlock.SetText(username);
            usernameBlock.SetFontSize(8, 15);
            usernameBlock.SetTextStyle(UnityEngine.FontStyle.Bold);
            MenuItemText lastMsgBlock = new MenuItemText("lastMsg");

            item.AddChild(0, 1, 4, 2, lastMsgBlock);
            string text = chat.Messages.Last().Message;

            if (text.Length > MAX_MSG_LEN)
            {
                text  = text.Substring(0, MAX_MSG_LEN - 3);
                text += "...";
            }
            lastMsgBlock.SetText(text);
            lastMsgBlock.SetFontSize(5, 10);
            lastMsgBlock.SetAlignment(UnityEngine.TextAnchor.MiddleLeft);
            MenuItemButton openChat = new MenuItemButton("openChat");

            item.AddChild(4, 0, 1, 3, openChat);
            openChat.SetText(">");
            openChat.Clicked += () => ChatSelected?.Invoke(chat);
            return(item);
        }
예제 #2
0
        private IMenuItem CreateBlock(FriendsAppUser friend)
        {
            MenuItemGrid item     = new MenuItemGrid(friend.Username, 5, 1);
            MenuItemText username = new MenuItemText("username");

            item.AddChild(0, 0, 4, 1, username);
            username.SetText(friend.Username);
            username.SetFontSize(8, 15);
            username.SetTextStyle(UnityEngine.FontStyle.Bold);
            MenuItemButton selectButton = new MenuItemButton("selectButton");

            item.AddChild(4, 0, 1, 1, selectButton);
            selectButton.SetText(">");
            selectButton.Clicked += () => FriendSelected?.Invoke(friend.UserId);
            return(item);
        }
예제 #3
0
        public IMenuItem CreateMessageObj(ChatObjMsg msg)
        {
            int          lines  = (int)Math.Ceiling(msg.Message.Length / (float)CHARS_PER_LINE) + 1;
            MenuItemGrid item   = new MenuItemGrid(msg.Time.ToString(), 1, lines);
            MenuItemText header = new MenuItemText("header");

            item.AddChild(0, 0, 1, 1, header);
            header.SetTextStyle(FontStyle.Bold);
            header.SetFontSize(5, HEADER_FONT_SIZE);
            TextAnchor alignment;

            if (msg.From == _userId)
            {
                alignment = TextAnchor.MiddleRight;
                header.SetText("You");
            }
            else
            {
                alignment = TextAnchor.MiddleLeft;
                header.SetText(_toUsername);
            }
            header.SetAlignment(alignment);
            string       text = msg.Message;
            int          i;
            string       textPart;
            MenuItemText message;

            for (i = 0; i < lines - 2; ++i)
            {
                textPart = text.Substring(i * CHARS_PER_LINE, CHARS_PER_LINE);
                message  = new MenuItemText($"message_line{i+1}");
                message.SetFontSize(5, FONT_SIZE);
                message.SetText(textPart);
                message.SetAlignment(alignment);
                item.AddChild(0, i + 1, 1, 1, message);
            }
            textPart = text.Substring(i * CHARS_PER_LINE);
            message  = new MenuItemText($"message_line{i + 1}");
            message.SetFontSize(5, FONT_SIZE);
            message.SetText(textPart);
            message.SetAlignment(alignment);
            item.AddChild(0, i + 1, 1, 1, message);
            return(item);
        }