private void SetUpConfig(object sender, StardewModdingAPI.Events.GameLaunchedEventArgs e) { var configMenu = Helper.ModRegistry.GetApi <IGenericModConfigMenuApi>("spacechase0.GenericModConfigMenu"); if (configMenu is null) { return; } configMenu.Register( mod: ModManifest, reset: () => Config = new ModConfig(), save: () => Helper.WriteConfig(Config) ); foreach (System.Reflection.PropertyInfo property in typeof(ModConfig).GetProperties()) { if (property.PropertyType.Equals(typeof(bool))) { configMenu.AddBoolOption( mod: ModManifest, getValue: () => (bool)property.GetValue(Config), setValue: value => property.SetValue(Config, value), name: () => Helper.Translation.Get($"{property.Name}.title") ); } } }
private void GameLoop_GameLaunchedSlow(object sender, StardewModdingAPI.Events.GameLaunchedEventArgs e) { Monitor.Log($"[{timer.Elapsed.TotalMilliseconds:N}][Slow] Game Launched", LogLevel.Info); }
public static void GameLoop_GameLaunched(object sender, StardewModdingAPI.Events.GameLaunchedEventArgs e) { foreach (IContentPack contentPack in Helper.ContentPacks.GetOwned()) { Monitor.Log($"Reading content pack: {contentPack.Manifest.Name} {contentPack.Manifest.Version} from {contentPack.DirectoryPath}"); try { MobilePhonePackJSON json = contentPack.ReadJsonFile <MobilePhonePackJSON>("content.json") ?? null; if (json != null) { if (json.apps != null && json.apps.Any()) { foreach (AppJSON app in json.apps) { Texture2D tex = contentPack.LoadAsset <Texture2D>(app.iconPath); if (tex == null) { continue; } ModEntry.apps.Add(app.id, new MobileApp(app.name, app.keyPress, app.closePhone, tex)); Monitor.Log($"Added app {app.name} from {contentPack.DirectoryPath}"); } } else if (json.iconPath != null) { Texture2D icon = contentPack.LoadAsset <Texture2D>(json.iconPath); if (icon == null) { continue; } ModEntry.apps.Add(json.id, new MobileApp(json.name, json.keyPress, json.closePhone, icon)); Monitor.Log($"Added app {json.name} from {contentPack.DirectoryPath}"); } if (json.invites != null && json.invites.Any()) { foreach (EventInvite invite in json.invites) { MobilePhoneCall.eventInvites.Add(invite); Monitor.Log($"Added event invite {invite.name} from {contentPack.DirectoryPath}"); } } } } catch (Exception ex) { Monitor.Log($"error reading content.json file in content pack {contentPack.Manifest.Name}.\r\n{ex}", LogLevel.Error); } if (Directory.Exists(Path.Combine(contentPack.DirectoryPath, "assets", "events"))) { Monitor.Log($"Adding events"); string[] events = Directory.GetFiles(Path.Combine(contentPack.DirectoryPath, "assets", "events"), "*.json"); Monitor.Log($"CP has {events.Length} events"); foreach (string eventFile in events) { try { string eventPath = Path.Combine("assets", "events", Path.GetFileName(eventFile)); Monitor.Log($"Adding events {Path.GetFileName(eventFile)} from {contentPack.DirectoryPath}"); Reminiscence r = contentPack.ReadJsonFile <Reminiscence>(eventPath); var key = Path.GetFileName(eventFile).Replace(".json", ""); MobilePhoneCall.contentPackReminiscences.TryAdd(key, new Reminiscence()); MobilePhoneCall.contentPackReminiscences[key].events.AddRange(r.events); Monitor.Log($"Added event {Path.GetFileName(eventFile)} from {contentPack.DirectoryPath}"); } catch { } } } if (Directory.Exists(Path.Combine(contentPack.DirectoryPath, "assets", "skins"))) { Monitor.Log($"Adding skins"); string[] skins = Directory.GetFiles(Path.Combine(contentPack.DirectoryPath, "assets", "skins"), "*_landscape.png"); Monitor.Log($"CP has {skins.Length} skins"); foreach (string skinFile in skins) { try { string skinPath = Path.Combine("assets", "skins", Path.GetFileName(skinFile)); Monitor.Log($"Adding skin {Path.GetFileName(skinFile).Replace("_landscape.png", "")} from {contentPack.DirectoryPath}"); Texture2D skin = contentPack.LoadAsset <Texture2D>(skinPath.Replace("_landscape.png", ".png")); Texture2D skinl = contentPack.LoadAsset <Texture2D>(skinPath); ThemeApp.skinList.Add(contentPack.Manifest.UniqueID + ":" + Path.GetFileName(skinFile).Replace("_landscape.png", "")); ThemeApp.skinDict.Add(contentPack.Manifest.UniqueID + ":" + Path.GetFileName(skinFile).Replace("_landscape.png", ""), new Texture2D[] { skin, skinl }); Monitor.Log($"Added skin {Path.GetFileName(skinFile).Replace("_landscape.png", "")} from {contentPack.DirectoryPath}"); } catch { } } } if (Directory.Exists(Path.Combine(contentPack.DirectoryPath, "assets", "backgrounds"))) { Monitor.Log($"Adding backgrounds"); string[] backgrounds = Directory.GetFiles(Path.Combine(contentPack.DirectoryPath, "assets", "backgrounds"), "*_landscape.png"); Monitor.Log($"CP has {backgrounds.Length} backgrounds"); foreach (string backFile in backgrounds) { try { string backPath = Path.Combine("assets", "backgrounds", Path.GetFileName(backFile)); Monitor.Log($"Adding background {Path.GetFileName(backFile).Replace("_landscape.png", "")} from {contentPack.DirectoryPath}"); Texture2D back = contentPack.LoadAsset <Texture2D>(backPath.Replace("_landscape.png", ".png")); Texture2D backl = contentPack.LoadAsset <Texture2D>(backPath); ThemeApp.backgroundDict.Add(contentPack.Manifest.UniqueID + ":" + Path.GetFileName(backFile).Replace("_landscape.png", ""), new Texture2D[] { back, backl }); ThemeApp.backgroundList.Add(contentPack.Manifest.UniqueID + ":" + Path.GetFileName(backFile).Replace("_landscape.png", "")); Monitor.Log($"Added background {Path.GetFileName(backFile).Replace("_landscape.png", "")} from {contentPack.DirectoryPath}"); } catch { } } } if (Directory.Exists(Path.Combine(contentPack.DirectoryPath, "assets", "ringtones"))) { Monitor.Log($"Adding ringtones"); string[] rings = Directory.GetFiles(Path.Combine(contentPack.DirectoryPath, "assets", "ringtones"), "*.wav"); Monitor.Log($"CP has {rings.Length} ringtones"); foreach (string path in rings) { try { object ring; try { var type = Type.GetType("System.Media.SoundPlayer, System"); ring = Activator.CreateInstance(type, new object[] { path }); } catch { ring = SoundEffect.FromStream(new FileStream(path, FileMode.Open)); } if (ring != null) { ThemeApp.ringDict.Add(string.Concat(contentPack.Manifest.UniqueID, ":", Path.GetFileName(path).Replace(".wav", "")), ring); ThemeApp.ringList.Add(string.Concat(contentPack.Manifest.UniqueID, ":", Path.GetFileName(path).Replace(".wav", ""))); Monitor.Log($"loaded ring {path}"); } else { Monitor.Log($"Couldn't load ring {path}"); } } catch (Exception ex) { Monitor.Log($"Couldn't load ring {path}:\r\n{ex}", LogLevel.Error); } } } } ModEntry.listHeight = Config.IconMarginY + (int)Math.Ceiling(ModEntry.apps.Count / (float)ModEntry.gridWidth) * (Config.IconHeight + Config.IconMarginY); PhoneVisuals.CreatePhoneTextures(); PhoneUtils.RefreshPhoneLayout(); if (Helper.ModRegistry.IsLoaded("purrplingcat.npcadventure")) { INpcAdventureModApi api = Helper.ModRegistry.GetApi <INpcAdventureModApi>("purrplingcat.npcadventure"); if (api != null) { Monitor.Log("Loaded NpcAdventureModApi successfully"); ModEntry.npcAdventureModApi = api; } } if (Helper.ModRegistry.IsLoaded("tlitookilakin.HDPortraits")) { IHDPortraitsAPI api = Helper.ModRegistry.GetApi <IHDPortraitsAPI>("tlitookilakin.HDPortraits"); if (api != null) { Monitor.Log("Loaded HD Portraits api successfully"); ModEntry.iHDPortraitsAPI = api; } } }
private void GameLoop_GameLaunched(object sender, StardewModdingAPI.Events.GameLaunchedEventArgs e) { // get Generic Mod Config Menu's API (if it's installed) var configMenu = Helper.ModRegistry.GetApi <IGenericModConfigMenuApi>("spacechase0.GenericModConfigMenu"); if (configMenu is null) { return; } // register mod configMenu.Register( mod: ModManifest, reset: () => Config = new ModConfig(), save: () => Helper.WriteConfig(Config) ); configMenu.AddBoolOption( mod: ModManifest, name: () => "Mod Enabled?", getValue: () => Config.EnableMod, setValue: value => Config.EnableMod = value ); configMenu.AddNumberOption( mod: ModManifest, name: () => "Min Points To Marry", getValue: () => Config.MinPointsToMarry, setValue: value => Config.MinPointsToMarry = value ); configMenu.AddNumberOption( mod: ModManifest, name: () => "Min Points To Date", getValue: () => Config.MinPointsToDate, setValue: value => Config.MinPointsToDate = value ); configMenu.AddNumberOption( mod: ModManifest, name: () => "Max Gifts Per Day", getValue: () => Config.MaxGiftsPerSpousePerDay, setValue: value => Config.MaxGiftsPerSpousePerDay = value ); configMenu.AddNumberOption( mod: ModManifest, name: () => "Max Gifts Per Week", getValue: () => Config.MaxGiftsPerSpousePerWeek, setValue: value => Config.MaxGiftsPerSpousePerWeek = value ); configMenu.AddBoolOption( mod: ModManifest, name: () => "Prevent Hostile Divorces", getValue: () => Config.PreventHostileDivorces, setValue: value => Config.PreventHostileDivorces = value ); configMenu.AddBoolOption( mod: ModManifest, name: () => "Complex Divorces", getValue: () => Config.ComplexDivorce, setValue: value => Config.ComplexDivorce = value ); configMenu.AddBoolOption( mod: ModManifest, name: () => "Roommate Romance", getValue: () => Config.RoommateRomance, setValue: value => Config.RoommateRomance = value ); configMenu.AddBoolOption( mod: ModManifest, name: () => "Show Parent Names", getValue: () => Config.ShowParentNames, setValue: value => Config.ShowParentNames = value ); configMenu.AddBoolOption( mod: ModManifest, name: () => "Buy Pendants Anytime", getValue: () => Config.BuyPendantsAnytime, setValue: value => Config.BuyPendantsAnytime = value ); configMenu.AddNumberOption( mod: ModManifest, name: () => "Pendant Price", getValue: () => Config.PendantPrice, setValue: value => Config.PendantPrice = value ); configMenu.AddNumberOption( mod: ModManifest, name: () => "Percent Chance For In Bed", getValue: () => Config.PercentChanceForSpouseInBed, setValue: value => Config.PercentChanceForSpouseInBed = value, min: 0, max: 100 ); configMenu.AddNumberOption( mod: ModManifest, name: () => "Chance For In Kitchen", getValue: () => Config.PercentChanceForSpouseInKitchen, setValue: value => Config.PercentChanceForSpouseInKitchen = value, min: 0, max: 100 ); configMenu.AddNumberOption( mod: ModManifest, name: () => "Chance For In Patio", getValue: () => Config.PercentChanceForSpouseAtPatio, setValue: value => Config.PercentChanceForSpouseAtPatio = value, min: 0, max: 100 ); LoadModApis(); }
private void SetUpConfig(object sender, StardewModdingAPI.Events.GameLaunchedEventArgs e) { // Try to get the GMCM menu var configMenu = Helper.ModRegistry.GetApi <IGenericModConfigMenuApi>("spacechase0.GenericModConfigMenu"); if (configMenu is null) { // Set up the modData recording wedding attire preferences even when GMCM is not installed Game1.player.modData[$"{this.ModManifest.UniqueID}/weddingAttirePref"] = this.Config.WeddingAttire; Monitor.Log("Saving player preferences into modData", LogLevel.Trace); return; } // Register the GMCM menu, and make sure write player preferences into moddata when the config is updated configMenu.Register( mod: ModManifest, reset: () => Config = new ModConfig(), save: () => { Helper.WriteConfig(Config); // Refresh the modData recording wedding attire preferences for this player Game1.player.modData[$"{this.ModManifest.UniqueID}/weddingAttirePref"] = this.Config.WeddingAttire; Monitor.Log("Saving player preferences into modData", LogLevel.Trace); } ); // Add the mod description into the GMCM menu configMenu.AddParagraph( mod: ModManifest, text: () => Helper.Translation.Get("mod.description") ); // If GMCM Options is not installed, add a text dropdown for the config options // Otherwise, add in the fancy display options using GMCM Options var configMenuExt = Helper.ModRegistry.GetApi <IGMCMOptionsAPI>("jltaylor-us.GMCMOptions"); if (configMenuExt is null) { configMenu.AddTextOption( mod: this.ModManifest, name: () => this.Helper.Translation.Get("weddingAttire.title"), tooltip: () => this.Helper.Translation.Get("weddingAttire.description"), getValue: () => this.Config.WeddingAttire, setValue: value => this.Config.WeddingAttire = value, allowedValues: new string[] { tuxOption, dressOption, noneOption, defaultOption }, formatAllowedValue: (str) => this.Helper.Translation.Get(str) ); } else { var values = new string[] { tuxOption, dressOption, noneOption, defaultOption }; configMenuExt.AddImageOption( mod: this.ModManifest, name: () => this.Helper.Translation.Get("weddingAttire.title"), tooltip: () => this.Helper.Translation.Get("weddingAttire.description"), getValue: () => (uint)Array.IndexOf(values, this.Config.WeddingAttire), setValue: (idx) => this.Config.WeddingAttire = values[idx], getMaxValue: () => (uint)values.Length - 1, maxImageHeight: () => 128, maxImageWidth: () => 64, drawImage: (v, b, pos) => { FarmerRenderer.isDrawingForUI = true; var farmer = Game1.player; var oldPantsColor = farmer.pantsColor.Value; var oldDir = farmer.facingDirection.Value; farmer.faceDirection(Game1.down); if (v == 0 || v == 3 && farmer.IsMale) // tux { farmer.changeShirt(10); farmer.changePantStyle(0); farmer.changePants(new Color(49, 49, 49)); } else if (v == 1) // dress { farmer.changeShirt(265); farmer.changePantStyle(2); farmer.changePants(new Color(255, 255, 255)); } farmer.FarmerRenderer.draw(b, farmer.FarmerSprite.CurrentAnimationFrame, farmer.FarmerSprite.CurrentFrame, farmer.FarmerSprite.SourceRect, pos, Vector2.Zero, 0.8f, Color.White, 0f, 1f, farmer); farmer.changeShirt(-1); farmer.changePants(oldPantsColor); farmer.changePantStyle(-1); farmer.faceDirection(oldDir); FarmerRenderer.isDrawingForUI = false; }, label: (idx) => this.Helper.Translation.Get(values[idx]), arrowLocation: (int)IGMCMOptionsAPI.ImageOptionArrowLocation.Sides, labelLocation: (int)IGMCMOptionsAPI.ImageOptionLabelLocation.Top ); } }