コード例 #1
0
ファイル: EmojiHelper.cs プロジェクト: 442803117/EmojiDotNet
        /// <summary>
        /// 通过图标路径获得表情的UTF字符串
        /// 该字符串可以直接发送给IOS 和 Android
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static string ConvertEmojiToString(string url)
        {
            string    emojiString = string.Empty;
            EmojiItem emojiItem   = null;

            if (DefaultsEmojis.Instance.IcoToEmojiDictionary.TryGetValue(url, out emojiItem))
            {
                if (emojiItem != null)
                {
                    string[] codeArr = emojiItem.Code.Split('_');
                    foreach (string subCode in codeArr)
                    {
                        if (((DefaultsEmojiItem)emojiItem).IsShort)
                        {
                            emojiString += EmojiHelper.ShortToUtf16String(subCode.Replace("0x", ""));
                        }
                        else
                        {
                            emojiString += EmojiHelper.Int32ToUtf16String(subCode.Replace("0x", ""));
                        }
                    }
                    return(emojiString);
                }
            }

            return(String.Empty);
        }
コード例 #2
0
 private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (this.MainListBox.SelectedItems.Count > 0)
     {
         this.selectedEmojiItem = (EmojiItem)this.MainListBox.SelectedItems[0];
     }
 }
コード例 #3
0
 private void FillEmojiToField(GameObject obj, EmojiItem ei)
 {
     if (null != obj)
     {
         UIInput expr_12 = this.content;
         expr_12.value += ei.EmojiName;
         this.GetSetEmojiPanelState(false);
     }
 }
コード例 #4
0
ファイル: EmojiHelper.cs プロジェクト: 442803117/EmojiDotNet
/// <summary>
/// 通过表情的UTF字符串,取得表情图标的路径
/// </summary>
/// <param name="code"></param>
/// <returns></returns>
        public static string GetEmojiIcoPath(string code)
        {
            EmojiItem emojiItem = null;

            if (DefaultsEmojis.Instance.EmojiToIcoDictionary.TryGetValue(code, out emojiItem))
            {
                return(emojiItem.ImgPath);
            }

            return(string.Empty);
        }
コード例 #5
0
ファイル: ChatPanel.cs プロジェクト: iLOVECris/CarWar
    private void AddEmojiToRoot()
    {
        string resname = null;

        for (int index = 1; index < (GameData.EmojiCount + 1); index++)
        {
            resname = EmojiName + index.ToString();
            EmojiItem item = UIManager.AddItem <EmojiItem>("EmojiItem", EmojiItemRoot.transform);
            item.SetEmoji(resname);
            item.Emoji_Id = index;
            ButtonClickListener listener = item.gameObject.AddComponent <ButtonClickListener>();
            listener.onClick = SendEmoji;
        }
    }
