public override void Entry(IModHelper helper)
        {
            oHelper  = helper;
            oManager = new BubbleGuyManager(Path.Combine(helper.DirectoryPath, "saves"), Path.Combine(helper.DirectoryPath, "sprites"), helper, Monitor);
            BubbleChat.Initialize(oManager);
            helper.Events.GameLoop.SaveLoaded += GameLoop_SaveLoaded;

            Harmony harmony = new Harmony(ModManifest.UniqueID);

            harmony.Patch(
                original: AccessTools.Method(typeof(ChatBox), "runCommand", new Type[] { typeof(string) }),
                prefix: new HarmonyMethod(typeof(BubbleChat), nameof(BubbleChat.RunCommand))
                );

            Monitor.Log($"Harmony patch applied", LogLevel.Info);
        }
Exemple #2
0
 public void ClearChatPage()
 {
     _previousBubbleChat = null;
     _headBubbleChat     = null;
     spMessagesContainer.Children.Clear();
 }
Exemple #3
0
        public void SendLeftMessages(AbstractMessage msg, bool isSimulating = false, bool reversed = false, bool loadConversation = false)
        {
            Console.WriteLine(msg.SenderID);

            if (reversed)
            {
                if (_headBubbleChat == null)
                {
                    _headBubbleChat = new BubbleChat();
                    _headBubbleChat.SetAva(msg.SenderID);
                    _headBubbleChat.NickName.Foreground = iconColor.Foreground;
                    spMessagesContainer.Children.Insert(0, _headBubbleChat);
                }
            }
            else
            {
                if (_previousBubbleChat == null)
                {
                    _previousBubbleChat = new BubbleChat();
                    _previousBubbleChat.SetAva(msg.SenderID);
                    _previousBubbleChat.NickName.Foreground = iconColor.Foreground;
                    spMessagesContainer.Children.Add(_previousBubbleChat);
                }
            }

            Bubble          b         = null;
            ThumbnailBubble thumbnail = null;
            var             app       = MainWindow.chatApplication;

            if (BubbleTypeParser.Parse(msg) == BubbleType.Text)
            {
                b          = new Bubble();
                b.Messages = (msg as TextMessage).Message;
            }
            else if (BubbleTypeParser.Parse(msg) == BubbleType.Attachment)
            {
                b          = new Bubble();
                b.Messages = (msg as AttachmentMessage).FileName;
                b.SetLink((msg as AttachmentMessage).FileID);
            }
            else if (BubbleTypeParser.Parse(msg) == BubbleType.Image)
            {
                string    fileID   = (msg as ImageMessage).FileID;
                string    fileName = (msg as ImageMessage).FileName;
                MediaInfo media    = GetMediaInfo(fileID, fileName, app.model.currentSelectedConversation);
                thumbnail = new ThumbnailBubble(media);
                thumbnail.HorizontalAlignment = HorizontalAlignment.Left;
                thumbnail.Margin = new Thickness(5, 0, 0, 0);
                Console.WriteLine("Image sent");
                AddMedia(fileID, fileName, isSimulating);
            }
            else if (BubbleTypeParser.Parse(msg) == BubbleType.Video)
            {
                string    fileID   = (msg as VideoMessage).FileID;
                string    fileName = (msg as VideoMessage).FileName;
                MediaInfo media    = GetMediaInfo(fileID, fileName, app.model.currentSelectedConversation);
                thumbnail = new ThumbnailBubble(media);
                thumbnail.HorizontalAlignment = HorizontalAlignment.Left;
                thumbnail.Margin = new Thickness(5, 0, 0, 0);
                AddMedia(fileID, fileName, isSimulating);
            }
            else if (BubbleTypeParser.Parse(msg) == BubbleType.Sticker)
            {
                MessageCore.Sticker.Sticker sticker = (msg as StickerMessage).Sticker;
                MessageCore.Sticker.Sticker.LoadedStickers.TryGetValue(sticker.ID, out var result);
                SendStickerOnTheLeft(result, reversed, _previousBubbleChat, _headBubbleChat);
            }

            if (b != null)
            {
                b.Type = BubbleTypeParser.Parse(msg);
                b.ControlUpdate();

                b.SetSeen(false);
                b.SetBG(Color.FromRgb(246, 246, 246));
                b.SetDirect(true); // true = left false = right
            }

            if (reversed)
            {
                if (b != null)
                {
                    _headBubbleChat.InsertBubble(0, b);
                }
                if (thumbnail != null)
                {
                    _headBubbleChat.InsertMedia(thumbnail);
                }
                if (loadConversation)
                {
                    MessagesContainer.ScrollToEnd();
                }
                else
                {
                    MessagesContainer.ScrollToHome();
                }
            }
            else
            {
                if (b != null)
                {
                    _previousBubbleChat.AddBubble(b);
                }
                if (thumbnail != null)
                {
                    _previousBubbleChat.AddMedia(thumbnail);
                }
                MessagesContainer.ScrollToEnd();
            }

            if (thumbnail != null)
            {
                thumbnail.Click += ThumbnailClick;
            }

            app.model.CurrentUserMessages.Add(new BubbleInfo(msg, true));
            app.model.Conversations[app.model.currentSelectedConversation].Bubbles.Add(new BubbleInfo(msg, true));
        }
