private void Update()
 {
     if (this._version != InputMappingIcons.Version)
     {
         this._texture.height = this._startHeight;
         if (!InputMappingIcons.UsesText(this._action))
         {
             this._texture.mainTexture = InputMappingIcons.GetTextureFor(this._action);
             this._label.enabled       = false;
             float num = (float)this._texture.mainTexture.width / (float)this._texture.mainTexture.height;
             if (num > 1.2f)
             {
                 this._texture.height = Mathf.RoundToInt((float)this._texture.height * 0.666f);
             }
             this._texture.width = Mathf.RoundToInt(num * (float)this._texture.height);
         }
         else
         {
             this._texture.mainTexture = InputMappingIcons.GetTextureFor(this._action);
             this._label.text          = InputMappingIcons.GetMappingFor(this._action);
             this._label.enabled       = true;
             float num2 = (float)this._label.width / (float)this._label.height;
             if (num2 > 1.5f)
             {
                 this._texture.width = Mathf.RoundToInt((float)this._startHeight * num2);
             }
             else
             {
                 this._texture.width = this._startHeight;
             }
         }
         this._version = InputMappingIcons.Version;
     }
 }
Beispiel #2
0
 private void Start()
 {
     InputMappingIcons.TextIconBacking = this._textIconBacking;
     InputMappingIcons.TexturesByName  = this._textures.ToDictionary((Texture2D t) => t.name);
     InputMappingIcons.Version         = 1;
     InputMappingIcons.RefreshMappings();
 }
Beispiel #3
0
        private static string GetMappingPrefixVR(Controller controllerSource)
        {
            VRControllerDisplayManager.VRControllerType activeControllerType = VRControllerDisplayManager.GetActiveControllerType();
            if (activeControllerType == VRControllerDisplayManager.VRControllerType.Vive)
            {
                return("VIVE_");
            }
            if (activeControllerType == VRControllerDisplayManager.VRControllerType.OculusTouch)
            {
                return("OCTOUCH_");
            }
            string[] matchStrings = new string[]
            {
                "Oculus Touch.*",
                "Oculus Controller"
            };
            string[] matchStrings2 = new string[]
            {
                "Open VR Controller.*"
            };
            string name = controllerSource.name;

            if (InputMappingIcons.GetMappingPrefix(name, matchStrings))
            {
                return("OCTOUCH_");
            }
            if (InputMappingIcons.GetMappingPrefix(name, matchStrings2))
            {
                return("VIVE_");
            }
            return(null);
        }
Beispiel #4
0
        private static string GetMappingPrefix(Controller controllerSource)
        {
            if (controllerSource == null)
            {
                return(string.Empty);
            }
            if (ForestVR.Enabled)
            {
                string mappingPrefixVR = InputMappingIcons.GetMappingPrefixVR(controllerSource);
                if (!mappingPrefixVR.NullOrEmpty())
                {
                    return(mappingPrefixVR);
                }
            }
            string name = controllerSource.name;

            string[] matchStrings = new string[]
            {
                "Sony DualShock.*"
            };
            string[] matchStrings2 = new string[]
            {
                ".*Dual Analog Gamepad",
                "Xbox.*Controller"
            };
            if (InputMappingIcons.GetMappingPrefix(name, matchStrings2))
            {
                return("360_");
            }
            if (InputMappingIcons.GetMappingPrefix(name, matchStrings))
            {
                return("PS4_");
            }
            return("360_");
        }
