Exemplo n.º 1
0
        public override void Entry(IModHelper helper)
        {
            context = this;
            Config  = Helper.ReadConfig <ModConfig>();

            SHelper  = Helper;
            SMonitor = Monitor;

            HelperEvents.Initialize(Config, Monitor, Helper);

            ModActions.CreateTextures();

            Helper.Events.Display.RenderedWorld    += HelperEvents.Display_RenderedWorld;
            Helper.Events.Input.ButtonPressed      += HelperEvents.Input_ButtonPressed;
            Helper.Events.GameLoop.UpdateTicked    += HelperEvents.GameLoop_UpdateTicked;
            Helper.Events.GameLoop.SaveLoaded      += HelperEvents.GameLoop_SaveLoaded;
            Helper.Events.GameLoop.ReturnedToTitle += HelperEvents.GameLoop_ReturnedToTitle;
            Helper.Events.Player.Warped            += HelperEvents.Player_Warped;

            var harmony = new Harmony(ModManifest.UniqueID);

            harmony.Patch(
                original: AccessTools.Method(typeof(Game1), nameof(Game1.pressSwitchToolButton)),
                prefix: new HarmonyMethod(typeof(ModEntry), nameof(ModEntry.pressSwitchToolButton_Prefix))
                );
        }
Exemplo n.º 2
0
 public static void Player_Warped(object sender, WarpedEventArgs e)
 {
     if (!Config.EnableMod)
     {
         return;
     }
     ModActions.DeactivateMod();
     MapActions.UpdateCurrentMap(false);
 }
Exemplo n.º 3
0
        private static bool pressSwitchToolButton_Prefix()
        {
            if (!Config.EnableMod || !Context.IsPlayerFree || Game1.input.GetMouseState().ScrollWheelValue == Game1.oldMouseState.ScrollWheelValue || !modActive || copiedTileLoc.X < 0)
            {
                return(true);
            }

            ModActions.SwitchTile(Game1.input.GetMouseState().ScrollWheelValue - Game1.oldMouseState.ScrollWheelValue > 0);

            return(false);
        }
Exemplo n.º 4
0
        public static void SwitchTile(bool increase)
        {
            List <string> layers = new List <string>();

            foreach (Layer layer in Game1.player.currentLocation.map.Layers)
            {
                if (ModEntry.currentTileDict.ContainsKey(layer.Id))
                {
                    layers.Add(layer.Id);
                }
            }

            if (ModEntry.SHelper.Input.IsDown(ModEntry.Config.LayerModButton))
            {
                if (layers.Count < 2)
                {
                    return;
                }
                if (increase)
                {
                    if (ModEntry.currentLayer >= layers.Count - 1)
                    {
                        ModEntry.currentLayer = 0;
                    }
                    else
                    {
                        ModEntry.currentLayer++;
                    }
                }
                else
                {
                    if (ModEntry.currentLayer < 1)
                    {
                        ModEntry.currentLayer = layers.Count - 1;
                    }
                    else
                    {
                        ModEntry.currentLayer--;
                    }
                }

                string text = string.Format(ModEntry.SHelper.Translation.Get("current-layer"), layers[ModEntry.currentLayer]);
                ModEntry.SMonitor.Log(text);
                ModActions.ShowMessage(text);
            }
            else if (ModEntry.SHelper.Input.IsDown(ModEntry.Config.SheetModButton))
            {
                if (ModEntry.currentTileDict[layers[ModEntry.currentLayer]] is AnimatedTile)
                {
                    return;
                }

                List <TileSheet> sheets = new List <TileSheet>();
                foreach (TileSheet sheet in Game1.player.currentLocation.map.TileSheets)
                {
                    if (sheet.Id != "Paths")
                    {
                        sheets.Add(sheet);
                    }
                }
                if (sheets.Count < 2)
                {
                    return;
                }
                Tile tile = ModEntry.currentTileDict[layers[ModEntry.currentLayer]];
                if (tile == null)
                {
                    Layer layer = Game1.player.currentLocation.map.GetLayer(layers[ModEntry.currentLayer]);
                    tile = new StaticTile(layer, sheets[0], BlendMode.Alpha, -1);
                }
                int tileSheetIndex = sheets.IndexOf(tile.TileSheet);
                if (increase)
                {
                    if (tileSheetIndex >= sheets.Count - 1)
                    {
                        tileSheetIndex = 0;
                    }
                    else
                    {
                        tileSheetIndex++;
                    }
                }
                else
                {
                    if (tileSheetIndex < 1)
                    {
                        tileSheetIndex = sheets.Count - 1;
                    }
                    else
                    {
                        tileSheetIndex--;
                    }
                }
                TileSheet tileSheet = sheets[tileSheetIndex];
                ModEntry.SHelper.Reflection.GetField <TileSheet>(tile, "m_tileSheet").SetValue(tileSheet);
                tile.TileIndex = 0;
                string text = string.Format(ModEntry.SHelper.Translation.Get("current-tilesheet"), tileSheet.Id);
                ModEntry.SMonitor.Log(text);
                ModActions.ShowMessage(text);
            }
            else
            {
                if (ModEntry.currentTileDict[layers[ModEntry.currentLayer]] == null)
                {
                    ModEntry.currentTileDict[layers[ModEntry.currentLayer]] = new StaticTile(Game1.player.currentLocation.map.GetLayer(layers[ModEntry.currentLayer]), Game1.player.currentLocation.map.TileSheets[0], BlendMode.Alpha, -1);
                }
                if (ModEntry.currentTileDict[layers[ModEntry.currentLayer]] is AnimatedTile)
                {
                    return;
                }

                Tile tile = ModEntry.currentTileDict[layers[ModEntry.currentLayer]];
                //context.Monitor.Log($"old index {tile.TileIndex}");
                if (tile == null)
                {
                    ModEntry.SMonitor.Log($"Layer {layers[ModEntry.currentLayer]} copied tile is null, creating empty tile");
                    Layer layer = Game1.player.currentLocation.map.GetLayer(layers[ModEntry.currentLayer]);
                    ModEntry.currentTileDict[layers[ModEntry.currentLayer]] = new StaticTile(layer, Game1.player.currentLocation.map.TileSheets[0], BlendMode.Alpha, -1);
                }
                if (increase)
                {
                    if (tile.TileIndex >= tile.TileSheet.TileCount - 1)
                    {
                        tile.TileIndex = -1;
                    }
                    else
                    {
                        tile.TileIndex++;
                    }
                }
                else
                {
                    if (tile.TileIndex < 0)
                    {
                        tile.TileIndex = tile.TileSheet.TileCount - 1;
                    }
                    else
                    {
                        tile.TileIndex--;
                    }
                }
                //context.Monitor.Log($"new index {tile.TileIndex}");
            }
            Game1.playSound(ModEntry.Config.ScrollSound);
        }
