protected virtual void DrawComponent(ProvenceComponent component, VisualElement parent, bool removeable = true, bool hide = false)
        {
            Div container = new Div();

            container.AddToClassList("search-list-item");
            container.userData = component.GetType().Name;
            foreach (Type tag in collection[chosenKey].tags)
            {
                if (((MainframeTag)Activator.CreateInstance(tag)).requiredComponents.Contains(component.GetType()))
                {
                    container.userData += tag.Name;
                }
            }
            ListItem     titleItem = new ListItem(false, true);
            ListItemText title     = titleItem.AddTitle(System.Text.RegularExpressions.Regex.Replace(component.GetType().Name, @"((?<=\p{Ll})\p{Lu})|((?!\A)\p{Lu}(?>\p{Ll}))", " $0"));

            titleItem.name = component.GetType().Name.ToLower() + "-control-title";
            titleItem.AddToClassList("structure-control-title", "spacer");

            Div structContainer = (Div)Helpers.InvokeGenericMethod <ProvenceCollectionEditor <U> >(this, "DrawComponentControl", component.GetType(), component);

            titleItem.eventManager.AddListener <MouseClickEvent>(e => {
                switch (e.button)
                {
                case 0:
                    if (title.ClassListContains("second-alternate"))
                    {
                        title.RemoveFromClassList("second-alternate");
                    }
                    else
                    {
                        title.AddToClassList("second-alternate");
                    }
                    structContainer.Toggle();
                    break;

                case 1:
                    if (removeable)
                    {
                        entryEditorComponentContextMenu.Show(root, e, true);

                        ListItem removeButton = entryEditorComponentContextMenu.Q <ListItem>("entry-editor-component-remove-button");
                        removeButton.eventManager.ClearListeners();
                        removeButton.eventManager.AddListener <MouseClickEvent>(ev => {
                            Helpers.InvokeGenericMethod <ProvenceCollectionEditor <U> >(this, "RemoveComponentFromEntry", component.GetType());
                            entryEditorComponentContextMenu.Toggle();
                        });
                    }
                    break;
                }
            });

            if (hide)
            {
                titleItem.eventManager.Raise <MouseClickEvent>(new MouseClickEvent(titleItem, 0, Vector2.zero));
            }

            container.Add(titleItem, structContainer);
            parent.Add(container);
        }
Пример #2
0
        protected override void RegisterEventListeners()
        {
            eventManager.AddListener <SelectKey <EntityHandle> >(SelectKey);
            eventManager.AddListener <SelectKey <ProvenceComponent> >(SelectKey);
            eventManager.AddListener <DrawColumnEventArgs <ProvenceComponent> >(DrawColumn);
            eventManager.AddListener <SceneSavedEvent>(SaveEntity);

            if (root == null)
            {
                return;
            }

            DropDownMenu archetypeMenu = root.Q <DropDownMenu>("archetype-menu");

            root.Q <ListItemText>("select-menu-button").eventManager.AddListener <MouseClickEvent>(e => {
                if (e.button != 0)
                {
                    return;
                }
            });
            root.Q <ListItemText>("archetype-menu-button").eventManager.AddListener <MouseClickEvent>(e => {
                if (e.button != 0)
                {
                    return;
                }
                archetypeMenu.Show(root, e);
            });
            root.Q <ListItem>("add-component-button").eventManager.AddListener <MouseClickEvent>(AddComponentButtonClicked);

            root.Q <ListItemTextInput>("entity-name").eventManager.AddListener <ListItemInputChange>(e => {
                if (chosenKeyNameHandle != null)
                {
                    string newName = ((ListItemTextInput)e.input).text;
                    if (chosenKeyNameHandle.component.name.Equals(newName))
                    {
                        return;
                    }
                    chosenKeyNameHandle.component.name = newName;
                    eventManager.Raise <SetSceneDirtyEvent>(new SetSceneDirtyEvent(SceneManager.GetActiveScene()));
                }
            });

            root.Q <ListItemText>("add-gameobject-button").eventManager.AddListener <MouseClickEvent>(AddGameObject);

            root.Q <ListItemText>("select-gameobject-button").eventManager.AddListener <MouseClickEvent>(e => {
                if (chosenGameObject != null)
                {
                    Selection.objects = new Object[] { chosenGameObject }
                }
                ;
            });

            root.Q <ListItemText>("remove-gameobject-button").eventManager.AddListener <MouseClickEvent>(RemoveGameObject);
        }
