Exemplo n.º 1
0
        public void AddMessage(string message, string hover, Color color)
        {
            if (string.IsNullOrEmpty(message))
            {
                return;
            }
            //bool scrollbarAtBottom = false;
            //if (ScrollRect != null && ScrollRect.verticalScrollbar != null && ScrollRect.verticalScrollbar.value < 0.05f) {
            //    scrollbarAtBottom = true;
            //}
            var item = ItemPool.SpawnUIPrefab <UINotificationMsg>(_msgPrefab.gameObject, _container);

            //item.transform.SetSiblingIndex(0); // Move to the top of the list
            item.Show(message, hover, color, 0);
            if (_scrollRect != null)
            {
                _scrollRect.verticalNormalizedPosition = 0.0f;
            }
            if (_msgTimeout > 0)
            {
                item.ExpireTime = TimeManager.TimeUnscaled + _msgTimeout;
            }
            _messages.Add(item);
            if (_messages.Count > _maxMessages)
            {
                _messages[0].Hide();
                _messages.RemoveAt(0);
            }
        }
Exemplo n.º 2
0
        private UIGenericLabel SetupLabel(Transform parent, string label)
        {
            var newButton = ItemPool.SpawnUIPrefab <UIGenericLabel>(_labelPrefab, parent);

            newButton.SetText(label);
            return(newButton);
        }
Exemplo n.º 3
0
 private void GenerateNewList()
 {
     if (_items != null)
     {
         for (int i = 0; i < _items.Length; i++)
         {
             ItemPool.Despawn(_items[i].gameObject);
         }
     }
     _items = new UIGenericButton[_menuActions.Count];
     for (int i = 0; i < _menuActions.Count; i++)
     {
         var listItem = ItemPool.SpawnUIPrefab <UIGenericButton>(_buttonPrefab.gameObject, _grid.transform);
         listItem.Index = i;
         listItem.SetText(_menuActions[i].Description);
         listItem.OnButtonClicked += ListItemSelected;
         _items[i] = listItem;
     }
     _canvas.alpha          = 1;
     _canvas.interactable   = true;
     _canvas.blocksRaycasts = true;
     UITooltip.main.HideTooltipImmediate();
     UITooltip.CanActivate = false;
     _currentId            = UnityEngine.Random.Range(int.MinValue, int.MaxValue);
     //_grid.CalculateLayoutInputHorizontal();
     //_grid.CalculateLayoutInputVertical();
     //if (Mathf.Abs(_targetPos.y) + _rectTr.sizeDelta.y > _topCanvas.pixelRect.height) {
     //    var diff = (Mathf.Abs(_targetPos.y) + _rectTr.sizeDelta.y) - _topCanvas.pixelRect.height;
     //    _targetPos.y -= diff;
     //}
     //if (Mathf.Abs(_targetPos.x) + _rectTr.sizeDelta.x > _topCanvas.pixelRect.height) {
     //    var diff = (Mathf.Abs(_targetPos.y) + _rectTr.sizeDelta.y) - _topCanvas.pixelRect.height;
     //    _targetPos.y -= diff;
     //}
 }
Exemplo n.º 4
0
        public static UIFloatingText Spawn(string text, RectTransform start, Color color, Orietation orientation)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(null);
            }
            UIFloatingText spawn;

            switch (orientation)
            {
            case Orietation.Right:
                spawn = ItemPool.SpawnUIPrefab <UIFloatingText>("UI/UIFloatingTextRight", start);
                break;

            case Orietation.Left:
                spawn = ItemPool.SpawnUIPrefab <UIFloatingText>("UI/UIFloatingTextLeft", start);
                break;

            case Orietation.Icon:
                spawn = ItemPool.SpawnUIPrefab <UIFloatingText>("UI/UIFloatingTextIcon", start);
                break;

            default:
                spawn = ItemPool.SpawnUIPrefab <UIFloatingText>("UI/UIFloatingTextStandard", start);
                break;
            }
            //spawn.RectTransform.sizeDelta = start.sizeDelta;
            spawn.RectTransform.SetParent(UIRoot.Player.Get().transform);
            spawn.RectTransform.SetAsLastSibling();
            TimeManager.StartUnscaled(spawn.SetTargetText(text, 2f, start.position + new Vector3(0, 150, 0), color));
            return(spawn);
        }
