Exemplo n.º 1
0
        ///<summary>
        ///</summary>
        ///<param name="adapter"></param>
        ///<returns></returns>
        public static List <ChildGroupDescriptor> GetChildGroupsReferences(GroupAdapter adapter)
        {
            Type adapterType   = adapter.GetType();
            Type componentType = adapter.ComponentType;
            List <ChildGroupDescriptor> descriptors = new List <ChildGroupDescriptor>();

            foreach (MemberInfo memberInfo in adapterType.GetMembers())
            {
                var attributes = Core.Reflection.CoreReflector.GetMemberAttributes <ChildCollectionAttribute>(memberInfo);

                if (null != attributes && attributes.Count > 0)
                {
                    ChildCollectionAttribute attribute = attributes[0];
                    MemberInfo mi = null;
                    if (!string.IsNullOrEmpty(attribute.TargetContainer))
                    {
                        MemberInfo[] list = componentType.GetMember(attribute.TargetContainer);
                        if (list.Length > 0)
                        {
                            mi = list[0];
                        }
                    }

                    ChildGroupDescriptor descriptor = new ChildGroupDescriptor
                    {
                        Attribute                 = attribute,
                        CollectionMemberInfo      = memberInfo,
                        TargetContainerMemberInfo = mi
                    };
                    descriptors.Insert(0, descriptor);
                }
            }

            return(descriptors);
        }
