Ejemplo n.º 1
0
        private void GenericModConfigMenuIntegration(object sender, RenderedActiveMenuEventArgs e)     //Generic Mod Config Menu API
        {
            Helper.Events.Display.RenderedActiveMenu -= GenericModConfigMenuIntegration;
            if (Context.IsSplitScreen)
            {
                return;
            }
            canStartEditingAssets = true;
            Helper.Content.InvalidateCache("TileSheets/tools");
            Helper.Content.InvalidateCache("Maps/springobjects");
            Helper.Content.InvalidateCache("Strings/StringsFromCSFiles");
            Helper.Content.InvalidateCache("Data/ObjectInformation");

            var GenericMC = Helper.ModRegistry.GetApi <IGenericModConfigMenuApi>("spacechase0.GenericModConfigMenu");

            if (GenericMC != null)
            {
                GenericMC.Register(ModManifest, () => config = new ModConfig(), () => Helper.WriteConfig(config));
                GenericMC.AddSectionTitle(ModManifest, () => translate.Get("GenericMC.MainLabel")); //All of these strings are stored in the traslation files.
                GenericMC.AddParagraph(ModManifest, () => translate.Get("GenericMC.MainDesc"));
                GenericMC.AddParagraph(ModManifest, () => translate.Get("GenericMC.MainDesc2"));
                GenericMC.AddParagraph(ModManifest, () => translate.Get("GenericMC.MainDesc3"));

                try
                {
                    GenericMC.AddNumberOption(ModManifest, () => config.VoiceVolume, (int val) => config.VoiceVolume = val, () => translate.Get("GenericMC.Volume"), () => translate.Get("GenericMC.VolumeDesc"), 0, 100);

                    GenericMCPerScreen(GenericMC, 0);
                    GenericMC.AddPageLink(ModManifest, "colors", () => translate.Get("GenericMC.Colors"), () => translate.Get("GenericMC.Colors"));
                    GenericMC.AddPageLink(ModManifest, "itemData", () => translate.Get("GenericMC.ItemData"), () => translate.Get("GenericMC.ItemData"));

                    GenericMC.AddPageLink(ModManifest, "s2", () => translate.Get("GenericMC.SplitScreen2"), () => translate.Get("GenericMC.SplitScreenDesc"));
                    GenericMC.AddPageLink(ModManifest, "s3", () => translate.Get("GenericMC.SplitScreen3"), () => translate.Get("GenericMC.SplitScreenDesc"));
                    GenericMC.AddPageLink(ModManifest, "s4", () => translate.Get("GenericMC.SplitScreen4"), () => translate.Get("GenericMC.SplitScreenDesc"));
                    GenericMCPerScreen(GenericMC, 1);
                    GenericMCPerScreen(GenericMC, 2);
                    GenericMCPerScreen(GenericMC, 3);

                    GenericMC.AddPage(ModManifest, "colors", () => translate.Get("GenericMC.Colors"));
                    GenericMCColorPicker(GenericMC, ModManifest);
                    GenericMC.AddBoolOption(ModManifest, () => config.BossTransparency, (bool val) => config.BossTransparency = val,
                                            () => translate.Get("GenericMC.BossTransparency"), () => translate.Get("GenericMC.BossTransparencyDesc"));

                    GenericMC.AddPage(ModManifest, "itemData", () => translate.Get("GenericMC.ItemData"));
                    GenericMC.AddParagraph(ModManifest, () => translate.Get("GenericMC.ItemDataDesc1"));
                    GenericMC.AddParagraph(ModManifest, () => translate.Get("GenericMC.ItemDataDesc2"));
                    GenericMC.AddParagraph(ModManifest, () => translate.Get("GenericMC.ItemDataDesc3"));
                    GenericMC.AddParagraph(ModManifest, () => translate.Get("GenericMC.ItemDataDesc4"));

                    foreach (var item in config.SeeInfoForBelowData)
                    {
                        Item   o     = (itemIDs.ContainsKey(item.Key)) ? new StardewValley.Object(itemIDs[item.Key], 1) : null;
                        string space = "";
                        if (o == null)
                        {
                            FishingRod rod = new FishingRod();
                            while (rod.UpgradeLevel < 5)
                            {
                                if (rod.Name.Equals(item.Key))
                                {
                                    o = rod;
                                    break;
                                }
                                rod.UpgradeLevel++;
                            }
                        }
                        if (o != null)
                        {
                            for (int i = 0; i < 26 - (o.DisplayName.Length / 2); i++)
                            {
                                space += " ";
                            }
                            if (o is FishingRod)
                            {
                                GenericMC.AddImage(ModManifest, () => Game1.toolSpriteSheet, Game1.getSourceRectForStandardTileSheet(Game1.toolSpriteSheet, (o as FishingRod).IndexOfMenuItemView, 16, 16), 4);
                            }
                            else
                            {
                                GenericMC.AddImage(ModManifest, () => Game1.objectSpriteSheet, Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, o.ParentSheetIndex, 16, 16), 4);
                            }
                            GenericMC.AddSectionTitle(ModManifest, () => space + o.DisplayName, () => item.Key);
                        }
                        else
                        {
                            for (int i = 0; i < 26 - (item.Key.Length / 2); i++)
                            {
                                space += " ";
                            }
                            GenericMC.AddSectionTitle(ModManifest, () => space + item.Key, () => item.Key);
                        }

                        foreach (var effect in item.Value)
                        {
                            if (effect.Key.StartsWith("EXTRA_", StringComparison.Ordinal))
                            {
                                GenericMC.AddNumberOption(ModManifest, () => config.SeeInfoForBelowData[item.Key][effect.Key],
                                                          (int val) => config.SeeInfoForBelowData[item.Key][effect.Key] = val, () => effect.Key, () => translate.Get("Effects.EXTRA").Tokens(new { max = "MAX", chance = "CHANCE" }),
                                                          0, effect.Key.Equals("EXTRA_MAX", StringComparison.Ordinal) ? 10 : 100);
                            }
                            else
                            {
                                GenericMC.AddNumberOption(ModManifest, () => config.SeeInfoForBelowData[item.Key][effect.Key], (int val) => config.SeeInfoForBelowData[item.Key][effect.Key] = val,
                                                          () => effect.Key, () => translate.Get("Effects." + effect.Key).Tokens(new { val = "X" }),
                                                          (effect.Key.Equals("QUALITY", StringComparison.Ordinal) ? -4 : effect.Key.Equals("LIFE", StringComparison.Ordinal) ? 0 : -100),
                                                          (effect.Key.Equals("QUALITY", StringComparison.Ordinal) ? 4 : effect.Key.Equals("LIFE", StringComparison.Ordinal) ? 50 : 300));
                            }
                        }
                    }

                    //dummy value validation trigger - must be the last thing, so all values are saved before validation
                    GenericMC.AddComplexOption(ModManifest, () => "", () => "", (SpriteBatch b, Vector2 pos) => { }, () => UpdateConfig(true));
                }
                catch (Exception)
                {
                    this.Monitor.Log("Error parsing config data. Please either fix your config.json, or delete it to generate a new one.", LogLevel.Error);
                }
            }
        }