Exemplo n.º 5
0
        public static void Input_ButtonPressed(object sender, ButtonPressedEventArgs e)
        {
            if (!Config.EnableMod || !Context.IsPlayerFree)
            {
                ModActions.DeactivateMod();
                return;
            }

            if (e.Button == Config.ToggleButton)
            {
                Helper.Input.Suppress(e.Button);
                ModEntry.modActive     = !ModEntry.modActive;
                ModEntry.copiedTileLoc = new Vector2(-1, -1);
                ModEntry.currentTileDict.Clear();
                Monitor.Log($"Toggled mod: {ModEntry.modActive}");
                if (ModEntry.modActive)
                {
                    ModActions.ShowMessage(string.Format(Helper.Translation.Get("mod-active"), Config.ToggleButton));
                }
                else
                {
                    ModActions.ShowMessage(string.Format(Helper.Translation.Get("mod-inactive"), Config.ToggleButton));
                }
            }
            else if (ModEntry.modActive && e.Button == Config.CopyButton)
            {
                Helper.Input.Suppress(e.Button);

                TileActions.CopyCurrentTile();
            }
            else if (ModEntry.modActive && ModEntry.copiedTileLoc.X > -1 && e.Button == Config.PasteButton && ModEntry.pastedTileLoc != Game1.currentCursorTile)
            {
                Helper.Input.Suppress(e.Button);
                TileActions.PasteCurrentTile();
            }
            else if (ModEntry.modActive && e.Button == Config.RevertButton && MapActions.MapHasTile(Game1.currentCursorTile))
            {
                Helper.Input.Suppress(e.Button);
                TileActions.RevertCurrentTile();
            }
            else if (ModEntry.modActive && e.Button == SButton.Escape)
            {
                Helper.Input.Suppress(e.Button);
                if (ModEntry.copiedTileLoc.X > -1)
                {
                    ModEntry.copiedTileLoc = new Vector2(-1, -1);
                    ModEntry.pastedTileLoc = new Vector2(-1, -1);
                    ModEntry.currentLayer  = 0;
                    ModEntry.currentTileDict.Clear();
                }
                else
                {
                    ModActions.DeactivateMod();
                }
            }
            else if (ModEntry.modActive && e.Button == Config.RefreshButton)
            {
                Helper.Input.Suppress(e.Button);
                ModEntry.cleanMaps.Clear();
                MapActions.GetMapCollectionData();
                MapActions.UpdateCurrentMap(true);
            }
            else if (ModEntry.modActive && e.Button == Config.ScrollUpButton)
            {
                Helper.Input.Suppress(e.Button);
                ModActions.SwitchTile(true);
            }
            else if (ModEntry.modActive && e.Button == Config.ScrollDownButton)
            {
                Helper.Input.Suppress(e.Button);
                ModActions.SwitchTile(false);
            }
        }
Exemplo n.º 6
0
 public static void GameLoop_ReturnedToTitle(object sender, ReturnedToTitleEventArgs e)
 {
     ModActions.DeactivateMod();
     ModEntry.cleanMaps.Clear();
 }