Ejemplo n.º 1
0
 public override void update(GameTime time)
 {
     base.update(time);
     if (_languageCode != LocalizedContentManager.CurrentLanguageCode)
     {
         _languageCode = LocalizedContentManager.CurrentLanguageCode;
         _amString     = Game1.content.LoadString("Strings\\StringsFromCSFiles:DayTimeMoneyBox.cs.10370");
         _pmString     = Game1.content.LoadString("Strings\\StringsFromCSFiles:DayTimeMoneyBox.cs.10371");
     }
     if (questPingTimer > 0)
     {
         questPingTimer -= (int)time.ElapsedGameTime.TotalMilliseconds;
     }
     if (questPingTimer < 0)
     {
         questPingTimer = 0;
     }
     if (questsDirty)
     {
         if (Game1.player.hasPendingCompletedQuests)
         {
             PingQuestLog();
         }
         questsDirty = false;
     }
 }
Ejemplo n.º 2
0
        /// <summary>Load an asset that has been processed by the content pipeline.</summary>
        /// <typeparam name="T">The type of asset to load.</typeparam>
        /// <param name="assetName">The asset path relative to the loader root directory, not including the <c>.xnb</c> extension.</param>
        /// <param name="language">The language code for which to load content.</param>
        /// <param name="useCache">Whether to read/write the loaded asset to the asset cache.</param>
        public override T Load <T>(string assetName, LocalizedContentManager.LanguageCode language, bool useCache)
        {
            // raise first-load callback
            if (GameContentManager.IsFirstLoad)
            {
                GameContentManager.IsFirstLoad = false;
                this.OnLoadingFirstAsset();
            }

            // normalize asset name
            assetName = this.AssertAndNormalizeAssetName(assetName);
            if (this.TryParseExplicitLanguageAssetKey(assetName, out string newAssetName, out LanguageCode newLanguage))
            {
                return(this.Load <T>(newAssetName, newLanguage, useCache));
            }

            // get from cache
            if (useCache && this.IsLoaded(assetName))
            {
                return(this.RawLoad <T>(assetName, language, useCache: true));
            }

            // get managed asset
            if (this.Coordinator.TryParseManagedAssetKey(assetName, out string contentManagerID, out string relativePath))
            {
                T managedAsset = this.Coordinator.LoadManagedAsset <T>(contentManagerID, relativePath);
                if (useCache)
                {
                    this.Inject(assetName, managedAsset, language);
                }
                return(managedAsset);
            }

            // load asset
            T data;

            if (this.AssetsBeingLoaded.Contains(assetName))
            {
                this.Monitor.Log($"Broke loop while loading asset '{assetName}'.", LogLevel.Warn);
                this.Monitor.Log($"Bypassing mod loaders for this asset. Stack trace:\n{Environment.StackTrace}", LogLevel.Trace);
                data = this.RawLoad <T>(assetName, language, useCache);
            }
            else
            {
                data = this.AssetsBeingLoaded.Track(assetName, () =>
                {
                    string locale    = this.GetLocale(language);
                    IAssetInfo info  = new AssetInfo(locale, assetName, typeof(T), this.AssertAndNormalizeAssetName);
                    IAssetData asset =
                        this.ApplyLoader <T>(info)
                        ?? new AssetDataForObject(info, this.RawLoad <T>(assetName, language, useCache), this.AssertAndNormalizeAssetName);
                    asset = this.ApplyEditors <T>(info, asset);
                    return((T)asset.Data);
                });
            }

            // update cache & return data
            this.Inject(assetName, data, language);
            return(data);
        }
Ejemplo n.º 3
0
        private void _loadPreferences()
        {
            string fullFilePath = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley"), _filename);

            if (!File.Exists(fullFilePath))
            {
                Console.WriteLine("path '{0}' did not exist and will be created", fullFilePath);
                try
                {
                    languageCode             = LocalizedContentManager.CurrentLanguageCode;
                    using FileStream stream2 = File.Create(fullFilePath);
                    writeSettings(stream2);
                }
                catch (Exception e2)
                {
                    Console.WriteLine("_loadPreferences; exception occured trying to create/write: {0}", e2);
                    Game1.debugOutput = Game1.parseText(e2.Message);
                    return;
                }
            }
            try
            {
                using (FileStream stream = File.Open(fullFilePath, FileMode.Open, FileAccess.Read))
                {
                    readSettings(stream);
                }
                isLoaded = true;
            }
            catch (Exception e)
            {
                Console.WriteLine("_loadPreferences; exception occured trying open/read: {0}", e);
                Game1.debugOutput = Game1.parseText(e.Message);
            }
        }
