Example #1
0
        public Bitmap RenderCaption(ClientBalloon balloon)
        {
            // replace template parameters by their values
            string content = (balloon.Label == null) ? "" : balloon.Label;
            var vals = new Dictionary<string, string>();
            vals.Add("@@CONTENT@@", content);
            string html = FillTemplate(templates["caption_box.html"], vals);

            var images = new Dictionary<string, Image>(staticImages);
            return RenderHtml(maxCaptionBoxSize, html, images);
        }
Example #2
0
        public void MoveBalloonOffscreen(ClientBalloon balloon, Direction direction, float exitHeight, Vector2 velocity)
        {
            Trace.WriteLine("Sending balloon away!");
            // Did we already notify the server that the balloon is off-screen?
            if (balloon.OffScreen)
            {
                return;
            }

            // notify the server that the balloon is moving off-screen
            m_conn.SendMessage(new ChangeScreenMessage(balloon.ID, direction, exitHeight, new Vector2D(velocity.X, velocity.Y)));
            balloon.OffScreen = true;
        }
Example #3
0
 public PopAnimation(ClientBalloon balloon)
 {
     this.ID = balloon.ID;
 }
Example #4
0
        public Bitmap RenderContent(ClientBalloon balloon)
        {
            // prepare the images
            BalloonContentCache cacheEntry = balloon.BalloonContentCache;
            var images = new Dictionary<string, Image>(staticImages);
            Bitmap qrImg = cacheEntry[CacheType.QRCode];
            Bitmap webImg = cacheEntry[CacheType.WebImage];
            if (qrImg != null)
            {
                images["qr.png"] = qrImg;
            }
            if (webImg != null)
            {
                images["web.png"] = webImg;
            }

            // replace template parameters by their values
            string title = (balloon.Label == null) ? "" : balloon.Label;
            string content = (balloon.Content == null) ? "" : balloon.Content;
            if (String.IsNullOrEmpty(content) && !String.IsNullOrEmpty(balloon.Url))
            {
                content = balloon.Url;
            }
            var vals = new Dictionary<string, string>();
            vals.Add("@@TITLE@@", title);
            vals.Add("@@CONTENT@@", content);
            vals.Add("@@MASK-COLOR@@", ColorTranslator.ToHtml(maskColour));
            if (balloon.Type == Balloons.Messaging.Model.BalloonType.CustomContent)
            {
                if (balloon.Votes >= 0)
                {
                    vals.Add("@@VOTES@@", balloon.Votes.ToString());
                    vals.Add("@@THUMBS-CLASS@@", "thumbsUp");
                    vals.Add("@@THUMBS-IMG@@", "thumbs-up.png");
                }
                else
                {
                    vals.Add("@@VOTES@@", (-balloon.Votes).ToString());
                    vals.Add("@@THUMBS-CLASS@@", "thumbsDown");
                    vals.Add("@@THUMBS-IMG@@", "thumbs-down.png");
                }
            }
            else
            {
                vals.Add("@@THUMBS-CLASS@@", "thumbsHidden");
            }

            // Generate CSS for images
            const int imageSize = 229;
            if (qrImg != null)
            {
                vals.Add("@@QRIMG_CSS@@", String.Format("width: {0}px; width: {0}px;", imageSize));
            }
            else
            {
                vals.Add("@@QRIMG_CSS@@", "display: none;");
            }
            if (webImg != null)
            {
                lock (gdiLock)
                {
                    if (webImg.Width > webImg.Height)
                    {
                        int realSize = Math.Min(imageSize, webImg.Width);
                        vals.Add("@@WEBIMG_CSS@@", String.Format("width: {0}px;", realSize));
                    }
                    else
                    {
                        int realSize = Math.Min(imageSize, webImg.Height);
                        vals.Add("@@WEBIMG_CSS@@", String.Format("height: {0}px;", realSize));
                    }
                }
            }
            else
            {
                vals.Add("@@WEBIMG_CSS@@", "display: none;");
            }

            string html = FillTemplate(templates["content_box.html"], vals);
            Bitmap bmp = RenderHtml(maxContentBoxSize, html, images);
            bmp.MakeTransparent(maskColour);
            return bmp;
        }
Example #5
0
        public void NotifyBalloonPopped(ClientBalloon balloon)
        {
            if (balloon.OffScreen)
            {
                return;
            }

            m_conn.SendMessage(new PopObjectMessage(balloon.ID));
            balloon.OffScreen = true;
        }