Exemplo n.º 2
0
        protected bool CheckSelection(bool mustBeContainer, bool renderMessage = true)
        {
            if (null == Selection.activeTransform)
            {
                if (renderMessage)
                {
                    GUILayout.Label(GuiContentCache.Instance.NoSelectionContent, StyleCache.Instance.CenteredLabel, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
                }
                return(false);
            }

            Adapter      = GuiLookup.GetAdapter(Selection.activeTransform);
            GroupAdapter = Adapter as GroupAdapter;

            if (null == Adapter)
            {
                if (renderMessage)
                {
                    GUILayout.Label(GuiContentCache.Instance.NotEDrivenComponentContent, StyleCache.Instance.CenteredLabel, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
                }
                return(false);
            }

            if (mustBeContainer && null == GroupAdapter)
            {
                if (renderMessage)
                {
                    GUILayout.Label(GuiContentCache.Instance.NotAContainerContent, StyleCache.Instance.CenteredLabel, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
                }
                return(false);
            }

            return(true);
        }
Exemplo n.º 3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.Main);
            _context = this;

            var toolbar = FindViewById <Toolbar>(Resource.Id.toolbar);

            SetActionBar(toolbar);
            ActionBar.Title = "Messenger";

            StartupHelper.Initialize();

            new MessageStream().Subscribe(callback);

            GetGroups();

            var groupList = FindViewById <ListView>(Resource.Id.groupListView);

            groupList.ItemClick += OnItemClick;

            Adapter = new GroupAdapter(Groups);

            groupList.Adapter = Adapter;
        }
Exemplo n.º 4
0
        protected override void HandleSelectionChange()
        {
            //Debug.Log("HandleSelectionChange");

            /**
             * If not a container, nothing to do here; so return immediatelly
             * */
            if (null == GroupAdapter)
            {
                return;
            }

#if DEBUG
            if (DebugMode)
            {
                Debug.Log(string.Format(@"=========== Order ({0}) =========
{1}============================", GroupAdapter.LayoutOrder.Count, GroupAdapter.DescribeLayoutOrder()));
            }
#endif

            SerializedObject serializedObject = EditorState.SerializedObject;

            if (null == serializedObject)
            {
                return;
            }

            _layout = serializedObject.FindProperty("Layout");

            InitLayout(serializedObject);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Since all of the tree displays use the selection change, I decided to implement it in superclass
        /// </summary>
        internal void ProcessSelectionChange()
        {
            //Debug.Log("ProcessSelectionChange: " + Selection.activeObject);
            if (null == Selection.activeGameObject)
            {
                return;
            }

            GameObject go = Selection.activeGameObject;

            /*if (null == go)
             *  throw new Exception("Couldn't get the selection");*/

            Adapter = go.GetComponent(typeof(ComponentAdapter)) as ComponentAdapter;
            if (null == Adapter)
            {
                /**
                 * Not a GUI component
                 * S hould do cleanup and handle selection (deselect basically)
                 * */
                GroupAdapter = null;
                //HandleSelectionChange();
                return;
            }
            Target       = Adapter;
            GroupAdapter = Target as GroupAdapter;

            HandleSelectionChange();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Scans the supplied parent adapter
        /// Converts ChildGroupPacks to SaveablePacks and saves them to dictionary
        /// These packs are used later (in "Process" method) to apply the changes after the play mode is stopped
        /// </summary>
        /// <param name="parentAdapter"></param>
        /// <param name="pack"></param>
        public void Update(GroupAdapter parentAdapter, ChildGroupPack pack)
        {
            //Debug.Log("Update: " + parentAdapter);
#if DEBUG
            if (DebugMode)
            {
                //Debug.Log(string.Format("Linking {0} -> {1}", parentAdapter, childAdapter));
                Debug.Log(string.Format("ParentChildLinker: Updating {0}", parentAdapter));
            }
#endif
            //Debug.Log("parentAdapter: " + parentAdapter);
            // 1. we have to monitor parentAdapter for later (if not yet monitored)
            if (Application.isPlaying)
            {
                PersistenceManager.Instance.Watch(parentAdapter);
            }

            // 2. if no pack supplied, read it now
            if (null == pack)
            {
                //Debug.Log("ParentChildLinker: Pack not defined. Reading now.");
                pack = ChildGroupPack.Read(parentAdapter);
            }

            // 3. register adapters for later
            pack.RegisterAdapters();

            // 4. get relation object
            var guidPack = pack.ToSaveablePack();

            // 5. cache it (overwrite existing!)
            _changes[guidPack.ParentInstanceId] = guidPack;
        }
Exemplo n.º 7
0
// ReSharper restore UnassignedField.Global
#endif

        internal static void Process(List <Node> removals)
        {
            if (0 == removals.Count)
            {
                return;
            }

#if DEBUG
            if (DebugMode)
            {
                Debug.Log(string.Format("Processing {0} removals.", removals.Count));
            }
#endif
            //Debug.Log(string.Format("Processing {0} removals.", removals.Count));
            // TODO: do removals bottom up! nesting level should be used here

            foreach (Node node in removals)
            {
                //if (null == node.Transform)
                //    continue; // ROOT

                node.RemoveFromHierarchy();

                //Debug.Log("node.ParentTransform: " + node.ParentTransform);
                if (null == node.ParentTransform) //|| /*!*/(adapter is StageAdapter))
                {
                    continue;                     // not a stage, return (if stage, should process)
                }
                // consolidate parent transform

                ComponentAdapter adapter = node.Adapter;

                GroupAdapter parentGroupAdapter = GuiLookup.GetAdapter(node.ParentTransform) as GroupAdapter;
                if (null != parentGroupAdapter)
                {
                    /**
                     * Stop monitoring
                     * */
                    PersistenceManager.Instance.Unwatch(node.AdapterId);

                    //PersistenceManager.Instance.RemoveAdapter(node.AdapterId);

                    /**
                     * Note: if object removed from the hierarchy, the adapter is destroyed
                     * In that case following command doesn nothing (doesn not remove the slot from the parent)
                     * Thus we have the consolidation below (removing null)
                     * */
                    parentGroupAdapter.RemoveChild(adapter);

                    // TODO: consolidate only for top level removals (add parameter)

                    /*parentContainerAdapter.RemoveChild(adapter);*/
                    //parentContainerAdapter.RemoveAllChildren();
                    ChildGroupPack pack = ChildGroupPack.Read(parentGroupAdapter);
                    pack.Consolidate(); // there is a null slot here. We have to re-render children
                    //Debug.Log("*pack: " + pack);
                    parentGroupAdapter.InstantiateChildren(true);
                }
            }
        }
Exemplo n.º 8
0
        public static void Process(List <Node> nodes)
        {
            if (nodes.Count == 0)
            {
                return;
            }

            //Debug.Log(string.Format("Processing {0} top level additions in edit mode.", nodes.Count));

            foreach (Node node in nodes)
            {
                /**
                 * 1. Process transforms
                 * */
                Transform transform = node.Transform;

                if (null == transform)
                {
                    continue; // ROOT
                }
                ComponentAdapter adapter = GuiLookup.GetAdapter(transform);
                bool             isStage = adapter is StageAdapter;

                Transform parentTransform = node.ParentTransform;

                /* This happens when a stage added to root */
                if (null == parentTransform && !isStage)
                {
                    continue; // not a stage, return (if stage, should process)
                }
                GroupAdapter parentAdapter = null;

                if (null != parentTransform)
                {
                    parentAdapter = GuiLookup.GetAdapter(node.ParentTransform) as GroupAdapter;
                }

                /**
                 * 2. Process adapters
                 * */
                if (null != adapter)
                {
                    // this is eDriven.Gui component. process it properly
                    if (null == parentAdapter)
                    {
                        if (!isStage)
                        {
                            const string txt = "eDriven.Gui components could be added to containers only";
                            throw new Exception(txt);
                        }
                    }
                    else
                    {
                        parentAdapter.AddChild(adapter, true);
                        //if (!PrefabUtil.IsCreatedFromPrefab(parentAdapter))
                        ParentChildLinker.Instance.Update(parentAdapter);
                    }
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Finds a gui element in children. If such an element exists, returns it; if not, returns null
        /// </summary>
        /// <typeparam name="T">Type of the adapter to find</typeparam>
        /// <param name="go">Game object on which to do the search</param>
        /// <param name="id">Adapter ID</param>
        /// <returns></returns>
        public static T FindComponent <T>(GameObject go, string id) where T : Component
        {
            ComponentAdapter adapter   = go.GetComponent <ComponentAdapter>();
            Component        component = adapter.Component;

            if (adapter.Id == id && adapter.ComponentType == typeof(T))
            {
                return(component as T);
            }

            GroupAdapter groupAdapter = adapter as GroupAdapter;

            if (null != groupAdapter)
            {
                int count = groupAdapter.transform.childCount;
                for (int i = 0; i < count; i++)
                {
                    Transform childTransform = groupAdapter.transform.GetChild(i);
                    adapter = childTransform.GetComponent <ComponentAdapter>();
                    if (adapter.ComponentType == typeof(T) && null != adapter.Component && adapter.Component.Id == id)
                    {
                        break;
                    }
                }
            }

            return(adapter.Component as T);
        }
Exemplo n.º 10
0
        public static ChildGroupPack Read(GroupAdapter groupAdapter)
        {
#if DEBUG
            if (DebugMode)
            {
                Debug.Log(string.Format(@"Read"));
            }
#endif
            ChildGroupPack childGroupPack = new ChildGroupPack(groupAdapter);

            var groupDescriptors = DesignerReflection.GetChildGroupsReferences(groupAdapter);

            foreach (ChildGroupDescriptor groupDescriptor in groupDescriptors)
            {
                List <ComponentAdapter> adapters = Core.Reflection.CoreReflector.GetMemberValue(groupDescriptor.CollectionMemberInfo, groupAdapter) as List <ComponentAdapter>;

                ChildGroup childGroup = new ChildGroup(adapters)
                {
                    GroupName = groupDescriptor.CollectionMemberInfo.Name
                };
                childGroupPack.Add(childGroup);
            }

#if DEBUG
            if (DebugMode)
            {
                Debug.Log("Read. childGroupPack: " + childGroupPack);
            }
#endif

            return(childGroupPack);
        }
Exemplo n.º 11
0
        private void SelectAdapter_Click(object sender, RoutedEventArgs e)
        {
            NetworkInterface ni = (NetworkInterface)Adapters.SelectedItem;

            if (ni != null)
            {
                Window window;
                if (ni.GetType().ToString() == "NSHG.NetworkInterfaces.Adaptor")
                {
                    Adapter a = (Adapter)ni;
                    window = new AdapterEditor(ref a, this);
                }
                else if (ni.GetType().ToString() == "NSHG.NetworkInterfaces.GroupAdaptor")
                {
                    return;

                    GroupAdapter ga = (GroupAdapter)ni;
                    //GroupAdapterEditor window = new GroupAdapterEditor(ref ga, this);
                }
                else
                {
                    return;
                }
                window.Show();
                window.Focus();
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Finds a gui element in children. If such an element exists, returns it; if not, returns null
        /// </summary>
        /// <param name="go">Game object on which to do the search</param>
        /// <param name="id">Adapter ID</param>
        /// <returns></returns>
        public static Component FindComponent(GameObject go, string id)
        {
            ComponentAdapter adapter   = go.GetComponent <ComponentAdapter>();
            Component        component = adapter.Component;

            if (adapter.Id == id)
            {
                return(component);
            }

            GroupAdapter groupAdapter = adapter as GroupAdapter;

            if (null != groupAdapter)
            {
                int count = groupAdapter.transform.childCount;
                for (int i = 0; i < count; i++)
                {
                    Transform childTransform = groupAdapter.transform.GetChild(i);
                    adapter = childTransform.GetComponent <ComponentAdapter>();
                    if (null != adapter.Component && adapter.Component.Id == id)
                    {
                        break;
                    }
                }
            }

            return(adapter.Component);
        }
Exemplo n.º 13
0
        internal static void Process(List <Node> nodes)
        {
            if (nodes.Count == 0)
            {
                return;
            }

            //Debug.Log(string.Format("Processing {0} top level removals in edit mode.", nodes.Count));

            foreach (Node node in nodes)
            {
                if (null == node.ParentTransform)
                {
                    continue;
                }

                GroupAdapter parentGroupAdapter = GuiLookup.GetAdapter(node.ParentTransform) as GroupAdapter;
                if (null != parentGroupAdapter)
                {
                    /**
                     * Important: the removal could happen when we *move* components outside of the Stage hierarchy
                     * From group's standpoint, these components have been *removed*
                     * However, the adapters are not null, so the consolidation without a prior
                     * removal would do nothing to the parent collection (e.g. the moved adapter
                     * would still be on the list)
                     * */
                    parentGroupAdapter.RemoveChild(node.Adapter);

                    ChildGroupPack pack = ChildGroupPack.Read(parentGroupAdapter);
                    pack.Consolidate(); // there is a null slot here. We have to re-render children
                }
            }
        }
Exemplo n.º 14
0
        public AdapterAnalysis(object target)
        {
            if (null != target)
            {
                ComponentAdapter          = target as ComponentAdapter;
                SkinnableComponentAdapter = target as SkinnableComponentAdapter;
                SkinnableContainerAdapter = target as SkinnableContainerAdapter;
                GroupAdapter = target as GroupAdapter;

                if (null != GroupAdapter)
                {
                    HasAbsoluteLayout = CheckForAbsoluteLayout(GroupAdapter);
                }

                if (null != ComponentAdapter && null != ComponentAdapter.transform && null != ComponentAdapter.transform.parent)
                {
                    ParentGroupAdapter = ComponentAdapter.transform.parent.GetComponent <GroupAdapter>();
                    HasParent          = null != ParentGroupAdapter;
                    if (null != ParentGroupAdapter)
                    {
                        ParentIsStage = ParentGroupAdapter is StageAdapter;
                        //ParentUsesLayoutDescriptor = ParentContainerAdapter.UseLayoutDescriptor;
                        //ParentLayoutDescriptor = ParentContainerAdapter.LayoutDescriptor;
                        ParentLayout = ParentGroupAdapter.Layout;

                        ParentHasAbsoluteLayout = CheckForAbsoluteLayout(ParentGroupAdapter);
                    }
                }
            }
        }
Exemplo n.º 15
0
        public GroupManager(GroupAdapter adapter)
        {
            //Debug.Log("Creating GroupManager");
            _groupAdapter     = adapter;
            _groupDescriptors = DesignerReflection.GetChildGroupsReferences(adapter);

            _pack = ChildGroupPack.Read(adapter);
        }
Exemplo n.º 16
0
        public void ChangeChannel(string channelId)
        {
            if (activeChat != null)
            {
                if (activeChat.Id.Equals(channelId))
                {
                    return;
                }

                activeChat.Hide();
            }

            if (chats.ContainsKey(channelId))
            {
                chats[channelId].Show();
                activeChat = chats[channelId];
            }
            else
            {
                MessagesAdapter adapter = null;
                switch (channelId[0])
                {
                case 'D':
                    adapter = new DirectMessageAdapter(Client.DirectMessages.Find((c) => c.id == channelId), this, Client);
                    break;

                case 'C':
                    adapter = new ChannelAdapter(Client.ChannelLookup[channelId], this, Client);
                    break;

                case 'G':
                    adapter = new GroupAdapter(Client.GroupLookup[channelId], this, Client);
                    break;
                }

                if (adapter != null)
                {
                    activeChat          = new ChatInterface(adapter, this);
                    activeChat.Location = new Point(220, 0);
                    activeChat.Width    = Width - 220;
                    activeChat.Height   = Height;
                    activeChat.Anchor   = AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right | AnchorStyles.Top;
                    chats.Add(channelId, activeChat);
                    Controls.Add(activeChat);
                }
                else if (activeChat != null)
                {
                    activeChat.Show();
                }
            }
        }
Exemplo n.º 17
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View view = inflater.Inflate(Resource.Layout.GroupsFragment, container, false);

            progressBar   = view.FindViewById <ProgressBar>(Resource.Id.progressBar);
            recyclerView  = view.FindViewById <RecyclerView>(Resource.Id.recycler_view);
            groupsAdapter = new GroupAdapter(Context, groupsList);
            recyclerView.SetAdapter(groupsAdapter);
            layoutManager = new LinearLayoutManager(Activity);
            recyclerView.SetLayoutManager(layoutManager);
            swiperefresh          = view.FindViewById <SwipeRefreshLayout>(Resource.Id.swiperefresh);
            swiperefresh.Refresh += (e, s) => RefreshData();
            return(view);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Evaluates saved Adapter IDs to real adapters
        /// Note: DO NOT use useEditorUtility=true because it will grab the old adapter!!!
        /// </summary>
        /// <returns></returns>
        public static ChildGroupPack Apply(SaveablePack saveablePack)
        {
#if DEBUG
            if (DebugMode)
            {
                Debug.Log(@"*** WRITING PACK ***
" + saveablePack);
            }
#endif

            // Note: we have to call the override having the second argument, supplying "true"
            // This is because if this is the adapter existing prior to play mode start, the dictionary points to the "old" adapter (a stale one)
            // this way we are making sure that the system looks for the specified adapter in the scene first, and then uses the dictionary (for the "new" adapters)
            GroupAdapter parentAdapter = ComponentRegistry.Instance.Get(saveablePack.ParentInstanceId, true) as GroupAdapter;

            ChildGroupPack childGroupPack = Read(parentAdapter);

            int index = 0;
            foreach (List <int> childGroupIds in saveablePack.InstanceIds)
            {
                List <ComponentAdapter> adapters = new List <ComponentAdapter>();
                foreach (int adapterId in childGroupIds)
                {
                    ComponentAdapter childAdapter = (ComponentAdapter)ComponentRegistry.Instance.Get(adapterId, true);  // FALSE!!!

                    /*if (null == childAdapter)
                     *  throw new Exception("Cannot find child adapter in dictionary: " + adapterId);*/

                    adapters.Add(childAdapter);
                }

                var actualGroup = childGroupPack.Groups[index];
                actualGroup.Clear();
                actualGroup.AddRange(adapters);

                index++;
            }

#if DEBUG
            if (DebugMode)
            {
                Debug.Log("Apply. childGroupPack: " + childGroupPack);
            }
#endif

            return(childGroupPack);
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Title = "Groups";
            SetActivityContentView(Resource.Layout.Groups, Resource.Id.groups_layout);
            SupportActionBar.SetDisplayHomeAsUpEnabled(false);
            SupportActionBar.SetHomeButtonEnabled(false);
            SetUpProgressDialog(this, "Loading Groups...");

            ViewModel   = (GroupsViewModel)DataContext;
            managerMode = Settings.OrganizerMode;
            ListView    = FindViewById <ListView>(Resource.Id.groupsList);

            GroupAdapter     = new GroupAdapter(this, ViewModel.Groups);
            ListView.Adapter = GroupAdapter;

            #region Events

            ViewModel.Groups.CollectionChanged += (s, e) =>
            {
                GroupAdapter.UpdateListView();
            };

            ViewModel.FinishedFirstLoad += (index) =>
            {
                if (ViewModel.Groups.Count == 0)
                {
                    return;
                }

                Timer timer = new Timer()
                {
                    Interval = 1000
                };
                timer.Elapsed += (s, e) => RunOnUiThread(() => ListView.SetSelection(index));
            };

            ListView.ItemClick += (sender, e) =>
            {
                if (ViewModel.Groups[e.Position] != null)
                {
                    ViewModel.GoToGroupCommand.Execute(ViewModel.Groups[e.Position]);
                }
            };

            #endregion
        }
Exemplo n.º 20
0
        public static void Write(GroupAdapter parentAdapter, ChildGroupPack pack)
        {
            ChildGroupPack currentGroupPack = ChildGroupPack.Read(parentAdapter);

            Debug.Log(string.Format("ParentAdapter: {0}, {1}", parentAdapter,
                                    parentAdapter.GetInstanceID()));

            for (int i = 0; i < currentGroupPack.Groups.Count; i++)
            {
                var currentGroup = currentGroupPack.Groups[i];
                Debug.Log("newGroup.Adapters: " + currentGroup.Adapters.Count);
                currentGroup.Adapters.Clear();
                //Debug.Log("newGroup.Adapters 2: " + newGroup.Adapters.Count);
                currentGroup.Adapters.AddRange(pack.Groups[i].Adapters);
                Debug.Log("newGroup.Adapters 2: " + currentGroup.Adapters.Count);
            }
        }
Exemplo n.º 21
0
        public static ChildGroupRenderingList BuildContentGroups(GroupAdapter groupAdapter)
        {
            //Debug.Log("BuildContentGroups");
            ChildGroupRenderingList childGroupList = new ChildGroupRenderingList();

            var  groupDescriptors = DesignerReflection.GetChildGroupsReferences(groupAdapter);
            bool skipFirst        = false;

            if (groupDescriptors.Count > 0)
            {
                skipFirst = groupDescriptors[0].Attribute.ShowHeader;
            }

            foreach (ChildGroupDescriptor descriptor in groupDescriptors)
            {
                var attr = descriptor.Attribute;

                ChildGroup group;

                if (attr.ShowHeader)
                {
                    Texture iconTexture = null;

                    if (!string.IsNullOrEmpty(attr.Icon))
                    {
                        iconTexture = (Texture)Resources.Load(attr.Icon);
                    }

                    group = new ChildGroup(new GUIContent(attr.Label, iconTexture, attr.Tooltip));
                }
                else
                {
                    group = new ChildGroup();
                }

                List <ComponentAdapter> adapters = Core.Reflection.CoreReflector.GetMemberValue(descriptor.CollectionMemberInfo, groupAdapter) as List <ComponentAdapter>;

                // temp hack
                // ReSharper disable ConvertIfStatementToNullCoalescingExpression
                if (null == adapters)
                // ReSharper restore ConvertIfStatementToNullCoalescingExpression
                {
                    // ReSharper disable AssignNullToNotNullAttribute
                    adapters = new List <ComponentAdapter>(Core.Reflection.CoreReflector.GetMemberValue(descriptor.CollectionMemberInfo, groupAdapter) as ComponentAdapter[]);
                    // ReSharper restore AssignNullToNotNullAttribute
                }

                //Debug.Log("adapters.Count: " + adapters.Count);
                foreach (ComponentAdapter adapter in adapters)
                {
                    //Debug.Log("  -> adapter: " + adapter);
                    if (null != adapter)
                    {
                        var dataObject = new OrderDisplayRow(adapter.ToString(), adapter, new Rect(0, 0, 0, 0))
                        {
                            Color       = (adapter is GroupAdapter) ? Dark : Light,
                            IsContainer = adapter is GroupAdapter
                        };

                        if (skipFirst)
                        {
                            dataObject.YMin = OrderDisplay.ElementHeight;
                        }

                        //Debug.Log("Adding " + dataObject);
                        group.Add(dataObject);
                    }
                }

//                Debug.Log(string.Format(@"***** Group created:
//{0}
//
//", group));
                childGroupList.AddGroup(group);
            }

            //Debug.Log(childGroupList);

            return(childGroupList);
        }
Exemplo n.º 22
0
        public override void Render()
        {
            // mode switch
            EditorGUILayout.BeginHorizontal(StyleCache.Instance.Toolbar);

            _oldEnabled = GUI.enabled;
            GUI.enabled = null != Adapter;

            _clicked = GUILayout.Toggle(!_depthMode, new GUIContent("Order", TextureCache.Instance.OrderSelected), StyleCache.Instance.Toggle, GUILayout.Height(30), GUILayout.ExpandWidth(false));
            if (_clicked && _depthMode)
            {
                _depthMode = false;
            }

            GUI.enabled = _oldEnabled;

            _oldEnabled = GUI.enabled;
            GUI.enabled = false;

            _clicked = GUILayout.Toggle(_depthMode, new GUIContent("Depth", TextureCache.Instance.Depth), StyleCache.Instance.Toggle, GUILayout.Height(30), GUILayout.ExpandWidth(false));
            if (_clicked && !_depthMode)
            {
                _depthMode = true;
            }

            GUI.enabled = _oldEnabled;

            GUILayout.FlexibleSpace();

            // Note: we need to always allow the addition of a Stage
            if (GUILayout.Button(GuiContentCache.Instance.AddChildControlContent, StyleCache.Instance.Toggle, GUILayout.Height(30), GUILayout.ExpandWidth(false)))
            {
                ToolboxDialog.Instance.ShowUtility();
            }

            _oldEnabled = GUI.enabled;
            GUI.enabled = null != GroupAdapter;

            if (GUILayout.Button(GuiContentCache.Instance.RemoveAllChildrenButton, StyleCache.Instance.Button, GUILayout.Height(30)))
            {
                if (EditorUtility.DisplayDialog("Remove all?", "Are you sure you want to remove all children?", "OK", "Cancel"))
                {
                    if (null != GroupAdapter)
                    {
                        //Debug.Log("Removing all children...");
                        GroupAdapter.RemoveAllChildren();
                    }
                }
            }

            GUI.enabled = _oldEnabled;

            EditorGUILayout.EndHorizontal();

            if (null == _list.Data)
            {
                GUILayout.Label(GuiContentCache.Instance.NotAContainerContent, StyleCache.Instance.CenteredLabel, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
                return;
            }

            int count = _list.Data.RenderingItemsCount;

            if (0 == count)
            {
                GUILayout.Label(GuiContentCache.Instance.NoComponentsInTheContainer, StyleCache.Instance.CenteredLabel, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
                return;
            }

            _rect = GUILayoutUtility.GetLastRect();
// ReSharper disable once CompareOfFloatsByEqualityOperator
            if (_rect.width != 1 && _rect != _lastRect)
            {
                _lastRect = _rect;
                //_displayRect = new Rect(Padding, _lastRect.yMax + Padding, Bounds.width - Padding * 2, Bounds.height - _lastRect.yMax);
                _displayRect = new Rect(_lastRect.x + 1, _lastRect.yMax + 1, _lastRect.width - 2, Bounds.height - _lastRect.yMax);
                _list.UpdateLayout(_displayRect.width, _displayRect.height);
            }

            // wrap list inside area because it is not using GUILayout
            GUILayout.BeginArea(_displayRect);
            _list.Render();
            GUILayout.EndArea();
        }
Exemplo n.º 23
0
        private static int[] SearchRecivers(Connection connection)
        {
            var profileAdapter = new ProfileAdapter(connection);

            // Находим друзей
            var friends = profileAdapter.GetFriends<UserExtended>();

            // Находим друзей друзей
            var friendsOfFriends = new List<UserExtended>();

            foreach (var userExtended in friends)
            {
                friendsOfFriends.AddRange(profileAdapter.GetFriends<UserExtended>(userExtended.Id).ToList());

                Console.WriteLine(friendsOfFriends.Count);
            }

            // Складываем всех друзей
            friendsOfFriends.AddRange(friends.ToList());

            var groupAdapter = new GroupAdapter(connection);

            var groups = groupAdapter.GetGroups(connection.UserId);

            var adminGroup = groups.First();

            var members = groupAdapter.GetGroupMembers(adminGroup.Id);

            friendsOfFriends = friendsOfFriends.Where(person => !members.Contains(person.Id)).ToList();

            friendsOfFriends = friendsOfFriends.Where(person => person.Sex == "1").ToList();

            friendsOfFriends = friendsOfFriends.Where(person => person.City == 144).ToList();

            var ids = friendsOfFriends.Select(person => person.Id).ToArray();

            ids = ids.Distinct().ToArray();

            using (var writer = new StreamWriter("ids.txt"))
            {
                foreach (var id in ids)
                {
                    writer.WriteLine(id);
                }
            }

            return ids;
        }
Exemplo n.º 24
0
 private ChildGroupPack(GroupAdapter parentAdapter)
 {
     _parentAdapter = parentAdapter;
 }
Exemplo n.º 25
0
// ReSharper restore UnassignedField.Global
#endif

        /// <summary>
        /// Is processing additions, as well as top level additions
        /// </summary>
        /// <param name="topLevelAdditions">Needed for adding into order</param>
        /// <param name="additions">Needed for child instantiation</param>
        internal static void Process(List <Node> topLevelAdditions, List <Node> additions)
        {
            if (0 == topLevelAdditions.Count && 0 == additions.Count)
            {
                return;
            }

#if DEBUG
            if (DebugMode)
            {
                Debug.Log(string.Format("Processing {0} topLevelAdditions, {1} additions.", topLevelAdditions.Count, additions.Count));
            }
#endif
            foreach (Node node in additions)
            {
                bool isTopLevelAddition = topLevelAdditions.Contains(node);
                bool isPrefab           = PrefabUtility.GetPrefabType(node.Adapter) == PrefabType.PrefabInstance;

                /**
                 * 1. Process transforms
                 * */
                Transform transform = node.Transform;

                if (null == transform)
                {
                    continue; // ROOT
                }
                ComponentAdapter adapter = GuiLookup.GetAdapter(transform);
                bool             isStage = adapter is StageAdapter;

                Transform parentTransform = node.ParentTransform;

                if (null == parentTransform && !isStage)
                {
                    continue; // not a stage, return (if stage, should process)
                }
                GroupAdapter parentAdapter = null;

                if (null != parentTransform)
                {
                    parentAdapter = GuiLookup.GetAdapter(node.ParentTransform) as GroupAdapter;
                }

                /**
                 * 2. Process adapters
                 * */
                if (null != adapter)
                {
                    // this is eDriven.Gui component. process it properly
                    if (null == parentAdapter)
                    {
                        if (!isStage)
                        {
                            const string txt = "eDriven.Gui components could be added to containers only";
                            throw new Exception(txt);
                        }
                    }
                    else
                    {
                        /**
                         * Update parent ordering for top level additions only!
                         * */
                        if (isTopLevelAddition)
                        {
                            //node.Transform.parent = parentTransform;
                            parentAdapter.AddChild(adapter, true); // instantiate and change the parent collection

                            // ReSharper disable once RedundantCheckBeforeAssignment
                            if (adapter.transform.parent != parentTransform) // avoid multiple OnHierarchyChange callbacks
                            {
                                adapter.transform.parent = parentTransform;
                            }

                            //adapter.transform.parent = parentTransform;
                            ParentChildLinker.Instance.Update(parentAdapter);
                        }
                        else
                        {
                            //parentAdapter.DoInstantiate(adapter, true); // instantiate only
                            ChildGroupPack pack = ChildGroupPack.Read(parentAdapter);
                            pack.Consolidate(); // there is a null slot here. We have to re-render children
                            parentAdapter.InstantiateChildren(true);
                        }

                        /**
                         * Instantiate component
                         * */
                        if (!adapter.Instantiated)
                        {
                            adapter.DoInstantiate(true);
                        }

                        /**
                         * By now, the component should be instantiated
                         * */
                        var cmp = adapter.Component;
                        if (null == cmp)
                        {
                            throw new Exception("Component not found on ComponentAdapter: " + adapter);
                        }
                    }
                }

                /**
                 * 3. If adapter stuff went without a problem...
                 * */
                // ReSharper disable once RedundantCheckBeforeAssignment
                if (node.Transform.parent != parentTransform)
                {
                    node.Transform.parent = parentTransform;
                }
            }
        }
Exemplo n.º 26
0
        internal static void Process(List <Node> nodes)
        {
            if (nodes.Count == 0)
            {
                return;
            }

            //Debug.Log(string.Format("Processing {0} moves in edit mode.", nodes.Count));

            foreach (Node node in nodes)
            {
                /**
                 * 1. Process transforms
                 * */
                Transform transform = node.Transform;
                if (null == node.Transform)
                {
                    throw new Exception("Transform is null");
                }

                /*if (null == transform)
                 *  continue; // ROOT*/

                //Debug.Log("node.Transform: " + transform);

                ComponentAdapter adapter = GuiLookup.GetAdapter(transform);
                bool             isStage = adapter is StageAdapter;

                Transform oldParentTransform = node.OldParentTransform;
                Transform newParentTransform = node.ParentTransform;

                /* This happens when a stage moved to root */
                if (null == newParentTransform && !isStage)
                {
                    continue; // not a stage, return (if stage, should process) - only stage could be added to root
                }

                /**
                 * The adapter was moved
                 * It is still placed on the same (moved) transform
                 * We are accessing the old and the new parent adapter via transforms:
                 * 1. old parent transform could be referenced using the node.OldParentTransform
                 * 2. new parent transform could be referenced using the node.ParentTransform
                 * */
                GroupAdapter oldParentAdapter = null != oldParentTransform?
                                                GuiLookup.GetAdapter(oldParentTransform) as GroupAdapter:
                                                null;

                GroupAdapter newParentAdapter = null != newParentTransform?
                                                GuiLookup.GetAdapter(newParentTransform) as GroupAdapter:
                                                null;

                Debug.Log(string.Format("[{0}] -> moving from [{1}] to [{2}]",
                                        adapter,
                                        null == oldParentAdapter ? "-" : oldParentAdapter.ToString(),
                                        null == newParentAdapter ? "-" : newParentAdapter.ToString()
                                        ));

                /**
                 * 2. Sanity check
                 * */
                if (null == newParentAdapter && !isStage)
                {
                    throw new Exception("eDriven.Gui components could be added to containers only");
                }

                /**
                 * 3. Process adapters
                 * */
                if (null != oldParentAdapter)
                {
                    oldParentAdapter.RemoveChild(adapter);
                    ParentChildLinker.Instance.Update(oldParentAdapter);
                }

                if (null != newParentAdapter)
                {
                    newParentAdapter.AddChild(adapter, true);
                    ParentChildLinker.Instance.Update(newParentAdapter);
                }

                /**
                 * 4. Set transform
                 * */
                node.Transform.parent = newParentTransform;
            }
        }
Exemplo n.º 27
0
 public void Update(GroupAdapter parentAdapter)
 {
     Update(parentAdapter, null);
 }
Exemplo n.º 28
0
        private void addItem(object item)
        {
            if (GroupAdapter == null)
            {
                return;
            }

            IGroupHeader correctHeader = GroupAdapter.GenerateHeader(item);

            for (int i = 0; i < _collection.Count; i++)
            {
                if (_collection[i] is IGroupHeader)
                {
                    IGroupHeader header = _collection[i] as IGroupHeader;

                    int comp = correctHeader.CompareTo(header);

                    //if goes inside this header
                    if (comp == 0)
                    {
                        //binary search insert would have to walk to the end of the items anyways, so might as well do linear insert

                        //move to the first item
                        i++;

                        for (; i < _collection.Count; i++)
                        {
                            //if we're at the next header, insert at here
                            if (_collection[i] is IGroupFooter || _collection[i] is IGroupHeader)
                            {
                                _collection.Insert(i, item);
                                return;
                            }

                            //or if the item goes before the item in the list
                            else if (header.CompareInsideHeader(item, _collection[i]) < 0)
                            {
                                _collection.Insert(i, item);
                                return;
                            }

                            //otherwise keep looking through the list
                        }

                        //if it wasn't added, must be at the end of the list
                        _collection.Add(item);
                        return;
                    }

                    //if goes before this header
                    else if (comp < 0)
                    {
                        insert(i, correctHeader, item);
                        return;
                    }
                }
            }

            //item didn't find a matching header, needs a new header
            insert(_collection.Count, correctHeader, item);
            return;
        }
Exemplo n.º 29
0
        public static Router FromXML(XmlNode Parent, Action <string> log = null)
        {
            uint ID = 0;
            Dictionary <MAC, NetworkInterface> NetworkInterfaces = new Dictionary <MAC, NetworkInterface>();
            bool respondToEcho = true;

            foreach (XmlNode n in Parent.ChildNodes)
            {
                switch (n.Name.ToLower())
                {
                case "id":
                    if (!uint.TryParse(n.InnerText, out ID))
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("failed to read ID");
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                    break;

                case "adapter":
                    try
                    {
                        Adapter a = Adapter.FromXML(n);
                        NetworkInterfaces.Add(a.MyMACAddress, a);
                    }
                    catch
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Failed to read adapter");
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                    break;

                case "groupadapter":
                    try
                    {
                        GroupAdapter a = GroupAdapter.FromXML(n);
                        NetworkInterfaces.Add(a.MyMACAddress, a);
                    }
                    catch
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Failed to read groupadapter");
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                    break;

                case "respondtoecho":
                    try
                    {
                        respondToEcho = bool.Parse(n.InnerText);
                    }
                    catch
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Failed to read flag: respondtoecho");
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                    break;
                }
            }
            if (ID == 0)
            {
                throw new Exception("Invalid System XML ID not Specified");
            }

            return(new Router(ID, NetworkInterfaces, RespToEcho: respondToEcho, Log: log));
        }
Exemplo n.º 30
0
// ReSharper restore UnassignedField.Global
#endif

        internal static void Process(List <Node> moves)
        {
#if DEBUG
            if (DebugMode)
            {
                Debug.Log(string.Format("Processing {0} moves.", moves.Count));
            }
#endif

            foreach (Node node in moves)
            {
                /**
                 * 1. Process transforms
                 * */
                Transform transform = node.Transform;

                Transform parentTransform = node.ParentTransform;

                if (null == transform)
                {
                    continue; // ROOT
                }
                //Debug.Log("node.Transform: " + transform);

                ComponentAdapter adapter     = GuiLookup.GetAdapter(transform);
                bool             thisIsStage = adapter is StageAdapter;

                /**
                 * The adapter has been moved
                 * It is still placed on the same (moved) transform
                 * We are accessing the old and the new parent adapter via transforms:
                 * - the old parent transform could be referenced using the node.OldParentTransform
                 * - the new parent transform could be referenced using the node.ParentTransform
                 * */

                if (null == node.Transform)
                {
                    throw new Exception("Transform is null");
                }

                GroupAdapter oldParentAdapter = GuiLookup.GetAdapter(node.OldParentTransform) as GroupAdapter;
                GroupAdapter newParentAdapter = GuiLookup.GetAdapter(node.ParentTransform) as GroupAdapter;

                //Debug.Log(string.Format("  -> moving from [{0}] to [{1}]", oldParentAdapter, newParentAdapter));

                /**
                 * 2. Process adapters
                 * */
                if (null != oldParentAdapter)
                {
                    oldParentAdapter.RemoveChild(adapter);
                    ParentChildLinker.Instance.Update(oldParentAdapter);
                }

                if (null == newParentAdapter)
                {
                    if (!thisIsStage)
                    {
                        const string txt = "eDriven.Gui components could be added to containers only";
                        //Debug.LogWarning(txt);
                        throw new Exception(txt);
                    }
                }
                else
                {
                    newParentAdapter.AddChild(adapter, true);
                    ParentChildLinker.Instance.Update(newParentAdapter);
                }

                /**
                 * 3. If adapter stuff went without a problem...
                 * */
                node.Transform.parent = parentTransform;

                //ComponentAdapter adapter = GuiLookup.GetAdapter(transform);
                //bool thisIsStage = adapter is StageAdapter;

                ////Debug.Log("done.");

                //Transform parentTransform = node.ParentTransform;

                //if (null == parentTransform && !thisIsStage)
                //    continue; // not a stage, return (if stage, should process) - only stage could be added to root

                //ContainerAdapter newParentAdapter = null;

                //if (null != parentTransform)
                //    newParentAdapter = GuiLookup.GetAdapter(parentTransform) as ContainerAdapter;

                //    /**
                //     * 2. Process adapters
                //     * */
                //    if (null != adapter)
                //    {
                //        // this is eDriven.Gui component. process it properly
                //        if (null == newParentAdapter)
                //        {
                //            if (!thisIsStage) {
                //                const string txt = "eDriven.Gui components could be added to containers only";
                //                //Debug.LogWarning(txt);
                //                throw new Exception(txt);
                //                //return;
                //            }
                //        }
                //        else
                //        {
                //            ContainerAdapter oldParentAdapter = node.OldParentTransform.GetComponent<ContainerAdapter>();

                //            //Debug.Log("oldParentAdapter: " + oldParentAdapter);
                //            //Debug.Log("newParentAdapter: " + newParentAdapter);

                //            oldParentAdapter.RemoveChild(adapter);

                //            newParentAdapter.AddChild(adapter, true);

                //            ////if (!PrefabUtil.IsCreatedFromPrefab(oldParentAdapter)) // TODO: Need this?
                //            //    ParentChildLinker.Instance.Update(oldParentAdapter);

                //            ////if (!PrefabUtil.IsCreatedFromPrefab(newParentAdapter)) // TODO: Need this?
                //            //    ParentChildLinker.Instance.Update(newParentAdapter);

                //            if (EditorApplication.isPlaying)
                //            {
                //                if (!adapter.Instantiated)
                //                    adapter.DoInstantiate(true);
                //                //Debug.Log(string.Format("OnHierarchyChange: Component instantiated: {0} [{1}]", adapter.Component, adapter.transform.GetInstanceID()));
                //            }

                //            var cmp = adapter.Component;
                //            if (null == cmp)
                //            {
                //                throw new Exception("Component not found on ComponentAdapter: " + adapter);
                //            }
                //        }
                //    }

                //    /**
                //     * 3. If adapter stuff went without a problem...
                //     * */
                //    node.Transform.parent = parentTransform;
            }
        }
Exemplo n.º 31
0
        /// <summary>
        /// Checks the flags and executes the change received via the slots
        /// (the change that is not healthy to do inside the Render method)
        /// </summary>
        public override void Update()
        {
            if (null != _positionChangedParms)
            {
                //Debug.Log(string.Format("PositionChangedSlot: {0}, {1}", parameters[0], parameters[1]));
                DraggableItem draggableItem = (DraggableItem)_positionChangedParms[0];
                int           newItemIndex  = (int)_positionChangedParms[1];
                int           newGroupIndex = (int)_positionChangedParms[2];

                _positionChangedParms = null;

                ComponentAdapter adapter = (ComponentAdapter)draggableItem.Data;

                // Note: this actually applies changes to collections
                var pack = _groupManager.Reorder(adapter, newGroupIndex, newItemIndex);

                ParentChildLinker.Instance.Update(GroupAdapter, pack);

                //Refresh();

                if (Application.isPlaying)
                {
                    //ParentChildLinker.Instance.Update(ContainerAdapter, pack); // TODO: calling ParentChildLinker from here messes the thing
                    RedrawComponentsInGameView(pack);
                }

                //HierarchyState.Instance.Rebuild();
                EditorState.Instance.HierarchyChange();

                /**
                 * Emit for debugging purposes
                 * */
                CollectionChangedSignal.Emit();
            }

            else if (null != _removedParms)
            {
                //Debug.Log(string.Format("RemovedSlot: {0}", parameters[0]));
                DraggableItem draggableItem = (DraggableItem)_removedParms[0];
                //int groupIndex = (int)_removedParms[1];
                //int itemIndex = (int)_removedParms[2];

                _removedParms = null;

                ComponentAdapter adapter = draggableItem.Data as ComponentAdapter;

                if (null == adapter)
                {
                    return;
                }

                //Debug.Log(string.Format("groupIndex: {0}, itemIndex: {1}", groupIndex, itemIndex));

                /**
                 * 1. Remove the adapter from the collection
                 * */
                var pack = _groupManager.Remove(adapter);

                /**
                 * NOTE: We should not call the linker directly
                 * That is because if we remove adapter from stage, the linker could not find it
                 * We call the EditorState.Instance.HierarchyChange() below, so the
                 * hierarchy change mechanism handles the removal stuff
                 * */
                //ParentChildLinker.Instance.Update(GroupAdapter, pack);

                if (Application.isPlaying)
                {
                    RedrawComponentsInGameView(pack);
                }

                if (adapter.transform.parent != GroupAdapter.transform)
                {
                    return;
                }

                //Refresh();

                /**
                 * 2. Check if the same adapter present in other collections
                 * If not, remove the transform
                 * */
                var group = _groupManager.GetGroupContainingAdapter(adapter);
                //Debug.Log("group: " + group);
                if (null == group)
                {
                    // this adapter is not present in any of the groups
                    // remove the transform now
                    OrderDisplayRow orderDisplayRow = (OrderDisplayRow)draggableItem;

                    Transform    transform    = orderDisplayRow.Adapter.transform;
                    GroupAdapter groupAdapter = transform.parent.GetComponent <GroupAdapter>();
                    groupAdapter.RemoveChild(orderDisplayRow.Adapter);

                    //int instanceId = transform.GetInstanceID();
                    Object.DestroyImmediate(transform.gameObject);
                }

                // apply the change, for not to get the "ArgumentException: Getting control 3's position in a group with only 3 controls when doing Repaint Aborting" error
                Refresh();

                //EditorState.Instance.HierarchyChange();

                /**
                 * Emit for debugging purposes
                 * */
                CollectionChangedSignal.Emit();
            }

            if (null != _depthChangedParms)
            {
                //Debug.Log("OrderDisplay: changing depth");
                // apply the change, for not to get the "ArgumentException: Getting control 3's position in a group with only 3 controls when doing Repaint Aborting" error
                //Refresh();

                _depthChangedParms = null;
            }
        }