Пример #3
0
        protected void DrawComponentListItem(ComponentHandle <ProvenceComponent> handle, DropDownMenu contextMenu, bool alternate)
        {
            ListItem item          = new ListItem(alternate, true);
            string   componentName = System.Text.RegularExpressions.Regex.Replace(handle.component.GetType().Name, @"((?<=\p{Ll})\p{Lu})|((?!\A)\p{Lu}(?>\p{Ll}))", " $0");

            item.AddButton(componentName, false, false, true);

            item.eventManager.AddListener <MouseClickEvent>(e => {
                if (e.element != item)
                {
                    return;
                }
                switch (e.button)
                {
                case 0:
                    if (item.ClassListContains("selected"))
                    {
                        item.RemoveFromClassList("selected");
                    }
                    else
                    {
                        item.AddToClassList("selected");
                    }
                    eventManager.Raise <SelectKey <ProvenceComponent> >(new SelectKey <ProvenceComponent>(handle.component));
                    break;

                case 1:
                    contextMenu.Show(root, e, true);
                    ListItemText removeButton = root.Q <ListItemText>("component-list-context-menu-remove-button");
                    removeButton.eventManager.ClearListeners();
                    removeButton.eventManager.AddListener <MouseClickEvent>(ev => {
                        if (ev.button != 0)
                        {
                            return;
                        }
                        if (chosenComponents.Contains(handle.component))
                        {
                            chosenComponents.Remove(handle.component);
                        }
                        Helpers.InvokeGenericMethod(this, "RemoveComponent", handle.component.GetType());
                        contextMenu.style.display = DisplayStyle.None;
                    });
                    break;
                }
            });

            componentListScroller.Add(item);
        }
        protected virtual void DrawTagList()
        {
            tagListScroller.Clear();
            if (chosenKey != null)
            {
                foreach (System.Type tag in collection[chosenKey].tags)
                {
                    ListItemText tagElement = new ListItemText(tag.Name);
                    tagElement.userData = tag;
                    tagElement.AddToClassList("entry-editor-tag");

                    tagElement.eventManager.AddListener <MouseClickEvent>(e => {
                        switch (e.button)
                        {
                        case 0:
                            ListItemSearchBar compSearchBar = root.Q <ListItemSearchBar>("entry-editor-search-bar");
                            compSearchBar.searchInput.value = compSearchBar.searchInput.value.Replace(" ", "");
                            if (tagElement.ClassListContains("selected"))
                            {
                                tagElement.RemoveFromClassList("selected");
                                compSearchBar.searchInput.value = compSearchBar.searchInput.text.ToLower().Replace(tag.Name.ToLower() + "/", "");
                            }
                            else
                            {
                                tagElement.AddToClassList("selected");
                                if (compSearchBar.searchInput.value == "")
                                {
                                    compSearchBar.searchInput.value = tag.Name.ToLower() + "/";
                                }
                                else
                                {
                                    if (compSearchBar.searchInput.value[compSearchBar.searchInput.value.Length - 1] != '/')
                                    {
                                        compSearchBar.searchInput.value += "/";
                                    }
                                    compSearchBar.searchInput.value += tag.Name.ToLower() + "/";
                                }
                            }
                            break;

                        case 1:
                            entryEditorTagContextMenu.Show(root, e, true);
                            ListItem removeButton = entryEditorTagContextMenu.Q <ListItem>("entry-editor-tag-remove-button");
                            removeButton.eventManager.ClearListeners();
                            removeButton.eventManager.AddListener <MouseClickEvent>(ev => {
                                RemoveTagFromEntry((dynamic)tagElement.userData);
                                entryEditorTagContextMenu.Toggle();
                            });
                            ListItem removeAllButton = entryEditorTagContextMenu.Q <ListItem>("entry-editor-tag-remove-all-button");
                            removeAllButton.eventManager.ClearListeners();
                            removeAllButton.eventManager.AddListener <MouseClickEvent>(ev => {
                                RemoveTagCompleteFromEntry((dynamic)tagElement.userData);
                                entryEditorTagContextMenu.Toggle();
                            });
                            break;
                        }
                    });

                    tagListScroller.Add(tagElement);
                }
            }
        }
        protected virtual void DrawKeyList()
        {
            keyListScroller.Clear();
            bool alternate = false;

            collection.Sort();
            foreach (string key in collection.Keys)
            {
                ListItem item = new ListItem(alternate, true, true);
                item.userData = key;
                item.AddIndent(true);

                ListItemImage icon = item.AddImage(keyIcon);
                icon.AddToClassList("icon");
                ListItemTextInput nameInput = item.AddTextField(key);
                nameInput.AddToClassList("key-list-name-input");
                ListItemText nameDisplay = item.AddTextDisplay(key);

                if (chosenKey == key)
                {
                    item.AddToClassList("selected");
                    item.Q <ListItemImage>().SetImage(selectedKeyIcon);
                }

                item.eventManager.AddListener <MouseClickEvent>(e => {
                    switch (e.button)
                    {
                    case 0:
                        if (!item.ClassListContains("selected"))
                        {
                            ListItem selected = keyListScroller.Q <ListItem>(null, "selected");
                            if (selected != null)
                            {
                                selected.RemoveFromClassList("selected");
                                selected.Q <ListItemImage>().SetImage(keyIcon);
                            }
                            item.AddToClassList("selected");
                            icon.SetImage(selectedKeyIcon);

                            eventManager.Raise <SelectKey <string> >(new SelectKey <string>(key));
                        }
                        break;

                    case 1:
                        keyListContextMenu.Show(root, e, true);
                        ListItem editButton = keyListContextMenu.Q <ListItem>("key-list-context-menu-edit-button");
                        editButton.eventManager.ClearListeners();
                        editButton.eventManager.AddListener <MouseClickEvent>(ev => {
                            if (ev.button != 0)
                            {
                                return;
                            }
                            nameInput.style.display          = DisplayStyle.Flex;
                            nameDisplay.style.display        = DisplayStyle.None;
                            keyListContextMenu.style.display = DisplayStyle.None;
                        });

                        ListItem removeButton = keyListContextMenu.Q <ListItem>("key-list-context-menu-remove-button");
                        removeButton.eventManager.ClearListeners();
                        removeButton.eventManager.AddListener <MouseClickEvent>(ev => {
                            if (ev.button != 0)
                            {
                                return;
                            }
                            RemoveManualEntry(key);
                            keyListContextMenu.style.display = DisplayStyle.None;
                        });
                        break;
                    }
                });

                nameInput.eventManager.AddListener <ListItemInputCommit>(e => {
                    EditManualEntryKey(key, nameInput.value);
                });

                nameInput.eventManager.AddListener <ListItemInputCancel>(e => {
                    nameInput.value           = key;
                    nameInput.style.display   = DisplayStyle.None;
                    nameDisplay.style.display = DisplayStyle.Flex;
                });

                keyListScroller.Add(item);
                alternate = !alternate;
            }
            //Scroll to selected if exists
        }