Ejemplo n.º 4
0
        /****
        ** Content loading
        ****/
        /// <summary>Load an asset name without heuristics to support mod content.</summary>
        /// <typeparam name="T">The type of asset to load.</typeparam>
        /// <param name="assetName">The asset path relative to the loader root directory, not including the <c>.xnb</c> extension.</param>
        /// <param name="language">The language code for which to load content.</param>
        private T LoadImpl <T>(string assetName, LocalizedContentManager.LanguageCode language)
        {
            // skip if already loaded
            if (this.IsNormalisedKeyLoaded(assetName))
            {
                return(base.Load <T>(assetName, language));
            }

            // load asset
            T data;

            if (this.AssetsBeingLoaded.Contains(assetName))
            {
                this.Monitor.Log($"Broke loop while loading asset '{assetName}'.", LogLevel.Warn);
                this.Monitor.Log($"Bypassing mod loaders for this asset. Stack trace:\n{Environment.StackTrace}", LogLevel.Trace);
                data = base.Load <T>(assetName, language);
            }
            else
            {
                data = this.AssetsBeingLoaded.Track(assetName, () =>
                {
                    string locale    = this.GetLocale(language);
                    IAssetInfo info  = new AssetInfo(locale, assetName, typeof(T), this.NormaliseAssetName);
                    IAssetData asset =
                        this.ApplyLoader <T>(info)
                        ?? new AssetDataForObject(info, base.Load <T>(assetName, language), this.NormaliseAssetName);
                    asset = this.ApplyEditors <T>(info, asset);
                    return((T)asset.Data);
                });
            }

            // update cache & return data
            this.Inject(assetName, data);
            return(data);
        }
Ejemplo n.º 5
0
        /// <summary>Update the current context.</summary>
        /// <param name="language">The current language.</param>
        /// <param name="date">The current in-game date (if applicable).</param>
        /// <param name="weather">The current in-game weather (if applicable).</param>
        /// <param name="dayEvent">The day event (e.g. wedding or festival) occurring today (if applicable).</param>
        /// <param name="spouse">The current player's internal spouse name (if applicable).</param>
        /// <param name="seenEvents">The event IDs which the player has seen.</param>
        /// <param name="mailFlags">The mail flags set for the player.</param>
        /// <param name="friendships">The current player's friendship details.</param>
        public void Set(LocalizedContentManager.LanguageCode language, SDate date, Weather?weather, string dayEvent, string spouse, int[] seenEvents, string[] mailFlags, IEnumerable <KeyValuePair <string, Friendship> > friendships)
        {
            // optional date
            if (date != null)
            {
                this.Set(ConditionKey.Day, date.Day.ToString(CultureInfo.InvariantCulture));
                this.Set(ConditionKey.DayOfWeek, date.DayOfWeek.ToString().ToLower());
                this.Set(ConditionKey.Season, date.Season.ToLower());
            }
            else
            {
                this.Set(ConditionKey.Day);
                this.Set(ConditionKey.DayOfWeek);
                this.Set(ConditionKey.Season);
            }

            // other basic conditions
            this.Set(ConditionKey.DayEvent, dayEvent);
            this.Set(ConditionKey.HasFlag, mailFlags);
            this.Set(ConditionKey.HasSeenEvent, seenEvents?.Select(p => p.ToString()).ToArray());
            this.Set(ConditionKey.Language, language.ToString().ToLower());
            this.Set(ConditionKey.Spouse, spouse);
            this.Set(ConditionKey.Weather, weather?.ToString().ToLower());

            // NPC friendship conditions
            this.RemoveAll(ConditionType.Hearts, ConditionType.Relationship);
            if (friendships != null)
            {
                foreach (KeyValuePair <string, Friendship> friendship in friendships)
                {
                    this.Set(new ConditionKey(ConditionType.Hearts, friendship.Key), (friendship.Value.Points / NPC.friendshipPointsPerHeartLevel).ToString());
                    this.Set(new ConditionKey(ConditionType.Relationship, friendship.Key), friendship.Value.Status.ToString());
                }
            }
        }
