예제 #1
0
    public ElementType GetElementAtCarretPosition()
    {
        var isLastElement = GetCarretIndex() == _elementsPool.Count;

        return(ElementsService.GetPreviousElementType(
                   _elementsPool, Elements,
                   _editableIndex, isLastElement
                   ));
    }
예제 #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);
    }