コード例 #6
0
 public override void Init()
 {
     base.Init();
     this.mgs = new object[]
     {
         ClientV2C.chatviewInitRoom,
         ClientV2C.chatviewOpenEmotion,
         ClientV2C.chatviewCloseEmotion,
         ClientC2V.ReceiveHallChatMessage,
         ClientC2C.WaitServerResponseTimeOut
     };
     this.Anchor                         = this.transform.Find("Anchor");
     this.hallToggle                     = this.Anchor.Find("Panel/Lounge").GetComponent <UIToggle>();
     this.friendToggle                   = this.Anchor.Find("Panel/Friend").GetComponent <UIToggle>();
     this.lobbyToggle                    = this.Anchor.Find("Panel/Room").GetComponent <UIToggle>();
     this.hallLabel                      = this.hallToggle.transform.Find("Label").GetComponent <UILabel>();
     this.friendLabel                    = this.friendToggle.transform.Find("Label").GetComponent <UILabel>();
     this.lobbyLabel                     = this.lobbyToggle.transform.Find("Label").GetComponent <UILabel>();
     this.BG                             = this.Anchor.Find("BG");
     this.emojiBG                        = this.Anchor.Find("Panel/EmojiBG");
     this.CloseBtn                       = this.Anchor.Find("BG/CloseBtn");
     this.FriendLst                      = this.Anchor.Find("FriendChat/FriendLst");
     this.FriendChat                     = this.Anchor.Find("FriendChat/Chat");
     this._friendChat                    = this.Anchor.GetComponent <FriendChat>();
     this.emojiList                      = this.Anchor.Find("EmojiLst");
     this.emoGrid                        = this.emojiList.Find("Scroll View/Grid").GetComponent <UIGrid>();
     this.friendNewsPoint                = this.Anchor.Find("Panel/Friend/Point");
     this._roomChat                      = this.Anchor.GetComponent <RoomChat>();
     this.playerInfoController           = this.Anchor.GetComponent <ChatPlayerInfoController>();
     this.tween_position                 = this.transform.GetComponent <TweenPosition>();
     this.markPoint                      = this.Anchor.Find("Panel/Lounge/Mark");
     this.hallEmojiField                 = this.Anchor.Find("HallChat/LoudSpeaker/InputField").GetComponent <UIInput>();
     this.friendEmojiField               = this.Anchor.Find("FriendChat/Chat/InputField").GetComponent <UIInput>();
     this.lobbyEmojiField                = this.Anchor.Find("RoomChat/Chat/InputField").GetComponent <UIInput>();
     this.emojiItem                      = Resources.Load <EmojiItem>("Prefab/UI/HomeChat/emojiItem");
     this.dsv                            = this.Anchor.Find("BG").GetComponent <UIDragScrollView>();
     this.hallScrollView                 = this.Anchor.Find("HallChat/MessageBox").GetComponent <UIScrollView>();
     this.friendScrollView               = this.Anchor.Find("FriendChat/Chat/MessageBox").GetComponent <UIScrollView>();
     this.roomScrollView                 = this.Anchor.Find("RoomChat/MessageBox").GetComponent <UIScrollView>();
     this.dicToggle[ChitchatType.Hall]   = this.hallToggle;
     this.dicToggle[ChitchatType.Friend] = this.friendToggle;
     this.dicToggle[ChitchatType.Lobby]  = this.lobbyToggle;
     EventDelegate.Add(this.hallToggle.onChange, new EventDelegate.Callback(this.ChangeToggle));
     EventDelegate.Add(this.friendToggle.onChange, new EventDelegate.Callback(this.ChangeToggle));
     EventDelegate.Add(this.lobbyToggle.onChange, new EventDelegate.Callback(this.ChangeToggle));
     UIEventListener.Get(this.CloseBtn.gameObject).onClick = new UIEventListener.VoidDelegate(this.CloseChatView);
     this.userID    = long.Parse(ModelManager.Instance.Get_userData_X().UserId);
     this.coroutine = new CoroutineManager();
 }
コード例 #7
0
 public override void Init()
 {
     base.Init();
     this.closeBtn    = this.transform.Find("BackBtn");
     this.confirmSend = this.transform.Find("ConfirmSend");
     this.emojiList   = this.transform.Find("EmojiLst");
     this.trumpet     = this.transform.Find("Trumpets");
     this.emoGrid     = this.emojiList.Find("Scroll View/Grid").GetComponent <UIGrid>();
     this.content     = this.transform.Find("InputField").GetComponent <UIInput>();
     this.emojiBtn    = this.transform.Find("Emoji").GetComponent <UISprite>();
     this.numLimit    = this.transform.Find("LimitNum").GetComponent <UILabel>();
     this.countLabel  = this.trumpet.Find("Count").GetComponent <UILabel>();
     this.emojiItem   = Resources.Load <EmojiItem>("Prefab/UI/HomeChat/emojiItem");
     UIEventListener.Get(this.closeBtn.gameObject).onClick    = new UIEventListener.VoidDelegate(this.CloseView);
     UIEventListener.Get(this.confirmSend.gameObject).onClick = new UIEventListener.VoidDelegate(this.ConfirmSendMessage);
     UIEventListener.Get(this.emojiBtn.gameObject).onClick    = new UIEventListener.VoidDelegate(this.ShowEmotionPanel);
     this.content.defaultText = "点此输入文字";
 }
コード例 #8
0
 private void FillEmojiToField(GameObject obj, EmojiItem ei)
 {
     if (null != obj)
     {
         ChitchatType chitchatType = this.currType;
         if (chitchatType != ChitchatType.Friend)
         {
             if (chitchatType == ChitchatType.Lobby)
             {
                 UIInput expr_4D = this.lobbyEmojiField;
                 expr_4D.value += ei.EmojiName;
             }
         }
         else
         {
             UIInput expr_2C = this.friendEmojiField;
             expr_2C.value += ei.EmojiName;
         }
         this.GetSetEmojiPanelState(false, this.nowSprite);
     }
 }
