Example #1
0
 public static Behavior GetUpdateFrameVisibleBehavior(bool isShow)
 {
     return(new Behavior(isReDo => DisplayObjectUtil.UpdateFrameVisible(isShow),
                         isReUndo => DisplayObjectUtil.UpdateFrameVisible(!isShow),
                         BehaviorType.UpdateFrameVisible,
                         false));
 }
Example #2
0
 public static Behavior GetCopyDisplayObjectsBehavior(string moduleName, List <Element> copiedElements, bool needSelect = true, CombineType combineType = CombineType.Independent)
 {
     return(new Behavior(isReDo => DisplayObjectUtil.CopySelectDisplayObjectsBehavior(moduleName, copiedElements, needSelect),
                         isReUndo => DisplayObjectUtil.RemoveDisplayObjectsBehavior(moduleName, copiedElements),
                         BehaviorType.CopyDisplayObjects,
                         true,
                         combineType));
 }
Example #3
0
    public static void ExportModules(string filePath, bool showQuickTip = false)
    {
        if (string.IsNullOrWhiteSpace(filePath))
        {
            return;
        }
        ContainerManager.UpdateCurrentDisplayObjectData();
        List <Module> modules = new List <Module>();
        int           count   = GlobalData.Modules.Count;

        for (int idx = 0; idx < count; ++idx)
        {
            Module module = new Module {
                Name = GlobalData.Modules[idx]
            };
            module.Elements = GlobalData.ModuleDic[module.Name];
            Rectangle rect = DisplayObjectUtil.GetMinRectangleContainsDisplayObjects(module.Elements);
            if (rect != null)
            {
                module.X      = rect.X;
                module.Y      = rect.Y;
                module.Width  = rect.Width;
                module.Height = rect.Height;
            }

            modules.Add(module);
        }

        string jsonString = JsonConvert.SerializeObject(modules, Formatting.Indented);
        bool   result     = Utils.WriteFile(filePath, Encoding.UTF8.GetBytes(jsonString));

        if (result)
        {
            string message = $"成功导出到 {filePath}";
            if (showQuickTip)
            {
                QuickTipManager.ShowQuickTip(message);
            }
            else
            {
                DialogManager.ShowInfo(message);
            }
            GlobalData.CurrentFilePath = filePath;
            GlobalData.ModifyCount     = 0;
        }
        else
        {
            const string message = "导出失败";
            if (showQuickTip)
            {
                QuickTipManager.ShowQuickTip(message);
            }
            else
            {
                DialogManager.ShowError(message, 0, 0);
            }
        }
    }
Example #4
0
 public static Behavior GetLoadImageToDisplayObjectBehavior(string moduleName,
                                                            string elementName,
                                                            string imageUrl,
                                                            bool isModify = true)
 {
     return(new Behavior(isReDo => DisplayObjectUtil.LoadImageBehavior(moduleName, elementName, imageUrl),
                         isReUndo => DisplayObjectUtil.RemoveImageBehavior(moduleName, elementName),
                         BehaviorType.LoadImageToDisplayObject,
                         isModify));
 }
Example #5
0
 public static Behavior GetUpdateSelectDisplayObjectBehavior(string moduleName,
                                                             List <string> addElements    = null,
                                                             List <string> removeElements = null,
                                                             CombineType combineType      = CombineType.Independent)
 {
     return(new Behavior(isReDo => DisplayObjectUtil.UpdateSelectDisplayObjectDicBehavior(moduleName, addElements, removeElements),
                         isReUndo => DisplayObjectUtil.UpdateSelectDisplayObjectDicBehavior(moduleName, removeElements, addElements),
                         BehaviorType.UpdateSelectedDisplayObjectDic,
                         false,
                         combineType));
 }
Example #6
0
 public static void RemoveSelectedDisplayObjectOrModules()
 {
     if (GlobalData.CurrentSelectDisplayObjectDic.Count > 0)
     {
         DisplayObjectUtil.RemoveSelectedDisplayObject();
     }
     else
     {
         ModuleUtil.CheckRemoveCurrentModule();
     }
 }