Пример #6
0
        protected void DrawSystemList()
        {
            ColumnScroller scroller = root.Q <ColumnScroller>("world-editor-system-scroller");

            scroller.Clear();
            bool         alternate   = false;
            DropDownMenu contextMenu = root.Q <DropDownMenu>("system-list-context-menu");

            foreach (string package in chosenKey.systemManager.systemPackages)
            {
                ListItem item = new ListItem(alternate, true, true);
                item.AddIndent();
                item.AddImage(packageIcon).AddToClassList("icon");
                item.AddTextDisplay(package);
                scroller.Add(item);

                item.eventManager.AddListener <MouseClickEvent>(e => {
                    switch (e.button)
                    {
                    case 0:
                        ListItem selected = scroller.Q <ListItem>(null, "selected");
                        if (selected != null)
                        {
                            selected.RemoveFromClassList("selected");
                        }
                        item.AddToClassList("selected");
                        break;

                    case 1:
                        contextMenu.Show(root, e, true);
                        ListItemText removeButton = root.Q <ListItemText>("system-list-context-menu-remove-button");
                        removeButton.eventManager.ClearListeners();
                        removeButton.eventManager.AddListener <MouseClickEvent>(ev => {
                            if (ev.button != 0)
                            {
                                return;
                            }
                            chosenKey.systemManager.systemPackages.Remove(package);
                            eventManager.Raise <SetSceneDirtyEvent>(new SetSceneDirtyEvent(EditorSceneManager.GetActiveScene()));
                            eventManager.Raise <DrawColumnEventArgs <World> >(new DrawColumnEventArgs <World>(1));
                        });
                        break;
                    }
                });

                alternate = !alternate;
            }

            foreach (System.Type systemType in chosenKey.systemManager.GetCurrentSystemTypes())
            {
                ListItem item = new ListItem(alternate, true, true);
                item.AddIndent();
                item.AddImage(systemIcon).AddToClassList("icon");
                item.AddTextDisplay(Regex.Replace(systemType.Name, @"((?<=\p{Ll})\p{Lu})|((?!\A)\p{Lu}(?>\p{Ll}))", " $0"));

                item.eventManager.AddListener <MouseClickEvent>(e => {
                    switch (e.button)
                    {
                    case 0:
                        if (item.ClassListContains("selected"))
                        {
                            Helpers.InvokeGenericMethod(this, "OpenSystemEditor", systemType);
                        }
                        else
                        {
                            ListItem selected = scroller.Q <ListItem>(null, "selected");
                            if (selected != null)
                            {
                                selected.RemoveFromClassList("selected");
                            }
                            item.AddToClassList("selected");
                        }
                        break;

                    case 1:
                        contextMenu.Show(root, e, true);
                        ListItemText removeButton = root.Q <ListItemText>("system-list-context-menu-remove-button");
                        removeButton.eventManager.ClearListeners();
                        removeButton.eventManager.AddListener <MouseClickEvent>(ev => {
                            if (ev.button != 0)
                            {
                                return;
                            }
                            Helpers.InvokeGenericMethod(this, "RemoveSystem", systemType);
                            contextMenu.style.display = DisplayStyle.None;
                        });
                        break;
                    }
                });

                scroller.Add(item);
                alternate = !alternate;
            }
        }
