Пример #1
0
        /// <summary>A fixed version of <see cref="Game1.parseText(string,SpriteFont,int)" /> that uses .X instead of .Length.</summary>
        private static string FixedParseText(string text, SpriteFont whichFont, int width, bool isConsole = false)
        {
            if (text == null)
            {
                return("");
            }
            string str1 = string.Empty;
            string str2 = string.Empty;

            if (LocalizedContentManager.CurrentLanguageCode == LocalizedContentManager.LanguageCode.ja ||
                LocalizedContentManager.CurrentLanguageCode == LocalizedContentManager.LanguageCode.zh ||
                LocalizedContentManager.CurrentLanguageCode == LocalizedContentManager.LanguageCode.th)
            {
                foreach (char ch in text)
                {
                    if (ConsoleChatMessage.MeasureStringWidth(whichFont, str1 + ch, isConsole) > (double)width)
                    {
                        str2 = str2 + str1 + Environment.NewLine;
                        str1 = string.Empty;
                    }

                    str1 += ch.ToString();
                }

                return(str2 + str1);
            }

            string str3 = text;

            char[] chArray = { ' ' };
            foreach (string str4 in str3.Split(chArray))
            {
                try
                {
                    if (ConsoleChatMessage.MeasureStringWidth(whichFont, str1 + str4, isConsole) > (double)width ||
                        str4.Equals(Environment.NewLine))
                    {
                        str2 = str2 + str1 + Environment.NewLine;
                        str1 = string.Empty;
                    }

                    if (!str4.Equals(Environment.NewLine))
                    {
                        str1 = str1 + str4 + " ";
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception measuring string: " + ex);
                }
            }

            return(str2 + str1);
        }
Пример #2
0
        /// <summary>Construct an instance.</summary>
        /// <remarks>Reassigns the enter handler, replaces <see cref="ChatTextBox" /> and <see cref="EmojiMenu" />.</remarks>
        public CommandChatBox(IModHelper helper, ICommandHandler handler, ChatCommandsConfig config)
        {
            this.handler = handler;
            this.bCheatHistoryPosition = helper.Reflection.GetField <int>(this, "cheatHistoryPosition");
            this.bFormatMessage        = helper.Reflection.GetMethod(this, "formatMessage");
            this.bMessages             = helper.Reflection.GetField <List <ChatMessage> >(this, "messages").GetValue();
            this.bEmojiMenuIcon        =
                helper.Reflection.GetField <ClickableTextureComponent>(this, "emojiMenuIcon").GetValue();
            this.bChoosingEmoji = helper.Reflection.GetField <bool>(this, "choosingEmoji");
            Texture2D chatBoxTexture = Game1.content.Load <Texture2D>("LooseSprites\\chatBox");

            this.chatBox.OnEnterPressed -= helper.Reflection.GetField <TextBoxEvent>(this, "e").GetValue();
            this.chatBox = this.commandChatTextBox = new CommandChatTextBox(chatBoxTexture,
                                                                            null, Game1.smallFont, Color.White);
            Game1.keyboardDispatcher.Subscriber = this.chatBox;
            this.chatBox.Selected        = false;
            this.chatBox.OnEnterPressed += this.EnterPressed;

            this.multiplayer = helper.Reflection.GetField <Multiplayer>(typeof(Game1), "multiplayer").GetValue();
            this.inputState  = helper.Reflection.GetField <InputState>(typeof(Game1), "input").GetValue();

            ConsoleChatMessage.Init(LocalizedContentManager.CurrentLanguageCode);

            this.emojiMenu = new CommandEmojiMenu(helper.Reflection, this, emojiTexture, chatBoxTexture);

            helper.Reflection.GetMethod(this, "updatePosition").Invoke();

            this.displayLineIndex = -1;
            this.config           = config;
            this.config.UseMonospacedFontForCommandOutput = this.config.UseMonospacedFontForCommandOutput && !(
                LocalizedContentManager.CurrentLanguageCode ==
                LocalizedContentManager.LanguageCode.ja ||
                LocalizedContentManager.CurrentLanguageCode ==
                LocalizedContentManager.LanguageCode.zh ||
                LocalizedContentManager.CurrentLanguageCode ==
                LocalizedContentManager.LanguageCode.th);
            this.DetermineNumberOfMaxMessages();
        }