private void Print(FluentNode node, TreeItemState treeItemState, bool isRoot = false)
    {
        if (node.HasChildren)
        {
            if (isRoot)
            {
                EditorGUILayout.BeginHorizontal();
                treeItemState.Expanded = EditorGUILayout.Foldout(treeItemState.Expanded, "Root", headerStyle) || pinAlwaysOpen;
                newPinAlwaysOpen       = EditorGUILayout.Toggle(pinAlwaysOpen);
                if (pinAlwaysOpen != newPinAlwaysOpen)
                {
                    pinAlwaysOpen = newPinAlwaysOpen;
                }
                EditorGUILayout.EndHorizontal();
            }
            else
            {
                bool newExpandedState = EditorGUILayout.Foldout(treeItemState.Expanded, node.StringInEditor(), headerStyle) || pinAlwaysOpen;

                if (!newExpandedState)
                {
                    pinAlwaysOpen = false;
                }

                if (treeItemState.Expanded != newExpandedState)
                {
                    treeItemState.Expanded = newExpandedState;
                }
            }

            if (!treeItemState.Expanded)
            {
                return;
            }

            // Make sure the TreeItemState has enough children
            while (treeItemState.Children.Count < node.Children.Count)
            {
                treeItemState.Children.Add(new TreeItemState());
            }

            // Print all the children
            EditorGUILayout.BeginVertical();
            for (int iChild = 0; iChild < node.Children.Count; iChild++)
            {
                FluentNode    childNode  = node.Children[iChild];
                TreeItemState childState = treeItemState.Children[iChild];
                EditorGUI.indentLevel++;
                Print(childNode, childState);
                EditorGUI.indentLevel--;
            }
            EditorGUILayout.EndVertical();
        }
        else
        {
            EditorGUILayout.LabelField(node.StringInEditor(), richTextStyle);
        }
    }