Пример #7
0
        protected void DrawEntityList()
        {
            ColumnScroller scroller = root.Q <ColumnScroller>("world-editor-entity-scroller");

            scroller.Clear();
            bool         alternate   = false;
            DropDownMenu contextMenu = root.Q <DropDownMenu>("entity-list-context-menu");

            foreach (EntityHandle entityHandle in chosenKey.LookUpAllEntities())
            {
                ListItem item = new ListItem(alternate, true, true);
                item.AddIndent();
                item.AddImage(entityIcon).AddToClassList("icon");

                ComponentHandle <Name> nameHandle = entityHandle.GetComponent <Name>();
                if (nameHandle != null)
                {
                    item.AddTextDisplay(nameHandle.component.name);
                }
                else
                {
                    item.AddTextDisplay(entityHandle.entity.ToString());
                }

                item.eventManager.AddListener <MouseClickEvent>(e => {
                    switch (e.button)
                    {
                    case 0:
                        ComponentHandle <UnityGameObject> objectHandle = entityHandle.GetComponent <UnityGameObject>();
                        GameObject entityGO = objectHandle != null ? objectHandle.component.gameObject : null;
                        if (entityGO != null)
                        {
                            Selection.objects = new Object[] { entityGO };
                        }
                        if (item.ClassListContains("selected"))
                        {
                            EntityEditor.Show(entityHandle);
                        }
                        else
                        {
                            ListItem selected = scroller.Q <ListItem>(null, "selected");
                            if (selected != null)
                            {
                                selected.RemoveFromClassList("selected");
                            }
                            item.AddToClassList("selected");
                        }
                        break;

                    case 1:
                        contextMenu.Show(root, e, true);
                        ListItemText duplicateButton = root.Q <ListItemText>("entity-list-context-menu-duplicate-button");
                        duplicateButton.eventManager.ClearListeners();
                        duplicateButton.eventManager.AddListener <MouseClickEvent>(ev => {
                            if (ev.button != 0)
                            {
                                return;
                            }
                            DuplicateEntity(entityHandle);
                            contextMenu.style.display = DisplayStyle.None;
                        });

                        ListItemText removeButton = root.Q <ListItemText>("entity-list-context-menu-remove-button");
                        removeButton.eventManager.ClearListeners();
                        removeButton.eventManager.AddListener <MouseClickEvent>(ev => {
                            if (ev.button != 0)
                            {
                                return;
                            }
                            RemoveEntity(entityHandle);
                            contextMenu.style.display = DisplayStyle.None;
                        });
                        break;
                    }
                });

                scroller.Add(item);
                alternate = !alternate;
            }
        }