Example #7
0
 private static void OnFiles(IEnumerable <string> aFiles, POINT aPos)
 {
     try {
         foreach (string path in aFiles)
         {
             if (!RegImageSuffix.IsMatch(path))
             {
                 continue;
             }
             Vector2 pos = Utils.GetRealPositionInContainer(new Vector2(aPos.x, aPos.y), 1);
             DisplayObjectUtil.AddDisplayObject(path, pos, Vector2.zero);
         }
     } catch (Exception e) {
         DialogManager.ShowError(e.ToString());
     }
 }
Example #8
0
    public static Behavior GetMoveDisplayObjectsDownBehavior(string moduleName, List <string> elementNames)
    {
        if (string.IsNullOrWhiteSpace(moduleName) || !moduleName.Equals(GlobalData.CurrentModule))
        {
            return(null);
        }
        if (elementNames == null || elementNames.Count == 0)
        {
            return(null);
        }
        string lastElementName = GlobalData.CurrentDisplayObjects[GlobalData.CurrentDisplayObjects.Count - 1].name;
        int    idx             = elementNames.FindIndex(lastElementName.Equals);

        if (idx != -1)
        {
            return(null);
        }
        return(new Behavior(isReDo => DisplayObjectUtil.MoveDisplayObjectsDownBehavior(moduleName, elementNames),
                            isReUndo => DisplayObjectUtil.MoveDisplayObjectsUpBehavior(moduleName, elementNames),
                            BehaviorType.MoveSelectDisplayObjectsDown));
    }
Example #9
0
    public void PasteDisplayObjects()
    {
        if (GlobalData.CurrentCopyDisplayObjects.Count == 0)
        {
            return;
        }
        List <Element> sourceList = GlobalData.CurrentCopyDisplayObjects;
        Vector2        leftTop    = DisplayObjectUtil.GetCopyDisplayObjectsLeftTop(sourceList);
        Vector2        mousePos   = Vector2.zero;

        if (Utils.IsPointOverGameObject(containerScrollView))
        {
            mousePos = Utils.GetRealPosition(Input.mousePosition);
        }
        Vector2        delta          = mousePos - leftTop;
        int            count          = sourceList.Count;
        string         moduleName     = GlobalData.CurrentModule;
        List <Element> copiedElements = new List <Element>();

        for (int idx = 0; idx < count; ++idx)
        {
            Element sourceElement = sourceList[idx];
            string  imageUrl      = DisplayObjectUtil.GetImageUrl(moduleName, sourceElement.Name);
            string  elementName   = DisplayObjectUtil.GetCanUseElementName(sourceElement.Name, imageUrl);
            Vector2 pos           = new Vector2(sourceElement.X + delta.x, sourceElement.Y + delta.y);
            Vector2 size          = new Vector2(sourceElement.Width, sourceElement.Height);
            Element element       = new Element {
                Name    = elementName,
                X       = pos.x,
                Y       = pos.y,
                Width   = size.x,
                Height  = size.y,
                Visible = true
            };
            DisplayObjectUtil.AddDisplayObjectBehavior(moduleName, element, imageUrl);
            copiedElements.Add(element);
        }

        HistoryManager.Do(BehaviorFactory.GetCopyDisplayObjectsBehavior(moduleName, copiedElements), true);
    }
Example #10
0
    public static Behavior GetAddDisplayObjectBehavior(string moduleName,
                                                       string elementName,
                                                       string imageUrl,
                                                       Vector2 pos,
                                                       Vector2 size,
                                                       CombineType combineType = CombineType.Independent)
    {
        Element element = new Element {
            Name    = elementName,
            X       = Element.ConvertX(pos.x),
            Y       = Element.ConvertY(pos.y),
            Width   = size.x,
            Height  = size.y,
            Visible = true
        };

        return(new Behavior(isRedo => DisplayObjectUtil.AddDisplayObjectBehavior(moduleName, element, imageUrl),
                            isReUndo => DisplayObjectUtil.RemoveDisplayObjectBehavior(moduleName, element.Name),
                            BehaviorType.AddDisplayObject,
                            true,
                            combineType));
    }
