Пример #1
0
 public static bool CreateModuleBehavior(string moduleName, List <Element> elements = null, bool selectModule = true, bool needCheckCache = false)
 {
     if (string.IsNullOrWhiteSpace(moduleName))
     {
         return(false);
     }
     if (GlobalData.ModuleDic.ContainsKey(moduleName))
     {
         return(false);
     }
     // 还原 module 时尝试取回删除时保存的数据
     if (needCheckCache && elements == null)
     {
         GlobalData.CacheModuleDic.TryGetValue(moduleName, out elements);
     }
     if (elements == null)
     {
         elements = new List <Element>();
     }
     GlobalData.ModuleDic[moduleName] = elements;
     GlobalData.Modules.Add(moduleName);
     if (selectModule)
     {
         UlEventSystem.Dispatch <DataEventType, ChangeModuleEventData>(DataEventType.ChangeModule, new ChangeModuleEventData(moduleName));
     }
     UlEventSystem.DispatchTrigger <UIEventType>(UIEventType.UpdateInspectorInfo);
     UlEventSystem.DispatchTrigger <UIEventType>(UIEventType.RefreshModuleItem);
     return(true);
 }
Пример #2
0
    public static void ChangeModuleName(string moduleName, string newModuleName)
    {
        if (string.IsNullOrWhiteSpace(moduleName) || !moduleName.Equals(GlobalData.CurrentModule))
        {
            return;
        }
        // 正常确保了可以修改才调用该方法
        if (GlobalData.ModuleDic.ContainsKey(newModuleName))
        {
            return;
        }
        int idx = GlobalData.Modules.FindIndex(module => module.Equals(moduleName));

        if (idx == -1)
        {
            return;
        }
        GlobalData.CurrentModule = newModuleName;
        GlobalData.Modules[idx]  = newModuleName;
        List <Element> elements = GlobalData.ModuleDic[moduleName];

        GlobalData.ModuleDic.Remove(moduleName);
        GlobalData.ModuleDic[newModuleName] = elements;
        UlEventSystem.DispatchTrigger <DataEventType>(DataEventType.CurrentModuleNameChanged);
        UlEventSystem.DispatchTrigger <UIEventType>(UIEventType.RefreshModuleItem);
    }
Пример #3
0
 public static void Do(bool justAdd = false)
 {
     while (UnDoneBehaviors.Count > 0)
     {
         Behavior behavior = UnDoneBehaviors.Pop();
         if (behavior == null || behavior.Type == BehaviorType.Null)
         {
             Debug.Log($"[WARN] [HistoryManager] Do() - behavior: {behavior}, behavior.Type: {behavior?.Type}");
             break;
         }
         Debug.Log($"[INFO] [HistoryManager] {(behavior.IsDone ? "ReDo" : "Do")}() - behavior: {behavior}, behavior.Type: {behavior.Type}, behavior.CombineType: {behavior.CombineType}");
         string key = $"{behavior.Type}_{behavior.CreateFrameCount}";
         if (GlobalData.ModifyDic.ContainsKey(key) && GlobalData.ModifyDic[key])
         {
             Debug.Log($"[WARN] [HistoryManager] {(behavior.IsDone ? "ReDo" : "Do")}() - key: {key}, behavior.Type: {behavior.Type}");
         }
         GlobalData.ModifyDic[key] = behavior.IsModify;
         if (behavior.IsModify)
         {
             UlEventSystem.DispatchTrigger <UIEventType>(UIEventType.UpdateTitle);
         }
         if (!justAdd)
         {
             try {
                 behavior.Do(behavior.IsDone);
             } catch (Exception e) {
                 Debug.Log(e);
                 throw;
             }
         }
         behavior.IsDone = true;
         Behaviors.Push(behavior);
         if (behavior.CombineType == CombineType.Next)
         {
             continue;
         }
         if (UnDoneBehaviors.Count == 0)
         {
             break;
         }
         behavior = UnDoneBehaviors.Peek();
         if (behavior == null || behavior.Type == BehaviorType.Null)
         {
             break;
         }
         if (behavior.CombineType == CombineType.Previous)
         {
             continue;
         }
         break;
     }
 }
Пример #4
0
 public static void Undo()
 {
     while (Behaviors.Count > 0)
     {
         Behavior behavior = Behaviors.Pop();
         if (behavior == null || behavior.Type == BehaviorType.Null)
         {
             Debug.Log($"[WARN] [HistoryManager] Undo() - behavior: {behavior}, behavior.Type: {behavior?.Type}");
             break;
         }
         Debug.Log($"[INFO] [HistoryManager] {(behavior.IsUndone ? "ReUndo" : "Undo")}() - behavior: {behavior}, behavior.Type: {behavior.Type}");
         string key = $"{behavior.Type}_{behavior.CreateFrameCount}";
         if (!GlobalData.ModifyDic.ContainsKey(key))
         {
             Debug.Log($"[ERROR] [HistoryManager] {(behavior.IsUndone ? "ReUndo" : "Undo")}() - key: {key}, behavior.Type: {behavior.Type}");
             return;
         }
         behavior.Undo(behavior.IsUndone);
         if (GlobalData.ModifyDic[key])
         {
             UlEventSystem.DispatchTrigger <UIEventType>(UIEventType.UpdateTitle);
         }
         GlobalData.ModifyDic[key] = false;
         behavior.IsUndone         = true;
         UnDoneBehaviors.Push(behavior);
         if (behavior.CombineType == CombineType.Previous)
         {
             continue;
         }
         if (Behaviors.Count == 0)
         {
             break;
         }
         behavior = Behaviors.Peek();
         if (behavior == null || behavior.Type == BehaviorType.Null)
         {
             break;
         }
         if (behavior.CombineType == CombineType.Next)
         {
             continue;
         }
         break;
     }
 }