Beispiel #5
0
 private void Update()
 {
     OVRInput.Update();
     if (InputMappingIcons.LastController != null)
     {
         Player.ControllerHelper controllers = ReInput.players.GetPlayer(0).controllers;
         if (InputMappingIcons._trackedInputs == null)
         {
             InputMappingIcons._trackedInputs = new Dictionary <string, List <string> >();
         }
         foreach (ControllerMap controllerMap in controllers.maps.GetAllMaps())
         {
             Controller controller = controllers.GetController(controllerMap.controllerType, controllerMap.controllerId);
             string     name       = controller.name;
             if (!InputMappingIcons._trackedInputs.ContainsKey(name))
             {
                 InputMappingIcons._trackedInputs.Add(name, new List <string>());
             }
             List <string> list = InputMappingIcons._trackedInputs[name];
             foreach (ActionElementMap actionElementMap in controllerMap.AllMaps)
             {
                 if (!list.Contains(actionElementMap.elementIdentifierName))
                 {
                     list.Add(actionElementMap.elementIdentifierName);
                 }
             }
         }
     }
     if (TheForest.Utils.Input.IsGamePad)
     {
         Controller lastActiveController = TheForest.Utils.Input.player.controllers.GetLastActiveController();
         if (lastActiveController != InputMappingIcons.LastController && lastActiveController != null)
         {
             if (InputMappingIcons.LastController != null)
             {
                 Debug.Log("===> Changing gamepad icons: currentController=" + lastActiveController.name + ", LastController=" + InputMappingIcons.LastController.name);
             }
             else
             {
                 Debug.Log("===> Init gamepad icons: currentController=" + lastActiveController.name);
             }
             InputMappingIcons.LastController = lastActiveController;
             InputMappingIcons.RefreshMappings();
             InputMappingIcons.Version++;
         }
     }
     if (this._usingGamePadVersion != TheForest.Utils.Input.IsGamePad)
     {
         this._usingGamePadVersion = TheForest.Utils.Input.IsGamePad;
         InputMappingIcons.Version++;
         if (TheForest.Utils.Input.IsGamePad)
         {
             Debug.Log("===> Switching from KM to gamepad     Version=" + InputMappingIcons.Version);
         }
         else
         {
             Debug.Log("===> Switching from gamepad to KM     Version = " + InputMappingIcons.Version);
         }
     }
 }
Beispiel #6
0
 public static UISprite RegisterIcon(Transform target, InputMappingIcons.Actions action, ActionIconSystem.CurrentViewOptions currentViewOption = ActionIconSystem.CurrentViewOptions.AllowInWorld)
 {
     if (ActionIconSystem.Instance && !ActionIconSystem.Instance._activeIcons.ContainsKey(target))
     {
         ActionIcon actionIcon;
         if (!InputMappingIcons.UsesText(action))
         {
             if (ActionIconSystem.Instance._spriteIconPool.Count > 0)
             {
                 actionIcon = ActionIconSystem.Instance._spriteIconPool.Dequeue();
                 actionIcon.gameObject.SetActive(true);
                 ActionIconSystem.Instance.SetIconHolderTr(actionIcon.transform, currentViewOption);
             }
             else
             {
                 actionIcon = UnityEngine.Object.Instantiate <ActionIcon>(ActionIconSystem.Instance._spriteIconPrefab);
                 ActionIconSystem.Instance.SetIconHolderTr(actionIcon.transform, currentViewOption);
                 actionIcon.transform.localScale = ActionIconSystem.Instance._spriteIconPrefab.transform.localScale;
             }
             actionIcon._sprite.spriteName = InputMappingIcons.GetMappingFor(action);
             UISpriteData atlasSprite = actionIcon._sprite.GetAtlasSprite();
             if (atlasSprite == null)
             {
                 ActionIconSystem.Instance.DisableActionIcon(actionIcon);
                 return(null);
             }
             actionIcon._sprite.width = Mathf.RoundToInt((float)atlasSprite.width / (float)atlasSprite.height * (float)actionIcon._sprite.height);
         }
         else
         {
             if (ActionIconSystem.Instance._textIconPool.Count > 0)
             {
                 actionIcon = ActionIconSystem.Instance._textIconPool.Dequeue();
                 actionIcon.gameObject.SetActive(true);
                 ActionIconSystem.Instance.SetIconHolderTr(actionIcon.transform, currentViewOption);
             }
             else
             {
                 actionIcon = UnityEngine.Object.Instantiate <ActionIcon>(ActionIconSystem.Instance._textIconPrefab);
                 ActionIconSystem.Instance.SetIconHolderTr(actionIcon.transform, currentViewOption);
                 actionIcon.transform.localScale = ActionIconSystem.Instance._textIconPrefab.transform.localScale;
             }
             actionIcon._label.text = InputMappingIcons.GetMappingFor(action);
         }
         actionIcon._follow._target = target;
         actionIcon._fillSprite.gameObject.SetActive(false);
         actionIcon._follow._inBook = (currentViewOption == ActionIconSystem.CurrentViewOptions.AllowInBook);
         ActionIconSystem.Instance._activeIcons.Add(target, actionIcon);
         return(actionIcon._fillSprite);
     }
     return(null);
 }