Example #11
0
    public static Behavior GetRemoveSelectedDisplayObjectBehavior(string moduleName)
    {
        List <Element> elements     = GlobalData.CurrentSelectDisplayObjectDic.Select(pair => GlobalData.GetElement(pair.Key)).ToList();
        int            length       = elements.Count;
        List <string>  elementNames = new List <string>();

        for (int idx = 0; idx < length; ++idx)
        {
            elementNames.Add(elements[idx].Name);
        }
        return(new Behavior(isReDo => DisplayObjectUtil.RemoveDisplayObjectsBehavior(moduleName, elementNames),
                            isReUndo => {
            DisplayObjectUtil.AddDisplayObjectsBehavior(moduleName, elements);
            foreach (string elementName in elementNames)
            {
                Transform displayObject = GlobalData.CurrentDisplayObjectDic[elementName];
                GlobalData.CurrentSelectDisplayObjectDic.Add(elementName, displayObject);
            }
            UlEventSystem.Dispatch <DataEventType, SelectedChangeData>(DataEventType.SelectedChange,
                                                                       new SelectedChangeData(moduleName, elementNames));
//								MessageBroker.SendUpdateSelectDisplayObjectDic(elementNames);
        },
                            BehaviorType.RemoveSelectedDisplayObject));
    }
Example #12
0
 public static Behavior GetChangeHeightBehavior(string moduleName, List <string> elementNames, float originHeight, float newHeight, bool isAdd = false)
 {
     return(new Behavior(isReDo => DisplayObjectUtil.ChangeHeightBehavior(moduleName, elementNames, newHeight, isAdd),
                         isReUndo => DisplayObjectUtil.ChangeHeightBehavior(moduleName, elementNames, originHeight, isAdd),
                         BehaviorType.ChangeHeight));
 }
Example #13
0
    private void Start()
    {
        UlEventSystem.GetSubject <DataEventType, ChangeModuleEventData>(DataEventType.ChangeModule)
        .Subscribe(eventData => {
            if (eventData == null)
            {
                return;
            }
            string module = eventData.Module;
            if (string.IsNullOrWhiteSpace(module))
            {
                module = null;
            }
            if (GlobalData.CurrentModule == module)
            {
                return;
            }
            List <string> removeElements = GlobalData.CurrentSelectDisplayObjectDic.KeyList();
            if (removeElements != null)
            {
                HistoryManager.Do(BehaviorFactory.GetUpdateSelectDisplayObjectBehavior(GlobalData.CurrentModule,
                                                                                       null,
                                                                                       removeElements,
                                                                                       CombineType.Previous));
            }
            GlobalData.CurrentModule = module;
            DisplayObjectUtil.RemoveAllDisplayObjectBehavior();
            DisplayObjectUtil.AddAllDisplayObjectBehavior();
            UlEventSystem.DispatchTrigger <DataEventType>(DataEventType.CurrentModuleNameChanged);
            GetComponent <RectTransform>().localPosition = Vector2.zero;
            scaleSlider.value = 10f;
        });
        UlEventSystem.GetTriggerSubject <DataEventType>(DataEventType.CurrentModuleNameChanged)
        .Subscribe(_ => {
            UlEventSystem.DispatchTrigger <UIEventType>(UIEventType.UpdateModuleTxtWidth);
            moduleNameText.text = string.IsNullOrWhiteSpace(GlobalData.CurrentModule) ? "null" : GlobalData.CurrentModule;
        });
        UlEventSystem.GetSubject <UIEventType, TriggerEventData>(UIEventType.UpdateModuleTxtWidth)
        .SampleFrame(1)
        .DelayFrame(0)
        .Subscribe(_ => {
            RectTransform rt     = moduleNameText.GetComponent <RectTransform>();
            RectTransform rt2    = selectedDisplayObjectText.GetComponent <RectTransform>();
            rt2.anchoredPosition = new Vector2(rt.anchoredPosition.x + rt.sizeDelta.x + 30, rt2.anchoredPosition.y);
        });
        UlEventSystem.GetSubject <DataEventType, SelectedChangeData>(DataEventType.SelectedChange)
        .Subscribe(eventData => {
            if (eventData == null ||
                string.IsNullOrWhiteSpace(eventData.ModuleName) ||
                !eventData.ModuleName.Equals(GlobalData.CurrentModule))
            {
                return;
            }
            if (eventData.RemoveElements != null)
            {
                foreach (Transform displayObject in eventData.RemoveElements
                         .Select(elementName => {
                    GlobalData.CurrentDisplayObjectDic.TryGetValue(elementName, out Transform displayObject);
                    return(displayObject);
                })
                         .Where(displayObject => displayObject))
                {
                    displayObject.GetComponent <FrameManager>().IsSelect = false;
                }
            }

            if (eventData.AddElements != null)
            {
                foreach (Transform displayObject in eventData.AddElements
                         .Select(elementName => GlobalData.CurrentDisplayObjectDic[elementName])
                         .Where(displayObject => displayObject))
                {
                    displayObject.GetComponent <FrameManager>().IsSelect = true;
                }
            }

            if (GlobalData.CurrentSelectDisplayObjectDic.Count < 1)
            {
                selectedDisplayObjectText.text = "null";
                return;
            }

            StringBuilder sb = new StringBuilder();
            foreach (var pair in GlobalData.CurrentSelectDisplayObjectDic)
            {
                sb.Append($"{pair.Value.name}, ");
                pair.Value.GetComponent <FrameManager>().IsSelect = true;
            }

            selectedDisplayObjectText.text = sb.ToString(0, sb.Length - 2);
        });
        GlobalData.GlobalObservable.ObserveEveryValueChanged(_ => GlobalData.ModifyDic)
        .SampleFrame(1)
        .Subscribe(modifyCount => UlEventSystem.DispatchTrigger <UIEventType>(UIEventType.UpdateTitle));
        GlobalData.GlobalObservable.ObserveEveryValueChanged(_ => GlobalData.CurrentFilePath)
        .SampleFrame(1)
        .Subscribe(_ => UlEventSystem.DispatchTrigger <UIEventType>(UIEventType.UpdateTitle));
        UlEventSystem.GetSubject <UIEventType, TriggerEventData>(UIEventType.UpdateTitle)
        .SampleFrame(1)
        .Subscribe(_ => {
            string title = GlobalData.ProductName;
            if (!string.IsNullOrWhiteSpace(GlobalData.CurrentFilePath))
            {
                title = GlobalData.CurrentFilePath;
            }
            Utils.ChangeTitle(GlobalData.ModifyCount != 0 ? $"* {title}" : title);
        });
    }
