Esempio n. 1
0
        public static void Bind(CropReplant cr)
        {
            c_range     = cr.Config.Bind("General", "MultipickRange", 2f, "Radius to pick crops in");
            c_multipick = cr.Config.Bind("General", "MultipickEnable", true, "Enable picking crops in radius");

            c_displayGrowth = cr.Config.Bind("General", "DisplayGrowth", true, "Enable growth % tooltip on plant.");

            c_useDurability = cr.Config.Bind("General", "UseDurability", true, "Enable cultivator durability depletion when replanting.");

            c_blockHarvestNoResources = cr.Config.Bind("General", "blockHarvestNoResources", false, "Block harvest if no resource to replant.");
            c_replantSame             = cr.Config.Bind("General", "replantSame", false, "Replant same plant if cultivate is selected in cultivator menu.");

            c_customReplantables = cr.Config.Bind("General", "customReplantables", "", "Custom plants to replant in format 'SeedName : PlantName, SeedName : PlantName'");
            customReplantables   = ParseReplantables(c_customReplantables.Value);

            c_oldStyle = cr.Config.Bind("General", "oldStyle", false, "1.6 style replanting");

            c_useCustomReplantKey = cr.Config.Bind("General", "UseCustomReplantKey", false, "Use a custom keybind instead of game's alternative attack bind.");

            c_customReplantKey = cr.Config.Bind("General", "customReplantKey", KeyCode.H, "Custom keybind to use instead of of game's alternative attack bind.");
            replantButton      = new ButtonConfig
            {
                Name      = "ReplantKey",
                Config    = c_customReplantKey,
                HintToken = "Replant"
            };
            replantHint = new KeyHintConfig
            {
                ButtonConfigs = new ButtonConfig[] { replantButton },
            };
            GUIManager.Instance.AddKeyHint(replantHint);
            InputManager.Instance.AddButton(CropReplant.PluginGUID, replantButton);
        }
Esempio n. 2
0
        internal void CreateKeyHint()
        {
            KeyHintConfig KHC = new KeyHintConfig
            {
                Item          = "BlueprintRune",
                Piece         = m_prefabname,
                ButtonConfigs = new[]
                {
                    new ButtonConfig {
                        Name = "Attack", HintToken = "$hud_bpplace"
                    },
                    new ButtonConfig {
                        Name = "AltPlace", HintToken = "$hud_bpflatten"
                    },
                    new ButtonConfig {
                        Name = "Crouch", HintToken = "$hud_bpdirect"
                    },
                    new ButtonConfig {
                        Name = "Scroll", Axis = "Mouse ScrollWheel", HintToken = "$hud_bprotate"
                    }
                }
            };

            GUIManager.Instance.AddKeyHint(KHC);
        }
Esempio n. 3
0
        /// <summary>
        ///     Add a <see cref="KeyHintConfig"/> to the manager.<br />
        ///     Checks if the custom key hint is unique (i.e. the first one registered for an item).<br />
        ///     Custom key hints are displayed in the game instead of the default
        ///     KeyHints for equipped tools or weapons they are registered for.
        /// </summary>
        /// <param name="hintConfig">The custom key hint config to add.</param>
        /// <returns>true if the custom key hint config was added to the manager.</returns>
        public bool AddKeyHint(KeyHintConfig hintConfig)
        {
            if (hintConfig.Item == null)
            {
                Logger.LogWarning($"Key hint config {hintConfig} is not valid");
                return(false);
            }
            if (KeyHints.ContainsKey(hintConfig.ToString()))
            {
                Logger.LogWarning($"Key hint config for item {hintConfig} already added");
                return(false);
            }

            // Register events for every ConfigEntry backed ButtonConfig to mark the KeyHint dirty
            foreach (var buttonConfig in hintConfig.ButtonConfigs.Where(x => x.IsConfigBacked))
            {
                if (buttonConfig.Config != null)
                {
                    buttonConfig.Config.SettingChanged += (sender, args) => hintConfig.Dirty = true;
                }

                if (buttonConfig.ShortcutConfig != null)
                {
                    buttonConfig.ShortcutConfig.SettingChanged += (sender, args) => hintConfig.Dirty = true;
                }

                if (buttonConfig.GamepadConfig != null)
                {
                    buttonConfig.GamepadConfig.SettingChanged += (sender, args) => hintConfig.Dirty = true;
                }
            }

            KeyHints.Add(hintConfig.ToString(), hintConfig);
            return(true);
        }
