コード例 #1
0
 public static void AutoShowAction(InputMappingIcons.Actions action, bool showValue, Texture2D iconTexture = null, ActionIcon.SideIconTypes sideIcon = ActionIcon.SideIconTypes.None, string actionStringOverride = null, DelayedAction delayedAction = null, bool useFillSprite = false)
 {
     foreach (VRControllerDisplayManager vrcontrollerDisplayManager in VRControllerDisplayManager._managerInstances)
     {
         vrcontrollerDisplayManager.ShowAction(action, showValue, iconTexture, sideIcon, actionStringOverride, delayedAction, useFillSprite);
     }
 }
コード例 #2
0
 public static string GetMappingFor(InputMappingIcons.Actions action)
 {
     if (TheForest.Utils.Input.IsGamePad)
     {
         return(InputMappingIcons.GamepadMappings[(int)action]);
     }
     return(InputMappingIcons.KeyboardMappings[(int)action]);
 }
コード例 #3
0
ファイル: DelayedAction.cs プロジェクト: DevZhav/The-Forest
 public void SetAction(InputMappingIcons.Actions action)
 {
     if (!DelayedAction.ActionNames.ContainsKey(action))
     {
         DelayedAction.ActionNames.Add(action, action.ToString());
     }
     this._actionName = DelayedAction.ActionNames[action];
 }
コード例 #4
0
 public void ChangeAction(InputMappingIcons.Actions action, bool useFillSprite)
 {
     if (this._action != action || this._useFillSprite != useFillSprite)
     {
         this._useFillSprite = useFillSprite;
         this._action        = action;
         this._version--;
         this.OnDisable();
         this.OnEnable();
     }
 }
コード例 #5
0
ファイル: ActionIconSystem.cs プロジェクト: K07H/The-Forest
        public static ActionIcon RegisterIcon(Transform target, InputMappingIcons.Actions action, ActionIcon.SideIconTypes sideIcon, ActionIconSystem.CurrentViewOptions currentViewOption = ActionIconSystem.CurrentViewOptions.AllowInWorld, bool useAltTextIcon = false, bool useBigIcon = false, Texture2D vrIcon = null, string actionStringOverride = null, bool useFillSprite = false)
        {
            ActionIcon actionIcon = ActionIconSystem.InitializeActionIcon(target, action, sideIcon, currentViewOption, useAltTextIcon, useBigIcon);

            if (ForestVR.Enabled && !ActionIconSystem.Instance._activeVRButtonActionIcons.ContainsKey(target))
            {
                VRControllerDisplayManager.AutoShowAction(action, true, vrIcon, sideIcon, actionStringOverride, (!actionIcon.IsNull()) ? actionIcon._fillSpriteAction : null, useFillSprite);
                ActionIconSystem.Instance._activeVRButtonActionIcons.Add(target, action);
            }
            return(actionIcon);
        }
コード例 #6
0
ファイル: ActionIconSystem.cs プロジェクト: Bruno13/TheForest
 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);
 }
コード例 #7
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);
        }
コード例 #8
0
        public static bool UsesText(InputMappingIcons.Actions action)
        {
            if (TheForest.Utils.Input.IsGamePad)
            {
                return(false);
            }
            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(false);
                }
            }
            return(true);
        }
コード例 #9
0
        public static string GetBackingFor(InputMappingIcons.Actions action)
        {
            if (TheForest.Utils.Input.IsGamePad)
            {
                return(InputMappingIcons.GamepadMappings[(int)action]);
            }
            string text = InputMappingIcons.KeyboardMappings[(int)action];

            if (text != null)
            {
                if (text == "Space")
                {
                    return("space_button");
                }
            }
            return(InputMappingIcons.TextIconBacking.name);
        }
コード例 #10
0
        public static string GetMappingFor(InputMappingIcons.Actions action)
        {
            if (TheForest.Utils.Input.IsGamePad)
            {
                return(InputMappingIcons.GamepadMappings[(int)action]);
            }
            string text = InputMappingIcons.KeyboardMappings[(int)action];

            if (text != null)
            {
                if (text == "Space")
                {
                    return(UiTranslationDatabase.TranslateKey("SPACE", "SPACE", true));
                }
            }
            return(InputMappingIcons.KeyboardMappings[(int)action]);
        }
コード例 #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);
        }
