Пример #1
0
        /*********
        ** Public methods
        *********/
        /// <summary>The mod entry point, called after the mod is first loaded.</summary>
        /// <param name="helper">Provides simplified APIs for writing mods.</param>
        public override void Entry(IModHelper helper)
        {
            // read config
            _config = helper.ReadConfig <ModConfigModel>();

            // set up sounds
            if (Constants.TargetPlatform == GamePlatform.Windows && _config.EnableWhistleAudio)
            {
                try
                {
                    _customSoundBank = new SoundBankWrapper(new SoundBank(Game1.audioEngine.Engine, Path.Combine(helper.DirectoryPath, "assets", "CustomSoundBank.xsb")));
                    _customWaveBank  = new WaveBank(Game1.audioEngine.Engine, Path.Combine(helper.DirectoryPath, "assets", "CustomWaveBank.xwb"));
                    _hasAudio        = true;
                }
                catch (ArgumentException ex)
                {
                    _customSoundBank = null;
                    _customWaveBank  = null;
                    _hasAudio        = false;

                    Monitor.Log("Couldn't load audio, so the whistle sound won't play.");
                    Monitor.Log(ex.ToString(), LogLevel.Trace);
                }
            }

            // add event listeners
            helper.Events.Input.ButtonPressed += this.OnButtonPressed;
            if (_config.EnableGrid)
            {
                helper.Events.GameLoop.UpdateTicked += this.UpdateTicked;
                helper.Events.Display.Rendered      += this.OnRendered;
            }
        }
Пример #2
0
        /*********
        ** Public methods
        *********/
        /// <inheritdoc />
        /// <summary>Initialise the mod.</summary>
        /// <param name="helper">Provides methods for interacting with the mod directory, such as read/writing a config file or custom JSON files.</param>
        public override void Entry(IModHelper helper)
        {
            _config = helper.ReadConfig <ModConfigModel>();

            if (Constants.TargetPlatform == GamePlatform.Windows && _config.EnableWhistleAudio)
            {
                try
                {
                    _customSoundBank = new SoundBankWrapper(new SoundBank(Game1.audioEngine,
                                                                          Path.Combine(helper.DirectoryPath, "assets", "CustomSoundBank.xsb")));
                    _customWaveBank = new WaveBank(Game1.audioEngine,
                                                   Path.Combine(helper.DirectoryPath, "assets", "CustomWaveBank.xwb"));
                    _hasAudio = true;
                }
                catch (ArgumentException ex)
                {
                    _customSoundBank = null;
                    _customWaveBank  = null;
                    _hasAudio        = false;

                    Monitor.Log("Couldn't load audio, so the whistle sound won't play.");
                    Monitor.Log(ex.ToString(), LogLevel.Trace);
                }
            }

            // add all event listener methods
            InputEvents.ButtonPressed += InputEvents_ButtonPressed;
            if (!_config.EnableGrid)
            {
                return;
            }
            GameEvents.SecondUpdateTick      += (sender, e) => UpdateGrid();
            GraphicsEvents.OnPostRenderEvent += (sender, e) => DrawGrid(Game1.spriteBatch);
        }
Пример #3
0
        /// <summary>Lets the handler run the logic for doing the split after the amount has been input.</summary>
        /// <param name="amount">The stack size the user requested.</param>
        public override void OnStackAmountEntered(int amount)
        {
            // Run regular inventory logic if that's what was clicked.
            if (this.WasInventoryClicked)
            {
                base.OnStackAmountEntered(amount);
                return;
            }

            int        count         = Math.Min(amount, this.MaxAmount);
            ISoundBank origSoundBank = Game1.soundBank;

            for (int i = 0; i < count; ++i)
            {
                // Only play sound for the very first RightClick, or else the sound will mix together and sounds horrible
                if (i > 0)
                {
                    Game1.soundBank = null;
                }
                this.MenuPage.receiveRightClick(this.ClickItemLocation.X, this.ClickItemLocation.Y, playSound: i == 0);
                Game1.soundBank = origSoundBank;
                // NOTE: This nullify-then-restore tactic is needed because as of SDV 1.5.4, CraftingPage.receiveRightClick actually
                //       *ignores* the playSound parameter; it's supposed to pass that parameter to CraftingPage.clickCraftingRecipe,
                //       but it doesn't. So the same sound gets layered one atop another with a slight shift, resulting in an overly
                //       loud and very distorted blip.
                //       If this oversight is fixed in a future patch, we can remove the nullify-and-restore lines.
            }
        }