Beispiel #7
0
 private void Update()
 {
     if (this._version != InputMappingIcons.Version)
     {
         this._sprite.height = this._startHeight;
         if (!InputMappingIcons.UsesText(this._action))
         {
             this._sprite.spriteName = InputMappingIcons.GetMappingFor(this._action);
             this._label.enabled     = false;
             UISpriteData atlasSprite = this._sprite.GetAtlasSprite();
             if (atlasSprite != null)
             {
                 float num = (float)atlasSprite.width / (float)atlasSprite.height;
                 if (num > 1.2f)
                 {
                     this._sprite.height = Mathf.RoundToInt((float)this._sprite.height * 0.666f);
                 }
                 this._sprite.width = Mathf.RoundToInt(num * (float)this._sprite.height);
             }
             else
             {
                 Debug.LogError("Missing sprite: " + this._sprite.spriteName);
             }
         }
         else
         {
             this._sprite.spriteName = InputMappingIcons.TextIconBacking.name;
             this._label.text        = InputMappingIcons.GetMappingFor(this._action);
             this._label.enabled     = true;
             float num2;
             if (this._invertScale)
             {
                 num2 = (float)this._label.width * 1f / this._label.transform.localScale.x / (float)this._startHeight;
             }
             else
             {
                 num2 = (float)this._label.width * 1f * this._label.transform.localScale.x / (float)this._startHeight;
             }
             if (num2 > 1.5f)
             {
                 this._sprite.width = Mathf.RoundToInt((float)this._startHeight * num2);
             }
             else
             {
                 this._sprite.width = this._startHeight;
             }
         }
         this._version = InputMappingIcons.Version;
     }
 }
Beispiel #8
0
        public static Texture GetTextureFor(InputMappingIcons.Actions action)
        {
            if (TheForest.Utils.Input.IsGamePad)
            {
                return(InputMappingIcons.TexturesByName[InputMappingIcons.GetMappingFor(action)]);
            }
            string text = InputMappingIcons.KeyboardMappings[(int)action];

            if (text != null)
            {
                if (text == "Right_Mouse_Button" || text == "Left_Mouse_Button" || text == "Mouse_Horizontal" || text == "Mouse_Vertical")
                {
                    return(InputMappingIcons.TexturesByName[InputMappingIcons.KeyboardMappings[(int)action]]);
                }
            }
            return(InputMappingIcons.TextIconBacking);
        }
Beispiel #9
0
 private void Update()
 {
     if (TheForest.Utils.Input.IsGamePad)
     {
         Controller lastActiveController = TheForest.Utils.Input.player.controllers.GetLastActiveController();
         if (lastActiveController != InputMappingIcons.LastController)
         {
             InputMappingIcons.LastController = lastActiveController;
             InputMappingIcons.RefreshMappings();
             InputMappingIcons.Version++;
         }
     }
     if (this._usingGamePadVersion != TheForest.Utils.Input.IsGamePad)
     {
         this._usingGamePadVersion = TheForest.Utils.Input.IsGamePad;
         InputMappingIcons.Version++;
     }
 }
Beispiel #10
0
 private void Update()
 {
     if (this._version != InputMappingIcons.Version)
     {
         this._texture.texture = InputMappingIcons.GetTextureFor(this._action);
         if (!InputMappingIcons.UsesText(this._action))
         {
             this._text.enabled    = false;
             this._texture.enabled = true;
         }
         else
         {
             this._text.text       = InputMappingIcons.GetMappingFor(this._action);
             this._text.enabled    = true;
             this._texture.enabled = this._useTextBacking;
         }
         this._version = InputMappingIcons.Version;
     }
 }