コード例 #9
0
ファイル: TextAndGraphics.cs プロジェクト: swicksu/UGUI_Demo
    private Vector2 InitItem(Match match, EmojiItem item)
    {
        string       keyContent = match.Groups[0].Value;
        EmojiTypeKey type       = EmojiTypeKey.S;
        string       id         = "";

        EmojiConfig.Instance.GetEmojiInfo(keyContent, ref type, ref id);
        Vector2 defaultSize  = Vector2.zero;
        bool    adpativeSize = false;

        switch (type)
        {
        case EmojiTypeKey.V:
            VideoData videoData = EmojiConfig.Instance.GetVideoData(id);
            item.PlayVideo(videoData.VideoClip);
            defaultSize  = videoData.DefaultSize;
            adpativeSize = videoData.AdaptiveSize;
            break;

        case EmojiTypeKey.S:
            SpriteData spriteData = EmojiConfig.Instance.GetSpriteData(id);
            item.SetSprite(spriteData.Sprite);
            defaultSize  = spriteData.DefaultSize;
            adpativeSize = spriteData.AdaptiveSize;
            break;

        default:
            throw new ArgumentOutOfRangeException();
        }

        if (adpativeSize)
        {
            defaultSize = Vector2.one * fontSize;
        }

        item.SetSize(type, defaultSize);

        return(defaultSize);
    }
コード例 #10
0
ファイル: EmojiHelper.cs プロジェクト: 442803117/EmojiDotNet
        /// <summary>
        /// 把包含表情的字符串进行解析
        /// </summary>
        /// <param name="text">文本消息内容</param>
        public static List <WordItem> ConvertTextToEmoji(string text)
        {
            List <WordItem> wordsList = new List <WordItem>();
            int             skip;
            int             textLengthToProcess = text.Length;

            if (textLengthToProcess == 0)
            {
                return(null);
            }
            StringBuilder textBuilder = new StringBuilder(); // 文字消息

            for (int i = 0; i < text.Length; i += skip)
            {
                skip = 0;
                string icon    = string.Empty;
                int    unicode = char.ConvertToUtf32(text, i);
                skip = char.IsSurrogatePair(text, i) ? 2 : 1;
                if (unicode > 0xff)
                {
                    icon = "0x" + unicode.ToString("x2");
                    if (!DefaultsEmojis.Instance.EmojiToIcoDictionary.ContainsKey(icon))
                    {
                        icon = string.Empty;
                    }
                }
                if (icon.Equals(string.Empty) && i + skip < textLengthToProcess)
                {
                    int followUnicode = char.ConvertToUtf32(text, i + skip);
                    if (followUnicode == 0x20e3)
                    {
                        int followSkip = char.IsSurrogatePair(text, i + skip) ? 2 : 1;
                        if ((unicode >= 0x0030 && unicode <= 0x0039) || 0x0023 == unicode)
                        {
                            icon = "0x" + unicode.ToString("x2") + "_0x20e3";
                        }
                        else
                        {
                            followSkip = 0;
                        }
                        skip += followSkip;
                    }
                    else
                    {
                        int followSkip = char.IsSurrogatePair(text, i + skip) ? 2 : 1;
                        switch (unicode)
                        {
                        case 0x1f1ef:
                            icon = (followUnicode == 0x1f1f5) ? "0x1f1ef_0x1f1f5"
                               : string.Empty;
                            break;

                        case 0x1f1fa:
                            icon = (followUnicode == 0x1f1f8) ? "0x1f1fa_0x1f1f8"
                               : string.Empty;
                            break;

                        case 0x1f1eb:
                            icon = (followUnicode == 0x1f1f7) ? "0x1f1eb_0x1f1f7"
                               : string.Empty;
                            break;

                        case 0x1f1e9:
                            icon = (followUnicode == 0x1f1ea) ? "0x1f1e9_0x1f1ea"
                               : string.Empty;
                            break;

                        case 0x1f1ee:
                            icon = (followUnicode == 0x1f1f9) ? "0x1f1ee_0x1f1f9"
                               : string.Empty;
                            break;

                        case 0x1f1ec:
                            icon = (followUnicode == 0x1f1e7) ? "0x1f1ec_0x1f1e7"
                               : string.Empty;
                            break;

                        case 0x1f1ea:
                            icon = (followUnicode == 0x1f1f8) ? "0x1f1ea_0x1f1f8"
                               : string.Empty;
                            break;

                        case 0x1f1f7:
                            icon = (followUnicode == 0x1f1fa) ? "0x1f1f7_0x1f1fa"
                               : string.Empty;
                            break;

                        case 0x1f1e8:
                            icon = (followUnicode == 0x1f1f3) ? "0x1f1e8_0x1f1f3"
                               : string.Empty;
                            break;

                        case 0x1f1f0:
                            icon = (followUnicode == 0x1f1f7) ? "0x1f1f0_0x1f1f7"
                               : string.Empty;
                            break;

                        default:
                            followSkip = 0;
                            break;
                        }
                        skip += followSkip;
                    }
                }

                if (!icon.Equals(string.Empty))
                {
                    // 表情符号的场合
                    EmojiItem emojiItem = null;
                    if (DefaultsEmojis.Instance.EmojiToIcoDictionary.TryGetValue(icon, out emojiItem))
                    {
                        string iconPath = emojiItem.ImgPath;
                        if (textBuilder.Length > 0)
                        {
                            // 把表情符号前面的文字创建出来
                            WordItem txtItem = new WordItem();
                            txtItem.Type    = WordType.Text;
                            txtItem.Content = textBuilder.ToString();
                            wordsList.Add(txtItem);
                            textBuilder.Clear();
                        }
                        // 找到表情图标,创建表情控件
                        WordItem imgItem = new WordItem();
                        imgItem.Type    = WordType.Emoji;
                        imgItem.Content = iconPath;
                        wordsList.Add(imgItem);
                    }
                    else
                    {
                        // 没有找到表情图标,直接当作普通字符输出
                        textBuilder.Append(text.Substring(i, skip));
                    }
                }
                else
                {
                    // 普通文字的场合
                    string currChar = text.Substring(i, 1);
                    if (currChar.Equals(Environment.NewLine))
                    {
                        // 换行符的场合
                        if (textBuilder.Length > 0)
                        {
                            // 生成前面的文字
                            WordItem txtItem = new WordItem();
                            txtItem.Type    = WordType.Text;
                            txtItem.Content = textBuilder.ToString();
                            wordsList.Add(txtItem);
                            textBuilder.Clear();
                        }
                        // 生成换行
                        LineBreak lineBreak = new LineBreak();
                        WordItem  warpItem  = new WordItem();
                        warpItem.Type    = WordType.Wrap;
                        warpItem.Content = string.Empty;
                        wordsList.Add(warpItem);
                    }
                    else
                    {
                        // 除换行符意外的普通文字
                        textBuilder.Append(text.Substring(i, 1));
                    }
                }
            }
            if (textBuilder.Length > 0)
            {
                // 生成前面的文字
                WordItem txtItem = new WordItem();
                txtItem.Type    = WordType.Text;
                txtItem.Content = textBuilder.ToString();
                wordsList.Add(txtItem);
                textBuilder.Clear();
            }

            return(wordsList);
        }