Example #14
0
    private void UpdateContainer()
    {
        bool  isControlDown    = GetControl();
        bool  isShiftDown      = GetShift();
        float mouseScrollValue = Input.GetAxis("Mouse ScrollWheel");

        if (isControlDown && Math.Abs(mouseScrollValue) > 0.001f)
        {
            Vector2 prevPos = Utils.GetAnchoredPositionInContainer(Input.mousePosition);
            scaleSlider.value += mouseScrollValue * 10;
            Vector2 currPos    = Utils.GetAnchoredPositionInContainer(Input.mousePosition);
            Vector2 offset     = currPos - prevPos;
            Vector3 localScale = containerRect.localScale;
            Debug.Log($"prev: {prevPos}, curr: {currPos}, offset: {offset}, scale: {localScale.x}");
            containerRect.anchoredPosition += offset * localScale.x;
        }

        if (isControlDown || Input.GetMouseButton(0))
        {
            containerScrollRect.horizontal = false;
            containerScrollRect.vertical   = false;
        }
        else if (Input.GetMouseButton(2))
        {
            containerScrollRect.horizontal = true;
            containerScrollRect.vertical   = true;
            if (Input.GetMouseButtonDown(2))
            {
                _containerOffset = containerRect.anchoredPosition3D - Input.mousePosition;
            }
            else
            {
                containerRect.anchoredPosition3D = Input.mousePosition + _containerOffset;
            }
        }
        else
        {
            containerScrollRect.horizontal        = isShiftDown;
            containerScrollRect.vertical          = !isShiftDown;
            containerScrollRect.scrollSensitivity = Math.Abs(containerScrollRect.scrollSensitivity) * (isShiftDown ? -1 : 1);
        }

        if (isControlDown || !Input.anyKey)
        {
            return;
        }
        if (GetAlt())
        {
            Transform displayObject = GlobalData.CurrentSelectDisplayObjectDic.OnlyValue();
            if (!displayObject)
            {
                return;
            }
            if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                DisplayObjectUtil.SelectDisplayObjectByOffset(displayObject, -1, isShiftDown);
            }
            else if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                DisplayObjectUtil.SelectDisplayObjectByOffset(displayObject, 1, isShiftDown);
            }
            return;
        }
        Vector2 delta = Vector2.zero;

        if (Input.GetKey(KeyCode.UpArrow))
        {
            delta += Vector2.up * containerKeyMoveSensitivity;
        }

        if (Input.GetKey(KeyCode.DownArrow))
        {
            delta += Vector2.down * containerKeyMoveSensitivity;
        }

        if (Input.GetKey(KeyCode.LeftArrow))
        {
            delta += Vector2.left * containerKeyMoveSensitivity;
        }

        if (Input.GetKey(KeyCode.RightArrow))
        {
            delta += Vector2.right * containerKeyMoveSensitivity;
        }

        if (Utils.IsFocusOnInputText() || Utils.IsEqual(delta.x, 0) && Utils.IsEqual(delta.y, 0))
        {
            return;
        }
        Debug.Log($"delta: {delta}");
        containerRect.anchoredPosition += delta;
    }