コード例 #12
0
        public static bool UsesText(InputMappingIcons.Actions action)
        {
            if (TheForest.Utils.Input.IsGamePad)
            {
                return(false);
            }
            string text = InputMappingIcons.KeyboardMappings[(int)action];

            if (text != null)
            {
                if (InputMappingIcons.< > f__switch$map18 == null)
                {
                    InputMappingIcons.< > f__switch$map18 = 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$map18.TryGetValue(text, out num))
                {
                    if (num == 0)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
コード例 #13
0
    private string GetActionText(InputMappingIcons.Actions actionTarget)
    {
        if (actionTarget == InputMappingIcons.Actions.None)
        {
            return(string.Empty);
        }
        string text = actionTarget.ToString();

        if (TheForest.Utils.Input.GetState(InputState.Menu))
        {
            text = this.GetActionText(text, this.MenuTranslations);
        }
        else if (TheForest.Utils.Input.GetState(InputState.Inventory))
        {
            text = this.GetActionText(text, this.InventoryTranslations);
        }
        else if (TheForest.Utils.Input.GetState(InputState.World))
        {
            text = this.GetActionText(text, this.WorldTranslations);
        }
        text = text.ToUpper();
        return(UiTranslationDatabase.TranslateKey(text, text, true));
    }
コード例 #14
0
    public void ShowAction(InputMappingIcons.Actions actionTarget, bool showValue, Texture2D iconTexture = null, ActionIcon.SideIconTypes sideIcon = ActionIcon.SideIconTypes.None, string actionStringOverride = null, DelayedAction delayedAction = null, bool useFillSprite = false)
    {
        Rewired.Player player = ReInput.players.GetPlayer(0);
        if (ReInput.players == null || player == null)
        {
            return;
        }
        Rewired.Player.ControllerHelper controllers = player.controllers;
        string stringValue = actionStringOverride.NullOrEmpty() ? this.GetActionText(actionTarget) : actionStringOverride;

        foreach (ControllerMap controllerMap in controllers.maps.GetAllMaps(ControllerType.Joystick))
        {
            if (controllerMap.enabled)
            {
                Controller controller = ReInput.controllers.GetController(ControllerType.Joystick, controllerMap.controllerId);
                if (controller.name.Equals(this.ControllerName))
                {
                    foreach (ActionElementMap actionElementMap in controllerMap.AllMaps)
                    {
                        InputAction action = ReInput.mapping.GetAction(actionElementMap.actionId);
                        if (action != null)
                        {
                            if (VRControllerDisplayManager.ActionMatches(actionTarget, action))
                            {
                                string elementIdentifierName = actionElementMap.elementIdentifierName;
                                if (iconTexture == null && showValue)
                                {
                                    this.RevertIcon(elementIdentifierName);
                                }
                                this.SetActive(elementIdentifierName, showValue, iconTexture, stringValue.IfNull(string.Empty).ToUpper(), this.ShouldShowTextBacking(), sideIcon, delayedAction, useFillSprite);
                            }
                        }
                    }
                }
            }
        }
    }
コード例 #15
0
 private static string GetActionTargetName(InputMappingIcons.Actions actionTarget)
 {
     return(actionTarget.ToString());
 }
コード例 #16
0
 public void OnEnable()
 {
     if (this._action != InputMappingIcons.Actions.None && (!this._gamepadOnly || TheForest.Utils.Input.IsGamePad || ForestVR.Enabled))
     {
         this._registeredAsBigIcon = (this._useBigIcon || (TheForest.Utils.Input.IsGamePad && this._useBigIconForGamepad));
         Transform transform = base.transform;
         InputMappingIcons.Actions           action            = this._action;
         ActionIcon.SideIconTypes            sideIcon          = this._sideIcon;
         ActionIconSystem.CurrentViewOptions currentViewOption = this._currentViewOption;
         bool       useAltTextIcon      = this._useAltTextIcon;
         bool       registeredAsBigIcon = this._registeredAsBigIcon;
         string     actionTextOverride  = this._actionTextOverride;
         ActionIcon actionIcon          = ActionIconSystem.RegisterIcon(transform, action, sideIcon, currentViewOption, useAltTextIcon, registeredAsBigIcon, null, actionTextOverride, false);
         if (actionIcon)
         {
             this._fillSprite = actionIcon._fillSprite;
             if (this._fillSprite)
             {
                 if (this._fillSprite.gameObject.activeSelf != this._useFillSprite)
                 {
                     this._fillSprite.gameObject.SetActive(this._useFillSprite);
                 }
                 if (this._useFillSprite && actionIcon._fillSpriteAction)
                 {
                     actionIcon._fillSpriteAction.SetAction(this._action);
                 }
             }
             if (actionIcon._sprite && this._widget && this._refreshSiblings)
             {
                 Transform target = this._widget.leftAnchor.target;
                 this._widget.leftAnchor.target = null;
                 this._widget.width             = Mathf.RoundToInt((float)actionIcon._sprite.width / base.transform.localScale.x);
                 this._widget.leftAnchor.target = target;
                 this._widget.SkipWidthUpdate   = true;
                 IEnumerator enumerator = base.transform.GetEnumerator();
                 try
                 {
                     while (enumerator.MoveNext())
                     {
                         object    obj        = enumerator.Current;
                         Transform transform2 = (Transform)obj;
                         UILabel   component  = transform2.GetComponent <UILabel>();
                         if (component)
                         {
                             component.MarkAsChanged();
                             component.ProcessText();
                         }
                     }
                 }
                 finally
                 {
                     IDisposable disposable;
                     if ((disposable = (enumerator as IDisposable)) != null)
                     {
                         disposable.Dispose();
                     }
                 }
             }
         }
     }
     if (this._sprite)
     {
         this._sprite.enabled = false;
     }
     if (this._label)
     {
         this._label.enabled = false;
     }
 }
コード例 #17
0
ファイル: ActionIconSystem.cs プロジェクト: K07H/The-Forest
        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);
        }
コード例 #18
0
    private static bool ActionMatches(InputMappingIcons.Actions actionTarget, InputAction action)
    {
        string name = action.name;

        return(name.Equals(VRControllerDisplayManager.GetActionTargetName(actionTarget), StringComparison.InvariantCultureIgnoreCase));
    }