Ejemplo n.º 1
0
        /// <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);
             * }
             */
        }
Ejemplo n.º 2
0
 internal static void ReturnedToTitle(object sender, ReturnedToTitleEventArgs e)
 {
     ModEntry.ClosePhone();
 }
Ejemplo n.º 3
0
        private static void Display_RenderingActiveMenu(object sender, StardewModdingAPI.Events.RenderingActiveMenuEventArgs e)
        {
            if (Helper.Input.IsDown(SButton.MouseLeft) && ModEntry.screenRect.Contains(Game1.getMousePosition()))
            {
                int dy = Game1.getMouseY() - lastMousePositionY;
                if (Math.Abs(dy) > 0)
                {
                    dragging = true;
                }
                if (dragging)
                {
                    yOffset = (int)Math.Max(Math.Min(0, yOffset + dy), -1 * Math.Max(0, listHeight - ModEntry.GetScreenSize().Y));
                }
            }

            lastMousePositionY = Game1.getMouseY();

            if (!ModEntry.appRunning || !ModEntry.phoneOpen || !(Game1.activeClickableMenu is PhoneBookMenu))
            {
                ModEntry.appRunning      = false;
                ModEntry.phoneAppRunning = false;
                Helper.Events.Display.RenderingActiveMenu -= Display_RenderingActiveMenu;
                Helper.Events.Input.ButtonPressed         -= Input_ButtonPressed;
                Helper.Events.Input.ButtonReleased        -= Input_ButtonReleased;
                return;
            }
            e.SpriteBatch.Draw(ModEntry.phoneBookTexture, ModEntry.screenPosition, Color.White);

            if (yOffset < 0)
            {
                e.SpriteBatch.Draw(ModEntry.upArrowTexture, ModEntry.upArrowPosition, Color.White);
            }
            if (yOffset > ModEntry.GetScreenSize().Y - listHeight)
            {
                e.SpriteBatch.Draw(ModEntry.downArrowTexture, ModEntry.downArrowPosition, Color.White);
            }

            int screenBottom = (int)(ModEntry.screenPosition.Y + ModEntry.GetScreenSize().Y);

            for (int i = 0; i < callableList.Count; i++)
            {
                Vector2   npcPos = GetNPCPos(i);
                Rectangle r      = callableList[i].sourceRect;
                if (npcPos.Y < ModEntry.screenPosition.Y - r.Height * 2 || npcPos.Y >= screenBottom)
                {
                    continue;
                }
                Rectangle sourceRect = r;
                int       cutTop     = 0;
                int       cutBottom  = 0;
                if (npcPos.Y < ModEntry.screenPosition.Y)
                {
                    cutTop     = (int)Math.Round((ModEntry.screenPosition.Y - (int)npcPos.Y) / 2f);
                    sourceRect = new Rectangle(r.X, r.Y + cutTop, r.Width, r.Height - cutTop);
                    npcPos     = new Vector2(npcPos.X, ModEntry.screenPosition.Y);
                }
                else if (npcPos.Y > screenBottom - r.Height * 2)
                {
                    cutBottom  = (int)Math.Round((screenBottom - r.Height * 2 - (int)npcPos.Y) / 2f);
                    sourceRect = new Rectangle(r.X, r.Y, r.Width, r.Height + cutBottom);
                }

                e.SpriteBatch.Draw(callableList[i].portrait, npcPos + new Vector2((Config.ContactWidth - 32) / 2, 0), sourceRect, Color.White, 0, Vector2.Zero, 2, SpriteEffects.None, 0.86f);
                if (Config.ShowNamesInPhoneBook && npcPos.Y < screenBottom - Config.ContactHeight - callableList[i].nameSize.Y * 0.4f + 6)
                {
                    e.SpriteBatch.DrawString(Game1.dialogueFont, callableList[i].name, GetNPCPos(i) + new Vector2(Config.ContactWidth / 2 - callableList[i].nameSize.X * 0.2f, Config.ContactHeight - 6), Color.Black, 0, Vector2.Zero, 0.4f, SpriteEffects.None, 0.86f);
                }
            }
        }
Ejemplo n.º 4
0
        /// <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;
        }