Example #15
0
    private void UpdateShortcut()
    {
        bool isFocusOnInputText = Utils.IsFocusOnInputText();
        bool isControlDown      = GetControl();
        bool isShiftDown        = GetShift();
        bool isAltDown          = GetAlt();

        if (isControlDown)
        {
            if (Input.GetKeyDown(KeyCode.M))
            {
                functionButtonHandler.OnCreateModuleButtonClick();
            }
            else if (Input.GetKeyDown(KeyCode.N))
            {
                Vector2 pos = Utils.GetRealPositionInContainer(Input.mousePosition);
                DisplayObjectUtil.AddDisplayObject(null, pos, GlobalData.DefaultSize, null, true);
            }
            else if (Input.GetKeyDown(KeyCode.Backspace))
            {
                functionButtonHandler.OnRemoveButtonClick();
            }
            else if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                functionButtonHandler.OnUpButtonClick();
            }
            else if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                functionButtonHandler.OnDownButtonClick();
            }
            else if (Input.GetKeyDown(KeyCode.P))
            {
                functionButtonHandler.OnCopyButtonClick();
            }
            else if (Input.GetKeyDown(KeyCode.I))
            {
                functionButtonHandler.OnImportButtonClick();
            }
            else if (Input.GetKeyDown(KeyCode.E))
            {
                functionButtonHandler.OnExportButtonClick();
            }
            else if (Input.GetKeyDown(KeyCode.H))
            {
                functionButtonHandler.OnHelpButtonClick();
            }
            else if (Input.GetKeyDown(KeyCode.T) && GlobalData.FrameToggle)
            {
                functionButtonHandler.OnToggleTrigger(!GlobalData.FrameToggle.isOn);
            }
        }

        if (Input.GetKeyDown(KeyCode.Delete) && !isFocusOnInputText)
        {
            functionButtonHandler.OnRemoveButtonClick();
        }

        if (Input.GetKeyDown(KeyCode.Escape) && GlobalData.CurrentSelectDisplayObjectDic.Count != 0 && !isFocusOnInputText)
        {
            List <string> removeElements = GlobalData.CurrentSelectDisplayObjectDic.KeyList();
            if (removeElements != null)
            {
                HistoryManager.Do(BehaviorFactory.GetUpdateSelectDisplayObjectBehavior(GlobalData.CurrentModule, null, removeElements));
            }
        }

        if (isControlDown && !isFocusOnInputText)
        {
            if (Input.GetKeyDown(KeyCode.C))
            {
                DisplayObjectUtil.CopySelectDisplayObjects();
            }
            else if (Input.GetKeyDown(KeyCode.V))
            {
                containerManager.PasteDisplayObjects();
            }
        }

        if (isControlDown)
        {
            if (Input.GetKeyDown(KeyCode.Z))
            {
                HistoryManager.Undo();
            }
            else if (Input.GetKeyDown(KeyCode.Y))
            {
                HistoryManager.Do();
            }
        }

        if (isControlDown && Input.GetKeyDown(KeyCode.S))
        {
            if (string.IsNullOrWhiteSpace(GlobalData.CurrentFilePath))
            {
                functionButtonHandler.OnExportButtonClick();
            }
            else
            {
                ModuleUtil.ExportModules(GlobalData.CurrentFilePath, true);
            }
        }

        if (isControlDown && isShiftDown && isAltDown && Input.GetKeyDown(KeyCode.D))
        {
            Debugger.ShowDebugging = !Debugger.ShowDebugging;
        }

        if (isControlDown && isShiftDown && isAltDown && Input.GetKeyDown(KeyCode.F))
        {
            Screen.fullScreen = !Screen.fullScreen;
        }

        if (Input.GetKeyDown(KeyCode.Q))
        {
            Debug.Log($"pos: {Utils.GetRealPosition(Input.mousePosition)}");
        }
    }