Beispiel #2
0
        void ITreeItemDataSource.SetState(ITreeItem treeItem, TreeItemState state)
        {
            if (!(treeItem is SimpleTreeItem simpleTreeItem))
            {
                throw new ArgumentException("treeItem");
            }

            simpleTreeItem.State = state;
        }
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        headerStyle           = new GUIStyle(EditorStyles.foldout);
        headerStyle.fontStyle = FontStyle.Bold;
        headerStyle.richText  = true;

        keywordStyle = new GUIStyle(EditorStyles.label);
        keywordStyle.normal.textColor = Color.blue;

        errorStyle = new GUIStyle(EditorStyles.foldout);
        errorStyle.normal.textColor = Color.red;

        richTextStyle          = new GUIStyle(GUI.skin.label);
        richTextStyle.richText = true;

        FluentNode root = null;

        try
        {
            root = ((FluentScript)target).SequentialNode(((FluentScript)target).Create());
        }
        catch (Exception ex)
        {
            DisplayException("There was an exception creating dialogue tree in editor mode",
                             "This is expected if you have runtime dependant code in your FluentScript" + Environment.NewLine + Environment.NewLine,
                             ex);
            return;
        }

        // Print the tree
        try
        {
            if (rootTreeItemState == null || lastFluentScript != target)
            {
                rootTreeItemState = new TreeItemState();
                lastFluentScript  = (FluentScript)target;
            }

            Print(root, rootTreeItemState, true);
        }
        catch (Exception ex)
        {
            DisplayException("There was an exception trying to show you the tree, please report this", "", ex);
        }
    }
        void BuildTree(XmlElement parent, SPWeb web, int level)
        {
            TreeItemState state = TreeItemState.Unselected;

            if (web.ID == this.currentWeb.ID)
            {
                state = TreeItemState.Selected;

                this.theTreeControl.ExpandParentNodes(parent);
            }

            bool isExpanded = level < this.ExpandLevels;

            string iconUrl = "/_layouts/15/images/STSICON.GIF";

            try
            {
                string iconFile = web.Properties["treeicon"];
                if (iconFile != null && iconFile != "")
                {
                    iconUrl = iconFile;
                }
            }
            catch {}
            string title = web.Title;

            if (this.ShowDescription && !string.IsNullOrEmpty(web.Description))
            {
                title += " - " + web.Description;
            }
            XmlElement current = this.theTreeControl.AddNode(ref parent, title, web.Description, web.ID.ToString(),
                                                             iconUrl, isExpanded, state, SPEncode.HtmlEncode(web.Url), "", "", "SNT_GetChildren('" + web.ID.ToString("D") + "','" + theTreeControl.ValidScriptClientID + "');");

            if (this.theTreeControl.IsNodeOpen(ref current))
            {
                foreach (SPWeb sub in web.GetSubwebsForCurrentUser())
                {
                    BuildTree(current, sub, level + 1);
                }
            }
            else if (web.GetSubwebsForCurrentUser().Count > 0)
            {
                this.theTreeControl.AddDummyNode(ref current);
            }
        }
        internal virtual void OnStateChanged(TreeItemState lastState)
        {
            // We want all expanded beatmap tree items to be initialized here to ensure correct fading behavior. This does not imply any significant performance disadvantage.
            if (!IsLoaded && Expanded)
            {
                Load(false);
            }

            if (lastState <= TreeItemState.Hidden)
            {
                // Move to the correct position before fading in
                if (!IsGroupLeader && GroupLeader != null)
                {
                    Position = GroupLeader.Position;
                }
            }
            // We don't need hidden panels to be loaded due to memory concerns. Loading them when they appear is trivial and happens automatically.
            else if (state <= TreeItemState.Hidden)
            {
                Unload();
            }
        }
        internal override void UpdateSprites(TreeItemState lastState, bool instant)
        {
            //handle hiding
            if (state <= TreeItemState.Hidden)
            {
                if (backgroundSprite.Alpha != 0)
                {
                    SpriteCollection.ForEach(p => p.FadeOut(instant ? 0 : 200));
                }

                return;
            }

            //from this point onwards we are confident this item is being displayed.
            if (lastState <= TreeItemState.Hidden)
            {
                for (int i = 0; i < SpriteCollection.Count; i++)
                {
                    SpriteCollection[i].FadeIn(instant ? 0 : 200);
                }
            }

            UpdateColours(instant);
        }
        internal virtual void UpdateSprites(TreeItemState lastState, bool instant)
        {
            //handle hiding
            if (state <= TreeItemState.Hidden)
            {
                if (SpriteCollection[0].Alpha != 0)
                {
                    SpriteCollection.ForEach(p => p.FadeOut(instant ? 0 : 200));
                }
            }
            else if (lastState <= TreeItemState.Hidden)
            {
                int showCount = state >= TreeItemState.ExtrasVisible ? SpriteCollection.Count : AlwaysVisibleSprites;
                for (int i = 0; i < showCount; i++)
                {
                    SpriteCollection[i].FadeInFromZero(instant ? 0 : 200);
                }
            }

            UpdateHorizontalLayout();

            //handle stars
            if ((state >= TreeItemState.ExtrasVisible && lastState < TreeItemState.ExtrasVisible) || (state < TreeItemState.ExtrasVisible && lastState >= TreeItemState.ExtrasVisible))
            {
                float yPadding     = OldLayout ? -3 : 0;
                float thumbPadding = shouldShowThumbnail ? 75 : 5;

                if (state >= TreeItemState.ExtrasVisible)
                {
                    starSpritesBeginIndex      = SpriteCollection.Count;
                    blackStarSpritesBeginIndex = blackSprites.Count;

                    Color backgroundStarColour = new Color(255, 255, 255, 30);
                    for (int i = 0; i < AMOUNT_STARS; ++i)
                    {
                        pSprite star = new pSprite(s_star, Fields.TopLeft, Origins.Centre, Clocks.Game, Vector2.Zero, textTitle.Depth, true, backgroundStarColour, Beatmap)
                        {
                            VectorScale = new Vector2(star_scale, star_scale),
                            Tag         = new Vector2(leftPadding + thumbPadding + (i + 0.5f) * (s_star.DisplayWidth * 0.625f) * star_scale, yPadding + 18),
                            Additive    = true,
                            Alpha       = 0
                        };

                        if (!OldLayout)
                        {
                            star.Scale = 0.35f;
                        }

                        SpriteCollection.Add(star);
                    }

                    for (int i = 0; i < AMOUNT_STARS; ++i)
                    {
                        pSprite star = new pSprite(s_star, Fields.TopLeft, Origins.Centre, Clocks.Game, Vector2.Zero, textTitle.Depth + DEPTH_INCREASE_STEP, true, Color.White, Beatmap)
                        {
                            VectorScale = new Vector2(star_scale, star_scale),
                            Tag         = new Vector2(leftPadding + thumbPadding + (i + 0.5f) * (s_star.DisplayWidth * 0.625f) * star_scale, yPadding + 18),
                        };

                        if (OldLayout)
                        {
                            star.DrawWidth = -(int)(star.Width * i);
                        }
                        else
                        {
                            star.Scale = 0;
                        }

                        SpriteCollection.Add(star);
                        blackSprites.Add(star);
                    }

                    for (int i = 0; i < SpriteCollection.Count; i++)
                    {
                        pSprite p = SpriteCollection[i] as pSprite;

                        if (i >= AlwaysVisibleSprites && (i < starSpritesBeginIndex || i >= starSpritesBeginIndex + AMOUNT_STARS))
                        {
                            // We don't want our background sprites to fade in yet
                            p.FadeIn(instant ? 0 : 300);
                        }
                    }

                    UpdateStarDifficultyDisplay(instant);
                }
                else
                {
                    for (int i = 0; i < SpriteCollection.Count; i++)
                    {
                        pSprite p = SpriteCollection[i] as pSprite;
                        if (i >= AlwaysVisibleSprites)
                        {
                            p.FadeOut(instant ? 0 : 300);
                        }
                    }

                    int starSpritesEndIndex = starSpritesBeginIndex + AMOUNT_STARS * 2;
                    for (int i = starSpritesBeginIndex; i < starSpritesEndIndex; ++i)
                    {
                        SpriteCollection[i].AlwaysDraw = false;
                    }

                    SpriteCollection.RemoveRange(starSpritesBeginIndex, AMOUNT_STARS * 2);
                    blackSprites.RemoveRange(blackStarSpritesBeginIndex, AMOUNT_STARS);

                    currentlyVisibleStars = -1;
                }
            }

            //handle expanded state changes.
            if ((state >= TreeItemState.Expanded && lastState < TreeItemState.Expanded) || (state < TreeItemState.Expanded && lastState >= TreeItemState.Expanded))
            {
                if (state >= TreeItemState.Expanded)
                {
                    if (thumbnail != null)
                    {
                        thumbnail.Additive = false;
                        thumbnail.FadeInFromZero(instant ? 0 : 1000);
                        thumbnail.TimeBeforeLoad = 100;
                        thumbnail.FadeColour(new Color(255, 255, 255, 255), instant ? 0 : 300);
                    }
                }
                else
                {
                    if (thumbnail != null)
                    {
                        thumbnail.Additive       = true;
                        thumbnail.TimeBeforeLoad = 500;
                        thumbnail.FadeColour(new Color(50, 50, 50, 255), instant ? 0 : 300);
                    }
                }

                UpdateHorizontalLayout();
            }

            UpdateUnselectedColour(instant ? 0 : 300);

            //handle active state changes.
            if (state == TreeItemState.Active)
            {
                blackSprites.ForEach(t => { t.InitialColour = BeatmapTreeItem.colourTextActive; });
            }
            else
            {
                blackSprites.ForEach(t =>
                {
                    Color c;
                    if (state <= TreeItemState.ExtrasVisible)
                    {
                        c = colourTextInactive;
                    }
                    else
                    {
                        if (t == textArtist || t == textTitle)
                        {
                            c = colourTextInactiveFaded;
                        }
                        else
                        {
                            c = colourTextInactive;
                        }
                    }

                    t.InitialColour = c;
                });
            }
        }
 internal override void OnStateChanged(TreeItemState lastState)
 {
 }