Ejemplo n.º 6
0
 public void OnLanguageChange(LocalizedContentManager.LanguageCode code)
 {
     if (isLoaded && languageCode != code)
     {
         savePreferences(async: false);
     }
 }
Ejemplo n.º 7
0
        /****
        ** Methods
        ****/
        /// <summary>Update the current context.</summary>
        private void UpdateContext()
        {
            // get context
            IContentHelper contentHelper = this.Helper.Content;

            LocalizedContentManager.LanguageCode language = contentHelper.CurrentLocaleConstant;
            SDate   date     = null;
            Weather?weather  = null;
            string  spouse   = null;
            string  dayEvent = null;

            int[]    seenEvents = null;
            string[] mailFlags  = null;
            if (Context.IsWorldReady)
            {
                date       = SDate.Now();
                weather    = this.GetCurrentWeather();
                spouse     = Game1.player?.spouse;
                dayEvent   = this.GetDayEvent();
                seenEvents = Game1.player?.eventsSeen.OrderBy(p => p).ToArray();
                mailFlags  = this.GetMailFlags().OrderBy(p => p).ToArray();
            }

            // update context
            this.VerboseLog($"Context: date={(date != null ? $"{date.DayOfWeek} {date.Season} {date.Day}" : "none")}, weather={(weather != null ? weather.ToString() : "none")}, locale={language}.");
            this.PatchManager.UpdateContext(contentHelper: contentHelper, language: language, date: date, weather: weather, dayEvent: dayEvent, spouse: spouse, seenEvents: seenEvents, mailFlags: mailFlags);
        }
Ejemplo n.º 8
0
        /// <summary>Adds a new message to the chat box.</summary>
        private void AddNewMessage(string message, Color color, SpriteFont font,
                                   LocalizedContentManager.LanguageCode code, bool isConsoleMessage = false)
        {
            if (string.IsNullOrEmpty(message))
            {
                message = " ";
            }

            ChatMessage newMessage = isConsoleMessage && this.config.UseMonospacedFontForCommandOutput
                ? new ConsoleChatMessage()
                : new ChatMessage();

            newMessage.timeLeftToDisplay = 600;
            newMessage.verticalSize      = (int)font.MeasureString(message).Y + 4;
            newMessage.color             = color;
            newMessage.language          = code;

            newMessage.parseMessageForEmoji(message);
            this.bMessages.Add(newMessage);
            if (this.config.MaximumNumberOfHistoryMessages > 0 &&
                this.bMessages.Count >= this.config.MaximumNumberOfHistoryMessages)
            {
                this.bMessages.RemoveAt(0);
            }
            else if (this.displayLineIndex == this.bMessages.Count - 2)
            {
                this.displayLineIndex++;
            }
        }
Ejemplo n.º 9
0
        /*********
        ** Public methods
        *********/
        /// <summary>Construct an instance.</summary>
        /// <param name="locale">The current language.</param>
        /// <param name="singleValueConditions">Condition keys which are guaranteed to only have one value.</param>
        public ConditionContext(LocalizedContentManager.LanguageCode locale, HashSet <ConditionKey> singleValueConditions)
        {
            this.SingleValueConditions = singleValueConditions;

            // set defaults
            this.Set(locale, null, null, null, null, null, null);
            this.Set(ConditionKey.HasMod);
        }
Ejemplo n.º 10
0
 /// <summary>Raised after the game language is changed, and after SMAPI handles the change.</summary>
 /// <param name="code">The new language code.</param>
 private void OnLocaleChanged(LocalizedContentManager.LanguageCode code)
 {
     // update if locale changes after initialization
     if (!this.IsFirstTick)
     {
         this.UpdateContext(ContextUpdateType.All);
     }
 }
Ejemplo n.º 11
0
 public static void SetForLanguage(LocalizedContentManager.LanguageCode code)
 {
     Translations.LanguageCodesToTry = new[]
     {
         code,
         Translations.DefaultLanguageCode
     };
 }