Example #16
0
 public static Behavior GetUpdateDisplayObjectsPosBehavior(string moduleName, IReadOnlyList <string> elementNames, Vector2 originPos, Vector2 targetPos)
 {
     return(new Behavior(isReDo => DisplayObjectUtil.UpdateDisplayObjectsPosition(moduleName, elementNames, targetPos),
                         isReUndo => DisplayObjectUtil.UpdateDisplayObjectsPosition(moduleName, elementNames, originPos),
                         BehaviorType.UpdateDisplayObjectsPos));
 }
Example #17
0
    public void OnDrag(PointerEventData eventData)
    {
        if (Input.GetMouseButton(2))
        {
            return;
        }
        if (_selfElement == null)
        {
            _selfElement = GlobalData.GetElement(transform.name);
        }
        Vector2 pos    = Utils.GetAnchoredPositionInContainer(Input.mousePosition) - _offset;
        Vector2 offset = pos - selfRect.anchoredPosition;

        DisplayObjectUtil.UpdateElementPosition(selfRect, _selfElement, pos);
        UlEventSystem.DispatchTrigger <UIEventType>(UIEventType.UpdateInspectorInfo);
        _alignInfo = DisplayObjectUtil.GetAlignLine(_selfElement, _alignInfo);
        if (_alignInfo?.HorizontalAlignLine != null)
        {
            Rectangle horizontalAlignRect = _alignInfo.HorizontalAlignLine;
            print($"_alignInfo.HorizontalAlignType: {_alignInfo.HorizontalAlignType}, isCenter: {_alignInfo.HorizontalAlignType == AlignType.HorizontalCenter}");
            _horizontalAlignLineManager.gameObject.SetActive(true);
            _horizontalAlignLineManager.transform.SetAsLastSibling();
            AlignType leftType  = _alignInfo.HorizontalAlignType;
            AlignType rightType = _alignInfo.OtherHorizontalAlignType;
            if (Math.Abs(_alignInfo.HorizontalAlignLine.Right - _selfElement.Right) < Math.Abs(_alignInfo.HorizontalAlignLine.Left - _selfElement.Left))
            {
                leftType  = _alignInfo.OtherHorizontalAlignType;
                rightType = _alignInfo.HorizontalAlignType;
            }
            _horizontalAlignLineManager.UpdateHorizontal(leftType,
                                                         rightType,
                                                         Element.InvConvertTo(new Vector2(horizontalAlignRect.X - GlobalData.AlignExtensionValue, horizontalAlignRect.Y)),
                                                         new Vector2(horizontalAlignRect.Width + (GlobalData.AlignExtensionValue << 1), horizontalAlignRect.Height));
        }
        else
        {
            _horizontalAlignLineManager.gameObject.SetActive(false);
        }

        if (_alignInfo?.VerticalAlignLine != null)
        {
            Rectangle verticalAlignRect = _alignInfo.VerticalAlignLine;
            print($"_alignInfo.VerticalAlignType: {_alignInfo.VerticalAlignType}, isCenter: {_alignInfo.VerticalAlignType == AlignType.VerticalCenter}");
            _verticalAlignLineManager.gameObject.SetActive(true);
            _verticalAlignLineManager.transform.SetAsLastSibling();
            AlignType upType   = _alignInfo.VerticalAlignType;
            AlignType downType = _alignInfo.OtherVerticalAlignType;
            if (Math.Abs(_alignInfo.VerticalAlignLine.Top - _selfElement.Top) < Math.Abs(_alignInfo.VerticalAlignLine.Bottom - _selfElement.Bottom))
            {
                upType   = _alignInfo.OtherVerticalAlignType;
                downType = _alignInfo.VerticalAlignType;
            }
            _verticalAlignLineManager.UpdateVertical(upType,
                                                     downType,
                                                     Element.InvConvertTo(new Vector2(verticalAlignRect.X, verticalAlignRect.Y - GlobalData.AlignExtensionValue)),
                                                     new Vector2(verticalAlignRect.Width, verticalAlignRect.Height + (GlobalData.AlignExtensionValue << 1)));
        }
        else
        {
            _verticalAlignLineManager.gameObject.SetActive(false);
        }

        if (GlobalData.CurrentSelectDisplayObjectDic.Count == 1)
        {
            return;
        }
        foreach (var pair in GlobalData.CurrentSelectDisplayObjectDic)
        {
            if (pair.Value == transform)
            {
                continue;
            }
            RectTransform rt = pair.Value.GetComponent <RectTransform>();
            DisplayObjectUtil.UpdateElementPosition(rt, pair.Key, rt.anchoredPosition + offset);
        }
    }