Example #6
0
 public abstract void ApplyToBalloon(ClientBalloon balloon);
        /// <summary>
        /// Removes (immediately) the given balloon from the physics world and screen.
        /// </summary>
        /// <param name="balloon">Balloon to remove. </param>
        private void RemoveBalloon(ClientBalloon balloon, Boolean animate = true)
        {
            if (animate)
            {
                // Create a new pop animation
                PopAnimation anim = new PopAnimation(balloon);
                anim.Pos = PhysicsManager.WorldToPixel(balloonEntities[balloon].Body.Position);
                anim.TimePopped = currentTime.TotalGameTime;
                anim.PopTexture = balloonPopTextures[rng.Next(0, balloonPopTextures.Length)];
                anim.PopColour = new Colour(255, 255, 255, 255);
                popAnimations.Add(anim);
            }

            // Remove balloon from screen.
            physicsManager.RemoveEntity(balloonEntities[balloon]);
            balloonEntities.Remove(balloon);
            balloons.Remove(balloon.ID);

            // Remove balloon from server. This must be done after removing the balloon
            // from the map or an exception can be raised when the server sends a
            // "new balloon" message with the same ID when the feed is updated.
            NetworkManager.NotifyBalloonPopped(balloon);
        }
        private void DrawBalloonCaptionSprites(ClientBalloon balloon)
        {
            // If the label is not cached then it means it has not
            // been formatted to fit in the box; therefore format it
            // and save it back
            if (!balloon.IsLabelCached)
            {
                string labelText = balloon.Label;
                balloon.Label = TextUtility.wrapText(summaryFont, labelText, new Vector2(382, 168));
                balloon.IsLabelCached = true;
            }

            // Measure the size of the string and add 4px padding
            Vector2 boxSize = summaryFont.MeasureString(balloon.Label) + new Vector2(8, 8);

            Vector2 boxPosition =
                PhysicsManager.WorldToPixel(balloonEntities[balloon].Body.Position)
                - new Vector2(boxSize.X / 2, 0);
            boxPosition.Y += balloon.Texture.Height - (ClientBalloon.BalloonHeight / 2);

            spriteBatch.Draw(boxBlackColour, new Rectangle((int)boxPosition.X - 2, (int)boxPosition.Y - 2, (int)boxSize.X + 4, (int)boxSize.Y + 4), Color.White);
            spriteBatch.Draw(boxWhiteColour, new Rectangle((int)boxPosition.X, (int)boxPosition.Y, (int)boxSize.X, (int)boxSize.Y), Color.White);

            TextUtility.drawTextLabel(spriteBatch, summaryFont, balloon.Label, new Vector2(boxPosition.X, boxPosition.Y) + new Vector2(4, 4));
        }
        private void DrawBalloonCaptionHtml(ClientBalloon balloon)
        {
            Vector2 boxPosition =
                PhysicsManager.WorldToPixel(balloonEntities[balloon].Body.Position);
            boxPosition.Y += balloon.Texture.Height - (ClientBalloon.BalloonHeight / 2);

            Texture2D caption = balloon.BalloonContentCache[CacheType.Caption, GraphicsDevice];
            if (caption != null)
            {
                boxPosition.X -= caption.Width / 2;
                spriteBatch.Draw(caption, boxPosition, Color.White);
            }
        }
Example #10
0
        private void ApplyBucketToBalloon(Bucket bucket, ClientBalloon balloon)
        {
            OverlayType oldOverlay = balloon.OverlayType;
            Colour oldBackgroundColor = balloon.BackgroundColor;

            // Only change colour if we're touching a new bucket
            if (bucket != oldBucket)
            {
                bucket.ApplyToBalloon(balloon);

                oldBucket = bucket;
            }

            // notify the server that the ballon's decoration changed.
            // otherwise decorations are lost when balloons change screens
            if (balloon.OverlayType != oldOverlay || !balloon.BackgroundColor.Equals(oldBackgroundColor))
            {
                NetworkManager.UpdateBalloonDetails(balloon);
            }

            balloon.Texture = balloonTextures[balloon.Type][balloon.OverlayType];
        }
Example #11
0
        public void OnNewBalloon(NewBalloonMessage m)
        {
            // Choose where to place the balloon
            Vector2 position = new Vector2();
            switch (m.Direction)
            {
                case Direction.Left:
                    position.X = ClientBalloon.BalloonWidth * -1;
                    break;
                case Direction.Right:
                    position.X = ClientBalloon.BalloonWidth + screenDimensions.X;
                    break;

                case Direction.Any:
                default:
                    position.X = rng.Next((int)screenDimensions.X);
                    break;
            }

            position.Y = m.Y * screenDimensions.Y;

            // Setup the balloon's body
            Vector2 velocity = new Vector2(m.Velocity.X, m.Velocity.Y);
            WorldEntity balloonEntity = physicsManager.CreateBalloon(position, velocity);

            Balloon balloon = NetworkManager.GetBalloonDetails(m.BalloonID);
            ClientBalloon b = new ClientBalloon(balloon);
            b.Texture = balloonTextures[balloon.Type][balloon.OverlayType];
            b.BalloonContentCache = contentBox.GetBalloonContent(b.ID);

            // Render the balloon's caption if we already have it
            if (!String.IsNullOrWhiteSpace(b.Label))
            {
                contentBox.GenerateCaption(b);
            }

            balloons.Add(b.ID, b);
            balloonEntities[b] = balloonEntity;
        }