Ejemplo n.º 2
0
        private void UpdateConfig(bool GMCM)
        {
            if (!GMCM)
            {
                config = Helper.ReadConfig <ModConfig>();
            }

            int fix = 0;

            foreach (var item in config.SeeInfoForBelowData.ToArray())//updates old configs to new format
            {
                foreach (var effect in item.Value.ToArray())
                {
                    if (effect.Key.Equals("DOUBLE", StringComparison.Ordinal))
                    {
                        config.SeeInfoForBelowData[item.Key].Remove(effect.Key);
                        if (item.Key.Equals("Wild Bait", StringComparison.Ordinal))
                        {
                            config.SeeInfoForBelowData[item.Key]["EXTRA_MAX"]    = 2;
                            config.SeeInfoForBelowData[item.Key]["EXTRA_CHANCE"] = 20;
                        }
                        else
                        {
                            config.SeeInfoForBelowData[item.Key]["EXTRA_MAX"]    = 0;
                            config.SeeInfoForBelowData[item.Key]["EXTRA_CHANCE"] = 0;
                        }
                        fix++;
                    }
                }
            }
            if (fix > 0)
            {
                Helper.WriteConfig(config);
            }

            Minigames.itemData = config.SeeInfoForBelowData;

            if (Minigames.voices == null)
            {
                Minigames.voices = new Dictionary <string, SoundEffect>();
                try
                {
                    DirectoryInfo dir = new DirectoryInfo(Path.Combine(Helper.DirectoryPath, "assets/audio"));

                    if (!dir.Exists)
                    {
                        throw new DirectoryNotFoundException();
                    }

                    FileInfo[] files = dir.GetFiles("*.wav");

                    foreach (FileInfo file in files)
                    {
                        Minigames.voices[Path.GetFileNameWithoutExtension(file.Name)] = SoundEffect.FromStream(file.Open(FileMode.Open));
                    }
                    //Minigames.fishySound["Mute"] = SoundEffect.FromStream(new FileStream(Path.Combine(Helper.DirectoryPath, "assets/audio", "Mute.wav"), FileMode.Open));
                }
                catch (Exception ex)
                {
                    Monitor.Log($"error loading audio: {ex}", LogLevel.Error);
                }
            }

            for (int i = 0; i < 4; i++)
            {
                if (!config.Voice_Test_Ignore_Me[i].Equals(config.VoiceVolume + "/" + config.VoiceType[i] + "/" + config.VoicePitch[i], StringComparison.Ordinal)) //play voice and save it if changed
                {
                    config.Voice_Test_Ignore_Me[i] = config.VoiceVolume + "/" + config.VoiceType[i] + "/" + config.VoicePitch[i];
                    if (Minigames.voices.TryGetValue(config.VoiceType[i], out SoundEffect sfx))
                    {
                        sfx.Play(config.VoiceVolume / 100f * 0.98f, config.VoicePitch[i] / 100f, 0f);
                    }
                    Helper.WriteConfig(config);
                }

                try //keybinds
                {
                    if (config.KeyBinds.Equals("") || config.KeyBinds.Equals(" "))
                    {
                        throw new FormatException("String can't be empty.");
                    }
                    Minigames.keyBinds[i] = KeybindList.Parse(config.KeyBinds[i]);
                }
                catch (Exception e)
                {
                    string def = "MouseLeft, C, ControllerX";
                    Minigames.keyBinds[i] = KeybindList.Parse(def);
                    config.KeyBinds[i]    = def;
                    Helper.WriteConfig(config);
                    Monitor.Log(e.Message + " Resetting KeyBinds for screen " + (i + 1) + " to default. For key names, see: https://stardewcommunitywiki.com/Modding:Player_Guide/Key_Bindings", LogLevel.Error);
                }

                Minigames.voicePitch[i] = config.VoicePitch[i] / 100f;
            }
            if (Context.IsWorldReady)
            {
                Minigames.voiceVolume             = config.VoiceVolume / 100f;
                Minigames.voiceType               = config.VoiceType;
                Minigames.freeAim                 = config.FreeAim;
                Minigames.startMinigameStyle      = config.StartMinigameStyle;
                Minigames.endMinigameStyle        = config.EndMinigameStyle;
                Minigames.endCanLoseTreasure      = config.EndLoseTreasureIfFailed;
                Minigames.minigameDamage          = config.EndMinigameDamage;
                Minigames.minigameDifficulty      = config.MinigameDifficulty;
                Minigames.festivalMode            = config.FestivalMode;
                Minigames.realisticSizes          = config.RealisticSizes;
                Minigames.fishTankSprites         = config.FishTankHoldSprites;
                Minigames.minigameColor           = config.MinigameColor;
                MinigamesStart.minigameStyle      = config.StartMinigameStyle;
                MinigamesStart.minigameColor      = config.MinigameColor;
                MinigamesStart.minigameDifficulty = config.MinigameDifficulty;
                MinigamesStart.startMinigameScale = config.StartMinigameScale;
                MinigamesStart.tutorialSkip       = config.TutorialSkip;
                MinigamesStart.bossTransparency   = config.BossTransparency;
                if (LocalizedContentManager.CurrentLanguageCode == 0 && Minigames.metricSizes != config.ConvertToMetric)
                {
                    Minigames.metricSizes = config.ConvertToMetric;
                    Helper.Content.InvalidateCache("Strings/StringsFromCSFiles");
                }
                Helper.Content.InvalidateCache("Data/ObjectInformation");
            }
        }