Пример #4
0
        /// <summary>Create a xwb and xsb music pack pair.</summary>
        /// <param name="helper">The mod helper from the mod that will handle loading in the file.</param>
        /// <param name="wavBankPath">A relative path to the .xwb file in the mod helper's mod directory.</param>
        /// <param name="soundBankPath">A relative path to the .xsb file in the mod helper's mod directory.</param>
        public XACTMusicPair(IModHelper helper, string wavBankPath, string soundBankPath)
        {
            wavBankPath   = Path.Combine(helper.DirectoryPath, wavBankPath);
            soundBankPath = Path.Combine(helper.DirectoryPath, soundBankPath);

            this.waveBank  = new WaveBank(Game1.audioEngine.Engine, wavBankPath);
            this.soundBank = new SoundBankWrapper(new SoundBank(Game1.audioEngine.Engine, soundBankPath));
        }
        /// <summary>
        /// Create a new instance of the <see cref="SAATSoundBankWrapper"/> class, an implementation of <see cref="ISoundBank"/>.
        /// </summary>
        /// <param name="defaultCue">The cue implementation to default to on failure to retrieve/load cues.</param>
        /// <param name="monitor">Implementation of SMAPI's monitor and logging system.</param>
        /// <param name="wrapper">The game code's implementation of <see cref="ISoundBank"/> currently in use.</param>
        internal SAATSoundBankWrapper(CueDefinition defaultCue, IMonitor monitor, ISoundBank wrapper)
        {
            this.defaultDefinition = defaultCue;
            wrapper.AddCue(defaultCue);
            this.defaultCue = wrapper.GetCue(this.defaultDefinition.name);

            this.sdvSoundBankWrapper = wrapper;
            this.monitor             = monitor;
        }
Пример #6
0
        /// <summary>
        /// Make a new Sound Manager to play and manage sounds in a modded wave bank.
        /// </summary>
        /// <param name="newWaveBank">The reference to the wave bank in the mod's asset folder.</param>
        /// <param name="newSoundBank">The reference to the sound bank in the mod's asset folder.</param>
        public XACTSound(WaveBank newWaveBank, ISoundBank newSoundBank, string soundName)
        {
            this.waveBank  = newWaveBank;
            this.soundBank = newSoundBank;

            vanillaSoundBank = Game1.soundBank;
            vanillaWaveBank  = Game1.waveBank;
            this.soundName   = soundName;
            song             = this.soundBank.GetCue(this.soundName);
        }
        /// <summary>
        /// Entry point for the mod.
        /// </summary>
        /// <param name="helper"></param>
        public override void Entry(IModHelper helper)
        {
            DefaultSoundBank = Game1.soundBank;
            DefaultWaveBank  = Game1.waveBank;
            ModHelper        = helper;
            ModMonitor       = Monitor;
            Manifest         = ModManifest;
            Config           = helper.ReadConfig <Config>();
            StardewModdingAPI.Events.SaveEvents.AfterLoad += SaveEvents_AfterLoad;
            // StardewModdingAPI.Events.EventArgsLocationsChanged += LocationEvents_CurrentLocationChanged;

            StardewModdingAPI.Events.PlayerEvents.Warped      += PlayerEvents_Warped;
            StardewModdingAPI.Events.GameEvents.UpdateTick    += GameEvents_UpdateTick;
            StardewModdingAPI.Events.ControlEvents.KeyPressed += ControlEvents_KeyPressed;
            StardewModdingAPI.Events.SaveEvents.BeforeSave    += SaveEvents_BeforeSave;

            StardewModdingAPI.Events.MenuEvents.MenuChanged += MenuEvents_MenuChanged;
            StardewModdingAPI.Events.MenuEvents.MenuClosed  += MenuEvents_MenuClosed;

            StardewModdingAPI.Events.GameEvents.FirstUpdateTick += GameEvents_FirstUpdateTick;
            StardewModdingAPI.Events.GameEvents.OneSecondTick   += GameEvents_OneSecondTick;


            musicManager = new MusicManager();

            MusicPath              = Path.Combine(ModHelper.DirectoryPath, "Content", "Music");
            WavMusicDirectory      = Path.Combine(MusicPath, "Wav");
            XACTMusicDirectory     = Path.Combine(MusicPath, "XACT");
            TemplateMusicDirectory = Path.Combine(MusicPath, "Templates");


            textureManager = new TextureManager();
            this.createDirectories();
            this.createBlankXACTTemplate();
            this.createBlankWAVTemplate();

            musicPacksInitialized = false;
            menuChangedMusic      = false;


            //Initialize all of the lists upon creation during entry.
            SongSpecifics.initializeMenuList();
            SongSpecifics.initializeEventsList();
            SongSpecifics.initializeFestivalsList();

            initializeMusicPacks();
        }