Exemplo n.º 5
0
        private UIGenericSlider SetupSlider(Transform parent, float value, float min, float max, System.Action <UIGenericSlider, float> onChange, bool wholeNumbers)
        {
            var newButton = ItemPool.SpawnUIPrefab <UIGenericSlider>(_sliderPrefab, parent);

            newButton.SetNewSlider(min, max, value, wholeNumbers);
            newButton.OnValueChanged = onChange;
            return(newButton);
        }
Exemplo n.º 6
0
        private UIGenericButton SetupButton(Transform parent, string label, System.Action <int> onClick)
        {
            var newButton = ItemPool.SpawnUIPrefab <UIGenericButton>(_buttonprefab, parent);

            newButton.Index = newButton.transform.GetSiblingIndex();
            newButton.SetText(label);
            newButton.OnButtonClicked = onClick;
            return(newButton);
        }
Exemplo n.º 7
0
        private UIGenericToggle SetupToggle(Transform parent, bool currentValue, Action <bool> onChange, string label)
        {
            var newButton = ItemPool.SpawnUIPrefab <UIGenericToggle>(_togglePrefab, parent);

            newButton.SetText(label);
            newButton.SetInitialValue(currentValue);
            newButton.OnValueChanged = onChange;
            return(newButton);
        }
Exemplo n.º 8
0
 private void SetupSlots()
 {
     _slots = new UIHotbarSlot[_size];
     for (int i = 0; i < _slots.Length; i++)
     {
         _slots[i] = ItemPool.SpawnUIPrefab <UIHotbarSlot>(_prefab.gameObject, _grid);
         _slots[i].SetIndex(i);
     }
 }
Exemplo n.º 9
0
        public static UIGenericValueWatcher Get(UIAnchor anchor, float timer, Func <string> del)
        {
            var valueWatcher = ItemPool.SpawnUIPrefab <UIGenericValueWatcher>(UnityDirs.UI + "UIGenericValueWatcher", anchor.Get().transform);

            valueWatcher._timer.StartNewTime(timer);
            valueWatcher._checkTimer = timer > 0;
            valueWatcher._updateDel  = del;
            anchor.SetAnchorPosition(valueWatcher._rectTr);
            return(valueWatcher);
        }
Exemplo n.º 10
0
        private UIGenericDropdown SetupDropdown(Transform parent, List <string> options, int index, Action <int> onChange, string label)
        {
            var newButton = ItemPool.SpawnUIPrefab <UIGenericDropdown>(_dropdownPrefab, parent);

            newButton.SetText(label);
            newButton.Dropdown.ClearOptions();
            newButton.Dropdown.AddOptions(options);
            newButton.Dropdown.value = index;
            newButton.OnValueChanged = onChange;
            return(newButton);
        }
Exemplo n.º 11
0
 public void Spawn(string title, Transform parent, bool isV3)
 {
     if (isV3)
     {
         _text = ItemPool.SpawnUIPrefab <UIDataText>(string.Format("{0}DataTextV3", UnityDirs.UI), parent);
     }
     else
     {
         _text = ItemPool.SpawnUIPrefab <UIDataText>(string.Format("{0}DataText", UnityDirs.UI), parent);
     }
     _text.SetTitle(title);
 }
Exemplo n.º 12
0
        public static void Spawn(string text, float duration, RectTransform start, Vector3 end, Color startColor)
        {
            if (string.IsNullOrEmpty(text) || _msgChecker.ContainsDuplicate(text, start))
            {
                return;
            }
            _msgChecker.Add(text, start);
            var spawn = ItemPool.SpawnUIPrefab <UIFloatingText>("UI/UIFloatingTextStandard", start);

            spawn.RectTransform.SetParent(UIRoot.Player.Get().transform);
            spawn.RectTransform.SetAsLastSibling();
            TimeManager.StartUnscaled(spawn.SetTargetText(text, duration, end, startColor));
        }
Exemplo n.º 13
0
        public UISimpleGameDataButton AddItem(Entity item)
        {
            var prefab = ItemPool.SpawnUIPrefab <UISimpleGameDataButton>(_prefab, _grid);

            if (OnClickDel != null)
            {
                prefab.OnClickDel = OnClickDel;
            }
            prefab.SetData(item);
            prefab.Index = _slots.Count;
            _slots.Add(prefab.gameObject);
            return(prefab);
        }
