Ejemplo n.º 1
0
    private List <int> FilterElementTypes()
    {
        if (ElementsController.Instance.Elements == null)
        {
            ElementsController.Instance.InitElements(new List <Element>());
        }
        if (ElementsController.Instance.Elements.Count == 0)
        {
            return(new List <int>()
            {
                0
            });
        }

        var previousElementType = ElementsController.Instance.GetElementAtCarretPosition();

        var options = new List <int>();
        int i       = 0;

        foreach (ElementType elementType in (ElementType[])System.Enum.GetValues(typeof(ElementType)))
        {
            if (ElementsService.FilterNewElements(elementType, previousElementType))
            {
                options.Add(i);
            }
            i++;
        }
        return(options);
    }
Ejemplo n.º 2
0
    public bool AddNewElement(ElementType elementType, bool autoCreate = false)
    {
        var currentIndex  = GetCarretIndex();
        var isLastElement = currentIndex == _elementsPool.Count;

        if (autoCreate && isLastElement == false)
        {
            TextEditorHotkeyController.Instance.MainEdit();
            return(false);
        }

        if ((Elements == null || Elements.Count == 0) && elementType != ElementType.SceneHeading)
        {
            return(false);
        }

        ElementType previousElementType = ElementsService.GetPreviousElementType(
            _elementsPool, Elements,
            _editableIndex, isLastElement
            );

        if (ElementsService.FilterNewElements(elementType, previousElementType) == false)
        {
            return(false);
        }

        if (TextEditorHotkeyController.Instance.ShowOptions)
        {
            TextEditorHotkeyController.Instance.FileMainButtons.SetActive(true);
            TextEditorHotkeyController.Instance.InLineSelection.gameObject.SetActive(false);
        }

        var element = new Element()
        {
            Text        = ElementsService.GetDefaultText(elementType),
            ElementType = elementType,
            Index       = currentIndex,
            IsNew       = true
        };

        Elements.Add(element);
        var el = AddElementInPool(element);

        if (isLastElement == false)
        {
            var newIndex = (_editableIndex + 1);
            el.GameObject.transform.SetSiblingIndex(newIndex);
        }
        else
        {
            MoveCarret(true);
        }
        ElementsService.RecalculateIndexes(_elementsPool, Elements);

        GameService.Instance.InternalWait(() =>
        {
            if (element.ElementType == ElementType.Picture)
            {
                (el as IPictureComponent).AutoSelect();
            }
            else
            {
                (el as ITextComponent).AutoSelect();
            }
            TextEditorHotkeyController.Instance.AppState = AppState.Editing;

            if (isLastElement)
            {
                ScrollController.Instance.ScrollToBottom();
            }
            else
            {
                ScrollController.Instance.KeepElementInView(el.GameObject.GetComponent <RectTransform>());
            }
        });
        return(true);
    }