Esempio n. 4
0
        internal void RemoveKeyHint()
        {
            KeyHintConfig KHC = new KeyHintConfig
            {
                Item  = "BlueprintRune",
                Piece = m_prefabname
            };

            GUIManager.Instance.RemoveKeyHint(KHC);
        }
Esempio n. 5
0
        /// <summary>
        ///     Removes a <see cref="KeyHintConfig"/> from the game.
        /// </summary>
        /// <param name="hintConfig">The custom key hint config to add.</param>
        public void RemoveKeyHint(KeyHintConfig hintConfig)
        {
            if (KeyHints.ContainsKey(hintConfig.ToString()))
            {
                KeyHints.Remove(hintConfig.ToString());
            }

            if (KeyHintObjects.TryGetValue(hintConfig.ToString(), out var hintObject))
            {
                Object.Destroy(hintObject);
                KeyHintObjects.Remove(hintConfig.ToString());
            }
        }
        // Implementation of key hints replacing vanilla keys and using custom keys
        private void KeyHintsEvilSword()
        {
            // Create custom KeyHints for the item
            KeyHintConfig KHC = new KeyHintConfig
            {
                Item          = "EvilSword",
                ButtonConfigs = new[]
                {
                    // Override vanilla "Attack" key text
                    new ButtonConfig {
                        Name = "Attack", HintToken = "$evilsword_shwing"
                    },
                    // New custom input
                    evilSwordSpecial,
                    // Override vanilla "Mouse Wheel" text
                    new ButtonConfig {
                        Name = "Scroll", Axis = "Mouse ScrollWheel", HintToken = "$evilsword_scroll"
                    }
                }
            };

            GUIManager.Instance.AddKeyHint(KHC);
        }
Esempio n. 7
0
        private void CreateCustomKeyHints()
        {
            KeyHintConfig KHC_default = new KeyHintConfig
            {
                Item          = "BlueprintRune",
                ButtonConfigs = new[]
                {
                    new ButtonConfig {
                        Name = "BuildMenu", HintToken = "$"
                    }
                }
            };

            GUIManager.Instance.AddKeyHint(KHC_default);

            KeyHintConfig KHC_make = new KeyHintConfig
            {
                Item          = "BlueprintRune",
                Piece         = "make_blueprint",
                ButtonConfigs = new[]
                {
                    new ButtonConfig {
                        Name = "Attack", HintToken = "$hud_bpcapture"
                    },
                    new ButtonConfig {
                        Name = "Scroll", Axis = "Mouse ScrollWheel", HintToken = "$hud_bpradius"
                    }
                }
            };

            GUIManager.Instance.AddKeyHint(KHC_make);

            foreach (var entry in m_blueprints)
            {
                entry.Value.CreateKeyHint();
            }
        }