Пример #8
0
        private static void PlayWhistle()
        {
            if (LoadSound < 0)
            {
                return;
            }

            if (LoadSound == 0)
            {
                try
                {
                    MySoundBank = new SoundBankWrapper(new SoundBank(Game1.audioEngine,
                                                                     Path.Combine(ModMain.ModHelper.DirectoryPath, "Assets", "WhistleSoundBank.xsb")));
                    MyWaveBank = new WaveBank(Game1.audioEngine,
                                              Path.Combine(ModMain.ModHelper.DirectoryPath, "Assets", "WhistleWaveBank.xwb"));

                    OrgSoundBank = Game1.soundBank;
                    OrgWaveBank  = Game1.waveBank;
                    LoadSound    = 1;
                }
                catch (ArgumentException ex)
                {
                    LoadSound = -1;
                }
            }

            try
            {
                Game1.soundBank = MySoundBank;
                Game1.waveBank  = MyWaveBank;
                Game1.audioEngine.Update();
                Game1.playSound("horseWhistle");
            }
            finally
            {
                Game1.soundBank = OrgSoundBank;
                Game1.waveBank  = OrgWaveBank;
                Game1.audioEngine.Update();
            }
        }
Пример #9
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="directoryToXwb"></param>
        /// <param name="pathToWaveBank"></param>
        /// <param name="pathToSoundBank"></param>
        public XACTMusicPack(string directoryToXwb, string pathToWaveBank, string pathToSoundBank)
        {
            this.directory     = directoryToXwb;
            this.WaveBankPath  = pathToWaveBank;
            this.SoundBankPath = pathToSoundBank;
            this.setModDirectoryFromFullDirectory();
            this.songInformation      = new SongSpecifics();
            this.currentCue           = null;
            this.musicPackInformation = MusicPackMetaData.readFromJson(directoryToXwb);
            if (this.musicPackInformation == null)
            {
                if (StardewSymphony.Config.EnableDebugLog)
                {
                    StardewSymphony.ModMonitor.Log("Error: MusicPackInformation.json not found at: " + directoryToXwb + ". Blank information will be put in place.", StardewModdingAPI.LogLevel.Warn);
                }
                this.musicPackInformation = new MusicPackMetaData("???", "???", "", "0.0.0", "");
            }

            this.WaveBank  = new WaveBank(Game1.audioEngine, this.WaveBankPath);
            this.SoundBank = (ISoundBank) new SoundBankWrapper(new SoundBank(Game1.audioEngine, this.SoundBankPath));
            this.loadMusicFiles();
        }
Пример #10
0
        /// <summary>
        /// Constructor for XACT files.
        /// </summary>
        /// <param name="waveBank"></param>
        /// <param name="soundBank"></param>
        /// <param name="songName"></param>
        public void loadXACTFile(WaveBank waveBank, ISoundBank soundBank, string songName)
        {
            XACTSound xactSound = new XACTSound(waveBank, soundBank, songName);

            this.sounds.Add(songName, xactSound);
        }