Example #18
0
 public static Behavior GetChangeNameBehavior(string moduleName, string originName, string newName)
 {
     return(new Behavior(isReDo => DisplayObjectUtil.ChangeNameBehavior(moduleName, originName, newName),
                         isReUndo => DisplayObjectUtil.ChangeNameBehavior(moduleName, newName, originName),
                         BehaviorType.ChangeName));
 }
Example #19
0
 void IBeginDragHandler.OnBeginDrag(PointerEventData eventData)
 {
     _isDrag = true;
     if (KeyboardEventManager.GetAlt() && _copying == null)
     {
         List <string>  removeElements   = GlobalData.CurrentSelectDisplayObjectDic.KeyList();
         List <Element> copiedElements   = new List <Element>();
         List <string>  addElements      = new List <string>();
         List <Element> selectedElements = GlobalData.ModuleDic[GlobalData.CurrentModule]
                                           .Where(element => GlobalData.CurrentSelectDisplayObjectDic.ContainsKey(element.Name))
                                           .ToList();
         GameObject selfReplisome = null;
         int        count         = selectedElements.Count;
         for (int idx = 0; idx < count; ++idx)
         {
             Element element = selectedElements[idx];
             if (element == null)
             {
                 continue;
             }
             string    key               = $"{GlobalData.CurrentModule}_{element.Name}";
             string    imageUrl          = GlobalData.DisplayObjectPathDic.ContainsKey(element.Name) ? imageUrl = GlobalData.DisplayObjectPathDic[key] : null;
             Vector2   pos               = new Vector2(element.X, element.Y) + Element.InvConvertTo(GlobalData.OriginPoint);
             Vector2   size              = new Vector2(element.Width, element.Height);
             Transform copyDisplayObject = DisplayObjectUtil.AddDisplayObject(imageUrl,
                                                                              pos,
                                                                              size,
                                                                              element.Name + "_copy",
                                                                              false,
                                                                              false);
             if (copyDisplayObject == null)
             {
                 continue;
             }
             copiedElements.Add(new Element {
                 Name    = copyDisplayObject.name,
                 X       = pos.x,
                 Y       = pos.y,
                 Width   = size.x,
                 Height  = size.y,
                 Visible = true
             });
             addElements.Add(copyDisplayObject.name);
             if (!element.Name.Equals(transform.name))
             {
                 continue;
             }
             selfReplisome = copyDisplayObject.gameObject;
             DisplayObjectManager dom = copyDisplayObject.GetComponent <DisplayObjectManager>();
             if (dom)
             {
                 dom._offset = _offset;
             }
         }
         HistoryManager.Do(BehaviorFactory.GetCopyDisplayObjectsBehavior(GlobalData.CurrentModule, copiedElements, false, CombineType.Next), true);
         HistoryManager.Do(BehaviorFactory.GetUpdateSelectDisplayObjectBehavior(GlobalData.CurrentModule, addElements, removeElements, CombineType.Next));
         ExecuteEvents.Execute(gameObject, eventData, ExecuteEvents.endDragHandler);
         if (selfReplisome == null)
         {
             return;
         }
         eventData.pointerDrag = selfReplisome;
     }
     else
     {
         _startPos = selfRect.anchoredPosition;
     }
 }
 public void OnAddButtonClick()
 {
     DisplayObjectUtil.AddDisplayObject(null, Element.InvConvertTo(GlobalData.OriginPoint), GlobalData.DefaultSize, null, true);
 }