Beispiel #11
0
        public static Texture GetTextureFor(InputMappingIcons.Actions action)
        {
            if (TheForest.Utils.Input.IsGamePad)
            {
                return(InputMappingIcons.TexturesByName[InputMappingIcons.GetMappingFor(action)]);
            }
            string text = InputMappingIcons.KeyboardMappings[(int)action];

            if (text != null)
            {
                if (InputMappingIcons.< > f__switch$map19 == null)
                {
                    InputMappingIcons.< > f__switch$map19 = new Dictionary <string, int>(4)
                    {
                        {
                            "Right_Mouse_Button",
                            0
                        },
                        {
                            "Left_Mouse_Button",
                            0
                        },
                        {
                            "Mouse_Horizontal",
                            0
                        },
                        {
                            "Mouse_Vertical",
                            0
                        }
                    };
                }
                int num;
                if (InputMappingIcons.< > f__switch$map19.TryGetValue(text, out num))
                {
                    if (num == 0)
                    {
                        return(InputMappingIcons.TexturesByName[InputMappingIcons.KeyboardMappings[(int)action]]);
                    }
                }
            }
            return(InputMappingIcons.TextIconBacking);
        }
Beispiel #12
0
 private void Update()
 {
     if (TheForest.Utils.Input.IsGamePad)
     {
         Controller lastActiveController = TheForest.Utils.Input.player.controllers.GetLastActiveController();
         if (lastActiveController != InputMappingIcons.LastController)
         {
             if (InputMappingIcons.LastController != null)
             {
                 Debug.Log(string.Concat(new object[]
                 {
                     "===> Changing gamepad icons: currentController=",
                     lastActiveController.name,
                     ", LastController=",
                     InputMappingIcons.LastController
                 }));
             }
             else
             {
                 Debug.Log("===> Init gamepad icons: currentController=" + lastActiveController.name);
             }
             InputMappingIcons.LastController = lastActiveController;
             InputMappingIcons.RefreshMappings();
             InputMappingIcons.Version++;
         }
     }
     if (this._usingGamePadVersion != TheForest.Utils.Input.IsGamePad)
     {
         this._usingGamePadVersion = TheForest.Utils.Input.IsGamePad;
         InputMappingIcons.Version++;
         if (TheForest.Utils.Input.IsGamePad)
         {
             Debug.Log("===> Switching from KM to gamepad     Version=" + InputMappingIcons.Version);
         }
         else
         {
             Debug.Log("===> Switching from gamepad to KM     Version = " + InputMappingIcons.Version);
         }
     }
 }
