public static void ExportSundial()
 {
     if (locations.Count > 0)
     {
         instance.config.UseTempFolder = true;
         GameLocation loc = locations.Dequeue();
         instance.Monitor.Log(loc.Name);
         PlatoWarpMenuMod.GetLocationShotSundial(loc, ExportSundial);
     }
 }
        public override void Entry(IModHelper helper)
        {
            instance        = this;
            _helper         = helper;
            WarpMenu.Helper = Helper;

            config = helper.ReadConfig <Config>();

            helper.Events.Input.ButtonPressed += Input_ButtonPressed;

            helper.Events.GameLoop.GameLaunched += (s, e) => SetUpConfigMenu();

            var harmony = Harmony.HarmonyInstance.Create("Platonymous.PlatoWarpMenu");

            harmony.Patch(typeof(Image).GetMethod("Save", new Type[] { typeof(string), typeof(ImageFormat) }), prefix: new Harmony.HarmonyMethod(this.GetType().GetMethod("InterceptScreenshot", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public)));
        }
Exemple #3
0
        public override void Entry(IModHelper helper)
        {
            instance = this;
            _helper = helper;
            tempFolder = Path.Combine(helper.DirectoryPath, "Temp");
            if (!Directory.Exists(tempFolder))
                Directory.CreateDirectory(tempFolder);
            config = helper.ReadConfig<Config>();

            helper.Events.Input.ButtonPressed += Input_ButtonPressed;

            helper.Events.GameLoop.GameLaunched += (s, e) =>
            {

                SetUpConfigMenu();

                if (Helper.ModRegistry.GetApi<IMobilePhoneApi>("aedenthorn.MobilePhone") is IMobilePhoneApi api)
                {
                    Texture2D appIcon = Helper.Content.Load<Texture2D>(Path.Combine("assets", "mobile_app_icon.png"));
                    bool success = api.AddApp(Helper.ModRegistry.ModID + "MobileWarpMenu", "Warp Menu", () =>
                    {
                        OpenUpMenu();
                    }, appIcon);
                }
            };

            var harmony = Harmony.HarmonyInstance.Create("Platonymous.PlatoWarpMenu");
            bool patched = false;

            if (!config.CompatibilityMode || Constants.TargetPlatform == GamePlatform.Android)
            {
                try
                {
                    harmony.Patch(Type.GetType("System.Drawing.Image, System.Drawing").GetMethod("Save", new Type[] { typeof(string), Type.GetType("System.Drawing.Imaging.ImageFormat, System.Drawing") }), prefix: new Harmony.HarmonyMethod(this.GetType().GetMethod("InterceptScreenshot", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public)));
                    patched = true;
                }
                catch
                {

                }
            }
        }
        private UIElement GetMenuForLocation(GameLocation location, NPC npc = null, bool artifacts = false, bool structure = false)
        {
            var   lmenu     = UIElement.GetContainer("Location Menu " + location.Name, positioner: UIHelper.GetCentered(0, 0, 1f, 1f));
            float textScale = 1.4f;

            if (LocalizedContentManager.CurrentLanguageLatin && menuFont2 != "" && menuFont2 != null)
            {
                textScale *= cFontAdjust;
            }
            var lname = !structure ? location.Name : location.uniqueName.Value;

            if (i18n.GetTranslations().ToList().Exists(t => t.Key == "location." + lname))
            {
                lname = i18n.Get("location." + lname);
            }

            var lmenuHead = new UITextElement(lname, Game1.dialogueFont, Color.White, textScale, positioner: UIHelper.GetTopCenter(0, 5));


            var back = location.Map.GetLayer("Back");

            double w = back.LayerWidth;
            double h = back.LayerHeight;
            double s = (h / w);

            int tw = (menuWidth / 2) - (4 * margins);
            int th = (int)(tw * s);

            if (th > menuHeight * 0.75f)
            {
                s  = (w / h);
                th = (int)(menuHeight * 0.75f);
                tw = (int)(th * s);
            }

            var lmenuViewer = UIElement.GetImage(PyDraw.getWhitePixel(), Color.Green, positioner: UIHelper.GetTopCenter(0, 50, tw, th));

            var lmenuWarp    = new UITextElement($"{i18n.Get("menu.locations.warp")} (X:0 Y:0)", Game1.dialogueFont, Color.White, textScale, positioner: UIHelper.GetTopCenter(0, th + 60));
            var lmenuLoading = new UITextElement(i18n.Get("menu.locations.loading"), Game1.dialogueFont, Color.White, textScale, positioner: UIHelper.GetCentered());

            lmenuViewer.Add(lmenuLoading);

            if (LocalizedContentManager.CurrentLanguageLatin && menuFont2 != "" && menuFont2 != null)
            {
                lmenuHead.WithFont(menuFont2);
                lmenuWarp.WithFont(menuFont2);
                lmenuLoading.WithFont(menuFont2);
            }

            lmenu.Add(lmenuViewer);

            Point tPoint = new Point(0, 0);

            lmenuViewer.WithInteractivity(update: (t, el) =>
            {
                PlatoWarpMenuMod.GetLocationShot(location, () =>
                {
                    Texture2D screen = PlatoWarpMenuMod.LastScreen;
                    if (PlatoWarpMenuMod.instance.config.UseTempFolder)
                    {
                        screen = Helper.Content.Load <Texture2D>(Path.Combine("Temp", (location.isStructure.Value ? location.uniqueName.Value : location.Name) + ".png"));
                    }
                    var image = UIElement.GetImage(screen, Color.White, positioner: el.Positioner);
                    image.WithInteractivity(click: (point, right, released, hold, imageContainer) =>
                    {
                        if (released && !right)
                        {
                            if (!location.isTileLocationTotallyClearAndPlaceableIgnoreFloors(new Vector2(tPoint.X, tPoint.Y)))
                            {
                                return;
                            }
                            Game1.activeClickableMenu = null;
                            Game1.player.warpFarmer(new Warp(0, 0, structure ? location.uniqueName.Value : location.Name, tPoint.X, tPoint.Y, false));
                        }
                    }, hover: (point, drag, imageContainer) =>
                    {
                        var rect = imageContainer.Bounds;
                        int x    = (int)(((point.X - rect.X) / (double)rect.Width) * location.Map.GetLayer("Back").LayerWidth);
                        int y    = (int)(((point.Y - rect.Y) / (double)rect.Height) * location.Map.GetLayer("Back").LayerHeight);
                        tPoint   = new Point(x, y);

                        lmenuWarp.Text = $"{i18n.Get("menu.locations.warp")} (X:{ (int)x} Y:{(int)y})";

                        if (!location.isTileLocationTotallyClearAndPlaceableIgnoreFloors(new Vector2(x, y)))
                        {
                            lmenuWarp.TextColor = Color.Red;
                        }
                        else
                        {
                            lmenuWarp.TextColor = Color.White;
                        }
                    });

                    lmenu.Add(image);
                    lmenu.Remove(lmenuViewer);
                    lmenu.UpdateBounds();

                    if (npc != null)
                    {
                        var rect        = image.Bounds;
                        int mx          = (int)((npc.getTileX() / (double)location.Map.GetLayer("Back").LayerWidth) * rect.Width);
                        int my          = (int)((npc.getTileY() / (double)location.Map.GetLayer("Back").LayerHeight) * rect.Height);
                        var lmenuMarker = UIElement.GetImage(CircleMarker, Color.Magenta * 0.6f, positioner: UIHelper.GetTopLeft(mx - 12, my - 12, 33, 33));
                        image.Add(lmenuMarker);
                    }

                    if (artifacts)
                    {
                        foreach (var spot in location.Objects.Keys.Where(o => location.Objects[o].ParentSheetIndex == 590))
                        {
                            var rect        = image.Bounds;
                            int mx          = (int)((spot.X / (double)location.Map.GetLayer("Back").LayerWidth) * rect.Width);
                            int my          = (int)((spot.Y / (double)location.Map.GetLayer("Back").LayerHeight) * rect.Height);
                            var lmenuMarker = UIElement.GetImage(CircleMarker, Color.Red, positioner: UIHelper.GetTopLeft(mx - 5, my - 5, 11, 11));
                            image.Add(lmenuMarker);
                        }
                    }
                });
                el.WithoutInteractivity(true);
            });


            lmenu.Add(lmenuHead);
            lmenu.Add(lmenuWarp);
            return(lmenu);
        }