public void Draw(GraphicsDevice gd, SpriteBatch sb, Texture2D boxTex, SpriteFont font, Texture2D scrollbarArrowTex)
        {
            UpdateScrollViewerRect();

            ScrollViewer.Draw(gd, sb, boxTex, scrollbarArrowTex);

            var oldViewport = gd.Viewport;

            gd.Viewport = new Viewport(ScrollViewer.Viewport);
            {
                sb.Begin(transformMatrix: ScrollViewer.GetScrollMatrix());

                //sb.Draw(texture: boxTex,
                //    position: Vector2.Zero,
                //    sourceRectangle: null,
                //    color: Color.DarkGray,
                //    rotation: 0,
                //    origin: Vector2.Zero,
                //    scale: new Vector2(Rect.Width, Rect.Height),
                //    effects: SpriteEffects.None,
                //    layerDepth: 0
                //    );

                float offset = 0;

                foreach (var taeSection in AnimTaeSections)
                {
                    var thisGroupRect = new Rectangle(1, (int)offset + 1, ScrollViewer.Viewport.Width - 2, AnimHeight - 2);
                    int border        = BorderThickness;
                    sb.Draw(boxTex, thisGroupRect, Color.White);
                    sb.Draw(boxTex,
                            new Rectangle(
                                thisGroupRect.X + border,
                                thisGroupRect.Y + border,
                                thisGroupRect.Width - border * 2,
                                thisGroupRect.Height - border * 2),
                            Color.Gray);
                    sb.DrawString(font, $"[{taeSection.SectionName}]", new Vector2(4 + AnimHeight, (int)(offset) + (float)Math.Round((AnimHeight / 2f) - (font.LineSpacing / 2f))) + Vector2.One, Color.Black);
                    sb.DrawString(font, $"[{taeSection.SectionName}]", new Vector2(4 + AnimHeight, (int)(offset) + (float)Math.Round((AnimHeight / 2f) - (font.LineSpacing / 2f))) + (Vector2.One * 2), Color.Black);
                    sb.DrawString(font, $"[{taeSection.SectionName}]", new Vector2(4 + AnimHeight, (int)(offset) + (float)Math.Round((AnimHeight / 2f) - (font.LineSpacing / 2f))), Color.White);


                    Rectangle sectionCollapseButton = new Rectangle(
                        (int)(AnimHeight / 4f),
                        (int)(offset + AnimHeight / 4f),
                        (int)(AnimHeight / 2f),
                        (int)(AnimHeight / 2f));

                    sb.Draw(texture: boxTex,
                            position: new Vector2(sectionCollapseButton.X, sectionCollapseButton.Y),
                            sourceRectangle: null,
                            color: Color.White,
                            rotation: 0,
                            origin: Vector2.Zero,
                            scale: new Vector2(sectionCollapseButton.Width, sectionCollapseButton.Height),
                            effects: SpriteEffects.None,
                            layerDepth: 0.01f
                            );

                    var collapseStr = taeSection.Collapsed ? "+" : "-";

                    var collapseStrScale = font.MeasureString(collapseStr);

                    Vector2 collapseStrPoint =
                        new Vector2(AnimHeight / 2, offset + AnimHeight / 2 + 1)
                        - (collapseStrScale / 2);

                    collapseStrPoint = new Vector2((int)collapseStrPoint.X, (int)collapseStrPoint.Y);

                    sb.DrawString(font, collapseStr, collapseStrPoint, Color.Black);

                    offset += AnimHeight; //Section Header

                    if (taeSection.Collapsed)
                    {
                        continue;
                    }

                    float sectionStartOffset = offset;

                    foreach (var anim in taeSection.InfoMap)
                    {
                        string animIDText = (anim.Value.Ref.GetIsModified() ? $"{anim.Value.GetName()}*" : anim.Value.GetName());

                        string animNameText = (anim.Value.Ref.AnimFileName ?? "<null>");

                        if (offset + AnimHeight < ScrollViewer.Scroll.Y || offset > ScrollViewer.Scroll.Y + Rect.Height)
                        {
                            offset += AnimHeight;
                            continue;
                        }

                        if (anim.Value.Ref == MainScreen.SelectedTaeAnim)
                        {
                            var thisAnimRect = new Rectangle(
                                GroupBraceMarginLeft / 2,
                                (int)(sectionStartOffset + anim.Value.VerticalOffset) - 1,
                                ScrollViewer.Viewport.Width - (GroupBraceMarginLeft),
                                AnimHeight + 1);

                            sb.Draw(boxTex, thisAnimRect, new Color(200, 200, 200));

                            sb.Draw(boxTex,
                                    new Rectangle(
                                        thisAnimRect.X + border,
                                        thisAnimRect.Y + border,
                                        thisAnimRect.Width - border * 2,
                                        thisAnimRect.Height - border * 2),
                                    Color.DodgerBlue);
                        }

                        sb.DrawString(font, animIDText, new Vector2(
                                          GroupBraceMarginLeft + 4,
                                          (int)(sectionStartOffset + anim.Value.VerticalOffset + (float)Math.Round((AnimHeight / 2f) - (font.LineSpacing / 2f)))) + (Vector2.One * 1.25f), Color.Black);
                        sb.DrawString(font, animIDText, new Vector2(
                                          GroupBraceMarginLeft + 4,
                                          (int)(sectionStartOffset + anim.Value.VerticalOffset + (float)Math.Round((AnimHeight / 2f) - (font.LineSpacing / 2f)))), Color.White);

                        var animNameTextSize = font.MeasureString(animNameText);

                        sb.DrawString(font, animNameText, new Vector2(
                                          ScrollViewer.Viewport.Width - animNameTextSize.X - GroupBraceMarginLeft - 4,
                                          (int)(sectionStartOffset + anim.Value.VerticalOffset + (float)Math.Round((AnimHeight / 2f) - (font.LineSpacing / 2f)))) + (Vector2.One * 1.25f), Color.Black);
                        sb.DrawString(font, animNameText, new Vector2(
                                          ScrollViewer.Viewport.Width - animNameTextSize.X - GroupBraceMarginLeft - 4,
                                          (int)(sectionStartOffset + anim.Value.VerticalOffset + (float)Math.Round((AnimHeight / 2f) - (font.LineSpacing / 2f)))), Color.PaleGoldenrod);

                        offset += AnimHeight;
                    }

                    //foreach (var group in taeSection.Tae.AnimationGroups)
                    //{
                    //    float startHeight = taeSection.InfoMap[group.FirstID].VerticalOffset + (AnimHeight / 2f) + sectionStartOffset;
                    //    if (startHeight > (ScrollViewer.Scroll.Y + Rect.Height))
                    //        continue;
                    //    float endHeight = taeSection.InfoMap[group.LastID].VerticalOffset + (AnimHeight / 2f) + sectionStartOffset;
                    //    if (endHeight < ScrollViewer.Scroll.Y)
                    //        continue;

                    //    float startX = GroupBraceMarginLeft / 2f;
                    //    float endX = GroupBraceMarginLeft;

                    //    if (startHeight == endHeight)
                    //    {
                    //        sb.Draw(texture: boxTex,
                    //        position: new Vector2(GroupBraceMarginLeft / 2f, startHeight)
                    //          + new Vector2(-GroupBraceThickness / 2f, -GroupBraceThickness / 2f),
                    //        sourceRectangle: null,
                    //        color: Color.White,
                    //        rotation: 0,
                    //        origin: Vector2.Zero,
                    //        scale: new Vector2((GroupBraceMarginLeft / 2f) + (GroupBraceThickness / 2f), GroupBraceThickness),
                    //        effects: SpriteEffects.None,
                    //        layerDepth: 0
                    //        );
                    //    }
                    //    else
                    //    {
                    //        sb.Draw(texture: boxTex,
                    //        position: new Vector2((GroupBraceMarginLeft / 2f), startHeight)
                    //          + new Vector2(-GroupBraceThickness / 2f, -GroupBraceThickness / 2f),
                    //        sourceRectangle: null,
                    //        color: Color.White,
                    //        rotation: 0,
                    //        origin: Vector2.Zero,
                    //        scale: new Vector2(GroupBraceThickness, endHeight - startHeight + GroupBraceThickness),
                    //        effects: SpriteEffects.None,
                    //        layerDepth: 0
                    //        );

                    //        sb.Draw(texture: boxTex,
                    //            position: new Vector2(GroupBraceMarginLeft / 2f, startHeight)
                    //              + new Vector2(-GroupBraceThickness / 2f, -GroupBraceThickness / 2f),
                    //            sourceRectangle: null,
                    //            color: Color.White,
                    //            rotation: 0,
                    //            origin: Vector2.Zero,
                    //            scale: new Vector2((GroupBraceMarginLeft / 2f) + (GroupBraceThickness / 2f), GroupBraceThickness),
                    //            effects: SpriteEffects.None,
                    //            layerDepth: 0
                    //            );

                    //        sb.Draw(texture: boxTex,
                    //            position: new Vector2(GroupBraceMarginLeft / 2f, endHeight)
                    //              + new Vector2(-GroupBraceThickness / 2f, GroupBraceThickness / 2f),
                    //            sourceRectangle: null,
                    //            color: Color.White,
                    //            rotation: 0,
                    //            origin: Vector2.Zero,
                    //            scale: new Vector2((GroupBraceMarginLeft / 2f) + (GroupBraceThickness / 2f), GroupBraceThickness),
                    //            effects: SpriteEffects.None,
                    //            layerDepth: 0
                    //            );
                    //    }


                    //}
                }


                sb.End();
            }
            gd.Viewport = oldViewport;
        }