Beispiel #13
0
        private static ActionIcon InitializeActionIcon(Transform target, InputMappingIcons.Actions action, ActionIcon.SideIconTypes sideIcon, ActionIconSystem.CurrentViewOptions currentViewOption, bool useAltTextIcon, bool useBigIcon)
        {
            ActionIcon actionIcon = null;

            if (ActionIconSystem.Instance && !ActionIconSystem.Instance._activeIcons.ContainsKey(target))
            {
                if (!InputMappingIcons.UsesText(action))
                {
                    actionIcon = ActionIconSystem.Instance.GetActionIconSprite(useBigIcon);
                    if (!ForestVR.Enabled)
                    {
                        actionIcon._sprite.spriteName = InputMappingIcons.GetMappingFor(action);
                        UISpriteData atlasSprite = actionIcon._sprite.GetAtlasSprite();
                        if (atlasSprite == null)
                        {
                            ActionIconSystem.Instance.DisableActionIcon(actionIcon, useAltTextIcon, useBigIcon);
                            return(null);
                        }
                        actionIcon._sprite.width = Mathf.RoundToInt((float)atlasSprite.width / (float)atlasSprite.height * (float)actionIcon._sprite.height);
                    }
                    else
                    {
                        actionIcon._sprite.enabled = false;
                    }
                }
                else
                {
                    actionIcon             = ActionIconSystem.Instance.GetActionIconLabel(useAltTextIcon, useBigIcon);
                    actionIcon._label.text = InputMappingIcons.GetMappingFor(action);
                    if (!useAltTextIcon)
                    {
                        if (actionIcon._sprite == null)
                        {
                            Debug.LogError(string.Concat(new object[]
                            {
                                "[ActionIcon] Invalid sprite for \"",
                                action,
                                "\" on ",
                                actionIcon.gameObject.GetFullName()
                            }));
                            return(null);
                        }
                        actionIcon._sprite.spriteName = InputMappingIcons.GetBackingFor(action);
                        actionIcon._sprite.enabled    = true;
                        float num = (float)actionIcon._label.width * actionIcon._label.transform.localScale.x / (float)actionIcon.StartHeight;
                        if (num > 1.5f)
                        {
                            actionIcon._sprite.width = Mathf.RoundToInt((float)actionIcon.StartHeight * (num * 1.2f));
                        }
                        else
                        {
                            actionIcon._sprite.width = actionIcon.StartHeight;
                        }
                    }
                }
                actionIcon._action         = action;
                actionIcon._follow._target = target;
                actionIcon._fillSprite.gameObject.SetActive(false);
                actionIcon._follow._inHud       = (currentViewOption == ActionIconSystem.CurrentViewOptions.HudIcon || currentViewOption == ActionIconSystem.CurrentViewOptions.DeathScreen);
                actionIcon._follow._inBook      = (currentViewOption == ActionIconSystem.CurrentViewOptions.AllowInBook);
                actionIcon._follow._inInventory = (currentViewOption == ActionIconSystem.CurrentViewOptions.AllowInInventory);
                actionIcon._follow._inPlane     = (currentViewOption == ActionIconSystem.CurrentViewOptions.AllowInPlane);
                if (actionIcon._sideUpArrowIcon)
                {
                    actionIcon._sideUpArrowIcon.enabled = (sideIcon == ActionIcon.SideIconTypes.UpArrow);
                }
                if (actionIcon._middleUpArrowIcon)
                {
                    actionIcon._middleUpArrowIcon.enabled = (sideIcon == ActionIcon.SideIconTypes.MiddleUpArrow);
                }
                ActionIconSystem.Instance.SetIconHolderTr(actionIcon.transform, currentViewOption);
                ActionIconSystem.Instance._activeIcons.Add(target, actionIcon);
            }
            return(actionIcon);
        }
Beispiel #14
0
 private void Start()
 {
     InputMappingIcons.RefreshMappings();
 }