Пример #5
0
    public static void ChangeHeightBehavior(string moduleName, List <string> elementNames, float height, bool isAdd = false)
    {
        if (string.IsNullOrWhiteSpace(moduleName) || !GlobalData.CurrentModule.Equals(moduleName))
        {
            return;
        }
        if (elementNames == null || elementNames.Count == 0)
        {
            return;
        }
        int length = elementNames.Count;

        for (int idx = 0; idx < length; ++idx)
        {
            ChangeHeightBehavior(elementNames[idx], height, isAdd);
        }
        UlEventSystem.DispatchTrigger <UIEventType>(UIEventType.UpdateInspectorInfo);
    }
Пример #6
0
 public static bool RemoveModuleBehavior(string moduleName, string targetModule = null)
 {
     if (string.IsNullOrWhiteSpace(moduleName))
     {
         return(false);
     }
     if (!GlobalData.ModuleDic.ContainsKey(moduleName))
     {
         return(false);
     }
     // 删除时将数据保存起来, 避免还原时没有数据
     GlobalData.CacheModuleDic[moduleName] = GlobalData.ModuleDic[moduleName];
     GlobalData.Modules.Remove(moduleName);
     GlobalData.ModuleDic.Remove(moduleName);
     if (moduleName.Equals(GlobalData.CurrentModule))
     {
         UlEventSystem.Dispatch <DataEventType, ChangeModuleEventData>(DataEventType.ChangeModule, new ChangeModuleEventData(targetModule));
     }
     UlEventSystem.DispatchTrigger <UIEventType>(UIEventType.UpdateInspectorInfo);
     UlEventSystem.DispatchTrigger <UIEventType>(UIEventType.RefreshModuleItem);
     return(true);
 }
Пример #7
0
    public static void UpdateDisplayObjectsPosition(string moduleName, IReadOnlyList <string> elementNames, Vector2 targetPos)
    {
        if (string.IsNullOrWhiteSpace(GlobalData.CurrentModule) || !GlobalData.CurrentModule.Equals(moduleName))
        {
            return;
        }
        if (elementNames == null || elementNames.Count == 0)
        {
            return;
        }
        Transform baseDisplayObject = GlobalData.CurrentDisplayObjectDic[elementNames[0]];

        if (baseDisplayObject == null)
        {
            return;
        }
        RectTransform baseRect = baseDisplayObject.GetComponent <RectTransform>();

        if (baseRect == null)
        {
            return;
        }
        Vector2 offset = targetPos - baseRect.anchoredPosition;

        UpdateElementPosition(baseRect, elementNames[0], targetPos);
        int count = elementNames.Count;

        for (int idx = 1; idx < count; ++idx)
        {
            Transform displayObject = GlobalData.CurrentDisplayObjectDic[elementNames[idx]];
            if (displayObject == null)
            {
                continue;
            }
            RectTransform rt = displayObject.GetComponent <RectTransform>();
            UpdateElementPosition(rt, elementNames[idx], rt.anchoredPosition + offset);
        }
        UlEventSystem.DispatchTrigger <UIEventType>(UIEventType.UpdateInspectorInfo);
    }
Пример #8
0
    public static void MoveDisplayObjectsUpBehavior(string moduleName, List <string> elementNames)
    {
        if (string.IsNullOrWhiteSpace(moduleName) || !moduleName.Equals(GlobalData.CurrentModule))
        {
            return;
        }
        if (elementNames == null || elementNames.Count == 0)
        {
            return;
        }
        List <Transform> displayObjects = GlobalData.CurrentDisplayObjects;
        List <int>       elementIdxList = elementNames.Select(elementName => displayObjects.FindIndex(element => elementName.Equals(element.name)))
                                          .Where(idx => idx != -1)
                                          .ToList();

        if (elementIdxList.Count == 0)
        {
            return;
        }
        List <Element> elements = GlobalData.ModuleDic[moduleName];
        int            count    = elementIdxList.Count;

        elementIdxList.Sort();
        for (int idx = 0; idx < count; ++idx)
        {
            int       elementIdx = elementIdxList[idx];
            Transform tmp        = displayObjects[elementIdx];
            displayObjects[elementIdx]     = displayObjects[elementIdx - 1];
            displayObjects[elementIdx - 1] = tmp;
            Element tmpElement = elements[elementIdx];
            elements[elementIdx]     = elements[elementIdx - 1];
            elements[elementIdx - 1] = tmpElement;
            int siblingIndex = displayObjects[elementIdx].GetSiblingIndex();
            tmp.SetSiblingIndex(siblingIndex);
        }

        UlEventSystem.DispatchTrigger <UIEventType>(UIEventType.UpdateHierarchy);
    }
Пример #9
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);
        }
    }
Пример #10
0
 public static void OpenModule(string moduleName)
 {
     UlEventSystem.Dispatch <DataEventType, ChangeModuleEventData>(DataEventType.ChangeModule, new ChangeModuleEventData(moduleName));
     UlEventSystem.DispatchTrigger <UIEventType>(UIEventType.UpdateInspectorInfo);
     UlEventSystem.DispatchTrigger <UIEventType>(UIEventType.RefreshModuleItem);
 }
Пример #11
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);
        });
    }