public static void RefreshPhoneLayout() { if (ModEntry.phoneRotated) { ModEntry.phoneWidth = Config.PhoneRotatedWidth; ModEntry.phoneHeight = Config.PhoneRotatedHeight; ModEntry.screenWidth = Config.ScreenRotatedWidth; ModEntry.screenHeight = Config.ScreenRotatedHeight; ModEntry.phoneOffsetX = Config.PhoneRotatedOffsetX; ModEntry.phoneOffsetY = Config.PhoneRotatedOffsetY; ModEntry.screenOffsetX = Config.ScreenRotatedOffsetX; ModEntry.screenOffsetY = Config.ScreenRotatedOffsetY; } else { ModEntry.phoneWidth = Config.PhoneWidth; ModEntry.phoneHeight = Config.PhoneHeight; ModEntry.screenWidth = Config.ScreenWidth; ModEntry.screenHeight = Config.ScreenHeight; ModEntry.phoneOffsetX = Config.PhoneOffsetX; ModEntry.phoneOffsetY = Config.PhoneOffsetY; ModEntry.screenOffsetX = Config.ScreenOffsetX; ModEntry.screenOffsetY = Config.ScreenOffsetY; } ModEntry.phonePosition = GetPhonePosition(); ModEntry.screenPosition = GetScreenPosition(); ModEntry.phoneIconPosition = GetPhoneIconPosition(); ModEntry.screenRect = new Rectangle((int)ModEntry.screenPosition.X, (int)ModEntry.screenPosition.Y, (int)ModEntry.screenWidth, (int)ModEntry.screenHeight); ModEntry.phoneRect = new Rectangle((int)ModEntry.phonePosition.X, (int)ModEntry.phonePosition.Y, ModEntry.phoneWidth, ModEntry.phoneHeight); GetArrowPositions(); ModEntry.appColumns = (ModEntry.screenWidth - Config.IconMarginX) / (Config.IconWidth + Config.IconMarginX); ModEntry.appRows = (ModEntry.screenHeight - Config.IconMarginY) / (Config.IconHeight + Config.IconMarginY); ModEntry.gridWidth = (ModEntry.screenWidth - Config.ContactMarginX) / (Config.ContactWidth + Config.ContactMarginX); ModEntry.gridHeight = (ModEntry.screenHeight - Config.ContactMarginY) / (Config.ContactHeight + Config.ContactMarginY); ModEntry.themeGridWidth = (ModEntry.screenWidth - Config.ThemeItemMarginX) / (Config.ThemeItemWidth + Config.ThemeItemMarginX); ModEntry.themeGridHeight = (ModEntry.screenHeight - Config.ThemeItemMarginY) / (Config.ThemeItemHeight + Config.ThemeItemMarginY); Vector2 screenSize = GetScreenSize(); ModEntry.phoneBookTexture = PhoneVisuals.MakeColorTexture(Config.PhoneBookBackgroundColor, screenSize); ModEntry.phoneBookHeaderTexture = PhoneVisuals.MakeColorTexture(Config.PhoneBookHeaderColor, new Vector2(screenSize.X, Config.AppHeaderHeight)); ModEntry.ringListBackgroundTexture = PhoneVisuals.MakeColorTexture(Config.RingListBackgroundColor, screenSize); ModEntry.ringListHighlightTexture = PhoneVisuals.MakeColorTexture(Config.RingListHighlightColor, new Vector2(screenSize.X, Config.RingListItemHeight)); ModEntry.themesHeaderTexture = PhoneVisuals.MakeColorTexture(Config.ThemesHeaderColor, new Vector2(screenSize.X, Config.AppHeaderHeight)); ModEntry.themesHighlightTexture = PhoneVisuals.MakeColorTexture(Config.ThemesFooterHighlightColor, new Vector2(screenSize.X / 2, Config.AppHeaderHeight)); ModEntry.answerTexture = PhoneVisuals.MakeColorTexture(Config.AnswerColor, new Vector2(screenSize.X / 2, Config.AppHeaderHeight)); ModEntry.declineTexture = PhoneVisuals.MakeColorTexture(Config.DeclineColor, new Vector2(screenSize.X / 2, Config.AppHeaderHeight)); }
/// <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) { context = this; Config = helper.ReadConfig <ModConfig>(); SHelper = helper; if (!Config.EnableMod) { return; } api = (MobilePhoneApi)GetApi(); MobilePhoneApp.Initialize(Helper, Monitor, Config); MobilePhoneCall.Initialize(Helper, Monitor, Config); ThemeApp.Initialize(Helper, Monitor, Config); PhoneVisuals.Initialize(Helper, Monitor, Config); PhoneInput.Initialize(Helper, Monitor, Config); PhoneGameLoop.Initialize(Helper, Monitor, Config); PhoneUtils.Initialize(Helper, Monitor, Config); PhonePatches.Initialize(Helper, Monitor, Config); if (Config.AddRotateApp) { apps.Add(Helper.ModRegistry.ModID + "_Rotate", new MobileApp(helper.Translation.Get("rotate-phone"), null, helper.Content.Load <Texture2D>("assets/rotate_icon.png"))); } var harmony = HarmonyInstance.Create(ModManifest.UniqueID); harmony.Patch( original: AccessTools.Method(typeof(Game1), nameof(Game1.pressSwitchToolButton)), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Game1_pressSwitchToolButton_prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(Event), nameof(Event.endBehaviors)), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_endBehaviors_prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(Farmer), nameof(Farmer.changeFriendship)), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Farmer_changeFriendship_prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(GameLocation), "resetLocalState"), postfix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.GameLocation_resetLocalState_postfix)) ); harmony.Patch( original: AccessTools.Method(typeof(GameLocation), nameof(GameLocation.answerDialogue)), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.GameLocation_answerDialogue_prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(Event), nameof(Event.command_awardFestivalPrize)), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(Event), nameof(Event.command_addTool)), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(Event), nameof(Event.command_addConversationTopic)), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(Event), nameof(Event.command_addCookingRecipe)), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(Event), nameof(Event.command_addCraftingRecipe)), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(Event), nameof(Event.command_money)), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(Event), nameof(Event.command_removeItem)), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(Event), nameof(Event.command_friendship)), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(Event), nameof(Event.command_dump)), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(Event), nameof(Event.command_addQuest)), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(Event), nameof(Event.command_cutscene)), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_cutscene_prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(Event), nameof(Event.skipEvent)), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_skipEvent_prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(Event), "namePet"), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_namePet_prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(CarpenterMenu), nameof(CarpenterMenu.returnToCarpentryMenu)), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.CarpenterMenu_returnToCarpentryMenu_prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(CarpenterMenu), nameof(CarpenterMenu.returnToCarpentryMenuAfterSuccessfulBuild)), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.CarpenterMenu_returnToCarpentryMenuAfterSuccessfulBuild_prefix)) ); Helper.Events.Input.ButtonPressed += PhoneInput.Input_ButtonPressed; Helper.Events.GameLoop.SaveLoaded += PhoneGameLoop.GameLoop_SaveLoaded; Helper.Events.GameLoop.GameLaunched += PhoneGameLoop.GameLoop_GameLaunched; Helper.Events.GameLoop.ReturnedToTitle += PhoneGameLoop.ReturnedToTitle; Helper.Events.GameLoop.TimeChanged += PhoneGameLoop.GameLoop_TimeChanged; Helper.Events.GameLoop.OneSecondUpdateTicked += PhoneGameLoop.GameLoop_OneSecondUpdateTicked; Helper.Events.Display.WindowResized += PhoneVisuals.Display_WindowResized; /* * var files = Directory.GetFiles(Path.Combine(Helper.DirectoryPath, Path.Combine("assets", "events"))); * foreach(string file in files) * { * Reminiscence r = Helper.Data.ReadJsonFile<Reminiscence>(Path.Combine("assets", Path.Combine("events", Path.GetFileName(file)))); * for(int i = 0; i < r.events.Count; i++) * { * string t = $"{Path.GetFileName(file).Replace(".json", "")}-event-{i}"; * Monitor.Log($"\"{t}\":\"{r.events[i].name}\""); * r.events[i].name = t; * } * Helper.Data.WriteJsonFile(Path.Combine("tmp", Path.GetFileName(file)),r); * } */ }
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; } } }
/// <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) { context = this; Config = helper.ReadConfig <ModConfig>(); SHelper = helper; if (!Config.EnableMod) { return; } api = (MobilePhoneApi)GetApi(); MobilePhoneApp.Initialize(Helper, Monitor, Config); MobilePhoneCall.Initialize(Helper, Monitor, Config); ThemeApp.Initialize(Helper, Monitor, Config); PhoneVisuals.Initialize(Helper, Monitor, Config); PhoneInput.Initialize(Helper, Monitor, Config); PhoneGameLoop.Initialize(Helper, Monitor, Config); PhoneUtils.Initialize(Helper, Monitor, Config); PhonePatches.Initialize(Helper, Monitor, Config); var harmony = HarmonyInstance.Create(ModManifest.UniqueID); harmony.Patch( original: AccessTools.Method(typeof(Game1), nameof(Game1.pressSwitchToolButton)), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Game1_pressSwitchToolButton_prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(Event), nameof(Event.endBehaviors)), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_endBehaviors_prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(Farmer), nameof(Farmer.changeFriendship)), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Farmer_changeFriendship_prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(GameLocation), "resetLocalState"), postfix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.GameLocation_resetLocalState_postfix)) ); harmony.Patch( original: AccessTools.Method(typeof(Event), nameof(Event.command_awardFestivalPrize)), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(Event), nameof(Event.command_addTool)), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(Event), nameof(Event.command_addConversationTopic)), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(Event), nameof(Event.command_addCookingRecipe)), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(Event), nameof(Event.command_addCraftingRecipe)), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(Event), nameof(Event.command_money)), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(Event), nameof(Event.command_removeItem)), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(Event), nameof(Event.command_friendship)), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(Event), nameof(Event.command_dump)), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(Event), nameof(Event.command_cutscene)), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_cutscene_prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(Event), "namePet"), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_namePet_prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(CarpenterMenu), nameof(CarpenterMenu.returnToCarpentryMenu)), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.CarpenterMenu_returnToCarpentryMenu_prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(CarpenterMenu), nameof(CarpenterMenu.returnToCarpentryMenuAfterSuccessfulBuild)), prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.CarpenterMenu_returnToCarpentryMenuAfterSuccessfulBuild_prefix)) ); Helper.Events.Input.ButtonPressed += PhoneInput.Input_ButtonPressed; Helper.Events.GameLoop.SaveLoaded += PhoneGameLoop.GameLoop_SaveLoaded; Helper.Events.GameLoop.GameLaunched += PhoneGameLoop.GameLoop_GameLaunched; Helper.Events.GameLoop.ReturnedToTitle += PhoneGameLoop.ReturnedToTitle; Helper.Events.GameLoop.TimeChanged += PhoneGameLoop.GameLoop_TimeChanged; Helper.Events.GameLoop.OneSecondUpdateTicked += PhoneGameLoop.GameLoop_OneSecondUpdateTicked; Helper.Events.Display.WindowResized += PhoneVisuals.Display_WindowResized; }