Exemple #4
0
        public void SendMessage(AbstractMessage msg, bool isSimulating = false, bool reversed = false, bool loadConversation = false) //on the Rightside
        {
            if (reversed)
            {
                _headBubbleChat = null;
            }
            else
            {
                _previousBubbleChat = null;
            }

            Bubble          b         = null;
            ThumbnailBubble thumbnail = null;
            var             app       = MainWindow.chatApplication;

            if (BubbleTypeParser.Parse(msg) == BubbleType.Text)
            {
                b          = new Bubble();
                b.Messages = (msg as TextMessage).Message;
            }
            else if (BubbleTypeParser.Parse(msg) == BubbleType.Attachment)
            {
                b          = new Bubble();
                b.Messages = (msg as AttachmentMessage).FileName;
                b.SetLink((msg as AttachmentMessage).FileID);
            }
            else if (BubbleTypeParser.Parse(msg) == BubbleType.Image)
            {
                string    fileID   = (msg as ImageMessage).FileID;
                string    fileName = (msg as ImageMessage).FileName;
                MediaInfo media    = GetMediaInfo(fileID, fileName, app.model.currentSelectedConversation);
                thumbnail = new ThumbnailBubble(media);
                thumbnail.HorizontalAlignment = HorizontalAlignment.Right;
                thumbnail.Margin = new Thickness(0, 0, 16, 0);
                // thumbnail.IsActive = true;
                Console.WriteLine("Image sent");
                AddMedia(fileID, fileName, isSimulating);
            }
            else if (BubbleTypeParser.Parse(msg) == BubbleType.Video)
            {
                string    fileID   = (msg as VideoMessage).FileID;
                string    fileName = (msg as VideoMessage).FileName;
                MediaInfo media    = GetMediaInfo(fileID, fileName, app.model.currentSelectedConversation);
                thumbnail = new ThumbnailBubble(media);
                thumbnail.HorizontalAlignment = HorizontalAlignment.Right;
                thumbnail.Margin = new Thickness(0, 0, 16, 0);
                // thumbnail.IsActive = true;

                AddMedia(fileID, fileName, isSimulating);
            }
            else if (BubbleTypeParser.Parse(msg) == BubbleType.Sticker)
            {
                MessageCore.Sticker.Sticker sticker = (msg as StickerMessage).Sticker;
                //var result;
                MessageCore.Sticker.Sticker.LoadedStickers.TryGetValue(sticker.ID, out var result);
                SendStickerOnTheRight(result, reversed);
            }

            if (b != null)
            {
                b.Type = BubbleTypeParser.Parse(msg);
                b.ControlUpdate();

                b.SetBG(bubbleColor);

                b.IsLeft = false;

                if (bubbleColor.R + bubbleColor.G + bubbleColor.B >= 565)
                {
                    b.SetTextColor(Colors.Black);
                }
                else
                {
                    b.SetTextColor(Colors.White);
                }
                b.SetDirect(false);// true = left false = right
                b.SetSeen(false);
            }

            if (reversed)
            {
                if (b != null)
                {
                    spMessagesContainer.Children.Insert(0, b);
                }
                if (thumbnail != null)
                {
                    spMessagesContainer.Children.Insert(0, thumbnail);
                }
                if (loadConversation)
                {
                    MessagesContainer.ScrollToEnd();
                }
                else
                {
                    MessagesContainer.ScrollToHome();
                }
            }
            else
            {
                if (b != null)
                {
                    spMessagesContainer.Children.Add(b);
                }
                if (thumbnail != null)
                {
                    spMessagesContainer.Children.Add(thumbnail);
                }
                MessagesContainer.ScrollToEnd();
            }

            if (thumbnail != null)
            {
                thumbnail.Click += ThumbnailClick;
            }

            app.model.CurrentUserMessages.Add(new BubbleInfo(msg, false));
            app.model.Conversations[app.model.currentSelectedConversation].Bubbles.Add(new BubbleInfo(msg, false));

            if (isSimulating)
            {
                return;
            }
            SendMessage packet = new SendMessage();

            packet.ConversationID = app.model.currentSelectedConversation;
            packet.Message        = msg;
            _ = ChatConnection.Instance.Send(packet);
        }
Exemple #5
0
        public void SendStickerOnTheLeft(MessageCore.Sticker.Sticker stickerInfo, bool reversed = false, BubbleChat previous = null, BubbleChat head = null)
        {
            try
            {
                Resources.CustomControls.Sticker sticker =
                    new Resources.CustomControls.Sticker(this, false, stickerInfo.ID, stickerInfo.CategoryID, 130, stickerInfo.Duration, stickerInfo.SpriteURL, true);

                Thickness margin = sticker.Margin;
                margin.Left   = 30;
                margin.Top    = 10;
                margin.Bottom = 10;
                sticker.HorizontalAlignment = HorizontalAlignment.Left;
                sticker.Margin = margin;

                if (reversed)
                {
                    head.InsertSticker(sticker);
                }
                else
                {
                    previous.AddSticker(sticker);
                }
                // spMessagesContainer.Children.Add(sticker);
                MessagesContainer.ScrollToEnd();
            }
            catch (Exception e)
            {
                throw new Exception("Sticker ex: ", e);
            }
        }