Пример #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);
    }
Пример #2
0
    public void DeleteElement(int uniqueId)
    {
        int index = Elements.FindIndex(e => e.UniqueId() == uniqueId);

        if (index < 0)
        {
            Debug.LogWarning("Element you are tring to delete doesn't exists. (" + uniqueId + ")");
            return;
        }
        ElementsService.RecalculateIndexes(_elementsPool, Elements);
        if (Elements[index].IsNew == false)
        {
            ElementData.Instance.DeleteElement(Elements[index].Id);
        }

        if (Elements[index].ElementType == ElementType.Character)
        {
            // Debug.Log("Element is Character");
            int indexOfDialog = index + 1;
            if (indexOfDialog <= Elements.Count - 1 &&
                Elements[indexOfDialog].ElementType == ElementType.Dialog)
            {
                // Debug.Log("Element " + Elements[indexOfDialog].ElementType + " can also be removed.");
                if (Elements[indexOfDialog].IsNew == false)
                {
                    ElementData.Instance.DeleteElement(Elements[indexOfDialog].Id);
                }
                RemoveElement(indexOfDialog, Elements[indexOfDialog].UniqueId());
            }
        }
        else if (Elements[index].ElementType == ElementType.Dialog)
        {
            int indexOfCharacter = index - 1;
            Debug.Log(Elements[indexOfCharacter].ElementType);
            if (indexOfCharacter >= 0 &&
                Elements[indexOfCharacter].ElementType == ElementType.Character)
            {
                Debug.Log("Element " + Elements[indexOfCharacter].ElementType + " can also be removed.");
                if (Elements[indexOfCharacter].IsNew == false)
                {
                    ElementData.Instance.DeleteElement(Elements[indexOfCharacter].Id);
                }
                RemoveElement(indexOfCharacter, Elements[indexOfCharacter].UniqueId());

                // we need to get the new uniqueId somehow
                ElementsService.RecalculateIndexes(_elementsPool, Elements);

                DeleteElement(uniqueId);
                return;
            }
        }

        RemoveElement(index, uniqueId);

        MoveCarret(true, index - 1);
        TextEditorHotkeyController.Instance.EscapeKey();

        // recalculate indexes again in case the order is screwed
        ElementsService.RecalculateIndexes(_elementsPool, Elements);
    }
Пример #3
0
    public ElementType GetElementAtCarretPosition()
    {
        var isLastElement = GetCarretIndex() == _elementsPool.Count;

        return(ElementsService.GetPreviousElementType(
                   _elementsPool, Elements,
                   _editableIndex, isLastElement
                   ));
    }
Пример #4
0
    private void InitInlineSelection()
    {
        List <string> options = new List <string>();

        foreach (ElementType elementType in (ElementType[])System.Enum.GetValues(typeof(ElementType)))
        {
            var buttonName = elementType.ToString() + ElementsService.GetButtonHotkey(elementType);
            options.Add(buttonName);
        }
        TextEditorHotkeyController.Instance.InLineSelection.Init(options, OnElementTypeSelected);
    }
Пример #5
0
 public void OnBeginDrag(PointerEventData eventData)
 {
     if (gameObject.activeSelf)
     {
         this.elemento    = ElementsService.findBySymbol(gameObject.transform.GetChild(0).GetComponent <Text>().text);
         this.endPosition = ElementsService.convertStringtoVector3(this.elemento.startPosition);
         this.element     = GameObject.Find(this.elemento.symbol);
     }
     itemBeingDragged = gameObject;
     startPosition    = transform.position;
 }
Пример #6
0
    private IPrefabComponent AddElementInPool(Element element, bool isInitializingElements = false)
    {
        var prefab  = GameHiddenOptions.Instance.GetPrefabElement(element.ElementType);
        var wasNull = UsefullUtils.CheckInPool(
            (IPrefabComponent component) =>
        {
            var typeId = (ElementType)((component as IElementComponent).TypeId);
            if (component.GameObject.activeSelf == false && typeId == element.ElementType)
            {
                return(true);
            }
            return(false);
        },
            prefab,
            transform,
            out IPrefabComponent el,
            ref _elementsPool
            );

        el.UniqueId        = element.UniqueId();
        el.GameObject.name = ElementsService.GetElementName(element);

        if (element.ElementType != ElementType.Picture)
        {
            var elementComponent = (el as ITextComponent);
            elementComponent.SetText(element.Text);
        }
        else
        {
            if (element.Paths != null)
            {
                (el as IPictureComponent).Paths = element.Paths;
                (el as IPictureComponent).FillImages();
            }
        }

        (el as IElementComponent).TypeId = element.TypeId;

        if (wasNull)
        {
            if (isInitializingElements)
            {
                _elementsPool.Add(el);
            }
            else
            {
                _elementsPool.Insert(element.Index, el);
            }
        }

        return(el);
    }
Пример #7
0
        protected override bool OnDeleteEvent(Gdk.Event evnt)
        {
            if (ElementsService.PrimaryWindowClose != null)
            {
                if (ElementsService.PrimaryWindowClose())
                {
                    return(true);
                }
            }

            Banshee.ServiceStack.Application.Shutdown();
            return(true);
        }
Пример #8
0
    public void SaveElements()
    {
        ElementsService.RecalculateIndexes(_elementsPool, Elements);

        foreach (Element element in Elements)
        {
            element.StoryId = StoryService.Instance.Story.Id;
            var el = _elementsPool.FirstOrDefault(e => e.UniqueId == element.UniqueId());

            // UsefullUtils.DumpToConsole(element);

            var isPicture = (el as IElementComponent).TypeId == (int)ElementType.Picture;
            if (isPicture)
            {
                element.Paths     = (el as IPictureComponent).Paths;
                element.FileNames = new List <string>();
            }
            else
            {
                element.Text = (el as ITextComponent).GetText();
            }

            ElementData.Instance.SaveElement(element);
            el.UniqueId   = element.UniqueId();
            element.IsNew = false;

            if (isPicture)
            {
                int index = 0;
                foreach (var path in element.Paths)
                {
                    if (string.IsNullOrWhiteSpace(path))
                    {
                        continue;
                    }
                    element.FileNames.Add("img_" + element.Id + "_0_" + ".jpg");
                    var newPath = StoryService.Instance.Story.GetActivePath() + element.FileNames[index];
                    if (path == newPath)
                    {
                        continue;
                    }
                    File.Copy(path, newPath, true);
                    element.Paths[index] = newPath;
                    index++;
                }
                ElementData.Instance.SaveElement(element);
            }
        }

        TextEditorHotkeyController.Instance.ToggleFileOptions();
    }
Пример #9
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);
    }
Пример #10
0
 public ElementsController(ElementsService elementsService)
 {
     _ElementsService = elementsService;
 }