Ejemplo n.º 12
0
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="monitor">Encapsulates monitoring and logging.</param>
 /// <param name="conditionFactory">Handles constructing, permuting, and updating conditions.</param>
 /// <param name="language">The current language.</param>
 /// <param name="verboseLog">Whether to enable verbose logging.</param>
 /// <param name="normaliseAssetName">Normalise an asset name.</param>
 public PatchManager(IMonitor monitor, ConditionFactory conditionFactory, LocalizedContentManager.LanguageCode language, bool verboseLog, Func <string, string> normaliseAssetName)
 {
     this.Monitor            = monitor;
     this.ConditionFactory   = conditionFactory;
     this.ConditionContext   = new ConditionContext(language);
     this.Verbose            = verboseLog;
     this.NormaliseAssetName = normaliseAssetName;
 }
Ejemplo n.º 13
0
        /*********
        ** Public methods
        *********/
        /// <summary>Construct an instance.</summary>
        /// <param name="modID">The unique ID of the relevant mod.</param>
        /// <param name="modName">The name of the relevant mod for error messages.</param>
        /// <param name="locale">The initial locale.</param>
        /// <param name="languageCode">The game's current language code.</param>
        public TranslationHelper(string modID, string modName, string locale, LocalizedContentManager.LanguageCode languageCode)
            : base(modID)
        {
            // save data
            this.ModName = modName;

            // set locale
            this.SetLocale(locale, languageCode);
        }
Ejemplo n.º 14
0
        /*********
        ** Public methods
        *********/
        /// <summary>Construct an instance.</summary>
        /// <param name="translationHelper">Gets translations from the content pack's translation folder.</param>
        public TranslationValueProvider(ITranslationHelper translationHelper)
            : base(ConditionType.I18n, mayReturnMultipleValuesForRoot: false)
        {
            this.TranslationHelper = translationHelper;
            this.LastLocale        = translationHelper.LocaleEnum;

            this.EnableInputArguments(required: true, mayReturnMultipleValues: false, maxPositionalArgs: 1);
            this.MarkReady(true);
        }
        /// <inheritdoc />
        public override bool UpdateContext(IContext context)
        {
            if (this.TranslationHelper.LocaleEnum == this.LastLocale)
            {
                return(false);
            }

            this.LastLocale = this.TranslationHelper.LocaleEnum;
            return(true);
        }
Ejemplo n.º 16
0
        private static void OnLanguageChange(LocalizedContentManager.LanguageCode code)
        {
            if (_characterMap != null)
            {
                _characterMap.Clear();
            }
            else
            {
                _characterMap = new Dictionary <char, FontChar>();
            }
            if (fontPages != null)
            {
                fontPages.Clear();
            }
            else
            {
                fontPages = new List <Texture2D>();
            }
            switch (code)
            {
            case LocalizedContentManager.LanguageCode.ja:
                FontFile      = loadFont("Fonts\\Japanese");
                fontPixelZoom = 1.75f;
                break;

            case LocalizedContentManager.LanguageCode.zh:
                FontFile      = loadFont("Fonts\\Chinese");
                fontPixelZoom = 1.5f;
                break;

            case LocalizedContentManager.LanguageCode.ru:
                FontFile      = loadFont("Fonts\\Russian");
                fontPixelZoom = 3f;
                break;

            case LocalizedContentManager.LanguageCode.th:
                FontFile      = loadFont("Fonts\\Thai");
                fontPixelZoom = 1.5f;
                break;

            case LocalizedContentManager.LanguageCode.ko:
                FontFile      = loadFont("Fonts\\Korean");
                fontPixelZoom = 1.5f;
                break;
            }
            foreach (FontChar fontCharacter in FontFile.Chars)
            {
                char c = (char)fontCharacter.ID;
                _characterMap.Add(c, fontCharacter);
            }
            foreach (FontPage fontPage in FontFile.Pages)
            {
                fontPages.Add(Game1.content.Load <Texture2D>("Fonts\\" + fontPage.File));
            }
        }
