This commit is contained in:
DuvelCorp
2026-03-31 21:25:35 +02:00
parent 680ddcba8a
commit 51d4c785fa
55 changed files with 5157 additions and 2530 deletions
+157 -23
View File
@@ -2,13 +2,16 @@ if type(MTH_HUNTERBOOK_TABS) ~= "table" then MTH_HUNTERBOOK_TABS = {} end
MTH_HUNTERBOOK_TABS.families = {
headerLabel = "Families",
columnLabels = { "Family", "Named", "Coords", "Abilities", "Diet" },
columnLabels = { "Family", "Named", "Coords", "Abilities", "Diet", "HP", "dmg", "Arm" },
columnLayout = {
{ x = 10, width = 106, align = "LEFT" },
{ x = 122, width = 52, align = "LEFT" },
{ x = 176, width = 52, align = "LEFT" },
{ x = 232, width = 364, align = "LEFT" },
{ x = 532, width = 112, align = "LEFT" },
{ x = 10, width = 100, align = "LEFT" },
{ x = 114, width = 38, align = "LEFT" },
{ x = 154, width = 38, align = "LEFT" },
{ x = 196, width = 364, align = "LEFT" },
{ x = 496, width = 102, align = "LEFT" },
{ x = 602, width = 30, align = "CENTER" },
{ x = 636, width = 36, align = "CENTER" },
{ x = 674, width = 38, align = "CENTER" },
},
}
@@ -26,6 +29,28 @@ local function MTH_BOOKTAB_FamiliesTrim(value)
return text
end
local function MTH_BOOKTAB_FormatFamilyStat(value)
local numeric = tonumber(value)
if not numeric then
return "-"
end
local colorPrefix = "|cFF4DA6FF"
if numeric < 1 then
colorPrefix = "|cFFFF4040"
elseif numeric > 1 then
colorPrefix = "|cFF40FF40"
end
local text = nil
if MTH_BOOK_STATE and MTH_BOOK_STATE.familyStatsPercent == true then
text = tostring(math.floor((numeric * 100) + 0.5)) .. "%"
return colorPrefix .. text .. "|r"
end
text = string.format("%.3f", numeric)
text = string.gsub(text, "(%..-)0+$", "%1")
text = string.gsub(text, "%.$", "")
return colorPrefix .. text .. "|r"
end
local function MTH_BOOKTAB_ShouldDisplayAllDiet(familyName)
local token = MTH_BOOKTAB_FamiliesSafeLower(MTH_BOOKTAB_FamiliesTrim(familyName))
return token == "bears" or token == "boars"
@@ -51,12 +76,41 @@ end
function MTH_BOOKTAB_BuildFamiliesRows()
local results = {}
local families = MTH_DS_Families
local beasts = MTH_DS_Beasts
if type(families) ~= "table" then
return results
end
local abilityCounts = {}
local canonicalMap = {}
local familyCounts = {}
if type(beasts) == "table" then
for _, beastRow in pairs(beasts) do
if type(beastRow) == "table" then
local familyName = MTH_BOOKTAB_FamiliesTrim(beastRow.family)
if familyName ~= "" then
local counts = familyCounts[familyName]
if not counts then
counts = { named = 0, coords = 0 }
familyCounts[familyName] = counts
end
counts.named = counts.named + 1
if type(beastRow.coords) == "table" then
for coordIndex = 1, table.getn(beastRow.coords) do
local coord = beastRow.coords[coordIndex]
if type(coord) == "table" then
if coord[1] ~= nil and coord[2] ~= nil then
counts.coords = counts.coords + 1
end
end
end
end
end
end
end
end
for _, familyRow in pairs(families) do
if type(familyRow) == "table" and type(familyRow.abilities) == "table" then
@@ -82,6 +136,7 @@ function MTH_BOOKTAB_BuildFamiliesRows()
for familyName, familyRow in pairs(families) do
if type(familyRow) == "table" then
local beastCounts = familyCounts[familyName] or nil
MTH_BOOKTAB_FamiliesTrace("BUILD " .. tostring(familyName) .. " icon=" .. tostring(familyRow.icon))
local abilities = {}
local seen = {}
@@ -171,6 +226,10 @@ function MTH_BOOKTAB_BuildFamiliesRows()
end)
local dietText = ""
local stats = type(familyRow.stats) == "table" and familyRow.stats or nil
local healthStat = stats and tonumber(stats.health) or nil
local damageStat = stats and tonumber(stats.damage) or nil
local armorStat = stats and tonumber(stats.armor) or nil
if MTH_BOOKTAB_ShouldDisplayAllDiet(familyName) then
dietText = "ALL"
else
@@ -178,7 +237,8 @@ function MTH_BOOKTAB_BuildFamiliesRows()
if type(familyRow.food) == "table" then
for i = 1, table.getn(familyRow.food) do
local food = MTH_BOOKTAB_FamiliesTrim(familyRow.food[i])
if food ~= "" then
local token = MTH_BOOKTAB_FamiliesSafeLower(food)
if food ~= "" and token ~= "raw fish" and token ~= "raw meat" then
table.insert(dietItems, string.upper(string.sub(food, 1, 1)) .. string.sub(food, 2))
end
end
@@ -186,16 +246,22 @@ function MTH_BOOKTAB_BuildFamiliesRows()
return MTH_BOOKTAB_FamiliesSafeLower(a) < MTH_BOOKTAB_FamiliesSafeLower(b)
end)
end
dietText = table.concat(dietItems, ", ")
dietText = table.concat(dietItems, "|")
end
table.insert(results, {
family = tostring(familyName),
icon = familyRow.icon or nil,
named = tonumber(familyRow.named) or 0,
coords = tonumber(familyRow.coords) or 0,
named = beastCounts and (tonumber(beastCounts.named) or 0) or 0,
coords = beastCounts and (tonumber(beastCounts.coords) or 0) or 0,
abilities = abilities,
dietText = dietText,
healthStat = healthStat,
healthText = MTH_BOOKTAB_FormatFamilyStat(healthStat),
damageStat = damageStat,
damageText = MTH_BOOKTAB_FormatFamilyStat(damageStat),
armorStat = armorStat,
armorText = MTH_BOOKTAB_FormatFamilyStat(armorStat),
})
end
end
@@ -253,31 +319,76 @@ function MTH_BOOKTAB_EnsureFamiliesUI()
ui.frame:SetPoint("BOTTOMRIGHT", listParent, "BOTTOMRIGHT", -6, 6)
ui.frame:Hide()
local statsText = getglobal("MTH_BOOK_StatsText")
local statsParent = statsText and statsText:GetParent() or nil
if statsParent then
ui.percentCheckbox = CreateFrame("CheckButton", "MTH_BOOK_FamiliesPercentCheckbox", statsParent, "UICheckButtonTemplate")
ui.percentCheckbox:SetFrameStrata(statsParent:GetFrameStrata())
ui.percentCheckbox:SetFrameLevel((statsParent:GetFrameLevel() or 0) + 20)
ui.percentCheckbox:ClearAllPoints()
if statsText then
ui.percentCheckbox:SetPoint("LEFT", statsText, "RIGHT", 260, 0)
else
ui.percentCheckbox:SetPoint("TOPLEFT", statsParent, "TOPLEFT", 538, -526)
end
ui.percentCheckbox.label = ui.percentCheckbox:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
ui.percentCheckbox.label:SetPoint("LEFT", ui.percentCheckbox, "RIGHT", 4, 0)
ui.percentCheckbox.label:SetTextColor(1.00, 0.82, 0.00)
ui.percentCheckbox.label:SetText("Show modifiers in %")
ui.percentCheckbox:SetScript("OnClick", function()
if not this then return end
MTH_BOOK_STATE.familyStatsPercent = this:GetChecked() == 1
MTH_BOOKTAB_RenderFamiliesList()
end)
ui.percentCheckbox:Hide()
end
ui.headerFamily = ui.frame:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
ui.headerFamily:SetPoint("TOPLEFT", ui.frame, "TOPLEFT", 4, -2)
ui.headerFamily:SetTextColor(1.00, 0.82, 0.00)
ui.headerFamily:SetText("Family")
ui.headerNamed = ui.frame:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
ui.headerNamed:SetPoint("TOPLEFT", ui.frame, "TOPLEFT", 122, -2)
ui.headerNamed:SetPoint("TOPLEFT", ui.frame, "TOPLEFT", 114, -2)
ui.headerNamed:SetTextColor(1.00, 0.82, 0.00)
ui.headerNamed:SetText("Named")
ui.headerCoords = ui.frame:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
ui.headerCoords:SetPoint("TOPLEFT", ui.frame, "TOPLEFT", 176, -2)
ui.headerCoords:SetPoint("TOPLEFT", ui.frame, "TOPLEFT", 154, -2)
ui.headerCoords:SetTextColor(1.00, 0.82, 0.00)
ui.headerCoords:SetText("Coords")
ui.headerAbilities = ui.frame:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
ui.headerAbilities:SetPoint("TOPLEFT", ui.frame, "TOPLEFT", 232, -2)
ui.headerAbilities:SetPoint("TOPLEFT", ui.frame, "TOPLEFT", 196, -2)
ui.headerAbilities:SetTextColor(1.00, 0.82, 0.00)
ui.headerAbilities:SetText("Abilities")
ui.headerDiet = ui.frame:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
ui.headerDiet:SetPoint("TOPLEFT", ui.frame, "TOPLEFT", 532, -2)
ui.headerDiet:SetPoint("TOPLEFT", ui.frame, "TOPLEFT", 496, -2)
ui.headerDiet:SetTextColor(1.00, 0.82, 0.00)
ui.headerDiet:SetText("Diet")
ui.headerHP = ui.frame:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
ui.headerHP:SetPoint("TOPLEFT", ui.frame, "TOPLEFT", 602, -2)
ui.headerHP:SetWidth(30)
ui.headerHP:SetJustifyH("CENTER")
ui.headerHP:SetTextColor(1.00, 0.82, 0.00)
ui.headerHP:SetText("HP")
ui.headerDmg = ui.frame:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
ui.headerDmg:SetPoint("TOPLEFT", ui.frame, "TOPLEFT", 636, -2)
ui.headerDmg:SetWidth(36)
ui.headerDmg:SetJustifyH("CENTER")
ui.headerDmg:SetTextColor(1.00, 0.82, 0.00)
ui.headerDmg:SetText("dmg")
ui.headerArm = ui.frame:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
ui.headerArm:SetPoint("TOPLEFT", ui.frame, "TOPLEFT", 674, -2)
ui.headerArm:SetWidth(38)
ui.headerArm:SetJustifyH("CENTER")
ui.headerArm:SetTextColor(1.00, 0.82, 0.00)
ui.headerArm:SetText("Arm")
ui.rows = {}
for i = 1, 28 do
local row = CreateFrame("Frame", nil, ui.frame)
@@ -298,24 +409,39 @@ function MTH_BOOKTAB_EnsureFamiliesUI()
row.family = row:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
row.family:SetPoint("LEFT", row, "LEFT", 24, 0)
row.family:SetWidth(88)
row.family:SetWidth(82)
row.family:SetJustifyH("LEFT")
row.named = row:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
row.named:SetPoint("LEFT", row, "LEFT", 122, 0)
row.named:SetWidth(52)
row.named:SetPoint("LEFT", row, "LEFT", 114, 0)
row.named:SetWidth(38)
row.named:SetJustifyH("LEFT")
row.coords = row:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
row.coords:SetPoint("LEFT", row, "LEFT", 176, 0)
row.coords:SetWidth(52)
row.coords:SetPoint("LEFT", row, "LEFT", 154, 0)
row.coords:SetWidth(38)
row.coords:SetJustifyH("LEFT")
row.diet = row:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
row.diet:SetPoint("LEFT", row, "LEFT", 532, 0)
row.diet:SetWidth(112)
row.diet:SetPoint("LEFT", row, "LEFT", 496, 0)
row.diet:SetWidth(102)
row.diet:SetJustifyH("LEFT")
row.hp = row:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
row.hp:SetPoint("LEFT", row, "LEFT", 602, 0)
row.hp:SetWidth(30)
row.hp:SetJustifyH("CENTER")
row.dmg = row:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
row.dmg:SetPoint("LEFT", row, "LEFT", 636, 0)
row.dmg:SetWidth(36)
row.dmg:SetJustifyH("CENTER")
row.arm = row:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
row.arm:SetPoint("LEFT", row, "LEFT", 674, 0)
row.arm:SetWidth(38)
row.arm:SetJustifyH("CENTER")
row.abilityButtons = {}
for b = 1, 16 do
local button = CreateFrame("Button", nil, row)
@@ -379,9 +505,14 @@ function MTH_BOOKTAB_SetFamiliesUIVisible(visible)
if detailParent then detailParent:Hide() end
if detailText then detailText:Hide() end
if openMapButton then openMapButton:Hide() end
if ui.percentCheckbox then
ui.percentCheckbox:SetChecked(MTH_BOOK_STATE and MTH_BOOK_STATE.familyStatsPercent == true and 1 or nil)
ui.percentCheckbox:Show()
end
ui.frame:Show()
else
ui.frame:Hide()
if ui.percentCheckbox then ui.percentCheckbox:Hide() end
if listParent then listParent:Show() end
if detailParent then detailParent:Show() end
if detailText then detailText:Show() end
@@ -411,9 +542,12 @@ function MTH_BOOKTAB_RenderFamiliesList()
rowFrame.named:SetText(tostring(row.named or 0))
rowFrame.coords:SetText(tostring(row.coords or 0))
rowFrame.diet:SetText(tostring(row.dietText or "-"))
rowFrame.hp:SetText(MTH_BOOKTAB_FormatFamilyStat(row.healthStat))
rowFrame.dmg:SetText(MTH_BOOKTAB_FormatFamilyStat(row.damageStat))
rowFrame.arm:SetText(MTH_BOOKTAB_FormatFamilyStat(row.armorStat))
local offsetX = 232
local abilityMaxRight = 526
local offsetX = 196
local abilityMaxRight = 490
for b = 1, table.getn(rowFrame.abilityButtons) do
local button = rowFrame.abilityButtons[b]
local ability = row.abilities and row.abilities[b] or nil