Esempio n. 1
0
        public override void Entry(IModHelper helper)
        {
            ModInstance = this;

            helper.Events.Input.ButtonPressed   += Input_ButtonPressed;
            helper.Events.Display.RenderedWorld += Display_RenderedWorld;
            helper.Events.Input.CursorMoved     += Input_CursorMoved;

            LoadUserConfig();

            DelayHelpers.Entry(helper);
            ModDataPersistenceHelper.Entry(helper, ModDataQuantityKey, ModDataOutputModifiedKey);
            PatchesHandler.Entry(helper);
        }
Esempio n. 2
0
        private void Input_ButtonPressed(object sender, ButtonPressedEventArgs e)
        {
#if NEVER //DEBUG
            //  Testing the Scarecrow transpiler harmony patch
            if (e.Button == SButton.R && Game1.activeClickableMenu == null && Game1.player.currentLocation is Farm farm)
            {
                farm.addCrows();
            }
#endif

            if (IsCombineKeyHeld(Helper.Input))
            {
                if (Game1.activeClickableMenu is GameMenu GM && GM.currentTab == GameMenu.inventoryTab && TryGetClickedInventoryItem(GM, e, out Item ClickedItem, out int ClickedItemIndex))
                {
                    //  Detect when player clicks on a machine in their inventory while another machine of the same type is selected
                    if (SButtonExtensions.IsUseToolButton(e.Button) /*e.Button == SButton.MouseLeft*/ && Game1.player.CursorSlotItem is SObject SourceObj && ClickedItem is SObject TargetObj && CanCombine(SourceObj, TargetObj))
                    {
                        if (!SourceObj.TryGetCombinedQuantity(out int SourceQuantity))
                        {
                            SourceQuantity = SourceObj.Stack;
                        }
                        if (!TargetObj.TryGetCombinedQuantity(out int TargetQuantity))
                        {
                            TargetQuantity = TargetObj.Stack;
                        }

                        TargetObj.SetCombinedQuantity(SourceQuantity + TargetQuantity);
                        Game1.player.CursorSlotItem = null;

                        //  Clicking an item will make the game set it to the new CursorSlotItem, but since we just combined them, we want the CursorSlotItem to be empty
                        DelayHelpers.InvokeLater(1, () =>
                        {
                            if (Game1.player.CursorSlotItem != null && Game1.player.Items[ClickedItemIndex] == null)
                            {
                                Game1.player.Items[ClickedItemIndex] = Game1.player.CursorSlotItem;
                                Game1.player.CursorSlotItem          = null;
                            }
                        });
                    }
                    //  Right-clicking a combined machine splits it to its un-combined state
                    else if (SButtonExtensions.IsActionButton(e.Button) /*e.Button == SButton.MouseRight*/ && Game1.player.CursorSlotItem == null && ClickedItem is SObject ClickedObject &&
                             ClickedObject.IsCombinedMachine() && ClickedObject.TryGetCombinedQuantity(out int CombinedQuantity) && CombinedQuantity > 1)
                    {
                        ClickedObject.modData.Remove(ModDataQuantityKey);
                        ClickedObject.Stack += CombinedQuantity - 1;
                        Logger.Log(string.Format("De-combined {0} (Stack={1})", ClickedObject.DisplayName, CombinedQuantity), InfoLogLevel);
                    }
                }
Esempio n. 3
0
        private void Input_ButtonPressed(object sender, ButtonPressedEventArgs e)
        {
            //  Detect when player clicks on a machine in their inventory while another machine of the same type is selected, and the CTRL key is held
            if (e.Button == SButton.MouseLeft && IsCombineKeyHeld(Helper.Input))
            {
                if (Game1.activeClickableMenu is GameMenu GM && GM.currentTab == GameMenu.inventoryTab)
                {
                    if (TryGetClickedInventoryItem(GM, e, out Item ClickedItem, out int ClickedItemIndex))
                    {
                        if (Game1.player.CursorSlotItem is SObject SourceObj && ClickedItem is SObject TargetObj && CanCombine(SourceObj, TargetObj))
                        {
                            if (!SourceObj.TryGetCombinedQuantity(out int SourceQuantity))
                            {
                                SourceQuantity = SourceObj.Stack;
                            }
                            if (!TargetObj.TryGetCombinedQuantity(out int TargetQuantity))
                            {
                                TargetQuantity = TargetObj.Stack;
                            }

                            TargetObj.SetCombinedQuantity(SourceQuantity + TargetQuantity);
                            Game1.player.CursorSlotItem = null;

                            //  Clicking an item will make the game set it to the new CursorSlotItem, but since we just combined them, we want the CursorSlotItem to be empty
                            DelayHelpers.InvokeLater(1, () =>
                            {
                                if (Game1.player.CursorSlotItem != null && Game1.player.Items[ClickedItemIndex] == null)
                                {
                                    Game1.player.Items[ClickedItemIndex] = Game1.player.CursorSlotItem;
                                    Game1.player.CursorSlotItem          = null;
                                }
                            });
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        public override void Entry(IModHelper helper)
        {
            ModInstance = this;

            IsAutomateModInstalled = helper.ModRegistry.IsLoaded("Pathoschild.Automate");

            helper.Events.Input.ButtonPressed   += Input_ButtonPressed;
            helper.Events.Display.RenderedWorld += Display_RenderedWorld;
            helper.Events.Input.CursorMoved     += Input_CursorMoved;

            string CommandName = "combine_machines_reload_config";
            string CommandHelp = "Reloads settings from the config.json file without requiring you to restart the game.";

            helper.ConsoleCommands.Add(CommandName, CommandHelp, (string Name, string[] Args) => {
                LoadUserConfig();
                Logger.Log(string.Format("Configuration settings successfully reloaded. (Some settings may still require a full restart, such as {0}.", nameof(UserConfig.AllowCombiningScarecrows)), LogLevel.Info);
            });

            LoadUserConfig();

            DelayHelpers.Entry(helper);
            ModDataPersistenceHelper.Entry(helper, ModDataQuantityKey, ModDataOutputModifiedKey);
            PatchesHandler.Entry(helper);
        }