Exemplo n.º 14
0
        public void OnCreate(PrefabEntity entity)
        {
            var currencies = GameData.Enums.GetFakeEnum(EnumTypes.Currencies);

            for (int i = 0; i < currencies.Length; i++)
            {
                var prefab = ItemPool.SpawnUIPrefab(_currencyPrefab, _currencyPivot);
                prefab.GetComponentInChildren <Image>().overrideSprite = SpriteDatabase.CurrencyIcons.SafeAccess(i);
                var text = prefab.GetComponentInChildren <TextMeshProUGUI>();
                text.text = "";
                var currency = Player.GetCurrency(currencies.GetShortID(i));
                currency.OnResourceChanged += () => { text.text = currency.Value.ToString("F0"); };
            }
        }
Exemplo n.º 15
0
        public static void WorldSpawn(string text, Vector3 start, Color color)
        {
            if (string.IsNullOrEmpty(text))
            {
                return;
            }
            _msgChecker.Add(text, UIRoot.Misc.Get().transform);
            UIFloatingText spawn = ItemPool.SpawnUIPrefab <UIFloatingText>("UI/UIFloatingTextStandard", UIRoot.Misc.Get().transform);

            spawn.transform.position = RectTransformUtility.WorldToScreenPoint(Player.Cam, start);
            var end = RectTransformUtility.WorldToScreenPoint(Player.Cam, start + new Vector3(0, 1, 0));

            spawn.RectTransform.SetAsLastSibling();
            TimeManager.StartUnscaled(spawn.SetTargetText(text, 2f, end, color));
        }
Exemplo n.º 16
0
 private void CheckMods()
 {
     ClearModList();
     for (int i = 0; i < _character.Modifiers.c.Count; i++)
     {
         var mod = _character.Modifiers.c[i];
         if (mod.Icon == null || ContainsMod(mod))
         {
             continue;
         }
         var modWatch = ItemPool.SpawnUIPrefab <UIModIcon>(_modPrefab.gameObject, _modGrid);
         _active.Add(modWatch);
         modWatch.Assign(mod, _character);
     }
 }
Exemplo n.º 17
0
        private void RefreshControls()
        {
            Controller controller = PlayerInput.RewiredPlayer.controllers.GetLastActiveController();

            if (controller.type == ControllerType.Mouse)
            {
                controller = PlayerInput.RewiredPlayer.controllers.Keyboard;
            }
            var controllerMap = PlayerInput.RewiredPlayer.controllers.maps.GetFirstMapInCategory(controller, 0);

            foreach (InputAction inputAction in ReInput.mapping.ActionsInCategory(0))
            {
                _targetOptions.Add(SetupLabel(_optionControlsTr, inputAction.descriptiveName).gameObject);
                var pivot = ItemPool.SpawnUIPrefab(_horizontalListPrefab, _optionControlsTr);
                _targetOptions.Add(pivot.gameObject);
                var action = inputAction;
                _targetOptions.Add(SetupButton(pivot.transform, "Add New", delegate(int i) {
                    InputMapper.Context context = new InputMapper.Context()
                    {
                        actionId      = action.id,
                        actionRange   = AxisRange.Positive,
                        controllerMap = controllerMap
                    };
                    SetInputListen(context);
                }).gameObject);
                // Write out assigned elements
                for (var i = 0; i < controllerMap.AllMaps.Count; i++)
                {
                    ActionElementMap elementMap = controllerMap.AllMaps[i];
                    if (elementMap.actionId != action.id)
                    {
                        continue;
                    }
                    _targetOptions.Add(SetupButton(pivot.transform, elementMap.elementIdentifierName, delegate(int i1) {
                        InputMapper.Context context = new InputMapper.Context()
                        {
                            actionId                  = action.id,
                            actionRange               = AxisRange.Positive,
                            controllerMap             = controllerMap,
                            actionElementMapToReplace = elementMap
                        };
                        SetInputListen(context);
                    }).gameObject
                                       );
                }
            }
        }
Exemplo n.º 18
0
        public static void SpawnIcon(Sprite icon, string text, RectTransform start, Color color)
        {
            var            startPosition = start.position;
            UIFloatingText spawn         = ItemPool.SpawnUIPrefab <UIFloatingText>("UI/UIFloatingTextIcon", start);

            spawn.RectTransform.SetParent(UIRoot.Misc.Get().transform);
            spawn.RectTransform.SetAsLastSibling();
            if (_iconTimer.IsActive)
            {
                startPosition = start.position + new Vector3(_negative ? -Offset : Offset, 0, 0);
                spawn.RectTransform.position = startPosition;
                _negative = !_negative;
            }
            _iconTimer.StartTimer();
            spawn._icon.sprite = icon;
            TimeManager.StartUnscaled(spawn.SetTargetText(text, 2f, startPosition + new Vector3(0, 150, 0), color));
        }