Ejemplo n.º 17
0
        private static void OnLanguageChange(LocalizedContentManager.LanguageCode code)
        {
            if (SpriteTextHelper._characterMap != null)
            {
                SpriteTextHelper._characterMap.Clear();
            }
            else
            {
                SpriteTextHelper._characterMap = new Dictionary <char, FontChar>();
            }
            if (SpriteTextHelper.fontPages != null)
            {
                SpriteTextHelper.fontPages.Clear();
            }
            else
            {
                SpriteTextHelper.fontPages = new List <Texture2D>();
            }
            switch (code)
            {
            case LocalizedContentManager.LanguageCode.ja:
                SpriteTextHelper.FontFile = SpriteTextHelper.LoadFont("Fonts\\Japanese");
                SpriteText.fontPixelZoom  = 1.75f;
                break;

            case LocalizedContentManager.LanguageCode.ru:
                SpriteTextHelper.FontFile = SpriteTextHelper.LoadFont("Fonts\\Russian");
                SpriteText.fontPixelZoom  = 3f;
                break;

            case LocalizedContentManager.LanguageCode.zh:
                SpriteTextHelper.FontFile = SpriteTextHelper.LoadFont("Fonts\\Chinese");
                SpriteText.fontPixelZoom  = 1.5f;
                break;

            case LocalizedContentManager.LanguageCode.th:
                SpriteTextHelper.FontFile = SpriteTextHelper.LoadFont("Fonts\\Thai");
                SpriteText.fontPixelZoom  = 1.5f;
                break;

            case LocalizedContentManager.LanguageCode.ko:
                SpriteTextHelper.FontFile = SpriteTextHelper.LoadFont("Fonts\\Korean");
                SpriteText.fontPixelZoom  = 1.5f;
                break;
            }
            foreach (FontChar fontChar in SpriteTextHelper.FontFile.Chars)
            {
                char id = (char)fontChar.ID;
                SpriteTextHelper._characterMap.Add(id, fontChar);
            }
            foreach (FontPage page in SpriteTextHelper.FontFile.Pages)
            {
                SpriteTextHelper.fontPages.Add(Game1.content.Load <Texture2D>("Fonts\\" + page.File));
            }
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Gets a translated string from the the dictionary with the proper translation; Returns an empty string if this fails somehow.
 /// </summary>
 /// <param name="Language"></param>
 /// <param name="Key"></param>
 /// <returns></returns>
 public string getTranslatedString(LocalizedContentManager.LanguageCode Language, string Key)
 {
     try
     {
         return(HappyBirthday.Instance.messages.translatedStrings[Language][Key]);
     }
     catch (Exception err)
     {
         return("");
     }
 }
Ejemplo n.º 19
0
        /// <summary>Set the current locale and precache translations.</summary>
        /// <param name="locale">The current locale.</param>
        /// <param name="localeEnum">The game's current language code.</param>
        public void SetLocale(string locale, LocalizedContentManager.LanguageCode localeEnum)
        {
            this.Locale     = locale.ToLower().Trim();
            this.LocaleEnum = localeEnum;

            this.ForLocale = new Dictionary <string, Translation>(StringComparer.OrdinalIgnoreCase);
            foreach (string key in this.GetAllKeysRaw())
            {
                string text = this.GetRaw(key, locale, withFallback: true);
                this.ForLocale.Add(key, new Translation(this.Locale, key, text));
            }
        }
Ejemplo n.º 20
0
 public void setTranslationFromLanguageCode(LocalizedContentManager.LanguageCode code)
 {
     foreach (var v in this.TranslationCodes)
     {
         if (v.Value.Equals(code))
         {
             this.CurrentTranslation = v.Key;
             HappyBirthday.ModHelper.WriteConfig <ModConfig>(HappyBirthday.Config);
             return;
         }
     }
 }
Ejemplo n.º 21
0
        /// <summary>Handle the game changing locale.</summary>
        private void OnLocaleChanged()
        {
            // get locale
            string locale = this.ContentManager.GetLocale();

            LocalizedContentManager.LanguageCode languageCode = this.ContentManager.GetCurrentLanguage();

            // update mod translation helpers
            foreach (IModMetadata mod in this.ModRegistry.GetMods())
            {
                (mod.Mod.Helper.Translation as TranslationHelper)?.SetLocale(locale, languageCode);
            }
        }
Ejemplo n.º 22
0
        /// <summary>Update the current context.</summary>
        /// <param name="language">The current language.</param>
        /// <param name="date">The current in-game date (if applicable).</param>
        /// <param name="weather">The current in-game weather (if applicable).</param>
        public void Update(LocalizedContentManager.LanguageCode language, SDate date, Weather?weather)
        {
            // language
            this.Values[ConditionKey.Language] = language.ToString().ToLower();

            // optional date
            this.Values[ConditionKey.Day]       = date?.Day.ToString(CultureInfo.InvariantCulture);
            this.Values[ConditionKey.DayOfWeek] = date?.DayOfWeek.ToString().ToLower();
            this.Values[ConditionKey.Season]    = date?.Season.ToLower();

            // weather
            this.Values[ConditionKey.Weather] = weather?.ToString().ToLower();
        }
Ejemplo n.º 23
0
        public string this[LocalizedContentManager.LanguageCode code]
        {
            get
            {
                switch (code)
                {
                case LocalizedContentManager.LanguageCode.en:
                    return(en);

                case LocalizedContentManager.LanguageCode.ja:
                    return(ja ?? en);

                case LocalizedContentManager.LanguageCode.ru:
                    return(ru ?? en);

                case LocalizedContentManager.LanguageCode.zh:
                    return(zh ?? en);

                case LocalizedContentManager.LanguageCode.pt:
                    return(pt ?? en);

                case LocalizedContentManager.LanguageCode.es:
                    return(es ?? en);

                case LocalizedContentManager.LanguageCode.de:
                    return(de ?? en);

                case LocalizedContentManager.LanguageCode.th:
                    return(th ?? en);

                case LocalizedContentManager.LanguageCode.fr:
                    return(fr ?? en);

                case LocalizedContentManager.LanguageCode.ko:
                    return(ko ?? en);

                case LocalizedContentManager.LanguageCode.it:
                    return(it ?? en);

                case LocalizedContentManager.LanguageCode.tr:
                    return(tr ?? en);

                case LocalizedContentManager.LanguageCode.hu:
                    return(hu ?? en);

                default:
                    return(null);
                }
            }
        }
Ejemplo n.º 24
0
 private void writeSettings(Stream stream)
 {
     using (XmlWriter xmlWriter = XmlWriter.Create(stream, new XmlWriterSettings
     {
         CloseOutput = true
     }))
     {
         xmlWriter.WriteStartDocument();
         this.languageCode = LocalizedContentManager.CurrentLanguageCode;
         StartupPreferences.serializer.Serialize(xmlWriter, this);
         xmlWriter.WriteEndDocument();
         xmlWriter.Flush();
     }
 }
Ejemplo n.º 25
0
        /// <inheritdoc />
        public override void receiveChatMessage(long sourceFarmer, int chatKind, LocalizedContentManager.LanguageCode language, string message)
        {
            if (chatKind == ChatBox.errorMessage)
            {
                // log error
                this.Monitor.Log(message, LogLevel.Error);

                // add event details if applicable
                if (Game1.CurrentEvent != null && message.StartsWith("Event script error:"))
                {
                    this.Monitor.Log($"In event #{Game1.CurrentEvent.id} for location {Game1.currentLocation?.NameOrUniqueName}", LogLevel.Error);
                }
            }

            base.receiveChatMessage(sourceFarmer, chatKind, language, message);
        }
Ejemplo n.º 26
0
        public static void Init(LocalizedContentManager.LanguageCode language)
        {
            SpriteFont font = ChatBox.messageFont(language);

            //This is theoretically right, but in practice makes everything too wide.

            /*widestCharacter = -1;
             * for (int i = 32; i < 127; i++)
             * {
             *  float width = font.MeasureString(char.ConvertFromUtf32(i)).X;
             *  if (width > widestCharacter)
             *      widestCharacter = width;
             * }*/

            widestCharacter = font.MeasureString("e").X;
        }
Ejemplo n.º 27
0
        /// <summary>This method get's ran whenever a player writes a message. This is used to capture the message sender and body to print into the console.</summary>
        /// <param name="sourceFarmer">The farmer that sent the message.</param>
        /// <param name="message">The message body.</param>
        private static void Postfix(long sourceFarmer, int chatKind, LocalizedContentManager.LanguageCode language, string message)
        {
            string playerName = "";

            // Find the player's nanme from the id
            if (sourceFarmer == Game1.player.UniqueMultiplayerID)
            {
                playerName = ChatBox.formattedUserName(Game1.player);
            }
            else if (Game1.otherFarmers.ContainsKey(sourceFarmer))
            {
                playerName = ChatBox.formattedUserName(Game1.otherFarmers[sourceFarmer]);
            }

            // Print to console the message
            ModMonitor.Log($"{playerName}: {message}", LogLevel.Info);
        }
Ejemplo n.º 28
0
        /****
        ** Methods
        ****/
        /// <summary>Update the current context.</summary>
        private void UpdateContext()
        {
            // get context
            IContentHelper contentHelper = this.Helper.Content;

            LocalizedContentManager.LanguageCode language = contentHelper.CurrentLocaleConstant;
            SDate   date    = null;
            Weather?weather = null;

            if (Context.IsWorldReady)
            {
                date    = SDate.Now();
                weather = this.GetCurrentWeather();
            }

            // update context
            this.VerboseLog($"Context: date={(date != null ? $"{date.DayOfWeek} {date.Season} {date.Day}" : "none")}, weather={(weather != null ? weather.ToString() : "none")}, locale={language}.");
            this.PatchManager.UpdateContext(contentHelper, language, date, weather);
        }
Ejemplo n.º 29
0
        /// <summary>Adds a message with formatting to the chat box.</summary>
        public override void receiveChatMessage(long sourceFarmer, int chatKind,
                                                LocalizedContentManager.LanguageCode language, string message)
        {
            bool   whisperMessage = false;
            string person         = "you";

            if (message[0] == WhisperSeparator)
            {
                string[] parts       = message.Substring(1).Split(WhisperSeparator);
                string   recipientId = Utils.DecipherText(parts[0], sourceFarmer ^ Game1.player.UniqueMultiplayerID);
                if (!long.TryParse(recipientId, out long recId) || recId != Game1.player.UniqueMultiplayerID)
                {
                    return;
                }
                message        = Utils.DecipherText(parts[1], sourceFarmer ^ Game1.player.UniqueMultiplayerID);
                whisperMessage = true;

                //check this tomorrow
                this.commandChatTextBox.LastWhisperId = sourceFarmer;
            }
            else if (message[0] == WhisperSeparator + 1)
            {
                string[] parts = message.Substring(1).Split(WhisperSeparator);
                person         = parts[0];
                message        = parts[1];
                whisperMessage = true;
            }

            string text1 = this.bFormatMessage.Invoke <string>(sourceFarmer, chatKind, message);

            if (whisperMessage)
            {
                text1 = text1.Substring(0, text1.IndexOf(":", StringComparison.InvariantCultureIgnoreCase)) +
                        $" (to {person} only):" +
                        text1.Substring(text1.IndexOf(":", StringComparison.InvariantCultureIgnoreCase) + 1);
            }
            string text2 = FixedParseText(text1, this.chatBox.Font, this.chatBox.Width - 16);

            foreach (string part in text2.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None))
            {
                this.AddNewMessage(part, this.messageColor(chatKind), this.chatBox.Font, language);
            }
        }
Ejemplo n.º 30
0
        private void readSettings(Stream stream)
        {
            StartupPreferences p = (StartupPreferences)serializer.Deserialize(stream);

            startMuted            = p.startMuted;
            timesPlayed           = p.timesPlayed + 1;
            levelTenCombat        = p.levelTenCombat;
            levelTenFishing       = p.levelTenFishing;
            levelTenForaging      = p.levelTenForaging;
            levelTenMining        = p.levelTenMining;
            skipWindowPreparation = p.skipWindowPreparation;
            windowMode            = p.windowMode;
            playerLimit           = p.playerLimit;
            gamepadMode           = p.gamepadMode;
            fullscreenResolutionX = p.fullscreenResolutionX;
            fullscreenResolutionY = p.fullscreenResolutionY;
            languageCode          = p.languageCode;
            clientOptions         = p.clientOptions;
        }