Esempio n. 8
0
        /// <summary>
        ///     Hook on <see cref="global::KeyHints.UpdateHints" /> to show custom key hints instead of the vanilla ones.
        /// </summary>
        private bool KeyHints_UpdateHints(KeyHints self)
        {
            // If something went wrong, dont NRE every Update
            if (!HasInitBaseGameObjects || KeyHintInstance == null || KeyHintContainer == null)
            {
                return(true);
            }

            bool UseCustomKeyHint()
            {
                // Guard
                if (!self.m_keyHintsEnabled || !Player.m_localPlayer || Player.m_localPlayer.IsDead() || Chat.instance.IsChatDialogWindowVisible())
                {
                    return(false);
                }

                // Get the current equipped item name
                ItemDrop.ItemData item = Player.m_localPlayer.m_rightItem;
                if (!(item != null && (item.IsWeapon() || item.m_shared?.m_buildPieces != null)))
                {
                    return(false);
                }
                string prefabName = item.m_dropPrefab?.name;

                if (string.IsNullOrEmpty(prefabName))
                {
                    return(false);
                }

                // Get the current selected piece name if any
                string pieceName = Player.m_localPlayer.m_buildPieces?.GetSelectedPiece()?.name;

                // Try to get a KeyHint for the item and piece selected or just the item without a piece
                KeyHintConfig hintConfig = null;

                if (!string.IsNullOrEmpty(pieceName))
                {
                    KeyHints.TryGetValue($"{prefabName}:{pieceName}", out hintConfig);
                }
                if (hintConfig == null)
                {
                    KeyHints.TryGetValue(prefabName, out hintConfig);
                }
                if (hintConfig == null)
                {
                    return(false);
                }

                // Try to get the hint object, if the keyhint is "dirty" (i.e. some config backed button changed), destroy the hint object
                if (KeyHintObjects.TryGetValue(hintConfig.ToString(), out var hintObject) && hintConfig.Dirty)
                {
                    Object.DestroyImmediate(hintObject);
                }

                // Display the KeyHint instead the vanilla one or remove the config if it fails
                if (!hintObject)
                {
                    try
                    {
                        hintObject = CreateKeyHintObject(hintConfig);
                    }
                    catch (Exception ex)
                    {
                        Logger.LogWarning($"Exception caught while creating KeyHint {hintConfig}: {ex}");
                        KeyHints.Remove(hintConfig.ToString());
                        return(false);
                    }
                }

                if (!hintObject.activeSelf)
                {
                    self.m_buildHints.SetActive(false);
                    self.m_combatHints.SetActive(false);
                    KeyHintObjects.Values.Where(x => x.activeSelf).Do(x => x.SetActive(false));
                    hintObject.SetActive(true);
                }

                return(true);
            }

            if (!UseCustomKeyHint())
            {
                KeyHintObjects.Values.Where(x => x.activeSelf).Do(x => x.SetActive(false));
                return(true);
            }

            return(false);
        }