コード例 #11
0
ファイル: EmojiHelper.cs プロジェクト: 442803117/EmojiDotNet
        /// <summary>
        /// 把包含表情的字符串中的表情替换为表情图片
        /// </summary>
        /// <param name="text">文本消息内容</param>
        /// <param name="txtBlock">显示消息控件</param>
        /// <param name="imgWidth">表情图标的宽度</param>
        /// <param name="imgHeight">表情图标的高度</param>
        public static void ReplaceEmojiToIco(string text, TextBlock txtBlock, int imgWidth = 24, int imgHeight = 24)
        {
            if (null == txtBlock)
            {
                return;
            }
            txtBlock.Inlines.Clear();

            int           skip;
            int           textLengthToProcess = text.Length;
            StringBuilder textBuilder         = new StringBuilder(); // 文字消息

            for (int i = 0; i < text.Length; i += skip)
            {
                skip = 0;
                string icon    = string.Empty;
                int    unicode = char.ConvertToUtf32(text, i);
                skip = char.IsSurrogatePair(text, i) ? 2 : 1;
                if (unicode > 0xff)
                {
                    icon = "0x" + unicode.ToString("x2");
                    if (!DefaultsEmojis.Instance.EmojiToIcoDictionary.ContainsKey(icon))
                    {
                        icon = string.Empty;
                    }
                }
                if (icon.Equals(string.Empty) && i + skip < textLengthToProcess)
                {
                    int followUnicode = char.ConvertToUtf32(text, i + skip);
                    if (followUnicode == 0x20e3)
                    {
                        int followSkip = char.IsSurrogatePair(text, i + skip) ? 2 : 1;
                        if ((unicode >= 0x0030 && unicode <= 0x0039) || 0x0023 == unicode)
                        {
                            icon = "0x" + unicode.ToString("x2") + "_0x20e3";
                        }
                        else
                        {
                            followSkip = 0;
                        }
                        skip += followSkip;
                    }
                    else
                    {
                        int followSkip = char.IsSurrogatePair(text, i + skip) ? 2 : 1;
                        switch (unicode)
                        {
                        case 0x1f1ef:
                            icon = (followUnicode == 0x1f1f5) ? "0x1f1ef_0x1f1f5"
                               : string.Empty;
                            break;

                        case 0x1f1fa:
                            icon = (followUnicode == 0x1f1f8) ? "0x1f1fa_0x1f1f8"
                               : string.Empty;
                            break;

                        case 0x1f1eb:
                            icon = (followUnicode == 0x1f1f7) ? "0x1f1eb_0x1f1f7"
                               : string.Empty;
                            break;

                        case 0x1f1e9:
                            icon = (followUnicode == 0x1f1ea) ? "0x1f1e9_0x1f1ea"
                               : string.Empty;
                            break;

                        case 0x1f1ee:
                            icon = (followUnicode == 0x1f1f9) ? "0x1f1ee_0x1f1f9"
                               : string.Empty;
                            break;

                        case 0x1f1ec:
                            icon = (followUnicode == 0x1f1e7) ? "0x1f1ec_0x1f1e7"
                               : string.Empty;
                            break;

                        case 0x1f1ea:
                            icon = (followUnicode == 0x1f1f8) ? "0x1f1ea_0x1f1f8"
                               : string.Empty;
                            break;

                        case 0x1f1f7:
                            icon = (followUnicode == 0x1f1fa) ? "0x1f1f7_0x1f1fa"
                               : string.Empty;
                            break;

                        case 0x1f1e8:
                            icon = (followUnicode == 0x1f1f3) ? "0x1f1e8_0x1f1f3"
                               : string.Empty;
                            break;

                        case 0x1f1f0:
                            icon = (followUnicode == 0x1f1f7) ? "0x1f1f0_0x1f1f7"
                               : string.Empty;
                            break;

                        default:
                            followSkip = 0;
                            break;
                        }
                        skip += followSkip;
                    }
                }
                //}

                if (!icon.Equals(string.Empty))
                {
                    // 表情符号的场合
                    EmojiItem emojiItem = null;
                    if (DefaultsEmojis.Instance.EmojiToIcoDictionary.TryGetValue(icon, out emojiItem))
                    {
                        string iconPath = emojiItem.ImgPath;
                        if (textBuilder.Length > 0)
                        {
                            // 把表情符号前面的文字创建出来
                            Run textrRun = new Run();
                            textrRun.Text = textBuilder.ToString();
                            txtBlock.Inlines.Add(textrRun);
                            textBuilder.Clear();
                        }
                        // 找到表情图标,创建表情控件
                        Image imgMessage = new Image();
                        imgMessage.Width  = imgWidth;
                        imgMessage.Height = imgHeight;
                        BitmapImage bImg = new BitmapImage();
                        imgMessage.IsEnabled = true;
                        bImg.BeginInit();
                        bImg.UriSource = new Uri(iconPath, UriKind.RelativeOrAbsolute);
                        bImg.EndInit();
                        imgMessage.Source = bImg;
                        InlineUIContainer iuc = new InlineUIContainer(imgMessage);
                        txtBlock.Inlines.Add(iuc);
                    }
                    else
                    {
                        // 没有找到表情图标,直接当作普通字符输出
                        textBuilder.Append(text.Substring(i, skip));
                    }
                }
                else
                {
                    // 普通文字的场合
                    string currChar = text.Substring(i, 1);
                    if (currChar.Equals(Environment.NewLine))
                    {
                        // 换行符的场合
                        if (textBuilder.Length > 0)
                        {
                            // 生成前面的文字
                            Run textrRun = new Run();
                            textrRun.Text = textBuilder.ToString();
                            txtBlock.Inlines.Add(textrRun);
                            textBuilder.Clear();
                        }
                        // 生成换行
                        LineBreak lineBreak = new LineBreak();
                        txtBlock.Inlines.Add(lineBreak);
                    }
                    else
                    {
                        // 除换行符意外的普通文字
                        textBuilder.Append(text.Substring(i, 1));
                    }
                }
            }
            if (textBuilder.Length > 0)
            {
                // 生成前面的文字
                Run textrRun = new Run();
                textrRun.Text = textBuilder.ToString();
                txtBlock.Inlines.Add(textrRun);
                textBuilder.Clear();
            }
        }