コード例 #1
0
        private void LoadGiftHelpers(IModHelper helper)
        {
            Utils.DebugLog("Initializing gift helpers");

            // TODO: add a reload method to the gift helpers instead of fully re-creating them
            // Force the gift info to be rebuilt
            IGiftDataProvider dataProvider = null;

            if (Config.ShowOnlyKnownGifts)
            {
                // The prefix is purely for convenience. Mostly so I know which is which.
                string prefix = new string(Game1.player.Name.Where(char.IsLetterOrDigit).ToArray());
                string path   = this.Config.ShareKnownGiftsWithAllSaves
                    ? Path.Combine(StoredGiftDatabase.DBRoot, StoredGiftDatabase.DBFileName)
                    : Path.Combine(StoredGiftDatabase.DBRoot, $"{prefix}_{Game1.player.UniqueMultiplayerID}", StoredGiftDatabase.DBFileName);

                GiftDatabase = new StoredGiftDatabase(helper, path);

                if (this.ModManifest.Version.IsNewerThan("2.7") && !this.Config.ShareKnownGiftsWithAllSaves)
                {
                    string oldPath     = Path.Combine(StoredGiftDatabase.DBRoot, Constants.SaveFolderName, StoredGiftDatabase.DBFileName);
                    string fullOldPath = Path.Combine(helper.DirectoryPath, oldPath);
                    if (File.Exists(fullOldPath))
                    {
                        Utils.DebugLog($"Found old DB at {oldPath}. Migrating to {path}.", LogLevel.Info);
                        StoredGiftDatabase dbRef = (StoredGiftDatabase)GiftDatabase;
                        StoredGiftDatabase.MigrateDatabase(helper, oldPath, ref dbRef);
                    }
                }

                dataProvider = new ProgressionGiftDataProvider(GiftDatabase);
                ControlEvents.MouseChanged            += CheckGiftGivenAfterMouseChanged;
                ControlEvents.ControllerButtonPressed += CheckGiftGivenAfterControllerButtonPressed;
            }
            else
            {
                GiftDatabase = new GiftDatabase(helper);
                dataProvider = new AllGiftDataProvider(GiftDatabase);
                ControlEvents.MouseChanged            -= CheckGiftGivenAfterMouseChanged;
                ControlEvents.ControllerButtonPressed -= CheckGiftGivenAfterControllerButtonPressed;
            }

            // Add the helpers if they're enabled in config
            CurrentGiftHelper = null;
            this.GiftHelpers  = new Dictionary <Type, IGiftHelper>();
            if (Config.ShowOnCalendar)
            {
                this.GiftHelpers.Add(typeof(Billboard), new CalendarGiftHelper(dataProvider, Config, helper.Reflection, helper.Translation));
            }
            if (Config.ShowOnSocialPage)
            {
                this.GiftHelpers.Add(typeof(GameMenu), new SocialPageGiftHelper(dataProvider, Config, helper.Reflection, helper.Translation));
            }

            MenuEvents.MenuClosed  += OnClickableMenuClosed;
            MenuEvents.MenuChanged += OnClickableMenuChanged;
        }
コード例 #2
0
        public AllGiftDataProvider(IGiftDatabase database)
            : base(database)
        {
            var tasteTypes = Enum.GetValues(typeof(GiftTaste)).Cast <GiftTaste>().Where(val => val != GiftTaste.MAX);

            foreach (var giftTaste in Game1.NPCGiftTastes)
            {
                foreach (var taste in tasteTypes)
                {
                    Database.AddGifts(giftTaste.Key, taste, Utils.GetItemsForTaste(giftTaste.Key, taste));
                }
            }
        }
コード例 #3
0
        private void LoadGiftHelpers(IModHelper helper)
        {
            Utils.DebugLog("Initializing gift helpers");

            // TODO: add a reload method to the gift helpers instead of fully re-creating them
            // Force the gift info to be rebuilt
            IGiftDataProvider dataProvider = null;

            if (Config.ShowOnlyKnownGifts)
            {
                string path = this.Config.ShareKnownGiftsWithAllSaves
                    ? Path.Combine(StoredGiftDatabase.DBRoot, StoredGiftDatabase.DBFileName)
                    : Path.Combine(StoredGiftDatabase.DBRoot, Constants.SaveFolderName, StoredGiftDatabase.DBFileName);

                GiftDatabase = new StoredGiftDatabase(helper, path);
                dataProvider = new ProgressionGiftDataProvider(GiftDatabase);
                ControlEvents.MouseChanged            += CheckGiftGivenAfterMouseChanged;
                ControlEvents.ControllerButtonPressed += CheckGiftGivenAfterControllerButtonPressed;
            }
            else
            {
                GiftDatabase = new GiftDatabase(helper);
                dataProvider = new AllGiftDataProvider(GiftDatabase);
                ControlEvents.MouseChanged            -= CheckGiftGivenAfterMouseChanged;
                ControlEvents.ControllerButtonPressed -= CheckGiftGivenAfterControllerButtonPressed;
            }

            // Add the helpers if they're enabled in config
            CurrentGiftHelper = null;
            this.GiftHelpers  = new Dictionary <Type, IGiftHelper>();
            if (Config.ShowOnCalendar)
            {
                this.GiftHelpers.Add(typeof(Billboard), new CalendarGiftHelper(dataProvider, Config, helper.Reflection, helper.Translation));
            }
            if (Config.ShowOnSocialPage)
            {
                this.GiftHelpers.Add(typeof(GameMenu), new SocialPageGiftHelper(dataProvider, Config, helper.Reflection, helper.Translation));
            }

            MenuEvents.MenuClosed  += OnClickableMenuClosed;
            MenuEvents.MenuChanged += OnClickableMenuChanged;
        }
コード例 #4
0
 public ProgressionGiftDataProvider(IGiftDatabase database)
     : base(database)
 {
 }
コード例 #5
0
 public BaseGiftDataProvider(IGiftDatabase database)
 {
     this.Database = database;
     this.Database.DatabaseChanged += () => DataSourceChanged?.Invoke();
 }