Esempio n. 9
0
        /// <summary>
        ///     Copy vanilla BuildHints object and create a custom one from a KeyHintConfig.
        /// </summary>
        /// <param name="config"></param>
        private GameObject CreateKeyHintObject(KeyHintConfig config)
        {
            // Clone BuildHints and add it under KeyHints to get the position right
            var baseKeyHint = Object.Instantiate(KeyHintInstance.m_buildHints, KeyHintContainer, false);

            baseKeyHint.name = config.ToString();
            //baseKeyHint.SetActive(false);

            // Get the Transforms of Keyboard and Gamepad
            var inputHint = baseKeyHint.GetComponent <UIInputHint>();
            var kb        = inputHint?.m_mouseKeyboardHint?.transform;
            var gp        = inputHint?.m_gamepadHint?.transform;

            if (kb == null || gp == null)
            {
                throw new Exception("Could not find child objects for KeyHints");
            }

            // Destroy all child objects
            foreach (Transform child in kb)
            {
                Object.Destroy(child.gameObject);
            }
            foreach (Transform child in gp)
            {
                Object.Destroy(child.gameObject);
            }

            foreach (var buttonConfig in config.ButtonConfigs)
            {
                string key = ZInput.instance.GetBoundKeyString(buttonConfig.Name, true);
                if (string.IsNullOrEmpty(key))
                {
                    key = buttonConfig.Name;
                }
                if (key[0].Equals(LocalizationManager.TokenFirstChar))
                {
                    key = LocalizationManager.Instance.TryTranslate(key);
                }
                string hint = LocalizationManager.Instance.TryTranslate(buttonConfig.HintToken);

                if (string.IsNullOrEmpty(buttonConfig.Axis) || !buttonConfig.Axis.Equals("Mouse ScrollWheel"))
                {
                    var customKeyboard = Object.Instantiate(BaseKey, kb, false);
                    customKeyboard.name = buttonConfig.Name;
                    customKeyboard.transform.Find("key_bkg/Key").gameObject.SetText(key);
                    customKeyboard.transform.Find("Text").gameObject.SetText(hint);
                    customKeyboard.SetActive(true);
                }
                else
                {
                    var customKeyboard = Object.Instantiate(BaseRotate, kb, false);
                    customKeyboard.transform.Find("Text").gameObject.SetText(hint);
                    customKeyboard.SetActive(true);
                }

                var gamepadButton = buttonConfig.GamepadButton;
                if (gamepadButton == GamepadButton.None &&
                    ZInput.instance.m_buttons.TryGetValue($"Joy{buttonConfig.Name}", out var buttonDef))
                {
                    if (!string.IsNullOrEmpty(buttonDef.m_axis))
                    {
                        string invAxis = $"{(buttonDef.m_inverted ? "-" : null)}{buttonDef.m_axis}";
                        gamepadButton = GetGamepadButton(invAxis);
                    }
                    else
                    {
                        gamepadButton = GetGamepadButton(buttonDef.m_key);
                    }
                }

                if (gamepadButton != GamepadButton.None)
                {
                    string buttonString = GetGamepadString(gamepadButton);

                    switch (gamepadButton)
                    {
                    case GamepadButton.DPadLeft:
                    case GamepadButton.DPadRight:
                        var customPadNoRotate = Object.Instantiate(BaseDPad, gp, false);
                        customPadNoRotate.name = buttonConfig.Name;
                        customPadNoRotate.GetComponentInChildren <Text>().text = buttonString;
                        customPadNoRotate.transform.Find("Text").gameObject.SetText(hint);
                        customPadNoRotate.SetActive(true);
                        break;

                    case GamepadButton.DPadUp:
                    case GamepadButton.DPadDown:
                        var customPadRotate = Object.Instantiate(BaseDPad, gp, false);
                        customPadRotate.name = buttonConfig.Name;
                        customPadRotate.transform.Find("Trigger").GetComponent <RectTransform>().Rotate(new Vector3(0, 0, 1f), 90f);
                        customPadRotate.GetComponentInChildren <Text>().text = buttonString;
                        customPadRotate.transform.Find("Text").gameObject.SetText(hint);
                        customPadRotate.SetActive(true);
                        break;

                    case GamepadButton.StartButton:
                    case GamepadButton.SelectButton:
                        var customPad = Object.Instantiate(BaseKey, gp, false);
                        customPad.name = buttonConfig.Name;
                        customPad.GetComponentInChildren <Text>().text = buttonString;
                        customPad.transform.Find("Text").gameObject.SetText(hint);
                        customPad.SetActive(true);
                        break;

                    case GamepadButton.ButtonNorth:
                    case GamepadButton.ButtonSouth:
                    case GamepadButton.ButtonWest:
                    case GamepadButton.ButtonEast:
                        var customButton = Object.Instantiate(BaseButton, gp, false);
                        customButton.name = buttonConfig.Name;
                        customButton.GetComponentInChildren <Text>().text = buttonString;
                        customButton.transform.Find("Text").gameObject.SetText(hint);
                        customButton.SetActive(true);
                        break;

                    case GamepadButton.LeftShoulder:
                    case GamepadButton.RightShoulder:
                        var customShoulder = Object.Instantiate(BaseShoulder, gp, false);
                        customShoulder.name = buttonConfig.Name;
                        customShoulder.GetComponentInChildren <Text>().text = buttonString;
                        customShoulder.transform.Find("Text").gameObject.SetText(hint);
                        customShoulder.SetActive(true);
                        break;

                    case GamepadButton.LeftTrigger:
                    case GamepadButton.RightTrigger:
                        var customTrigger = Object.Instantiate(BaseTrigger, gp, false);
                        customTrigger.name = buttonConfig.Name;
                        customTrigger.GetComponentInChildren <Text>().text = buttonString;
                        customTrigger.transform.Find("Text").gameObject.SetText(hint);
                        customTrigger.SetActive(true);
                        break;

                    case GamepadButton.LeftStickButton:
                    case GamepadButton.RightStickButton:
                        var customStick = Object.Instantiate(BaseStick, gp, false);
                        customStick.name = buttonConfig.Name;
                        customStick.GetComponentInChildren <Text>().text = buttonString;
                        customStick.transform.Find("Text").gameObject.SetText(hint);
                        customStick.SetActive(true);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
            }

            KeyHintObjects[config.ToString()] = baseKeyHint;
            config.Dirty = false;
            return(baseKeyHint);
        }
Esempio n. 10
0
        // Add new items as copies of vanilla items - just works when vanilla prefabs are already loaded (ObjectDB.CopyOtherDB for example)
        // You can use the Cache of the PrefabManager in here
        private void AddClonedItems()
        {
            try
            {
                // Create and add a custom item based on SwordBlackmetal
                var CI = new CustomItem("EvilSword", "SwordBlackmetal");
                ItemManager.Instance.AddItem(CI);

                // Replace vanilla properties of the custom item
                var itemDrop = CI.ItemDrop;
                itemDrop.m_itemData.m_shared.m_name        = "$item_evilsword";
                itemDrop.m_itemData.m_shared.m_description = "$item_evilsword_desc";

                // Add our custom status effect to it
                itemDrop.m_itemData.m_shared.m_equipStatusEffect = evilSwordEffect.StatusEffect;

                // Create and add a recipe for the copied item
                var recipe = ScriptableObject.CreateInstance <Recipe>();
                recipe.name              = "Recipe_EvilSword";
                recipe.m_item            = itemDrop;
                recipe.m_craftingStation = PrefabManager.Cache.GetPrefab <CraftingStation>("piece_workbench");
                recipe.m_resources       = new[]
                {
                    new Piece.Requirement {
                        m_resItem = PrefabManager.Cache.GetPrefab <ItemDrop>("Stone"), m_amount = 1
                    },
                    new Piece.Requirement {
                        m_resItem = PrefabManager.Cache.GetPrefab <ItemDrop>("Wood"), m_amount = 1
                    }
                };
                var CR = new CustomRecipe(recipe, fixReference: false, fixRequirementReferences: false);  // no need to fix because the refs from the cache are valid
                ItemManager.Instance.AddRecipe(CR);

                // Create custom KeyHints for the item
                KeyHintConfig KHC = new KeyHintConfig
                {
                    Item          = "EvilSword",
                    ButtonConfigs = new[]
                    {
                        // Override vanilla "Attack" key text
                        new ButtonConfig {
                            Name = "Attack", HintToken = "$evilsword_shwing"
                        },
                        // New custom input
                        evilSwordSpecial,
                        // Override vanilla "Mouse Wheel" text
                        new ButtonConfig {
                            Name = "Scroll", Axis = "Mouse ScrollWheel", HintToken = "$evilsword_scroll"
                        }
                    }
                };
                GUIManager.Instance.AddKeyHint(KHC);
            }
            catch (Exception ex)
            {
                Jotunn.Logger.LogError($"Error while adding cloned item: {ex.Message}");
            }
            finally
            {
                // You want that to run only once, Jotunn has the item cached for the game session
                ItemManager.OnVanillaItemsAvailable -= AddClonedItems;
            }
        }