PHP Code:
-- We are going to create a Frame that will support multiple Healing Tables and visually show them...
-- We will try to add in targeting support by clicking the names of the Tagets shown on the Table...
-- We will try and make it look clean and orderly, while looking simplistic in design...
-- Layout for information will be in said order
-- Name | Actual HP% | Weighted HP% | In Range of Heals (for Custom Table)
-- Still debating on Update Time (how frequently to refresh data)
-- Should I allow sorting based on other factors (for the Visual part only, not the healing part)
if not VHT_List or not VHT_Timer or not VHT_FramePool then
VHT_List = { }
VHT_FramePool = { }
VHT_Timer = 0
end
local function UpdateVisualTable(tableName, VHT)
local tableName, VHT = tableName, VHT
local startPoint_X, startPoint_Y = 10, 16
local frameScrollContent = _G['VisualHealingTableScrollContent']
-- Name Font String Setup
for i=1, #VHT do
local TestName = VHT[i].name
TestName:SetFontObject("GameTooltipText")
TestName:ClearAllPoints()
TestName:SetText(GetUnitName(tableName[i].Unit, true))
TestName:SetSize(150, 13)
TestName:SetPoint("TOPLEFT", frameScrollContent, "TOPLEFT", 10, - 12 - (14 * i) )
end
-- HP Font String Setup
for i=1, #VHT do
local TestHP = VHT[i].HP
TestHP:SetFontObject("GameTooltipText")
TestHP:ClearAllPoints()
TestHP:SetText(math.floor(tableName[i].HP))
TestHP:SetSize(40, 13)
TestHP:SetTextHeight(12)
TestHP:SetJustifyH("CENTER")
TestHP:SetPoint("LEFT", VHT[i].name, "RIGHT", 4, 0 )
end
_G['VHT_Timer'] = GetTime()
end
local function RemoveFrames()
print("Before Removing, ", #VHT_List)
local VHT_Frame = tremove(VHT_List, #VHT_List)
print("After Removing, ", #VHT_List)
VHT_Frame.name:Hide()
VHT_Frame.HP:Hide()
VHT_Frame.range:Hide()
table.insert(VHT_FramePool, VHT_Frame)
end
local function GetFrames(valueVHT)
local i = valueVHT
if #VHT_FramePool > 0 then
local VHT_Frame = tremove(VHT_FramePool)
local VHT_FrameName, VHT_FrameHP, VHT_FrameRange = VHT_Frame.name, VHT_Frame.HP, VHT_Frame.range
VHT_FrameName:Show()
VHT_FrameHP:Show()
VHT_FrameRange:Show()
table.insert(VHT_List, { name = VHT_FrameName, HP = VHT_FrameHP, range = VHT_FrameRange })
print("Reused Old Frame")
else
local Frame = _G['VisualHealingTableScrollContent']
local VHT_FrameName = Frame:CreateFontString("FontStringName"..tostring(i))
VHT_FrameName:SetFontObject("GameTooltipText")
VHT_FrameName:SetHeight(12)
VHT_FrameName:SetText("Test")
local VHT_FrameHP = Frame:CreateFontString("FontStringHP"..tostring(i))
VHT_FrameHP:SetFontObject("GameTooltipText")
VHT_FrameHP:SetHeight(12)
local VHT_FrameRange = Frame:CreateFontString("FontStringRange"..tostring(i))
VHT_FrameRange:SetFontObject("GameTooltipText")
VHT_FrameRange:SetHeight(12)
table.insert(VHT_List, { name = VHT_FrameName, HP = VHT_FrameHP, range = VHT_FrameRange })
print("Created New Frame")
end
end
local function UpdateFontStrings(tableName)
local VHTDD = _G['VisualHealingTableDropDown'].selectedID
local tableName = tableName[VHTDD]
if #tableName ~= #VHT_List then
if #tableName < #VHT_List then
i = #VHT_List
while #tableName ~= i do
RemoveFrames()
i = i - 1
end
elseif #tableName > #VHT_List then
local i=#VHT_List
while i ~= #tableName do
i = i + 1
GetFrames(i)
end
end
end
UpdateVisualTable(tableName, VHT_List)
end
local function VisualTableFrameSetup(tableNames)
if type(tableNames) ~= table then
local tableNames = { tableNames }
else
local tableNames = tableNames
end
-- Title
local frameTitle = CreateFrame("frame", "VisualHealingTableTitle", UIParent)
frameTitle:ClearAllPoints()
frameTitle:SetSize(150, 27)
frameTitle:SetMovable(true)
frameTitle:EnableMouse(true)
frameTitle:RegisterForDrag("LeftButton")
frameTitle:SetScript("OnDragStart", frameTitle.StartMoving)
frameTitle:SetScript("OnDragStop", frameTitle.StopMovingOrSizing)
frameTitle:SetScript("OnShow", RefreshFrameBoxes)
local TitleString = frameTitle:CreateFontString("TitleString")
TitleString:SetFontObject("GameTooltipText")
TitleString:SetText("Visual Healing Table")
TitleString:SetJustifyH("CENTER")
TitleString:SetJustifyV("CENTER")
TitleString:ClearAllPoints()
TitleString:SetPoint("TOPLEFT", VisualHealingTableTitle, "TOPLEFT")
TitleString:SetPoint("BOTTOMRIGHT", VisualHealingTableTitle, "BOTTOMRIGHT")
frameTitle:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background",
edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 }});
frameTitle:SetBackdropColor(0,0,0,1);
frameTitle:SetPoint("CENTER", -300, 100)
frameTitle:Show()
-- Main Frame that we shall link everything to
local frameMain = CreateFrame("frame", "VisualHealingTable", VisualHealingTableTitle)
frameMain:ClearAllPoints()
frameMain:SetSize(320, 140)
frameMain:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background",
edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 }});
frameMain:SetBackdropColor(0,0,0,1);
frameMain:SetPoint("TOP", VisualHealingTableTitle, "BOTTOM", 0, -2)
frameMain:Show()
-- Close/Hide Button
local frameClose = CreateFrame('Button', 'frameClose', frameMain, "UIPanelButtonTemplate")
frameClose:ClearAllPoints()
frameClose:SetPoint("BOTTOMRIGHT", frameMain, "TOPRIGHT", 20, 4)
frameClose:RegisterForClicks("LeftButtonDown")
frameClose:SetSize(20, 20)
local closeText = frameClose:CreateFontString("closeText")
closeText:SetFontObject("GameTooltipTextSmall")
closeText:SetText("|cFFFFFAFA X|cffffffff")
closeText:ClearAllPoints()
closeText:SetAllPoints(frameClose)
closeText:SetJustifyH("CENTER")
closeText:SetJustifyV("CENTER")
frameClose:SetScript('OnClick', function() frameTitle:Hide() end )
frameClose:SetBackdrop({
--bgFile = "Interface/Tooltips/UI-Tooltip-Background",
edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
tile = false, tileSize = 12, edgeSize = 12,
insets = { left = 6, right = 6, top = 6, bottom = 6 }
})
frameClose:Show()
-- DropDownMenu
local frameDropDown = CreateFrame("Button", "VisualHealingTableDropDown", VisualHealingTableTitle, "UIDropDownMenuTemplate")
frameDropDown:ClearAllPoints()
frameDropDown:SetPoint("TOPLEFT", frameMain, "TOPLEFT", -2, -3)
frameDropDown:Show()
local function OnClick(self)
UIDropDownMenu_SetSelectedID(frameDropDown, self:GetID())
end
local function initialize(self, level)
local info = UIDropDownMenu_CreateInfo()
for i=1, #tableNames do
info = UIDropDownMenu_CreateInfo()
info.text = "Table "..tostring(i)
info.func = OnClick
UIDropDownMenu_AddButton(info, level)
end
end
UIDropDownMenu_Initialize(frameDropDown, initialize)
UIDropDownMenu_SetWidth(frameDropDown, 100);
UIDropDownMenu_SetButtonWidth(frameDropDown, 124)
UIDropDownMenu_SetSelectedID(frameDropDown, 1)
UIDropDownMenu_JustifyText(frameDropDown, "LEFT")
-- Scroll Frame Creation (Scary!!!!)
local frameScroll = CreateFrame("ScrollFrame", "VisualHealingTableScroll", VisualHealingTable)
frameScroll:SetPoint("TOPLEFT", 10, -30)
frameScroll:SetPoint("BOTTOMRIGHT", -10, 10)
frameScroll:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background",
edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
tile = true, tileSize = 8, edgeSize = 8,
insets = { left = 4, right = 4, top = 4, bottom = 4 }});
frameScroll:SetBackdropColor(0,0,0,.8);
frameMain.frameScroll = frameScroll
--scrollbar
local frameScrollBar = CreateFrame("Slider", "VisualHealingTableScrollBar", frameScroll, "UIPanelScrollBarTemplate")
frameScrollBar:SetPoint("TOPLEFT", frameMain, "TOPRIGHT", 4, -16)
frameScrollBar:SetPoint("BOTTOMLEFT", frameMain, "BOTTOMRIGHT", 4, 16)
frameScrollBar:SetMinMaxValues(1, 200)
frameScrollBar:SetValueStep(1)
frameScrollBar.scrollStep = 1
frameScrollBar:SetValue(0)
frameScrollBar:SetWidth(16)
frameScrollBar:SetScript("OnValueChanged",
function (self, value)
self:GetParent():SetVerticalScroll(value)
end)
local scrollbg = frameScrollBar:CreateTexture(nil, "BACKGROUND")
scrollbg:SetAllPoints(frameScrollBar)
scrollbg:SetTexture(0, 0, 0, 0.4)
frameMain.frameScrollBar = frameScrollBar
-- Content Frame
local frameScrollContent = CreateFrame("frame", "VisualHealingTableScrollContent", frameScroll)
frameScrollContent:ClearAllPoints()
frameScrollContent:SetWidth(300)
frameScrollContent:SetHeight(30)
frameScroll:SetScrollChild(frameScrollContent)
local NameTitle = frameScrollContent:CreateFontString("NameTitle")
NameTitle:SetFontObject("GameTooltipText")
NameTitle:SetSize(150, 13)
NameTitle:SetTextHeight(13)
NameTitle:SetJustifyV("CENTER")
NameTitle:SetJustifyH("CENTER")
NameTitle:SetTextColor(1, 1, 0, 1)
NameTitle:SetText("Name")
NameTitle:SetPoint("TOPLEFT", frameScrollContent, "TOPLEFT", 10, -2)
local HPTitle = frameScrollContent:CreateFontString("HPTitle")
HPTitle:SetFontObject("GameTooltipText")
HPTitle:SetSize(40, 13)
HPTitle:SetTextHeight(13)
HPTitle:SetJustifyV("CENTER")
HPTitle:SetJustifyH("CENTER")
HPTitle:SetTextColor(1, 1, 0, 1)
HPTitle:SetText("HP %")
HPTitle:SetPoint("LEFT", NameTitle, "RIGHT", 4, 0)
local RangeTitle = frameScrollContent:CreateFontString("RangeTitle")
RangeTitle:SetFontObject("GameTooltipText")
RangeTitle:SetSize(50, 13)
RangeTitle:SetTextHeight(13)
RangeTitle:SetJustifyV("CENTER")
RangeTitle:SetJustifyH("CENTER")
RangeTitle:SetTextColor(1, 1, 0, 1)
RangeTitle:SetText("Range")
RangeTitle:SetPoint("LEFT", HPTitle, "RIGHT", 4, 0)
local line1 = frameScrollContent:CreateTexture()
line1:ClearAllPoints()
line1:SetHeight(1)
line1:SetTexture(.9, .9, 0, .8)
line1:SetPoint("TOPLEFT", NameTitle, "BOTTOMLEFT", 0, -2)
line1:SetPoint("TOPRIGHT", RangeTitle, "BOTTOMRIGHT", 0, -2)
local line2 = frameScrollContent:CreateTexture()
line2:ClearAllPoints()
line2:SetWidth(1)
line2:SetHeight(13)
line2:SetTexture(.9, .9, 0, .8)
line2:SetPoint("LEFT", NameTitle, "RIGHT", 0, 0)
local line3 = frameScrollContent:CreateTexture()
line3:ClearAllPoints()
line3:SetWidth(1)
line3:SetHeight(13)
line3:SetTexture(.9, .9, 0, .8)
line3:SetPoint("RIGHT", RangeTitle, "LEFT", 0, 0)
UpdateFontStrings(tableNames)
_G["FrameSetup"] = true
end
if not _G['FrameSetup'] then
VisualTableFrameSetup(TableCompilation)
end
if GetTime() - _G['VHT_Timer'] >= 0.5 and _G['VisualHealingTableTitle']:IsVisible() then
UpdateFontStrings(TableCompilation)
end