Beispiel #1
0
        private void DrawDisplayIcons(MonitorDisplay display, List <DisplayTimer> timerList)
        {
            if (display.DirectionBtT)
            {
                ImGui.SetCursorPosY(ImGui.GetWindowHeight() - (display.RowSize + ImGui.GetStyle().WindowPadding.Y));
            }

            if (display.DirectionRtL)
            {
                ImGui.SetCursorPosX(ImGui.GetWindowWidth() - (display.RowSize + ImGui.GetStyle().WindowPadding.X));
            }

            var sPosX = ImGui.GetCursorPosX();
            var sPosY = ImGui.GetCursorPosY();

            ImGui.SetWindowFontScale(display.TextScale);
            foreach (var timer in timerList)
            {
                var cPosX    = ImGui.GetCursorPosX();
                var cPosY    = ImGui.GetCursorPosY();
                var fraction = (float)(timer.TimerCurrent + display.CacheAge.TotalSeconds) / timer.TimerMax;

                if (display.LimitDisplayTime && timer.TimerMax > display.LimitDisplayTimeSeconds)
                {
                    fraction = (float)(display.LimitDisplayTimeSeconds - timer.TimerRemaining + display.CacheAge.TotalSeconds) / display.LimitDisplayTimeSeconds;
                }

                if (display.FillToComplete && fraction < 1)
                {
                    fraction = 1 - fraction;
                }

                ImGui.BeginGroup();

                var drawList = ImGui.GetWindowDrawList();

                var barTopLeft     = ImGui.GetCursorScreenPos();
                var barBottomRight = ImGui.GetCursorScreenPos() + new Vector2(display.RowSize);

                var barSize = barBottomRight - barTopLeft;
                var hovered = false;

                if (display.AllowClicking && timer.ClickAction != null)
                {
                    // Check Mouse Position
                    var mouse = ImGui.GetMousePos();
                    var pos1  = ImGui.GetCursorScreenPos();
                    var pos2  = ImGui.GetCursorScreenPos() + barSize;

                    if (mouse.X > pos1.X && mouse.X < pos2.X && mouse.Y > pos1.Y && mouse.Y < pos2.Y)
                    {
                        display.IsClickableHovered = true;
                        hovered = true;
                        ImGui.SetMouseCursor(ImGuiMouseCursor.Hand);
                    }
                }

                var barFractionCompleteSize   = new Vector2(0, barSize.Y * (1 - fraction));
                var barFractionIncompleteSize = new Vector2(0, barSize.Y * fraction);

                DrawBar(barTopLeft, barSize, 1 - fraction, display.IconDisplayFillDirection, GetBarBackgroundColor(display, timer), timer.ProgressColor);

                if (hovered)
                {
                    drawList.AddRect(barTopLeft, barBottomRight, 0xFF0000FF);
                    drawList.AddRect(barTopLeft + Vector2.One, barBottomRight - Vector2.One, 0xFF0000FF);
                }


                if (display.ShowActionIcon && timer.IconId > 0)
                {
                    var iconSize = new Vector2(display.RowSize * display.ActionIconScale);


                    var icon = IconManager.GetIconTexture(timer.IconId);

                    if (icon != null)
                    {
                        iconSize *= new Vector2((float)icon.Width / Math.Max(icon.Width, icon.Height), (float)icon.Height / Math.Max(icon.Width, icon.Height));

                        ImGui.SetCursorPosY(cPosY + barSize.Y / 2 - iconSize.X / 2);
                        ImGui.SetCursorPosX(cPosX + barSize.X / 2 - iconSize.X / 2);

                        ImGui.Image(icon.ImGuiHandle, iconSize);
                    }
                }

                if (timer.AllowCountdown && display.ShowCountdown && (!timer.IsComplete || display.ShowCountdownReady))
                {
                    var countdownText = Math.Abs(timer.TimerRemaining - display.CacheAge.TotalSeconds).ToString("F1");
                    var countdownSize = ImGui.CalcTextSize(countdownText);
                    ImGui.SetCursorPosY(cPosY + (display.RowSize / 2f) - (countdownSize.Y / 2));
                    ImGui.SetCursorPosX(cPosX + (display.RowSize / 2f) - (countdownSize.X / 2));

                    // ImGui.TextColored(display.TextColor, countdownText);
                    TextShadowed(countdownText, display.TextColor, new Vector4(0, 0, 0, 1), 2);
                }

                ImGui.EndGroup();
                if (timer.ClickAction != null)
                {
                    if (hovered && ImGui.GetIO().MouseDown[0])
                    {
                        timer.ClickAction?.Invoke(this, timer.ClickParam);
                    }
                }


                var newX = cPosX;
                var newY = cPosY;
                if (display.IconVerticalStack)
                {
                    if (display.DirectionBtT)
                    {
                        newY = cPosY - display.RowSize - display.BarSpacing;
                        if (newY < 0 + ImGui.GetStyle().WindowPadding.Y)
                        {
                            newY = sPosY;
                            if (display.DirectionRtL)
                            {
                                newX = cPosX - display.RowSize - display.BarSpacing;
                            }
                            else
                            {
                                newX = cPosX + display.RowSize + display.BarSpacing;
                            }
                        }
                    }
                    else
                    {
                        newY = cPosY + display.RowSize + display.BarSpacing;
                        newX = cPosX;
                        if (newY > ImGui.GetWindowHeight() - display.RowSize - ImGui.GetStyle().WindowPadding.Y)
                        {
                            newY = sPosY;
                            if (display.DirectionRtL)
                            {
                                newX = cPosX - display.RowSize - display.BarSpacing;
                            }
                            else
                            {
                                newX = cPosX + display.RowSize + display.BarSpacing;
                            }
                        }
                    }
                }
                else
                {
                    if (display.DirectionRtL)
                    {
                        newX = cPosX - display.RowSize - display.BarSpacing;
                        if (newX < 0 + ImGui.GetStyle().WindowPadding.X)
                        {
                            newX = sPosX;
                            if (display.DirectionBtT)
                            {
                                newY = cPosY - display.RowSize - display.BarSpacing;
                            }
                            else
                            {
                                newY = cPosY + display.RowSize + display.BarSpacing;
                            }
                        }
                    }
                    else
                    {
                        newX = cPosX + display.RowSize + display.BarSpacing;
                        newY = cPosY;
                        if (newX > ImGui.GetWindowWidth() - display.RowSize - ImGui.GetStyle().WindowPadding.X)
                        {
                            newX = sPosX;
                            if (display.DirectionBtT)
                            {
                                newY = cPosY - display.RowSize - display.BarSpacing;
                            }
                            else
                            {
                                newY = cPosY + display.RowSize + display.BarSpacing;
                            }
                        }
                    }
                }



                ImGui.SetCursorPosY(newY);
                ImGui.SetCursorPosX(newX);
            }
        }
        private void DrawDisplayVertical(MonitorDisplay display, List <DisplayTimer> timerList)
        {
            if (display.DirectionRtL)
            {
                ImGui.SetCursorPosX(ImGui.GetWindowWidth() - (display.RowSize + ImGui.GetStyle().WindowPadding.X));
            }
            ImGui.SetWindowFontScale(display.TextScale);

            var barSize = new Vector2(display.RowSize, ImGui.GetWindowHeight() - ImGui.GetStyle().WindowPadding.Y * 2);

            foreach (var timer in timerList)
            {
                var cPosX    = ImGui.GetCursorPosX();
                var cPosY    = ImGui.GetCursorPosY();
                var fraction = (float)(timer.TimerCurrent + display.CacheAge.TotalSeconds) / timer.TimerMax;

                if (display.LimitDisplayTime && timer.TimerMax > display.LimitDisplayTimeSeconds)
                {
                    fraction = (float)(display.LimitDisplayTimeSeconds - timer.TimerRemaining + display.CacheAge.TotalSeconds) / display.LimitDisplayTimeSeconds;
                }

                if (display.FillToComplete && fraction < 1)
                {
                    fraction = 1 - fraction;
                }

                ImGui.BeginGroup();

                var drawList = ImGui.GetWindowDrawList();

                var barTopLeft     = ImGui.GetCursorScreenPos();
                var barBottomRight = ImGui.GetCursorScreenPos() + barSize;

                var hovered = false;
                if (display.AllowClicking && timer.ClickAction != null)
                {
                    // Check Mouse Position
                    var mouse = ImGui.GetMousePos();
                    var pos1  = ImGui.GetCursorScreenPos();
                    var pos2  = ImGui.GetCursorScreenPos() + barSize;

                    if (mouse.X > pos1.X && mouse.X < pos2.X && mouse.Y > pos1.Y && mouse.Y < pos2.Y)
                    {
                        display.IsClickableHovered = true;
                        hovered = true;
                        ImGui.SetMouseCursor(ImGuiMouseCursor.Hand);
                    }
                }

                DrawBar(barTopLeft, barSize, 1 - fraction, display.ReverseFill ? FillDirection.FromTop : FillDirection.FromBottom, GetBarBackgroundColor(display, timer), timer.ProgressColor);
                var iconSize = new Vector2(display.RowSize) * display.ActionIconScale;
                if (display.ShowActionIcon)
                {
                    if (timer.IconId > 0)
                    {
                        var icon = IconManager.GetIconTexture(timer.IconId);
                        if (icon != null)
                        {
                            iconSize *= new Vector2((float)icon.Width / Math.Max(icon.Width, icon.Height), (float)icon.Height / Math.Max(icon.Width, icon.Height));

                            if (display.ReverseSideIcon)
                            {
                                ImGui.SetCursorPosY(cPosY + (barSize.X - iconSize.X) / 2);
                            }
                            else
                            {
                                ImGui.SetCursorPosY(cPosY + barSize.Y - iconSize.Y - (barSize.X - iconSize.X) / 2);
                            }
                            ImGui.SetCursorPosX(cPosX + (display.RowSize / 2f) - (iconSize.X / 2));

                            ImGui.Image(icon.ImGuiHandle, iconSize);
                        }
                    }
                }

                if (timer.AllowCountdown && display.ShowCountdown && (!timer.IsComplete || display.ShowCountdownReady))
                {
                    var countdownValue = Math.Abs(timer.TimerRemaining - display.CacheAge.TotalSeconds);
                    var countdownText  = countdownValue.ToString(countdownValue >= 100 ? "F0" : "F1");
                    var countdownSize  = ImGui.CalcTextSize(countdownText);
                    if (display.ReverseCountdownSide)
                    {
                        ImGui.SetCursorPosY(cPosY + barSize.Y - (display.RowSize / 2f) - countdownSize.Y / 2);
                    }
                    else
                    {
                        ImGui.SetCursorPosY(cPosY + (display.RowSize / 2f) - countdownSize.Y / 2);
                    }

                    ImGui.SetCursorPosX(cPosX + (display.RowSize / 2f) - (countdownSize.X / 2));
                    if (display.ShowActionIcon && display.ReverseCountdownSide != display.ReverseSideIcon)
                    {
                        TextShadowed(countdownText, display.TextColor, new Vector4(0, 0, 0, 0.5f), 2);
                    }
                    else
                    {
                        ImGui.TextColored(display.TextColor, countdownText);
                    }
                }

                if (display.ShowSkillName)
                {
                    var size = ImGui.CalcTextSize(timer.Name);
                    ImGui.SetCursorPosX(cPosX + display.RowSize / 2f - size.Y / 2);
                    ImGui.SetCursorPosY(ImGui.GetWindowHeight() - (display.RowSize + (size.X * display.TextScale) + ImGui.GetStyle().ItemSpacing.X));
                    AddTextVertical(timer.Name, ImGui.GetColorU32(display.TextColor), display.TextScale);
                }

                if (hovered)
                {
                    drawList.AddRect(barTopLeft, barBottomRight, 0xFF0000FF);
                    drawList.AddRect(barTopLeft + Vector2.One, barBottomRight - Vector2.One, 0xFF0000FF);
                }


                ImGui.EndGroup();
                if (ImGui.IsItemClicked(ImGuiMouseButton.Left))
                {
                    timer.ClickAction?.Invoke(this, timer.ClickParam);
                }

                ImGui.SameLine();
                if (display.DirectionRtL)
                {
                    ImGui.SetCursorPosX(cPosX - display.RowSize - display.BarSpacing);
                }
                else
                {
                    ImGui.SetCursorPosX(cPosX + display.RowSize + display.BarSpacing);
                }

                if (ImGui.GetCursorPosX() + display.RowSize > ImGui.GetWindowWidth())
                {
                    return;
                }
            }
        }
        private void DrawDisplayHorizontal(MonitorDisplay display, List <DisplayTimer> timerList)
        {
            if (display.DirectionBtT)
            {
                ImGui.SetCursorPosY(ImGui.GetWindowHeight() - (display.RowSize + ImGui.GetStyle().WindowPadding.Y));
            }
            ImGui.SetWindowFontScale(display.TextScale);
            var barSize = new Vector2(ImGui.GetWindowWidth() - ImGui.GetStyle().WindowPadding.X * 2, display.RowSize);

            foreach (var timer in timerList)
            {
                var barTopLeft     = ImGui.GetCursorScreenPos();
                var barBottomRight = ImGui.GetCursorScreenPos() + barSize;

                ImGui.BeginGroup();

                var hovered = false;

                if (display.AllowClicking && timer.ClickAction != null)
                {
                    // Check Mouse Position
                    var mouse = ImGui.GetMousePos();
                    var pos1  = ImGui.GetCursorScreenPos();
                    var pos2  = ImGui.GetCursorScreenPos() + barSize;

                    if (mouse.X > pos1.X && mouse.X < pos2.X && mouse.Y > pos1.Y && mouse.Y < pos2.Y)
                    {
                        display.IsClickableHovered = true;
                        hovered = true;
                        ImGui.SetMouseCursor(ImGuiMouseCursor.Hand);
                    }
                }
                var cPosY = ImGui.GetCursorPosY();

                var fraction = (float)(timer.TimerCurrent + display.CacheAge.TotalSeconds) / timer.TimerMax;

                if (display.LimitDisplayTime && timer.TimerMax > display.LimitDisplayTimeSeconds)
                {
                    fraction = (float)(display.LimitDisplayTimeSeconds - timer.TimerRemaining + display.CacheAge.TotalSeconds) / display.LimitDisplayTimeSeconds;
                }

                if (display.FillToComplete && fraction < 1)
                {
                    fraction = 1 - fraction;
                }

                DrawBar(ImGui.GetCursorScreenPos(), barSize, 1 - fraction, display.ReverseFill ? FillDirection.FromRight : FillDirection.FromLeft, GetBarBackgroundColor(display, timer), timer.ProgressColor);

                var iconSize = new Vector2(display.RowSize) * display.ActionIconScale;

                if (display.ShowActionIcon)
                {
                    var x = ImGui.GetCursorPosX();
                    if (timer.IconId > 0)
                    {
                        var icon = IconManager.GetIconTexture(timer.IconId);
                        if (icon != null)
                        {
                            var iconRatio = new Vector2((float)icon.Width / Math.Max(icon.Width, icon.Height), (float)icon.Height / Math.Max(icon.Width, icon.Height));

                            var displayedIconSize = iconSize * iconRatio;

                            ImGui.SetCursorPosY(cPosY + (display.RowSize / 2f) - (displayedIconSize.Y / 2));
                            if (display.ReverseSideIcon)
                            {
                                ImGui.SetCursorPosX(ImGui.GetWindowWidth() - (display.RowSize / 2f) - (displayedIconSize.X / 2) - ImGui.GetStyle().WindowPadding.X);
                            }
                            else
                            {
                                ImGui.SetCursorPosX(ImGui.GetCursorPosX() + (display.RowSize / 2f) - (displayedIconSize.X / 2));
                            }


                            ImGui.Image(icon.ImGuiHandle, displayedIconSize);
                        }
                    }
                    ImGui.SameLine();
                    ImGui.SetCursorPosX(x + (display.RowSize / 2f) + (iconSize.X / 2) + ImGui.GetStyle().ItemSpacing.X);
                }

                if (timer.AllowCountdown && display.ShowCountdown && (!timer.IsComplete || display.ShowCountdownReady))
                {
                    var time          = Math.Abs(timer.TimerRemaining - display.CacheAge.TotalSeconds);
                    var countdownText = time.ToString(time >= 100 ? "F0" : "F1");
                    var countdownSize = ImGui.CalcTextSize(countdownText);

                    ImGui.SetCursorPosY(cPosY + (display.RowSize / 2f - countdownSize.Y / 2f));

                    if (display.ReverseCountdownSide)
                    {
                        ImGui.SetCursorPosX(ImGui.GetStyle().WindowPadding.X + display.RowSize / 2f - countdownSize.X / 2);
                    }
                    else
                    {
                        ImGui.SetCursorPosX(ImGui.GetWindowWidth() - ImGui.GetStyle().WindowPadding.X - display.RowSize / 2f - countdownSize.X * 0.6f);
                    }

                    if (display.ShowActionIcon && display.ReverseSideIcon != display.ReverseCountdownSide)
                    {
                        TextShadowed(countdownText, display.TextColor, new Vector4(0, 0, 0, 0.5f), 2);
                    }
                    else
                    {
                        ImGui.TextColored(display.TextColor, countdownText);
                    }
                }

                if (display.ShowSkillName)
                {
                    var name = timer.Name;
                    if (display.ShowStatusEffectTarget && !string.IsNullOrEmpty(timer.TargetName))
                    {
                        name += $" on {timer.TargetName}";
                    }
                    var size = ImGui.CalcTextSize(name);
                    if (display.SkillNameRight)
                    {
                        ImGui.SetCursorPosX(
                            ImGui.GetWindowWidth() -
                            size.X -
                            ImGui.GetStyle().WindowPadding.X -
                            ImGui.GetStyle().FramePadding.X -
                            ((display.ShowActionIcon && display.ReverseSideIcon) || (display.ShowCountdown && !display.ReverseCountdownSide) ? (iconSize.X + ImGui.GetStyle().ItemSpacing.X) : 0)
                            );
                    }
                    else
                    {
                        ImGui.SetCursorPosX(
                            ImGui.GetStyle().WindowPadding.X +
                            ImGui.GetStyle().FramePadding.X +
                            ((display.ShowActionIcon && !display.ReverseSideIcon) || (display.ShowCountdown && display.ReverseCountdownSide) ? (iconSize.X + ImGui.GetStyle().ItemSpacing.X) : 0)
                            );
                    }

                    ImGui.SetCursorPosY(cPosY + (display.RowSize / 2f - size.Y / 2f));
                    ImGui.TextColored(display.TextColor, name);
                }

                if (hovered)
                {
                    var drawList = ImGui.GetWindowDrawList();
                    drawList.AddRect(barTopLeft, barBottomRight, 0xFF0000FF);
                    drawList.AddRect(barTopLeft + Vector2.One, barBottomRight - Vector2.One, 0xFF0000FF);
                }

                ImGui.EndGroup();
                if (ImGui.IsItemClicked(0))
                {
                    timer.ClickAction?.Invoke(this, timer.ClickParam);
                }

                if (display.DirectionBtT)
                {
                    ImGui.SetCursorPosY(cPosY - display.RowSize - display.BarSpacing);
                }
                else
                {
                    ImGui.SetCursorPosY(cPosY + display.RowSize + display.BarSpacing);
                }

                if (ImGui.GetCursorPosY() + display.RowSize > ImGui.GetWindowHeight())
                {
                    return;
                }
            }
        }