예제 #1
0
        /** Insert newlines to fit the text in the box*/
        private List <String> InsertNewlines(ChatLogStyle style, string message)
        {
            string[]      words   = message.Split(' ');
            List <String> lines   = new List <String>();
            StringBuilder builder = new StringBuilder();

            foreach (string word in words)
            {
                String  nextString = builder.ToString() + word + " ";
                Vector2 size       = style.font.MeasureString(nextString);

                if (size.X > style.internalBounds.Width)
                {                   // start a new line if it would be too long
                    lines.Add(builder.ToString());
                    builder.Clear();
                }

                builder.Append(word);
                builder.Append(" ");
            }
            if (builder.Length != 0)
            {
                lines.Add(builder.ToString());
            }

            //Debug.WriteLine("generated list with lines.. ");
            //foreach (string line in lines)
            //{
            //	Debug.WriteLine("    " + line);
            //}

            // concatenate lines
            return(lines);
        }
예제 #2
0
 public void Draw(ChatLogStyle style, Point origin, TojamGame game)
 {
     for (int i = 0; i < lines.Count; i++)
     {
         Point drawOrigin = origin + new Point(0, (style.linePadding + style.font.LineSpacing) * i);
         game.spriteBatch.DrawString(
             style.font,
             lines[i],
             new Vector2(drawOrigin.X, drawOrigin.Y),
             lineColor
             );
     }
 }
예제 #3
0
        public void Initialize(TojamGame game)
        {
            // get dimensions to size thingsa round
            renderTarget = new RenderTarget2D(game.GraphicsDevice, chatSceneDimensions.Width, chatSceneDimensions.Height);
            Rectangle screenBounds       = chatSceneDimensions;
            int       messageBufferWidth = 200;

            // build chatlog
            ChatLogStyle style = new ChatLogStyle();

            style.font            = game.GameFont;
            style.linePadding     = 1;
            style.messagePadding  = 5;
            style.externalPadding = 10;
            style.internalBounds  = new Rectangle(
                screenBounds.Width - messageBufferWidth + style.externalPadding,
                style.externalPadding,
                messageBufferWidth - style.externalPadding * 2,
                screenBounds.Height - style.externalPadding
                );
            style.backgroundColor = Color.Black;

            chatLog = new ChatLog(style);
            chatLog.Initialize(game);
            chatLog.AppendMessage("Welcome to Algonquin Park Roadtrip Simulator 2018!", Color.White);
            chatLog.AppendMessage("Your goal is to reach Algonquin Park and have happy camping trip", Color.Gray);
            chatLog.AppendMessage("Type `help` to see commands", Color.Gray);
//			chatLog.AppendMessage("Type 'join <ip>' to join a game, or 'host' to start a new one", Color.Gray);
            chatLog.AppendMessage("Type 'setname <name>' set your name before starting a game", Color.Gray);

            // build textbox
            textBox = new TextBox(
                game.GameFont,
                new Rectangle(
                    0,
                    screenBounds.Height - game.GameFont.LineSpacing,
                    screenBounds.Width - messageBufferWidth,
                    game.GameFont.LineSpacing
                    ));

            // initialize displayable scene
            carPicture = new CarPicture(new Rectangle(0, 0, screenBounds.Width - messageBufferWidth, screenBounds.Height - game.GameFont.LineSpacing * 2 - 5));
            carPicture.Initialize(game);
            carPicture.SetSky(CarPicture.Sky.Day);
            carPicture.SetBackground(CarPicture.Background.Title);
            //carPicture.TriggerEvent("town", new Dictionary<String, Object> { { "townName", "Algonquin" } });

            playerStatusIndicator = new PlayerStatusIndicator(game.GameFont, new Vector2(0, screenBounds.Height - game.GameFont.LineSpacing * 2));
        }
예제 #4
0
 public int getHeight(ChatLogStyle style)
 {
     return
         (style.font.LineSpacing * this.lines.Count +
          style.linePadding * (this.lines.Count - 1));
 }
예제 #5
0
 public Message(ChatLogStyle style, string message, Color color)
 {
     this.lines     = InsertNewlines(style, message);
     this.lineColor = color;
 }
예제 #6
0
 public ChatLog(ChatLogStyle style)
 {
     this.style = style;
 }