Beispiel #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Parent">The Parent Element this item will be added under. Send null to create a new root item.</param>
        /// <param name="Title">the title that will be displayed</param>
        /// <param name="ToolTip">the tool tip for the item</param>
        /// <param name="ID">for future use by the provider</param>
        /// <param name="IconUrl">The icon for the item will be displayed between the +- mark and the title</param>
        /// <param name="IsExpanded">True will show the item opened and all child items will be shown as well</param>
        /// <param name="State">TreeItemState will decide the css style for the item</param>
        /// <param name="OnClick">hadle click on the item</param>
        /// <param name="OnContextMenu">handle right click and click not on text (like WSS menu)</param>
        /// <returns>The new item that was created. for use to add children.</returns>
        public XmlElement AddNode(ref XmlElement elmParent, string Title, string ToolTip, string ID, string IconUrl
                                  , bool IsExpanded, TreeItemState State, string OnClick, string OnContextMenu, string OnLoadChildren)
        {
            this.EnsureChildControls();

            //default expanded state is saved by view state.
            IsExpanded = IsExpanded || (hdnOpenTreeNodes.Text.IndexOf(";" + ID + ";") >= 0);

            //Do we have a parent? if not - create.
            if (elmParent == null)
            {
                if (treeXml == null)
                {
                    treeXml = new XmlDocument();
                    treeXml.LoadXml(TreeXML_Root_TreeRoot);
                }

                elmParent = treeXml.FirstChild as XmlElement;
            }

            if (elmParent.GetAttribute(TreeXML_Attribue_Locked) == bool.TrueString.ToLower())
            {
                throw new Exception(Exception_Message_CannotEditLockedElm);
            }

            //create new tree item under parent
            XmlElement treeItem = elmParent.OwnerDocument.CreateElement(TreeXML_Elm_TreeItem);

            elmParent.AppendChild(treeItem);

            //fill new tree item with data.
            treeItem.SetAttribute(TreeXML_Attribue_Title, Title.Replace("\"", "''"));
            treeItem.SetAttribute(TreeXML_Attribue_Description, ToolTip.Replace("\"", "''"));
            treeItem.SetAttribute(TreeXML_Attribue_ID, ID);
            treeItem.SetAttribute(TreeXML_Attribue_Icon, IconUrl);

            treeItem.SetAttribute(TreeXML_Attribue_OnLoadChildren, OnLoadChildren);

            //overloads - empty is default
            treeItem.SetAttribute(TreeXML_Attribue_IsExpanded, IsExpanded.ToString().ToLower());
            treeItem.SetAttribute(TreeXML_Attribue_OnClick, OnClick);
            treeItem.SetAttribute(TreeXML_Attribue_OnContextMenu, OnContextMenu);

            switch (State)
            {
            case TreeItemState.Selected:
                treeItem.SetAttribute(TreeXML_Attribue_CSSClassName, ItemStyles.SelectedCssName);
                break;

            case TreeItemState.Unselected:
                treeItem.SetAttribute(TreeXML_Attribue_CSSClassName, ItemStyles.UnSelectedCssName);
                break;

            case TreeItemState.Disabled:
                treeItem.SetAttribute(TreeXML_Attribue_CSSClassName, ItemStyles.DisabledCssName);
                break;
            }

            treeItem.SetAttribute(TreeXML_Attribue_State, State.ToString());

            return(treeItem);
        }
Beispiel #10
0
 public XmlElement AddNode(ref XmlElement elmParent, string Title, string ToolTip, string ID, string IconUrl
                           , bool IsExpanded, TreeItemState State, string OnClick, string OnLoadChildren)
 {
     return(AddNode(ref elmParent, Title, ToolTip, ID, IconUrl, IsExpanded, State, OnClick, "", OnLoadChildren));
 }