/// <summary> /// Creates an instance of <see cref="XmlMessageReader"/> using the /// specified socked. /// </summary> /// <param name="socket"></param> /// <param name="client">This should be the client that created the reader.</param> public XmlMessageReader(Socket socket, XmlMessageClient client) { if (socket == null) throw new ArgumentNullException("socket"); _unproccessedData = new StringBuilder(); _socket = socket; _socket.ReceiveTimeout = 1000; _readBuffer = new byte[BufferSize]; _currentStage = MessageStage.ContentType; _client = client; }
private void AdvanceStage() { int i = (int)messageStage + 1; messageStage = (MessageStage)i; if (messageStage == MessageStage.MOVING) { count = moveTime; } else if (messageStage == MessageStage.MOVINGANDFADE) { count = fadeTime; } else if (messageStage == MessageStage.DESTROY) { destroy = true; } }
public Message(Color fontColor, Vector2 locationText, string text) : base("", Font.CarterOne18, fontColor, locationText, false, text) { messageStage = MessageStage.CLEARINGSTART; transparency = 0; InitCountDown(); }
private void ProcessMessageBody() { var data = _unproccessedData.ToString(); int index = data.IndexOf("\r\n", StringComparison.Ordinal); if (index != -1) { OnMessageReceived(_unproccessedData.ToString(0, index)); _currentStage = MessageStage.ContentType; _unproccessedData.Remove(0, index + 2); ProcessData(); } }
private void ProcessContentType() { int index = _unproccessedData.ToString().IndexOf("\r\n", StringComparison.Ordinal); if (index != -1) { _currentStage = MessageStage.Body; _unproccessedData.Remove(0,index+2);//Remove the header ProcessData(); } }
//------------------------------------------------------------------------------ // Method: Update // Author: Neil Holmes // Summary: updates the achievement display //------------------------------------------------------------------------------ public void Update(Rectangle displayArea, float timeStep) { float displayAmount; // increase the counter if an achievement is actively being displayed if (stage > MessageStage.begin) counter += timeStep; else { // check the message list for a new message if (messageQueue.Count > 0) { // store the text to be used titleText = messageQueue[0].title; messageText = messageQueue[0].message; // remove the message from the list messageQueue.Remove(messageQueue[0]); // calcuate the number of lines in the messageText int index = 0; int numLines = 1; while ((index = messageText.IndexOf('\n', index)) != -1) { index++; numLines++; } // set the message height messageHeight = (int)(((messageBorderSize * 2) * displayScale) + titleFont.LineSpacing + (messageFont.LineSpacing * numLines)); // calculate the width of the text messageWidth = (int)Math.Max(messageFont.MeasureString(messageText).X, messageFont.MeasureString(titleText).X); // calculate the display width (and enforce minimum and maximum widths) displayWidth = messageWidth + (int)((badgeBorderSize + (messageBorderSize * 2) + badgeSize) * displayScale); if (displayWidth < minDisplayWidth * displayScale) displayWidth = (int)(minDisplayWidth * displayScale); if (displayWidth > maxDisplayWidth * displayScale) { displayWidth = (int)(maxDisplayWidth * displayScale); messageWidth = (int)(maxDisplayWidth * displayScale); } // get screen width and height int screenWidth = displayArea.Width; int screenHeight = displayArea.Height; int halfScreenWidth = screenWidth / 2; // calculate the size of the screen safe zone int screenBorderSizeX = (int)(screenWidth * safeZoneScaleValue); int screenBorderSizeY = (int)(screenHeight * safeZoneScaleValue); // calculate the top middle of the achievement based on the requested positioning switch (positionMode) { case ICMessagePosition.topLeft: displayPosition.X = screenBorderSizeX; displayPosition.Y = screenBorderSizeY; break; case ICMessagePosition.topMiddle: displayPosition.X = halfScreenWidth - (displayWidth / 2); displayPosition.Y = screenBorderSizeY; break; case ICMessagePosition.topRight: displayPosition.X = screenWidth - screenBorderSizeX - displayWidth; displayPosition.Y = screenBorderSizeY; break; case ICMessagePosition.bottomLeft: displayPosition.X = screenBorderSizeX; displayPosition.Y = screenHeight - (screenBorderSizeY + messageHeight); break; case ICMessagePosition.bottomMiddle: displayPosition.X = halfScreenWidth - (displayWidth / 2); displayPosition.Y = screenHeight - (screenBorderSizeY + messageHeight); break; case ICMessagePosition.bottomRight: displayPosition.X = screenWidth - screenBorderSizeX - displayWidth; displayPosition.Y = screenHeight - (screenBorderSizeY + messageHeight); break; } // set up the badge display rectangle badgeRect.X = (int)(displayPosition.X + (badgeBorderSize * displayScale)); badgeRect.Y = (int)(displayPosition.Y + (badgeBorderSize * displayScale)); badgeRect.Width = (int)(badgeSize * displayScale); badgeRect.Height = (int)(badgeSize * displayScale); // setup the title and message text positions titlePosition.X = displayPosition.X + ((badgeBorderSize + messageBorderSize + badgeSize) * displayScale); titlePosition.Y = displayPosition.Y + (messageBorderSize * displayScale); messagePosition.X = displayPosition.X + ((badgeBorderSize + messageBorderSize + badgeSize) * displayScale); messagePosition.Y = displayPosition.Y + (messageBorderSize * displayScale) + titleFont.LineSpacing; // tell the message to start displaying stage = MessageStage.begin; } } // process according to the current stage of achievement display switch (stage) { // do nothing case MessageStage.idle: break; // initialise the achievement unlocked display ready to draw case MessageStage.begin: // set the counter to zero and display flag to true counter = 0; // set the initial size of the message box messageRect.X = (int)(displayPosition.X); messageRect.Y = (int)(displayPosition.Y + messageHeight / 2); messageRect.Width = displayWidth; messageRect.Height = 0; // tell the message system to draw stuff display = true; // move on to the next step in the process stage++; break; // makes the message appear on screen case MessageStage.messageAppear: // clamp counter to the appearance duration if (counter > messageAppearDuration) counter = messageAppearDuration; // calculate how much of the message should be displayed displayAmount = counter / messageAppearDuration; messageRect.Y = (int)((displayPosition.Y + messageHeight / 2) - ((messageHeight / 2) * displayAmount)); messageRect.Height = (int)(messageHeight * displayAmount); // check if we have reached the end of this stage if (counter == messageAppearDuration) { // we have reached the end of the message appearance stage, reset counter and move on to the next stage counter = 0; stage++; } break; // pause for a short time before removing the message case MessageStage.messageDisplay: // check if we have reached the end of this stage if (counter >= messageDisplayDuration) { // we have reached the end of this pause - reset counter and move on to the next stage counter = 0.0f; stage++; } break; // remove the message case MessageStage.messageRemove: // clamp counter to the message removal duration if (counter > messageRemoveDuration) counter = messageRemoveDuration; // calculate how much of the message should be displayed displayAmount = 1 - (counter / messageAppearDuration); messageRect.Y = (int)((displayPosition.Y + messageHeight / 2) - ((messageHeight / 2) * displayAmount)); messageRect.Height = (int)(messageHeight * displayAmount); // check if we have reached the end of this stage if (counter == messageRemoveDuration) { // display finished - ensure everything is reset to the defaults counter = 0; display = false; stage = MessageStage.idle; } break; } }
//------------------------------------------------------------------------------ // Method: AddMessage // Author: Neil Holmes // Summary: add a new message to the message queue for display //------------------------------------------------------------------------------ public void AddMessage(string title, string message, ICMessagePriority priority) { int insertionIndex = 0; ICMessageData newMessage = new ICMessageData(title, message, priority); // is this an urgent message? if (newMessage.priority == ICMessagePriority.urgent) { // tell the message system to stop displaying any message it might be in the middle of stage = MessageStage.idle; // urgent messages always go at the top of the queue, in time order foreach (ICMessageData item in messageQueue) { if (item.priority != ICMessagePriority.urgent) break; else insertionIndex ++; } } else { // find the first lower-priorty message in the queue and push this one ahead of it foreach (ICMessageData item in messageQueue) { if (item.priority < newMessage.priority) break; else insertionIndex ++; } } // insert here! messageQueue.Insert(insertionIndex, newMessage); }
//------------------------------------------------------------------------------ // Constructor: ICMessagePopUp // Author: Neil Holmes // Summary: Constructor - prepares the message pop up system //------------------------------------------------------------------------------ public ICMessagePopUp(Game game, GraphicsDeviceManager graphicsDeviceManager, ICMessagePosition positionMode, ICMessageScale scale) { // create a content manager to handle loading the textures we need ContentManager content = new ContentManager(game.Services); // store the graphics device for future reference this.graphicsDevice = game.GraphicsDevice; // store the position mode that we are using this.positionMode = positionMode; // store the scale we are using if (scale == ICMessageScale.normal) displayScale = 1.0f; else displayScale = 0.5f; // create a sprite batch for rendering spriteBatch = new SpriteBatch(graphicsDevice); // load the achievement display textures badgeTexture = content.Load<Texture2D>(@"Content\ICMessages\Badge"); bannerTexture = content.Load<Texture2D>(@"Content\ICMessages\Shadow"); // store the size of the badge graphic badgeSize = badgeTexture.Height; // load the message fonts if (scale == ICMessageScale.normal) { titleFont = content.Load<SpriteFont>(@"Content\ICMessages\titleFont"); messageFont = content.Load<SpriteFont>(@"Content\ICMessages\MessageFont"); } else { titleFont = content.Load<SpriteFont>(@"Content\ICMessages\titleFontSmall"); messageFont = content.Load<SpriteFont>(@"Content\ICMessages\MessageFontSmall"); } // nothing to display yet! display = false; // set the message display stage to 'idle' so nothing is displayed this.stage = MessageStage.idle; }