示例#2
0
        public void Draw(GraphicsDevice gd, SpriteBatch sb, Texture2D boxTex, SpriteFont font, Texture2D scrollbarArrowTex)
        {
            if (MainScreen.Graph == null)
            {
                return;
            }

            UpdateScrollViewerRect();

            if (ScrollViewer.Scroll.Y != StartDrawScroll)
            {
                //UpdateScrollViewerRect();
                ClearStartDrawSkip();
            }


            ScrollViewer.Draw(gd, sb, boxTex, scrollbarArrowTex);

            var oldViewport = gd.Viewport;

            gd.Viewport = new Viewport(ScrollViewer.Viewport.DpiScaled());
            {
                sb.Begin(transformMatrix: ScrollViewer.GetScrollMatrix() * Main.DPIMatrix);
                try
                {
                    //sb.Draw(texture: boxTex,
                    //    position: Vector2.Zero,
                    //    sourceRectangle: null,
                    //    color: Color.DarkGray,
                    //    rotation: 0,
                    //    origin: Vector2.Zero,
                    //    scale: new Vector2(Rect.Width, Rect.Height),
                    //    effects: SpriteEffects.None,
                    //    layerDepth: 0
                    //    );

                    bool  isUsingSavedStart = false;
                    bool  hasFoundStart     = false;
                    float offset            = 0;

                    //if (StartDrawSectionOffset >= 0 &&
                    //    StartDrawSection >= 0 && StartDrawSection < AnimTaeSections.Count &&
                    //    StartDrawAnim >= 0 && StartDrawAnim < AnimTaeSections[StartDrawSection].InfoMap.Count &&
                    //    StartDrawScroll >= 0)
                    //{
                    //    // Commented out because it was buggy and I realized the performance wasn't
                    //    // too bad without this skip drawing system in place
                    //    //isUsingSavedStart = true;
                    //    //offset = StartDrawSectionOffset;
                    //}
                    //else
                    //{
                    //    ClearStartDrawSkip();
                    //}

                    var taeSectionValueList = AnimTaeSections.Values.ToList();

                    for (int taeSectionIndex = (isUsingSavedStart ? StartDrawSection : 0); taeSectionIndex < AnimTaeSections.Count; taeSectionIndex++)
                    {
                        var sectionOffset = offset;
                        var taeSection    = taeSectionValueList[taeSectionIndex];
                        var thisGroupRect = new Rectangle(0, (int)offset + 1, ScrollViewer.Viewport.Width, AnimSectionHeaderHeight - 2);
                        int border        = BorderThickness;
                        sb.Draw(boxTex, thisGroupRect, Main.Colors.GuiColorAnimListAnimSectionHeaderRectOutline);
                        sb.Draw(boxTex,
                                new Rectangle(
                                    thisGroupRect.X + border,
                                    thisGroupRect.Y + border,
                                    thisGroupRect.Width - border * 2,
                                    thisGroupRect.Height - border * 2),
                                Main.Colors.GuiColorAnimListAnimSectionHeaderRectFill);
                        sb.DrawString(font, $"[{taeSection.SectionName}]", new Vector2(22, (int)(offset) + (float)Math.Round((AnimSectionHeaderHeight / 2f) - (font.LineSpacing / 2f))) + Vector2.One
                                      + Main.GlobalTaeEditorFontOffset, Main.Colors.GuiColorAnimListTextShadow);
                        sb.DrawString(font, $"[{taeSection.SectionName}]", new Vector2(22, (int)(offset) + (float)Math.Round((AnimSectionHeaderHeight / 2f) - (font.LineSpacing / 2f))) + (Vector2.One * 2)
                                      + Main.GlobalTaeEditorFontOffset, Main.Colors.GuiColorAnimListTextShadow);
                        sb.DrawString(font, $"[{taeSection.SectionName}]", new Vector2(22, (int)(offset) + (float)Math.Round((AnimSectionHeaderHeight / 2f) - (font.LineSpacing / 2f)))
                                      + Main.GlobalTaeEditorFontOffset, Main.Colors.GuiColorAnimListTextAnimSectionName);


                        Rectangle sectionCollapseButton = new Rectangle(
                            (int)(AnimSectionHeaderHeight / 4f),
                            (int)(offset + AnimSectionHeaderHeight / 4f),
                            (int)(AnimSectionHeaderHeight / 2f),
                            (int)(AnimSectionHeaderHeight / 2f));

                        sb.Draw(texture: boxTex,
                                position: new Vector2(sectionCollapseButton.X, sectionCollapseButton.Y),
                                sourceRectangle: null,
                                color: Main.Colors.GuiColorAnimListCollapsePlusMinusBackground,
                                rotation: 0,
                                origin: Vector2.Zero,
                                scale: new Vector2(sectionCollapseButton.Width, sectionCollapseButton.Height),
                                effects: SpriteEffects.None,
                                layerDepth: 0.01f
                                );

                        var collapseStr = taeSection.Collapsed ? "+" : "-";

                        var collapseStrScale = font.MeasureString(collapseStr);

                        Vector2 collapseStrPoint =
                            new Vector2(AnimSectionHeaderHeight / 2, offset + AnimSectionHeaderHeight / 2 + 1)
                            - (collapseStrScale / 2);

                        collapseStrPoint = new Vector2((int)collapseStrPoint.X, (int)collapseStrPoint.Y);

                        sb.DrawString(font, collapseStr, collapseStrPoint + Main.GlobalTaeEditorFontOffset, Main.Colors.GuiColorAnimListCollapsePlusMinusForeground);

                        offset += AnimSectionHeaderHeight; //Section Header

                        if (taeSection.Collapsed)
                        {
                            continue;
                        }

                        float animsInSectionStartOffset = offset;

                        //if (isUsingSavedStart && taeSectionIndex == StartDrawSection)
                        //    offset += animsInSectionStartOffset;

                        for (int animIndex = 0; animIndex < taeSection.Tae.Animations.Count; animIndex++)
                        {
                            var anim = taeSection.InfoMap[taeSection.Tae.Animations[animIndex]];

                            if (offset + AnimHeight < ScrollViewer.Scroll.Y || offset > ScrollViewer.Scroll.Y + Rect.Height)
                            {
                                offset += AnimHeight;
                                if (offset > ScrollViewer.Scroll.Y + Rect.Height)
                                {
                                    break;
                                }
                                else
                                {
                                    continue;
                                }
                            }

                            if (!hasFoundStart)
                            {
                                StartDrawSection             = taeSectionIndex;
                                StartDrawAnim                = animIndex;
                                StartDrawSectionOffset       = sectionOffset;
                                StartDrawAnimOffsetInSection = offset - animsInSectionStartOffset;
                                StartDrawScroll              = ScrollViewer.Scroll.Y;
                                hasFoundStart                = true;
                            }

                            string animIDText = "";

                            float animBlendWeight = 1;

                            if (MainScreen.IsCurrentlyLoadingGraph)
                            {
                                animIDText = "□" + (anim.Ref.GetIsModified() ? $"{anim.GetName()}*" : anim.GetName());
                            }
                            else
                            {
                                var animFileName = MainScreen.Graph.ViewportInteractor.GetFinalAnimFileName(taeSection.Tae, anim.Ref);
                                animIDText = ((animFileName != null && MainScreen.Graph.ViewportInteractor.IsAnimLoaded(animFileName)) ? "■" : "□") +
                                             (anim.Ref.GetIsModified() ? $"{anim.GetName()}*" : anim.GetName());
                                animBlendWeight = animFileName != null?MainScreen.Graph.ViewportInteractor.GetAnimWeight(animFileName) : -1;
                            }

                            var animIDTextSize = font.MeasureString(animIDText);
                            if ((animIDTextSize.X + 8) > DevNameStartX)
                            {
                                DevNameStartX = animIDTextSize.X + 8;
                            }

                            string animNameText = (anim.Ref.AnimFileName ?? "<null>");

                            if (anim.Ref == MainScreen.SelectedTaeAnim)
                            {
                                var thisAnimRect = new Rectangle(
                                    GroupBraceMarginLeft / 2,
                                    (int)(animsInSectionStartOffset + anim.VerticalOffset) - 1,
                                    ScrollViewer.Viewport.Width - (GroupBraceMarginLeft),
                                    AnimHeight + 1);

                                sb.Draw(boxTex, thisAnimRect, Main.Colors.GuiColorAnimListHighlightRectOutline);

                                sb.Draw(boxTex,
                                        new Rectangle(
                                            thisAnimRect.X + border,
                                            thisAnimRect.Y + border,
                                            thisAnimRect.Width - border * 2,
                                            thisAnimRect.Height - border * 2),
                                        Main.Colors.GuiColorAnimListHighlightRectFill);
                            }

                            Color animNameColor = Color.White;

                            if (animBlendWeight >= 0)
                            {
                                animNameColor = Color.Lerp(Main.Colors.GuiColorAnimListTextAnimNameMinBlend,
                                                           Main.Colors.GuiColorAnimListTextAnimNameMaxBlend, MathHelper.Clamp(animBlendWeight, 0, 1));
                            }
                            else if (anim.Ref == MainScreen.SelectedTaeAnim)
                            {
                                animNameColor = Main.Colors.GuiColorAnimListTextAnimNameMaxBlend;
                            }

                            sb.DrawString(font, animIDText, new Vector2(
                                              GroupBraceMarginLeft + 4,
                                              (int)(animsInSectionStartOffset + anim.VerticalOffset + (float)Math.Round((AnimHeight / 2f) - (font.LineSpacing / 2f)))) + (Vector2.One * 1.25f)
                                          + Main.GlobalTaeEditorFontOffset, Main.Colors.GuiColorAnimListTextShadow);
                            sb.DrawString(font, animIDText, new Vector2(
                                              GroupBraceMarginLeft + 4,
                                              (int)(animsInSectionStartOffset + anim.VerticalOffset + (float)Math.Round((AnimHeight / 2f) - (font.LineSpacing / 2f))))
                                          + Main.GlobalTaeEditorFontOffset, anim.IsRedErrorPrefix ? Color.Red : animNameColor);

                            var animNameTextSize = font.MeasureString(animNameText);

                            var devNamePos = new Vector2(
                                DevNameStartX,
                                (int)(animsInSectionStartOffset + anim.VerticalOffset + (float)Math.Round((AnimHeight / 2f) - (font.LineSpacing / 2f))));

                            sb.DrawString(font, animNameText, devNamePos + (Vector2.One * 1.25f)
                                          + Main.GlobalTaeEditorFontOffset, Main.Colors.GuiColorAnimListTextShadow);
                            sb.DrawString(font, animNameText, devNamePos
                                          + Main.GlobalTaeEditorFontOffset, Main.Colors.GuiColorAnimListTextAnimDevName);

                            offset += AnimHeight;
                        }

                        //foreach (var group in taeSection.Tae.AnimationGroups)
                        //{
                        //    float startHeight = taeSection.InfoMap[group.FirstID].VerticalOffset + (AnimHeight / 2f) + sectionStartOffset;
                        //    if (startHeight > (ScrollViewer.Scroll.Y + Rect.Height))
                        //        continue;
                        //    float endHeight = taeSection.InfoMap[group.LastID].VerticalOffset + (AnimHeight / 2f) + sectionStartOffset;
                        //    if (endHeight < ScrollViewer.Scroll.Y)
                        //        continue;

                        //    float startX = GroupBraceMarginLeft / 2f;
                        //    float endX = GroupBraceMarginLeft;

                        //    if (startHeight == endHeight)
                        //    {
                        //        sb.Draw(texture: boxTex,
                        //        position: new Vector2(GroupBraceMarginLeft / 2f, startHeight)
                        //          + new Vector2(-GroupBraceThickness / 2f, -GroupBraceThickness / 2f),
                        //        sourceRectangle: null,
                        //        color: Color.White,
                        //        rotation: 0,
                        //        origin: Vector2.Zero,
                        //        scale: new Vector2((GroupBraceMarginLeft / 2f) + (GroupBraceThickness / 2f), GroupBraceThickness),
                        //        effects: SpriteEffects.None,
                        //        layerDepth: 0
                        //        );
                        //    }
                        //    else
                        //    {
                        //        sb.Draw(texture: boxTex,
                        //        position: new Vector2((GroupBraceMarginLeft / 2f), startHeight)
                        //          + new Vector2(-GroupBraceThickness / 2f, -GroupBraceThickness / 2f),
                        //        sourceRectangle: null,
                        //        color: Color.White,
                        //        rotation: 0,
                        //        origin: Vector2.Zero,
                        //        scale: new Vector2(GroupBraceThickness, endHeight - startHeight + GroupBraceThickness),
                        //        effects: SpriteEffects.None,
                        //        layerDepth: 0
                        //        );

                        //        sb.Draw(texture: boxTex,
                        //            position: new Vector2(GroupBraceMarginLeft / 2f, startHeight)
                        //              + new Vector2(-GroupBraceThickness / 2f, -GroupBraceThickness / 2f),
                        //            sourceRectangle: null,
                        //            color: Color.White,
                        //            rotation: 0,
                        //            origin: Vector2.Zero,
                        //            scale: new Vector2((GroupBraceMarginLeft / 2f) + (GroupBraceThickness / 2f), GroupBraceThickness),
                        //            effects: SpriteEffects.None,
                        //            layerDepth: 0
                        //            );

                        //        sb.Draw(texture: boxTex,
                        //            position: new Vector2(GroupBraceMarginLeft / 2f, endHeight)
                        //              + new Vector2(-GroupBraceThickness / 2f, GroupBraceThickness / 2f),
                        //            sourceRectangle: null,
                        //            color: Color.White,
                        //            rotation: 0,
                        //            origin: Vector2.Zero,
                        //            scale: new Vector2((GroupBraceMarginLeft / 2f) + (GroupBraceThickness / 2f), GroupBraceThickness),
                        //            effects: SpriteEffects.None,
                        //            layerDepth: 0
                        //            );
                        //    }


                        //}
                    }
                }
                finally { sb.End(); }
            }
            gd.Viewport = oldViewport;
        }