Ejemplo n.º 1
0
        /// <summary>
        ///     Extract base key hint elements and create key hint objects.
        /// </summary>
        private void KeyHints_Start(KeyHints self)
        {
            if (!HasInitBaseGameObjects)
            {
                return;
            }

            KeyHintInstance  = self;
            KeyHintContainer = self.transform as RectTransform;
            KeyHintObjects.Clear();
        }
Ejemplo n.º 2
0
 private static void KeyHints_Start(KeyHints __instance)
 {
     try
     {
         Instance.GetBaseGameObjects(__instance);
         Instance.KeyHints_Start(__instance);
     }
     catch (Exception ex)
     {
         Logger.LogWarning($"Exception caught while creating key hint objects: {ex}");
     }
 }
Ejemplo n.º 3
0
 private static bool KeyHints_UpdateHints(KeyHints __instance) => Instance.KeyHints_UpdateHints(__instance);
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Instantiate base GameObjects from vanilla KeyHints to use in our custom key hints
        /// </summary>
        private void GetBaseGameObjects(KeyHints self)
        {
            if (HasInitBaseGameObjects)
            {
                return;
            }

            var baseKeyHint = self.m_buildHints;

            // 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)
            {
                Logger.LogWarning("Could not find child objects for KeyHints");
                return;
            }

            // Clone vanilla key hint objects and use it as the base for custom key hints
            var origKey      = kb.transform.Find("Place")?.gameObject;
            var origRotate   = kb.transform.Find("rotate")?.gameObject;
            var origButton   = gp.transform.Find("BuildMenu")?.gameObject;
            var origTrigger  = gp.transform.Find("Place")?.gameObject;
            var origShoulder = gp.transform.Find("Remove")?.gameObject;
            var origStick    = gp.transform.Find("rotate")?.gameObject;

            if (!origKey || !origRotate || !origButton || !origTrigger || !origShoulder || !origStick)
            {
                Logger.LogWarning("Could not find child objects for KeyHints");
                return;
            }

            BaseKey      = Object.Instantiate(origKey);
            BaseKey.name = "JotunnKeyHintBaseKey";
            PrefabManager.Instance.AddPrefab(BaseKey);

            BaseRotate      = Object.Instantiate(origRotate);
            BaseRotate.name = "JotunnKeyHintBaseRotate";
            PrefabManager.Instance.AddPrefab(BaseRotate);

            BaseButton      = Object.Instantiate(origButton);
            BaseButton.name = "JotunnKeyHintBaseButton";
            PrefabManager.Instance.AddPrefab(BaseButton);

            BaseTrigger      = Object.Instantiate(origTrigger);
            BaseTrigger.name = "JotunnKeyHintBaseTrigger";
            PrefabManager.Instance.AddPrefab(BaseTrigger);

            BaseShoulder      = Object.Instantiate(origShoulder);
            BaseShoulder.name = "JotunnKeyHintBaseShoulder";
            PrefabManager.Instance.AddPrefab(BaseShoulder);

            BaseStick      = Object.Instantiate(origStick);
            BaseStick.name = "JotunnKeyHintBaseStick";
            Object.DestroyImmediate(BaseStick.transform.Find("Trigger").gameObject);
            Object.DestroyImmediate(BaseStick.transform.Find("plus").gameObject);
            PrefabManager.Instance.AddPrefab(BaseStick);

            BaseDPad      = Object.Instantiate(BaseTrigger);
            BaseDPad.name = "JotunnKeyHintBaseDPad";
            BaseDPad.transform.Find("Trigger").GetComponent <RectTransform>().pivot     = new Vector2(0.5f, 0.5f);
            BaseDPad.transform.Find("Trigger").GetComponent <RectTransform>().sizeDelta = new Vector2(25f, 25f);
            PrefabManager.Instance.AddPrefab(BaseDPad);

            HasInitBaseGameObjects = true;
        }