Exemplo n.º 19
0
 private void CheckMods()
 {
     ClearList();
     for (int i = _actor.Modifiers.c.Count - 1; i >= 0; i--)
     {
         if (_active.Count >= _modLimit)
         {
             break;
         }
         var mod = _actor.Modifiers.c[i];
         if (mod.Icon == null || ContainsMod(mod))
         {
             continue;
         }
         var modWatch = ItemPool.SpawnUIPrefab <UIModIcon>(_prefab.gameObject, transform);
         _active.Add(modWatch);
         modWatch.Assign(mod, _actor);
     }
 }
Exemplo n.º 20
0
        public void ListScores()
        {
            for (int i = 0; i < _currentLines.Count; i++)
            {
                ItemPool.Despawn(_currentLines[i].gameObject);
            }
            _currentLines.Clear();

            var scores = ScoreKeeper.RetrieveScores();

            if (scores == null || scores.Length == 0)
            {
                return;
            }
            for (int i = 0; i < scores.Length; i++)
            {
                var newLine = ItemPool.SpawnUIPrefab <UIScoreLine>(_scorePrefab.gameObject, _listTr);
                newLine.SetScore(scores[i]);
                _currentLines.Add(newLine);
            }
        }
Exemplo n.º 21
0
 private void CheckMods()
 {
     ClearList();
     _mods.Clear();
     World.Get <ModifierSystem>().FillModList(_mods, _actor.Entity.Id);
     for (int i = _mods.Count - 1; i >= 0; i--)
     {
         if (_active.Count >= _modLimit)
         {
             break;
         }
         var mod = _mods[i];
         if (mod.Icon == null)
         {
             continue;
         }
         var modWatch = ItemPool.SpawnUIPrefab <UIModIcon>(_prefab.gameObject, transform);
         _active.Add(modWatch);
         modWatch.Assign(mod);
     }
 }
Exemplo n.º 22
0
        public static void UpdatePermText(string label, string text)
        {
            if (!Application.isPlaying)
            {
                Debug.Log(text);
                return;
            }
            if (main == null)
            {
                return;
            }
            Text objText;

            if (!main._permTextDict.TryGetValue(label, out objText))
            {
                var textObject = ItemPool.SpawnUIPrefab("UI/DebugTextPerm", main.PermRoot);
                objText = textObject.GetComponent <Text>();
                main._permTextDict.Add(label, objText);
            }
            objText.text = string.Format("{0} - {1}", label, text);
        }
Exemplo n.º 23
0
 private void CheckMods()
 {
     if (_character == null)
     {
         return;
     }
     ClearModList();
     _mods.Clear();
     World.Get <ModifierSystem>().FillModList(_mods, _character.Entity.Id);
     for (int i = 0; i < _mods.Count; i++)
     {
         var mod = _mods[i];
         if (mod.Icon == null)
         {
             continue;
         }
         var modWatch = ItemPool.SpawnUIPrefab <UIModIcon>(_modPrefab.gameObject, _modGrid);
         _active.Add(modWatch);
         modWatch.Assign(mod);
     }
 }
Exemplo n.º 24
0
        public static void Log(string text, float length = 2f)
        {
            if (!Application.isPlaying)
            {
                Debug.Log(text);
                return;
            }
            if (main == null)
            {
                return;
            }
            if (_lastText == text)
            {
                return;
            }
            _lastText = text;
            var newText    = main._textTimers.New();
            var textObject = ItemPool.SpawnUIPrefab("UI/DebugTextTemp", main.TempRoot);

            textObject.GetComponent <Text>().text = text;
            newText.Time.StartNewTime(length);
            newText.TextObject = textObject;
            main._tempText.Add(newText);
        }
Exemplo n.º 25
0
 public UIRadialElement CreateElement()
 {
     return(ItemPool.SpawnUIPrefab <UIRadialElement>(_radialPrefab.gameObject, _elementsPivot));
 }
Exemplo n.º 26
0
 protected virtual UIItemDragDrop SpawnPrefab()
 {
     return(ItemPool.SpawnUIPrefab <UIItemDragDrop>(StringConst.ItemDragDrop, _grid));
 }