diff --git a/Libs/DF/button.lua b/Libs/DF/button.lua index fde3a244..01b5bc62 100644 --- a/Libs/DF/button.lua +++ b/Libs/DF/button.lua @@ -444,64 +444,73 @@ local ButtonMetaFunctions = _G[DF.GlobalWidgetControlNames ["button"]] function ButtonMetaFunctions:SetBackdropBorderColor(...) return self.button:SetBackdropBorderColor(...) end - - function ButtonMetaFunctions:SetIcon (texture, width, height, layout, texcoord, overlay, textdistance, leftpadding, textheight, short_method) + + function ButtonMetaFunctions:SetIcon(texture, width, height, layout, texcoord, overlay, textDistance, leftPadding, textHeight, shortMethod) if (not self.icon) then - self.icon = self:CreateTexture (nil, "artwork") - self.icon:SetSize (self.height*0.8, self.height*0.8) - self.icon:SetPoint ("left", self.widget, "left", 4 + (leftpadding or 0), 0) - self.icon.leftpadding = leftpadding or 0 + self.icon = self:CreateTexture(nil, "artwork") + self.icon:SetSize(self.height * 0.8, self.height * 0.8) + self.icon:SetPoint("left", self.widget, "left", 4 + (leftPadding or 0), 0) + self.icon.leftPadding = leftPadding or 0 self.widget.text:ClearAllPoints() - self.widget.text:SetPoint ("left", self.icon, "right", textdistance or 2, 0 + (textheight or 0)) + self.widget.text:SetPoint ("left", self.icon, "right", textDistance or 2, 0 + (textHeight or 0)) end - - self.icon:SetTexture (texture) - self.icon:SetSize (width or self.height*0.8, height or self.height*0.8) - self.icon:SetDrawLayer (layout or "artwork") - if (texcoord) then - self.icon:SetTexCoord (unpack (texcoord)) - else - self.icon:SetTexCoord (0, 1, 0, 1) - end - if (overlay) then - if (type (overlay) == "string") then - local r, g, b, a = DF:ParseColors (overlay) - self.icon:SetVertexColor (r, g, b, a) + + if (type(texture) == "string") then + local isAtlas = C_Texture.GetAtlasInfo(texture) + if (isAtlas) then + self.icon:SetAtlas(texture) else - self.icon:SetVertexColor (unpack (overlay)) + self.icon:SetTexture(texture) end else - self.icon:SetVertexColor (1, 1, 1, 1) + self.icon:SetTexture(texture) end - - local w = self.button:GetWidth() - local iconw = self.icon:GetWidth() - local text_width = self.button.text:GetStringWidth() - if (text_width > w-15-iconw) then - if (short_method == false) then - - elseif (not short_method) then - local new_width = text_width+15+iconw - self.button:SetWidth (new_width) - - elseif (short_method == 1) then + self.icon:SetSize(width or self.height * 0.8, height or self.height * 0.8) + self.icon:SetDrawLayer(layout or "artwork") + + if (texcoord) then + self.icon:SetTexCoord(unpack(texcoord)) + else + self.icon:SetTexCoord(0, 1, 0, 1) + end + + if (overlay) then + if (type(overlay) == "string") then + local r, g, b, a = DF:ParseColors(overlay) + self.icon:SetVertexColor(r, g, b, a) + else + self.icon:SetVertexColor(unpack(overlay)) + end + else + self.icon:SetVertexColor(1, 1, 1, 1) + end + + local buttonWidth = self.button:GetWidth() + local iconWidth = self.icon:GetWidth() + local textWidth = self.button.text:GetStringWidth() + if (textWidth > buttonWidth - 15 - iconWidth) then + if (shortMethod == false) then + + elseif (not shortMethod) then + local new_width = textWidth + 15 + iconWidth + self.button:SetWidth(new_width) + + elseif (shortMethod == 1) then local loop = true - local textsize = 11 + local textSize = 11 while (loop) do - if (text_width+15+iconw < w or textsize < 8) then + if (textWidth + 15 + iconWidth < buttonWidth or textSize < 8) then loop = false break else - DF:SetFontSize (self.button.text, textsize) - text_width = self.button.text:GetStringWidth() - textsize = textsize - 1 + DF:SetFontSize(self.button.text, textSize) + textWidth = self.button.text:GetStringWidth() + textSize = textSize - 1 end end - end end - end -- frame stratas diff --git a/Libs/DF/cooltip.lua b/Libs/DF/cooltip.lua index 4f760dca..af984116 100644 --- a/Libs/DF/cooltip.lua +++ b/Libs/DF/cooltip.lua @@ -1,1605 +1,1484 @@ local DF = _G ["DetailsFramework"] if (not DF or not DetailsFrameworkCanLoad) then - return + return end local SharedMedia = LibStub:GetLibrary("LibSharedMedia-3.0") local _ + --lua locals -local _math_floor= math.floor -local _type = type -local _math_abs = math.abs -local _tinsert = tinsert -local _unpack = unpack -local _ipairs = ipairs -local _table_wipe = table.wipe -local _table_insert = table.insert -local _math_max = math.max +local ipairs = ipairs +local wipe = table.wipe +local insert = table.insert +local max = math.max + --api locals -local _GetScreenWidth = GetScreenWidth -local _GetScreenHeight = GetScreenHeight -local _UIParent = UIParent -local _CreateFrame = CreateFrame - local PixelUtil = PixelUtil or DFPixelUtil +local version = 3 -local version = 2 +local CONST_MENU_TYPE_MAINMENU = "main" +local CONST_MENU_TYPE_SUBMENU = "sec" +local CONST_COOLTIP_TYPE_MENU = "menu" +local CONST_COOLTIP_TYPE_TOOLTIP = "tooltip" function DF:CreateCoolTip() - ----------------------------------------------------------------------- - --> Cooltip Startup ----------------------------------------------------------------------- - - --> if a cooltip is already created with a higher version + --if a cooltip is already created with a higher version if (_G.GameCooltip2 and _G.GameCooltip2.version >= version) then return end - --> initialize - local CoolTip = { - version = version - } - _G.GameCooltip2 = CoolTip - _G.GameCooltip = CoolTip --back compatibility - - --> containers - CoolTip.LeftTextTable = {} - CoolTip.LeftTextTableSub = {} - CoolTip.RightTextTable = {} - CoolTip.RightTextTableSub = {} - CoolTip.LeftIconTable = {} - CoolTip.LeftIconTableSub = {} - CoolTip.RightIconTable = {} - CoolTip.RightIconTableSub = {} - CoolTip.Banner = {false, false, false} - CoolTip.TopIconTableSub = {} - CoolTip.StatusBarTable = {} - CoolTip.StatusBarTableSub = {} - CoolTip.WallpaperTable = {} - CoolTip.WallpaperTableSub = {} - - CoolTip.PopupFrameTable = {} - - CoolTip.FunctionsTableMain = {} --> menus - CoolTip.FunctionsTableSub = {} --> menus - CoolTip.ParametersTableMain = {} --> menus - CoolTip.ParametersTableSub = {} --> menus - - CoolTip.FixedValue = nil --> menus - CoolTip.SelectedIndexMain = nil --> menus - CoolTip.SelectedIndexSec = {} --> menus + local defaultBackdrop = {bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, + tile = true, tileSize = 16, insets = {left = 0, right = 0, top = 0, bottom = 0}} + local defaultBackdropColor = {.2, .2, .2, 1} + local defaultBackdropBorderColor = {0.05, 0.05, 0.05, 1} + + --initialize + local CoolTip = { + version = version, + debug = false, + } + _G.GameCooltip2 = CoolTip + _G.GameCooltip = CoolTip --back compatibility + + function CoolTip:PrintDebug(...) + if (CoolTip.debug) then + print("|cFFFFFF00Cooltip|r:", ...) + print(debugstack()) + end + end + + function CoolTip:SetDebug(bDebugState) + CoolTip.debug = bDebugState + end + + --containers + CoolTip.LeftTextTable = {} + CoolTip.LeftTextTableSub = {} + CoolTip.RightTextTable = {} + CoolTip.RightTextTableSub = {} + CoolTip.LeftIconTable = {} + CoolTip.LeftIconTableSub = {} + CoolTip.RightIconTable = {} + CoolTip.RightIconTableSub = {} + CoolTip.Banner = {false, false, false} + CoolTip.TopIconTableSub = {} + CoolTip.StatusBarTable = {} + CoolTip.StatusBarTableSub = {} + CoolTip.WallpaperTable = {} + CoolTip.WallpaperTableSub = {} + CoolTip.PopupFrameTable = {} + + --menus + CoolTip.FunctionsTableMain = {} + CoolTip.FunctionsTableSub = {} + CoolTip.ParametersTableMain = {} + CoolTip.ParametersTableSub = {} + CoolTip.FixedValue = nil + CoolTip.SelectedIndexMain = nil + CoolTip.SelectedIndexSec = {} --options table - CoolTip.OptionsList = { - ["RightTextMargin"] = true, - ["IconSize"] = true, - ["HeightAnchorMod"] = true, - ["WidthAnchorMod"] = true, - ["MinWidth"] = true, - ["FixedWidth"] = true, - ["FixedHeight"] = true, - ["FixedWidthSub"] = true, - ["FixedHeightSub"] = true, - ["AlignAsBlizzTooltip"] = true, - ["AlignAsBlizzTooltipFrameHeightOffset"] = true, - ["IgnoreSubMenu"] = true, - ["IgnoreButtonAutoHeight"] = true, - ["TextHeightMod"] = true, - ["ButtonHeightMod"] = true, - ["ButtonHeightModSub"] = true, - ["YSpacingMod"] = true, - ["YSpacingModSub"] = true, - ["ButtonsYMod"] = true, - ["ButtonsYModSub"] = true, - ["IconHeightMod"] = true, - ["StatusBarHeightMod"] = true, - ["StatusBarTexture"] = true, - ["TextSize"] = true, - ["TextFont"] = true, - ["TextColor"] = true, - ["TextColorRight"] = true, - ["TextShadow"] = true, - ["LeftTextWidth"] = true, - ["RightTextWidth"] = true, - ["LeftTextHeight"] = true, - ["RightTextHeight"] = true, - ["NoFade"] = true, - ["MyAnchor"] = true, - ["Anchor"] = true, - ["RelativeAnchor"] = true, - ["NoLastSelectedBar"] = true, - ["SubMenuIsTooltip"] = true, - ["LeftBorderSize"] = true, - ["RightBorderSize"] = true, - ["HeighMod"] = true, - ["HeighModSub"] = true, - ["IconBlendMode"] = true, - ["IconBlendModeHover"] = true, - ["SubFollowButton"] = true, - ["IgnoreArrows"] = true, - ["SelectedTopAnchorMod"] = true, - ["SelectedBottomAnchorMod"] = true, - ["SelectedLeftAnchorMod"] = true, - ["SelectedRightAnchorMod"] = true, - } - - CoolTip.AliasList = { - ["VerticalOffset"] = "ButtonsYMod", - ["VerticalPadding"] = "YSpacingMod", - ["LineHeightSizeOffset"] = "ButtonHeightMod", - ["FrameHeightSizeOffset"] = "HeighMod", - - } - - CoolTip.OptionsTable = {} - - --cprops - CoolTip.Indexes = 0 --> amount of lines current on shown - CoolTip.IndexesSub = {} --> amount of lines current on shown - CoolTip.HaveSubMenu = false --> amount of lines current on shown - CoolTip.SubIndexes = 0 --> amount of lines current on shown on sub menu - CoolTip.Type = 1 --> 1 tooltip 2 tooltip with bars 3 menu 4 menu + submenus - CoolTip.Host = nil --> frame to anchor - CoolTip.LastSize = 0 --> last size - - CoolTip.LastIndex = 0 - - CoolTip.internal_x_mod = 0 - CoolTip.internal_y_mod = 0 - CoolTip.overlap_checked = false - - --defaults - CoolTip.default_height = 20 - CoolTip.default_text_size = 10.5 - CoolTip.default_text_font = "GameFontHighlight" - - CoolTip.selected_anchor = {} - CoolTip.selected_anchor.left = 2 - CoolTip.selected_anchor.right = 0 - CoolTip.selected_anchor.top = 0 - CoolTip.selected_anchor.bottom = 0 - - CoolTip._default_font = SharedMedia:Fetch ("font", "Friz Quadrata TT") - - --> create frames - - local build_main_frame = function (self) - - self:SetSize (500, 500) - self:SetPoint ("CENTER", UIParent, "CENTER") - self:SetBackdrop ({bgFile = [[Interface\DialogFrame\UI-DialogBox-Background-Dark]], edgeFile = [[Interface\Buttons\WHITE8X8]], tile = true, edgeSize = 1, tileSize = 16, insets = {left = 0, right = 0, top = 0, bottom = 0}}) - self:SetBackdropColor (0.09019, 0.09019, 0.18823, 1) - self:SetBackdropBorderColor (0, 0, 0, 1) - - if (not self.framebackgroundCenter) then - self.framebackgroundCenter = self:CreateTexture ("$parent_FrameBackgroundCenter", "BACKGROUND") - self.framebackgroundCenter:SetDrawLayer ("BACKGROUND", 2) - self.framebackgroundCenter:SetColorTexture (0, 0, 0, .5) - self.framebackgroundCenter:SetPoint ("TOPLEFT", self, "TOPLEFT", 35, -3) - self.framebackgroundCenter:SetPoint ("TOPRIGHT", self, "TOPRIGHT", -35, -3) - self.framebackgroundCenter:SetPoint ("BOTTOMLEFT", self, "BOTTOMLEFT", 35, 3) - self.framebackgroundCenter:SetPoint ("BOTTOMRIGHT", self, "BOTTOMRIGHT", -35, 3) - end - - if (not self.framebackgroundLeft) then - self.framebackgroundLeft = self:CreateTexture ("$parent_FrameBackgroundLeft", "BACKGROUND") - self.framebackgroundLeft:SetDrawLayer ("BACKGROUND", 3) - self.framebackgroundLeft:SetColorTexture (0, 0, 0, .5) - self.framebackgroundLeft:SetPoint ("TOPLEFT", self, "TOPLEFT", 3, -3) - self.framebackgroundLeft:SetPoint ("BOTTOMLEFT", self, "BOTTOMLEFT", 3, 3) - self.framebackgroundLeft:SetWidth (32) - end + CoolTip.OptionsList = { + ["RightTextMargin"] = true, + ["IconSize"] = true, + ["HeightAnchorMod"] = true, + ["WidthAnchorMod"] = true, + ["MinWidth"] = true, + ["FixedWidth"] = true, + ["FixedHeight"] = true, + ["FixedWidthSub"] = true, + ["FixedHeightSub"] = true, + ["AlignAsBlizzTooltip"] = true, + ["AlignAsBlizzTooltipFrameHeightOffset"] = true, + ["IgnoreSubMenu"] = true, + ["IgnoreButtonAutoHeight"] = true, + ["TextHeightMod"] = true, + ["ButtonHeightMod"] = true, + ["ButtonHeightModSub"] = true, + ["YSpacingMod"] = true, + ["YSpacingModSub"] = true, + ["ButtonsYMod"] = true, + ["ButtonsYModSub"] = true, + ["IconHeightMod"] = true, + ["StatusBarHeightMod"] = true, + ["StatusBarTexture"] = true, + ["TextSize"] = true, + ["TextFont"] = true, + ["TextColor"] = true, + ["TextColorRight"] = true, + ["TextShadow"] = true, + ["LeftTextWidth"] = true, + ["RightTextWidth"] = true, + ["LeftTextHeight"] = true, + ["RightTextHeight"] = true, + ["NoFade"] = true, + ["MyAnchor"] = true, + ["Anchor"] = true, + ["RelativeAnchor"] = true, + ["NoLastSelectedBar"] = true, + ["SubMenuIsTooltip"] = true, + ["LeftBorderSize"] = true, + ["RightBorderSize"] = true, + ["HeighMod"] = true, + ["HeighModSub"] = true, + ["IconBlendMode"] = true, + ["IconBlendModeHover"] = true, + ["SubFollowButton"] = true, + ["IgnoreArrows"] = true, + ["SelectedTopAnchorMod"] = true, + ["SelectedBottomAnchorMod"] = true, + ["SelectedLeftAnchorMod"] = true, + ["SelectedRightAnchorMod"] = true, + } - if (not self.framebackgroundRight) then - self.framebackgroundRight = self:CreateTexture ("$parent_FrameBackgroundRight", "BACKGROUND") - self.framebackgroundRight:SetDrawLayer ("BACKGROUND", 3) - self.framebackgroundRight:SetColorTexture (0, 0, 0, .5) - self.framebackgroundRight:SetPoint ("TOPRIGHT", self, "TOPRIGHT", -3, -3) - self.framebackgroundRight:SetPoint ("BOTTOMRIGHT", self, "BOTTOMRIGHT", -3, 3) - self.framebackgroundRight:SetWidth (32) - end - - if (not self.frameWallpaper) then - self.frameWallpaper = self:CreateTexture ("$parent_FrameWallPaper", "BACKGROUND") - self.frameWallpaper:SetDrawLayer ("BACKGROUND", 4) - self.frameWallpaper:SetPoint ("TOPLEFT", self, "TOPLEFT", 0, 0) - self.frameWallpaper:SetPoint ("BOTTOMRIGHT", self, "BOTTOMRIGHT", 0, 0) - end - - if (not self.selectedTop) then - self.selectedTop = self:CreateTexture ("$parent_SelectedTop", "ARTWORK") - self.selectedTop:SetColorTexture (.5, .5, .5, .75) - self.selectedTop:SetHeight (3) - end - - if (not self.selectedBottom) then - self.selectedBottom = self:CreateTexture ("$parent_SelectedBottom", "ARTWORK") - self.selectedBottom:SetColorTexture (.5, .5, .5, .75) - self.selectedBottom:SetHeight (3) - end - - if (not self.selectedMiddle) then - self.selectedMiddle = self:CreateTexture ("$parent_Selected", "ARTWORK") - self.selectedMiddle:SetColorTexture (.5, .5, .5, .75) - self.selectedMiddle:SetPoint ("TOPLEFT", self.selectedTop, "BOTTOMLEFT") - self.selectedMiddle:SetPoint ("BOTTOMRIGHT", self.selectedBottom, "TOPRIGHT") - end - - if (not self.upperImage2) then - self.upperImage2 = self:CreateTexture ("$parent_UpperImage2", "ARTWORK") - self.upperImage2:Hide() - self.upperImage2:SetPoint ("CENTER", self, "CENTER", 0, -3) - self.upperImage2:SetPoint ("BOTTOM", self, "TOP", 0, -3) - end - - if (not self.upperImage) then - self.upperImage = self:CreateTexture ("$parent_UpperImage", "OVERLAY") - self.upperImage:Hide() - self.upperImage:SetPoint ("CENTER", self, "CENTER", 0, -3) - self.upperImage:SetPoint ("BOTTOM", self, "TOP", 0, -3) - end - - if (not self.upperImageText) then - self.upperImageText = self:CreateFontString ("$parent_UpperImageText", "OVERLAY", "GameTooltipHeaderText") - self.upperImageText:SetJustifyH ("LEFT") - self.upperImageText:SetPoint ("LEFT", self.upperImage, "RIGHT", 5, 0) - DF:SetFontSize (self.upperImageText, 13) - end - - if (not self.upperImageText2) then - self.upperImageText2 = self:CreateFontString ("$parent_UpperImageText2", "OVERLAY", "GameTooltipHeaderText") - self.upperImageText2:SetJustifyH ("LEFT") - self.upperImageText2:SetPoint ("BOTTOMRIGHT", self, "LEFT", 0, 3) - DF:SetFontSize (self.upperImageText2, 13) - end - - if (not self.titleIcon) then - self.titleIcon = self:CreateTexture ("$parent_TitleIcon", "OVERLAY") - self.titleIcon:SetTexture ("Interface\\Challenges\\challenges-main") - self.titleIcon:SetTexCoord (0.1521484375, 0.563671875, 0.160859375, 0.234375) - self.titleIcon:SetPoint ("CENTER", self, "CENTER") - self.titleIcon:SetPoint ("BOTTOM", self, "TOP", 0, -22) - self.titleIcon:Hide() - end - - if (not self.titleText) then - self.titleText = self:CreateFontString ("$parent_TitleText", "OVERLAY", "GameFontHighlightSmall") - self.titleText:SetJustifyH ("LEFT") - DF:SetFontSize (self.titleText, 10) - self.titleText:SetPoint ("CENTER", self.titleIcon, "CENTER", 0, 6) - end + CoolTip.AliasList = { + ["VerticalOffset"] = "ButtonsYMod", + ["VerticalPadding"] = "YSpacingMod", + ["LineHeightSizeOffset"] = "ButtonHeightMod", + ["FrameHeightSizeOffset"] = "HeighMod", + } + + CoolTip.OptionsTable = {} + + --amount of lines current on shown + CoolTip.Indexes = 0 + --amount of lines current on shown + CoolTip.IndexesSub = {} + --amount of lines current on shown + CoolTip.HaveSubMenu = false + --amount of lines current on shown on sub menu + CoolTip.SubIndexes = 0 + --1 tooltip 2 tooltip with bars 3 menu 4 menu + submenus + CoolTip.Type = 1 + --frame to anchor + CoolTip.Host = nil + --last size + CoolTip.LastSize = 0 + CoolTip.LastIndex = 0 + CoolTip.internalYMod = 0 + CoolTip.internalYMod = 0 + CoolTip.overlapChecked = false + + --defaults + CoolTip.default_height = 20 + CoolTip.default_text_size = 10.5 + CoolTip.default_text_font = "GameFontHighlight" + CoolTip.selectedAnchor = {} + CoolTip.selectedAnchor.left = 2 + CoolTip.selectedAnchor.right = 0 + CoolTip.selectedAnchor.top = 0 + CoolTip.selectedAnchor.bottom = 0 + + CoolTip.defaultFont = DF:GetBestFontForLanguage() + + --create frames, self is frame1 or frame2 + local createTooltipFrames = function(self) + self:SetSize(500, 500) + self:SetPoint("CENTER", UIParent, "CENTER", 0, 0) + self:SetBackdrop(defaultBackdrop) + self:SetBackdropColor(DF:ParseColors(defaultBackdropColor)) + self:SetBackdropBorderColor(DF:ParseColors(defaultBackdropBorderColor)) + + if (not self.frameBackgroundTexture) then + self.frameBackgroundTexture = self:CreateTexture("$parent_FrameBackgroundTexture", "BACKGROUND", nil, 2) + self.frameBackgroundTexture:SetColorTexture(0, 0, 0, 0) + self.frameBackgroundTexture:SetAllPoints() end - - --> main frame - local frame1 + + if (not self.frameWallpaper) then + self.frameWallpaper = self:CreateTexture("$parent_FrameWallPaper", "BACKGROUND", nil, 4) + self.frameWallpaper:SetPoint("TOPLEFT", self, "TOPLEFT", 0, 0) + self.frameWallpaper:SetPoint("BOTTOMRIGHT", self, "BOTTOMRIGHT", 0, 0) + end + + if (not self.selectedTop) then + self.selectedTop = self:CreateTexture("$parent_SelectedTop", "ARTWORK") + self.selectedTop:SetColorTexture(.5, .5, .5, .75) + self.selectedTop:SetHeight(3) + end + + if (not self.selectedBottom) then + self.selectedBottom = self:CreateTexture("$parent_SelectedBottom", "ARTWORK") + self.selectedBottom:SetColorTexture(.5, .5, .5, .75) + self.selectedBottom:SetHeight(3) + end + + if (not self.selectedMiddle) then + self.selectedMiddle = self:CreateTexture("$parent_Selected", "ARTWORK") + self.selectedMiddle:SetColorTexture(.5, .5, .5, .75) + self.selectedMiddle:SetPoint("TOPLEFT", self.selectedTop, "BOTTOMLEFT") + self.selectedMiddle:SetPoint("BOTTOMRIGHT", self.selectedBottom, "TOPRIGHT") + end + + if (not self.upperImage2) then + self.upperImage2 = self:CreateTexture("$parent_UpperImage2", "ARTWORK") + self.upperImage2:SetPoint("CENTER", self, "CENTER", 0, -3) + self.upperImage2:SetPoint("BOTTOM", self, "TOP", 0, -3) + self.upperImage2:Hide() + end + + if (not self.upperImage) then + self.upperImage = self:CreateTexture("$parent_UpperImage", "OVERLAY") + self.upperImage:SetPoint("CENTER", self, "CENTER", 0, -3) + self.upperImage:SetPoint("BOTTOM", self, "TOP", 0, -3) + self.upperImage:Hide() + end + + if (not self.upperImageText) then + self.upperImageText = self:CreateFontString("$parent_UpperImageText", "OVERLAY", "GameTooltipHeaderText") + self.upperImageText:SetJustifyH("LEFT") + self.upperImageText:SetPoint("LEFT", self.upperImage, "RIGHT", 5, 0) + DF:SetFontSize(self.upperImageText, 13) + end + + if (not self.upperImageText2) then + self.upperImageText2 = self:CreateFontString("$parent_UpperImageText2", "OVERLAY", "GameTooltipHeaderText") + self.upperImageText2:SetJustifyH("LEFT") + self.upperImageText2:SetPoint("BOTTOMRIGHT", self, "LEFT", 0, 3) + DF:SetFontSize(self.upperImageText2, 13) + end + + if (not self.titleIcon) then + self.titleIcon = self:CreateTexture("$parent_TitleIcon", "OVERLAY") + self.titleIcon:SetTexture("Interface\\Challenges\\challenges-main") + self.titleIcon:SetTexCoord(0.1521484375, 0.563671875, 0.160859375, 0.234375) + self.titleIcon:SetPoint("CENTER", self, "CENTER") + self.titleIcon:SetPoint("BOTTOM", self, "TOP", 0, -22) + self.titleIcon:Hide() + end + + if (not self.titleText) then + self.titleText = self:CreateFontString("$parent_TitleText", "OVERLAY", "GameFontHighlightSmall") + self.titleText:SetJustifyH("LEFT") + DF:SetFontSize(self.titleText, 10) + self.titleText:SetPoint("CENTER", self.titleIcon, "CENTER", 0, 6) + end + end + + --> main frame + local frame1 = GameCooltipFrame1 if (not GameCooltipFrame1) then - frame1 = CreateFrame ("Frame", "GameCooltipFrame1", UIParent, "BackdropTemplate") - - tinsert (UISpecialFrames, "GameCooltipFrame1") - DF:CreateFlashAnimation (frame1) - - --removing the border makes the cooltip much more clear - if (DF.CreateBorder) then - DF:CreateBorder (frame1, .3, .1, .03) - frame1:SetBorderAlpha (0, 0, 0) - end - else - frame1 = GameCooltipFrame1 + frame1 = CreateFrame("Frame", "GameCooltipFrame1", UIParent, "BackdropTemplate") end - - --> build widgets for frame - build_main_frame (frame1) - - --is this still in use? - GameCooltipFrame1_FrameBackgroundCenter:SetTexture ([[Interface\Tooltips\UI-Tooltip-Background]]) - GameCooltipFrame1_FrameBackgroundCenter:SetTexCoord (0.10546875, 0.89453125, 0, 1) - GameCooltipFrame1_FrameBackgroundLeft:SetTexture ([[Interface\Tooltips\UI-Tooltip-Background]]) - GameCooltipFrame1_FrameBackgroundLeft:SetTexCoord (0, 0.103515625, 0, 1) - GameCooltipFrame1_FrameBackgroundRight:SetTexture ([[Interface\Tooltips\UI-Tooltip-Background]]) - GameCooltipFrame1_FrameBackgroundRight:SetTexCoord (0.896484375, 1, 0, 1) - - --> secondary frame - local frame2 + + DF.table.addunique(UISpecialFrames, "GameCooltipFrame1") + + if (not frame1.FlashAnimation) then + DF:CreateFlashAnimation(frame1) + end + + createTooltipFrames(frame1) + + --> secondary frame + local frame2 = GameCooltipFrame2 if (not GameCooltipFrame2) then - frame2 = CreateFrame ("Frame", "GameCooltipFrame2", UIParent,"BackdropTemplate") - - tinsert (UISpecialFrames, "GameCooltipFrame2") - DF:CreateFlashAnimation (frame2) - frame2:SetClampedToScreen (true) - - --removing the border makes the cooltip much more clear - if (DF.CreateBorder) then - DF:CreateBorder (frame2, .3, .1, .03) - frame2:SetBorderAlpha (0, 0, 0) + frame2 = CreateFrame("Frame", "GameCooltipFrame2", UIParent, "BackdropTemplate") + end + + frame2:SetClampedToScreen(true) + DF.table.addunique(UISpecialFrames, "GameCooltipFrame2") + createTooltipFrames(frame2) + frame2:SetPoint("bottomleft", frame1, "bottomright", 4, 0) + + if (not frame2.FlashAnimation) then + DF:CreateFlashAnimation(frame2) + end + + CoolTip.frame1 = frame1 + CoolTip.frame2 = frame2 + DF:FadeFrame(frame1, 0) + DF:FadeFrame(frame2, 0) + frame1.Lines = {} + frame2.Lines = {} + +---------------------------------------------------------------------- + --Title Function +---------------------------------------------------------------------- + + function CoolTip:SetTitle(frameId, text) + if (frameId == 1) then + CoolTip.title1 = true + CoolTip.title_text = text + end + end + + function CoolTip:SetTitleAnchor(frameId, anchorPoint, ...) + anchorPoint = string.lower(anchorPoint) + if (frameId == 1) then + self.frame1.titleIcon:ClearAllPoints() + self.frame1.titleText:ClearAllPoints() + + if (anchorPoint == "left") then + self.frame1.titleIcon:SetPoint("left", frame1, "left", ...) + self.frame1.titleText:SetPoint("left", frame1.titleIcon, "right") + + elseif (anchorPoint == "center") then + self.frame1.titleIcon:SetPoint("center", frame1, "center") + self.frame1.titleIcon:SetPoint("bottom", frame1, "top") + self.frame1.titleText:SetPoint("left", frame1.titleIcon, "right") + self.frame1.titleText:SetText("TESTE") + + self.frame1.titleText:Show() + self.frame1.titleIcon:Show() + + elseif (anchorPoint == "right") then + self.frame1.titleIcon:SetPoint("right", frame1, "right", ...) + self.frame1.titleText:SetPoint("right", frame1.titleIcon, "left") + + end + + elseif (frameId == 2) then + self.frame2.titleIcon:ClearAllPoints() + self.frame2.titleText:ClearAllPoints() + + if (anchorPoint == "left") then + self.frame2.titleIcon:SetPoint("left", frame2, "left", ...) + self.frame2.titleText:SetPoint("left", frame2.titleIcon, "right") + + elseif (anchorPoint == "center") then + self.frame2.titleIcon:SetPoint("center", frame2, "center", ...) + self.frame2.titleText:SetPoint("left", frame2.titleIcon, "right") + + elseif (anchorPoint == "right") then + self.frame2.titleIcon:SetPoint("right", frame2, "right", ...) + self.frame2.titleText:SetPoint("right", frame2.titleIcon, "left") + end + end + end + +---------------------------------------------------------------------- + --Button Hide and Show Functions +---------------------------------------------------------------------- + local elapsedTime = 0 + CoolTip.mouseOver = false + CoolTip.buttonClicked = false + + frame1:SetScript("OnEnter", function(self) + --is cooltip a menu? + if (CoolTip.Type ~= 1 and CoolTip.Type ~= 2) then + CoolTip.active = true + CoolTip.mouseOver = true + CoolTip.hadInteractions = true + + self:SetScript("OnUpdate", nil) + DF:FadeFrame(self, 0) + + if (CoolTip.sub_menus) then + DF:FadeFrame(frame2, 0) + end + end + end) + + frame2:SetScript("OnEnter", function(self) + if (CoolTip.OptionsTable.SubMenuIsTooltip) then + return CoolTip:Close() + end + + if (CoolTip.Type ~= 1 and CoolTip.Type ~= 2) then + CoolTip.active = true + CoolTip.mouseOver = true + CoolTip.hadInteractions = true + + self:SetScript("OnUpdate", nil) + DF:FadeFrame(self, 0) + DF:FadeFrame(frame1, 0) + end + end) + + local OnLeaveUpdateFrame1 = function(self, deltaTime) + elapsedTime = elapsedTime + deltaTime + if (elapsedTime > 0.7) then + if (not CoolTip.active and not CoolTip.buttonClicked and self == CoolTip.Host) then + DF:FadeFrame(self, 1) + DF:FadeFrame(frame2, 1) + + elseif (not CoolTip.active) then + DF:FadeFrame(self, 1) + DF:FadeFrame(frame2, 1) + end + + self:SetScript("OnUpdate", nil) + frame2:SetScript("OnUpdate", nil) + end + end + + frame1:SetScript("OnLeave", function(self) + if (CoolTip.Type ~= 1 and CoolTip.Type ~= 2) then + CoolTip.active = false + CoolTip.mouseOver = false + elapsedTime = 0 + self:SetScript("OnUpdate", OnLeaveUpdateFrame1) + else + CoolTip.active = false + CoolTip.mouseOver = false + elapsedTime = 0 + self:SetScript("OnUpdate", OnLeaveUpdateFrame1) + end + end) + + local OnLeaveUpdateFrame2 = function(self, deltaTime) + elapsedTime = elapsedTime + deltaTime + if (elapsedTime > 0.7) then + if (not CoolTip.active and not CoolTip.buttonClicked and self == CoolTip.Host) then + DF:FadeFrame(self, 1) + DF:FadeFrame(frame2, 1) + + elseif (not CoolTip.active) then + DF:FadeFrame(self, 1) + DF:FadeFrame(frame2, 1) + end + + self:SetScript("OnUpdate", nil) + frame1:SetScript("OnUpdate", nil) + end + end + + frame2:SetScript("OnLeave", function(self) + if (CoolTip.Type ~= 1 and CoolTip.Type ~= 2) then + CoolTip.active = false + CoolTip.mouseOver = false + elapsedTime = 0 + self:SetScript("OnUpdate", OnLeaveUpdateFrame2) + else + CoolTip.active = false + CoolTip.mouseOver = false + elapsedTime = 0 + self:SetScript("OnUpdate", OnLeaveUpdateFrame2) + end + end) + + frame1:SetScript("OnHide", function(self) + CoolTip.active = false + CoolTip.buttonClicked = false + CoolTip.mouseOver = false + --reset parent and strata + frame1:SetParent(UIParent) + frame2:SetParent(UIParent) + frame1:SetFrameStrata("TOOLTIP") + frame2:SetFrameStrata("TOOLTIP") + end) + +---------------------------------------------------------------------- + --Button Creation Functions +---------------------------------------------------------------------- + --self is the new button created + local createButtonWidgets = function(self) + self:SetSize(1, 20) + + --status bar + self.statusbar = CreateFrame("StatusBar", "$Parent_StatusBar", self) + self.statusbar:SetPoint("LEFT", self, "LEFT", 10, 0) + self.statusbar:SetPoint("RIGHT", self, "RIGHT", -10, 0) + self.statusbar:SetPoint("TOP", self, "TOP", 0, 0) + self.statusbar:SetPoint("BOTTOM", self, "BOTTOM", 0, 0) + self.statusbar:SetHeight(20) + + local statusbar = self.statusbar + + statusbar.texture = statusbar:CreateTexture("$parent_Texture", "BACKGROUND") + statusbar.texture:SetTexture("Interface\\PaperDollInfoFrame\\UI-Character-Skills-Bar") + statusbar.texture:SetSize(300, 14) + statusbar:SetStatusBarTexture (statusbar.texture) + statusbar:SetMinMaxValues (0, 100) + + statusbar.spark = statusbar:CreateTexture("$parent_Spark", "BACKGROUND") + statusbar.spark:Hide() + statusbar.spark:SetTexture("Interface\\CastingBar\\UI-CastingBar-Spark") + statusbar.spark:SetBlendMode("ADD") + statusbar.spark:SetSize(12, 24) + statusbar.spark:SetPoint("LEFT", statusbar, "RIGHT", -20, -1) + + statusbar.background = statusbar:CreateTexture("$parent_Background", "ARTWORK") + statusbar.background:Hide() + statusbar.background:SetTexture("Interface\\FriendsFrame\\UI-FriendsFrame-HighlightBar") + statusbar.background:SetPoint("LEFT", statusbar, "LEFT", -6, 0) + statusbar.background:SetPoint("RIGHT", statusbar, "RIGHT", 6, 0) + statusbar.background:SetPoint("TOP", statusbar, "TOP", 0, 0) + statusbar.background:SetPoint("BOTTOM", statusbar, "BOTTOM", 0, 0) + + self.background = statusbar.background + + statusbar.leftIcon = statusbar:CreateTexture("$parent_LeftIcon", "OVERLAY") + statusbar.leftIcon:SetSize(16, 16) + statusbar.leftIcon:SetPoint("LEFT", statusbar, "LEFT", 0, 0) + + statusbar.rightIcon = statusbar:CreateTexture("$parent_RightIcon", "OVERLAY") + statusbar.rightIcon:SetSize(16, 16) + statusbar.rightIcon:SetPoint("RIGHT", statusbar, "RIGHT", 0, 0) + + statusbar.spark2 = statusbar:CreateTexture("$parent_Spark2", "OVERLAY") + statusbar.spark2:SetSize(32, 32) + statusbar.spark2:SetPoint("LEFT", statusbar, "RIGHT", -17, -1) + statusbar.spark2:SetBlendMode("ADD") + statusbar.spark2:SetTexture("Interface\\CastingBar\\UI-CastingBar-Spark") + statusbar.spark2:Hide() + + statusbar.subMenuArrow = statusbar:CreateTexture("$parent_SubMenuArrow", "OVERLAY") + statusbar.subMenuArrow:SetSize(12, 12) + statusbar.subMenuArrow:SetPoint("RIGHT", statusbar, "RIGHT", 3, 0) + statusbar.subMenuArrow:SetBlendMode("ADD") + statusbar.subMenuArrow:SetTexture("Interface\\CHATFRAME\\ChatFrameExpandArrow") + statusbar.subMenuArrow:Hide() + + statusbar.leftText = statusbar:CreateFontString("$parent_LeftText", "OVERLAY", "GameTooltipHeaderText") + statusbar.leftText:SetJustifyH("LEFT") + statusbar.leftText:SetPoint("LEFT", statusbar.leftIcon, "RIGHT", 3, 0) + DF:SetFontSize(statusbar.leftText, 10) + + statusbar.rightText = statusbar:CreateFontString("$parent_TextRight", "OVERLAY", "GameTooltipHeaderText") + statusbar.rightText:SetJustifyH("RIGHT") + statusbar.rightText:SetPoint("RIGHT", statusbar.rightIcon, "LEFT", -3, 0) + DF:SetFontSize(statusbar.leftText, 10) + + --background status bar + self.statusbar2 = CreateFrame("StatusBar", "$Parent_StatusBarBackground", self) + self.statusbar2:SetPoint("LEFT", self.statusbar, "LEFT") + self.statusbar2:SetPoint("RIGHT", self.statusbar, "RIGHT") + self.statusbar2:SetPoint("TOP", self.statusbar, "TOP") + self.statusbar2:SetPoint("BOTTOM", self.statusbar, "BOTTOM") + + local statusbar2 = self.statusbar2 + statusbar2.texture = statusbar2:CreateTexture("$parent_Texture", "BACKGROUND") + statusbar2.texture:SetTexture("Interface\\PaperDollInfoFrame\\UI-Character-Skills-Bar") + statusbar2.texture:SetSize(300, 14) + statusbar2:SetStatusBarTexture (statusbar2.texture) + statusbar2:SetMinMaxValues (0, 100) + + --on load + self:RegisterForClicks("LeftButtonDown") + self.leftIcon = self.statusbar.leftIcon + self.rightIcon = self.statusbar.rightIcon + self.texture = self.statusbar.texture + self.spark = self.statusbar.spark + self.spark2 = self.statusbar.spark2 + self.leftText = self.statusbar.leftText + self.rightText = self.statusbar.rightText + self.statusbar:SetFrameLevel(self:GetFrameLevel()+2) + self.statusbar2:SetFrameLevel(self.statusbar:GetFrameLevel()-1) + self.statusbar2:SetValue(0) + + --scripts + self:SetScript("OnMouseDown", GameCooltipButtonMouseDown) + self:SetScript("OnMouseUp", GameCooltipButtonMouseUp) + end + + function GameCooltipButtonMouseDown(button) + local heightMod = CoolTip.OptionsTable.TextHeightMod or 0 + button.leftText:SetPoint("center", button.leftIcon, "center", 0, 0 + heightMod) + button.leftText:SetPoint("left", button.leftIcon, "right", 4, -1 + heightMod) + end + + function GameCooltipButtonMouseUp(button) + local heightMod = CoolTip.OptionsTable.TextHeightMod or 0 + button.leftText:SetPoint("center", button.leftIcon, "center", 0, 0 + heightMod) + button.leftText:SetPoint("left", button.leftIcon, "right", 3, 0 + heightMod) + end + + function CoolTip:CreateButton(index, frame, name) + local newNutton = CreateFrame("Button", name, frame) + createButtonWidgets (newNutton) + frame.Lines[index] = newNutton + return newNutton + end + + local OnEnterUpdateButton = function(self, deltaTime) + elapsedTime = elapsedTime + deltaTime + if (elapsedTime > 0.001) then + --search key: ~onenterupdatemain + CoolTip:ShowSub(self.index) + CoolTip.lastButtonInteracted = self.index + self:SetScript("OnUpdate", nil) + end + end + + local OnLeaveUpdateButton = function(self, deltaTime) + elapsedTime = elapsedTime + deltaTime + if (elapsedTime > 0.7) then + if (not CoolTip.active and not CoolTip.buttonClicked) then + DF:FadeFrame(frame1, 1) + DF:FadeFrame(frame2, 1) + elseif (not CoolTip.active) then + DF:FadeFrame(frame1, 1) + DF:FadeFrame(frame2, 1) + end + frame1:SetScript("OnUpdate", nil) + end + end + + local OnEnterMainButton = function(self) + if (CoolTip.Type ~= 1 and CoolTip.Type ~= 2 and not self.isDiv) then + CoolTip.active = true + CoolTip.mouseOver = true + CoolTip.hadInteractions = true + + frame1:SetScript("OnUpdate", nil) + frame2:SetScript("OnUpdate", nil) + + self.background:Show() + + if (CoolTip.OptionsTable.IconBlendModeHover) then + self.leftIcon:SetBlendMode(CoolTip.OptionsTable.IconBlendModeHover) + else + self.leftIcon:SetBlendMode("BLEND") + end + + if (CoolTip.PopupFrameTable[self.index]) then + local onEnter, onLeave, param1, param2 = unpack(CoolTip.PopupFrameTable[self.index]) + if (onEnter) then + xpcall(onEnter, geterrorhandler(), frame1, param1, param2) + end + + elseif (CoolTip.IndexesSub[self.index] and CoolTip.IndexesSub[self.index] > 0) then + if (CoolTip.OptionsTable.SubMenuIsTooltip) then + CoolTip:ShowSub(self.index) + self.index = self.ID + else + if (CoolTip.lastButtonInteracted) then + CoolTip:ShowSub(CoolTip.lastButtonInteracted) + else + CoolTip:ShowSub(self.index) + end + elapsedTime = 0 + self.index = self.ID + self:SetScript("OnUpdate", OnEnterUpdateButton) + end + else + --hide second frame + DF:FadeFrame(frame2, 1) + CoolTip.lastButtonInteracted = nil end else - frame2 = GameCooltipFrame2 + CoolTip.mouseOver = true + CoolTip.hadInteractions = true end - - --> build widgets for frame - build_main_frame (frame2) + end - frame2:SetPoint ("bottomleft", frame1, "bottomright", 4, 0) - - --is this still in use? - GameCooltipFrame2_FrameBackgroundCenter:SetTexture ([[Interface\Tooltips\UI-Tooltip-Background]]) - GameCooltipFrame2_FrameBackgroundCenter:SetTexCoord (0.10546875, 0.89453125, 0, 1) - GameCooltipFrame2_FrameBackgroundLeft:SetTexture ([[Interface\Tooltips\UI-Tooltip-Background]]) - GameCooltipFrame2_FrameBackgroundLeft:SetTexCoord (0, 0.103515625, 0, 1) - GameCooltipFrame2_FrameBackgroundRight:SetTexture ([[Interface\Tooltips\UI-Tooltip-Background]]) - GameCooltipFrame2_FrameBackgroundRight:SetTexCoord (0.896484375, 1, 0, 1) - - CoolTip.frame1 = frame1 - CoolTip.frame2 = frame2 - DF:FadeFrame (frame1, 0) - DF:FadeFrame (frame2, 0) - - --> line container - frame1.Lines = {} - frame2.Lines = {} - ----------------------------------------------------------------------- - --> Title Function ----------------------------------------------------------------------- - - function CoolTip:SetTitle (_f, text) - if (_f == 1) then - CoolTip.title1 = true - CoolTip.title_text = text - end - end - - function CoolTip:SetTitleAnchor (_f, _anchor, ...) - _anchor = string.lower (_anchor) - if (_f == 1) then - self.frame1.titleIcon:ClearAllPoints() - self.frame1.titleText:ClearAllPoints() - - if (_anchor == "left") then - self.frame1.titleIcon:SetPoint ("left", frame1, "left", ...) - self.frame1.titleText:SetPoint ("left", frame1.titleIcon, "right") - - elseif (_anchor == "center") then - self.frame1.titleIcon:SetPoint ("center", frame1, "center") - self.frame1.titleIcon:SetPoint ("bottom", frame1, "top") - self.frame1.titleText:SetPoint ("left", frame1.titleIcon, "right") - self.frame1.titleText:SetText ("TESTE") - - self.frame1.titleText:Show() - self.frame1.titleIcon:Show() - - elseif (_anchor == "right") then - self.frame1.titleIcon:SetPoint ("right", frame1, "right", ...) - self.frame1.titleText:SetPoint ("right", frame1.titleIcon, "left") - - end - elseif (_f == 2) then - self.frame2.titleIcon:ClearAllPoints() - self.frame2.titleText:ClearAllPoints() - if (_anchor == "left") then - self.frame2.titleIcon:SetPoint ("left", frame2, "left", ...) - self.frame2.titleText:SetPoint ("left", frame2.titleIcon, "right") - elseif (_anchor == "center") then - self.frame2.titleIcon:SetPoint ("center", frame2, "center", ...) - self.frame2.titleText:SetPoint ("left", frame2.titleIcon, "right") - elseif (_anchor == "right") then - self.frame2.titleIcon:SetPoint ("right", frame2, "right", ...) - self.frame2.titleText:SetPoint ("right", frame2.titleIcon, "left") - end - end - end - ----------------------------------------------------------------------- - --> Button Hide and Show Functions ----------------------------------------------------------------------- - - local elapsedTime = 0 - - CoolTip.mouseOver = false - CoolTip.buttonClicked = false - - frame1:SetScript ("OnEnter", function (self) - --> is cooltip a menu? - if (CoolTip.Type ~= 1 and CoolTip.Type ~= 2) then - CoolTip.active = true - CoolTip.mouseOver = true - CoolTip.had_interaction = true - self:SetScript ("OnUpdate", nil) - DF:FadeFrame (self, 0) - - if (CoolTip.sub_menus) then - DF:FadeFrame (frame2, 0) - end - end - end) - - frame2:SetScript ("OnEnter", function (self) - if (CoolTip.OptionsTable.SubMenuIsTooltip) then - return CoolTip:Close() - end - if (CoolTip.Type ~= 1 and CoolTip.Type ~= 2) then - CoolTip.active = true - CoolTip.mouseOver = true - CoolTip.had_interaction = true - self:SetScript ("OnUpdate", nil) - DF:FadeFrame (self, 0) - DF:FadeFrame (frame1, 0) - end - end) - - local OnLeaveUpdateFrame1 = function (self, elapsed) - elapsedTime = elapsedTime+elapsed - if (elapsedTime > 0.7) then - if (not CoolTip.active and not CoolTip.buttonClicked and self == CoolTip.Host) then - DF:FadeFrame (self, 1) - DF:FadeFrame (frame2, 1) - elseif (not CoolTip.active) then - DF:FadeFrame (self, 1) - DF:FadeFrame (frame2, 1) - end - self:SetScript ("OnUpdate", nil) - frame2:SetScript ("OnUpdate", nil) - end - end - - frame1:SetScript ("OnLeave", function (self) - - if (CoolTip.Type ~= 1 and CoolTip.Type ~= 2) then - CoolTip.active = false - CoolTip.mouseOver = false - elapsedTime = 0 - self:SetScript ("OnUpdate", OnLeaveUpdateFrame1) - else - CoolTip.active = false - CoolTip.mouseOver = false - elapsedTime = 0 - self:SetScript ("OnUpdate", OnLeaveUpdateFrame1) - end - end) - - local OnLeaveUpdateFrame2 = function (self, elapsed) - elapsedTime = elapsedTime+elapsed - if (elapsedTime > 0.7) then - if (not CoolTip.active and not CoolTip.buttonClicked and self == CoolTip.Host) then - DF:FadeFrame (self, 1) - DF:FadeFrame (frame2, 1) - elseif (not CoolTip.active) then - DF:FadeFrame (self, 1) - DF:FadeFrame (frame2, 1) - end - self:SetScript ("OnUpdate", nil) - frame1:SetScript ("OnUpdate", nil) - end - end - - frame2:SetScript ("OnLeave", function (self) - if (CoolTip.Type ~= 1 and CoolTip.Type ~= 2) then - CoolTip.active = false - CoolTip.mouseOver = false - elapsedTime = 0 - self:SetScript ("OnUpdate", OnLeaveUpdateFrame2) - else - CoolTip.active = false - CoolTip.mouseOver = false - elapsedTime = 0 - self:SetScript ("OnUpdate", OnLeaveUpdateFrame2) - - end - end) - - frame1:SetScript ("OnHide", function (self) + local OnLeaveMainButton = function(self) + if (CoolTip.Type ~= 1 and CoolTip.Type ~= 2 and not self.isDiv) then CoolTip.active = false - CoolTip.buttonClicked = false CoolTip.mouseOver = false - - --> reset parent and strata - frame1:SetParent (UIParent) - frame2:SetParent (UIParent) - frame1:SetFrameStrata ("TOOLTIP") - frame2:SetFrameStrata ("TOOLTIP") - end) - ----------------------------------------------------------------------- - --> Button Creation Functions ----------------------------------------------------------------------- - - local build_button = function (self) - - self:SetSize (1, 20) - - --> status bar - self.statusbar = CreateFrame ("StatusBar", "$Parent_StatusBar", self) - self.statusbar:SetPoint ("LEFT", self, "LEFT", 10, 0) - self.statusbar:SetPoint ("RIGHT", self, "RIGHT", -10, 0) - self.statusbar:SetPoint ("TOP", self, "TOP", 0, 0) - self.statusbar:SetPoint ("BOTTOM", self, "BOTTOM", 0, 0) - self.statusbar:SetHeight (20) + self:SetScript("OnUpdate", nil) - local statusbar = self.statusbar - - statusbar.texture = statusbar:CreateTexture ("$parent_Texture", "BACKGROUND") - statusbar.texture:SetTexture ("Interface\\PaperDollInfoFrame\\UI-Character-Skills-Bar") - statusbar.texture:SetSize (300, 14) - statusbar:SetStatusBarTexture (statusbar.texture) - statusbar:SetMinMaxValues (0, 100) - - statusbar.spark = statusbar:CreateTexture ("$parent_Spark", "BACKGROUND") - statusbar.spark:Hide() - statusbar.spark:SetTexture ("Interface\\CastingBar\\UI-CastingBar-Spark") - statusbar.spark:SetBlendMode ("ADD") - statusbar.spark:SetSize (12, 24) - statusbar.spark:SetPoint ("LEFT", statusbar, "RIGHT", -20, -1) - - statusbar.background = statusbar:CreateTexture ("$parent_Background", "ARTWORK") - statusbar.background:Hide() - statusbar.background:SetTexture ("Interface\\FriendsFrame\\UI-FriendsFrame-HighlightBar") - statusbar.background:SetPoint ("LEFT", statusbar, "LEFT", -6, 0) - statusbar.background:SetPoint ("RIGHT", statusbar, "RIGHT", 6, 0) - statusbar.background:SetPoint ("TOP", statusbar, "TOP", 0, 0) - statusbar.background:SetPoint ("BOTTOM", statusbar, "BOTTOM", 0, 0) - - self.background = statusbar.background - - statusbar.leftIcon = statusbar:CreateTexture ("$parent_LeftIcon", "OVERLAY") - statusbar.leftIcon:SetSize (16, 16) - statusbar.leftIcon:SetPoint ("LEFT", statusbar, "LEFT", 0, 0) - - statusbar.rightIcon = statusbar:CreateTexture ("$parent_RightIcon", "OVERLAY") - statusbar.rightIcon:SetSize (16, 16) - statusbar.rightIcon:SetPoint ("RIGHT", statusbar, "RIGHT", 0, 0) - - statusbar.spark2 = statusbar:CreateTexture ("$parent_Spark2", "OVERLAY") - statusbar.spark2:SetSize (32, 32) - statusbar.spark2:SetPoint ("LEFT", statusbar, "RIGHT", -17, -1) - statusbar.spark2:SetBlendMode ("ADD") - statusbar.spark2:SetTexture ("Interface\\CastingBar\\UI-CastingBar-Spark") - statusbar.spark2:Hide() - - statusbar.subMenuArrow = statusbar:CreateTexture ("$parent_SubMenuArrow", "OVERLAY") - statusbar.subMenuArrow:SetSize (12, 12) - statusbar.subMenuArrow:SetPoint ("RIGHT", statusbar, "RIGHT", 3, 0) - statusbar.subMenuArrow:SetBlendMode ("ADD") - statusbar.subMenuArrow:SetTexture ("Interface\\CHATFRAME\\ChatFrameExpandArrow") - statusbar.subMenuArrow:Hide() - - statusbar.leftText = statusbar:CreateFontString ("$parent_LeftText", "OVERLAY", "GameTooltipHeaderText") - statusbar.leftText:SetJustifyH ("LEFT") - statusbar.leftText:SetPoint ("LEFT", statusbar.leftIcon, "RIGHT", 3, 0) - DF:SetFontSize (statusbar.leftText, 10) - - statusbar.rightText = statusbar:CreateFontString ("$parent_TextRight", "OVERLAY", "GameTooltipHeaderText") - statusbar.rightText:SetJustifyH ("RIGHT") - statusbar.rightText:SetPoint ("RIGHT", statusbar.rightIcon, "LEFT", -3, 0) - DF:SetFontSize (statusbar.leftText, 10) + self.background:Hide() - --> background status bar - self.statusbar2 = CreateFrame ("StatusBar", "$Parent_StatusBarBackground", self) - self.statusbar2:SetPoint ("LEFT", self.statusbar, "LEFT") - self.statusbar2:SetPoint ("RIGHT", self.statusbar, "RIGHT") - self.statusbar2:SetPoint ("TOP", self.statusbar, "TOP") - self.statusbar2:SetPoint ("BOTTOM", self.statusbar, "BOTTOM") - - local statusbar2 = self.statusbar2 - - statusbar2.texture = statusbar2:CreateTexture ("$parent_Texture", "BACKGROUND") - statusbar2.texture:SetTexture ("Interface\\PaperDollInfoFrame\\UI-Character-Skills-Bar") - statusbar2.texture:SetSize (300, 14) - statusbar2:SetStatusBarTexture (statusbar2.texture) - statusbar2:SetMinMaxValues (0, 100) - - --> on load - self:RegisterForClicks ("LeftButtonDown") - self.leftIcon = self.statusbar.leftIcon - self.rightIcon = self.statusbar.rightIcon - self.texture = self.statusbar.texture - self.spark = self.statusbar.spark - self.spark2 = self.statusbar.spark2 - self.leftText = self.statusbar.leftText - self.rightText = self.statusbar.rightText - self.statusbar:SetFrameLevel (self:GetFrameLevel()+2) - self.statusbar2:SetFrameLevel (self.statusbar:GetFrameLevel()-1) - self.statusbar2:SetValue (0) - - --> scripts - self:SetScript ("OnMouseDown", GameCooltipButtonMouseDown) - self:SetScript ("OnMouseUp", GameCooltipButtonMouseUp) - - end - - function GameCooltipButtonMouseDown (button) - local mod = CoolTip.OptionsTable.TextHeightMod or 0 - button.leftText:SetPoint ("center", button.leftIcon, "center", 0, 0+mod) - button.leftText:SetPoint ("left", button.leftIcon, "right", 4, -1+mod) - end - - function GameCooltipButtonMouseUp (button) - local mod = CoolTip.OptionsTable.TextHeightMod or 0 - button.leftText:SetPoint ("center", button.leftIcon, "center", 0, 0+mod) - button.leftText:SetPoint ("left", button.leftIcon, "right", 3, 0+mod) - end - - function CoolTip:CreateButton (index, frame, name) - local new_button = CreateFrame ("Button", name, frame) - build_button (new_button) - - frame.Lines [index] = new_button - return new_button - end - - local OnEnterUpdateButton = function (self, elapsed) - elapsedTime = elapsedTime+elapsed - if (elapsedTime > 0.001) then - --> search key: ~onenterupdatemain - CoolTip:ShowSub (self.index) - CoolTip.last_button = self.index - self:SetScript ("OnUpdate", nil) - end - end - - local OnLeaveUpdateButton = function (self, elapsed) - elapsedTime = elapsedTime+elapsed - if (elapsedTime > 0.7) then - if (not CoolTip.active and not CoolTip.buttonClicked) then - DF:FadeFrame (frame1, 1) - DF:FadeFrame (frame2, 1) - - elseif (not CoolTip.active) then - DF:FadeFrame (frame1, 1) - DF:FadeFrame (frame2, 1) - end - frame1:SetScript ("OnUpdate", nil) - end - end - - local OnEnterMainButton = function (self) - if (CoolTip.Type ~= 1 and CoolTip.Type ~= 2 and not self.isDiv) then - CoolTip.active = true - CoolTip.mouseOver = true - CoolTip.had_interaction = true - - frame1:SetScript ("OnUpdate", nil) - frame2:SetScript ("OnUpdate", nil) - - self.background:Show() - - if (CoolTip.OptionsTable.IconBlendModeHover) then - self.leftIcon:SetBlendMode (CoolTip.OptionsTable.IconBlendModeHover) - else - self.leftIcon:SetBlendMode ("BLEND") - end - - if (CoolTip.PopupFrameTable [self.index]) then - local on_enter, on_leave, param1, param2 = unpack (CoolTip.PopupFrameTable [self.index]) - if (on_enter) then - xpcall (on_enter, geterrorhandler(), frame1, param1, param2) - end - - elseif (CoolTip.IndexesSub [self.index] and CoolTip.IndexesSub [self.index] > 0) then - if (CoolTip.OptionsTable.SubMenuIsTooltip) then - CoolTip:ShowSub (self.index) - self.index = self.ID - else - if (CoolTip.last_button) then - CoolTip:ShowSub (CoolTip.last_button) - else - CoolTip:ShowSub (self.index) - end - elapsedTime = 0 - self.index = self.ID - self:SetScript ("OnUpdate", OnEnterUpdateButton) - end - - else - --hide second frame - DF:FadeFrame (frame2, 1) - CoolTip.last_button = nil - end + if (CoolTip.OptionsTable.IconBlendMode) then + self.leftIcon:SetBlendMode(CoolTip.OptionsTable.IconBlendMode) + self.rightIcon:SetBlendMode(CoolTip.OptionsTable.IconBlendMode) else - CoolTip.mouseOver = true - CoolTip.had_interaction = true + self.leftIcon:SetBlendMode("BLEND") + self.rightIcon:SetBlendMode("BLEND") end + + if (CoolTip.PopupFrameTable[self.index]) then + local onEnter, onLeave, param1, param2 = unpack(CoolTip.PopupFrameTable[self.index]) + if (onLeave) then + xpcall(onLeave, geterrorhandler(), frame1, param1, param2) + end + end + + elapsedTime = 0 + frame1:SetScript("OnUpdate", OnLeaveUpdateButton) + else + CoolTip.active = false + elapsedTime = 0 + frame1:SetScript("OnUpdate", OnLeaveUpdateButton) + CoolTip.mouseOver = false end - - local OnLeaveMainButton = function (self) - if (CoolTip.Type ~= 1 and CoolTip.Type ~= 2 and not self.isDiv) then - CoolTip.active = false - CoolTip.mouseOver = false - self:SetScript ("OnUpdate", nil) - - self.background:Hide() - - if (CoolTip.OptionsTable.IconBlendMode) then - self.leftIcon:SetBlendMode (CoolTip.OptionsTable.IconBlendMode) - self.rightIcon:SetBlendMode (CoolTip.OptionsTable.IconBlendMode) - else - self.leftIcon:SetBlendMode ("BLEND") - self.rightIcon:SetBlendMode ("BLEND") - end - - if (CoolTip.PopupFrameTable [self.index]) then - local on_enter, on_leave, param1, param2 = unpack (CoolTip.PopupFrameTable [self.index]) - if (on_leave) then - xpcall (on_leave, geterrorhandler(), frame1, param1, param2) - end - end - - elapsedTime = 0 - frame1:SetScript ("OnUpdate", OnLeaveUpdateButton) + end + + --serach key: ~onenter + function CoolTip:CreateMainFrameButton(i) + local newButton = CoolTip:CreateButton(i, frame1, "GameCooltipMainButton" .. i) + newButton.ID = i + newButton:SetScript("OnEnter", OnEnterMainButton) + newButton:SetScript("OnLeave", OnLeaveMainButton) + return newButton + end + + --buttons for the secondary frame + local OnLeaveUpdateButtonSec = function(self, deltaTime) + elapsedTime = elapsedTime + deltaTime + if (elapsedTime > 0.7) then + if (not CoolTip.active and not CoolTip.buttonClicked) then + DF:FadeFrame(frame1, 1) + DF:FadeFrame(frame2, 1) + elseif (not CoolTip.active) then + DF:FadeFrame(frame1, 1) + DF:FadeFrame(frame2, 1) + end + frame2:SetScript("OnUpdate", nil) + end + end + + local OnEnterSecondaryButton = function(self) + if (CoolTip.OptionsTable.SubMenuIsTooltip) then + return CoolTip:Close() + end + + if (CoolTip.Type ~= 1 and CoolTip.Type ~= 2 and not self.isDiv) then + CoolTip.active = true + CoolTip.mouseOver = true + CoolTip.hadInteractions = true + + self.background:Show() + + if (CoolTip.OptionsTable.IconBlendModeHover) then + self.leftIcon:SetBlendMode(CoolTip.OptionsTable.IconBlendModeHover) else - CoolTip.active = false - elapsedTime = 0 - frame1:SetScript ("OnUpdate", OnLeaveUpdateButton) - CoolTip.mouseOver = false + self.leftIcon:SetBlendMode("BLEND") end + + frame1:SetScript("OnUpdate", nil) + frame2:SetScript("OnUpdate", nil) + + DF:FadeFrame(frame1, 0) + DF:FadeFrame(frame2, 0) + else + CoolTip.mouseOver = true + CoolTip.hadInteractions = true end - - function CoolTip:NewMainButton (i) - local newButton = CoolTip:CreateButton (i, frame1, "GameCooltipMainButton"..i) - - --> serach key: ~onenter - newButton.ID = i - newButton:SetScript ("OnEnter", OnEnterMainButton) - newButton:SetScript ("OnLeave", OnLeaveMainButton) - - return newButton - end - - --> buttons for the secondary frame - - local OnLeaveUpdateButtonSec = function (self, elapsed) - elapsedTime = elapsedTime+elapsed - if (elapsedTime > 0.7) then - if (not CoolTip.active and not CoolTip.buttonClicked) then - DF:FadeFrame (frame1, 1) - DF:FadeFrame (frame2, 1) - elseif (not CoolTip.active) then - DF:FadeFrame (frame1, 1) - DF:FadeFrame (frame2, 1) - end - frame2:SetScript ("OnUpdate", nil) - end - end - - local OnEnterSecondaryButton = function (self) - if (CoolTip.OptionsTable.SubMenuIsTooltip) then - return CoolTip:Close() - end - if (CoolTip.Type ~= 1 and CoolTip.Type ~= 2 and not self.isDiv) then - CoolTip.active = true - CoolTip.mouseOver = true - CoolTip.had_interaction = true - - self.background:Show() - - if (CoolTip.OptionsTable.IconBlendModeHover) then - self.leftIcon:SetBlendMode (CoolTip.OptionsTable.IconBlendModeHover) - else - self.leftIcon:SetBlendMode ("BLEND") - end - - frame1:SetScript ("OnUpdate", nil) - frame2:SetScript ("OnUpdate", nil) - - DF:FadeFrame (frame1, 0) - DF:FadeFrame (frame2, 0) + end + + local OnLeaveSecondaryButton = function(self) + if (CoolTip.Type ~= 1 and CoolTip.Type ~= 2) then + CoolTip.active = false + CoolTip.mouseOver = false + self.background:Hide() + + if (CoolTip.OptionsTable.IconBlendMode) then + self.leftIcon:SetBlendMode(CoolTip.OptionsTable.IconBlendMode) + self.rightIcon:SetBlendMode(CoolTip.OptionsTable.IconBlendMode) else - CoolTip.mouseOver = true - CoolTip.had_interaction = true + self.leftIcon:SetBlendMode("BLEND") + self.rightIcon:SetBlendMode("BLEND") end + + elapsedTime = 0 + frame2:SetScript("OnUpdate", OnLeaveUpdateButtonSec) + else + CoolTip.active = false + CoolTip.mouseOver = false + elapsedTime = 0 + frame2:SetScript("OnUpdate", OnLeaveUpdateButtonSec) end - - local OnLeaveSecondaryButton = function (self) - if (CoolTip.Type ~= 1 and CoolTip.Type ~= 2) then - CoolTip.active = false - CoolTip.mouseOver = false - - self.background:Hide() - - if (CoolTip.OptionsTable.IconBlendMode) then - self.leftIcon:SetBlendMode (CoolTip.OptionsTable.IconBlendMode) - self.rightIcon:SetBlendMode (CoolTip.OptionsTable.IconBlendMode) - else - self.leftIcon:SetBlendMode ("BLEND") - self.rightIcon:SetBlendMode ("BLEND") - end - - elapsedTime = 0 - frame2:SetScript ("OnUpdate", OnLeaveUpdateButtonSec) - else - CoolTip.active = false - CoolTip.mouseOver = false - elapsedTime = 0 - frame2:SetScript ("OnUpdate", OnLeaveUpdateButtonSec) - end - end - - function CoolTip:NewSecondaryButton (i) - local newButton = CoolTip:CreateButton (i, frame2, "GameCooltipSecButton"..i) - - newButton.ID = i - newButton:SetScript ("OnEnter", OnEnterSecondaryButton) - newButton:SetScript ("OnLeave", OnLeaveSecondaryButton) - - return newButton - end - + end + + function CoolTip:CreateButtonOnSecondFrame(i) + local newButton = CoolTip:CreateButton(i, frame2, "GameCooltipSecButton" .. i) + newButton.ID = i + newButton:SetScript("OnEnter", OnEnterSecondaryButton) + newButton:SetScript("OnLeave", OnLeaveSecondaryButton) + return newButton + end + ---------------------------------------------------------------------- - --> Button Click Functions + --Button Click Functions ---------------------------------------------------------------------- - - CoolTip.selected_anchor.left = 4 - CoolTip.selected_anchor.right = -4 - CoolTip.selected_anchor.top = 0 - CoolTip.selected_anchor.bottom = 0 - - function CoolTip:HideSelectedTexture (frame) - frame.selectedTop:Hide() - frame.selectedBottom:Hide() - frame.selectedMiddle:Hide() - end - - function CoolTip:ShowSelectedTexture (frame) - frame.selectedTop:Show() - frame.selectedBottom:Show() - frame.selectedMiddle:Show() - end - - function CoolTip:SetSelectedAnchor (frame, button) + CoolTip.selectedAnchor.left = 4 + CoolTip.selectedAnchor.right = -4 + CoolTip.selectedAnchor.top = 0 + CoolTip.selectedAnchor.bottom = 0 - local left = CoolTip.selected_anchor.left + (CoolTip.OptionsTable.SelectedLeftAnchorMod or 0) - local right = CoolTip.selected_anchor.right + (CoolTip.OptionsTable.SelectedRightAnchorMod or 0) - - local top = CoolTip.selected_anchor.top + (CoolTip.OptionsTable.SelectedTopAnchorMod or 0) - local bottom = CoolTip.selected_anchor.bottom + (CoolTip.OptionsTable.SelectedBottomAnchorMod or 0) - - frame.selectedTop:ClearAllPoints() - frame.selectedBottom:ClearAllPoints() - - frame.selectedTop:SetPoint ("topleft", button, "topleft", left+1, top) -- - frame.selectedTop:SetPoint ("topright", button, "topright", right-1, top) -- - - frame.selectedBottom:SetPoint ("bottomleft", button, "bottomleft", left+1, bottom) -- - frame.selectedBottom:SetPoint ("bottomright", button, "bottomright", right-1, bottom) -- + function CoolTip:HideSelectedTexture(frame) + frame.selectedTop:Hide() + frame.selectedBottom:Hide() + frame.selectedMiddle:Hide() + end - CoolTip:ShowSelectedTexture (frame) + function CoolTip:ShowSelectedTexture(frame) + frame.selectedTop:Show() + frame.selectedBottom:Show() + frame.selectedMiddle:Show() + end + + function CoolTip:SetSelectedAnchor(frame, button) + local left = CoolTip.selectedAnchor.left + (CoolTip.OptionsTable.SelectedLeftAnchorMod or 0) + local right = CoolTip.selectedAnchor.right + (CoolTip.OptionsTable.SelectedRightAnchorMod or 0) + + local top = CoolTip.selectedAnchor.top + (CoolTip.OptionsTable.SelectedTopAnchorMod or 0) + local bottom = CoolTip.selectedAnchor.bottom + (CoolTip.OptionsTable.SelectedBottomAnchorMod or 0) + + frame.selectedTop:ClearAllPoints() + frame.selectedBottom:ClearAllPoints() + + frame.selectedTop:SetPoint("topleft", button, "topleft", left+1, top) + frame.selectedTop:SetPoint("topright", button, "topright", right-1, top) + frame.selectedBottom:SetPoint("bottomleft", button, "bottomleft", left+1, bottom) + frame.selectedBottom:SetPoint("bottomright", button, "bottomright", right-1, bottom) + + CoolTip:ShowSelectedTexture(frame) + end + + local OnClickFunctionMainButton = function(self, button) + if (CoolTip.IndexesSub[self.index] and CoolTip.IndexesSub[self.index] > 0) then + CoolTip:ShowSub(self.index) + CoolTip.lastButtonInteracted = self.index end - - local OnClickFunctionMainButton = function (self, button) - if (CoolTip.IndexesSub [self.index] and CoolTip.IndexesSub [self.index] > 0) then - CoolTip:ShowSub (self.index) - CoolTip.last_button = self.index - end - - CoolTip.buttonClicked = true - CoolTip:SetSelectedAnchor (frame1, self) - - if (not CoolTip.OptionsTable.NoLastSelectedBar) then - CoolTip:ShowSelectedTexture (frame1) - end - CoolTip.SelectedIndexMain = self.index - - if (CoolTip.FunctionsTableMain [self.index]) then - local parameterTable = CoolTip.ParametersTableMain [self.index] - local func = CoolTip.FunctionsTableMain [self.index] - --> passing nil as the first parameter was a design mistake - --CoolTip.FunctionsTableMain [self.index] (_, CoolTip.FixedValue, parameterTable [1], parameterTable [2], parameterTable [3], button) - local okay, errortext = pcall (func, CoolTip.Host, CoolTip.FixedValue, parameterTable [1], parameterTable [2], parameterTable [3], button) - if (not okay) then - print ("Cooltip OnClick Error:", errortext) - end + + CoolTip.buttonClicked = true + CoolTip:SetSelectedAnchor(frame1, self) + + if (not CoolTip.OptionsTable.NoLastSelectedBar) then + CoolTip:ShowSelectedTexture(frame1) + end + CoolTip.SelectedIndexMain = self.index + + if (CoolTip.FunctionsTableMain[self.index]) then + local parameterTable = CoolTip.ParametersTableMain[self.index] + local func = CoolTip.FunctionsTableMain[self.index] + local okay, errortext = pcall(func, CoolTip.Host, CoolTip.FixedValue, parameterTable[1], parameterTable[2], parameterTable[3], button) + if (not okay) then + print ("Cooltip OnClick Error:", errortext) end end - - local OnClickFunctionSecondaryButton = function (self, button) - CoolTip.buttonClicked = true - - CoolTip:SetSelectedAnchor (frame2, self) - - if (CoolTip.FunctionsTableSub [self.mainIndex] and CoolTip.FunctionsTableSub [self.mainIndex] [self.index]) then - local parameterTable = CoolTip.ParametersTableSub [self.mainIndex] [self.index] - local func = CoolTip.FunctionsTableSub [self.mainIndex] [self.index] - --CoolTip.FunctionsTableSub [self.mainIndex] [self.index] (_, CoolTip.FixedValue, parameterTable [1], parameterTable [2], parameterTable [3], button) - local okay, errortext = pcall (func, CoolTip.Host, CoolTip.FixedValue, parameterTable [1], parameterTable [2], parameterTable [3], button) - if (not okay) then - print ("Cooltip OnClick Error:", errortext) - end - end - - local botao_p = frame1.Lines [self.mainIndex] - CoolTip:SetSelectedAnchor (frame1, botao_p) + end - if (not CoolTip.OptionsTable.NoLastSelectedBar) then - CoolTip:ShowSelectedTexture (frame1) + local OnClickFunctionSecondaryButton = function(self, button) + CoolTip.buttonClicked = true + CoolTip:SetSelectedAnchor(frame2, self) + + if (CoolTip.FunctionsTableSub[self.mainIndex] and CoolTip.FunctionsTableSub[self.mainIndex][self.index]) then + local parameterTable = CoolTip.ParametersTableSub[self.mainIndex][self.index] + local func = CoolTip.FunctionsTableSub[self.mainIndex][self.index] + local okay, errortext = pcall(func, CoolTip.Host, CoolTip.FixedValue, parameterTable[1], parameterTable[2], parameterTable[3], button) + if (not okay) then + print("Cooltip OnClick Error:", errortext) end - - CoolTip.SelectedIndexMain = self.mainIndex - CoolTip.SelectedIndexSec [self.mainIndex] = self.index end - - - --> format functions - - function CoolTip:TextAndIcon (index, frame, menuButton, leftTextTable, rightTextTable, leftIconTable, rightIconTable, isSub) - --> reset width - menuButton.leftText:SetWidth (0) - menuButton.leftText:SetHeight (0) - menuButton.rightText:SetWidth (0) - menuButton.rightText:SetHeight (0) - menuButton.rightText:SetPoint ("right", menuButton.rightIcon, "left", CoolTip.OptionsTable.RightTextMargin or -3, 0) + CoolTip:SetSelectedAnchor(frame1, frame1.Lines[self.mainIndex]) - --> set text - if (leftTextTable) then - - menuButton.leftText:SetText (leftTextTable [1]) - - local r, g, b, a = leftTextTable [2], leftTextTable [3], leftTextTable [4], leftTextTable [5] - - if (r == 0 and g == 0 and b == 0 and a == 0) then - if (CoolTip.OptionsTable.TextColor) then - r, g, b, a = DF:ParseColors (CoolTip.OptionsTable.TextColor) - DF:SetFontColor(menuButton.leftText, r, g, b, a) - else - menuButton.leftText:SetTextColor (1, 1, 1, 1) - end - else + if (not CoolTip.OptionsTable.NoLastSelectedBar) then + CoolTip:ShowSelectedTexture(frame1) + end + + CoolTip.SelectedIndexMain = self.mainIndex + CoolTip.SelectedIndexSec[self.mainIndex] = self.index + end + + function CoolTip:TextAndIcon(index, frame, menuButton, leftTextSettings, rightTextSettings, leftIconSettings, rightIconSettings, isSecondFrame) + --reset width + menuButton.leftText:SetWidth(0) + menuButton.leftText:SetHeight(0) + menuButton.rightText:SetWidth(0) + menuButton.rightText:SetHeight(0) + menuButton.rightText:SetPoint("right", menuButton.rightIcon, "left", CoolTip.OptionsTable.RightTextMargin or -3, 0) + + --set text + if (leftTextSettings) then + menuButton.leftText:SetText(leftTextSettings[1]) + local r, g, b, a = leftTextSettings[2], leftTextSettings[3], leftTextSettings[4], leftTextSettings[5] + + if (r == 0 and g == 0 and b == 0 and a == 0) then + if (CoolTip.OptionsTable.TextColor) then + r, g, b, a = DF:ParseColors(CoolTip.OptionsTable.TextColor) DF:SetFontColor(menuButton.leftText, r, g, b, a) - end - - if (CoolTip.OptionsTable.TextSize and not leftTextTable [6]) then - DF:SetFontSize (menuButton.leftText, CoolTip.OptionsTable.TextSize) - end - - if (CoolTip.OptionsTable.LeftTextWidth) then - menuButton.leftText:SetWidth (CoolTip.OptionsTable.LeftTextWidth) else - menuButton.leftText:SetWidth (0) + menuButton.leftText:SetTextColor(1, 1, 1, 1) end - - if (CoolTip.OptionsTable.LeftTextHeight) then - menuButton.leftText:SetHeight (CoolTip.OptionsTable.LeftTextHeight) - else - menuButton.leftText:SetHeight (0) - end - - if (CoolTip.OptionsTable.TextFont and not leftTextTable [7]) then --font - - if (_G [CoolTip.OptionsTable.TextFont]) then - menuButton.leftText:SetFontObject (GameFontRed or CoolTip.OptionsTable.TextFont) - else - local font = SharedMedia:Fetch ("font", CoolTip.OptionsTable.TextFont) - local _, size, flags = menuButton.leftText:GetFont() - flags = leftTextTable [8] or CoolTip.OptionsTable.TextShadow or nil - size = leftTextTable [6] or CoolTip.OptionsTable.TextSize or size - menuButton.leftText:SetFont (font, size, flags) - end - - elseif (leftTextTable [7]) then - if (_G [leftTextTable [7]]) then - menuButton.leftText:SetFontObject (leftTextTable [7]) - local face, size, flags = menuButton.leftText:GetFont() - flags = leftTextTable [8] or CoolTip.OptionsTable.TextShadow or nil - size = leftTextTable [6] or CoolTip.OptionsTable.TextSize or size - menuButton.leftText:SetFont (face, size, flags) - else - local font = SharedMedia:Fetch ("font", leftTextTable [7]) - local face, size, flags = menuButton.leftText:GetFont() - flags = leftTextTable [8] or CoolTip.OptionsTable.TextShadow or nil - size = leftTextTable [6] or CoolTip.OptionsTable.TextSize or size - menuButton.leftText:SetFont (face, size, flags) - end - else - menuButton.leftText:SetFont (CoolTip._default_font, leftTextTable [6] or CoolTip.OptionsTable.TextSize or 10, leftTextTable [8] or CoolTip.OptionsTable.TextShadow) - end - - local height_mod = CoolTip.OptionsTable.TextHeightMod or 0 - menuButton.leftText:SetPoint ("center", menuButton.leftIcon, "center", 0, 0+height_mod) - menuButton.leftText:SetPoint ("left", menuButton.leftIcon, "right", 3, 0+height_mod) - else - menuButton.leftText:SetText ("") + DF:SetFontColor(menuButton.leftText, r, g, b, a) end - if (rightTextTable) then - menuButton.rightText:SetText (rightTextTable [1]) - - local r, g, b, a = rightTextTable [2], rightTextTable [3], rightTextTable [4], rightTextTable [5] - - if (r == 0 and g == 0 and b == 0 and a == 0) then - - if (CoolTip.OptionsTable.TextColorRight) then - r, g, b, a = DF:ParseColors (CoolTip.OptionsTable.TextColorRight) - DF:SetFontColor(menuButton.rightText, r, g, b, a) - elseif (CoolTip.OptionsTable.TextColor) then - r, g, b, a = DF:ParseColors (CoolTip.OptionsTable.TextColor) - DF:SetFontColor(menuButton.rightText, r, g, b, a) - else - menuButton.rightText:SetTextColor (1, 1, 1, 1) - end - else - DF:SetFontColor(menuButton.rightText, r, g, b, a) - end - - if (CoolTip.OptionsTable.TextSize and not rightTextTable [6]) then - DF:SetFontSize (menuButton.rightText, CoolTip.OptionsTable.TextSize) - end - - if (CoolTip.OptionsTable.RightTextWidth) then - menuButton.rightText:SetWidth (CoolTip.OptionsTable.RightTextWidth) - else - menuButton.rightText:SetWidth (0) - end - - if (CoolTip.OptionsTable.TextFont and not rightTextTable [7]) then - if (_G [CoolTip.OptionsTable.TextFont]) then - menuButton.rightText:SetFontObject (CoolTip.OptionsTable.TextFont) - else - local font = SharedMedia:Fetch ("font", CoolTip.OptionsTable.TextFont) - local _, size, flags = menuButton.rightText:GetFont() - flags = rightTextTable [8] or CoolTip.OptionsTable.TextShadow or nil - size = rightTextTable [6] or CoolTip.OptionsTable.TextSize or size - menuButton.rightText:SetFont (font, size, flags) - end - - elseif (rightTextTable [7]) then - if (_G [rightTextTable [7]]) then - menuButton.rightText:SetFontObject (rightTextTable [7]) - local face, size, flags = menuButton.rightText:GetFont() - flags = rightTextTable [8] or CoolTip.OptionsTable.TextShadow or nil - size = rightTextTable [6] or CoolTip.OptionsTable.TextSize or size - menuButton.rightText:SetFont (face, size, flags) - else - local font = SharedMedia:Fetch ("font", rightTextTable [7]) - local face, size, flags = menuButton.rightText:GetFont() - flags = rightTextTable [8] or CoolTip.OptionsTable.TextShadow or nil - size = rightTextTable [6] or CoolTip.OptionsTable.TextSize or size - menuButton.rightText:SetFont (face, size, flags) - end - - else - menuButton.rightText:SetFont (CoolTip._default_font, rightTextTable [6] or CoolTip.OptionsTable.TextSize or 10, rightTextTable [8] or CoolTip.OptionsTable.TextShadow) - end - - - else - menuButton.rightText:SetText ("") + if (CoolTip.OptionsTable.TextSize and not leftTextSettings[6]) then + DF:SetFontSize(menuButton.leftText, CoolTip.OptionsTable.TextSize) end - --> left icon - if (leftIconTable and leftIconTable [1]) then - menuButton.leftIcon:SetTexture (leftIconTable [1]) - menuButton.leftIcon:SetWidth (leftIconTable [2]) - menuButton.leftIcon:SetHeight (leftIconTable [3]) - menuButton.leftIcon:SetTexCoord (leftIconTable [4], leftIconTable [5], leftIconTable [6], leftIconTable [7]) - - local ColorR, ColorG, ColorB, ColorA = DF:ParseColors (leftIconTable [8]) - menuButton.leftIcon:SetVertexColor (ColorR, ColorG, ColorB, ColorA) - - if (CoolTip.OptionsTable.IconBlendMode) then - menuButton.leftIcon:SetBlendMode (CoolTip.OptionsTable.IconBlendMode) - else - menuButton.leftIcon:SetBlendMode ("BLEND") - end - - menuButton.leftIcon:SetDesaturated (leftIconTable [9]) + if (CoolTip.OptionsTable.LeftTextWidth) then + menuButton.leftText:SetWidth(CoolTip.OptionsTable.LeftTextWidth) else - menuButton.leftIcon:SetTexture ("") - menuButton.leftIcon:SetWidth (1) - menuButton.leftIcon:SetHeight (1) - end - - --> right icon - if (rightIconTable and rightIconTable [1]) then - menuButton.rightIcon:SetTexture (rightIconTable [1]) - menuButton.rightIcon:SetWidth (rightIconTable [2]) - menuButton.rightIcon:SetHeight (rightIconTable [3]) - menuButton.rightIcon:SetTexCoord (rightIconTable [4], rightIconTable [5], rightIconTable [6], rightIconTable [7]) - - local ColorR, ColorG, ColorB, ColorA = DF:ParseColors (rightIconTable [8]) - menuButton.rightIcon:SetVertexColor (ColorR, ColorG, ColorB, ColorA) - - if (CoolTip.OptionsTable.IconBlendMode) then - menuButton.rightIcon:SetBlendMode (CoolTip.OptionsTable.IconBlendMode) - else - menuButton.rightIcon:SetBlendMode ("BLEND") - end - - menuButton.rightIcon:SetDesaturated (rightIconTable [9]) - else - menuButton.rightIcon:SetTexture ("") - menuButton.rightIcon:SetWidth (1) - menuButton.rightIcon:SetHeight (1) - end - - --> overwrite icon size - if (CoolTip.OptionsTable.IconSize) then - menuButton.leftIcon:SetWidth (CoolTip.OptionsTable.IconSize) - menuButton.leftIcon:SetHeight (CoolTip.OptionsTable.IconSize) - menuButton.rightIcon:SetWidth (CoolTip.OptionsTable.IconSize) - menuButton.rightIcon:SetHeight (CoolTip.OptionsTable.IconSize) - end - - menuButton.leftText:SetHeight (0) - menuButton.rightText:SetHeight (0) - - if (CoolTip.Type == 2) then - CoolTip:LeftTextSpace (menuButton) + menuButton.leftText:SetWidth(0) end + if (CoolTip.OptionsTable.LeftTextHeight) then - menuButton.leftText:SetHeight (CoolTip.OptionsTable.LeftTextHeight) - end - if (CoolTip.OptionsTable.RightTextHeight) then - menuButton.rightText:SetHeight (CoolTip.OptionsTable.RightTextHeight) - end - - --> string length - if (not isSub) then --> main frame - if (not CoolTip.OptionsTable.FixedWidth) then - if (CoolTip.Type == 1 or CoolTip.Type == 2) then - local stringWidth = menuButton.leftText:GetStringWidth() + menuButton.rightText:GetStringWidth() + menuButton.leftIcon:GetWidth() + menuButton.rightIcon:GetWidth() + 10 - if (stringWidth > frame.w) then - frame.w = stringWidth - end - end - else - menuButton.leftText:SetWidth (CoolTip.OptionsTable.FixedWidth - menuButton.leftIcon:GetWidth() - menuButton.rightText:GetStringWidth() - menuButton.rightIcon:GetWidth() - 22) - end + menuButton.leftText:SetHeight(CoolTip.OptionsTable.LeftTextHeight) else - if (not CoolTip.OptionsTable.FixedWidthSub) then - if (CoolTip.Type == 1 or CoolTip.Type == 2) then - local stringWidth = menuButton.leftText:GetStringWidth() + menuButton.rightText:GetStringWidth() + menuButton.leftIcon:GetWidth() + menuButton.rightIcon:GetWidth() - if (stringWidth > frame.w) then - frame.w = stringWidth - end - end - else - menuButton.leftText:SetWidth (CoolTip.OptionsTable.FixedWidthSub - menuButton.leftIcon:GetWidth() - 12) - end + menuButton.leftText:SetHeight(0) end - - local height = _math_max ( menuButton.leftIcon:GetHeight(), menuButton.rightIcon:GetHeight(), menuButton.leftText:GetStringHeight(), menuButton.rightText:GetStringHeight() ) - if (height > frame.hHeight) then - frame.hHeight = height - end - - end - - function CoolTip:RefreshSpark (menuButton) - menuButton.spark:ClearAllPoints() - menuButton.spark:SetPoint ("LEFT", menuButton.statusbar, "LEFT", (menuButton.statusbar:GetValue() * (menuButton.statusbar:GetWidth() / 100)) - 5, 0) - menuButton.spark2:ClearAllPoints() - menuButton.spark2:SetPoint ("left", menuButton.statusbar, "left", menuButton.statusbar:GetValue() * (menuButton.statusbar:GetWidth()/100) - 16, 0) - end - - function CoolTip:StatusBar (menuButton, StatusBar) - - if (StatusBar) then - - menuButton.statusbar:SetValue (StatusBar [1]) - menuButton.statusbar:SetStatusBarColor (StatusBar [2], StatusBar [3], StatusBar [4], StatusBar [5]) - menuButton.statusbar:SetHeight (20 + (CoolTip.OptionsTable.StatusBarHeightMod or 0)) - - menuButton.spark2:Hide() - if (StatusBar [6]) then - menuButton.spark:Show() - --menuButton.spark:ClearAllPoints() - --menuButton.spark:SetPoint ("LEFT", menuButton.statusbar, "LEFT", (StatusBar [1] * (menuButton.statusbar:GetWidth() / 100)) - 3, 0) - else - menuButton.spark:Hide() - end - - if (StatusBar [7]) then - menuButton.statusbar2:SetValue (StatusBar[7].value) - menuButton.statusbar2.texture:SetTexture (StatusBar[7].texture or [[Interface\RaidFrame\Raid-Bar-Hp-Fill]]) - if (StatusBar[7].specialSpark) then - menuButton.spark2:Show() - end - if (StatusBar[7].color) then - local ColorR, ColorG, ColorB, ColorA = DF:ParseColors (StatusBar[7].color) - menuButton.statusbar2:SetStatusBarColor (ColorR, ColorG, ColorB, ColorA) - else - menuButton.statusbar2:SetStatusBarColor (1, 1, 1, 1) - end - else - menuButton.statusbar2:SetValue (0) - menuButton.spark2:Hide() - end - - if (StatusBar [8]) then - local texture = SharedMedia:Fetch ("statusbar", StatusBar [8], true) - if (texture) then - menuButton.statusbar.texture:SetTexture (texture) - else - menuButton.statusbar.texture:SetTexture (StatusBar [8]) - end - elseif (CoolTip.OptionsTable.StatusBarTexture) then - local texture = SharedMedia:Fetch ("statusbar", CoolTip.OptionsTable.StatusBarTexture, true) - if (texture) then - menuButton.statusbar.texture:SetTexture (texture) - else - menuButton.statusbar.texture:SetTexture (CoolTip.OptionsTable.StatusBarTexture) - end - else - menuButton.statusbar.texture:SetTexture ("Interface\\PaperDollInfoFrame\\UI-Character-Skills-Bar") - end - - --[[ - if (CoolTip.OptionsTable.StatusBarTexture) then - menuButton.statusbar.texture:SetTexture (CoolTip.OptionsTable.StatusBarTexture) - else - menuButton.statusbar.texture:SetTexture ("Interface\\PaperDollInfoFrame\\UI-Character-Skills-Bar") - end - --]] - else - menuButton.statusbar:SetValue (0) - menuButton.statusbar2:SetValue (0) - menuButton.spark:Hide() - menuButton.spark2:Hide() - end - - if (CoolTip.OptionsTable.LeftBorderSize) then - menuButton.statusbar:SetPoint ("left", menuButton, "left", 10 + CoolTip.OptionsTable.LeftBorderSize, 0) - else - menuButton.statusbar:SetPoint ("left", menuButton, "left", 10, 0) - end - - if (CoolTip.OptionsTable.RightBorderSize) then - menuButton.statusbar:SetPoint ("right", menuButton, "right", CoolTip.OptionsTable.RightBorderSize + (- 10), 0) - else - menuButton.statusbar:SetPoint ("right", menuButton, "right", -10, 0) - end - end - - function CoolTip:SetupMainButton (menuButton, index) - menuButton.index = index - - --> setup texts and icons - CoolTip:TextAndIcon (index, frame1, menuButton, CoolTip.LeftTextTable [index], CoolTip.RightTextTable [index], CoolTip.LeftIconTable [index], CoolTip.RightIconTable [index]) - --> setup statusbar - CoolTip:StatusBar (menuButton, CoolTip.StatusBarTable [index]) - --> click - menuButton:RegisterForClicks ("LeftButtonDown") - - --> string length + if (CoolTip.OptionsTable.TextFont and not leftTextSettings[7]) then --font + if (_G[CoolTip.OptionsTable.TextFont]) then + menuButton.leftText:SetFontObject(_G.GameFontRed or CoolTip.OptionsTable.TextFont) + else + local font = SharedMedia:Fetch("font", CoolTip.OptionsTable.TextFont) + local _, size, flags = menuButton.leftText:GetFont() + flags = leftTextSettings[8] or CoolTip.OptionsTable.TextShadow or nil + size = leftTextSettings[6] or CoolTip.OptionsTable.TextSize or size + menuButton.leftText:SetFont(font, size, flags) + end + + elseif (leftTextSettings[7]) then + if (_G[leftTextSettings[7]]) then + menuButton.leftText:SetFontObject(leftTextSettings[7]) + local fontFace, fontSize, fontFlags = menuButton.leftText:GetFont() + fontFlags = leftTextSettings[8] or CoolTip.OptionsTable.TextShadow or nil + fontSize = leftTextSettings[6] or CoolTip.OptionsTable.TextSize or fontSize + menuButton.leftText:SetFont(fontFace, fontSize, fontFlags) + else + local font = SharedMedia:Fetch("font", leftTextSettings[7]) + local fontFace, fontSize, fontFlags = menuButton.leftText:GetFont() + --fontFace = font or fontFace + fontFlags = leftTextSettings[8] or CoolTip.OptionsTable.TextShadow or nil + fontSize = leftTextSettings[6] or CoolTip.OptionsTable.TextSize or fontSize + menuButton.leftText:SetFont(fontFace, fontSize, fontFlags) + end + else + menuButton.leftText:SetFont(CoolTip.defaultFont, leftTextSettings[6] or CoolTip.OptionsTable.TextSize or 10, leftTextSettings[8] or CoolTip.OptionsTable.TextShadow) + end + + local heightMod = CoolTip.OptionsTable.TextHeightMod or 0 + menuButton.leftText:SetPoint("center", menuButton.leftIcon, "center", 0, 0 + heightMod) + menuButton.leftText:SetPoint("left", menuButton.leftIcon, "right", 3, 0 + heightMod) + else + menuButton.leftText:SetText("") + end + + if (rightTextSettings) then + menuButton.rightText:SetText(rightTextSettings[1]) + local r, g, b, a = rightTextSettings[2], rightTextSettings[3], rightTextSettings[4], rightTextSettings[5] + + if (r == 0 and g == 0 and b == 0 and a == 0) then + if (CoolTip.OptionsTable.TextColorRight) then + r, g, b, a = DF:ParseColors(CoolTip.OptionsTable.TextColorRight) + DF:SetFontColor(menuButton.rightText, r, g, b, a) + elseif (CoolTip.OptionsTable.TextColor) then + r, g, b, a = DF:ParseColors(CoolTip.OptionsTable.TextColor) + DF:SetFontColor(menuButton.rightText, r, g, b, a) + else + menuButton.rightText:SetTextColor(1, 1, 1, 1) + end + else + DF:SetFontColor(menuButton.rightText, r, g, b, a) + end + + if (CoolTip.OptionsTable.TextSize and not rightTextSettings[6]) then + DF:SetFontSize(menuButton.rightText, CoolTip.OptionsTable.TextSize) + end + + if (CoolTip.OptionsTable.RightTextWidth) then + menuButton.rightText:SetWidth(CoolTip.OptionsTable.RightTextWidth) + else + menuButton.rightText:SetWidth(0) + end + + if (CoolTip.OptionsTable.TextFont and not rightTextSettings[7]) then + if (_G[CoolTip.OptionsTable.TextFont]) then + menuButton.rightText:SetFontObject(CoolTip.OptionsTable.TextFont) + else + local fontFace = SharedMedia:Fetch("font", CoolTip.OptionsTable.TextFont) + local _, fontSize, fontFlags = menuButton.rightText:GetFont() + fontFlags = rightTextSettings[8] or CoolTip.OptionsTable.TextShadow or nil + fontSize = rightTextSettings[6] or CoolTip.OptionsTable.TextSize or fontSize + menuButton.rightText:SetFont(fontFace, fontSize, fontFlags) + end + + elseif (rightTextSettings[7]) then + if (_G[rightTextSettings[7]]) then + menuButton.rightText:SetFontObject(rightTextSettings[7]) + local fontFace, fontSize, fontFlags = menuButton.rightText:GetFont() + fontFlags = rightTextSettings[8] or CoolTip.OptionsTable.TextShadow or nil + fontSize = rightTextSettings[6] or CoolTip.OptionsTable.TextSize or fontSize + menuButton.rightText:SetFont(fontFace, fontSize, fontFlags) + else + local font = SharedMedia:Fetch("font", rightTextSettings[7]) + local fontFace, fontSize, fontFlags = menuButton.rightText:GetFont() + fontFlags = rightTextSettings[8] or CoolTip.OptionsTable.TextShadow or nil + fontSize = rightTextSettings[6] or CoolTip.OptionsTable.TextSize or fontSize + menuButton.rightText:SetFont(fontFace, fontSize, fontFlags) + end + else + menuButton.rightText:SetFont(CoolTip.defaultFont, rightTextSettings[6] or CoolTip.OptionsTable.TextSize or 10, rightTextSettings[8] or CoolTip.OptionsTable.TextShadow) + end + else + menuButton.rightText:SetText("") + end + + --left icon + if (leftIconSettings and leftIconSettings[1]) then + menuButton.leftIcon:SetTexture(leftIconSettings[1]) + menuButton.leftIcon:SetWidth(leftIconSettings[2]) + menuButton.leftIcon:SetHeight(leftIconSettings[3]) + menuButton.leftIcon:SetTexCoord(leftIconSettings[4], leftIconSettings[5], leftIconSettings[6], leftIconSettings[7]) + + local colorRed, colorGreen, colorBlue, colorAlpha = DF:ParseColors(leftIconSettings[8]) + menuButton.leftIcon:SetVertexColor(colorRed, colorGreen, colorBlue, colorAlpha) + + if (CoolTip.OptionsTable.IconBlendMode) then + menuButton.leftIcon:SetBlendMode(CoolTip.OptionsTable.IconBlendMode) + else + menuButton.leftIcon:SetBlendMode("BLEND") + end + + menuButton.leftIcon:SetDesaturated(leftIconSettings[9]) + else + menuButton.leftIcon:SetTexture("") + menuButton.leftIcon:SetWidth(1) + menuButton.leftIcon:SetHeight(1) + end + + --right icon + if (rightIconSettings and rightIconSettings[1]) then + menuButton.rightIcon:SetTexture(rightIconSettings[1]) + menuButton.rightIcon:SetWidth(rightIconSettings[2]) + menuButton.rightIcon:SetHeight(rightIconSettings[3]) + menuButton.rightIcon:SetTexCoord(rightIconSettings[4], rightIconSettings[5], rightIconSettings[6], rightIconSettings[7]) + + local colorRed, colorGreen, colorBlue, colorAlpha = DF:ParseColors(rightIconSettings[8]) + menuButton.rightIcon:SetVertexColor(colorRed, colorGreen, colorBlue, colorAlpha) + + if (CoolTip.OptionsTable.IconBlendMode) then + menuButton.rightIcon:SetBlendMode(CoolTip.OptionsTable.IconBlendMode) + else + menuButton.rightIcon:SetBlendMode("BLEND") + end + + menuButton.rightIcon:SetDesaturated(rightIconSettings[9]) + else + menuButton.rightIcon:SetTexture("") + menuButton.rightIcon:SetWidth(1) + menuButton.rightIcon:SetHeight(1) + end + + --overwrite icon size + if (CoolTip.OptionsTable.IconSize) then + menuButton.leftIcon:SetWidth(CoolTip.OptionsTable.IconSize) + menuButton.leftIcon:SetHeight(CoolTip.OptionsTable.IconSize) + menuButton.rightIcon:SetWidth(CoolTip.OptionsTable.IconSize) + menuButton.rightIcon:SetHeight(CoolTip.OptionsTable.IconSize) + end + + menuButton.leftText:SetHeight(0) + menuButton.rightText:SetHeight(0) + + if (CoolTip.Type == 2) then + CoolTip:LeftTextSpace(menuButton) + end + if (CoolTip.OptionsTable.LeftTextHeight) then + menuButton.leftText:SetHeight(CoolTip.OptionsTable.LeftTextHeight) + end + if (CoolTip.OptionsTable.RightTextHeight) then + menuButton.rightText:SetHeight(CoolTip.OptionsTable.RightTextHeight) + end + + --string length + if (not isSecondFrame) then --main frame if (not CoolTip.OptionsTable.FixedWidth) then - local stringWidth = menuButton.leftText:GetStringWidth() + menuButton.rightText:GetStringWidth() + menuButton.leftIcon:GetWidth() + menuButton.rightIcon:GetWidth() - if (stringWidth > frame1.w) then - frame1.w = stringWidth + if (CoolTip.Type == 1 or CoolTip.Type == 2) then + local stringWidth = menuButton.leftText:GetStringWidth() + menuButton.rightText:GetStringWidth() + menuButton.leftIcon:GetWidth() + menuButton.rightIcon:GetWidth() + 10 + if (stringWidth > frame.w) then + frame.w = stringWidth + end end + else + menuButton.leftText:SetWidth(CoolTip.OptionsTable.FixedWidth - menuButton.leftIcon:GetWidth() - menuButton.rightText:GetStringWidth() - menuButton.rightIcon:GetWidth() - 22) + end + else + if (not CoolTip.OptionsTable.FixedWidthSub) then + if (CoolTip.Type == 1 or CoolTip.Type == 2) then + local stringWidth = menuButton.leftText:GetStringWidth() + menuButton.rightText:GetStringWidth() + menuButton.leftIcon:GetWidth() + menuButton.rightIcon:GetWidth() + if (stringWidth > frame.w) then + frame.w = stringWidth + end + end + else + menuButton.leftText:SetWidth(CoolTip.OptionsTable.FixedWidthSub - menuButton.leftIcon:GetWidth() - 12) end - - --> register click function - menuButton:SetScript ("OnClick", OnClickFunctionMainButton) - menuButton:Show() end - function CoolTip:SetupSecondaryButton (menuButton, index, mainMenuIndex) - - menuButton.index = index - menuButton.mainIndex = mainMenuIndex - - --> setup texts and icons - CoolTip:TextAndIcon (index, frame2, menuButton, CoolTip.LeftTextTableSub [mainMenuIndex] and CoolTip.LeftTextTableSub [mainMenuIndex] [index], - CoolTip.RightTextTableSub [mainMenuIndex] and CoolTip.RightTextTableSub [mainMenuIndex] [index], - CoolTip.LeftIconTableSub [mainMenuIndex] and CoolTip.LeftIconTableSub [mainMenuIndex] [index], - CoolTip.RightIconTableSub [mainMenuIndex] and CoolTip.RightIconTableSub [mainMenuIndex] [index], true) - --> setup statusbar - CoolTip:StatusBar (menuButton, CoolTip.StatusBarTableSub [mainMenuIndex] and CoolTip.StatusBarTableSub [mainMenuIndex] [index]) + local height = max(menuButton.leftIcon:GetHeight(), menuButton.rightIcon:GetHeight(), menuButton.leftText:GetStringHeight(), menuButton.rightText:GetStringHeight()) + if (height > frame.hHeight) then + frame.hHeight = height + end + end - --> click - menuButton:RegisterForClicks ("LeftButtonDown") - - menuButton:ClearAllPoints() - menuButton:SetPoint ("center", frame2, "center") - menuButton:SetPoint ("top", frame2, "top", 0, (((index-1)*20)*-1)-3) - menuButton:SetPoint ("left", frame2, "left", -4, 0) - menuButton:SetPoint ("right", frame2, "right", 4, 0) - - DF:FadeFrame (menuButton, 0) - - --> string length + function CoolTip:RefreshSpark(menuButton) + menuButton.spark:ClearAllPoints() + menuButton.spark:SetPoint("LEFT", menuButton.statusbar, "LEFT", (menuButton.statusbar:GetValue() * (menuButton.statusbar:GetWidth() / 100)) - 5, 0) + menuButton.spark2:ClearAllPoints() + menuButton.spark2:SetPoint("left", menuButton.statusbar, "left", menuButton.statusbar:GetValue() * (menuButton.statusbar:GetWidth()/100) - 16, 0) + end + + function CoolTip:StatusBar(menuButton, statusBarSettings) + if (statusBarSettings) then + menuButton.statusbar:SetValue(statusBarSettings[1]) + menuButton.statusbar:SetStatusBarColor (statusBarSettings[2], statusBarSettings[3], statusBarSettings[4], statusBarSettings[5]) + menuButton.statusbar:SetHeight(20 + (CoolTip.OptionsTable.StatusBarHeightMod or 0)) + + menuButton.spark2:Hide() + if (statusBarSettings[6]) then + menuButton.spark:Show() + else + menuButton.spark:Hide() + end + + if (statusBarSettings[7]) then + menuButton.statusbar2:SetValue(statusBarSettings[7].value) + menuButton.statusbar2.texture:SetTexture(statusBarSettings[7].texture or [[Interface\RaidFrame\Raid-Bar-Hp-Fill]]) + if (statusBarSettings[7].specialSpark) then + menuButton.spark2:Show() + end + if (statusBarSettings[7].color) then + local colorRed, colorGreen, colorBlue, colorAlpha = DF:ParseColors(statusBarSettings[7].color) + menuButton.statusbar2:SetStatusBarColor (colorRed, colorGreen, colorBlue, colorAlpha) + else + menuButton.statusbar2:SetStatusBarColor (1, 1, 1, 1) + end + else + menuButton.statusbar2:SetValue(0) + menuButton.spark2:Hide() + end + + if (statusBarSettings[8]) then + local texture = SharedMedia:Fetch("statusbar", statusBarSettings[8], true) + if (texture) then + menuButton.statusbar.texture:SetTexture(texture) + else + menuButton.statusbar.texture:SetTexture(statusBarSettings[8]) + end + elseif (CoolTip.OptionsTable.StatusBarTexture) then + local texture = SharedMedia:Fetch("statusbar", CoolTip.OptionsTable.StatusBarTexture, true) + if (texture) then + menuButton.statusbar.texture:SetTexture(texture) + else + menuButton.statusbar.texture:SetTexture(CoolTip.OptionsTable.StatusBarTexture) + end + else + menuButton.statusbar.texture:SetTexture("Interface\\PaperDollInfoFrame\\UI-Character-Skills-Bar") + end + else + menuButton.statusbar:SetValue(0) + menuButton.statusbar2:SetValue(0) + menuButton.spark:Hide() + menuButton.spark2:Hide() + end + + if (CoolTip.OptionsTable.LeftBorderSize) then + menuButton.statusbar:SetPoint("left", menuButton, "left", 10 + CoolTip.OptionsTable.LeftBorderSize, 0) + else + menuButton.statusbar:SetPoint("left", menuButton, "left", 10, 0) + end + + if (CoolTip.OptionsTable.RightBorderSize) then + menuButton.statusbar:SetPoint("right", menuButton, "right", CoolTip.OptionsTable.RightBorderSize + (- 10), 0) + else + menuButton.statusbar:SetPoint("right", menuButton, "right", -10, 0) + end + end + + function CoolTip:SetupMainButton(menuButton, index) + menuButton.index = index + --setup texts and icons + CoolTip:TextAndIcon(index, frame1, menuButton, CoolTip.LeftTextTable[index], CoolTip.RightTextTable[index], CoolTip.LeftIconTable[index], CoolTip.RightIconTable[index]) + --setup statusbar + CoolTip:StatusBar(menuButton, CoolTip.StatusBarTable[index]) + --click + menuButton:RegisterForClicks("LeftButtonDown") + + --string length + if (not CoolTip.OptionsTable.FixedWidth) then local stringWidth = menuButton.leftText:GetStringWidth() + menuButton.rightText:GetStringWidth() + menuButton.leftIcon:GetWidth() + menuButton.rightIcon:GetWidth() - if (stringWidth > frame2.w) then - frame2.w = stringWidth + if (stringWidth > frame1.w) then + frame1.w = stringWidth end - - menuButton:SetScript ("OnClick", OnClickFunctionSecondaryButton) - menuButton:Show() - - return true end - - -- -- -------------------------------------------------------------------------------------------------------------- - - function CoolTip:SetupWallpaper (wallpaperTable, wallpaper) - local texture = wallpaperTable [1] - if (DF:IsHtmlColor (texture) or type (texture) == "table") then - local r, g, b, a = DF:ParseColors (texture) - wallpaper:SetTexture (r, g, b, a) - else - wallpaper:SetTexture (texture) - end - - wallpaper:SetTexCoord (wallpaperTable[2], wallpaperTable[3], wallpaperTable[4], wallpaperTable[5]) - - local color = wallpaperTable[6] - if (color) then - local r, g, b, a = DF:ParseColors (color) - wallpaper:SetVertexColor (r, g, b, a) - else - wallpaper:SetVertexColor (1, 1, 1, 1) - end - - if (wallpaperTable[7]) then - wallpaper:SetDesaturated (true) - else - wallpaper:SetDesaturated (false) - end - wallpaper:Show() + --register click function + menuButton:SetScript("OnClick", OnClickFunctionMainButton) + menuButton:Show() + end + + function CoolTip:SetupButtonOnSecondFrame(menuButton, index, mainMenuIndex) + menuButton.index = index + menuButton.mainIndex = mainMenuIndex + + --setup texts and icons + CoolTip:TextAndIcon(index, frame2, menuButton, CoolTip.LeftTextTableSub[mainMenuIndex] and CoolTip.LeftTextTableSub[mainMenuIndex][index], + CoolTip.RightTextTableSub[mainMenuIndex] and CoolTip.RightTextTableSub[mainMenuIndex][index], + CoolTip.LeftIconTableSub[mainMenuIndex] and CoolTip.LeftIconTableSub[mainMenuIndex][index], + CoolTip.RightIconTableSub[mainMenuIndex] and CoolTip.RightIconTableSub[mainMenuIndex][index], true) + + --setup statusbar + CoolTip:StatusBar(menuButton, CoolTip.StatusBarTableSub[mainMenuIndex] and CoolTip.StatusBarTableSub[mainMenuIndex][index]) + + --click + menuButton:RegisterForClicks("LeftButtonDown") + + menuButton:ClearAllPoints() + menuButton:SetPoint("center", frame2, "center") + menuButton:SetPoint("top", frame2, "top", 0, (((index-1) * 20) * -1) -3) + menuButton:SetPoint("left", frame2, "left", -4, 0) + menuButton:SetPoint("right", frame2, "right", 4, 0) + + DF:FadeFrame(menuButton, 0) + + --string length + local stringWidth = menuButton.leftText:GetStringWidth() + menuButton.rightText:GetStringWidth() + menuButton.leftIcon:GetWidth() + menuButton.rightIcon:GetWidth() + if (stringWidth > frame2.w) then + frame2.w = stringWidth end - - -- -- -------------------------------------------------------------------------------------------------------------- - - function CoolTip:ShowSub (index) - + + menuButton:SetScript("OnClick", OnClickFunctionSecondaryButton) + menuButton:Show() + return true + end + + ------------------------------------------------------------------------------------------------------------------ + + function CoolTip:SetupWallpaper(wallpaperTable, wallpaper) + local texture = wallpaperTable[1] + if (DF:IsHtmlColor(texture) or type(texture) == "table") then + local color = texture + local r, g, b, a = DF:ParseColors(color) + wallpaper:SetColorTexture(r, g, b, a) + else + wallpaper:SetTexture(texture) + end + + wallpaper:SetTexCoord(wallpaperTable[2], wallpaperTable[3], wallpaperTable[4], wallpaperTable[5]) + + local color = wallpaperTable[6] + if (color) then + local r, g, b, a = DF:ParseColors(color) + wallpaper:SetVertexColor(r, g, b, a) + else + wallpaper:SetVertexColor(1, 1, 1, 1) + end + + if (wallpaperTable[7]) then + wallpaper:SetDesaturated(true) + else + wallpaper:SetDesaturated(false) + end + + wallpaper:Show() + end + + ------------------------------------------------------------------------------------------------------------------ + + function CoolTip:ShowSub(index) if (CoolTip.OptionsTable.IgnoreSubMenu) then - DF:FadeFrame (frame2, 1) + DF:FadeFrame(frame2, 1) return end - - frame2:SetHeight (6) - - local amtIndexes = CoolTip.IndexesSub [index] - if (not amtIndexes) then - --print ("Sub menu called but sub menu indexes is nil") + + frame2:SetHeight(6) + local amountIndexes = CoolTip.IndexesSub[index] + if (not amountIndexes) then + --sub menu called but sub menu indexes is nil return end if (CoolTip.OptionsTable.FixedWidthSub) then - frame2:SetWidth (CoolTip.OptionsTable.FixedWidthSub) + frame2:SetWidth(CoolTip.OptionsTable.FixedWidthSub) end - - frame2.h = CoolTip.IndexesSub [index] * 20 + + frame2.h = CoolTip.IndexesSub[index] * 20 frame2.hHeight = 0 frame2.w = 0 - - --> pegar a fontsize da label principal - local mainButton = frame1.Lines [index] - local fontSize = DF:GetFontSize (mainButton.leftText) - - local GotChecked = false - - local IsTooltip = CoolTip.OptionsTable.SubMenuIsTooltip - if (IsTooltip) then - frame2:EnableMouse (false) - else - frame2:EnableMouse (true) - end - - for i = 1, CoolTip.IndexesSub [index] do - - local button = frame2.Lines [i] - - if (not button) then - button = CoolTip:NewSecondaryButton (i) - end - - local checked = CoolTip:SetupSecondaryButton (button, i, index) - if (checked) then - GotChecked = true - end - - if (IsTooltip) then - button:EnableMouse (false) - else - button:EnableMouse (true) - end - end - - local selected = CoolTip.SelectedIndexSec [index] - if (selected) then - - CoolTip:SetSelectedAnchor (frame2, frame2.Lines [selected]) + local isTooltip = CoolTip.OptionsTable.SubMenuIsTooltip + if (isTooltip) then + frame2:EnableMouse(false) + else + frame2:EnableMouse(true) + end + + for i = 1, CoolTip.IndexesSub[index] do + local button = frame2.Lines[i] + if (not button) then + button = CoolTip:CreateButtonOnSecondFrame(i) + end + CoolTip:SetupButtonOnSecondFrame(button, i, index) + + if (isTooltip) then + button:EnableMouse(false) + else + button:EnableMouse(true) + end + end + + local selected = CoolTip.SelectedIndexSec[index] + if (selected) then + CoolTip:SetSelectedAnchor(frame2, frame2.Lines[selected]) if (not CoolTip.OptionsTable.NoLastSelectedBar) then - CoolTip:ShowSelectedTexture (frame2) + CoolTip:ShowSelectedTexture(frame2) end else - CoolTip:HideSelectedTexture (frame2) + CoolTip:HideSelectedTexture(frame2) end - - for i = CoolTip.IndexesSub [index] + 1, #frame2.Lines do - DF:FadeFrame (frame2.Lines[i], 1) + + for i = CoolTip.IndexesSub[index] + 1, #frame2.Lines do + DF:FadeFrame(frame2.Lines[i], 1) end local spacing = 0 if (CoolTip.OptionsTable.YSpacingModSub) then spacing = CoolTip.OptionsTable.YSpacingModSub end - - --> normalize height of all rows - for i = 1, CoolTip.IndexesSub [index] do - - local menuButton = frame2.Lines [i] - - -- CoolTipFrame2.Lines [2].divbar - + + --normalize height of all rows + for i = 1, CoolTip.IndexesSub[index] do + local menuButton = frame2.Lines[i] + if (menuButton.leftText:GetText() == "$div") then - - --> height - menuButton:SetHeight (4) - - --> points + menuButton:SetHeight(4) + + --points menuButton:ClearAllPoints() - - menuButton:SetPoint ("center", frame2, "center") - menuButton:SetPoint ("left", frame2, "left", -4, 0) - menuButton:SetPoint ("right", frame2, "right", 4, 0) - - menuButton.rightText:SetText ("") - - local div_size_up = tonumber (CoolTip.RightTextTableSub [index] [i] [2]) - if (not div_size_up) then - div_size_up = 0 + menuButton:SetPoint("center", frame2, "center") + menuButton:SetPoint("left", frame2, "left", -4, 0) + menuButton:SetPoint("right", frame2, "right", 4, 0) + + menuButton.rightText:SetText("") + + local divisorOffsetTop = tonumber(CoolTip.RightTextTableSub[index][i][2]) + if (not divisorOffsetTop) then + divisorOffsetTop = 0 end - local div_size_down = tonumber (CoolTip.RightTextTableSub [index] [i] [3]) - if (not div_size_down) then - div_size_down = 0 + local divisorOffsetBottom = tonumber(CoolTip.RightTextTableSub[index][i][3]) + if (not divisorOffsetBottom) then + divisorOffsetBottom = 0 end - - menuButton:SetPoint ("top", frame2, "top", 0, ( ( (i-1) * frame2.hHeight) * -1) - 4 + (CoolTip.OptionsTable.ButtonsYModSub or 0) + spacing + (2 + (div_size_up or 0))) - + + menuButton:SetPoint("top", frame2, "top", 0, ( ( (i-1) * frame2.hHeight) * -1) - 4 + (CoolTip.OptionsTable.ButtonsYModSub or 0) + spacing + (2 + (divisorOffsetTop or 0))) + if (CoolTip.OptionsTable.YSpacingModSub) then spacing = spacing + CoolTip.OptionsTable.YSpacingModSub end - - spacing = spacing + 17 + (div_size_down or 0) - menuButton.leftText:SetText ("") + spacing = spacing + 17 + (divisorOffsetBottom or 0) + + menuButton.leftText:SetText("") menuButton.isDiv = true - + if (not menuButton.divbar) then - CoolTip:CreateDivBar (menuButton) + CoolTip:CreateDivBar(menuButton) else menuButton.divbar:Show() end - menuButton.divbar:SetPoint ("left", menuButton, "left", frame1:GetWidth()*0.10, 0) - menuButton.divbar:SetPoint ("right", menuButton, "right", -frame1:GetWidth()*0.10, 0) + menuButton.divbar:SetPoint("left", menuButton, "left", frame1:GetWidth() * 0.10, 0) + menuButton.divbar:SetPoint("right", menuButton, "right", -frame1:GetWidth() * 0.10, 0) else - --> height - menuButton:SetHeight (frame2.hHeight + (CoolTip.OptionsTable.ButtonHeightModSub or 0)) - --> points + menuButton:SetHeight(frame2.hHeight + (CoolTip.OptionsTable.ButtonHeightModSub or 0)) + + --points menuButton:ClearAllPoints() - menuButton:SetPoint ("center", frame2, "center") - menuButton:SetPoint ("top", frame2, "top", 0, ( ( (i-1) * frame2.hHeight) * -1) - 4 + (CoolTip.OptionsTable.ButtonsYModSub or 0) + spacing) + menuButton:SetPoint("center", frame2, "center") + menuButton:SetPoint("top", frame2, "top", 0, ( ( (i-1) * frame2.hHeight) * -1) - 4 + (CoolTip.OptionsTable.ButtonsYModSub or 0) + spacing) + if (CoolTip.OptionsTable.YSpacingModSub) then spacing = spacing + CoolTip.OptionsTable.YSpacingModSub end - menuButton:SetPoint ("left", frame2, "left", -4, 0) - menuButton:SetPoint ("right", frame2, "right", 4, 0) - + + menuButton:SetPoint("left", frame2, "left", -4, 0) + menuButton:SetPoint("right", frame2, "right", 4, 0) + if (menuButton.divbar) then menuButton.divbar:Hide() menuButton.isDiv = false end - end - + end end - + local mod = CoolTip.OptionsTable.HeighModSub or 0 - frame2:SetHeight ( (frame2.hHeight * CoolTip.IndexesSub [index]) + 12 + (-spacing) + mod) - - if (CoolTip.TopIconTableSub [index]) then - local upperImageTable = CoolTip.TopIconTableSub [index] - frame2.upperImage:SetTexture (upperImageTable [1]) - frame2.upperImage:SetWidth (upperImageTable [2]) - frame2.upperImage:SetHeight (upperImageTable [3]) - frame2.upperImage:SetTexCoord (upperImageTable[4], upperImageTable[5], upperImageTable[6], upperImageTable[7]) + frame2:SetHeight((frame2.hHeight * CoolTip.IndexesSub[index]) + 12 + (-spacing) + mod) + + if (CoolTip.TopIconTableSub[index]) then + local upperImageTable = CoolTip.TopIconTableSub[index] + frame2.upperImage:SetTexture(upperImageTable[1]) + frame2.upperImage:SetWidth(upperImageTable[2]) + frame2.upperImage:SetHeight(upperImageTable[3]) + frame2.upperImage:SetTexCoord(upperImageTable[4], upperImageTable[5], upperImageTable[6], upperImageTable[7]) frame2.upperImage:Show() else frame2.upperImage:Hide() end - - if (CoolTip.WallpaperTableSub [index]) then - CoolTip:SetupWallpaper (CoolTip.WallpaperTableSub [index], frame2.frameWallpaper) + + if (CoolTip.WallpaperTableSub[index]) then + CoolTip:SetupWallpaper(CoolTip.WallpaperTableSub[index], frame2.frameWallpaper) else frame2.frameWallpaper:Hide() end if (not CoolTip.OptionsTable.FixedWidthSub) then - frame2:SetWidth (frame2.w + 44) + frame2:SetWidth(frame2.w + 44) end - - DF:FadeFrame (frame2, 0) - + + DF:FadeFrame(frame2, 0) CoolTip:CheckOverlap() - - if (CoolTip.OptionsTable.SubFollowButton and not CoolTip.frame2_leftside) then - - local button = frame1.Lines [index] - + + if (CoolTip.OptionsTable.SubFollowButton and not CoolTip.frame2_IsOnLeftside) then + local button = frame1.Lines[index] frame2:ClearAllPoints() - frame2:SetPoint ("left", button, "right", 4, 0) - - elseif (CoolTip.OptionsTable.SubFollowButton and CoolTip.frame2_leftside) then - - local button = frame1.Lines [index] - + frame2:SetPoint("left", button, "right", 4, 0) + + elseif (CoolTip.OptionsTable.SubFollowButton and CoolTip.frame2_IsOnLeftside) then + local button = frame1.Lines[index] frame2:ClearAllPoints() - frame2:SetPoint ("right", button, "left", -4, 0) - - elseif (CoolTip.frame2_leftside) then + frame2:SetPoint("right", button, "left", -4, 0) + + elseif (CoolTip.frame2_IsOnLeftside) then frame2:ClearAllPoints() - frame2:SetPoint ("bottomright", frame1, "bottomleft", -4, 0) + frame2:SetPoint("bottomright", frame1, "bottomleft", -4, 0) else frame2:ClearAllPoints() - frame2:SetPoint ("bottomleft", frame1, "bottomright", 4, 0) + frame2:SetPoint("bottomleft", frame1, "bottomright", 4, 0) end - end - + function CoolTip:HideSub() - DF:FadeFrame (frame2, 1) - end - - - function CoolTip:LeftTextSpace (row) - row.leftText:SetWidth (row:GetWidth() - 30 - row.leftIcon:GetWidth() - row.rightIcon:GetWidth() - row.rightText:GetStringWidth()) - row.leftText:SetHeight (10) + DF:FadeFrame(frame2, 1) end - --> ~inicio ~start ~tooltip - function CoolTip:monta_tooltip() - - --> hide sub frame - DF:FadeFrame (frame2, 1) - --> hide select bar - CoolTip:HideSelectedTexture (frame1) + function CoolTip:LeftTextSpace(row) + row.leftText:SetWidth(row:GetWidth() - 30 - row.leftIcon:GetWidth() - row.rightIcon:GetWidth() - row.rightText:GetStringWidth()) + row.leftText:SetHeight(10) + end - frame1:EnableMouse (false) - - --> elevator - local yDown = 5 - --> width + --~inicio ~start ~tooltip + function CoolTip:BuildTooltip() + --hide sub frame + DF:FadeFrame(frame2, 1) + --hide select bar + CoolTip:HideSelectedTexture(frame1) + + frame1:EnableMouse(false) + + --width if (CoolTip.OptionsTable.FixedWidth) then - frame1:SetWidth (CoolTip.OptionsTable.FixedWidth) + frame1:SetWidth(CoolTip.OptionsTable.FixedWidth) end - + frame1.w = CoolTip.OptionsTable.FixedWidth or 0 frame1.hHeight = 0 frame2.hHeight = 0 - - CoolTip.active = true + CoolTip.active = true for i = 1, CoolTip.Indexes do - - local button = frame1.Lines [i] + local button = frame1.Lines[i] if (not button) then - button = CoolTip:NewMainButton (i) + button = CoolTip:CreateMainFrameButton(i) end - + button.index = i - - --> basic stuff + + --basic stuff button:Show() button.background:Hide() - button:SetHeight (CoolTip.OptionsTable.ButtonHeightMod or CoolTip.default_height) + button:SetHeight(CoolTip.OptionsTable.ButtonHeightMod or CoolTip.default_height) button:RegisterForClicks() - --> setup texts and icons - CoolTip:TextAndIcon (i, frame1, button, CoolTip.LeftTextTable [i], CoolTip.RightTextTable [i], CoolTip.LeftIconTable [i], CoolTip.RightIconTable [i]) - --> setup statusbar - CoolTip:StatusBar (button, CoolTip.StatusBarTable [i]) + --setup texts and icons + CoolTip:TextAndIcon(i, frame1, button, CoolTip.LeftTextTable[i], CoolTip.RightTextTable[i], CoolTip.LeftIconTable[i], CoolTip.RightIconTable[i]) + --setup statusbar + CoolTip:StatusBar(button, CoolTip.StatusBarTable[i]) end - - --> hide unused lines - for i = CoolTip.Indexes+1, #frame1.Lines do + + --hide unused lines + for i = CoolTip.Indexes+1, #frame1.Lines do frame1.Lines[i]:Hide() end CoolTip.NumLines = CoolTip.Indexes @@ -1608,178 +1487,170 @@ function DF:CreateCoolTip() if (CoolTip.OptionsTable.YSpacingMod) then spacing = CoolTip.OptionsTable.YSpacingMod end - - --> normalize height of all rows - local temp = -6 + spacing + (CoolTip.OptionsTable.ButtonsYMod or 0) + + --normalize height of all rows + local heightValue = -6 + spacing + (CoolTip.OptionsTable.ButtonsYMod or 0) for i = 1, CoolTip.Indexes do - local menuButton = frame1.Lines [i] - + local menuButton = frame1.Lines[i] + menuButton:ClearAllPoints() - menuButton:SetPoint ("center", frame1, "center") - menuButton:SetPoint ("left", frame1, "left", -4, 0) - menuButton:SetPoint ("right", frame1, "right", 4, 0) - + menuButton:SetPoint("center", frame1, "center") + menuButton:SetPoint("left", frame1, "left", -4, 0) + menuButton:SetPoint("right", frame1, "right", 4, 0) + if (menuButton.divbar) then menuButton.divbar:Hide() menuButton.isDiv = false end - - --> height + + --height if (CoolTip.OptionsTable.AlignAsBlizzTooltip) then - local height = _math_max (2, menuButton.leftText:GetStringHeight(), menuButton.rightText:GetStringHeight(), menuButton.leftIcon:GetHeight(), menuButton.rightIcon:GetHeight(), CoolTip.OptionsTable.AlignAsBlizzTooltipForceHeight or 2) - menuButton:SetHeight (height) - menuButton:SetPoint ("top", frame1, "top", 0, temp) - temp = temp + ( height * -1) - + local height = max(2, menuButton.leftText:GetStringHeight(), menuButton.rightText:GetStringHeight(), menuButton.leftIcon:GetHeight(), menuButton.rightIcon:GetHeight(), CoolTip.OptionsTable.AlignAsBlizzTooltipForceHeight or 2) + menuButton:SetHeight(height) + menuButton:SetPoint("top", frame1, "top", 0, heightValue) + heightValue = heightValue + ( height * -1) + elseif (CoolTip.OptionsTable.IgnoreButtonAutoHeight) then - - local height = _math_max (menuButton.leftText:GetStringHeight(), menuButton.rightText:GetStringHeight(), menuButton.leftIcon:GetHeight(), menuButton.rightIcon:GetHeight()) - menuButton:SetHeight (height) - menuButton:SetPoint ("top", frame1, "top", 0, temp) - - temp = temp + ( height * -1) + spacing + (CoolTip.OptionsTable.ButtonsYMod or 0) - + + local height = max(menuButton.leftText:GetStringHeight(), menuButton.rightText:GetStringHeight(), menuButton.leftIcon:GetHeight(), menuButton.rightIcon:GetHeight()) + menuButton:SetHeight(height) + menuButton:SetPoint("top", frame1, "top", 0, heightValue) + + heightValue = heightValue + ( height * -1) + spacing + (CoolTip.OptionsTable.ButtonsYMod or 0) + else - menuButton:SetHeight (frame1.hHeight + (CoolTip.OptionsTable.ButtonHeightMod or 0)) - menuButton:SetPoint ("top", frame1, "top", 0, ( ( (i-1) * frame1.hHeight) * -1) - 6 + (CoolTip.OptionsTable.ButtonsYMod or 0) + spacing) + menuButton:SetHeight(frame1.hHeight + (CoolTip.OptionsTable.ButtonHeightMod or 0)) + menuButton:SetPoint("top", frame1, "top", 0, ( ( (i-1) * frame1.hHeight) * -1) - 6 + (CoolTip.OptionsTable.ButtonsYMod or 0) + spacing) end - - --> points - + if (CoolTip.OptionsTable.YSpacingMod and not CoolTip.OptionsTable.IgnoreButtonAutoHeight) then spacing = spacing + CoolTip.OptionsTable.YSpacingMod end - - menuButton:EnableMouse (false) + + menuButton:EnableMouse(false) end - + if (not CoolTip.OptionsTable.FixedWidth) then - if (CoolTip.Type == 2) then --> with bars + if (CoolTip.Type == 2) then --with bars if (CoolTip.OptionsTable.MinWidth) then local w = frame1.w + 34 - PixelUtil.SetWidth (frame1, math.max (w, CoolTip.OptionsTable.MinWidth)) + PixelUtil.SetWidth(frame1, math.max(w, CoolTip.OptionsTable.MinWidth)) else - PixelUtil.SetWidth (frame1, frame1.w + 34) + PixelUtil.SetWidth(frame1, frame1.w + 34) end else - --> width stability check + --width stability check local width = frame1.w + 24 - if (width > CoolTip.LastSize-5 and width < CoolTip.LastSize+5) then + if (width > CoolTip.LastSize - 5 and width < CoolTip.LastSize + 5) then width = CoolTip.LastSize else CoolTip.LastSize = width end - + if (CoolTip.OptionsTable.MinWidth) then - PixelUtil.SetWidth (frame1, math.max (width, CoolTip.OptionsTable.MinWidth)) + PixelUtil.SetWidth(frame1, math.max(width, CoolTip.OptionsTable.MinWidth)) else - PixelUtil.SetWidth (frame1, width) + PixelUtil.SetWidth(frame1, width) end end end - + if (CoolTip.OptionsTable.FixedHeight) then - PixelUtil.SetHeight (frame1, CoolTip.OptionsTable.FixedHeight) + PixelUtil.SetHeight(frame1, CoolTip.OptionsTable.FixedHeight) else if (CoolTip.OptionsTable.AlignAsBlizzTooltip) then - PixelUtil.SetHeight (frame1, ((temp-10) * -1) + (CoolTip.OptionsTable.AlignAsBlizzTooltipFrameHeightOffset or 0)) - + PixelUtil.SetHeight(frame1, ((heightValue - 10) * -1) + (CoolTip.OptionsTable.AlignAsBlizzTooltipFrameHeightOffset or 0)) + elseif (CoolTip.OptionsTable.IgnoreButtonAutoHeight) then - PixelUtil.SetHeight (frame1, (temp+spacing) * -1) - + PixelUtil.SetHeight(frame1, (heightValue + spacing) * -1) + else - PixelUtil.SetHeight (frame1, _math_max ( (frame1.hHeight * CoolTip.Indexes) + 8 + ((CoolTip.OptionsTable.ButtonsYMod or 0)*-1), 22 )) + PixelUtil.SetHeight(frame1, max( (frame1.hHeight * CoolTip.Indexes) + 8 + ((CoolTip.OptionsTable.ButtonsYMod or 0)*-1), 22 )) end end - if (CoolTip.WallpaperTable [1]) then - CoolTip:SetupWallpaper (CoolTip.WallpaperTable, frame1.frameWallpaper) + if (CoolTip.WallpaperTable[1]) then + CoolTip:SetupWallpaper(CoolTip.WallpaperTable, frame1.frameWallpaper) else frame1.frameWallpaper:Hide() end - - --> unhide frame - DF:FadeFrame (frame1, 0) - CoolTip:SetMyPoint (host) - - --> fix sparks - for i = 1, CoolTip.Indexes do - local menuButton = frame1.Lines [i] + + --unhide frame + DF:FadeFrame(frame1, 0) + CoolTip:SetMyPoint() + + --fix sparks + for i = 1, CoolTip.Indexes do + local menuButton = frame1.Lines[i] if (menuButton.spark:IsShown() or menuButton.spark2:IsShown()) then - CoolTip:RefreshSpark (menuButton) + CoolTip:RefreshSpark(menuButton) end end end - function CoolTip:CreateDivBar (button) - button.divbar = button:CreateTexture (nil, "overlay") - - button.divbar:SetTexture ([[Interface\QUESTFRAME\AutoQuest-Parts]]) - button.divbar:SetTexCoord (238/512, 445/512, 0/64, 4/64) - - button.divbar:SetHeight (3) - button.divbar:SetAlpha (0.1) - - button.divbar:SetDesaturated (true) + function CoolTip:CreateDivBar(button) + button.divbar = button:CreateTexture(nil, "overlay") + button.divbar:SetTexture([[Interface\QUESTFRAME\AutoQuest-Parts]]) + button.divbar:SetTexCoord(238/512, 445/512, 0/64, 4/64) + button.divbar:SetHeight(3) + button.divbar:SetAlpha(0.1) + button.divbar:SetDesaturated(true) end - - --> ~inicio ~start ~menu - function CoolTip:monta_cooltip (host, instancia, options, sub_menus, icones, tamanho1, tamanho2, font, fontsize) + --~inicio ~start ~menu + function CoolTip:BuildCooltip(host) if (CoolTip.Indexes == 0) then CoolTip:Reset() - CoolTip:SetType ("tooltip") - CoolTip:AddLine ("There is no options.") + CoolTip:SetType(CONST_COOLTIP_TYPE_TOOLTIP) + CoolTip:AddLine("There is no options.") CoolTip:ShowCooltip() return end - + if (CoolTip.OptionsTable.FixedWidth) then - frame1:SetWidth (CoolTip.OptionsTable.FixedWidth) - end - + frame1:SetWidth(CoolTip.OptionsTable.FixedWidth) + end + frame1.w = CoolTip.OptionsTable.FixedWidth or 0 frame1.hHeight = 0 frame2.hHeight = 0 - - frame1:EnableMouse (true) - - if (CoolTip.HaveSubMenu) then --> zera o segundo frame + + frame1:EnableMouse(true) + + if (CoolTip.HaveSubMenu) then frame2.w = 0 - frame2:SetHeight (6) - if (CoolTip.SelectedIndexMain and CoolTip.IndexesSub [CoolTip.SelectedIndexMain] and CoolTip.IndexesSub [CoolTip.SelectedIndexMain] > 0) then - DF:FadeFrame (frame2, 0) + frame2:SetHeight(6) + if (CoolTip.SelectedIndexMain and CoolTip.IndexesSub[CoolTip.SelectedIndexMain] and CoolTip.IndexesSub[CoolTip.SelectedIndexMain] > 0) then + DF:FadeFrame(frame2, 0) else - DF:FadeFrame (frame2, 1) + DF:FadeFrame(frame2, 1) end else - DF:FadeFrame (frame2, 1) + DF:FadeFrame(frame2, 1) end - + CoolTip.active = true - + for i = 1, CoolTip.Indexes do - local menuButton = frame1.Lines [i] + local menuButton = frame1.Lines[i] if (not menuButton) then - menuButton = CoolTip:NewMainButton (i) + menuButton = CoolTip:CreateMainFrameButton(i) end - - CoolTip:SetupMainButton (menuButton, i) - + CoolTip:SetupMainButton(menuButton, i) menuButton.background:Hide() end - --> selected texture + --selected texture if (CoolTip.SelectedIndexMain) then - CoolTip:SetSelectedAnchor (frame1, frame1.Lines [CoolTip.SelectedIndexMain]) + CoolTip:SetSelectedAnchor(frame1, frame1.Lines[CoolTip.SelectedIndexMain]) if (CoolTip.OptionsTable.NoLastSelectedBar) then - CoolTip:HideSelectedTexture (frame1) + CoolTip:HideSelectedTexture(frame1) else - CoolTip:ShowSelectedTexture (frame1) + CoolTip:ShowSelectedTexture(frame1) end else - CoolTip:HideSelectedTexture (frame1) + CoolTip:HideSelectedTexture(frame1) end if (CoolTip.Indexes < #frame1.Lines) then @@ -1787,1631 +1658,1503 @@ function DF:CreateCoolTip() frame1.Lines[i]:Hide() end end - + CoolTip.NumLines = CoolTip.Indexes local spacing = 0 if (CoolTip.OptionsTable.YSpacingMod) then spacing = CoolTip.OptionsTable.YSpacingMod end - + if (not CoolTip.OptionsTable.FixedWidth) then if (CoolTip.OptionsTable.MinWidth) then local w = frame1.w + 24 - frame1:SetWidth (math.max (w, CoolTip.OptionsTable.MinWidth)) + frame1:SetWidth(math.max(w, CoolTip.OptionsTable.MinWidth)) else - frame1:SetWidth (frame1.w + 24) + frame1:SetWidth(frame1.w + 24) end end - - --> normalize height of all rows - for i = 1, CoolTip.Indexes do - local menuButton = frame1.Lines [i] - menuButton:EnableMouse (true) - + + --normalize height of all rows + for i = 1, CoolTip.Indexes do + local menuButton = frame1.Lines[i] + menuButton:EnableMouse(true) + if (menuButton.leftText:GetText() == "$div") then - - --> height - menuButton:SetHeight (4) - --> points - menuButton:ClearAllPoints() - menuButton:SetPoint ("left", frame1, "left", -4, 0) - menuButton:SetPoint ("right", frame1, "right", 4, 0) - menuButton:SetPoint ("center", frame1, "center") - - local div_size_up = tonumber (CoolTip.LeftTextTable [i] [2]) - if (not div_size_up) then - div_size_up = 0 + --height + menuButton:SetHeight(4) + --points + menuButton:ClearAllPoints() + menuButton:SetPoint("left", frame1, "left", -4, 0) + menuButton:SetPoint("right", frame1, "right", 4, 0) + menuButton:SetPoint("center", frame1, "center") + + local divisorOffsetTop = tonumber(CoolTip.LeftTextTable[i][2]) + if (not divisorOffsetTop) then + divisorOffsetTop = 0 end - local div_size_down = tonumber (CoolTip.LeftTextTable [i] [3]) - if (not div_size_down) then - div_size_down = 0 + local divisorOffsetBottom = tonumber(CoolTip.LeftTextTable[i][3]) + if (not divisorOffsetBottom) then + divisorOffsetBottom = 0 end - - menuButton:SetPoint ("top", frame1, "top", 0, ( ( (i-1) * frame1.hHeight) * -1) - 4 + (CoolTip.OptionsTable.ButtonsYMod or 0) + spacing - 4 + div_size_up) + + menuButton:SetPoint("top", frame1, "top", 0, ( ( (i-1) * frame1.hHeight) * -1) - 4 + (CoolTip.OptionsTable.ButtonsYMod or 0) + spacing - 4 + divisorOffsetTop) if (CoolTip.OptionsTable.YSpacingMod) then spacing = spacing + CoolTip.OptionsTable.YSpacingMod end - - spacing = spacing + 4 + div_size_down - - menuButton.leftText:SetText ("") + + spacing = spacing + 4 + divisorOffsetBottom + + menuButton.leftText:SetText("") menuButton.isDiv = true - + if (not menuButton.divbar) then - CoolTip:CreateDivBar (menuButton) + CoolTip:CreateDivBar(menuButton) else menuButton.divbar:Show() end - - menuButton.divbar:SetPoint ("left", menuButton, "left", frame1:GetWidth()*0.10, 0) - menuButton.divbar:SetPoint ("right", menuButton, "right", -frame1:GetWidth()*0.10, 0) + menuButton.divbar:SetPoint("left", menuButton, "left", frame1:GetWidth() * 0.10, 0) + menuButton.divbar:SetPoint("right", menuButton, "right", -frame1:GetWidth() * 0.10, 0) else - - --> height - menuButton:SetHeight (frame1.hHeight + (CoolTip.OptionsTable.ButtonHeightMod or 0)) - --> points + --height + menuButton:SetHeight(frame1.hHeight + (CoolTip.OptionsTable.ButtonHeightMod or 0)) + --points menuButton:ClearAllPoints() - menuButton:SetPoint ("center", frame1, "center") - menuButton:SetPoint ("top", frame1, "top", 0, ( ( (i-1) * frame1.hHeight) * -1) - 4 + (CoolTip.OptionsTable.ButtonsYMod or 0) + spacing) + menuButton:SetPoint("center", frame1, "center") + menuButton:SetPoint("top", frame1, "top", 0, ( ( (i-1) * frame1.hHeight) * -1) - 4 + (CoolTip.OptionsTable.ButtonsYMod or 0) + spacing) if (CoolTip.OptionsTable.YSpacingMod) then spacing = spacing + CoolTip.OptionsTable.YSpacingMod end - menuButton:SetPoint ("left", frame1, "left", -4, 0) - menuButton:SetPoint ("right", frame1, "right", 4, 0) - + menuButton:SetPoint("left", frame1, "left", -4, 0) + menuButton:SetPoint("right", frame1, "right", 4, 0) + if (menuButton.divbar) then menuButton.divbar:Hide() menuButton.isDiv = false end end - end - + if (CoolTip.OptionsTable.FixedHeight) then - frame1:SetHeight (CoolTip.OptionsTable.FixedHeight) + frame1:SetHeight(CoolTip.OptionsTable.FixedHeight) else local mod = CoolTip.OptionsTable.HeighMod or 0 - frame1:SetHeight (_math_max ( (frame1.hHeight * CoolTip.Indexes) + 12 + (-spacing) + mod, 22 )) + frame1:SetHeight(max((frame1.hHeight * CoolTip.Indexes) + 12 + (-spacing) + mod, 22)) end - - --> sub menu arrows + + --sub menu arrows if (CoolTip.HaveSubMenu and not CoolTip.OptionsTable.IgnoreArrows and not CoolTip.OptionsTable.SubMenuIsTooltip) then for i = 1, CoolTip.Indexes do - if (CoolTip.IndexesSub [i] and CoolTip.IndexesSub [i] > 0) then - frame1.Lines [i].statusbar.subMenuArrow:Show() + if (CoolTip.IndexesSub[i] and CoolTip.IndexesSub[i] > 0) then + frame1.Lines[i].statusbar.subMenuArrow:Show() else - frame1.Lines [i].statusbar.subMenuArrow:Hide() + frame1.Lines[i].statusbar.subMenuArrow:Hide() end end - - frame1:SetWidth (frame1:GetWidth() + 16) + frame1:SetWidth(frame1:GetWidth() + 16) end - + frame1:ClearAllPoints() - CoolTip:SetMyPoint (host) - + CoolTip:SetMyPoint(host) + if (CoolTip.title1) then CoolTip.frame1.titleText:Show() CoolTip.frame1.titleIcon:Show() - CoolTip.frame1.titleText:SetText (CoolTip.title_text) - CoolTip.frame1.titleIcon:SetWidth (frame1:GetWidth()) - CoolTip.frame1.titleIcon:SetHeight (40) + CoolTip.frame1.titleText:SetText(CoolTip.title_text) + CoolTip.frame1.titleIcon:SetWidth(frame1:GetWidth()) + CoolTip.frame1.titleIcon:SetHeight(40) end - - if (CoolTip.WallpaperTable [1]) then - CoolTip:SetupWallpaper (CoolTip.WallpaperTable, frame1.frameWallpaper) + + if (CoolTip.WallpaperTable[1]) then + CoolTip:SetupWallpaper(CoolTip.WallpaperTable, frame1.frameWallpaper) else frame1.frameWallpaper:Hide() end - - DF:FadeFrame (frame1, 0) + + DF:FadeFrame(frame1, 0) for i = 1, CoolTip.Indexes do if (CoolTip.SelectedIndexMain and CoolTip.SelectedIndexMain == i) then - if (CoolTip.HaveSubMenu and CoolTip.IndexesSub [i] and CoolTip.IndexesSub [i] > 0) then - CoolTip:ShowSub (i) + if (CoolTip.HaveSubMenu and CoolTip.IndexesSub[i] and CoolTip.IndexesSub[i] > 0) then + CoolTip:ShowSub(i) end end end - + return true end - - function CoolTip:SetMyPoint (host, x_mod, y_mod) - - local moveX = x_mod or 0 - local moveY = y_mod or 0 - - --> clear all points - frame1:ClearAllPoints() - - local anchor = CoolTip.OptionsTable.Anchor or CoolTip.Host - - --frame1:SetPoint (CoolTip.OptionsTable.MyAnchor, anchor, CoolTip.OptionsTable.RelativeAnchor, 0 + moveX + CoolTip.OptionsTable.WidthAnchorMod, 10 + CoolTip.OptionsTable.HeightAnchorMod + moveY) - PixelUtil.SetPoint (frame1, CoolTip.OptionsTable.MyAnchor, anchor, CoolTip.OptionsTable.RelativeAnchor, 0 + moveX + CoolTip.OptionsTable.WidthAnchorMod, 10 + CoolTip.OptionsTable.HeightAnchorMod + moveY) - - if (not x_mod) then - --> check if cooltip is out of screen bounds - local center_x = frame1:GetCenter() - - if (center_x) then - local screen_x_res = GetScreenWidth() - local half_x = frame1:GetWidth() / 2 - - if (center_x+half_x > screen_x_res) then - --> out of right side - local move_to_left = (center_x + half_x) - screen_x_res - CoolTip.internal_x_mod = -move_to_left - return CoolTip:SetMyPoint (host, -move_to_left, 0) - - elseif (center_x-half_x < 0) then - --> out of left side - local move_to_right = center_x - half_x - CoolTip.internal_x_mod = move_to_right*-1 - return CoolTip:SetMyPoint (host, move_to_right*-1, 0) - end - end - end - - if (not y_mod) then - --> check if cooltip is out of screen bounds - local _, center_y = frame1:GetCenter() - local screen_y_res = GetScreenHeight() - local half_y = frame1:GetHeight() / 2 - - if (center_y) then - if (center_y+half_y > screen_y_res) then - --> out of top side - local move_to_down = (center_y + half_y) - screen_y_res - CoolTip.internal_y_mod = -move_to_down - return CoolTip:SetMyPoint (host, 0, -move_to_down) - - elseif (center_y-half_y < 0) then - --> out of bottom side - local move_to_up = center_y - half_y - CoolTip.internal_y_mod = move_to_up*-1 - return CoolTip:SetMyPoint (host, 0, move_to_up*-1) - - end - end - end - - if (frame2:IsShown() and not CoolTip.overlap_checked) then - local frame_2_center_x = frame2:GetCenter() - if (frame_2_center_x) then - local frame_2_half_x = frame2:GetWidth() / 2 - - local frame_1_center_x = frame1:GetCenter() - if (frame_1_center_x) then - - local frame_1_half_x = frame1:GetWidth() / 2 - - local f1_end_point = frame_1_center_x + frame_1_half_x - 3 - local f2_start_point = frame_2_center_x - frame_2_half_x - - if (f2_start_point < f1_end_point) then - local diff = f2_start_point - f1_end_point - CoolTip.overlap_checked = true - - frame2:ClearAllPoints() - frame2:SetPoint ("bottomright", frame1, "bottomleft", 4, 0) - CoolTip.frame2_leftside = true - --> diff - return CoolTip:SetMyPoint (host, CoolTip.internal_x_mod , CoolTip.internal_y_mod) - end - + function CoolTip:SetMyPoint(host, xOffset, yOffset) + local thisXOffset = xOffset or 0 + local thisYOffset = yOffset or 0 + + --clear all points + frame1:ClearAllPoints() + + local anchor = CoolTip.OptionsTable.Anchor or CoolTip.Host + PixelUtil.SetPoint(frame1, CoolTip.OptionsTable.MyAnchor, anchor, CoolTip.OptionsTable.RelativeAnchor, 0 + thisXOffset + CoolTip.OptionsTable.WidthAnchorMod, 10 + CoolTip.OptionsTable.HeightAnchorMod + thisYOffset) + + if (not xOffset) then + --check if cooltip is out of screen bounds + local xCenter = frame1:GetCenter() + if (xCenter) then + local screenWidth = GetScreenWidth() + local frame1WidthHalf = frame1:GetWidth() / 2 + + if (xCenter + frame1WidthHalf > screenWidth) then + --out of right side + local newXOffset = (xCenter + frame1WidthHalf) - screenWidth + CoolTip.internalYMod = -newXOffset + return CoolTip:SetMyPoint(host, -newXOffset, 0) + + elseif (xCenter - frame1WidthHalf < 0) then + --out of left side + local newXOffset = xCenter - frame1WidthHalf + CoolTip.internalYMod = newXOffset * -1 + return CoolTip:SetMyPoint(host, newXOffset * -1, 0) + end + end + end + + if (not yOffset) then + --check if cooltip is out of screen bounds + local _, xCenter = frame1:GetCenter() + local screenHeight = GetScreenHeight() + local frame1HeightHalf = frame1:GetHeight() / 2 + + if (xCenter) then + if (xCenter + frame1HeightHalf > screenHeight) then + --out of top side + local newYOffset = (xCenter + frame1HeightHalf) - screenHeight + CoolTip.internalYMod = -newYOffset + return CoolTip:SetMyPoint(host, 0, -newYOffset) + + elseif (xCenter - frame1HeightHalf < 0) then + --out of bottom side + local newYOffset = xCenter - frame1HeightHalf + CoolTip.internalYMod = newYOffset * -1 + return CoolTip:SetMyPoint(host, 0, newYOffset * -1) + end + end + end + + if (frame2:IsShown() and not CoolTip.overlapChecked) then + local xCenter = frame2:GetCenter() + if (xCenter) then + local frame2WidthHalf = frame2:GetWidth() / 2 + local frame1XCenter = frame1:GetCenter() + + if (frame1XCenter) then + local frame1WidthHalf = frame1:GetWidth() / 2 + local frame1EndPoint = frame1XCenter + frame1WidthHalf - 3 + local frame2StartPoint = xCenter - frame2WidthHalf + + if (frame2StartPoint < frame1EndPoint) then + local diff = frame2StartPoint - frame1EndPoint --not in use + CoolTip.overlapChecked = true + frame2:ClearAllPoints() + frame2:SetPoint("bottomright", frame1, "bottomleft", 4, 0) + CoolTip.frame2_IsOnLeftside = true + --diff + return CoolTip:SetMyPoint(host, CoolTip.internalYMod , CoolTip.internalYMod) + end end end - end - end - + function CoolTip:CheckOverlap() if (frame2:IsShown()) then - - local frame_2_center_x = frame2:GetCenter() - if (frame_2_center_x) then - local frame_2_half_x = frame2:GetWidth() / 2 - - local frame_1_center_x = frame1:GetCenter() - if (frame_1_center_x) then - - local frame_1_half_x = frame1:GetWidth() / 2 - - local f1_end_point = frame_1_center_x + frame_1_half_x - 3 - local f2_start_point = frame_2_center_x - frame_2_half_x - - if (f2_start_point < f1_end_point) then - local diff = f2_start_point - f1_end_point - + local xCenter = frame2:GetCenter() + if (xCenter) then + local frame2WidthHalf = frame2:GetWidth() / 2 + local frame1XCenter = frame1:GetCenter() + if (frame1XCenter) then + local frame1WidthHalf = frame1:GetWidth() / 2 + local frame1EndPoint = frame1XCenter + frame1WidthHalf - 3 + local frame2StartPoint = xCenter - frame2WidthHalf + if (frame2StartPoint < frame1EndPoint) then + local diff = frame2StartPoint - frame1EndPoint --not in use frame2:ClearAllPoints() - frame2:SetPoint ("bottomright", frame1, "bottomleft", 4, 0) - CoolTip.frame2_leftside = true + frame2:SetPoint("bottomright", frame1, "bottomleft", 4, 0) + CoolTip.frame2_IsOnLeftside = true end - end end - end end - - function CoolTip:GetText (buttonIndex) - local button1 = frame1.Lines [buttonIndex] + + --retrive the left and right text shown on a line + function CoolTip:GetText(buttonIndex) + local button1 = frame1.Lines[buttonIndex] if (not button1) then return "", "" else return button1.leftText:GetText() or "", button1.rightText:GetText() or "" end end - ----------------------------------------------------------------------- - --> Get the number of lines current shown on cooltip - + + --get the number of lines current shown on cooltip function CoolTip:GetNumLines() return CoolTip.NumLines or 0 end ----------------------------------------------------------------------- - --> Remove all options actived - --> Set a option on current cooltip - - function CoolTip:ClearAllOptions() - for option, _ in pairs (CoolTip.OptionsTable) do - CoolTip.OptionsTable [option] = nil - end - - CoolTip:SetOption ("MyAnchor", "bottom") - CoolTip:SetOption ("RelativeAnchor", "top") - CoolTip:SetOption ("WidthAnchorMod", 0) - CoolTip:SetOption ("HeightAnchorMod", 0) + --remove all options actived, set a option on current cooltip + function CoolTip:ClearAllOptions() + for option, _ in pairs(CoolTip.OptionsTable) do + CoolTip.OptionsTable[option] = nil end - - function CoolTip:SetOption (optionName, value) - - --> check for name alias - optionName = CoolTip.AliasList [optionName] or optionName - - --> check if this options exists - if (not CoolTip.OptionsList [optionName]) then - return --> error - end - - --> set options - CoolTip.OptionsTable [optionName] = value + CoolTip:SetOption("MyAnchor", "bottom") + CoolTip:SetOption("RelativeAnchor", "top") + CoolTip:SetOption("WidthAnchorMod", 0) + CoolTip:SetOption("HeightAnchorMod", 0) + end + + function CoolTip:SetOption(optionName, value) + --check for name alias + optionName = CoolTip.AliasList[optionName] or optionName + --check if this options exists + if (not CoolTip.OptionsList[optionName]) then + return CoolTip:PrintDebug("SetOption() option not found:", optionName) end + --set options + CoolTip.OptionsTable[optionName] = value + end + + --return the current frame using cooltip + function CoolTip:GetOwner() + return CoolTip.Host + end + + --set the anchor of cooltip, parameters: frame [, cooltip anchor point, frame anchor point[, x mod, y mod]] + function CoolTip:SetOwner(frame, myPoint, hisPoint, x, y) + return CoolTip:SetHost(frame, myPoint, hisPoint, x, y) + end + + function CoolTip:SetHost(frame, myPoint, hisPoint, x, y) + --check data integrity + if (type(frame) ~= "table" or not frame.GetObjectType) then + return CoolTip:PrintDebug("SetHost() need a WOWObject.") + end + + CoolTip.Host = frame + CoolTip.frame1:SetFrameLevel(frame:GetFrameLevel() + 1) + + --defaults + myPoint = myPoint or CoolTip.OptionsTable.MyAnchor or "bottom" + hisPoint = hisPoint or CoolTip.OptionsTable.hisPoint or "top" + + x = x or CoolTip.OptionsTable.WidthAnchorMod or 0 + y = y or CoolTip.OptionsTable.HeightAnchorMod or 0 + + --set options + if (type(myPoint) == "string") then + CoolTip:SetOption("MyAnchor", myPoint) + CoolTip:SetOption("WidthAnchorMod", x) + elseif (type(myPoint) == "number") then + CoolTip:SetOption("HeightAnchorMod", myPoint) + end + + if (type(hisPoint) == "string") then + CoolTip:SetOption("RelativeAnchor", hisPoint) + CoolTip:SetOption("HeightAnchorMod", y) + elseif (type(hisPoint) == "number") then + CoolTip:SetOption("WidthAnchorMod", hisPoint) + end + end ---------------------------------------------------------------------- - --> set the anchor of cooltip - --> parameters: frame [, cooltip anchor point, frame anchor point [, x mod, y mod]] - --> frame [, x mod, y mod] - - --> alias - function CoolTip:GetOwner() - return CoolTip.Host - end - - function CoolTip:SetOwner (frame, myPoint, hisPoint, x, y) - return CoolTip:SetHost (frame, myPoint, hisPoint, x, y) - end - - function CoolTip:SetHost (frame, myPoint, hisPoint, x, y) - --> check data integrity - if (type (frame) ~= "table" or not frame.GetObjectType) then - print ("host needs to be a frame") - return --> error - end - - CoolTip.Host = frame - - CoolTip.frame1:SetFrameLevel (frame:GetFrameLevel()+1) - - --> defaults - myPoint = myPoint or CoolTip.OptionsTable.MyAnchor or "bottom" - hisPoint = hisPoint or CoolTip.OptionsTable.hisPoint or "top" + --set cooltip type + --parameters: type(1 = tooltip | 2 = tooltip with bars | 3 = menu) - x = x or CoolTip.OptionsTable.WidthAnchorMod or 0 - y = y or CoolTip.OptionsTable.HeightAnchorMod or 0 - - --> check options - if (type (myPoint) == "string") then - CoolTip:SetOption ("MyAnchor", myPoint) - CoolTip:SetOption ("WidthAnchorMod", x) - elseif (type (myPoint) == "number") then - CoolTip:SetOption ("HeightAnchorMod", myPoint) + --return if the current shown cooltip is a menu + function CoolTip:IsMenu() + return CoolTip.frame1:IsShown() and CoolTip.Type == 3 + end + + --return if the current shown cooltip is a tooltip + function CoolTip:IsTooltip() + return CoolTip.frame1:IsShown() and (CoolTip.Type == 1 or CoolTip.Type == 2) + end + + function CoolTip:GetType() + if (CoolTip.Type == 1 or CoolTip.Type == 2) then + return CONST_COOLTIP_TYPE_TOOLTIP + elseif (CoolTip.Type == 3) then + return CONST_COOLTIP_TYPE_MENU + else + return "none" + end + end + + function CoolTip:SetType(newType) + if (type(newType) == "string") then + if (newType == CONST_COOLTIP_TYPE_TOOLTIP) then + CoolTip.Type = 1 + elseif (newType == "tooltipbar") then + CoolTip.Type = 2 + elseif (newType == CONST_COOLTIP_TYPE_MENU) then + CoolTip.Type = 3 + else + return CoolTip:PrintDebug("SetType() unknown type.", newType) end - - if (type (hisPoint) == "string") then - CoolTip:SetOption ("RelativeAnchor", hisPoint) - CoolTip:SetOption ("HeightAnchorMod", y) - elseif (type (hisPoint) == "number") then - CoolTip:SetOption ("WidthAnchorMod", hisPoint) + + elseif (type(newType) == "number") then + if (newType == 1) then + CoolTip.Type = 1 + elseif (newType == 2) then + CoolTip.Type = 2 + elseif (newType == 3) then + CoolTip.Type = 3 + else + return CoolTip:PrintDebug("SetType() unknown type.", newType) + end + else + return CoolTip:PrintDebug("SetType() unknown type.", newType) + end + end + + --set a fixed value for menu, the fixedValue is sent with the menu callback function + function CoolTip:SetFixedParameter(value, injected) + if (injected ~= nil) then + local frame = value + if (frame.dframework) then + frame = frame.widget + end + if (frame.CoolTip) then + frame.CoolTip.FixedValue = injected end end + CoolTip.FixedValue = value + end + + --set tooltip color + function CoolTip:SetColor(menuType, ...) + local colorRed, colorGreen, colorBlue, colorAlpha = DF:ParseColors(...) + if ((type(menuType) == "string" and menuType == CONST_MENU_TYPE_MAINMENU) or (type(menuType) == "number" and menuType == 1)) then + frame1.frameBackgroundTexture:SetVertexColor(colorRed, colorGreen, colorBlue, colorAlpha) + + --hide textures from older versions if exists + if (frame1.frameBackgroundLeft) then + frame1.frameBackgroundLeft:Hide() + frame1.frameBackgroundRight:Hide() + frame1.frameBackgroundCenter:Hide() + end + + elseif ((type(menuType) == "string" and menuType == CONST_MENU_TYPE_SUBMENU) or (type(menuType) == "number" and menuType == 2)) then + frame2.frameBackgroundTexture:SetVertexColor(colorRed, colorGreen, colorBlue, colorAlpha) + + --hide textures from older versions if exists + if (frame2.frameBackgroundLeft) then + frame2.frameBackgroundLeft:Hide() + frame2.frameBackgroundRight:Hide() + frame2.frameBackgroundCenter:Hide() + end + else + return CoolTip:PrintDebug("SetColor() unknown menuType.", menuType) + end + end + + --set last selected option + function CoolTip:SetLastSelected(menuType, index, index2) + if (CoolTip.Type == 3) then + if ((type(menuType) == "string" and menuType == CONST_MENU_TYPE_MAINMENU) or (type(menuType) == "number" and menuType == 1)) then + CoolTip.SelectedIndexMain = index + elseif ((type(menuType) == "string" and menuType == CONST_MENU_TYPE_SUBMENU) or (type(menuType) == "number" and menuType == 2)) then + CoolTip.SelectedIndexSec[index] = index2 + else + return CoolTip:PrintDebug("SetLastSelected() unknown menuType.", menuType) + end + else + return CoolTip:PrintDebug("SetLastSelected() current cooltip isn't a menu.") + end + end + + --serack key: ~select + function CoolTip:Select(menuType, option, mainIndex) + if (menuType == 1) then --main menu + local botao = frame1.Lines[option] + CoolTip.buttonClicked = true + CoolTip:SetSelectedAnchor(frame1, botao) + + elseif (menuType == 2) then --sub menu + CoolTip:ShowSub(mainIndex) + local botao = frame2.Lines[option] + CoolTip.buttonClicked = true + CoolTip:SetSelectedAnchor(frame2, botao) + end + end ---------------------------------------------------------------------- - --> set cooltip type - --> parameters: type (1 = tooltip | 2 = tooltip with bars | 3 = menu) - - function CoolTip:IsMenu() - return CoolTip.frame1:IsShown() and CoolTip.Type == 3 - end - - function CoolTip:IsTooltip() - return CoolTip.frame1:IsShown() and (CoolTip.Type == 1 or CoolTip.Type == 2) - end - - function CoolTip:GetType() - if (CoolTip.Type == 1 or CoolTip.Type == 2) then - return "tooltip" - elseif (CoolTip.Type == 3) then - return "menu" - else - return "none" - end - end - - function CoolTip:SetType (newType) - if (type (newType) == "string") then - if (newType == "tooltip") then - CoolTip.Type = 1 - elseif (newType == "tooltipbar") then - CoolTip.Type = 2 - elseif (newType == "menu") then - CoolTip.Type = 3 - else - --> error - end - elseif (type (newType) == "number") then - if (newType == 1) then - CoolTip.Type = 1 - elseif (newType == 2) then - CoolTip.Type = 2 - elseif (newType == 3) then - CoolTip.Type = 3 - else - --> error - end - else - --> error - end - end - - --> Set a fixed value for menu - function CoolTip:SetFixedParameter (value, injected) - if (injected ~= nil) then - local frame = value - if (frame.dframework) then - frame = frame.widget - end - if (frame.CoolTip) then - frame.CoolTip.FixedValue = injected - else - --debug - end - end - CoolTip.FixedValue = value - end - - function CoolTip:SetColor (menuType, ...) - local ColorR, ColorG, ColorB, ColorA = DF:ParseColors (...) - if ((type (menuType) == "string" and menuType == "main") or (type (menuType) == "number" and menuType == 1)) then - frame1.framebackgroundLeft:SetVertexColor (ColorR, ColorG, ColorB, ColorA) - frame1.framebackgroundRight:SetVertexColor (ColorR, ColorG, ColorB, ColorA) - frame1.framebackgroundCenter:SetVertexColor (ColorR, ColorG, ColorB, ColorA) - - elseif ((type (menuType) == "string" and menuType == "sec") or (type (menuType) == "number" and menuType == 2)) then - frame2.framebackgroundLeft:SetVertexColor (ColorR, ColorG, ColorB, ColorA) - frame2.framebackgroundRight:SetVertexColor (ColorR, ColorG, ColorB, ColorA) - frame2.framebackgroundCenter:SetVertexColor (ColorR, ColorG, ColorB, ColorA) - - else - return --> error - end - end - - --> Set last selected option - function CoolTip:SetLastSelected (menuType, index, index2) - - if (CoolTip.Type == 3) then - if ((type (menuType) == "string" and menuType == "main") or (type (menuType) == "number" and menuType == 1)) then - CoolTip.SelectedIndexMain = index - elseif ((type (menuType) == "string" and menuType == "sec") or (type (menuType) == "number" and menuType == 2)) then - CoolTip.SelectedIndexSec [index] = index2 - else - return --> error - end - else - return --> error - end - end + --wipe all data ~reset + function CoolTip:Reset(fromPreset) + frame2:ClearAllPoints() + frame2:SetPoint("bottomleft", frame1, "bottomright", 4, 0) + frame1:SetWidth(170) + frame2:SetWidth(170) - --> serack key: ~select - function CoolTip:Select (menuType, option, mainIndex) - if (menuType == 1) then --main menu - local botao = frame1.Lines [option] - CoolTip.buttonClicked = true - CoolTip:SetSelectedAnchor (frame1, botao) + frame1:SetParent(UIParent) + frame2:SetParent(UIParent) + frame1:SetFrameStrata("TOOLTIP") + frame2:SetFrameStrata("TOOLTIP") - --UIFrameFlash (frame1.selected, 0.05, 0.05, 0.2, true, 0, 0) - - elseif (menuType == 2) then --sub menu - CoolTip:ShowSub (mainIndex) - local botao = frame2.Lines [option] - CoolTip.buttonClicked = true - - CoolTip:SetSelectedAnchor (frame2, botao) - end - end - ----------------------------------------------------------------------- - --> Reset cooltip - - local default_backdrop = {bgFile = [[Interface\DialogFrame\UI-DialogBox-Background-Dark]], edgeFile = [[Interface\Buttons\WHITE8X8]], tile = true, - edgeSize = 1, tileSize = 16, insets = {left = 0, right = 0, top = 0, bottom = 0}} - local default_backdrop_color = {0.09019, 0.09019, 0.18823, 1} - local default_backdropborder_color = {1, 1, 1, 1} - - --borda preta sem usar unpack - - --> wipe all data ~reset - function CoolTip:Reset() + CoolTip:HideSelectedTexture(frame1) + CoolTip:HideSelectedTexture(frame2) - frame2:ClearAllPoints() - frame2:SetPoint ("bottomleft", frame1, "bottomright", 4, 0) + CoolTip.FixedValue = nil + CoolTip.HaveSubMenu = false + CoolTip.SelectedIndexMain = nil + CoolTip.Indexes = 0 + CoolTip.SubIndexes = 0 + CoolTip.internalYMod = 0 + CoolTip.internalYMod = 0 + CoolTip.current_anchor = nil + CoolTip.overlapChecked = false + CoolTip.frame2_IsOnLeftside = nil - frame1:SetParent (UIParent) - frame2:SetParent (UIParent) - frame1:SetFrameStrata ("TOOLTIP") - frame2:SetFrameStrata ("TOOLTIP") - - CoolTip:HideSelectedTexture (frame1) - CoolTip:HideSelectedTexture (frame2) - - CoolTip.FixedValue = nil - CoolTip.HaveSubMenu = false - - CoolTip.SelectedIndexMain = nil - _table_wipe (CoolTip.SelectedIndexSec) - - CoolTip.Indexes = 0 - CoolTip.SubIndexes = 0 - _table_wipe (CoolTip.IndexesSub) - - CoolTip.internal_x_mod = 0 - CoolTip.internal_y_mod = 0 - CoolTip.current_anchor = nil - CoolTip.overlap_checked = false - - CoolTip.frame2_leftside = nil + wipe(CoolTip.SelectedIndexSec) + wipe(CoolTip.IndexesSub) + wipe(CoolTip.PopupFrameTable) - frame1:SetBackdrop (default_backdrop) - frame1:SetBackdropColor (unpack (default_backdrop_color)) - frame1:SetBackdropBorderColor (unpack (default_backdropborder_color)) - - frame2:SetBackdrop (default_backdrop) - frame2:SetBackdropColor (unpack (default_backdrop_color)) - frame2:SetBackdropBorderColor (unpack (default_backdropborder_color)) + wipe(CoolTip.LeftTextTable) + wipe(CoolTip.LeftTextTableSub) + wipe(CoolTip.RightTextTable) + wipe(CoolTip.RightTextTableSub) - --[ - _table_wipe (CoolTip.PopupFrameTable) - - _table_wipe (CoolTip.LeftTextTable) - _table_wipe (CoolTip.LeftTextTableSub) - _table_wipe (CoolTip.RightTextTable) - _table_wipe (CoolTip.RightTextTableSub) - - _table_wipe (CoolTip.LeftIconTable) - _table_wipe (CoolTip.LeftIconTableSub) - _table_wipe (CoolTip.RightIconTable) - _table_wipe (CoolTip.RightIconTableSub) + wipe(CoolTip.LeftIconTable) + wipe(CoolTip.LeftIconTableSub) + wipe(CoolTip.RightIconTable) + wipe(CoolTip.RightIconTableSub) - _table_wipe (CoolTip.StatusBarTable) - _table_wipe (CoolTip.StatusBarTableSub) - - _table_wipe (CoolTip.FunctionsTableMain) - _table_wipe (CoolTip.FunctionsTableSub) - - _table_wipe (CoolTip.ParametersTableMain) - _table_wipe (CoolTip.ParametersTableSub) - - _table_wipe (CoolTip.WallpaperTable) - _table_wipe (CoolTip.WallpaperTableSub) - --]] - - _table_wipe (CoolTip.TopIconTableSub) - CoolTip.Banner [1] = false - CoolTip.Banner [2] = false - CoolTip.Banner [3] = false - - frame1.upperImage:Hide() - frame1.upperImage2:Hide() - frame1.upperImageText:Hide() - frame1.upperImageText2:Hide() - - frame1.frameWallpaper:Hide() - frame2.frameWallpaper:Hide() - - frame2.upperImage:Hide() + wipe(CoolTip.StatusBarTable) + wipe(CoolTip.StatusBarTableSub) - CoolTip.title1 = nil - CoolTip.title_text = nil - - CoolTip.frame1.titleText:Hide() - CoolTip.frame1.titleIcon:Hide() - - CoolTip:ClearAllOptions() - CoolTip:SetColor (1, "transparent") - CoolTip:SetColor (2, "transparent") - - local f1Lines = frame1.Lines - for i = 1, #f1Lines do - f1Lines [i].statusbar.subMenuArrow:Hide() - end - end + wipe(CoolTip.FunctionsTableMain) + wipe(CoolTip.FunctionsTableSub) ----------------------------------------------------------------------- - --> Menu functions - - local _default_color = {1, 1, 1} - local _default_point = {"center", "center", 0, -3} - - function CoolTip:AddMenu (menuType, func, param1, param2, param3, leftText, leftIcon, indexUp) - - if (leftText and indexUp and ((type (menuType) == "string" and menuType == "main") or (type (menuType) == "number" and menuType == 1))) then - CoolTip.Indexes = CoolTip.Indexes + 1 - - if (not CoolTip.IndexesSub [CoolTip.Indexes]) then - CoolTip.IndexesSub [CoolTip.Indexes] = 0 - end - - CoolTip.SubIndexes = 0 - end - - --> need a previous line - if (CoolTip.Indexes == 0) then - print ("Indexes are 0") - return --> return error - end - - --> check data integrity - if (type (func) ~= "function") then - print ("No function") - return --> erroe - end - - --> add - - if ((type (menuType) == "string" and menuType == "main") or (type (menuType) == "number" and menuType == 1)) then + wipe(CoolTip.ParametersTableMain) + wipe(CoolTip.ParametersTableSub) - local parameterTable - if (CoolTip.isSpecial) then - parameterTable = {} - _table_insert (CoolTip.FunctionsTableMain, CoolTip.Indexes, func) - _table_insert (CoolTip.ParametersTableMain, CoolTip.Indexes, parameterTable) - else - - CoolTip.FunctionsTableMain [CoolTip.Indexes] = func - - parameterTable = CoolTip.ParametersTableMain [CoolTip.Indexes] - if (not parameterTable) then - parameterTable = {} - CoolTip.ParametersTableMain [CoolTip.Indexes] = parameterTable - end - end - - parameterTable [1] = param1 - parameterTable [2] = param2 - parameterTable [3] = param3 - - if (leftIcon) then - local iconTable = CoolTip.LeftIconTable [CoolTip.Indexes] - - if (not iconTable or CoolTip.isSpecial) then - iconTable = {} - CoolTip.LeftIconTable [CoolTip.Indexes] = iconTable - end - - iconTable [1] = leftIcon - iconTable [2] = 16 --> default 16 - iconTable [3] = 16 --> default 16 - iconTable [4] = 0 --> default 0 - iconTable [5] = 1 --> default 1 - iconTable [6] = 0 --> default 0 - iconTable [7] = 1 --> default 1 - iconTable [8] = _default_color - end - - if (leftText) then - local lineTable_left = CoolTip.LeftTextTable [CoolTip.Indexes] + wipe(CoolTip.WallpaperTable) + wipe(CoolTip.WallpaperTableSub) - if (not lineTable_left or CoolTip.isSpecial) then - lineTable_left = {} - CoolTip.LeftTextTable [CoolTip.Indexes] = lineTable_left - end - - lineTable_left [1] = leftText --> line text - lineTable_left [2] = 0 - lineTable_left [3] = 0 - lineTable_left [4] = 0 - lineTable_left [5] = 0 - lineTable_left [6] = false - lineTable_left [7] = false - lineTable_left [8] = false - - end - - elseif ((type (menuType) == "string" and menuType == "sec") or (type (menuType) == "number" and menuType == 2)) then - - if (CoolTip.SubIndexes == 0) then - if (not indexUp or not leftText) then - print ("GameCooltip Error: Attempt to add a submenu with a parent") - return --> error - end - end - - if (indexUp and leftText) then - CoolTip.SubIndexes = CoolTip.SubIndexes + 1 - CoolTip.IndexesSub [CoolTip.Indexes] = CoolTip.IndexesSub [CoolTip.Indexes] + 1 - - elseif (indexUp and not leftText) then - print ("GameCooltip Error: Attempt to add a submenu with a parent") - return --> error [leftText can't be nil if indexUp are true] - end - - --> menu container - local subMenuContainerParameters = CoolTip.ParametersTableSub [CoolTip.Indexes] - if (not subMenuContainerParameters) then - subMenuContainerParameters = {} - CoolTip.ParametersTableSub [CoolTip.Indexes] = subMenuContainerParameters - end - - local subMenuContainerFunctions = CoolTip.FunctionsTableSub [CoolTip.Indexes] - if (not subMenuContainerFunctions or CoolTip.isSpecial) then - subMenuContainerFunctions = {} - CoolTip.FunctionsTableSub [CoolTip.Indexes] = subMenuContainerFunctions - end - - --> menu table - local subMenuTablesParameters = subMenuContainerParameters [CoolTip.SubIndexes] - if (not subMenuTablesParameters or CoolTip.isSpecial) then - subMenuTablesParameters = {} - subMenuContainerParameters [CoolTip.SubIndexes] = subMenuTablesParameters - end - - --> add - subMenuContainerFunctions [CoolTip.SubIndexes] = func - - subMenuTablesParameters [1] = param1 - subMenuTablesParameters [2] = param2 - subMenuTablesParameters [3] = param3 - - --> text and icon - if (leftIcon) then - - local subMenuContainerIcons = CoolTip.LeftIconTableSub [CoolTip.Indexes] - if (not subMenuContainerIcons) then - subMenuContainerIcons = {} - CoolTip.LeftIconTableSub [CoolTip.Indexes] = subMenuContainerIcons - end - local subMenuTablesIcons = subMenuContainerIcons [CoolTip.SubIndexes] - if (not subMenuTablesIcons or CoolTip.isSpecial) then - subMenuTablesIcons = {} - subMenuContainerIcons [CoolTip.SubIndexes] = subMenuTablesIcons - end - - subMenuTablesIcons [1] = leftIcon - subMenuTablesIcons [2] = 16 --> default 16 - subMenuTablesIcons [3] = 16 --> default 16 - subMenuTablesIcons [4] = 0 --> default 0 - subMenuTablesIcons [5] = 1 --> default 1 - subMenuTablesIcons [6] = 0 --> default 0 - subMenuTablesIcons [7] = 1 --> default 1 - subMenuTablesIcons [8] = _default_color - end - - if (leftText) then - - local subMenuContainerTexts = CoolTip.LeftTextTableSub [CoolTip.Indexes] - if (not subMenuContainerTexts) then - subMenuContainerTexts = {} - CoolTip.LeftTextTableSub [CoolTip.Indexes] = subMenuContainerTexts - end - local subMenuTablesTexts = subMenuContainerTexts [CoolTip.SubIndexes] - if (not subMenuTablesTexts or CoolTip.isSpecial) then - subMenuTablesTexts = {} - subMenuContainerTexts [CoolTip.SubIndexes] = subMenuTablesTexts - end - - subMenuTablesTexts [1] = leftText --> line text - subMenuTablesTexts [2] = 0 - subMenuTablesTexts [3] = 0 - subMenuTablesTexts [4] = 0 - subMenuTablesTexts [5] = 0 - subMenuTablesTexts [6] = false - subMenuTablesTexts [7] = false - subMenuTablesTexts [8] = false - - end - - CoolTip.HaveSubMenu = true - - else - return --> error - end - end - ----------------------------------------------------------------------- - --> adds a statusbar to the last line added. - --> only works with cooltip type 2 (tooltip with bars) - --> parameters: value [, color red, color green, color blue, color alpha [, glow]] - --> can also use a table or html color name in color red and send glow in color green - - function CoolTip:AddStatusBar (statusbarValue, frame, ColorR, ColorG, ColorB, ColorA, statusbarGlow, backgroundBar, barTexture) - - --> need a previous line - if (CoolTip.Indexes == 0) then - return --> return error - end - - --> check data integrity - if (type (statusbarValue) ~= "number") then - return --> error - end - - if (type (ColorR) == "table" or type (ColorR) == "string") then - statusbarGlow, backgroundBar, ColorR, ColorG, ColorB, ColorA = ColorG, ColorB, DF:ParseColors (ColorR) - elseif (type (ColorR) == "boolean") then - backgroundBar = ColorG - statusbarGlow = ColorR - ColorR, ColorG, ColorB, ColorA = 1, 1, 1, 1 - else - --> error - end - - --> add - local frameTable - local statusbarTable - - if (not frame or (type (frame) == "string" and frame == "main") or (type (frame) == "number" and frame == 1)) then - frameTable = CoolTip.StatusBarTable - - if (CoolTip.isSpecial) then - statusbarTable = {} - _table_insert (frameTable, CoolTip.Indexes, statusbarTable) - else - statusbarTable = frameTable [CoolTip.Indexes] - if (not statusbarTable) then - statusbarTable = {} - _table_insert (frameTable, CoolTip.Indexes, statusbarTable) - --frameTable [CoolTip.Indexes] = statusbarTable - end - end - - elseif ((type (frame) == "string" and frame == "sub") or (type (frame) == "number" and frame == 2)) then - - frameTable = CoolTip.StatusBarTableSub - - local subMenuContainerStatusBar = frameTable [CoolTip.Indexes] - if (not subMenuContainerStatusBar) then - subMenuContainerStatusBar = {} - frameTable [CoolTip.Indexes] = subMenuContainerStatusBar - end - - if (CoolTip.isSpecial) then - statusbarTable = {} - _table_insert (subMenuContainerStatusBar, CoolTip.SubIndexes, statusbarTable) - else - statusbarTable = subMenuContainerStatusBar [CoolTip.SubIndexes] - if (not statusbarTable) then - statusbarTable = {} - _table_insert (subMenuContainerStatusBar, CoolTip.SubIndexes, statusbarTable) - end - end - else - print ("unknow frame") - return --> error - end - - statusbarTable [1] = statusbarValue - statusbarTable [2] = ColorR - statusbarTable [3] = ColorG - statusbarTable [4] = ColorB - statusbarTable [5] = ColorA - statusbarTable [6] = statusbarGlow - statusbarTable [7] = backgroundBar - statusbarTable [8] = barTexture - - end + wipe(CoolTip.TopIconTableSub) + CoolTip.Banner[1] = false + CoolTip.Banner[2] = false + CoolTip.Banner[3] = false + frame1.upperImage:Hide() + frame1.upperImage2:Hide() + frame1.upperImageText:Hide() + frame1.upperImageText2:Hide() frame1.frameWallpaper:Hide() frame2.frameWallpaper:Hide() - - function CoolTip:SetWallpaper (index, texture, texcoord, color, desaturate) - - if (CoolTip.Indexes == 0) then - return --> return error - end - - local frameTable - local wallpaperTable - - if ( (type (index) == "number" and index == 1) or (type (index) == "string" and index == "main") ) then - wallpaperTable = CoolTip.WallpaperTable + frame2.upperImage:Hide() - elseif ( (type (index) == "number" and index == 2) or (type (index) == "string" and index == "sub") ) then - frameTable = CoolTip.WallpaperTableSub - - local subMenuContainerWallpapers = frameTable [CoolTip.Indexes] - if (not subMenuContainerWallpapers) then - subMenuContainerWallpapers = {} - frameTable [CoolTip.Indexes] = subMenuContainerWallpapers - end - - wallpaperTable = subMenuContainerWallpapers - end - - wallpaperTable [1] = texture - if (texcoord) then - wallpaperTable [2] = texcoord [1] - wallpaperTable [3] = texcoord [2] - wallpaperTable [4] = texcoord [3] - wallpaperTable [5] = texcoord [4] - else - wallpaperTable [2] = 0 - wallpaperTable [3] = 1 - wallpaperTable [4] = 0 - wallpaperTable [5] = 1 - end - wallpaperTable [6] = color - wallpaperTable [7] = desaturate - end - - function CoolTip:SetBannerText (index, text, anchor, color, fontsize, fontface, fontflag) - local fontstring - - if (index == 1) then - fontstring = frame1.upperImageText - elseif (index == 2) then - fontstring = frame1.upperImageText2 - end - - fontstring:SetText (text or "") - - if (anchor and index == 1) then - local myAnchor, hisAnchor, x, y = unpack (anchor) - fontstring:SetPoint (myAnchor, frame1.upperImage, hisAnchor or myAnchor, x or 0, y or 0) - elseif (anchor and index == 2) then - local myAnchor, hisAnchor, x, y = unpack (anchor) - fontstring:SetPoint (myAnchor, frame1, hisAnchor or myAnchor, x or 0, y or 0) - end - - if (color) then - local r, g, b, a = DF:ParseColors (color) - fontstring:SetTextColor (r, g, b, a) - end - - local face, size, flags = fontstring:GetFont() - face = fontface or [[Fonts\FRIZQT__.TTF]] - size = fontsize or 13 - flags = fontflag or nil - fontstring:SetFont (face, size, flags) - fontstring:Show() - end - - function CoolTip:SetBackdrop (index, backdrop, backdropcolor, bordercolor) - - local f - if (index == 1) then - f = frame1 - elseif (index == 2) then - f = frame2 - end - - if (backdrop) then - f:SetBackdrop (backdrop) - end - if (backdropcolor) then - local r, g, b, a = DF:ParseColors (backdropcolor) - f:SetBackdropColor (r, g, b, a) - end - if (bordercolor) then - local r, g, b, a = DF:ParseColors (bordercolor) - f:SetBackdropBorderColor (r, g, b, a) - end - - --[=[ - f:SetBackdrop (nil) - - f.framebackgroundCenter:SetTexture (nil) - f.framebackgroundLeft:SetTexture (nil) - f.framebackgroundRight:SetTexture (nil) - f.frameWallpaper:SetTexture (nil) - --]=] - end - - function CoolTip:SetBannerImage (index, texturepath, width, height, anchor, texcoord, overlay) - - local texture - - if (index == 1) then - texture = frame1.upperImage - elseif (index == 2) then - texture = frame1.upperImage2 - end - - if (texturepath) then - texture:SetTexture (texturepath) - end - - if (width) then - texture:SetWidth (width) - end - if (height) then - texture:SetHeight (height) - end - - if (anchor) then - if (type (anchor[1]) == "table") then - for _, t in _ipairs (anchor) do - local myAnchor, hisAnchor, x, y = unpack (t) - texture:SetPoint (myAnchor, frame1, hisAnchor or myAnchor, x or 0, y or 0) - end - else - local myAnchor, hisAnchor, x, y = unpack (anchor) - texture:SetPoint (myAnchor, frame1, hisAnchor or myAnchor, x or 0, y or 0) - end - end - - if (texcoord) then - local L, R, T, B = unpack (texcoord) - texture:SetTexCoord (L, R, T, B) - end - - if (overlay) then - texture:SetVertexColor (unpack (overlay)) - end - - CoolTip.Banner [index] = true - texture:Show() + CoolTip.title1 = nil + CoolTip.title_text = nil + CoolTip.frame1.titleText:Hide() + CoolTip.frame1.titleIcon:Hide() + CoolTip:ClearAllOptions() + CoolTip:SetColor(1, "transparent") + CoolTip:SetColor(2, "transparent") + + for i = 1, #frame1.Lines do + frame1.Lines[i].statusbar.subMenuArrow:Hide() end - + + --older versions has these three textures + if (frame1.frameBackgroundLeft) then + frame1.frameBackgroundLeft:Hide() + frame1.frameBackgroundRight:Hide() + frame1.frameBackgroundCenter:Hide() + end + frame1.frameBackgroundTexture:SetVertexColor(0, 0, 0, 0) + + if (not fromPreset) then + CoolTip:Preset(3, true) + end + end + ---------------------------------------------------------------------- - --> adds a icon to the last line added. - --> only works with cooltip type 1 and 2 (tooltip and tooltip with bars) - --> parameters: icon [, width [, height [, TexCoords L R T B ]]] - --> texture support string path or texture object - - function CoolTip:AddTexture (iconTexture, frame, side, iconWidth, iconHeight, L, R, T, B, overlayColor, point, desaturated) - return CoolTip:AddIcon (iconTexture, frame, side, iconWidth, iconHeight, L, R, T, B, overlayColor, point, desaturated) + --menu functions + local defaultWhiteColor = {1, 1, 1} + function CoolTip:AddMenu(menuType, func, param1, param2, param3, leftText, leftIcon, indexUp) + if (leftText and indexUp and ((type(menuType) == "string" and menuType == CONST_MENU_TYPE_MAINMENU) or (type(menuType) == "number" and menuType == 1))) then + CoolTip.Indexes = CoolTip.Indexes + 1 + if (not CoolTip.IndexesSub[CoolTip.Indexes]) then + CoolTip.IndexesSub[CoolTip.Indexes] = 0 + end + CoolTip.SubIndexes = 0 end - function CoolTip:AddIcon (iconTexture, frame, side, iconWidth, iconHeight, L, R, T, B, overlayColor, point, desaturated) - --> need a previous line - if (CoolTip.Indexes == 0) then - return --> return error - end - - --> check data integrity - if ( (type (iconTexture) ~= "string" and type (iconTexture) ~= "number") and (type (iconTexture) ~= "table" or not iconTexture.GetObjectType or iconTexture:GetObjectType() ~= "Texture") ) then - return --> return error - end - - side = side or 1 + --need a previous line + if (CoolTip.Indexes == 0) then + return CoolTip:PrintDebug("AddMenu() requires an already added line (Cooltip:AddLine()).") + end - local frameTable - local iconTable + --check data integrity + if (type(func) ~= "function") then + return CoolTip:PrintDebug("AddMenu() no function passed.") + end - if (not frame or (type (frame) == "string" and frame == "main") or (type (frame) == "number" and frame == 1)) then - - if (not side or (type (side) == "string" and side == "left") or (type (side) == "number" and side == 1)) then - frameTable = CoolTip.LeftIconTable - - elseif ((type (side) == "string" and side == "right") or (type (side) == "number" and side == 2)) then - frameTable = CoolTip.RightIconTable - + if ((type(menuType) == "string" and menuType == CONST_MENU_TYPE_MAINMENU) or (type(menuType) == "number" and menuType == 1)) then + local parameterTable + if (CoolTip.isSpecial) then + parameterTable = {} + insert(CoolTip.FunctionsTableMain, CoolTip.Indexes, func) + insert(CoolTip.ParametersTableMain, CoolTip.Indexes, parameterTable) + else + CoolTip.FunctionsTableMain[CoolTip.Indexes] = func + parameterTable = CoolTip.ParametersTableMain[CoolTip.Indexes] + if (not parameterTable) then + parameterTable = {} + CoolTip.ParametersTableMain[CoolTip.Indexes] = parameterTable end - - if (CoolTip.isSpecial) then + end + + parameterTable[1] = param1 + parameterTable[2] = param2 + parameterTable[3] = param3 + + if (leftIcon) then + local iconTable = CoolTip.LeftIconTable[CoolTip.Indexes] + if (not iconTable or CoolTip.isSpecial) then iconTable = {} - _table_insert (frameTable, CoolTip.Indexes, iconTable) - else - iconTable = frameTable [CoolTip.Indexes] - if (not iconTable) then - iconTable = {} - _table_insert (frameTable, CoolTip.Indexes, iconTable) - --frameTable [CoolTip.Indexes] = iconTable - end + CoolTip.LeftIconTable[CoolTip.Indexes] = iconTable end - - elseif ((type (frame) == "string" and frame == "sub") or (type (frame) == "number" and frame == 2)) then - - if ((type (side) == "string" and side == "left") or (type (side) == "number" and side == 1)) then - frameTable = CoolTip.LeftIconTableSub - elseif ((type (side) == "string" and side == "right") or (type (side) == "number" and side == 2)) then - frameTable = CoolTip.RightIconTableSub - elseif ((type (side) == "string" and side == "top") or (type (side) == "number" and side == 3)) then - CoolTip.TopIconTableSub [CoolTip.Indexes] = CoolTip.TopIconTableSub [CoolTip.Indexes] or {} - CoolTip.TopIconTableSub [CoolTip.Indexes] [1] = iconTexture - CoolTip.TopIconTableSub [CoolTip.Indexes] [2] = iconWidth or 16 - CoolTip.TopIconTableSub [CoolTip.Indexes] [3] = iconHeight or 16 - CoolTip.TopIconTableSub [CoolTip.Indexes] [4] = L or 0 - CoolTip.TopIconTableSub [CoolTip.Indexes] [5] = R or 1 - CoolTip.TopIconTableSub [CoolTip.Indexes] [6] = T or 0 - CoolTip.TopIconTableSub [CoolTip.Indexes] [7] = B or 1 - CoolTip.TopIconTableSub [CoolTip.Indexes] [8] = overlayColor or _default_color - CoolTip.TopIconTableSub [CoolTip.Indexes] [9] = desaturated - return + iconTable[1] = leftIcon + iconTable[2] = 16 --default 16 + iconTable[3] = 16 --default 16 + iconTable[4] = 0 --default 0 + iconTable[5] = 1 --default 1 + iconTable[6] = 0 --default 0 + iconTable[7] = 1 --default 1 + iconTable[8] = defaultWhiteColor + end + + if (leftText) then + local lineTable_Left = CoolTip.LeftTextTable[CoolTip.Indexes] + if (not lineTable_Left or CoolTip.isSpecial) then + lineTable_Left = {} + CoolTip.LeftTextTable[CoolTip.Indexes] = lineTable_Left end - - local subMenuContainerIcons = frameTable [CoolTip.Indexes] + lineTable_Left[1] = leftText + lineTable_Left[2] = 0 + lineTable_Left[3] = 0 + lineTable_Left[4] = 0 + lineTable_Left[5] = 0 + lineTable_Left[6] = false + lineTable_Left[7] = false + lineTable_Left[8] = false + end + + elseif ((type(menuType) == "string" and menuType == CONST_MENU_TYPE_SUBMENU) or (type(menuType) == "number" and menuType == 2)) then + if (CoolTip.SubIndexes == 0) then + if (not indexUp or not leftText) then + return CoolTip:PrintDebug("AddMenu() attempt to add a submenu with a parent.") --error[leftText can't be nil if indexUp are true] + end + end + + if (indexUp and leftText) then + CoolTip.SubIndexes = CoolTip.SubIndexes + 1 + CoolTip.IndexesSub[CoolTip.Indexes] = CoolTip.IndexesSub[CoolTip.Indexes] + 1 + + elseif (indexUp and not leftText) then + return CoolTip:PrintDebug("AddMenu() attempt to add a submenu with a parent.") --error[leftText can't be nil if indexUp are true] + end + + --menu container + local subMenuContainerParameters = CoolTip.ParametersTableSub[CoolTip.Indexes] + if (not subMenuContainerParameters) then + subMenuContainerParameters = {} + CoolTip.ParametersTableSub[CoolTip.Indexes] = subMenuContainerParameters + end + + local subMenuContainerFunctions = CoolTip.FunctionsTableSub[CoolTip.Indexes] + if (not subMenuContainerFunctions or CoolTip.isSpecial) then + subMenuContainerFunctions = {} + CoolTip.FunctionsTableSub[CoolTip.Indexes] = subMenuContainerFunctions + end + + --menu table + local subMenuTablesParameters = subMenuContainerParameters[CoolTip.SubIndexes] + if (not subMenuTablesParameters or CoolTip.isSpecial) then + subMenuTablesParameters = {} + subMenuContainerParameters[CoolTip.SubIndexes] = subMenuTablesParameters + end + + --add + subMenuContainerFunctions[CoolTip.SubIndexes] = func + subMenuTablesParameters[1] = param1 + subMenuTablesParameters[2] = param2 + subMenuTablesParameters[3] = param3 + + --text and icon + if (leftIcon) then + local subMenuContainerIcons = CoolTip.LeftIconTableSub[CoolTip.Indexes] if (not subMenuContainerIcons) then subMenuContainerIcons = {} - frameTable [CoolTip.Indexes] = subMenuContainerIcons + CoolTip.LeftIconTableSub[CoolTip.Indexes] = subMenuContainerIcons end - - if (CoolTip.isSpecial) then + local subMenuTablesIcons = subMenuContainerIcons[CoolTip.SubIndexes] + if (not subMenuTablesIcons or CoolTip.isSpecial) then + subMenuTablesIcons = {} + subMenuContainerIcons[CoolTip.SubIndexes] = subMenuTablesIcons + end + + subMenuTablesIcons[1] = leftIcon + subMenuTablesIcons[2] = 16 --default 16 + subMenuTablesIcons[3] = 16 --default 16 + subMenuTablesIcons[4] = 0 --default 0 + subMenuTablesIcons[5] = 1 --default 1 + subMenuTablesIcons[6] = 0 --default 0 + subMenuTablesIcons[7] = 1 --default 1 + subMenuTablesIcons[8] = defaultWhiteColor + end + + if (leftText) then + local subMenuContainerTexts = CoolTip.LeftTextTableSub[CoolTip.Indexes] + if (not subMenuContainerTexts) then + subMenuContainerTexts = {} + CoolTip.LeftTextTableSub[CoolTip.Indexes] = subMenuContainerTexts + end + local subMenuTablesTexts = subMenuContainerTexts[CoolTip.SubIndexes] + if (not subMenuTablesTexts or CoolTip.isSpecial) then + subMenuTablesTexts = {} + subMenuContainerTexts[CoolTip.SubIndexes] = subMenuTablesTexts + end + + subMenuTablesTexts[1] = leftText + subMenuTablesTexts[2] = 0 + subMenuTablesTexts[3] = 0 + subMenuTablesTexts[4] = 0 + subMenuTablesTexts[5] = 0 + subMenuTablesTexts[6] = false + subMenuTablesTexts[7] = false + subMenuTablesTexts[8] = false + end + + CoolTip.HaveSubMenu = true + else + return CoolTip:PrintDebug("AddMenu() unknown menuType.", menuType) + end + end + +---------------------------------------------------------------------- + --adds a statusbar to the last line added. + --only works with cooltip type2 (tooltip with bars) + --parameters: value [, color red, color green, color blue, color alpha [, glow]] + --can also use a table or html color name in color red and send glow in color green + function CoolTip:AddStatusBar(statusbarValue, menuType, colorRed, colorGreen, colorBlue, colorAlpha, statusbarGlow, backgroundBar, barTexture) + --need a previous line + if (CoolTip.Indexes == 0) then + return CoolTip:PrintDebug("AddStatusBar() requires an already added line (Cooltip:AddLine()).") + end + + --check data integrity + if (type(statusbarValue) ~= "number") then + return + end + + if (type(colorRed) == "table" or type(colorRed) == "string") then + statusbarGlow, backgroundBar, colorRed, colorGreen, colorBlue, colorAlpha = colorGreen, colorBlue, DF:ParseColors(colorRed) + elseif (type(colorRed) == "boolean") then + backgroundBar = colorGreen + statusbarGlow = colorRed + colorRed, colorGreen, colorBlue, colorAlpha = 1, 1, 1, 1 + end + + --add + local frameTable + local statusbarTable + if (not menuType or (type(menuType) == "string" and menuType == CONST_MENU_TYPE_MAINMENU) or (type(menuType) == "number" and menuType == 1)) then + frameTable = CoolTip.StatusBarTable + if (CoolTip.isSpecial) then + statusbarTable = {} + insert(frameTable, CoolTip.Indexes, statusbarTable) + else + statusbarTable = frameTable[CoolTip.Indexes] + if (not statusbarTable) then + statusbarTable = {} + insert(frameTable, CoolTip.Indexes, statusbarTable) + end + end + + elseif ((type(menuType) == "string" and menuType == "sub") or (type(menuType) == "number" and menuType == 2)) then + frameTable = CoolTip.StatusBarTableSub + local subMenuContainerStatusBar = frameTable[CoolTip.Indexes] + if (not subMenuContainerStatusBar) then + subMenuContainerStatusBar = {} + frameTable[CoolTip.Indexes] = subMenuContainerStatusBar + end + + if (CoolTip.isSpecial) then + statusbarTable = {} + insert(subMenuContainerStatusBar, CoolTip.SubIndexes, statusbarTable) + else + statusbarTable = subMenuContainerStatusBar[CoolTip.SubIndexes] + if (not statusbarTable) then + statusbarTable = {} + insert(subMenuContainerStatusBar, CoolTip.SubIndexes, statusbarTable) + end + end + else + return CoolTip:PrintDebug("AddStatusBar() unknown menuType.", menuType) + end + + statusbarTable[1] = statusbarValue + statusbarTable[2] = colorRed + statusbarTable[3] = colorGreen + statusbarTable[4] = colorBlue + statusbarTable[5] = colorAlpha + statusbarTable[6] = statusbarGlow + statusbarTable[7] = backgroundBar + statusbarTable[8] = barTexture + end + + frame1.frameWallpaper:Hide() + frame2.frameWallpaper:Hide() + function CoolTip:SetWallpaper(index, texture, texcoord, color, desaturate) + if (CoolTip.Indexes == 0) then + return CoolTip:PrintDebug("SetWallpaper() requires an already added line (Cooltip:AddLine()).") + end + + local frameTable + local wallpaperTable + if ((type(index) == "number" and index == 1) or (type(index) == "string" and index == CONST_MENU_TYPE_MAINMENU)) then + wallpaperTable = CoolTip.WallpaperTable + + elseif ((type(index) == "number" and index == 2) or (type(index) == "string" and index == "sub")) then + frameTable = CoolTip.WallpaperTableSub + local subMenuContainerWallpapers = frameTable[CoolTip.Indexes] + if (not subMenuContainerWallpapers) then + subMenuContainerWallpapers = {} + frameTable[CoolTip.Indexes] = subMenuContainerWallpapers + end + wallpaperTable = subMenuContainerWallpapers + end + + wallpaperTable[1] = texture + if (texcoord) then + wallpaperTable[2] = texcoord[1] + wallpaperTable[3] = texcoord[2] + wallpaperTable[4] = texcoord[3] + wallpaperTable[5] = texcoord[4] + else + wallpaperTable[2] = 0 + wallpaperTable[3] = 1 + wallpaperTable[4] = 0 + wallpaperTable[5] = 1 + end + wallpaperTable[6] = color + wallpaperTable[7] = desaturate + end + + function CoolTip:SetBannerText(index, text, anchor, color, fontSize, fontFace, fontFlag) + local fontstring + if (index == 1) then + fontstring = frame1.upperImageText + elseif (index == 2) then + fontstring = frame1.upperImageText2 + end + + fontstring:SetText(text or "") + + if (anchor and index == 1) then + local myAnchor, hisAnchor, x, y = unpack(anchor) + fontstring:SetPoint(myAnchor, frame1.upperImage, hisAnchor or myAnchor, x or 0, y or 0) + elseif (anchor and index == 2) then + local myAnchor, hisAnchor, x, y = unpack(anchor) + fontstring:SetPoint(myAnchor, frame1, hisAnchor or myAnchor, x or 0, y or 0) + end + + if (color) then + local r, g, b, a = DF:ParseColors(color) + fontstring:SetTextColor(r, g, b, a) + end + + local face, size, flags = fontstring:GetFont() + face = fontFace or DF:GetBestFontForLanguage() + size = fontSize or 13 + flags = fontFlag or nil + fontstring:SetFont(face, size, flags) + fontstring:Show() + end + + function CoolTip:SetBackdrop(index, backdrop, backdropcolor, bordercolor) + local frame + if (index == 1) then + frame = frame1 + elseif (index == 2) then + frame = frame2 + end + + if (backdrop) then + frame:SetBackdrop(backdrop) + end + if (backdropcolor) then + local r, g, b, a = DF:ParseColors(backdropcolor) + frame:SetBackdropColor(r, g, b, a) + end + if (bordercolor) then + local r, g, b, a = DF:ParseColors(bordercolor) + frame:SetBackdropBorderColor(r, g, b, a) + end + end + + function CoolTip:SetBannerImage(index, texturePath, width, height, anchor, texCoord, overlay) + local texture + if (index == 1) then + texture = frame1.upperImage + elseif (index == 2) then + texture = frame1.upperImage2 + end + + if (texturePath) then + texture:SetTexture(texturePath) + end + + if (width) then + texture:SetWidth(width) + end + if (height) then + texture:SetHeight(height) + end + + if (anchor) then + if (type(anchor[1]) == "table") then + for _, anchorPoints in ipairs(anchor) do + local myAnchor, hisAnchor, x, y = unpack(anchorPoints) + texture:SetPoint(myAnchor, frame1, hisAnchor or myAnchor, x or 0, y or 0) + end + else + local myAnchor, hisAnchor, x, y = unpack(anchor) + texture:SetPoint(myAnchor, frame1, hisAnchor or myAnchor, x or 0, y or 0) + end + end + + if (texCoord) then + local L, R, T, B = unpack(texCoord) + texture:SetTexCoord(L, R, T, B) + end + if (overlay) then + texture:SetVertexColor(unpack(overlay)) + end + + CoolTip.Banner[index] = true + texture:Show() + end + +---------------------------------------------------------------------- + --adds a icon to the last line added. + --only works with cooltip type1 and 2 (tooltip and tooltip with bars) + --parameters: icon [, width [, height [, TexCoords L R T B ]]] + --texture support string path or texture object + + function CoolTip:AddTexture(iconTexture, menuType, side, iconWidth, iconHeight, L, R, T, B, overlayColor, point, desaturated) + return CoolTip:AddIcon(iconTexture, menuType, side, iconWidth, iconHeight, L, R, T, B, overlayColor, point, desaturated) + end + + function CoolTip:AddIcon(iconTexture, menuType, side, iconWidth, iconHeight, L, R, T, B, overlayColor, point, desaturated) + --need a previous line + if (CoolTip.Indexes == 0) then + return CoolTip:PrintDebug("AddIcon() requires an already added line (Cooltip:AddLine()).") + end + --check data integrity + if ((type(iconTexture) ~= "string" and type(iconTexture) ~= "number") and (type(iconTexture) ~= "table" or not iconTexture.GetObjectType or iconTexture:GetObjectType() ~= "Texture")) then + return CoolTip:PrintDebug("AddIcon() invalid parameters.") + end + + side = side or 1 + local frameTable + local iconTable + + if (not menuType or (type(menuType) == "string" and menuType == CONST_MENU_TYPE_MAINMENU) or (type(menuType) == "number" and menuType == 1)) then + if (not side or (type(side) == "string" and side == "left") or (type(side) == "number" and side == 1)) then + frameTable = CoolTip.LeftIconTable + + elseif ((type(side) == "string" and side == "right") or (type(side) == "number" and side == 2)) then + frameTable = CoolTip.RightIconTable + end + + if (CoolTip.isSpecial) then + iconTable = {} + insert(frameTable, CoolTip.Indexes, iconTable) + else + iconTable = frameTable[CoolTip.Indexes] + if (not iconTable) then iconTable = {} - subMenuContainerIcons [CoolTip.SubIndexes] = iconTable - else - iconTable = subMenuContainerIcons [CoolTip.SubIndexes] - if (not iconTable) then - iconTable = {} - subMenuContainerIcons [CoolTip.SubIndexes] = iconTable - end + insert(frameTable, CoolTip.Indexes, iconTable) end - + end + + elseif ((type(menuType) == "string" and menuType == "sub") or (type(menuType) == "number" and menuType == 2)) then + if ((type(side) == "string" and side == "left") or (type(side) == "number" and side == 1)) then + frameTable = CoolTip.LeftIconTableSub + + elseif ((type(side) == "string" and side == "right") or (type(side) == "number" and side == 2)) then + frameTable = CoolTip.RightIconTableSub + + elseif ((type(side) == "string" and side == "top") or (type(side) == "number" and side == 3)) then + CoolTip.TopIconTableSub[CoolTip.Indexes] = CoolTip.TopIconTableSub[CoolTip.Indexes] or {} + CoolTip.TopIconTableSub[CoolTip.Indexes][1] = iconTexture + CoolTip.TopIconTableSub[CoolTip.Indexes][2] = iconWidth or 16 + CoolTip.TopIconTableSub[CoolTip.Indexes][3] = iconHeight or 16 + CoolTip.TopIconTableSub[CoolTip.Indexes][4] = L or 0 + CoolTip.TopIconTableSub[CoolTip.Indexes][5] = R or 1 + CoolTip.TopIconTableSub[CoolTip.Indexes][6] = T or 0 + CoolTip.TopIconTableSub[CoolTip.Indexes][7] = B or 1 + CoolTip.TopIconTableSub[CoolTip.Indexes][8] = overlayColor or defaultWhiteColor + CoolTip.TopIconTableSub[CoolTip.Indexes][9] = desaturated + return + end + + local subMenuContainerIcons = frameTable[CoolTip.Indexes] + if (not subMenuContainerIcons) then + subMenuContainerIcons = {} + frameTable[CoolTip.Indexes] = subMenuContainerIcons + end + + if (CoolTip.isSpecial) then + iconTable = {} + subMenuContainerIcons[CoolTip.SubIndexes] = iconTable else - return --> error + iconTable = subMenuContainerIcons[CoolTip.SubIndexes] + if (not iconTable) then + iconTable = {} + subMenuContainerIcons[CoolTip.SubIndexes] = iconTable + end end + else + return --error + end - iconTable [1] = iconTexture - iconTable [2] = iconWidth or 16 --> default 16 - iconTable [3] = iconHeight or 16 --> default 16 - iconTable [4] = L or 0 --> default 0 - iconTable [5] = R or 1 --> default 1 - iconTable [6] = T or 0 --> default 0 - iconTable [7] = B or 1 --> default 1 - iconTable [8] = overlayColor or _default_color --> default 1, 1, 1 - iconTable [9] = desaturated - - return true - end - ----------------------------------------------------------------------- - --> popup frame - function CoolTip:AddPopUpFrame (func_on_show, func_on_hide, param1, param2) - - -- act like a sub menu - if (CoolTip.Indexes > 0) then - CoolTip.PopupFrameTable [CoolTip.Indexes] = {func_on_show or false, func_on_hide or false, param1, param2} - end - - end + iconTable[1] = iconTexture + iconTable[2] = iconWidth or 16 --default 16 + iconTable[3] = iconHeight or 16 --default 16 + iconTable[4] = L or 0 --default 0 + iconTable[5] = R or 1 --default 1 + iconTable[6] = T or 0 --default 0 + iconTable[7] = B or 1 --default 1 + iconTable[8] = overlayColor or defaultWhiteColor --default 1, 1, 1 + iconTable[9] = desaturated + + return true + end ---------------------------------------------------------------------- - --> adds a line. - --> only works with cooltip type 1 and 2 (tooltip and tooltip with bars) - --> parameters: left text, right text [, L color R, L color G, L color B, L color A [, R color R, R color G, R color B, R color A [, wrap]]] - - --> alias - function CoolTip:AddDoubleLine (leftText, rightText, frame, ColorR1, ColorG1, ColorB1, ColorA1, ColorR2, ColorG2, ColorB2, ColorA2, fontSize, fontFace, fontFlag) - return CoolTip:AddLine (leftText, rightText, frame, ColorR1, ColorG1, ColorB1, ColorA1, ColorR2, ColorG2, ColorB2, ColorA2, fontSize, fontFace, fontFlag) + --popup frame + function CoolTip:AddPopUpFrame(onShowFunc, onHideFunc, param1, param2) + --act like a sub menu + if (CoolTip.Indexes > 0) then + CoolTip.PopupFrameTable[CoolTip.Indexes] = {onShowFunc or false, onHideFunc or false, param1, param2} end - - --> adds a line for tooltips - function CoolTip:AddLine (leftText, rightText, frame, ColorR1, ColorG1, ColorB1, ColorA1, ColorR2, ColorG2, ColorB2, ColorA2, fontSize, fontFace, fontFlag) - - --> check data integrity - local t = type (leftText) - if (t ~= "string") then - if (t == "number") then - leftText = tostring (leftText) - else - leftText = "" - end - end - - local t = type (rightText) - if (t ~= "string") then - if (t == "number") then - rightText = tostring (rightText) - else - rightText = "" - end - end - - if (type (ColorR1) ~= "number") then - ColorR2, ColorG2, ColorB2, ColorA2, fontSize, fontFace, fontFlag = ColorG1, ColorB1, ColorA1, ColorR2, ColorG2, ColorB2, ColorA2 - - if (type (ColorR1) == "boolean" or not ColorR1) then - ColorR1, ColorG1, ColorB1, ColorA1 = 0, 0, 0, 0 - else - ColorR1, ColorG1, ColorB1, ColorA1 = DF:ParseColors (ColorR1) - end - end - - if (type (ColorR2) ~= "number") then - fontSize, fontFace, fontFlag = ColorG2, ColorB2, ColorA2 - - if (type (ColorR2) == "boolean" or not ColorR2) then - ColorR2, ColorG2, ColorB2, ColorA2 = 0, 0, 0, 0 - else - ColorR2, ColorG2, ColorB2, ColorA2 = DF:ParseColors (ColorR2) - end - end - - local frameTableLeft - local frameTableRight - local lineTable_left - local lineTable_right - - if (not frame or (type (frame) == "string" and frame == "main") or (type (frame) == "number" and frame == 1)) then - - CoolTip.Indexes = CoolTip.Indexes + 1 - - if (not CoolTip.IndexesSub [CoolTip.Indexes]) then - CoolTip.IndexesSub [CoolTip.Indexes] = 0 - end - - CoolTip.SubIndexes = 0 - - frameTableLeft = CoolTip.LeftTextTable - frameTableRight = CoolTip.RightTextTable - - if (CoolTip.isSpecial) then - lineTable_left = {} - _table_insert (frameTableLeft, CoolTip.Indexes, lineTable_left) - lineTable_right = {} - _table_insert (frameTableRight, CoolTip.Indexes, lineTable_right) - else - lineTable_left = frameTableLeft [CoolTip.Indexes] - lineTable_right = frameTableRight [CoolTip.Indexes] - - if (not lineTable_left) then - lineTable_left = {} - _table_insert (frameTableLeft, CoolTip.Indexes, lineTable_left) - end - if (not lineTable_right) then - lineTable_right = {} - _table_insert (frameTableRight, CoolTip.Indexes, lineTable_right) - end - end + end - elseif ((type (frame) == "string" and frame == "sub") or (type (frame) == "number" and frame == 2)) then - - CoolTip.SubIndexes = CoolTip.SubIndexes + 1 - CoolTip.IndexesSub [CoolTip.Indexes] = CoolTip.IndexesSub [CoolTip.Indexes] + 1 - CoolTip.HaveSubMenu = true - - frameTableLeft = CoolTip.LeftTextTableSub - frameTableRight = CoolTip.RightTextTableSub - - local subMenuContainerTexts = frameTableLeft [CoolTip.Indexes] - if (not subMenuContainerTexts) then - subMenuContainerTexts = {} - _table_insert (frameTableLeft, CoolTip.Indexes, subMenuContainerTexts) - end - - if (CoolTip.isSpecial) then - lineTable_left = {} - _table_insert (subMenuContainerTexts, CoolTip.SubIndexes, lineTable_left) - else - lineTable_left = subMenuContainerTexts [CoolTip.SubIndexes] - if (not lineTable_left) then - lineTable_left = {} - --subMenuContainerTexts [CoolTip.SubIndexes] = lineTable_left - _table_insert (subMenuContainerTexts, CoolTip.SubIndexes, lineTable_left) - end - end +---------------------------------------------------------------------- + --adds a line. + --only works with cooltip type1 and 2 (tooltip and tooltip with bars) + --parameters: left text, right text[, L color R, L color G, L color B, L color A[, R color R, R color G, R color B, R color A[, wrap]]] + function CoolTip:AddDoubleLine (leftText, rightText, menuType, ColorR1, ColorG1, ColorB1, ColorA1, ColorR2, ColorG2, ColorB2, ColorA2, fontSize, fontFace, fontFlag) + return CoolTip:AddLine(leftText, rightText, menuType, ColorR1, ColorG1, ColorB1, ColorA1, ColorR2, ColorG2, ColorB2, ColorA2, fontSize, fontFace, fontFlag) + end - local subMenuContainerTexts = frameTableRight [CoolTip.Indexes] - if (not subMenuContainerTexts) then - subMenuContainerTexts = {} - _table_insert (frameTableRight, CoolTip.Indexes, subMenuContainerTexts) - --frameTableRight [CoolTip.Indexes] = subMenuContainerTexts - end - - if (CoolTip.isSpecial) then - lineTable_right = {} - _table_insert (subMenuContainerTexts, CoolTip.SubIndexes, lineTable_right) - else - lineTable_right = subMenuContainerTexts [CoolTip.SubIndexes] - if (not lineTable_right) then - lineTable_right = {} - _table_insert (subMenuContainerTexts, CoolTip.SubIndexes, lineTable_right) - --subMenuContainerTexts [CoolTip.SubIndexes] = lineTable_right - end - end + --adds a line for tooltips + function CoolTip:AddLine(leftText, rightText, menuType, ColorR1, ColorG1, ColorB1, ColorA1, ColorR2, ColorG2, ColorB2, ColorA2, fontSize, fontFace, fontFlag) + --check data integrity + local leftTextType = type(leftText) + if (leftTextType ~= "string") then + if (leftTextType == "number") then + leftText = tostring(leftText) else - return --> error - end - - lineTable_left [1] = leftText --> line text - lineTable_left [2] = ColorR1 - lineTable_left [3] = ColorG1 - lineTable_left [4] = ColorB1 - lineTable_left [5] = ColorA1 - lineTable_left [6] = fontSize - lineTable_left [7] = fontFace - lineTable_left [8] = fontFlag - - lineTable_right [1] = rightText --> line text - lineTable_right [2] = ColorR2 - lineTable_right [3] = ColorG2 - lineTable_right [4] = ColorB2 - lineTable_right [5] = ColorA2 - lineTable_right [6] = fontSize - lineTable_right [7] = fontFace - lineTable_right [8] = fontFlag - end - - function CoolTip:AddSpecial (widgetType, index, subIndex, ...) - - local currentIndex = CoolTip.Indexes - local currentSubIndex = CoolTip.SubIndexes - CoolTip.isSpecial = true - - widgetType = string.lower (widgetType) - - if (widgetType == "line") then - - if (subIndex) then - CoolTip.Indexes = index - CoolTip.SubIndexes = subIndex-1 - else - CoolTip.Indexes = index-1 - end - - CoolTip:AddLine (...) - - if (subIndex) then - CoolTip.Indexes = currentIndex - CoolTip.SubIndexes = currentSubIndex+1 - else - CoolTip.Indexes = currentIndex+1 - end - - elseif (widgetType == "icon") then - - CoolTip.Indexes = index - if (subIndex) then - CoolTip.SubIndexes = subIndex - end - - CoolTip:AddIcon (...) - - CoolTip.Indexes = currentIndex - if (subIndex) then - CoolTip.SubIndexes = currentSubIndex - end - - elseif (widgetType == "statusbar") then - - CoolTip.Indexes = index - if (subIndex) then - CoolTip.SubIndexes = subIndex - end - - CoolTip:AddStatusBar (...) - - CoolTip.Indexes = currentIndex - if (subIndex) then - CoolTip.SubIndexes = currentSubIndex - end - - elseif (widgetType == "menu") then - - CoolTip.Indexes = index - if (subIndex) then - CoolTip.SubIndexes = subIndex - end - - CoolTip:AddMenu (...) - - CoolTip.Indexes = currentIndex - if (subIndex) then - CoolTip.SubIndexes = currentSubIndex - end - - end - - CoolTip.isSpecial = false - - end - - --> search key: ~fromline - function CoolTip:AddFromTable (_table) - for index, menu in _ipairs (_table) do - if (menu.func) then - CoolTip:AddMenu (menu.type or 1, menu.func, menu.param1, menu.param2, menu.param3, nil, menu.icon) - elseif (menu.statusbar) then - CoolTip:AddStatusBar (menu.value, menu.type or 1, menu.color, true) - elseif (menu.icon) then - CoolTip:AddIcon (menu.icon, menu.type or 1, menu.side or 1, menu.width, menu.height, menu.l, menu.r, menu.t, menu.b, menu.color) - elseif (menu.textleft or menu.textright or menu.text) then - CoolTip:AddLine (menu.text, "", menu.type, menu.color, menu.color) - end + leftText = "" end end + local rightTextType = type(rightText) + if (rightTextType ~= "string") then + if (rightTextType == "number") then + rightText = tostring(rightText) + else + rightText = "" + end + end + + if (type(ColorR1) ~= "number") then + ColorR2, ColorG2, ColorB2, ColorA2, fontSize, fontFace, fontFlag = ColorG1, ColorB1, ColorA1, ColorR2, ColorG2, ColorB2, ColorA2 + if (type(ColorR1) == "boolean" or not ColorR1) then + ColorR1, ColorG1, ColorB1, ColorA1 = 0, 0, 0, 0 + else + ColorR1, ColorG1, ColorB1, ColorA1 = DF:ParseColors(ColorR1) + end + end + + if (type(ColorR2) ~= "number") then + fontSize, fontFace, fontFlag = ColorG2, ColorB2, ColorA2 + if (type(ColorR2) == "boolean" or not ColorR2) then + ColorR2, ColorG2, ColorB2, ColorA2 = 0, 0, 0, 0 + else + ColorR2, ColorG2, ColorB2, ColorA2 = DF:ParseColors(ColorR2) + end + end + + local frameTableLeft + local frameTableRight + local lineTable_Left + local lineTable_Right + + if (not menuType or (type(menuType) == "string" and menuType == CONST_MENU_TYPE_MAINMENU) or (type(menuType) == "number" and menuType == 1)) then + CoolTip.Indexes = CoolTip.Indexes + 1 + if (not CoolTip.IndexesSub[CoolTip.Indexes]) then + CoolTip.IndexesSub[CoolTip.Indexes] = 0 + end + + CoolTip.SubIndexes = 0 + + frameTableLeft = CoolTip.LeftTextTable + frameTableRight = CoolTip.RightTextTable + + if (CoolTip.isSpecial) then + lineTable_Left = {} + insert(frameTableLeft, CoolTip.Indexes, lineTable_Left) + lineTable_Right = {} + insert(frameTableRight, CoolTip.Indexes, lineTable_Right) + else + lineTable_Left = frameTableLeft[CoolTip.Indexes] + lineTable_Right = frameTableRight[CoolTip.Indexes] + if (not lineTable_Left) then + lineTable_Left = {} + insert(frameTableLeft, CoolTip.Indexes, lineTable_Left) + end + if (not lineTable_Right) then + lineTable_Right = {} + insert(frameTableRight, CoolTip.Indexes, lineTable_Right) + end + end + + elseif ((type(menuType) == "string" and menuType == "sub") or (type(menuType) == "number" and menuType == 2)) then + CoolTip.SubIndexes = CoolTip.SubIndexes + 1 + CoolTip.IndexesSub[CoolTip.Indexes] = CoolTip.IndexesSub[CoolTip.Indexes] + 1 + CoolTip.HaveSubMenu = true + + frameTableLeft = CoolTip.LeftTextTableSub + frameTableRight = CoolTip.RightTextTableSub + + local subMenuContainerTexts = frameTableLeft[CoolTip.Indexes] + if (not subMenuContainerTexts) then + subMenuContainerTexts = {} + insert(frameTableLeft, CoolTip.Indexes, subMenuContainerTexts) + end + + if (CoolTip.isSpecial) then + lineTable_Left = {} + insert(subMenuContainerTexts, CoolTip.SubIndexes, lineTable_Left) + else + lineTable_Left = subMenuContainerTexts[CoolTip.SubIndexes] + if (not lineTable_Left) then + lineTable_Left = {} + insert(subMenuContainerTexts, CoolTip.SubIndexes, lineTable_Left) + end + end + + local subMenuContainerTexts = frameTableRight[CoolTip.Indexes] + if (not subMenuContainerTexts) then + subMenuContainerTexts = {} + insert(frameTableRight, CoolTip.Indexes, subMenuContainerTexts) + end + + if (CoolTip.isSpecial) then + lineTable_Right = {} + insert(subMenuContainerTexts, CoolTip.SubIndexes, lineTable_Right) + else + lineTable_Right = subMenuContainerTexts[CoolTip.SubIndexes] + if (not lineTable_Right) then + lineTable_Right = {} + insert(subMenuContainerTexts, CoolTip.SubIndexes, lineTable_Right) + end + end + else + return CoolTip:PrintDebug("AddLine() unknown menuType.", menuType) + end + + lineTable_Left[1] = leftText + lineTable_Left[2] = ColorR1 + lineTable_Left[3] = ColorG1 + lineTable_Left[4] = ColorB1 + lineTable_Left[5] = ColorA1 + lineTable_Left[6] = fontSize + lineTable_Left[7] = fontFace + lineTable_Left[8] = fontFlag + + lineTable_Right[1] = rightText + lineTable_Right[2] = ColorR2 + lineTable_Right[3] = ColorG2 + lineTable_Right[4] = ColorB2 + lineTable_Right[5] = ColorA2 + lineTable_Right[6] = fontSize + lineTable_Right[7] = fontFace + lineTable_Right[8] = fontFlag + end + + function CoolTip:AddSpecial(widgetType, index, subIndex, ...) + local currentIndex = CoolTip.Indexes + local currentSubIndex = CoolTip.SubIndexes + CoolTip.isSpecial = true + + widgetType = string.lower(widgetType) + + if (widgetType == "line") then + if (subIndex) then + CoolTip.Indexes = index + CoolTip.SubIndexes = subIndex-1 + else + CoolTip.Indexes = index-1 + end + + CoolTip:AddLine(...) + + if (subIndex) then + CoolTip.Indexes = currentIndex + CoolTip.SubIndexes = currentSubIndex + 1 + else + CoolTip.Indexes = currentIndex + 1 + end + + elseif (widgetType == "icon") then + CoolTip.Indexes = index + if (subIndex) then + CoolTip.SubIndexes = subIndex + end + + CoolTip:AddIcon(...) + + CoolTip.Indexes = currentIndex + if (subIndex) then + CoolTip.SubIndexes = currentSubIndex + end + + elseif (widgetType == "statusbar") then + CoolTip.Indexes = index + if (subIndex) then + CoolTip.SubIndexes = subIndex + end + + CoolTip:AddStatusBar(...) + CoolTip.Indexes = currentIndex + if (subIndex) then + CoolTip.SubIndexes = currentSubIndex + end + + elseif (widgetType == "menu") then + CoolTip.Indexes = index + if (subIndex) then + CoolTip.SubIndexes = subIndex + end + + CoolTip:AddMenu(...) + + CoolTip.Indexes = currentIndex + if (subIndex) then + CoolTip.SubIndexes = currentSubIndex + end + end + + CoolTip.isSpecial = false + end + + --search key: ~fromline + function CoolTip:AddFromTable(thisTable) + for index, menu in ipairs(thisTable) do + if (menu.func) then + CoolTip:AddMenu(menu.type or 1, menu.func, menu.param1, menu.param2, menu.param3, nil, menu.icon) + + elseif (menu.statusbar) then + CoolTip:AddStatusBar(menu.value, menu.type or 1, menu.color, true) + + elseif (menu.icon) then + CoolTip:AddIcon(menu.icon, menu.type or 1, menu.side or 1, menu.width, menu.height, menu.l, menu.r, menu.t, menu.b, menu.color) + + elseif (menu.textleft or menu.textright or menu.text) then + CoolTip:AddLine(menu.text, "", menu.type, menu.color, menu.color) + end + end + end + ---------------------------------------------------------------------- - --> show cooltip - - --> serach key: ~start - function CoolTip:Show (frame, menuType, color) - CoolTip.had_interaction = false - return CoolTip:ShowCooltip (frame, menuType, color) - end - - function CoolTip:ShowCooltip (frame, menuType, color) + --serach key: ~start + function CoolTip:Show(frame, menuType, color) + CoolTip.hadInteractions = false + return CoolTip:ShowCooltip(frame, menuType, color) + end - frame1:SetFrameStrata ("TOOLTIP") - frame2:SetFrameStrata ("TOOLTIP") - frame1:SetParent (UIParent) - frame2:SetParent (UIParent) - - CoolTip.had_interaction = false - - if (frame) then - --> details framework - if (frame.dframework) then - frame = frame.widget - end - CoolTip:SetHost (frame) - end - if (menuType) then - CoolTip:SetType (menuType) - end - if (color) then - CoolTip:SetColor (1, color) - CoolTip:SetColor (2, color) - end - - if (CoolTip.Type == 1 or CoolTip.Type == 2) then - return CoolTip:monta_tooltip() - - elseif (CoolTip.Type == 3) then - return CoolTip:monta_cooltip() - + function CoolTip:ShowCooltip(frame, menuType, color) + frame1:SetFrameStrata("TOOLTIP") + frame2:SetFrameStrata("TOOLTIP") + frame1:SetParent(UIParent) + frame2:SetParent(UIParent) + + CoolTip.hadInteractions = false + + if (frame) then + --check if is a details framework widget + if (frame.dframework) then + frame = frame.widget end + CoolTip:SetHost(frame) end - - local emptyOptions = {} - + + if (menuType) then + CoolTip:SetType(menuType) + end + + if (color) then + CoolTip:SetColor(1, color) + CoolTip:SetColor(2, color) + end + + if (CoolTip.Type == 1 or CoolTip.Type == 2) then + return CoolTip:BuildTooltip() + + elseif (CoolTip.Type == 3) then + return CoolTip:BuildCooltip() + end + end + function CoolTip:Hide() return CoolTip:Close() end - + function CoolTip:Close() CoolTip.active = false CoolTip.Host = nil - DF:FadeFrame (frame1, 1) - DF:FadeFrame (frame2, 1) + DF:FadeFrame(frame1, 1) + DF:FadeFrame(frame2, 1) end - - - - --> old function call - function CoolTip:ShowMe (host, arg2) - --> ignore if mouse is up me + + --old function call + function CoolTip:ShowMe(host, arg2) --drunk code + --ignore if mouse is within the frame region if (CoolTip.mouseOver) then return end - - if (not host or not arg2) then --> hideme + if (not host or not arg2) then --hide the frame CoolTip:Close() end end - - --> search key: ~inject - function CoolTip:ExecFunc (host, fromClick) - + + --search key: ~inject + function CoolTip:ExecFunc(host, fromClick) if (host.dframework) then if (not host.widget.CoolTip) then host.widget.CoolTip = host.CoolTip end host = host.widget end - - CoolTip:Reset() - CoolTip:SetType (host.CoolTip.Type) - CoolTip:SetFixedParameter (host.CoolTip.FixedValue) - CoolTip:SetColor ("main", host.CoolTip.MainColor or "transparent") - CoolTip:SetColor ("sec", host.CoolTip.SubColor or "transparent") - - local okay, errortext = pcall (host.CoolTip.BuildFunc, host, host.CoolTip and host.CoolTip.FixedValue) --resetting anchors - if (not okay) then - print ("Cooltip Injected Fucntion Error:", errortext) - end - CoolTip:SetOwner (host, host.CoolTip.MyAnchor, host.CoolTip.HisAnchor, host.CoolTip.X, host.CoolTip.Y) - - local options = host.CoolTip.Options - if (type (options) == "function") then - options = options() + CoolTip:Reset() + CoolTip:SetType(host.CoolTip.Type) + CoolTip:SetFixedParameter(host.CoolTip.FixedValue) + CoolTip:SetColor(CONST_MENU_TYPE_MAINMENU, host.CoolTip.MainColor or "transparent") + CoolTip:SetColor(CONST_MENU_TYPE_SUBMENU, host.CoolTip.SubColor or "transparent") + + local okay, errortext = pcall(host.CoolTip.BuildFunc, host, host.CoolTip and host.CoolTip.FixedValue) + if (not okay) then + CoolTip:PrintDebug("ExecFunc() injected function error:", errortext) end - if (options) then - for optionName, optionValue in pairs (options) do - CoolTip:SetOption (optionName, optionValue) + + CoolTip:SetOwner(host, host.CoolTip.MyAnchor, host.CoolTip.HisAnchor, host.CoolTip.X, host.CoolTip.Y) + + local options = host.CoolTip.Options + if (type(options) == "function") then + local runCompleted, returnedOptions = pcall(options) + if (not runCompleted) then + errortext = returnedOptions + CoolTip:PrintDebug("ExecFunc() options function error:", errortext) + options = nil + else + options = returnedOptions end end - + + if (options) then + if (type(options) == "table") then + for optionName, optionValue in pairs(options) do + CoolTip:SetOption(optionName, optionValue) + end + else + CoolTip:PrintDebug("ExecFunc() options function did not returned a table.") + end + end + if (CoolTip.Indexes == 0) then if (host.CoolTip.Default) then - CoolTip:SetType ("tooltip") - CoolTip:AddLine (host.CoolTip.Default, nil, 1, "white") + CoolTip:SetType(CONST_COOLTIP_TYPE_TOOLTIP) + CoolTip:AddLine(host.CoolTip.Default, nil, 1, "white") end end CoolTip:ShowCooltip() - + if (fromClick) then - --UIFrameFlash (frame1, ) frame1:Flash (0.05, 0.05, 0.2, true, 0, 0) end end - + local wait = 0.2 - - local InjectOnUpdateEnter = function (self, elapsed) - elapsedTime = elapsedTime+elapsed + local InjectOnUpdateEnter = function(self, deltaTime) + elapsedTime = elapsedTime + deltaTime if (elapsedTime > wait) then - self:SetScript ("OnUpdate", nil) - CoolTip:ExecFunc (self) + self:SetScript("OnUpdate", nil) + CoolTip:ExecFunc(self) end end - local InjectOnUpdateLeave = function (self, elapsed) - elapsedTime = elapsedTime+elapsed + local InjectOnUpdateLeave = function(self, deltaTime) + elapsedTime = elapsedTime + deltaTime if (elapsedTime > 0.2) then if (not CoolTip.mouseOver and not CoolTip.buttonOver and self == CoolTip.Host) then - CoolTip:ShowMe (false) + CoolTip:ShowMe(false) end - self:SetScript ("OnUpdate", nil) + self:SetScript("OnUpdate", nil) end end - - local InjectOnLeave = function (self) - CoolTip.buttonOver = false - - if (CoolTip.active) then - elapsedTime = 0 - self:SetScript ("OnUpdate", InjectOnUpdateLeave) - else - self:SetScript ("OnUpdate", nil) - end - - if (self.CoolTip.OnLeaveFunc) then - self.CoolTip.OnLeaveFunc (self) - end - - if (self.OldOnLeaveScript) then - self:OldOnLeaveScript() - end - end - local InjectOnEnter = function (self) + local InjectOnLeave = function(self) + CoolTip.buttonOver = false + + if (CoolTip.active) then + elapsedTime = 0 + self:SetScript("OnUpdate", InjectOnUpdateLeave) + else + self:SetScript("OnUpdate", nil) + end + + if (self.CoolTip.OnLeaveFunc) then + self.CoolTip.OnLeaveFunc(self) + end + + if (self.OldOnLeaveScript) then + self:OldOnLeaveScript() + end + end + + local InjectOnEnter = function(self) CoolTip.buttonOver = true if (CoolTip.active) then - CoolTip:ExecFunc (self) + CoolTip:ExecFunc(self) else elapsedTime = 0 wait = self.CoolTip.ShowSpeed or 0.2 - self:SetScript ("OnUpdate", InjectOnUpdateEnter) + self:SetScript("OnUpdate", InjectOnUpdateEnter) end if (self.CoolTip.OnEnterFunc) then - self.CoolTip.OnEnterFunc (self) + self.CoolTip.OnEnterFunc(self) end - + if (self.OldOnEnterScript) then self:OldOnEnterScript() end end - - function CoolTip:CoolTipInject (host, openOnClick) + + function CoolTip:CoolTipInject(host, openOnClick) if (host.dframework) then if (not host.widget.CoolTip) then host.widget.CoolTip = host.CoolTip end host = host.widget end - + local coolTable = host.CoolTip if (not coolTable) then - print ("Host nao tem uma CoolTable.") + CoolTip:PrintDebug("CoolTipInject() host frame does not have a .CoolTip table.") return false end - host.OldOnEnterScript = host:GetScript ("OnEnter") - host.OldOnLeaveScript = host:GetScript ("OnLeave") - - host:SetScript ("OnEnter", InjectOnEnter) - host:SetScript ("OnLeave", InjectOnLeave) - + host.OldOnEnterScript = host:GetScript("OnEnter") + host.OldOnLeaveScript = host:GetScript("OnLeave") + + host:SetScript("OnEnter", InjectOnEnter) + host:SetScript("OnLeave", InjectOnLeave) + if (openOnClick) then if (host:GetObjectType() == "Button") then - host:SetScript ("OnClick", function() CoolTip:ExecFunc (host, true) end) + host:SetScript("OnClick", function() CoolTip:ExecFunc(host, true) end) end end - + return true end - - --> all done + + --all done CoolTip:ClearAllOptions() - local preset2_backdrop = {bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, - tile = true, tileSize = 16, insets = {left = 0, right = 0, top = 0, bottom = 0}} - local default_backdrop_color = {0.09019, 0.09019, 0.18823, 0.8} - local default_backdropborder_color = {1, 1, 1, 1} - - local gray_table = {0.37, 0.37, 0.37, 0.95} - local white_table = {1, 1, 1, 1} - local black_table = {0.2, 0.2, 0.2, 1} + function CoolTip:Preset(presetId, fromReset) + if (not fromReset) then + self:Reset(true) + end - local backdropColorPreset2 = {.2, .2, .2, 1} - local borderColorPreset2 = {.2, .2, .2, 1} - - function CoolTip:Preset (number) - self:Reset() - - if (number == 1) then - self:SetOption ("TextFont", "Friz Quadrata TT") - self:SetOption ("TextColor", "orange") - self:SetOption ("TextSize", 12) - self:SetOption ("ButtonsYMod", -4) - self:SetOption ("YSpacingMod", -4) - self:SetOption ("IgnoreButtonAutoHeight", true) - self:SetColor (1, 0.5, 0.5, 0.5, 0.5) - - elseif (number == 2) then - self:SetOption ("TextFont", "Friz Quadrata TT") - self:SetOption ("TextColor", "orange") - self:SetOption ("TextSize", 12) - self:SetOption ("FixedWidth", 220) - self:SetOption ("ButtonsYMod", -4) - self:SetOption ("YSpacingMod", -4) - self:SetOption ("IgnoreButtonAutoHeight", true) - self:SetColor (1, 0.5, 0.5, 0.5, 0) - - self:SetBackdrop (1, preset2_backdrop, backdropColorPreset2, borderColorPreset2) - self:SetBackdrop (2, preset2_backdrop, backdropColorPreset2, borderColorPreset2) + if (presetId == 1) then + self:SetOption("TextFont", DF:GetBestFontForLanguage()) + self:SetOption("TextColor", "orange") + self:SetOption("TextSize", 12) + self:SetOption("ButtonsYMod", -4) + self:SetOption("YSpacingMod", -4) + self:SetOption("IgnoreButtonAutoHeight", true) + self:SetColor(1, 0.5, 0.5, 0.5, 0.5) + + elseif (presetId == 2) then + self:SetOption("TextFont", DF:GetBestFontForLanguage()) + self:SetOption("TextColor", "orange") + self:SetOption("TextSize", 12) + self:SetOption("FixedWidth", 220) + self:SetOption("ButtonsYMod", -4) + self:SetOption("YSpacingMod", -4) + self:SetOption("IgnoreButtonAutoHeight", true) + self:SetColor(1, "transparent") + + self:SetBackdrop(1, defaultBackdrop, defaultBackdropColor, defaultBackdropBorderColor) + self:SetBackdrop(2, defaultBackdrop, defaultBackdropColor, defaultBackdropBorderColor) + + elseif (presetId == 3) then + self:SetOption("TextFont", DF:GetBestFontForLanguage()) + self:SetOption("TextColor", "orange") + self:SetOption("TextSize", 12) + self:SetOption("ButtonsYMod", -4) + self:SetOption("YSpacingMod", -4) + self:SetOption("IgnoreButtonAutoHeight", true) + self:SetColor(1, "transparent") + + self:SetBackdrop(1, defaultBackdrop, defaultBackdropColor, defaultBackdropBorderColor) + self:SetBackdrop(2, defaultBackdrop, defaultBackdropColor, defaultBackdropBorderColor) end end - - function CoolTip:QuickTooltip (host, ...) - - CoolTip:Preset (2) - CoolTip:SetHost (host) - - for i = 1, select ("#", ...) do - local line = select (i, ...) - CoolTip:AddLine (line) + + function CoolTip:QuickTooltip(host, ...) + CoolTip:Preset(2) + CoolTip:SetHost(host) + + for i = 1, select("#", ...) do + local line = select(i, ...) + CoolTip:AddLine(line) end - + CoolTip:ShowCooltip() end - - function CoolTip:InjectQuickTooltip (host, ...) + + function CoolTip:InjectQuickTooltip(host, ...) host.CooltipQuickTooltip = {...} - host:HookScript ("OnEnter", function() - CoolTip:QuickTooltip (host, unpack (host.CooltipQuickTooltip)) + host:HookScript("OnEnter", function() + CoolTip:QuickTooltip(host, unpack(host.CooltipQuickTooltip)) end) - host:HookScript ("OnLeave", function() + host:HookScript("OnLeave", function() CoolTip:Hide() end) end - - - return CoolTip - end -DF:CreateCoolTip() +DF:CreateCoolTip() \ No newline at end of file diff --git a/Libs/DF/fw.lua b/Libs/DF/fw.lua index 63325053..0ebc7660 100644 --- a/Libs/DF/fw.lua +++ b/Libs/DF/fw.lua @@ -1,6 +1,6 @@ -local dversion = 356 +local dversion = 359 local major, minor = "DetailsFramework-1.0", dversion local DF, oldminor = LibStub:NewLibrary (major, minor) diff --git a/Libs/DF/pictureedit.lua b/Libs/DF/pictureedit.lua index 19b8456e..532967a1 100644 --- a/Libs/DF/pictureedit.lua +++ b/Libs/DF/pictureedit.lua @@ -5,58 +5,57 @@ if (not DF or not DetailsFrameworkCanLoad) then end local _ -local ttexcoord +local texCoordinates local CreateImageEditorFrame = function() - - local window = DF:NewPanel (UIParent, nil, "DetailsFrameworkImageEdit", nil, 650, 500, false) - window:SetPoint ("center", UIParent, "center") - window:SetResizable (true) - window:SetMovable (true) - window:SetClampedToScreen (true) + local editorWindow = DF:NewPanel (UIParent, nil, "DetailsFrameworkImageEdit", nil, 650, 500, false) + editorWindow:SetPoint("center", UIParent, "center") + editorWindow:SetResizable (true) + editorWindow:SetMovable (true) + editorWindow:SetClampedToScreen (true) tinsert (UISpecialFrames, "DetailsFrameworkImageEdit") - window:SetFrameStrata ("TOOLTIP") + editorWindow:SetFrameStrata("TOOLTIP") if (not DetailsFramework.IsDragonflight()) then - window:SetMaxResize(500, 500) + editorWindow:SetMaxResize(500, 500) else - window:SetResizeBounds(100, 100, 500, 500) + editorWindow:SetResizeBounds(100, 100, 500, 500) end - _G.DetailsFrameworkImageEditTable = window + _G.DetailsFrameworkImageEditTable = editorWindow - window.hooks = {} + editorWindow.hooks = {} - local background = DF:NewImage (window, nil, nil, nil, "background", nil, "background", "$parentBackground") + local background = DF:NewImage (editorWindow, nil, nil, nil, "background", nil, "background", "$parentBackground") background:SetAllPoints() - background:SetTexture (0, 0, 0, .8) + background:SetTexture(0, 0, 0, .8) - local edit_texture = DF:NewImage (window, nil, 500, 500, "artwork", nil, "edit_texture", "$parentImage") + local edit_texture = DF:NewImage (editorWindow, nil, 500, 500, "artwork", nil, "edit_texture", "$parentImage") edit_texture:SetAllPoints() _G.DetailsFrameworkImageEdit_EditTexture = edit_texture local background_frame = CreateFrame ("frame", "DetailsFrameworkImageEditBackground", DetailsFrameworkImageEdit, "BackdropTemplate") - background_frame:SetPoint ("topleft", DetailsFrameworkImageEdit, "topleft", -10, 30) - background_frame:SetFrameStrata ("TOOLTIP") - background_frame:SetFrameLevel (window:GetFrameLevel()) + background_frame:SetPoint("topleft", DetailsFrameworkImageEdit, "topleft", -10, 30) + background_frame:SetFrameStrata("TOOLTIP") + background_frame:SetFrameLevel (editorWindow:GetFrameLevel()) background_frame:SetSize (790, 560) background_frame:SetResizable (true) background_frame:SetMovable (true) - background_frame:SetScript ("OnMouseDown", function() - window:StartMoving() + background_frame:SetScript("OnMouseDown", function() + editorWindow:StartMoving() end) - background_frame:SetScript ("OnMouseUp", function() - window:StopMovingOrSizing() + background_frame:SetScript("OnMouseUp", function() + editorWindow:StopMovingOrSizing() end) DF:CreateTitleBar (background_frame, "Image Editor") DF:ApplyStandardBackdrop (background_frame, false, 0.98) DF:CreateStatusBar(background_frame) - background_frame:SetBackdrop ({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true}) - background_frame:SetBackdropColor (0, 0, 0, 0.9) + background_frame:SetBackdrop({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true}) + background_frame:SetBackdropColor(0, 0, 0, 0.9) background_frame:SetBackdropBorderColor (0, 0, 0, 1) local haveHFlip = false @@ -64,31 +63,31 @@ local CreateImageEditorFrame = function() --> Top Slider - local topCoordTexture = DF:NewImage (window, nil, nil, nil, "overlay", nil, nil, "$parentImageTopCoord") - topCoordTexture:SetPoint ("topleft", window, "topleft") - topCoordTexture:SetPoint ("topright", window, "topright") - topCoordTexture:SetColorTexture (1, 0, 0) + local topCoordTexture = DF:NewImage (editorWindow, nil, nil, nil, "overlay", nil, nil, "$parentImageTopCoord") + topCoordTexture:SetPoint("topleft", editorWindow, "topleft") + topCoordTexture:SetPoint("topright", editorWindow, "topright") + topCoordTexture:SetColorTexture(1, 0, 0) topCoordTexture.height = 1 topCoordTexture.alpha = .2 - local topSlider = DF:NewSlider (window, nil, "$parentTopSlider", "topSlider", 100, 100, 0.1, 100, 0.1, 0) - topSlider:SetAllPoints (window.widget) + local topSlider = DF:NewSlider (editorWindow, nil, "$parentTopSlider", "topSlider", 100, 100, 0.1, 100, 0.1, 0) + topSlider:SetAllPoints (editorWindow.widget) topSlider:SetOrientation ("VERTICAL") topSlider.backdrop = nil topSlider.fractional = true topSlider:SetHook ("OnEnter", function() return true end) topSlider:SetHook ("OnLeave", function() return true end) - local topSliderThumpTexture = topSlider:CreateTexture (nil, "overlay") - topSliderThumpTexture:SetColorTexture (1, 1, 1) - topSliderThumpTexture:SetWidth (512) - topSliderThumpTexture:SetHeight (1) + local topSliderThumpTexture = topSlider:CreateTexture(nil, "overlay") + topSliderThumpTexture:SetColorTexture(1, 1, 1) + topSliderThumpTexture:SetWidth(512) + topSliderThumpTexture:SetHeight(1) topSlider:SetThumbTexture (topSliderThumpTexture) - topSlider:SetHook ("OnValueChange", function (_, _, value) - topCoordTexture.image:SetHeight (window.frame:GetHeight()/100*value) - if (window.callback_func) then - window.accept (nil, nil, true) + topSlider:SetHook ("OnValueChange", function(_, _, value) + topCoordTexture.image:SetHeight(editorWindow.frame:GetHeight()/100*value) + if (editorWindow.callback_func) then + editorWindow.accept(nil, nil, true) end end) @@ -96,32 +95,32 @@ local CreateImageEditorFrame = function() --> Bottom Slider - local bottomCoordTexture = DF:NewImage (window, nil, nil, nil, "overlay", nil, nil, "$parentImageBottomCoord") - bottomCoordTexture:SetPoint ("bottomleft", window, "bottomleft", 0, 0) - bottomCoordTexture:SetPoint ("bottomright", window, "bottomright", 0, 0) - bottomCoordTexture:SetColorTexture (1, 0, 0) + local bottomCoordTexture = DF:NewImage (editorWindow, nil, nil, nil, "overlay", nil, nil, "$parentImageBottomCoord") + bottomCoordTexture:SetPoint("bottomleft", editorWindow, "bottomleft", 0, 0) + bottomCoordTexture:SetPoint("bottomright", editorWindow, "bottomright", 0, 0) + bottomCoordTexture:SetColorTexture(1, 0, 0) bottomCoordTexture.height = 1 bottomCoordTexture.alpha = .2 - local bottomSlider= DF:NewSlider (window, nil, "$parentBottomSlider", "bottomSlider", 100, 100, 0.1, 100, 0.1, 100) - bottomSlider:SetAllPoints (window.widget) + local bottomSlider= DF:NewSlider (editorWindow, nil, "$parentBottomSlider", "bottomSlider", 100, 100, 0.1, 100, 0.1, 100) + bottomSlider:SetAllPoints (editorWindow.widget) bottomSlider:SetOrientation ("VERTICAL") bottomSlider.backdrop = nil bottomSlider.fractional = true bottomSlider:SetHook ("OnEnter", function() return true end) bottomSlider:SetHook ("OnLeave", function() return true end) - local bottomSliderThumpTexture = bottomSlider:CreateTexture (nil, "overlay") - bottomSliderThumpTexture:SetColorTexture (1, 1, 1) - bottomSliderThumpTexture:SetWidth (512) - bottomSliderThumpTexture:SetHeight (1) + local bottomSliderThumpTexture = bottomSlider:CreateTexture(nil, "overlay") + bottomSliderThumpTexture:SetColorTexture(1, 1, 1) + bottomSliderThumpTexture:SetWidth(512) + bottomSliderThumpTexture:SetHeight(1) bottomSlider:SetThumbTexture (bottomSliderThumpTexture) - bottomSlider:SetHook ("OnValueChange", function (_, _, value) + bottomSlider:SetHook ("OnValueChange", function(_, _, value) value = math.abs (value-100) - bottomCoordTexture.image:SetHeight (math.max (window.frame:GetHeight()/100*value, 1)) - if (window.callback_func) then - window.accept (nil, nil, true) + bottomCoordTexture.image:SetHeight(math.max (editorWindow.frame:GetHeight()/100*value, 1)) + if (editorWindow.callback_func) then + editorWindow.accept(nil, nil, true) end end) @@ -129,30 +128,30 @@ local CreateImageEditorFrame = function() --> Left Slider - local leftCoordTexture = DF:NewImage (window, nil, nil, nil, "overlay", nil, nil, "$parentImageLeftCoord") - leftCoordTexture:SetPoint ("topleft", window, "topleft", 0, 0) - leftCoordTexture:SetPoint ("bottomleft", window, "bottomleft", 0, 0) - leftCoordTexture:SetColorTexture (1, 0, 0) + local leftCoordTexture = DF:NewImage (editorWindow, nil, nil, nil, "overlay", nil, nil, "$parentImageLeftCoord") + leftCoordTexture:SetPoint("topleft", editorWindow, "topleft", 0, 0) + leftCoordTexture:SetPoint("bottomleft", editorWindow, "bottomleft", 0, 0) + leftCoordTexture:SetColorTexture(1, 0, 0) leftCoordTexture.width = 1 leftCoordTexture.alpha = .2 - local leftSlider = DF:NewSlider (window, nil, "$parentLeftSlider", "leftSlider", 100, 100, 0.1, 100, 0.1, 0.1) - leftSlider:SetAllPoints (window.widget) + local leftSlider = DF:NewSlider (editorWindow, nil, "$parentLeftSlider", "leftSlider", 100, 100, 0.1, 100, 0.1, 0.1) + leftSlider:SetAllPoints (editorWindow.widget) leftSlider.backdrop = nil leftSlider.fractional = true leftSlider:SetHook ("OnEnter", function() return true end) leftSlider:SetHook ("OnLeave", function() return true end) - local leftSliderThumpTexture = leftSlider:CreateTexture (nil, "overlay") - leftSliderThumpTexture:SetColorTexture (1, 1, 1) - leftSliderThumpTexture:SetWidth (1) - leftSliderThumpTexture:SetHeight (512) + local leftSliderThumpTexture = leftSlider:CreateTexture(nil, "overlay") + leftSliderThumpTexture:SetColorTexture(1, 1, 1) + leftSliderThumpTexture:SetWidth(1) + leftSliderThumpTexture:SetHeight(512) leftSlider:SetThumbTexture (leftSliderThumpTexture) - leftSlider:SetHook ("OnValueChange", function (_, _, value) - leftCoordTexture.image:SetWidth (window.frame:GetWidth()/100*value) - if (window.callback_func) then - window.accept (nil, nil, true) + leftSlider:SetHook ("OnValueChange", function(_, _, value) + leftCoordTexture.image:SetWidth(editorWindow.frame:GetWidth()/100*value) + if (editorWindow.callback_func) then + editorWindow.accept(nil, nil, true) end end) @@ -160,31 +159,31 @@ local CreateImageEditorFrame = function() --> Right Slider - local rightCoordTexture = DF:NewImage (window, nil, nil, nil, "overlay", nil, nil, "$parentImageRightCoord") - rightCoordTexture:SetPoint ("topright", window, "topright", 0, 0) - rightCoordTexture:SetPoint ("bottomright", window, "bottomright", 0, 0) - rightCoordTexture:SetColorTexture (1, 0, 0) + local rightCoordTexture = DF:NewImage (editorWindow, nil, nil, nil, "overlay", nil, nil, "$parentImageRightCoord") + rightCoordTexture:SetPoint("topright", editorWindow, "topright", 0, 0) + rightCoordTexture:SetPoint("bottomright", editorWindow, "bottomright", 0, 0) + rightCoordTexture:SetColorTexture(1, 0, 0) rightCoordTexture.width = 1 rightCoordTexture.alpha = .2 - local rightSlider = DF:NewSlider (window, nil, "$parentRightSlider", "rightSlider", 100, 100, 0.1, 100, 0.1, 100) - rightSlider:SetAllPoints (window.widget) + local rightSlider = DF:NewSlider (editorWindow, nil, "$parentRightSlider", "rightSlider", 100, 100, 0.1, 100, 0.1, 100) + rightSlider:SetAllPoints (editorWindow.widget) rightSlider.backdrop = nil rightSlider.fractional = true rightSlider:SetHook ("OnEnter", function() return true end) rightSlider:SetHook ("OnLeave", function() return true end) --[ - local rightSliderThumpTexture = rightSlider:CreateTexture (nil, "overlay") - rightSliderThumpTexture:SetColorTexture (1, 1, 1) - rightSliderThumpTexture:SetWidth (1) - rightSliderThumpTexture:SetHeight (512) + local rightSliderThumpTexture = rightSlider:CreateTexture(nil, "overlay") + rightSliderThumpTexture:SetColorTexture(1, 1, 1) + rightSliderThumpTexture:SetWidth(1) + rightSliderThumpTexture:SetHeight(512) rightSlider:SetThumbTexture (rightSliderThumpTexture) --]] - rightSlider:SetHook ("OnValueChange", function (_, _, value) + rightSlider:SetHook ("OnValueChange", function(_, _, value) value = math.abs (value-100) - rightCoordTexture.image:SetWidth (math.max (window.frame:GetWidth()/100*value, 1)) - if (window.callback_func) then - window.accept (nil, nil, true) + rightCoordTexture.image:SetWidth(math.max (editorWindow.frame:GetWidth()/100*value, 1)) + if (editorWindow.callback_func) then + editorWindow.accept(nil, nil, true) end end) @@ -193,12 +192,12 @@ local CreateImageEditorFrame = function() --> Edit Buttons local buttonsBackground = DF:NewPanel (UIParent, nil, "DetailsFrameworkImageEditButtonsBg", nil, 115, 230) - --buttonsBackground:SetPoint ("topleft", window, "topright", 2, 0) - buttonsBackground:SetPoint ("topright", background_frame, "topright", -8, -10) + --buttonsBackground:SetPoint("topleft", window, "topright", 2, 0) + buttonsBackground:SetPoint("topright", background_frame, "topright", -8, -10) buttonsBackground:Hide() --buttonsBackground:SetMovable (true) tinsert (UISpecialFrames, "DetailsFrameworkImageEditButtonsBg") - buttonsBackground:SetFrameStrata ("TOOLTIP") + buttonsBackground:SetFrameStrata("TOOLTIP") local alphaFrameShown = false @@ -207,12 +206,12 @@ local CreateImageEditorFrame = function() local alphaFrame local originalColor = {0.9999, 0.8196, 0} - local enableTexEdit = function (button, b, side) + local enableTexEdit = function(button, bottom, side) if (alphaFrameShown) then alphaFrame:Hide() alphaFrameShown = false - button.text:SetTextColor (unpack (originalColor)) + button.text:SetTextColor (unpack(originalColor)) end if (ColorPickerFrame:IsShown()) then @@ -220,58 +219,58 @@ local CreateImageEditorFrame = function() end if (lastButton) then - lastButton.text:SetTextColor (unpack (originalColor)) + lastButton.text:SetTextColor (unpack(originalColor)) end if (editingSide == side) then - window [editingSide.."Slider"]:Hide() + editorWindow [editingSide.."Slider"]:Hide() editingSide = nil return elseif (editingSide) then - window [editingSide.."Slider"]:Hide() + editorWindow [editingSide.."Slider"]:Hide() end editingSide = side button.text:SetTextColor (1, 1, 1) lastButton = button - window [side.."Slider"]:Show() + editorWindow [side.."Slider"]:Show() end local yMod = -10 - local leftTexCoordButton = DF:NewButton (buttonsBackground, nil, "$parentLeftTexButton", nil, 100, 20, enableTexEdit, "left", nil, nil, "Crop Left", 1) - leftTexCoordButton:SetPoint ("topright", buttonsBackground, "topright", -8, -10 + yMod) - leftTexCoordButton:SetTemplate (DF:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")) + local leftTexCoordButton = DF:NewButton(buttonsBackground, nil, "$parentLeftTexButton", nil, 100, 20, enableTexEdit, "left", nil, nil, "Crop Left", 1) + leftTexCoordButton:SetPoint("topright", buttonsBackground, "topright", -8, -10 + yMod) + leftTexCoordButton:SetTemplate(DF:GetTemplate("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")) - local rightTexCoordButton = DF:NewButton (buttonsBackground, nil, "$parentRightTexButton", nil, 100, 20, enableTexEdit, "right", nil, nil, "Crop Right", 1) - rightTexCoordButton:SetPoint ("topright", buttonsBackground, "topright", -8, -30 + yMod) - rightTexCoordButton:SetTemplate (DF:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")) + local rightTexCoordButton = DF:NewButton(buttonsBackground, nil, "$parentRightTexButton", nil, 100, 20, enableTexEdit, "right", nil, nil, "Crop Right", 1) + rightTexCoordButton:SetPoint("topright", buttonsBackground, "topright", -8, -30 + yMod) + rightTexCoordButton:SetTemplate(DF:GetTemplate("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")) - local topTexCoordButton = DF:NewButton (buttonsBackground, nil, "$parentTopTexButton", nil, 100, 20, enableTexEdit, "top", nil, nil, "Crop Top", 1) - topTexCoordButton:SetPoint ("topright", buttonsBackground, "topright", -8, -50 + yMod) - topTexCoordButton:SetTemplate (DF:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")) + local topTexCoordButton = DF:NewButton(buttonsBackground, nil, "$parentTopTexButton", nil, 100, 20, enableTexEdit, "top", nil, nil, "Crop Top", 1) + topTexCoordButton:SetPoint("topright", buttonsBackground, "topright", -8, -50 + yMod) + topTexCoordButton:SetTemplate(DF:GetTemplate("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")) - local bottomTexCoordButton = DF:NewButton (buttonsBackground, nil, "$parentBottomTexButton", nil, 100, 20, enableTexEdit, "bottom", nil, nil, "Crop Bottom", 1) - bottomTexCoordButton:SetPoint ("topright", buttonsBackground, "topright", -8, -70 + yMod) - bottomTexCoordButton:SetTemplate (DF:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")) + local bottomTexCoordButton = DF:NewButton(buttonsBackground, nil, "$parentBottomTexButton", nil, 100, 20, enableTexEdit, "bottom", nil, nil, "Crop Bottom", 1) + bottomTexCoordButton:SetPoint("topright", buttonsBackground, "topright", -8, -70 + yMod) + bottomTexCoordButton:SetTemplate(DF:GetTemplate("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")) - local Alpha = DF:NewButton (buttonsBackground, nil, "$parentBottomAlphaButton", nil, 100, 20, alpha, nil, nil, nil, "Alpha", 1) - Alpha:SetPoint ("topright", buttonsBackground, "topright", -8, -115 + yMod) - Alpha:SetTemplate (DF:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")) + local Alpha = DF:NewButton(buttonsBackground, nil, "$parentBottomAlphaButton", nil, 100, 20, alpha, nil, nil, nil, "Alpha", 1) + Alpha:SetPoint("topright", buttonsBackground, "topright", -8, -115 + yMod) + Alpha:SetTemplate(DF:GetTemplate("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")) --> overlay color - local selectedColor = function (default) + local selectedColor = function(default) if (default) then - edit_texture:SetVertexColor (unpack (default)) - if (window.callback_func) then - window.accept (nil, nil, true) + edit_texture:SetVertexColor(unpack(default)) + if (editorWindow.callback_func) then + editorWindow.accept(nil, nil, true) end else - edit_texture:SetVertexColor (ColorPickerFrame:GetColorRGB()) - if (window.callback_func) then - window.accept (nil, nil, true) + edit_texture:SetVertexColor(ColorPickerFrame:GetColorRGB()) + if (editorWindow.callback_func) then + editorWindow.accept(nil, nil, true) end end end @@ -283,347 +282,331 @@ local CreateImageEditorFrame = function() ColorPickerFrame.cancelFunc = nil ColorPickerFrame.previousValues = nil - local r, g, b = edit_texture:GetVertexColor() - ColorPickerFrame:SetColorRGB (r, g, b) + local right, g, bottom = edit_texture:GetVertexColor() + ColorPickerFrame:SetColorRGB (right, g, bottom) ColorPickerFrame:SetParent (buttonsBackground.widget) ColorPickerFrame.hasOpacity = false - ColorPickerFrame.previousValues = {r, g, b} + ColorPickerFrame.previousValues = {right, g, bottom} ColorPickerFrame.func = selectedColor ColorPickerFrame.cancelFunc = selectedColor ColorPickerFrame:ClearAllPoints() - ColorPickerFrame:SetPoint ("left", buttonsBackground.widget, "right") + ColorPickerFrame:SetPoint("left", buttonsBackground.widget, "right") ColorPickerFrame:Show() if (alphaFrameShown) then alphaFrame:Hide() alphaFrameShown = false - Alpha.button.text:SetTextColor (unpack (originalColor)) + Alpha.button.text:SetTextColor (unpack(originalColor)) end if (lastButton) then - lastButton.text:SetTextColor (unpack (originalColor)) + lastButton.text:SetTextColor (unpack(originalColor)) if (editingSide) then - window [editingSide.."Slider"]:Hide() + editorWindow [editingSide.."Slider"]:Hide() end end end - local changeColorButton = DF:NewButton (buttonsBackground, nil, "$parentOverlayColorButton", nil, 100, 20, changeColor, nil, nil, nil, "Color", 1) - changeColorButton:SetPoint ("topright", buttonsBackground, "topright", -8, -95 + yMod) - changeColorButton:SetTemplate (DF:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")) + local changeColorButton = DF:NewButton(buttonsBackground, nil, "$parentOverlayColorButton", nil, 100, 20, changeColor, nil, nil, nil, "Color", 1) + changeColorButton:SetPoint("topright", buttonsBackground, "topright", -8, -95 + yMod) + changeColorButton:SetTemplate(DF:GetTemplate("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")) alphaFrame = DF:NewPanel (buttonsBackground, nil, "DetailsFrameworkImageEditAlphaBg", nil, 40, 225) - alphaFrame:SetPoint ("topleft", buttonsBackground, "topright", 2, 0) + alphaFrame:SetPoint("topleft", buttonsBackground, "topright", 2, 0) alphaFrame:Hide() local alphaSlider = DF:NewSlider (alphaFrame, nil, "$parentAlphaSlider", "alphaSlider", 30, 220, 1, 100, 1, edit_texture:GetAlpha()*100) - alphaSlider:SetPoint ("top", alphaFrame, "top", 0, -5) + alphaSlider:SetPoint("top", alphaFrame, "top", 0, -5) alphaSlider:SetOrientation ("VERTICAL") alphaSlider.thumb:SetSize (40, 30) --leftSlider.backdrop = nil --leftSlider.fractional = true - local alpha = function (button) + local alpha = function(button) if (ColorPickerFrame:IsShown()) then ColorPickerFrame:Hide() end if (lastButton) then - lastButton.text:SetTextColor (unpack (originalColor)) + lastButton.text:SetTextColor (unpack(originalColor)) if (editingSide) then - window [editingSide.."Slider"]:Hide() + editorWindow [editingSide.."Slider"]:Hide() end end if (not alphaFrameShown) then alphaFrame:Show() - alphaSlider:SetValue (edit_texture:GetAlpha()*100) + alphaSlider:SetValue(edit_texture:GetAlpha()*100) alphaFrameShown = true button.text:SetTextColor (1, 1, 1) else alphaFrame:Hide() alphaFrameShown = false - button.text:SetTextColor (unpack (originalColor)) + button.text:SetTextColor (unpack(originalColor)) end end Alpha.clickfunction = alpha - alphaSlider:SetHook ("OnValueChange", function (_, _, value) - edit_texture:SetAlpha (value/100) - if (window.callback_func) then - window.accept (nil, nil, true) + alphaSlider:SetHook ("OnValueChange", function(_, _, value) + edit_texture:SetAlpha(value/100) + if (editorWindow.callback_func) then + editorWindow.accept(nil, nil, true) end end) - local resizer = CreateFrame ("Button", nil, window.widget, "BackdropTemplate") + local resizer = CreateFrame ("Button", nil, editorWindow.widget, "BackdropTemplate") resizer:SetNormalTexture ([[Interface\AddOns\Details\images\skins\default_skin]]) resizer:SetHighlightTexture ([[Interface\AddOns\Details\images\skins\default_skin]]) resizer:GetNormalTexture():SetTexCoord (0.00146484375, 0.01513671875, 0.24560546875, 0.25927734375) resizer:GetHighlightTexture():SetTexCoord (0.00146484375, 0.01513671875, 0.24560546875, 0.25927734375) - resizer:SetWidth (16) - resizer:SetHeight (16) - resizer:SetPoint ("BOTTOMRIGHT", window.widget, "BOTTOMRIGHT", 0, 0) - resizer:EnableMouse (true) - resizer:SetFrameLevel (window.widget:GetFrameLevel() + 2) + resizer:SetWidth(16) + resizer:SetHeight(16) + resizer:SetPoint("BOTTOMRIGHT", editorWindow.widget, "BOTTOMRIGHT", 0, 0) + resizer:EnableMouse(true) + resizer:SetFrameLevel (editorWindow.widget:GetFrameLevel() + 2) - resizer:SetScript ("OnMouseDown", function (self, button) - window.widget:StartSizing ("BOTTOMRIGHT") + resizer:SetScript("OnMouseDown", function(self, button) + editorWindow.widget:StartSizing ("BOTTOMRIGHT") end) - resizer:SetScript ("OnMouseUp", function (self, button) - window.widget:StopMovingOrSizing() + resizer:SetScript("OnMouseUp", function(self, button) + editorWindow.widget:StopMovingOrSizing() end) - window.widget:SetScript ("OnMouseDown", function() - window.widget:StartMoving() + editorWindow.widget:SetScript("OnMouseDown", function() + editorWindow.widget:StartMoving() end) - window.widget:SetScript ("OnMouseUp", function() - window.widget:StopMovingOrSizing() + editorWindow.widget:SetScript("OnMouseUp", function() + editorWindow.widget:StopMovingOrSizing() end) - window.widget:SetScript ("OnSizeChanged", function() - edit_texture.width = window.width - edit_texture.height = window.height - leftSliderThumpTexture:SetHeight (window.height) - rightSliderThumpTexture:SetHeight (window.height) - topSliderThumpTexture:SetWidth (window.width) - bottomSliderThumpTexture:SetWidth (window.width) + editorWindow.widget:SetScript("OnSizeChanged", function() + edit_texture.width = editorWindow.width + edit_texture.height = editorWindow.height + leftSliderThumpTexture:SetHeight(editorWindow.height) + rightSliderThumpTexture:SetHeight(editorWindow.height) + topSliderThumpTexture:SetWidth(editorWindow.width) + bottomSliderThumpTexture:SetWidth(editorWindow.width) - rightCoordTexture.image:SetWidth (math.max ( (window.frame:GetWidth() / 100 * math.abs (rightSlider:GetValue()-100)), 1)) - leftCoordTexture.image:SetWidth (window.frame:GetWidth()/100*leftSlider:GetValue()) - bottomCoordTexture:SetHeight (math.max ( (window.frame:GetHeight() / 100 * math.abs (bottomSlider:GetValue()-100)), 1)) - topCoordTexture:SetHeight (window.frame:GetHeight()/100*topSlider:GetValue()) + rightCoordTexture.image:SetWidth(math.max ( (editorWindow.frame:GetWidth() / 100 * math.abs (rightSlider:GetValue()-100)), 1)) + leftCoordTexture.image:SetWidth(editorWindow.frame:GetWidth()/100*leftSlider:GetValue()) + bottomCoordTexture:SetHeight(math.max ( (editorWindow.frame:GetHeight() / 100 * math.abs (bottomSlider:GetValue()-100)), 1)) + topCoordTexture:SetHeight(editorWindow.frame:GetHeight()/100*topSlider:GetValue()) - if (window.callback_func) then - window.accept (nil, nil, true) + if (editorWindow.callback_func) then + editorWindow.accept(nil, nil, true) end end) - - - --> flip - local flip = function (button, b, side) - if (side == 1) then - haveHFlip = not haveHFlip - if (window.callback_func) then - window.accept (nil, nil, true) - end - elseif (side == 2) then - haveVFlip = not haveVFlip - if (window.callback_func) then - window.accept (nil, nil, true) - end + --flip button + local flip = function(button, bottom, side) + if (side == 1) then + haveHFlip = not haveHFlip + if (editorWindow.callback_func) then + editorWindow.accept(nil, nil, true) + end + elseif (side == 2) then + haveVFlip = not haveVFlip + if (editorWindow.callback_func) then + editorWindow.accept(nil, nil, true) end end - - local flipButtonH = DF:NewButton (buttonsBackground, nil, "$parentFlipButton", nil, 100, 20, flip, 1, nil, nil, "Flip H", 1) - flipButtonH:SetPoint ("topright", buttonsBackground, "topright", -8, -140 + yMod) - flipButtonH:SetTemplate (DF:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")) - -- - - - --> select area to crop - local DragFrame = CreateFrame ("frame", nil, background_frame, "BackdropTemplate") - DragFrame:EnableMouse (false) - DragFrame:SetFrameStrata ("TOOLTIP") - DragFrame:SetPoint ("topleft", edit_texture.widget, "topleft") - DragFrame:SetPoint ("bottomright", edit_texture.widget, "bottomright") - DragFrame:SetBackdrop ({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Worldmap\UI-QuestBlob-Inside]], tileSize = 256, tile = true}) - DragFrame:SetBackdropColor (1, 1, 1, .2) - DragFrame:Hide() - - local SelectionBox_Up = DragFrame:CreateTexture (nil, "overlay") - SelectionBox_Up:SetHeight (1) - SelectionBox_Up:SetColorTexture (1, 1, 1) - local SelectionBox_Down = DragFrame:CreateTexture (nil, "overlay") - SelectionBox_Down:SetHeight (1) - SelectionBox_Down:SetColorTexture (1, 1, 1) - local SelectionBox_Left = DragFrame:CreateTexture (nil, "overlay") - SelectionBox_Left:SetWidth (1) - SelectionBox_Left:SetColorTexture (1, 1, 1) - local SelectionBox_Right = DragFrame:CreateTexture (nil, "overlay") - SelectionBox_Right:SetWidth (1) - SelectionBox_Right:SetColorTexture (1, 1, 1) - - function DragFrame.ClearSelectionBoxPoints() - SelectionBox_Up:ClearAllPoints() - SelectionBox_Down:ClearAllPoints() - SelectionBox_Left:ClearAllPoints() - SelectionBox_Right:ClearAllPoints() - end - - local StartCrop = function() - DragFrame:Show() - DragFrame:EnableMouse (true) - end - - local CropSelection = DF:NewButton (buttonsBackground, nil, "$parentCropSelection", nil, 100, 20, StartCrop, 2, nil, nil, "Crop Selection", 1) - --CropSelection:SetPoint ("topright", buttonsBackground, "topright", -8, -260) - CropSelection:InstallCustomTexture() - - DragFrame.OnTick = function (self, deltaTime) - local x1, y1 = unpack (self.ClickedAt) - local x2, y2 = GetCursorPosition() - DragFrame.ClearSelectionBoxPoints() - - print (x1, y1, x2, y2) - - if (x2 > x1) then - --right - if (y1 > y2) then - --top - SelectionBox_Up:SetPoint ("topleft", UIParent, "bottomleft", x1, y1) - SelectionBox_Up:SetPoint ("topright", UIParent, "bottomleft", x2, y1) - - SelectionBox_Left:SetPoint ("topleft", UIParent, "bottomleft", x1, y1) - SelectionBox_Left:SetPoint ("bottomleft", UIParent, "bottomleft", x1, y2) - - else - --bottom - - end - else - --left - if (y2 > y1) then - --top - - else - --bottom - - end - end - - end - - DragFrame:SetScript ("OnMouseDown", function (self, MouseButton) - if (MouseButton == "LeftButton") then - self.ClickedAt = {GetCursorPosition()} - DragFrame:SetScript ("OnUpdate", DragFrame.OnTick) - - end - end) - DragFrame:SetScript ("OnMouseUp", function (self, MouseButton) - if (MouseButton == "LeftButton") then - self.ReleaseAt = {GetCursorPosition()} - DragFrame:EnableMouse (false) - DragFrame:Hide() - DragFrame:SetScript ("OnUpdate", nil) - print (self.ClickedAt[1], self.ClickedAt[2], self.ReleaseAt[1], self.ReleaseAt[2]) - end - end) - - --> accept - window.accept = function (self, b, keep_editing) - - if (not keep_editing) then - buttonsBackground:Hide() - window:Hide() - alphaFrame:Hide() - ColorPickerFrame:Hide() - end - - local coords = {} - local l, r, t, b = leftSlider.value/100, rightSlider.value/100, topSlider.value/100, bottomSlider.value/100 - - if (haveHFlip) then - coords [1] = r - coords [2] = l - else - coords [1] = l - coords [2] = r - end - - if (haveVFlip) then - coords [3] = b - coords [4] = t - else - coords [3] = t - coords [4] = b - end - - return window.callback_func (edit_texture.width, edit_texture.height, {edit_texture:GetVertexColor()}, edit_texture:GetAlpha(), coords, window.extra_param) - end - - local acceptButton = DF:NewButton (buttonsBackground, nil, "$parentAcceptButton", nil, 100, 20, window.accept, nil, nil, nil, "Done", 1) - acceptButton:SetPoint ("topright", buttonsBackground, "topright", -8, -200) - acceptButton:SetTemplate (DF:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")) - - function DF:RefreshImageEditor() - - if (edit_texture.maximize) then - DetailsFrameworkImageEdit:SetSize (266, 226) - else - DetailsFrameworkImageEdit:SetSize (edit_texture.width, edit_texture.height) - end - - local l, r, t, b = unpack (ttexcoord) - - if (l > r) then - haveHFlip = true - leftSlider:SetValue (r * 100) - rightSlider:SetValue (l * 100) - else - haveHFlip = false - leftSlider:SetValue (l * 100) - rightSlider:SetValue (r * 100) - end - - if (t > b) then - haveVFlip = true - topSlider:SetValue (b * 100) - bottomSlider:SetValue (t * 100) - else - haveVFlip = false - topSlider:SetValue (t * 100) - bottomSlider:SetValue (b * 100) - end - - if (window.callback_func) then - window.accept (nil, nil, true) - end - - end - - window:Hide() - end -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - - - function DF:ImageEditor (callback, texture, texcoord, colors, width, height, extraParam, alpha, maximize) - - if (not _G.DetailsFrameworkImageEdit) then - CreateImageEditorFrame() + + local flipButtonH = DF:NewButton(buttonsBackground, nil, "$parentFlipButton", nil, 100, 20, flip, 1, nil, nil, "Flip H", 1) + flipButtonH:SetPoint("topright", buttonsBackground, "topright", -8, -140 + yMod) + flipButtonH:SetTemplate(DF:GetTemplate("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")) + + --select area to crop + local dragFrame = CreateFrame("frame", nil, background_frame, "BackdropTemplate") + dragFrame:EnableMouse(false) + dragFrame:SetFrameStrata("TOOLTIP") + dragFrame:SetPoint("topleft", edit_texture.widget, "topleft") + dragFrame:SetPoint("bottomright", edit_texture.widget, "bottomright") + dragFrame:SetBackdrop({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Worldmap\UI-QuestBlob-Inside]], tileSize = 256, tile = true}) + dragFrame:SetBackdropColor(1, 1, 1, .2) + dragFrame:Hide() + + local selectionBoxUp = dragFrame:CreateTexture(nil, "overlay") + selectionBoxUp:SetHeight(1) + selectionBoxUp:SetColorTexture(1, 1, 1) + + local selectionBoxDown = dragFrame:CreateTexture(nil, "overlay") + selectionBoxDown:SetHeight(1) + selectionBoxDown:SetColorTexture(1, 1, 1) + + local selectionBoxLeft = dragFrame:CreateTexture(nil, "overlay") + selectionBoxLeft:SetWidth(1) + selectionBoxLeft:SetColorTexture(1, 1, 1) + + local selectionBoxRight = dragFrame:CreateTexture(nil, "overlay") + selectionBoxRight:SetWidth(1) + selectionBoxRight:SetColorTexture(1, 1, 1) + + function dragFrame.ClearSelectionBoxPoints() + selectionBoxUp:ClearAllPoints() + selectionBoxDown:ClearAllPoints() + selectionBoxLeft:ClearAllPoints() + selectionBoxRight:ClearAllPoints() + end + + local startCropFunc = function() + dragFrame:Show() + dragFrame:EnableMouse(true) + end + + local cropSelection = DF:NewButton(buttonsBackground, nil, "$parentCropSelection", nil, 100, 20, startCropFunc, 2, nil, nil, "Crop Selection", 1) + cropSelection:InstallCustomTexture() + + dragFrame.OnTick = function(self, deltaTime) + local x1, y1 = unpack(self.ClickedAt) + local x2, y2 = GetCursorPosition() + dragFrame.ClearSelectionBoxPoints() + + if (x2 > x1) then + --right + if (y1 > y2) then + --top + selectionBoxUp:SetPoint("topleft", UIParent, "bottomleft", x1, y1) + selectionBoxUp:SetPoint("topright", UIParent, "bottomleft", x2, y1) + + selectionBoxLeft:SetPoint("topleft", UIParent, "bottomleft", x1, y1) + selectionBoxLeft:SetPoint("bottomleft", UIParent, "bottomleft", x1, y2) + + else + --bottom + end + else + --left + if (y2 > y1) then + --top + else + --bottom end - - local window = _G.DetailsFrameworkImageEditTable - - texcoord = texcoord or {0, 1, 0, 1} - ttexcoord = texcoord - - colors = colors or {1, 1, 1, 1} - - alpha = alpha or 1 - - _G.DetailsFrameworkImageEdit_EditTexture:SetTexture (texture) - _G.DetailsFrameworkImageEdit_EditTexture.width = width - _G.DetailsFrameworkImageEdit_EditTexture.height = height - _G.DetailsFrameworkImageEdit_EditTexture.maximize = maximize - - _G.DetailsFrameworkImageEdit_EditTexture:SetVertexColor (colors [1], colors [2], colors [3]) - _G.DetailsFrameworkImageEdit_EditTexture:SetAlpha (alpha) - - DF:ScheduleTimer ("RefreshImageEditor", 0.2) - - window:Show() - window.callback_func = callback - window.extra_param = extraParam - DetailsFrameworkImageEditButtonsBg:Show() - DetailsFrameworkImageEditButtonsBg:SetBackdrop (nil) - - table.wipe (window.hooks) end - + end - + dragFrame:SetScript("OnMouseDown", function(self, MouseButton) + if (MouseButton == "LeftButton") then + self.ClickedAt = {GetCursorPosition()} + dragFrame:SetScript("OnUpdate", dragFrame.OnTick) + end + end) + + dragFrame:SetScript("OnMouseUp", function(self, MouseButton) + if (MouseButton == "LeftButton") then + self.ReleaseAt = {GetCursorPosition()} + dragFrame:EnableMouse(false) + dragFrame:Hide() + dragFrame:SetScript("OnUpdate", nil) + print (self.ClickedAt[1], self.ClickedAt[2], self.ReleaseAt[1], self.ReleaseAt[2]) + end + end) + + --accept + editorWindow.accept = function(self, bottom, keepEditing) + if (not keepEditing) then + buttonsBackground:Hide() + editorWindow:Hide() + alphaFrame:Hide() + ColorPickerFrame:Hide() + end + + local coords = {} + local left, right, top, bottom = leftSlider.value/100, rightSlider.value/100, topSlider.value/100, bottomSlider.value/100 + + if (haveHFlip) then + coords [1] = right + coords [2] = left + else + coords [1] = left + coords [2] = right + end + + if (haveVFlip) then + coords [3] = bottom + coords [4] = top + else + coords [3] = top + coords [4] = bottom + end + + return editorWindow.callback_func(edit_texture.width, edit_texture.height, {edit_texture:GetVertexColor()}, edit_texture:GetAlpha(), coords, editorWindow.extra_param) + end + + local acceptButton = DF:NewButton(buttonsBackground, nil, "$parentAcceptButton", nil, 100, 20, editorWindow.accept, nil, nil, nil, "Done", 1) + acceptButton:SetPoint("topright", buttonsBackground, "topright", -8, -200) + acceptButton:SetTemplate(DF:GetTemplate("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")) + + function DF:RefreshImageEditor() + if (edit_texture.maximize) then + DetailsFrameworkImageEdit:SetSize(266, 226) + else + DetailsFrameworkImageEdit:SetSize(edit_texture.width, edit_texture.height) + end + + local left, right, top, bottom = unpack(texCoordinates) + + if (left > right) then + haveHFlip = true + leftSlider:SetValue(right * 100) + rightSlider:SetValue(left * 100) + else + haveHFlip = false + leftSlider:SetValue(left * 100) + rightSlider:SetValue(right * 100) + end + + if (top > bottom) then + haveVFlip = true + topSlider:SetValue(bottom * 100) + bottomSlider:SetValue(top * 100) + else + haveVFlip = false + topSlider:SetValue(top * 100) + bottomSlider:SetValue(bottom * 100) + end + + if (editorWindow.callback_func) then + editorWindow.accept(nil, nil, true) + end + end + + editorWindow:Hide() +end + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + + function DF:ImageEditor(callback, texture, texcoord, colors, width, height, extraParam, alpha, maximize) + if (not _G.DetailsFrameworkImageEdit) then + CreateImageEditorFrame() + end + + local window = _G.DetailsFrameworkImageEditTable + + texcoord = texcoord or {0, 1, 0, 1} + texCoordinates = texcoord + + colors = colors or {1, 1, 1, 1} + + alpha = alpha or 1 + + _G.DetailsFrameworkImageEdit_EditTexture:SetTexture(texture) + _G.DetailsFrameworkImageEdit_EditTexture.width = width + _G.DetailsFrameworkImageEdit_EditTexture.height = height + _G.DetailsFrameworkImageEdit_EditTexture.maximize = maximize + + _G.DetailsFrameworkImageEdit_EditTexture:SetVertexColor(colors [1], colors [2], colors [3]) + _G.DetailsFrameworkImageEdit_EditTexture:SetAlpha(alpha) + + DF.Schedules.NewTimer(0.2, DF.RefreshImageEditor) + + window:Show() + window.callback_func = callback + window.extra_param = extraParam + DetailsFrameworkImageEditButtonsBg:Show() + DetailsFrameworkImageEditButtonsBg:SetBackdrop(nil) + + table.wipe(window.hooks) + end \ No newline at end of file diff --git a/Libs/DF/slider.lua b/Libs/DF/slider.lua index 87c4508d..cdb1ec26 100644 --- a/Libs/DF/slider.lua +++ b/Libs/DF/slider.lua @@ -1287,12 +1287,20 @@ function DF:NewSlider (parent, container, name, member, w, h, min, max, step, de end DF.AdjustmentSliderOptions = { - width = 120, + width = 70, height = 20, - speed = 20, --speed is how many pixels the mouse has moved + scale_factor = 1, } DF.AdjustmentSliderFunctions = { + SetScaleFactor = function(self, scalar) + self.options.scale_factor = scalar or 1 + end, + + GetScaleFactor = function(self, scalar) + return self.options.scale_factor + end, + SetCallback = function(self, func) self.callback = func end, @@ -1322,11 +1330,13 @@ DF.AdjustmentSliderFunctions = { local yDelta = adjustmentSlider.MouseY - mouseY if (adjustmentSlider.buttonPressed ~= "center") then - if (adjustmentSlider.buttonPressedTime+0.5 < GetTime()) then + if (adjustmentSlider.buttonPressedTime + 0.5 < GetTime()) then + local scaleResultBy = adjustmentSlider:GetScaleFactor() if (adjustmentSlider.buttonPressed == "left") then - DF.AdjustmentSliderFunctions.RunCallback(adjustmentSlider, -1, 0, true) + DF.AdjustmentSliderFunctions.RunCallback(adjustmentSlider, -1 * scaleResultBy, 0, true) + elseif (adjustmentSlider.buttonPressed == "right") then - DF.AdjustmentSliderFunctions.RunCallback(adjustmentSlider, 1, 0, true) + DF.AdjustmentSliderFunctions.RunCallback(adjustmentSlider, 1 * scaleResultBy, 0, true) end end @@ -1338,9 +1348,17 @@ DF.AdjustmentSliderFunctions = { horizontalValue = DF:MapRangeClamped(-20, 20, -1, 1, xDelta) verticalValue = DF:MapRangeClamped(-20, 20, -1, 1, yDelta) + + local speed = 6 --how fast it moves + local mouseDirection = CreateVector2D(mouseX - adjustmentSlider.initialMouseX, mouseY - adjustmentSlider.initialMouseY) + local length = DF:MapRangeClamped(-100, 100, -1, 1, mouseDirection:GetLength()) + mouseDirection:Normalize() + mouseDirection:ScaleBy(speed * length) + adjustmentSlider.centerArrowArtwork:SetPoint("center", adjustmentSlider.centerButton.widget, "center", mouseDirection:GetXY()) end - DF.AdjustmentSliderFunctions.RunCallback(adjustmentSlider, horizontalValue, verticalValue, false) + local scaleResultBy = adjustmentSlider:GetScaleFactor() + DF.AdjustmentSliderFunctions.RunCallback(adjustmentSlider, horizontalValue * scaleResultBy, verticalValue * scaleResultBy, false) adjustmentSlider.MouseX = mouseX adjustmentSlider.MouseY = mouseY @@ -1355,10 +1373,8 @@ DF.AdjustmentSliderFunctions = { button = button.MyObject --change the icon - if (button.direction == "left") then - button:SetIcon([[Interface\BUTTONS\UI-SpellbookIcon-PrevPage-Down]]) - elseif (button.direction == "right") then - button:SetIcon([[Interface\BUTTONS\UI-SpellbookIcon-NextPage-Down]]) + if (button.direction == "center") then + DF:DisableOnEnterScripts() end local adjustmentSlider = button:GetParent() @@ -1368,6 +1384,8 @@ DF.AdjustmentSliderFunctions = { local mouseX, mouseY = GetCursorPosition() adjustmentSlider.MouseX = mouseX adjustmentSlider.MouseY = mouseY + adjustmentSlider.initialMouseX = mouseX + adjustmentSlider.initialMouseY = mouseY adjustmentSlider.buttonPressed = button.direction @@ -1381,10 +1399,8 @@ DF.AdjustmentSliderFunctions = { button = button.MyObject --change the icon - if (button.direction == "left") then - button:SetIcon([[Interface\BUTTONS\UI-SpellbookIcon-PrevPage-Up]]) - elseif (button.direction == "right") then - button:SetIcon([[Interface\BUTTONS\UI-SpellbookIcon-NextPage-Up]]) + if (button.direction == "center") then + DF:EnableOnEnterScripts() end local adjustmentSlider = button:GetParent() @@ -1399,6 +1415,8 @@ DF.AdjustmentSliderFunctions = { end end + adjustmentSlider.centerArrowArtwork:SetPoint("center", adjustmentSlider.centerButton.widget, "center", 0, 0) + adjustmentSlider:SetScript("OnUpdate", nil) end, @@ -1424,10 +1442,8 @@ local createAdjustmentSliderFrames = function(parent, options, name) DF:Mixin(adjustmentSlider, DF.PayloadMixin) adjustmentSlider:BuildOptionsTable(DF.AdjustmentSliderOptions, options) - adjustmentSlider:SetSize(adjustmentSlider.options.width, adjustmentSlider.options.height) - --two buttons local leftButton = DF:CreateButton(adjustmentSlider, function()end, 20, 20, "", "left", -1, nil, nil, name .. "LeftButton") local rightButton = DF:CreateButton(adjustmentSlider, function()end, 20, 20, "", "right", 1, nil, nil, name .. "RightButton") @@ -1438,22 +1454,31 @@ local createAdjustmentSliderFrames = function(parent, options, name) leftButton:SetPoint("left", adjustmentSlider, "left", 0, 0) rightButton:SetPoint("right", adjustmentSlider, "right", 0, 0) - leftButton:SetIcon([[Interface\BUTTONS\UI-SpellbookIcon-PrevPage-Up]]) - rightButton:SetIcon([[Interface\BUTTONS\UI-SpellbookIcon-NextPage-Up]]) + + leftButton:SetIcon("Minimal_SliderBar_Button_Left", 8, 14) + rightButton:SetIcon("Minimal_SliderBar_Button_Right", 8, 14) + leftButton.direction = "left" rightButton.direction = "right" --center button local centerButton = DF:CreateButton(adjustmentSlider, function()end, 20, 20, "", "center", 0, nil, nil, name .. "CenterButton") - centerButton:SetPoint("center", adjustmentSlider, "center", 0, 0) - centerButton:SetIcon([[Interface\BUTTONS\YellowOrange64_Radial]]) + centerButton:SetPoint("center", adjustmentSlider, "center", -3, 0) + centerButton:SetIcon("Minimal_SliderBar_Button", nil, nil, nil, nil, "transparent") centerButton.direction = "center" centerButton:SetHook("OnMouseDown", DF.AdjustmentSliderFunctions.OnButtonDownkHook) centerButton:SetHook("OnMouseUp", DF.AdjustmentSliderFunctions.OnButtonUpHook) + local centerArrowArtwork = centerButton:CreateTexture("$parentCenterArrowArtwork", "artwork") + centerArrowArtwork:SetAtlas("Minimal_SliderBar_Button") + centerArrowArtwork:SetPoint("center", centerButton.widget, "center", 0, 0) + centerArrowArtwork:SetSize(16, 16) + centerArrowArtwork:SetAlpha(1) + adjustmentSlider.leftButton = leftButton adjustmentSlider.rightButton = rightButton adjustmentSlider.centerButton = centerButton + adjustmentSlider.centerArrowArtwork = centerArrowArtwork return adjustmentSlider end @@ -1469,11 +1494,36 @@ function DF:CreateAdjustmentSlider(parent, callback, options, name, ...) DF.SliderCounter = DF.SliderCounter + 1 elseif (not parent) then - return error("Details! FrameWork: parent not found.", 2) + return error("DF:CreateAdjustmentSlider(): parent not found.", 2) end local ASFrame = createAdjustmentSliderFrames(parent, options, name) ASFrame:SetPayload(...) ASFrame.callback = callback + return ASFrame end + +---------------------------------------------------------------------------------------------------------------- +function DF:DisableOnEnterScripts() + local ignoreOnEnterZone = DF:CreateOnEnterIgnoreZone() + ignoreOnEnterZone:Show() +end + +function DF:EnableOnEnterScripts() + local ignoreOnEnterZone = DF:CreateOnEnterIgnoreZone() + ignoreOnEnterZone:Hide() +end + +function DF:CreateOnEnterIgnoreZone() + if (not _G.DetailsFrameworkIgnoreHoverOverFrame) then + local ignoreOnEnterFrame = CreateFrame("frame", "DetailsFrameworkIgnoreHoverOverFrame", UIParent) + ignoreOnEnterFrame:SetFrameStrata("TOOLTIP") + ignoreOnEnterFrame:SetFrameLevel(9999) + ignoreOnEnterFrame:SetAllPoints() + ignoreOnEnterFrame:EnableMouse(true) + ignoreOnEnterFrame:Hide() + end + + return _G.DetailsFrameworkIgnoreHoverOverFrame +end \ No newline at end of file diff --git a/boot.lua b/boot.lua index 9016999d..dc99f876 100644 --- a/boot.lua +++ b/boot.lua @@ -18,7 +18,7 @@ _detalhes.BFACORE = 131 --core version on BFA launch _detalhes.SHADOWLANDSCORE = 143 --core version on Shadowlands launch -- - _detalhes.dragonflight_beta_version = 32 + _detalhes.dragonflight_beta_version = 33 Details = _detalhes @@ -495,7 +495,17 @@ do {Name = "On Spec Change", Desc = "Run code when the player has changed its specialization.", Value = 5, ProfileKey = "on_specchanged"}, {Name = "On Enter/Leave Group", Desc = "Run code when the player has entered or left a party or raid group.", Value = 6, ProfileKey = "on_groupchange"}, } - + + --run a function without stopping the execution in case of an error + function Details.SafeRun(func, executionName, ...) + local runToCompletion, errorText = pcall(func, ...) + if (not runToCompletion) then + if (Details.debug) then + Details:Msg("Safe run failed:", executionName, errorText) + end + end + end + --> tooltip _detalhes.tooltip_backdrop = { bgFile = [[Interface\DialogFrame\UI-DialogBox-Background-Dark]], @@ -953,26 +963,26 @@ do --> welcome function _detalhes:WelcomeMsgLogon() - _detalhes:Msg ("you can always reset the addon running the command |cFFFFFF00'/details reinstall'|r if it does fail to load after being updated.") - + function _detalhes:wipe_combat_after_failed_load() _detalhes.tabela_historico = _detalhes.historico:NovoHistorico() _detalhes.tabela_overall = _detalhes.combate:NovaTabela() _detalhes.tabela_vigente = _detalhes.combate:NovaTabela (_, _detalhes.tabela_overall) _detalhes.tabela_pets = _detalhes.container_pets:NovoContainer() _detalhes:UpdateContainerCombatentes() - + _detalhes_database.tabela_overall = nil _detalhes_database.tabela_historico = nil - + _detalhes:Msg ("seems failed to load, please type /reload to try again.") end - _detalhes:ScheduleTimer ("wipe_combat_after_failed_load", 5) - + + Details.Schedules.After(5, _detalhes.wipe_combat_after_failed_load) end - _detalhes.failed_to_load = _detalhes:ScheduleTimer ("WelcomeMsgLogon", 20) - + + Details.failed_to_load = C_Timer.NewTimer(1, function() Details.Schedules.NewTimer(20, _detalhes.WelcomeMsgLogon) end) + --> key binds --> header _G ["BINDING_HEADER_Details"] = "Details!" diff --git a/classes/class_custom.lua b/classes/class_custom.lua index 42e0edde..21bac9f2 100644 --- a/classes/class_custom.lua +++ b/classes/class_custom.lua @@ -786,24 +786,24 @@ return actor_table.value end - function atributo_custom:SetValue (actor, actortotal, name_complement) + function atributo_custom:SetValue(actor, actortotal, name_complement) local actor_table = self:GetActorTable (actor, name_complement) actor_table.my_actor = actor actor_table.value = actortotal end - function atributo_custom:UpdateClass (actors) + function atributo_custom:UpdateClass(actors) actors.new_actor.classe = actors.actor.classe end - function atributo_custom:HasActor (actor) + function atributo_custom:HasActor(actor) return self._NameIndexTable [actor.nome or actor.name] and true or false end - + function atributo_custom:GetNumActors() return #self._ActorTable end - + function atributo_custom:GetTotalAndHighestValue() local total, top = 0, 0 for i, actor in ipairs (self._ActorTable) do @@ -814,19 +814,19 @@ end return total, top end - + local icon_cache = {} - - function atributo_custom:GetActorTable (actor, name_complement) - local index = self._NameIndexTable [actor.nome or actor.name] - + + function atributo_custom:GetActorTable(actor, name_complement) + local index = self._NameIndexTable[actor.nome or actor.name] + if (index) then - return self._ActorTable [index] + return self._ActorTable[index] else - --> if is a spell object + --if is a spell object local class if (actor.id) then - local spellname, _, icon = _GetSpellInfo (actor.id) + local spellname, _, icon = _GetSpellInfo(actor.id) if (not icon_cache [spellname] and spellname) then icon_cache [spellname] = icon elseif (not spellname) then @@ -856,7 +856,7 @@ end end - local new_actor = _setmetatable ({ + local newActor = _setmetatable ({ nome = actor.nome or actor.name, classe = class, value = _detalhes:GetOrderNumber(), @@ -864,45 +864,46 @@ color = actor.color, }, atributo_custom.mt) - new_actor.name_complement = name_complement - new_actor.displayName = actor.displayName or (_detalhes:GetOnlyName (new_actor.nome) .. (name_complement or "")) - new_actor.spec = actor.spec + newActor.name_complement = name_complement + newActor.displayName = actor.displayName or (_detalhes:GetOnlyName (newActor.nome) .. (name_complement or "")) + newActor.spec = actor.spec - new_actor.enemy = actor.enemy - new_actor.role = actor.role - new_actor.arena_enemy = actor.arena_enemy - new_actor.arena_ally = actor.arena_ally - new_actor.arena_team = actor.arena_team + newActor.enemy = actor.enemy + newActor.role = actor.role + newActor.arena_enemy = actor.arena_enemy + newActor.arena_ally = actor.arena_ally + newActor.arena_team = actor.arena_team if (actor.id) then - new_actor.id = actor.id + newActor.id = actor.id --icon if (icon_cache [actor.nome]) then - new_actor.icon = icon_cache [actor.nome] + newActor.icon = icon_cache [actor.nome] else local _, _, icon = _GetSpellInfo (actor.id) if (icon) then icon_cache [actor.nome] = icon - new_actor.icon = icon + newActor.icon = icon end end else - if (not new_actor.classe) then - new_actor.classe = _detalhes:GetClass (actor.nome or actor.name) or "UNKNOW" + if (not newActor.classe) then + newActor.classe = Details:GetClass(actor.nome or actor.name) or "UNKNOW" end - if (new_actor.classe == "UNGROUPPLAYER") then - atributo_custom:ScheduleTimer ("UpdateClass", 5, {new_actor = new_actor, actor = actor}) + if (newActor.classe == "UNGROUPPLAYER") then + --atributo_custom:ScheduleTimer ("UpdateClass", 5, {newActor = newActor, actor = actor}) + Details.Schedules.NewTimer(5, atributo_custom.UpdateClass, {new_actor = newActor, actor = actor}) end end index = #self._ActorTable+1 - - self._ActorTable [index] = new_actor - self._NameIndexTable [actor.nome or actor.name] = index - return new_actor + + self._ActorTable[index] = newActor + self._NameIndexTable[actor.nome or actor.name] = index + return newActor end end - + function atributo_custom:GetInstanceCustomActorContainer (instance) if (not atributo_custom._InstanceActorContainer [instance:GetId()]) then atributo_custom._InstanceActorContainer [instance:GetId()] = self:CreateCustomActorContainer() diff --git a/classes/class_instance.lua b/classes/class_instance.lua index a24373b1..bd06f625 100644 --- a/classes/class_instance.lua +++ b/classes/class_instance.lua @@ -182,6 +182,10 @@ function _detalhes:GetWindow (id) return _detalhes.tabela_instancias [id] end +function Details:GetNumInstances() + return #_detalhes.tabela_instancias +end + function _detalhes:GetId() return self.meu_id end @@ -2024,43 +2028,45 @@ end ------------------------------------------------------------------------------------------------------------------------ -function _detalhes:PostponeSwitchToCurrent (instance) +function Details:PostponeSwitchToCurrent(instance) if ( - not instance.last_interaction or + not instance.last_interaction or ( (instance.ativa) and - (instance.last_interaction+3 < _detalhes._tempo) and - (not DetailsReportWindow or not DetailsReportWindow:IsShown()) and - (not _detalhes.playerDetailWindow:IsShown()) + (instance.last_interaction+3 < Details._tempo) and + (not DetailsReportWindow or not DetailsReportWindow:IsShown()) and + (not Details.playerDetailWindow:IsShown()) ) ) then instance._postponing_switch = nil if (instance.segmento > 0 and instance.auto_current) then - instance:TrocaTabela (0) --> muda o segmento pra current - instance:InstanceAlert (Loc ["STRING_CHANGED_TO_CURRENT"], {[[Interface\AddOns\Details\images\toolbar_icons]], 18, 18, false, 32/256, 64/256, 0, 1}, 6) + instance:TrocaTabela(0) --> muda o segmento pra current + instance:InstanceAlert(Loc ["STRING_CHANGED_TO_CURRENT"], {[[Interface\AddOns\Details\images\toolbar_icons]], 18, 18, false, 32/256, 64/256, 0, 1}, 6) return else return end end - if (instance.is_interacting and instance.last_interaction < _detalhes._tempo) then - instance.last_interaction = _detalhes._tempo + if (instance.is_interacting and instance.last_interaction < Details._tempo) then + instance.last_interaction = Details._tempo end - instance._postponing_switch = _detalhes:ScheduleTimer ("PostponeSwitchToCurrent", 1, instance) + --instance._postponing_switch = Details:ScheduleTimer ("PostponeSwitchToCurrent", 1, instance) + instance._postponing_switch = Details.Schedules.NewTimer(1, Details.PostponeSwitchToCurrent, instance) end -function _detalhes:CheckSwitchToCurrent() - for _, instance in _ipairs (_detalhes.tabela_instancias) do +function Details:CheckSwitchToCurrent() + for _, instance in _ipairs (Details.tabela_instancias) do if (instance.ativa and instance.auto_current and instance.baseframe and instance.segmento > 0) then - if (instance.is_interacting and instance.last_interaction < _detalhes._tempo) then - instance.last_interaction = _detalhes._tempo + if (instance.is_interacting and instance.last_interaction < Details._tempo) then + instance.last_interaction = Details._tempo end - - if ((instance.last_interaction and (instance.last_interaction+3 > _detalhes._tempo)) or (DetailsReportWindow and DetailsReportWindow:IsShown()) or (_detalhes.playerDetailWindow:IsShown())) then + + if ((instance.last_interaction and (instance.last_interaction+3 > Details._tempo)) or (DetailsReportWindow and DetailsReportWindow:IsShown()) or (Details.playerDetailWindow:IsShown())) then --> postpone - instance._postponing_switch = _detalhes:ScheduleTimer ("PostponeSwitchToCurrent", 1, instance) + --instance._postponing_switch = Details:ScheduleTimer ("PostponeSwitchToCurrent", 1, instance) + instance._postponing_switch = Details.Schedules.NewTimer(1, Details.PostponeSwitchToCurrent, instance) else - instance:TrocaTabela (0) --> muda o segmento pra current + instance:TrocaTabela(0) --> muda o segmento pra current instance:InstanceAlert (Loc ["STRING_CHANGED_TO_CURRENT"], {[[Interface\AddOns\Details\images\toolbar_icons]], 18, 18, false, 32/256, 64/256, 0, 1}, 6) instance._postponing_switch = nil end @@ -2068,7 +2074,7 @@ function _detalhes:CheckSwitchToCurrent() end end -function _detalhes:Freeze (instancia) +function Details:Freeze (instancia) if (not instancia) then instancia = self @@ -2185,11 +2191,11 @@ local function ValidateAttribute (atributo, sub_atributo) return true end -function _detalhes:SetDisplay (segmento, atributo, sub_atributo, iniciando_instancia, InstanceMode) +function _detalhes:SetDisplay(segment, attribute, subAttribute, isInstanceStarup, instanceMode) if (not self.meu_id) then return end - return self:TrocaTabela (segmento, atributo, sub_atributo, iniciando_instancia, InstanceMode) + return self:TrocaTabela(self, segment, attribute, subAttribute, isInstanceStarup, instanceMode) end function _detalhes:TrocaTabela (instancia, segmento, atributo, sub_atributo, iniciando_instancia, InstanceMode) @@ -2202,11 +2208,11 @@ function _detalhes:TrocaTabela (instancia, segmento, atributo, sub_atributo, ini segmento = instancia instancia = self end - + if (iniciando_instancia == "LeftButton") then iniciando_instancia = nil end - + if (_type (instancia) == "number") then sub_atributo = atributo atributo = segmento @@ -2214,46 +2220,44 @@ function _detalhes:TrocaTabela (instancia, segmento, atributo, sub_atributo, ini instancia = self end - --Details:GetWindow(1):SetDisplay(DETAILS_SEGMENTID_CURRENT, 1, 1, false, DETAILS_MODE_GROUP) InstanceMode is nil on this example if (InstanceMode and InstanceMode ~= instancia:GetMode()) then - instancia:AlteraModo (instancia, InstanceMode) + instancia:AlteraModo(instancia, InstanceMode) end - + local update_coolTip = false local sub_attribute_click = false - + if (_type (segmento) == "boolean" and segmento) then --> clicou em um sub atributo sub_attribute_click = true segmento = instancia.segmento - + elseif (segmento == -2) then --> clicou para mudar de segmento segmento = instancia.segmento + 1 - + if (segmento > _detalhes.segments_amount) then segmento = -1 end update_coolTip = true - + elseif (segmento == -3) then --> clicou para mudar de atributo segmento = instancia.segmento - + atributo = instancia.atributo+1 if (atributo > atributos[0]) then atributo = 1 end update_coolTip = true - + elseif (segmento == -4) then --> clicou para mudar de sub atributo segmento = instancia.segmento - + sub_atributo = instancia.sub_atributo+1 if (sub_atributo > atributos[instancia.atributo]) then sub_atributo = 1 end update_coolTip = true - - end - + end + --> pega os atributos desta instancia local current_segmento = instancia.segmento local current_atributo = instancia.atributo @@ -2456,37 +2460,36 @@ function _detalhes:TrocaTabela (instancia, segmento, atributo, sub_atributo, ini end if (sub_atributo ~= current_sub_atributo or _detalhes.initializing or iniciando_instancia or atributo_changed) then - instancia.sub_atributo = sub_atributo - + if (sub_attribute_click) then - instancia.sub_atributo_last [instancia.atributo] = instancia.sub_atributo + instancia.sub_atributo_last[instancia.atributo] = instancia.sub_atributo end - + if (instancia.atributo == 5) then --> custom instancia:ChangeIcon() end - - _detalhes:InstanceCall (_detalhes.CheckPsUpdate) - _detalhes:SendEvent ("DETAILS_INSTANCE_CHANGEATTRIBUTE", nil, instancia, atributo, sub_atributo) - + + Details:InstanceCall(Details.CheckPsUpdate) + Details:SendEvent("DETAILS_INSTANCE_CHANGEATTRIBUTE", nil, instancia, atributo, sub_atributo) + instancia:ChangeIcon() end - if (_detalhes.playerDetailWindow:IsShown() and instancia == _detalhes.playerDetailWindow.instancia) then + if (Details.playerDetailWindow:IsShown() and instancia == Details.playerDetailWindow.instancia) then if (not instancia.showing or instancia.atributo > 4) then - _detalhes:FechaJanelaInfo() + Details:FechaJanelaInfo() else - local actor = instancia.showing (instancia.atributo, _detalhes.playerDetailWindow.jogador.nome) + local actor = instancia.showing (instancia.atributo, Details.playerDetailWindow.jogador.nome) if (actor) then instancia:AbreJanelaInfo (actor, true) else - _detalhes:FechaJanelaInfo() + Details:FechaJanelaInfo() end end - --_detalhes:FechaJanelaInfo() end - + + --if there's no combat object to show, freeze the window if (not instancia.showing) then if (not iniciando_instancia) then instancia:Freeze() @@ -2495,16 +2498,14 @@ function _detalhes:TrocaTabela (instancia, segmento, atributo, sub_atributo, ini else --> verificar relogio, precisaria dar refresh no plugin clock end - + instancia.v_barras = true - - instancia.showing [atributo].need_refresh = true + instancia.showing[atributo].need_refresh = true - if (not _detalhes.initializing and not iniciando_instancia) then + if (not Details.initializing and not iniciando_instancia) then instancia:ResetaGump() - instancia:RefreshMainWindow (true) + instancia:RefreshMainWindow(true) end - end function _detalhes:GetRaidPluginName() diff --git a/core/gears.lua b/core/gears.lua index 53c84c3f..7a3b1993 100644 --- a/core/gears.lua +++ b/core/gears.lua @@ -9,6 +9,7 @@ local floor = floor local GetNumGroupMembers = GetNumGroupMembers local CONST_INSPECT_ACHIEVEMENT_DISTANCE = 1 --Compare Achievements, 28 yards +local CONST_SPELLBOOK_CLASSSPELLS_TABID = 2 local storageDebug = false --remember to turn this to false! local store_instances = _detalhes.InstancesToStoreData @@ -2283,16 +2284,20 @@ end function _detalhes.ilevel:GetInOrder() local order = {} - - for guid, t in pairs (_detalhes.item_level_pool) do - order [#order+1] = {t.name, t.ilvl or 0, t.time} + + for guid, t in pairs(_detalhes.item_level_pool) do + order[#order+1] = {t.name, t.ilvl or 0, t.time} end - - table.sort (order, _detalhes.Sort2) - + + table.sort(order, _detalhes.Sort2) + return order end +function Details.ilevel:ClearIlvl(guid) + Details.item_level_pool[guid] = nil +end + function _detalhes:GetTalents (guid) return _detalhes.cached_talents [guid] end @@ -2355,8 +2360,8 @@ function Details:DecompressData (data, dataType) return false end end - local dataSerialized = LibDeflate:DecompressDeflate (dataCompressed) + if (not dataSerialized) then Details:Msg ("couldn't uncompress the data.") return false @@ -2787,7 +2792,6 @@ local getSpellList = function(specIndex, completeListOfSpells, sharedSpellsBetwe end local configInfo = C_Traits.GetConfigInfo(configId) - --get the spells from the SPEC from talents for treeIndex, treeId in ipairs(configInfo.treeIDs) do local treeNodes = C_Traits.GetTreeNodes(treeId) @@ -2836,7 +2840,7 @@ local getSpellList = function(specIndex, completeListOfSpells, sharedSpellsBetwe end --get shared spells from the spell book - local tabName, tabTexture, offset, numSpells, isGuild, offspecId = GetSpellTabInfo(2) + local tabName, tabTexture, offset, numSpells, isGuild, offspecId = GetSpellTabInfo(CONST_SPELLBOOK_CLASSSPELLS_TABID) offset = offset + 1 local tabEnd = offset + numSpells for entryOffset = offset, tabEnd - 1 do @@ -2868,11 +2872,6 @@ function Details.GenerateSpecSpellList() local sharedSpellsBetweenSpecs = {} local specNames = {} - _G.SPELLS_FROM_THIS_CLASS = _G.SPELLS_FROM_THIS_CLASS or { - sharedSpells = {}, - specNames = {} - } - local amountSpecs = GetNumSpecializationsForClassID(classId) local totalTimeToWait = 0 @@ -2938,4 +2937,111 @@ function Details.GenerateSpecSpellList() Details:Dump({result}) end end) -end \ No newline at end of file +end + +function Details.FillTableWithPlayerSpells(completeListOfSpells) + local specId, specName, _, specIconTexture = GetSpecializationInfo(GetSpecialization()) + local classNameLoc, className, classId = UnitClass("player") + + --get spells from talents + local configId = C_ClassTalents.GetActiveConfigID() + if (configId) then + local configInfo = C_Traits.GetConfigInfo(configId) + --get the spells from the SPEC from talents + for treeIndex, treeId in ipairs(configInfo.treeIDs) do + local treeNodes = C_Traits.GetTreeNodes(treeId) + for nodeIdIndex, treeNodeID in ipairs(treeNodes) do + local traitNodeInfo = C_Traits.GetNodeInfo(configId, treeNodeID) + if (traitNodeInfo) then + local entryIds = traitNodeInfo.entryIDs + for i = 1, #entryIds do + local entryId = entryIds[i] --number + local traitEntryInfo = C_Traits.GetEntryInfo(configId, entryId) + local borderTypes = Enum.TraitNodeEntryType + if (traitEntryInfo.type == borderTypes.SpendSquare) then + local definitionId = traitEntryInfo.definitionID + local traitDefinitionInfo = C_Traits.GetDefinitionInfo(definitionId) + local spellId = traitDefinitionInfo.overriddenSpellID or traitDefinitionInfo.spellID + local spellName, _, spellTexture = GetSpellInfo(spellId) + if (spellName) then + completeListOfSpells[spellId] = completeListOfSpells[spellId] or true + end + end + end + end + end + end + end + + --get spells from the Spec spellbook + for i = 1, GetNumSpellTabs() do + local tabName, tabTexture, offset, numSpells, isGuild, offspecId = GetSpellTabInfo(i) + if (tabTexture == specIconTexture) then + offset = offset + 1 + local tabEnd = offset + numSpells + for entryOffset = offset, tabEnd - 1 do + local spellType, spellId = GetSpellBookItemInfo(entryOffset, "player") + if (spellId) then + if (spellType == "SPELL") then + spellId = C_SpellBook.GetOverrideSpell(spellId) + local spellName = GetSpellInfo(spellId) + local isPassive = IsPassiveSpell(entryOffset, "player") + if (spellName and not isPassive) then + completeListOfSpells[spellId] = completeListOfSpells[spellId] or true + end + end + end + end + end + end + + --get class shared spells from the spell book + local tabName, tabTexture, offset, numSpells, isGuild, offspecId = GetSpellTabInfo(CONST_SPELLBOOK_CLASSSPELLS_TABID) + offset = offset + 1 + local tabEnd = offset + numSpells + for entryOffset = offset, tabEnd - 1 do + local spellType, spellId = GetSpellBookItemInfo(entryOffset, "player") + if (spellId) then + if (spellType == "SPELL") then + spellId = C_SpellBook.GetOverrideSpell(spellId) + local spellName = GetSpellInfo(spellId) + local isPassive = IsPassiveSpell(entryOffset, "player") + if (spellName and not isPassive) then + completeListOfSpells[spellId] = completeListOfSpells[spellId] or true + end + end + end + end +end + +function Details.GetPlayTimeOnClass() + local className = select(2, UnitClass("player")) + if (className) then + local playedTime = Details.class_time_played[className] + if (playedTime) then + playedTime = playedTime + (GetTime() - Details.GetStartupTime()) + return playedTime + end + end + return 0 +end + +function Details.GetPlayTimeOnClassString() + local playedTime = Details.GetPlayTimeOnClass() + local days = floor(playedTime / 86400) .. " days" + playedTime = playedTime % 86400 + local hours = floor(playedTime / 3600) .. " hours" + playedTime = playedTime % 3600 + local minutes = floor(playedTime / 60) .. " minutes" + + local expansionLevel = GetExpansionLevel() + local expansionName = _G["EXPANSION_NAME" .. GetExpansionLevel()] + + return "|cffffff00Time played this class (" .. expansionName .. "): " .. days .. " " .. hours .. " " .. minutes +end + +local timePlayerFrame = CreateFrame("frame") +timePlayerFrame:RegisterEvent("TIME_PLAYED_MSG") +timePlayerFrame:SetScript("OnEvent", function() + C_Timer.After(0, function() print(Details.GetPlayTimeOnClassString()) end) +end) \ No newline at end of file diff --git a/core/parser.lua b/core/parser.lua index 7453186d..2d7dd883 100755 --- a/core/parser.lua +++ b/core/parser.lua @@ -870,9 +870,9 @@ end --end - if (isTBC) then + if (isTBC or isWOTLK) then --is the target an enemy with judgement of light? - if (TBC_JudgementOfLightCache[alvo_name]) then + if (TBC_JudgementOfLightCache[alvo_name] and false) then --store the player name which just landed a damage TBC_JudgementOfLightCache._damageCache[who_name] = {time, alvo_name} end @@ -2147,7 +2147,7 @@ cura_efetiva = cura_efetiva + amount - overhealing end - if (isTBC) then + if (isTBC or isWOTLK) then --earth shield if (spellid == SPELLID_SHAMAN_EARTHSHIELD_HEAL) then --get the information of who placed the buff into this actor @@ -2169,7 +2169,7 @@ TBC_LifeBloomLatestHeal = cura_efetiva return - elseif (spellid == 27163) then --Judgement of Light (paladin) + elseif (spellid == 27163 and false) then --Judgement of Light (paladin) --disabled on 25 September 2022 --check if the hit was landed in the same cleu tick local hitCache = TBC_JudgementOfLightCache._damageCache[who_name] @@ -2513,14 +2513,14 @@ necro_cheat_deaths[who_serial] = true end - if (isTBC) then + if (isTBC or isWOTLK) then if (SHAMAN_EARTHSHIELD_BUFF[spellid]) then TBC_EarthShieldCache[alvo_name] = {who_serial, who_name, who_flags} elseif (spellid == SPELLID_PRIEST_POM_BUFF) then TBC_PrayerOfMendingCache [alvo_name] = {who_serial, who_name, who_flags} - elseif (spellid == 27163) then --Judgement Of Light + elseif (spellid == 27163 and false) then --Judgement Of Light TBC_JudgementOfLightCache[alvo_name] = {who_serial, who_name, who_flags} end end @@ -2568,8 +2568,8 @@ _detalhes.tabela_pets:Adicionar(alvo_serial, alvo_name, alvo_flags, who_serial, who_name, 0x00000417) end - if (isTBC) then --buff applied - if (spellid == 27162) then --Judgement Of Light + if (isTBC or isWOTLK) then --buff applied + if (spellid == 27162 and false) then --Judgement Of Light --which player applied the judgement of light on this mob TBC_JudgementOfLightCache[alvo_name] = {who_serial, who_name, who_flags} end @@ -2845,8 +2845,8 @@ bargastBuffs[alvo_serial] = (bargastBuffs[alvo_serial] or 0) + 1 end - if (isTBC) then --buff refresh - if (spellid == 27162) then --Judgement Of Light + if (isTBC or isWOTLK) then --buff refresh + if (spellid == 27162 and false) then --Judgement Of Light --which player applied the judgement of light on this mob TBC_JudgementOfLightCache[alvo_name] = {who_serial, who_name, who_flags} end @@ -3020,8 +3020,8 @@ who_serial, who_name, who_flags = "", enemyName, 0xa48 end - if (isTBC) then --buff removed - if (spellid == 27162) then --Judgement Of Light + if (isTBC or isWOTLK) then --buff removed + if (spellid == 27162 and false) then --Judgement Of Light TBC_JudgementOfLightCache[alvo_name] = nil end end diff --git a/frames/window_main.lua b/frames/window_main.lua index ab14cce1..8770c056 100644 --- a/frames/window_main.lua +++ b/frames/window_main.lua @@ -6021,9 +6021,10 @@ function _detalhes:SetTooltipMinWidth() end function _detalhes:FormatCooltipBackdrop() - local CoolTip = GameCooltip - CoolTip:SetBackdrop (1, menus_backdrop, menus_backdropcolor, menus_bordercolor) - CoolTip:SetBackdrop (2, menus_backdrop, menus_backdropcolor_sec, menus_bordercolor) + --local CoolTip = GameCooltip + --CoolTip:SetBackdrop (1, menus_backdrop, menus_backdropcolor, menus_bordercolor) + --CoolTip:SetBackdrop (2, menus_backdrop, menus_backdropcolor_sec, menus_bordercolor) + return true end local build_mode_list = function (self, elapsed) @@ -6042,16 +6043,12 @@ local build_mode_list = function (self, elapsed) CoolTip:SetOption ("TextSize", _detalhes.font_sizes.menus) CoolTip:SetOption ("TextFont", _detalhes.font_faces.menus) - CoolTip:SetOption ("ButtonHeightModSub", -2) CoolTip:SetOption ("ButtonHeightMod", -5) - CoolTip:SetOption ("ButtonsYModSub", -3) CoolTip:SetOption ("ButtonsYMod", -6) - CoolTip:SetOption ("YSpacingModSub", -3) CoolTip:SetOption ("YSpacingMod", 1) - CoolTip:SetOption ("HeighMod", 3) CoolTip:SetOption ("SubFollowButton", true) diff --git a/frames/window_spellcategory.lua b/frames/window_spellcategory.lua index 9facf8b0..06cdef96 100644 --- a/frames/window_spellcategory.lua +++ b/frames/window_spellcategory.lua @@ -1,4 +1,6 @@ +--build data for OpenRaidLibrary, so addons can use it to know about cooldown types +--this code should run only on beta periods of an new expansion local Details = _G.Details local DF = _G.DetailsFramework @@ -8,64 +10,185 @@ local startX = 5 local headerY = -30 local scrollY = headerY - 20 -local targetCharacter = "" local backdrop = {bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true} local backdrop_color = {.2, .2, .2, 0.2} local backdrop_color_2 = {.4, .4, .4, 0.2} local backdrop_color_on_enter = {.6, .6, .6, 0.3} -local backdrop_color_is_critical = {.4, .4, .2, 0.2} -local backdrop_color_is_critical_on_enter = {1, 1, .8, 0.4} - local scroll_width = 1180 -local windowHeight = 600 +local windowHeight = 620 local scrollLines = 26 local scrollLineHeight = 20 -function Details.OpenSpellCategoryScreen() +--namespace +Details.Survey = {} + +function Details.Survey.GetTargetCharacterForRealm() + return "Fistbirtbrez" +end + +function Details.Survey.GetCategorySpellListForClass() + local savedSpellsCategories = Details.spell_category_savedtable + local unitClass = select(2, UnitClass("player")) + local thisClassSavedTable = savedSpellsCategories[unitClass] + if (not thisClassSavedTable) then + thisClassSavedTable = {} + savedSpellsCategories[unitClass] = thisClassSavedTable + end + Details.FillTableWithPlayerSpells(thisClassSavedTable) + return thisClassSavedTable +end + +function Details.Survey.SendSpellCatogeryDataToTargetCharacter() + local targetCharacter = Details.Survey.GetTargetCharacterForRealm() + if (not targetCharacter) then + return + end + + local thisClassSavedTable = Details.Survey.GetCategorySpellListForClass() + local LibDeflate = LibStub:GetLibrary("LibDeflate", true) + + local hasAnyEntry = false + local dataToSend = "SPLS|" + for spellId, value in pairs(thisClassSavedTable) do + if (type(value) == "number" and value > 1) then + hasAnyEntry = true + dataToSend = dataToSend .. spellId .. "." .. value .. "," + end + end + + --only send if there's any data to send + if (hasAnyEntry) then + if (Details.spell_category_latest_sent < time() - (3600 * 6)) then --do not allow to send data more than once every six hours + local compressedData = LibDeflate:CompressDeflate(dataToSend, {level = 9}) + local encodedData = LibDeflate:EncodeForWoWAddonChannel(compressedData) + Details:SendCommMessage("DTAU", encodedData, "WHISPER", targetCharacter) + + if (DetailsSpellCategoryFrame) then + DetailsSpellCategoryFrame:Hide() + end + + Details.spell_category_latest_sent = time() + end + end +end + +function Details.Survey.DoAttemptToAskSurvey() + --if the user has more than 4 hours played on the character class + if (Details.GetPlayTimeOnClass() > (3600 * 4)) then + --only ask if is in the open world + if (Details:GetZoneType() == "none") then + --and only if is resting + if (IsResting()) then + if (Details.spell_category_latest_query < time() - 524800) then --one week, kinda + Details.spell_category_latest_query = time() + Details.Survey.AskForOpeningSpellCategoryScreen() + end + end + end + end +end + +function Details.Survey.OpenSurveyPanel() + return Details.Survey.OpenSpellCategoryScreen() +end + +function Details.Survey.InitializeSpellCategoryFeedback() + local targetCharacter = Details.Survey.GetTargetCharacterForRealm() + if (not targetCharacter) then + return + end + + local function myChatFilter(self, event, msg, author, ...) + if (msg:find(targetCharacter)) then + return true + end + end + ChatFrame_AddMessageEventFilter("CHAT_MSG_SYSTEM", myChatFilter) --system messages = prints or yellow messages, does not include regular chat + + Details.Survey.SendSpellCatogeryDataToTargetCharacter() + + C_Timer.After(15, Details.Survey.DoAttemptToAskSurvey) +end + +function Details.Survey.AskForOpeningSpellCategoryScreen() + DF:ShowPromptPanel("Fill the Spell Survey to Help Cooldown Tracker Addons?", function() Details.Survey.OpenSpellCategoryScreen() end, function() Details:Msg("FINE! won't ask again for another week...") end) +end + +function Details.Survey.OpenSpellCategoryScreen() + if (not Details.Survey.GetTargetCharacterForRealm()) then + Details:Msg("No survey at the moment.") + return + end + if (not DetailsSpellCategoryFrame) then DetailsSpellCategoryFrame = DetailsFramework:CreateSimplePanel(UIParent) local detailsSpellCategoryFrame = DetailsSpellCategoryFrame - detailsSpellCategoryFrame:SetSize(scroll_width, windowHeight) - detailsSpellCategoryFrame:SetTitle("Details Spell Categories") + detailsSpellCategoryFrame:SetSize(scroll_width, windowHeight+26) + detailsSpellCategoryFrame:SetTitle("Identifying and Categorizing Cooldown Spells") detailsSpellCategoryFrame.Data = {} --statusbar local statusBar = CreateFrame("frame", nil, detailsSpellCategoryFrame, "BackdropTemplate") statusBar:SetPoint("bottomleft", detailsSpellCategoryFrame, "bottomleft") statusBar:SetPoint("bottomright", detailsSpellCategoryFrame, "bottomright") - statusBar:SetHeight(20) + statusBar:SetHeight(26) statusBar:SetAlpha (0.8) DF:ApplyStandardBackdrop(statusBar) + --statusbar of the statusbar + local statusBar2 = CreateFrame("frame", nil, statusBar, "BackdropTemplate") + statusBar2:SetPoint("topleft", statusBar, "bottomleft") + statusBar2:SetPoint("topright", statusBar, "bottomright") + statusBar2:SetHeight(20) + statusBar2:SetAlpha (0.8) + DF:ApplyStandardBackdrop(statusBar2) + DF:ApplyStandardBackdrop(statusBar2) + local dataInfoLabel = DF:CreateLabel(statusBar2, "This cooldown data is send to people on Details! team and shared in 'Open Raid' library where any weakaura or addon can use it", 12, "silver") + dataInfoLabel:SetPoint("center", 0, 0) + dataInfoLabel.justifyH = "center" + --create the header local headerTable = { {text = "Icon", width = 24}, - {text = "Spell Name", width = 100}, - {text = "NONE", width = 120}, - {text = "Offensive CD", width = 120}, + {text = "Spell Name", width = 140}, + {text = "NONE", width = 70}, + {text = "Offensive CD", width = 100}, {text = "Personal Defensive CD", width = 120}, {text = "Targeted Defensive CD", width = 120}, {text = "Raid Defensive CD", width = 120}, - {text = "Raid Utility CD", width = 120}, - {text = "Interrupt", width = 120}, - {text = "Dispel", width = 120}, - {text = "CC", width = 120}, + {text = "Raid Utility CD", width = 100}, + {text = "Interrupt", width = 70}, + {text = "Dispel", width = 50}, + {text = "CC", width = 50}, } local headerOptions = { padding = 2, } - local savedSpellsCategories = Details.spell_category_savedtable - local unitClass = select(2, UnitClass("player")) - local thisClassSavedTable = savedSpellsCategories[unitClass] - if (not thisClassSavedTable) then - thisClassSavedTable = {} - savedSpellsCategories[unitClass] = thisClassSavedTable + local maxLineWidth = 20 + for headerIndex, headerSettings in pairs(headerTable) do + maxLineWidth = maxLineWidth + headerSettings.width end + detailsSpellCategoryFrame:SetWidth(maxLineWidth + 20) + + local thisClassSavedTable = Details.Survey.GetCategorySpellListForClass() + local sendButton = DetailsFramework:CreateButton(statusBar, function() Details.Survey.SendSpellCatogeryDataToTargetCharacter(); DetailsSpellCategoryFrame:Hide() end, 800, 20, "SAVE and SEND") + sendButton:SetPoint("center", statusBar, "center", 0, 0) + detailsSpellCategoryFrame.Header = DetailsFramework:CreateHeader(detailsSpellCategoryFrame, headerTable, headerOptions) detailsSpellCategoryFrame.Header:SetPoint("topleft", detailsSpellCategoryFrame, "topleft", startX, headerY) + local tooltipDesc = {} + tooltipDesc[2] = "|cffffff00" .. headerTable[4].text .. "|r|n" .. "Examples:\nPower Infusion, Ice Veins, Combustion, Adrenaline Rush" --ofensive cooldowns + tooltipDesc[3] = "|cffffff00" .. headerTable[5].text .. "|r|n" .. "Examples:\nIce Block, Dispersion, Cloak of Shadows, Shield Wall " --personal cooldowns + tooltipDesc[4] = "|cffffff00" .. headerTable[6].text .. "|r|n" .. "Examples:\nBlessing of Sacrifice, Ironbark, Life Cocoon, Pain Suppression" --targetted devense cooldowns + tooltipDesc[5] = "|cffffff00" .. headerTable[7].text .. "|r|n" .. "Examples:\nPower Word: Barrier, Spirit Link Totem, Tranquility, Anti-Magic Zone" --raid wide cooldowns + tooltipDesc[6] = "|cffffff00" .. headerTable[8].text .. "|r|n" .. "Examples:\nStampeding Roar, Leap of Faith" + tooltipDesc[7] = "" + tooltipDesc[8] = "" + tooltipDesc[9] = "" + --create the scroll bar local scrollRefreshFunc = function(self, data, offset, totalLines) for i = 1, totalLines do @@ -74,46 +197,79 @@ function Details.OpenSpellCategoryScreen() if (spellTable) then local spellId = spellTable[1] - --get a line local line = self:GetLine(i) - local spellName, _, spellIcon = GetSpellInfo(spellId) - print(spellName, spellId) - line.Icon:SetTexture(spellIcon) line.Icon:SetTexCoord(.1, .9, .1, .9) line.SpellNameText.text = spellName local radioGroup = line.RadioGroup + line.spellId = spellId + local hasOptionSelected = false local radioGroupOptions = {} for o in ipairs({"", "", "", "", "", "", "", "", ""}) do + hasOptionSelected = spellTable[2] ~= 1 radioGroupOptions[o] = { name = "", param = o, get = function() return spellTable[2] == o end, - callback = function(param, optionId) spellTable[2] = param end, + callback = function(param, optionId) spellTable[2] = param; thisClassSavedTable[spellId] = param; Details.spell_category_latest_save = time() end, } end radioGroup:SetOptions(radioGroupOptions) + + if (hasOptionSelected) then + line.hasDataBackground:Show() + else + line.hasDataBackground:Hide() + end + local children = {radioGroup:GetChildren()} + local currentWidth = headerTable[1].width + headerTable[2].width for childId, childrenFrame in ipairs(children) do childrenFrame:ClearAllPoints() - childrenFrame:SetPoint("left", line, "left", 126 + ((childId-1) * 122), 0) + childrenFrame:SetPoint("left", line, "left", currentWidth, 0) + + if (not childrenFrame.haveTooltipAlready and childId > 1) then + if (tooltipDesc[childId] and tooltipDesc[childId] ~= "") then + childrenFrame:SetScript("OnEnter", function() + GameCooltip:Preset(2) + GameCooltip:AddLine(tooltipDesc[childId]) + GameCooltip:SetOwner(childrenFrame) + GameCooltip:Show() + GameCooltipFrame1:ClearAllPoints() + GameCooltipFrame1:SetPoint("bottomright", line, "bottomleft", -2, 0) + end) + childrenFrame:SetScript("OnLeave", function() + GameCooltip:Hide() + end) + childrenFrame.haveTooltipAlready = true + end + end + + currentWidth = currentWidth + headerTable[childId+2].width + 3 end end end end - local lineOnEnter = function (self) + local lineOnEnter = function(self) self:SetBackdropColor(unpack(backdrop_color_on_enter)) + if (self.spellId) then + GameTooltip:SetOwner(self, "ANCHOR_NONE") + GameTooltip:SetPoint("bottomright", self, "bottomleft", -2, 0) + GameTooltip:SetSpellByID(self.spellId) + GameTooltip:Show() + end end local lineOnLeave = function(self) self:SetBackdropColor(unpack(self.backdropColor)) + GameTooltip:Hide() end - local spellScroll = DF:CreateScrollBox(detailsSpellCategoryFrame, "$parentSpellScroll", scrollRefreshFunc, detailsSpellCategoryFrame.Data, scroll_width - 10, windowHeight - 58, scrollLines, scrollLineHeight) + local spellScroll = DF:CreateScrollBox(detailsSpellCategoryFrame, "$parentSpellScroll", scrollRefreshFunc, detailsSpellCategoryFrame.Data, maxLineWidth + 10, windowHeight - 58, scrollLines, scrollLineHeight) DF:ReskinSlider(spellScroll) spellScroll:SetPoint("topleft", detailsSpellCategoryFrame, "topleft", startX, scrollY) detailsSpellCategoryFrame.SpellScroll = spellScroll @@ -123,9 +279,15 @@ function Details.OpenSpellCategoryScreen() DF:Mixin(line, DF.HeaderFunctions) line:SetPoint("topleft", self, "topleft", 1, -((lineId-1) * (scrollLineHeight+1)) - 1) - line:SetSize(scroll_width - 2, scrollLineHeight) - line:SetScript ("OnEnter", lineOnEnter) - line:SetScript ("OnLeave", lineOnLeave) + line:SetSize(maxLineWidth, scrollLineHeight) + line:SetScript("OnEnter", lineOnEnter) + line:SetScript("OnLeave", lineOnLeave) + + local background = line:CreateTexture(nil, "background") + background:SetAllPoints() + background:SetColorTexture(1, 1, 1, 0.08) + line.hasDataBackground = background + background:Hide() line:SetBackdrop(backdrop) if (lineId % 2 == 0) then @@ -144,7 +306,8 @@ function Details.OpenSpellCategoryScreen() local spellNameText = DF:CreateLabel(line) --create radio buttons - local radioGroup = DF:CreateRadioGroup(line, {}, "$parentRadioGroup1", {width = scroll_width, height = 20}, {offset_x = 0, amount_per_line = 7}) + --164 is the with of the first two headers (icon and spell name) + local radioGroup = DF:CreateRadioGroup(line, {}, "$parentRadioGroup1", {width = maxLineWidth - 164, height = 20}, {offset_x = 0, amount_per_line = 7}) line:AddFrameToHeaderAlignment(icon) line:AddFrameToHeaderAlignment(spellNameText) @@ -163,73 +326,12 @@ function Details.OpenSpellCategoryScreen() spellScroll:CreateLine(scrollCreateline) end - function detailsSpellCategoryFrame.GetSpellBookSpells() - local spellIdsInSpellBook = {} - - for i = 1, GetNumSpellTabs() do - local tabName, tabTexture, offset, numSpells, isGuild, offspecId = GetSpellTabInfo(i) - - if (offspecId == 0 and tabTexture ~= 136830) then --don't add spells found in the General tab - offset = offset + 1 - local tabEnd = offset + numSpells - - for j = offset, tabEnd - 1 do - local spellType, spellId = GetSpellBookItemInfo(j, "player") - - if (spellId) then - if (spellType ~= "FLYOUT") then - local spellName = GetSpellInfo(spellId) - if (spellName) then - GameTooltip:SetOwner(UIParent, "ANCHOR_TOPLEFT") - GameTooltip:SetSpellByID(spellId) - - local spellIsPassive = false - local spellHasCooldown = false - - for sideName in pairs({Left = true, Right = true}) do - for fontStringIndex = 1, 3 do - local tooltipFontString = _G["GameTooltipText" .. sideName .. fontStringIndex] - if (tooltipFontString) then - local text = tooltipFontString:GetText() - if (text) then - if (text == "Passive") then - spellIsPassive = true - - elseif (text:find("cooldown")) then - spellHasCooldown = true - end - end - end - end - end - - if (not spellIsPassive and spellHasCooldown) then -- - spellIdsInSpellBook[#spellIdsInSpellBook+1] = {spellId, 0} - end - end - else - local _, _, numSlots, isKnown = GetFlyoutInfo(spellId) - if (isKnown and numSlots > 0) then - for k = 1, numSlots do - local spellID, overrideSpellID, isKnown = GetFlyoutSlotInfo(spellId, k) - if (isKnown) then - local spellName = GetSpellInfo(spellID) - --spellIdsInSpellBook[#spellIdsInSpellBook+1] = spellID - end - end - end - end - end - end - end - end - - return spellIdsInSpellBook - end - function spellScroll:RefreshScroll() --create a list of spells from the spell book - local indexedSpells = detailsSpellCategoryFrame.GetSpellBookSpells() + local indexedSpells = {} + for spellId, result in pairs(thisClassSavedTable) do + indexedSpells[#indexedSpells+1] = {spellId, result == true and 1 or result} + end spellScroll:SetData(indexedSpells) spellScroll:Refresh() end diff --git a/functions/classes.lua b/functions/classes.lua index 6298eb4f..93852f90 100644 --- a/functions/classes.lua +++ b/functions/classes.lua @@ -115,6 +115,12 @@ do function _detalhes:GetDisplayName (actor) return self.displayName or actor and actor.displayName end + + function Details:SetDisplayName(actor, newDisplayName) + local thisActor = self.displayName and self or actor + thisActor.displayName = newDisplayName + end + function _detalhes:GetOnlyName (string) if (string) then return string:gsub (("%-.*"), "") diff --git a/functions/profiles.lua b/functions/profiles.lua index 43a9357f..830b6d8d 100644 --- a/functions/profiles.lua +++ b/functions/profiles.lua @@ -1302,6 +1302,9 @@ local default_global_data = { --> spell category feedback spell_category_savedtable = {}, + spell_category_latest_query = 0, + spell_category_latest_save = 0, + spell_category_latest_sent = 0, --> class time played class_time_played = {}, diff --git a/functions/slash.lua b/functions/slash.lua index 28363ed9..414c2e02 100644 --- a/functions/slash.lua +++ b/functions/slash.lua @@ -1569,6 +1569,9 @@ function SlashCmdList.DETAILS (msg, editbox) elseif (msg == "generatespelllist") then Details.GenerateSpecSpellList() + elseif (msg == "survey") then + Details.Survey.OpenSurveyPanel() + elseif (msg == "share") then local f = {} diff --git a/startup.lua b/startup.lua index f6b60e7c..75bb8247 100644 --- a/startup.lua +++ b/startup.lua @@ -127,51 +127,47 @@ function Details:StartMeUp() --I'll never stop! self:RefreshMainWindow(-1, true) Details:RefreshUpdater() - for index = 1, #self.tabela_instancias do - local instance = self.tabela_instancias[index] - if (instance:IsAtiva()) then + for id = 1, Details:GetNumInstances() do + local instance = Details:GetInstance(id) + if (instance:IsEnabled()) then Details.Schedules.NewTimer(1, Details.RefreshBars, Details, instance) Details.Schedules.NewTimer(1, Details.InstanceReset, Details, instance) Details.Schedules.NewTimer(1, Details.InstanceRefreshRows, Details, instance) - - --self:ScheduleTimer("RefreshBars", 1, instance) - --self:ScheduleTimer("InstanceReset", 1, instance) - --self: ("InstanceRefreshRows", 1, instance) end end function self:RefreshAfterStartup() - --repair nicknames + --repair nicknames as nicknames aren't saved within the actor when leaving the game if (not Details.ignore_nicktag) then local currentCombat = Details:GetCurrentCombat() local containerDamage = currentCombat:GetContainer(DETAILS_ATTRIBUTE_DAMAGE) for _, actorObject in containerDamage:ListActors() do --get the actor nickname local nickname = Details:GetNickname(actorObject:Name(), false, true) - if (nickname) then - actorObject.displayName = nickname + if (nickname and type(nickname) == "string" and nickname:len() >= 2) then + actorObject:SetDisplayName(nickname) end end end - self:RefreshMainWindow(-1, true) + local refreshAllInstances = -1 + local forceRefresh = true + self:RefreshMainWindow(refreshAllInstances, forceRefresh) + local lowerInstance = Details:GetLowerInstanceNumber() - local lower_instance = Details:GetLowerInstanceNumber() - - for index = 1, #self.tabela_instancias do - local instance = self.tabela_instancias [index] - if(instance:IsAtiva()) then + for id = 1, Details:GetNumInstances() do + local instance = Details:GetInstance(id) + if (instance:IsEnabled()) then --refresh wallpaper - if(instance.wallpaper.enabled) then + if (instance.wallpaper.enabled) then instance:InstanceWallpaper(true) else instance:InstanceWallpaper(false) end - --refresh desaturated icons if is lower instance - if(index == lower_instance) then + --refresh desaturated icons if is lower instance because plugins shall have installed their icons at this point + if (id == lowerInstance) then instance:DesaturateMenu() - instance:SetAutoHideMenu(nil, nil, true) end end @@ -181,9 +177,9 @@ function Details:StartMeUp() --I'll never stop! Details.ToolBar:ReorganizeIcons() --refresh skin for other windows - if (lower_instance) then - for i = lower_instance+1, #self.tabela_instancias do - local instance = self:GetInstance(i) + if (lowerInstance) then + for id = lowerInstance+1, Details:GetNumInstances() do + local instance = Details:GetInstance(id) if (instance and instance.baseframe and instance.ativa) then instance:ChangeSkin() end @@ -195,77 +191,73 @@ function Details:StartMeUp() --I'll never stop! function Details:CheckWallpaperAfterStartup() if (not Details.profile_loaded) then Details.Schedules.NewTimer(5, Details.CheckWallpaperAfterStartup, Details) - --return Details:ScheduleTimer ("CheckWallpaperAfterStartup", 2) end - for i = 1, self.instances_amount do - local instance = self:GetInstance (i) + for id = 1, self.instances_amount do + local instance = self:GetInstance(id) if (instance and instance:IsEnabled()) then if (not instance.wallpaper.enabled) then - instance:InstanceWallpaper (false) + instance:InstanceWallpaper(false) end instance.do_not_snap = true - self.move_janela_func (instance.baseframe, true, instance, true) - self.move_janela_func (instance.baseframe, false, instance, true) + self.move_janela_func(instance.baseframe, true, instance, true) + self.move_janela_func(instance.baseframe, false, instance, true) instance.do_not_snap = false end end + self.CheckWallpaperAfterStartup = nil Details.profile_loaded = nil end - --Details:ScheduleTimer ("CheckWallpaperAfterStartup", 5) Details.Schedules.NewTimer(5, Details.CheckWallpaperAfterStartup, Details) end - --self:ScheduleTimer ("RefreshAfterStartup", 5) Details.Schedules.NewTimer(5, Details.RefreshAfterStartup, Details) --start garbage collector self.ultima_coleta = 0 self.intervalo_coleta = 720 self.intervalo_memoria = 180 - --self.garbagecollect = self:ScheduleRepeatingTimer ("IniciarColetaDeLixo", self.intervalo_coleta) --deprecated self.garbagecollect = Details.Schedules.NewTicker(self.intervalo_coleta, Details.IniciarColetaDeLixo, Details) - self.next_memory_check = _G.time()+self.intervalo_memoria + self.next_memory_check = _G.time() + self.intervalo_memoria --player role - self.last_assigned_role = UnitGroupRolesAssigned ("player") - + self.last_assigned_role = UnitGroupRolesAssigned and UnitGroupRolesAssigned("player") + --> start parser - --> load parser capture options self:CaptureRefresh() --> register parser events - self.listener:RegisterEvent ("PLAYER_REGEN_DISABLED") - self.listener:RegisterEvent ("PLAYER_REGEN_ENABLED") - self.listener:RegisterEvent ("UNIT_PET") + self.listener:RegisterEvent("PLAYER_REGEN_DISABLED") + self.listener:RegisterEvent("PLAYER_REGEN_ENABLED") + self.listener:RegisterEvent("UNIT_PET") - self.listener:RegisterEvent ("GROUP_ROSTER_UPDATE") - self.listener:RegisterEvent ("INSTANCE_ENCOUNTER_ENGAGE_UNIT") - - self.listener:RegisterEvent ("ZONE_CHANGED_NEW_AREA") - self.listener:RegisterEvent ("PLAYER_ENTERING_WORLD") - - self.listener:RegisterEvent ("ENCOUNTER_START") - self.listener:RegisterEvent ("ENCOUNTER_END") - - self.listener:RegisterEvent ("START_TIMER") - self.listener:RegisterEvent ("UNIT_NAME_UPDATE") + self.listener:RegisterEvent("GROUP_ROSTER_UPDATE") + self.listener:RegisterEvent("INSTANCE_ENCOUNTER_ENGAGE_UNIT") - self.listener:RegisterEvent ("PLAYER_ROLES_ASSIGNED") - self.listener:RegisterEvent ("ROLE_CHANGED_INFORM") - - self.listener:RegisterEvent ("UNIT_FACTION") + self.listener:RegisterEvent("ZONE_CHANGED_NEW_AREA") + self.listener:RegisterEvent("PLAYER_ENTERING_WORLD") - if (not _G.DetailsFramework.IsTimewalkWoW()) then - self.listener:RegisterEvent ("PET_BATTLE_OPENING_START") - self.listener:RegisterEvent ("PET_BATTLE_CLOSE") - self.listener:RegisterEvent ("PLAYER_SPECIALIZATION_CHANGED") - self.listener:RegisterEvent ("PLAYER_TALENT_UPDATE") - self.listener:RegisterEvent ("CHALLENGE_MODE_START") - self.listener:RegisterEvent ("CHALLENGE_MODE_COMPLETED") + self.listener:RegisterEvent("ENCOUNTER_START") + self.listener:RegisterEvent("ENCOUNTER_END") + + self.listener:RegisterEvent("START_TIMER") + self.listener:RegisterEvent("UNIT_NAME_UPDATE") + + self.listener:RegisterEvent("PLAYER_ROLES_ASSIGNED") + self.listener:RegisterEvent("ROLE_CHANGED_INFORM") + + self.listener:RegisterEvent("UNIT_FACTION") + + if (not DetailsFramework.IsTimewalkWoW()) then + self.listener:RegisterEvent("PET_BATTLE_OPENING_START") + self.listener:RegisterEvent("PET_BATTLE_CLOSE") + self.listener:RegisterEvent("PLAYER_SPECIALIZATION_CHANGED") + self.listener:RegisterEvent("PLAYER_TALENT_UPDATE") + self.listener:RegisterEvent("CHALLENGE_MODE_START") + self.listener:RegisterEvent("CHALLENGE_MODE_COMPLETED") end self.parser_frame:RegisterEvent ("COMBAT_LOG_EVENT_UNFILTERED") @@ -281,37 +273,34 @@ function Details:StartMeUp() --I'll never stop! Details:SchedulePetUpdate(1) --send messages gathered on initialization - --self:ScheduleTimer ("ShowDelayMsg", 10) Details.Schedules.NewTimer(10, Details.ShowDelayMsg, Details) --send instance open signal - for index, instancia in Details:ListInstances() do + for id, instancia in Details:ListInstances() do if (instancia.ativa) then - self:SendEvent ("DETAILS_INSTANCE_OPEN", nil, instancia) + self:SendEvent("DETAILS_INSTANCE_OPEN", nil, instancia) end end --send details startup done signal function self:AnnounceStartup() - self:SendEvent ("DETAILS_STARTED", "SEND_TO_ALL") + self:SendEvent("DETAILS_STARTED", "SEND_TO_ALL") if (Details.in_group) then - Details:SendEvent ("GROUP_ONENTER") + Details:SendEvent("GROUP_ONENTER") else - Details:SendEvent ("GROUP_ONLEAVE") + Details:SendEvent("GROUP_ONLEAVE") end Details.last_zone_type = "INIT" Details.parser_functions:ZONE_CHANGED_NEW_AREA() - Details.AnnounceStartup = nil end - --self:ScheduleTimer ("AnnounceStartup", 5) Details.Schedules.NewTimer(5, Details.AnnounceStartup, Details) if (Details.failed_to_load) then - Details:CancelTimer (Details.failed_to_load) + Details.failed_to_load:Cancel() Details.failed_to_load = nil end @@ -328,7 +317,7 @@ function Details:StartMeUp() --I'll never stop! Details:CheckVersion(true) --restore cooltip anchor position, this is for the custom anchor in the screen - _G.DetailsTooltipAnchor:Restore() + DetailsTooltipAnchor:Restore() --check is this is the first run if (self.is_first_run) then @@ -340,11 +329,11 @@ function Details:StartMeUp() --I'll never stop! --check is this is the first run of this version if (self.is_version_first_run) then - local lower_instance = Details:GetLowerInstanceNumber() - if (lower_instance) then - lower_instance = Details:GetInstance (lower_instance) + local lowerInstanceId = Details:GetLowerInstanceIdNumber() + if (lowerInstanceId) then + lowerInstanceId = Details:GetInstance(lowerInstanceId) - if (lower_instance) then + if (lowerInstanceId) then --check if there's changes in the size of the news string if (Details.last_changelog_size < #Loc["STRING_VERSION_LOG"]) then Details.last_changelog_size = #Loc["STRING_VERSION_LOG"] @@ -355,10 +344,10 @@ function Details:StartMeUp() --I'll never stop! end) end - if (lower_instance) then - _G.C_Timer.After(10, function() - if (lower_instance:IsEnabled()) then - lower_instance:InstanceAlert(Loc ["STRING_VERSION_UPDATE"], {[[Interface\GossipFrame\AvailableQuestIcon]], 16, 16, false}, 60, {Details.OpenNewsWindow}, true) + if (lowerInstanceId) then + C_Timer.After(10, function() + if (lowerInstanceId:IsEnabled()) then + lowerInstanceId:InstanceAlert(Loc ["STRING_VERSION_UPDATE"], {[[Interface\GossipFrame\AvailableQuestIcon]], 16, 16, false}, 60, {Details.OpenNewsWindow}, true) Details:Msg("A new version has been installed: /details news") --localize-me end end) @@ -371,37 +360,37 @@ function Details:StartMeUp() --I'll never stop! Details:AddDefaultCustomDisplays() end - local lower = Details:GetLowerInstanceNumber() - if (lower) then - local instance = Details:GetInstance (lower) + local lowerInstanceId = Details:GetLowerInstanceNumber() + if (lowerInstanceId) then + local instance = Details:GetInstance(lowerInstanceId) if (instance) then --in development - local dev_icon = instance.bgdisplay:CreateTexture (nil, "overlay") - dev_icon:SetWidth (40) - dev_icon:SetHeight (40) - dev_icon:SetPoint ("bottomleft", instance.baseframe, "bottomleft", 4, 8) - dev_icon:SetAlpha (.3) + local devIcon = instance.bgdisplay:CreateTexture(nil, "overlay") + devIcon:SetWidth(40) + devIcon:SetHeight(40) + devIcon:SetPoint("bottomleft", instance.baseframe, "bottomleft", 4, 8) + devIcon:SetAlpha(.3) - local dev_text = instance.bgdisplay:CreateFontString (nil, "overlay", "GameFontHighlightSmall") - dev_text:SetHeight (64) - dev_text:SetPoint ("left", dev_icon, "right", 5, 0) - dev_text:SetTextColor (1, 1, 1) - dev_text:SetAlpha (.3) + local devText = instance.bgdisplay:CreateFontString(nil, "overlay", "GameFontHighlightSmall") + devText:SetHeight(64) + devText:SetPoint("left", devIcon, "right", 5, 0) + devText:SetTextColor(1, 1, 1) + devText:SetAlpha(.3) --version - Details.FadeHandler.Fader (instance._version, 0) - instance._version:SetText ("Details! " .. Details.userversion .. " (core " .. self.realversion .. ")") - instance._version:SetTextColor (1, 1, 1, .35) - instance._version:SetPoint ("bottomleft", instance.baseframe, "bottomleft", 5, 1) + Details.FadeHandler.Fader(instance._version, 0) + instance._version:SetText("Details! " .. Details.userversion .. " (core " .. self.realversion .. ")") + instance._version:SetTextColor(1, 1, 1, .35) + instance._version:SetPoint("bottomleft", instance.baseframe, "bottomleft", 5, 1) if (instance.auto_switch_to_old) then instance:SwitchBack() end function Details:FadeStartVersion() - Details.FadeHandler.Fader (dev_icon, "in", 2) - Details.FadeHandler.Fader (dev_text, "in", 2) - Details.FadeHandler.Fader (instance._version, "in", 2) + Details.FadeHandler.Fader(devIcon, "in", 2) + Details.FadeHandler.Fader(devText, "in", 2) + Details.FadeHandler.Fader(instance._version, "in", 2) end Details.Schedules.NewTimer(12, Details.FadeStartVersion, Details) end @@ -413,20 +402,14 @@ function Details:StartMeUp() --I'll never stop! --Details:OpenCustomDisplayWindow() --Details:OpenWelcomeWindow() end - --Details:ScheduleTimer ("OpenOptionsWindowAtStart", 2) Details.Schedules.NewTimer(2, Details.OpenOptionsWindowAtStart, Details) --Details:OpenCustomDisplayWindow() - --> minimap - pcall (Details.RegisterMinimap, Details) + --minimap registration + Details.SafeRun(Details.RegisterMinimap, "Register Minimap Icon", Details) --hot corner addon - function Details:RegisterHotCorner() - Details:DoRegisterHotCorner() - end - --Details:ScheduleTimer ("RegisterHotCorner", 5) - Details.Schedules.NewTimer(5, Details.RegisterHotCorner, Details) - + Details.Schedules.NewTimer(5, function() Details.SafeRun(Details.DoRegisterHotCorner, "Register on Hot Corner Addon", Details) end, Details) --restore mythic dungeon state Details:RestoreState_CurrentMythicDungeonRun() @@ -452,15 +435,15 @@ function Details:StartMeUp() --I'll never stop! Details.Schedules.NewTimer(5, Details.BossModsLink, Details) --limit item level life for 24Hs - local now = _G.time() - for guid, t in pairs(Details.item_level_pool) do - if (t.time + 86400 < now) then - Details.item_level_pool[guid] = nil + local now = time() + for guid, ilevelTable in pairs(Details.ilevel:GetPool()) do + if (ilevelTable.time + 86400 < now) then + Details.ilevel:ClearIlvl(guid) end end --dailly reset of the cache for talents and specs - local today = _G.date("%d") + local today = date("%d") if (Details.last_day ~= today) then wipe(Details.cached_specs) wipe(Details.cached_talents) @@ -479,10 +462,10 @@ function Details:StartMeUp() --I'll never stop! end if (Details.player_details_window.skin ~= "ElvUI") then - local reset_player_detail_window = function() + local setDefaultSkinOnPlayerBreakdownWindow = function() Details:ApplyPDWSkin("ElvUI") end - C_Timer.After(2, reset_player_detail_window) + C_Timer.After(2, setDefaultSkinOnPlayerBreakdownWindow) end --coach feature startup @@ -514,8 +497,11 @@ function Details:StartMeUp() --I'll never stop! Details:InstallHook("HOOK_DEATH", Details.Coach.Client.SendMyDeath) - if (math.random(10) == 1) then + local sentMessageOnStartup = false + + if (math.random(20) == 1) then Details:Msg("use '/details me' macro to open the player breakdown for you!") + sentMessageOnStartup = true end if (not DetailsFramework.IsTimewalkWoW()) then @@ -563,6 +549,15 @@ function Details:StartMeUp() --I'll never stop! if (DetailsFramework.IsDragonflight()) then DetailsFramework.Schedules.NewTimer(5, Details.RegisterDragonFlightEditMode) + --run only on beta, remove on 10.0 launch + if (Details.Survey.GetTargetCharacterForRealm()) then + Details.Survey.InitializeSpellCategoryFeedback() + if (not sentMessageOnStartup) then + if (math.random(10) == 1) then + Details:Msg("use '/details survey' to help on identifying cooldown spells.") + end + end + end end function Details:InstallOkey() @@ -575,12 +570,3 @@ function Details:StartMeUp() --I'll never stop! end Details.AddOnLoadFilesTime = _G.GetTime() - - - - - - - - -