Beispiel #15
0
        public static void RefreshMappings()
        {
            if (SteamDSConfig.isDedicatedServer)
            {
                return;
            }
            if (!ReInput.isReady || ReInput.players == null)
            {
                return;
            }
            Player player = ReInput.players.GetPlayer(0);

            if (player == null || player.controllers == null)
            {
                return;
            }
            Player.ControllerHelper controllers = player.controllers;
            foreach (ControllerMap controllerMap in controllers.maps.GetAllMaps(ControllerType.Mouse))
            {
                if (controllerMap.enabled)
                {
                    foreach (ActionElementMap actionElementMap in controllerMap.AllMaps)
                    {
                        if (!string.IsNullOrEmpty(actionElementMap.elementIdentifierName))
                        {
                            try
                            {
                                string      text   = actionElementMap.elementIdentifierName.Replace(' ', '_');
                                InputAction action = ReInput.mapping.GetAction(actionElementMap.actionId);
                                if (action.type == InputActionType.Axis)
                                {
                                    InputMappingIcons.KeyboardMappings[(int)Enum.Parse(typeof(InputMappingIcons.Actions), ((actionElementMap.axisContribution != Pole.Positive) ? action.negativeDescriptiveName : action.positiveDescriptiveName).Replace(' ', '_'))] = text;
                                }
                                InputMappingIcons.KeyboardMappings[(int)Enum.Parse(typeof(InputMappingIcons.Actions), action.name.Replace(' ', '_'))] = text;
                            }
                            catch
                            {
                            }
                        }
                    }
                }
            }
            foreach (ControllerMap controllerMap2 in controllers.maps.GetAllMaps(ControllerType.Keyboard))
            {
                if (controllerMap2.enabled)
                {
                    foreach (ActionElementMap actionElementMap2 in controllerMap2.AllMaps)
                    {
                        if (!string.IsNullOrEmpty(actionElementMap2.elementIdentifierName))
                        {
                            try
                            {
                                string elementIdentifierName = actionElementMap2.elementIdentifierName;
                                string text2;
                                if (elementIdentifierName != null)
                                {
                                    if (elementIdentifierName == "Left Control")
                                    {
                                        text2 = "LCtrl";
                                        goto IL_244;
                                    }
                                    if (elementIdentifierName == "Right Control")
                                    {
                                        text2 = "RCtrl";
                                        goto IL_244;
                                    }
                                }
                                text2 = actionElementMap2.elementIdentifierName;
IL_244:
                                InputAction action2 = ReInput.mapping.GetAction(actionElementMap2.actionId);
                                if (action2.type == InputActionType.Axis)
                                {
                                    InputMappingIcons.KeyboardMappings[(int)Enum.Parse(typeof(InputMappingIcons.Actions), ((actionElementMap2.axisContribution != Pole.Positive) ? action2.negativeDescriptiveName : action2.positiveDescriptiveName).Replace(' ', '_'))] = text2;
                                }
                                InputMappingIcons.KeyboardMappings[(int)Enum.Parse(typeof(InputMappingIcons.Actions), action2.name.Replace(' ', '_'))] = text2;
                            }
                            catch
                            {
                            }
                        }
                    }
                }
            }
            if (InputMappingIcons.LastController != null)
            {
                bool   flag = InputMappingIcons.LastController.name.Contains("DualShock") || InputMappingIcons.LastController.GetExtension <DualShock4Extension>() != null;
                string str;
                if (flag)
                {
                    str = "PS4_";
                }
                else
                {
                    str = InputMappingIcons.GetMappingPrefix(InputMappingIcons.LastController);
                }
                foreach (ControllerMap controllerMap3 in controllers.maps.GetAllMaps(ControllerType.Joystick))
                {
                    if (controllerMap3.enabled && controllerMap3.controllerId == InputMappingIcons.LastController.id)
                    {
                        foreach (ActionElementMap actionElementMap3 in controllerMap3.AllMaps)
                        {
                            if (!string.IsNullOrEmpty(actionElementMap3.elementIdentifierName))
                            {
                                try
                                {
                                    string elementIdentifierName2 = actionElementMap3.elementIdentifierName;
                                    string text3;
                                    if (elementIdentifierName2 != null)
                                    {
                                        if (elementIdentifierName2 == "View")
                                        {
                                            text3 = "Back";
                                            goto IL_4C3;
                                        }
                                        if (elementIdentifierName2 == "Right Stick X" || elementIdentifierName2 == "Right Stick Y")
                                        {
                                            text3 = "Right_Stick_Button";
                                            goto IL_4C3;
                                        }
                                        if (elementIdentifierName2 == "Left Stick X" || elementIdentifierName2 == "Left Stick Y")
                                        {
                                            text3 = "Left_Stick_Button";
                                            goto IL_4C3;
                                        }
                                    }
                                    text3 = actionElementMap3.elementIdentifierName.Replace(" X", string.Empty).Replace(" Y", string.Empty).TrimEnd(new char[]
                                    {
                                        ' ',
                                        '+',
                                        '-'
                                    }).Replace(' ', '_');
IL_4C3:
                                    InputAction action3 = ReInput.mapping.GetAction(actionElementMap3.actionId);
                                    text3 = str + text3;
                                    if (action3.type == InputActionType.Axis && (!string.IsNullOrEmpty(action3.positiveDescriptiveName) || !string.IsNullOrEmpty(action3.negativeDescriptiveName)))
                                    {
                                        InputMappingIcons.GamepadMappings[(int)Enum.Parse(typeof(InputMappingIcons.Actions), ((actionElementMap3.axisContribution != Pole.Positive) ? action3.negativeDescriptiveName : action3.positiveDescriptiveName).Replace(' ', '_'))] = text3;
                                    }
                                    InputMappingIcons.GamepadMappings[(int)Enum.Parse(typeof(InputMappingIcons.Actions), action3.name.Replace(' ', '_'))] = text3;
                                }
                                catch
                                {
                                }
                            }
                        }
                    }
                }
            }
            InputMappingIcons.Version++;
        }