You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

350 lines
16 KiB

4 years ago
local Details = Details
local DetailsFramework = _G.DetailsFramework
local GameCooltip2 = GameCooltip2
function Details:CreateAPI2Frame()
if (not _G.DetailsAPI2Frame or not _G.DetailsAPI2Frame.Initialized) then
--menu settings
_G.DetailsAPI2Frame.Initialized = true
local panelWidth = 800
local panelHeight = 610
local scrollWidth = 200
local scrollHeight = 570
local lineHeight = 20
local lineAmount = 27
local backdropColor = {.2, .2, .2, 0.2}
local backdropColorOnEnter = {.8, .8, .8, 0.4}
local backdropColorSelected = {1, 1, .8, 0.4}
local yStart = -30
local xAnchorPoint = 250
local parametersAmount = 10
local returnAmount = 10
3 years ago
--local Api2Frame = DetailsFramework:CreateSimplePanel(UIParent, panelWidth, panelHeight, "Details! API 2.0", "DetailsAPI2Frame")
4 years ago
local Api2Frame = _G.DetailsAPI2Frame
3 years ago
Api2Frame:SetFrameStrata("FULLSCREEN")
Api2Frame:SetPoint("center")
DetailsFramework:ApplyStandardBackdrop(Api2Frame, false, 1.2)
4 years ago
--store
local apiFunctionNames = {}
local parametersLines = {}
local returnLines = {}
local currentSelected = 1
local api = Details.API_Description.namespaces[1].api
--on select api on the menu
3 years ago
local onSelectAPI = function(self)
4 years ago
local apiName = apiFunctionNames [self.index]
if (not apiName) then
3 years ago
Details:Msg("API name not found:", apiName)
4 years ago
return
end
--fill the box in the right with information about the API
local apiInfo = api [self.index]
if (not apiInfo) then
3 years ago
Details:Msg("API information for api not found", apiName)
4 years ago
return
end
currentSelected = self.index
--update name and desc
Api2Frame.ApiFunctionName.text = apiName
Api2Frame.ApiFunctionDesc.text = apiInfo.desc
--update the copy line text box
local parameters = ""
3 years ago
for parameterIndex, parameterInfo in ipairs(apiInfo.parameters) do
4 years ago
if (parameterInfo.required) then
parameters = parameters .. parameterInfo.name .. ", "
end
end
3 years ago
parameters = parameters:gsub(", $", "")
4 years ago
local returnValues = "local "
3 years ago
for returnIndex, returnInfo in ipairs(apiInfo.returnValues) do
4 years ago
returnValues = returnValues .. returnInfo.name .. ", "
end
3 years ago
returnValues = returnValues:gsub(", $", "")
4 years ago
returnValues = returnValues .. " = "
if (parameters ~= "") then
Api2Frame.ApiCopy.text = returnValues .. "Details." .. apiName .. "( " .. parameters .. " )"
else
Api2Frame.ApiCopy.text = returnValues .. "Details." .. apiName .. "()"
end
3 years ago
Api2Frame.ApiCopy:SetFocus(true)
4 years ago
Api2Frame.ApiCopy:HighlightText()
--parameters
for i = 1, #parametersLines do
local parameterLine = parametersLines [i]
local parameterInfo = apiInfo.parameters [i]
if (parameterInfo) then
parameterLine:Show()
parameterLine.index = i
parameterLine.name.text = parameterInfo.name
parameterLine.typeData.text = parameterInfo.type
parameterLine.required.text = parameterInfo.required and "yes" or "no"
parameterLine.default.text = parameterInfo.default or ""
else
parameterLine:Hide()
end
end
--return values
for i = 1, #returnLines do
local returnLine = returnLines [i]
local returnInfo = apiInfo.returnValues [i]
if (returnInfo) then
returnLine:Show()
returnLine.index = i
returnLine.name.text = returnInfo.name
returnLine.typeData.text = returnInfo.type
returnLine.desc.text = returnInfo.desc
else
returnLine:Hide()
end
end
--refresh the scroll box
Api2Frame.scrollMenu:Refresh()
end
--menu scroll
3 years ago
local apiMenuScrollRefresh = function(self, data, offset, total_lines)
4 years ago
for i = 1, total_lines do
local index = i + offset
local apiName = data [index]
if (apiName) then
local line = self:GetLine (i)
3 years ago
line.text:SetText(apiName)
4 years ago
line.index = index
if (currentSelected == index) then
3 years ago
line:SetBackdropColor(unpack(backdropColorSelected))
4 years ago
else
3 years ago
line:SetBackdropColor(unpack(backdropColor))
4 years ago
end
end
end
end
3 years ago
for apiIndex, apiDesc in ipairs(api) do
table.insert(apiFunctionNames, apiDesc.name)
4 years ago
end
local api2ScrollMenu = DetailsFramework:CreateScrollBox (Api2Frame, "$parentApi2MenuScroll", apiMenuScrollRefresh, apiFunctionNames, scrollWidth, scrollHeight, lineAmount, lineHeight)
3 years ago
DetailsFramework:ReskinSlider(api2ScrollMenu)
api2ScrollMenu:SetPoint("topleft", Api2Frame, "topleft", 10, yStart)
4 years ago
Api2Frame.scrollMenu = api2ScrollMenu
3 years ago
local lineOnEnter = function(self)
self:SetBackdropColor(unpack(backdropColorOnEnter))
4 years ago
local apiName = apiFunctionNames [self.index]
if (not apiName) then
return
end
--fill the box in the right with information about the API
local apiInfo = api [self.index]
if (not apiInfo) then
return
end
GameCooltip2:Preset(2)
3 years ago
GameCooltip2:SetOwner(self, "left", "right", 2, 0)
GameCooltip2:AddLine(apiInfo.desc)
4 years ago
GameCooltip2:ShowCooltip()
end
3 years ago
local lineOnLeave = function(self)
4 years ago
if (currentSelected == self.index) then
3 years ago
self:SetBackdropColor(unpack(backdropColorSelected))
4 years ago
else
3 years ago
self:SetBackdropColor(unpack(backdropColor))
4 years ago
end
GameCooltip2:Hide()
end
--create lines
for i = 1, lineAmount do
3 years ago
api2ScrollMenu:CreateLine (function(self, index)
local line = CreateFrame("button", "$parentLine" .. index, self, "BackdropTemplate")
line:SetPoint("topleft", self, "topleft", 1, -((index-1)*(lineHeight+1)) - 1)
line:SetSize(scrollWidth - 2, lineHeight)
4 years ago
line.index = index
3 years ago
line:SetScript("OnEnter", lineOnEnter)
line:SetScript("OnLeave", lineOnLeave)
4 years ago
3 years ago
line:SetBackdrop({bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true})
line:SetBackdropColor(unpack(backdropColor))
4 years ago
3 years ago
line.text = DetailsFramework:CreateLabel(line)
line.text:SetPoint("left", line, "left", 2, 0)
4 years ago
3 years ago
line:SetScript("OnMouseDown", onSelectAPI)
4 years ago
return line
end)
end
--info box
local infoWidth = panelWidth - xAnchorPoint - 10
--api name
3 years ago
Api2Frame.ApiFunctionName = DetailsFramework:CreateLabel(Api2Frame, "", 14, "orange")
Api2Frame.ApiFunctionName:SetPoint("topleft", Api2Frame, "topleft", xAnchorPoint, yStart)
4 years ago
--api desc
3 years ago
Api2Frame.ApiFunctionDesc = DetailsFramework:CreateLabel(Api2Frame)
Api2Frame.ApiFunctionDesc:SetPoint("topleft", Api2Frame.ApiFunctionName, "bottomleft", 0, -2)
4 years ago
Api2Frame.ApiFunctionDesc.width = infoWidth
Api2Frame.ApiFunctionDesc.height = 22
Api2Frame.ApiFunctionDesc.valign = "top"
--api func to copy
3 years ago
local apiCopyString = DetailsFramework:CreateLabel(Api2Frame, "Copy String", 12, "orange")
apiCopyString:SetPoint("topleft", Api2Frame.ApiFunctionDesc, "bottomleft", 0, -20)
Api2Frame.ApiCopy = DetailsFramework:CreateTextEntry(Api2Frame, function() end, infoWidth, 20)
Api2Frame.ApiCopy:SetPoint("topleft", apiCopyString, "bottomleft", 0, -2)
Api2Frame.ApiCopy:SetTemplate(DetailsFramework:GetTemplate("button", "DETAILS_CUSTOMDISPLAY_CODE_BOX"))
4 years ago
--parameters
local parametersYStart = yStart - 110
3 years ago
local parametersString = DetailsFramework:CreateLabel(Api2Frame, "Parameters", 12, "orange")
parametersString:SetPoint("topleft", Api2Frame, "topleft", xAnchorPoint, parametersYStart)
4 years ago
parametersYStart = parametersYStart - 20
local space1, space2, space3 = 150, 300, 450
3 years ago
local parametersHeader = CreateFrame("frame", nil, Api2Frame, "BackdropTemplate")
parametersHeader:SetSize(infoWidth, 20)
parametersHeader:SetPoint("topleft", Api2Frame, "topleft", xAnchorPoint, parametersYStart)
parametersHeader:SetBackdrop({bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true})
parametersHeader:SetBackdropColor(unpack(backdropColor))
parametersHeader.name = DetailsFramework:CreateLabel(parametersHeader, "Name", 12, "yellow")
parametersHeader.typeData = DetailsFramework:CreateLabel(parametersHeader, "Type", 12, "yellow")
parametersHeader.required = DetailsFramework:CreateLabel(parametersHeader, "Is Required", 12, "yellow")
parametersHeader.default = DetailsFramework:CreateLabel(parametersHeader, "Default Value", 12, "yellow")
parametersHeader.name:SetPoint("left", parametersHeader, "left", 2, 0)
parametersHeader.typeData:SetPoint("left", parametersHeader, "left", space1, 0)
parametersHeader.required:SetPoint("left", parametersHeader, "left", space2, 0)
parametersHeader.default:SetPoint("left", parametersHeader, "left", space3, 0)
4 years ago
3 years ago
local parameterOnEnter = function(self)
4 years ago
GameCooltip2:Preset(2)
3 years ago
GameCooltip2:SetOwner(self)
4 years ago
--fill the box in the right with information about the API
local apiInfo = api [currentSelected]
if (not apiInfo) then
return
end
3 years ago
GameCooltip2:AddLine(apiInfo.parameters [self.index].desc)
4 years ago
GameCooltip2:ShowCooltip()
3 years ago
self:SetBackdropColor(unpack(backdropColorOnEnter))
4 years ago
end
3 years ago
local parameterOnLeave = function(self)
4 years ago
GameCooltip2:Hide()
3 years ago
self:SetBackdropColor(unpack(backdropColor))
4 years ago
end
for i = 1, parametersAmount do
local parameterLine = {}
3 years ago
local f = CreateFrame("frame", nil, Api2Frame, "BackdropTemplate")
f:SetSize(infoWidth, 20)
f:SetScript("OnEnter", parameterOnEnter)
f:SetScript("OnLeave", parameterOnLeave)
f:SetBackdrop({bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true})
f:SetBackdropColor(unpack(backdropColor))
4 years ago
f:Hide()
3 years ago
f.name = DetailsFramework:CreateLabel(f)
f.typeData = DetailsFramework:CreateLabel(f)
f.required = DetailsFramework:CreateLabel(f)
f.default = DetailsFramework:CreateLabel(f)
4 years ago
3 years ago
f:SetPoint("topleft", Api2Frame, "topleft", xAnchorPoint, parametersYStart + (-i * 20))
4 years ago
3 years ago
f.name:SetPoint("left", f, "left", 2, 0)
f.typeData:SetPoint("left", f, "left", space1, 0)
f.required:SetPoint("left", f, "left", space2, 0)
f.default:SetPoint("left", f, "left", space3, 0)
4 years ago
table.insert(parametersLines, f)
4 years ago
end
--return value box
local returnYStart = yStart - 260
3 years ago
local returnString = DetailsFramework:CreateLabel(Api2Frame, "Return Values", 12, "orange")
returnString:SetPoint("topleft", Api2Frame, "topleft", xAnchorPoint, returnYStart)
4 years ago
returnYStart = returnYStart - 20
local space1 = 200
3 years ago
local returnHeader = CreateFrame("frame", nil, Api2Frame, "BackdropTemplate")
returnHeader:SetSize(infoWidth, 20)
returnHeader:SetPoint("topleft", Api2Frame, "topleft", xAnchorPoint, returnYStart)
returnHeader:SetBackdrop({bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true})
returnHeader:SetBackdropColor(unpack(backdropColor))
returnHeader.name = DetailsFramework:CreateLabel(returnHeader, "Name", 12, "yellow")
returnHeader.typeData = DetailsFramework:CreateLabel(returnHeader, "Type", 12, "yellow")
returnHeader.name:SetPoint("left", returnHeader, "left", 2, 0)
returnHeader.typeData:SetPoint("left", returnHeader, "left", space1, 0)
4 years ago
3 years ago
local returnOnEnter = function(self)
self:SetBackdropColor(unpack(backdropColorOnEnter))
4 years ago
end
3 years ago
local returnOnLeave = function(self)
self:SetBackdropColor(unpack(backdropColor))
4 years ago
end
for i = 1, returnAmount do
local parameterLine = {}
3 years ago
local f = CreateFrame("frame", nil, Api2Frame, "BackdropTemplate")
f:SetSize(infoWidth, 20)
f:SetScript("OnEnter", returnOnEnter)
f:SetScript("OnLeave", returnOnLeave)
f:SetBackdrop({bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true})
f:SetBackdropColor(unpack(backdropColor))
4 years ago
f:Hide()
3 years ago
f.name = DetailsFramework:CreateLabel(f)
f.typeData = DetailsFramework:CreateLabel(f)
4 years ago
3 years ago
f.desc = DetailsFramework:CreateLabel(f, "", 10, "gray")
4 years ago
f.desc.width = infoWidth
f.desc.height = 60
f.desc.valign = "top"
3 years ago
f:SetPoint("topleft", Api2Frame, "topleft", xAnchorPoint, returnYStart + (-i * 20))
4 years ago
3 years ago
f.name:SetPoint("left", f, "left", 2, 0)
f.typeData:SetPoint("left", f, "left", space1, 0)
4 years ago
3 years ago
f.desc:SetPoint("topleft", f.name, "bottomleft", 0, -5)
4 years ago
table.insert(returnLines, f)
4 years ago
end
function Api2Frame.Refresh()
onSelectAPI (api2ScrollMenu.Frames [1])
end
end
end