Skills from TRP profile

This commit is contained in:
Gonçalo Correia 2026-04-11 19:38:19 +01:00
parent ce1c6768e1
commit 9e629aec31
4 changed files with 161 additions and 24 deletions

75
UI.lua
View file

@ -10,6 +10,22 @@ local PADDING = 12
local ROW_HEIGHT = 30
local LABEL_WIDTH = 80
-- Helper: Build the skill option list from current AltSystem.Data.Skills
local function BuildSkillOptions()
local options = {}
for _, skill in ipairs(AltSystem.Data.Skills) do
local sign = skill.modifier >= 0 and "+" or ""
local text
if skill.level == "Unskilled" then
text = skill.name .. " (" .. sign .. skill.modifier .. ")"
else
text = skill.name .. " (" .. skill.level .. " " .. sign .. skill.modifier .. ")"
end
table.insert(options, { text = text })
end
return options
end
-- Helper: Create a modern dropdown (WowStyle1DropdownTemplate)
local function CreateDropdown(parent, name, yOffset, labelText, options, defaultIndex, onSelect)
local label = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
@ -38,7 +54,7 @@ local function CreateDropdown(parent, name, yOffset, labelText, options, default
end
end)
return dropdown
return dropdown, function() return selectedIndex end, function(idx) selectedIndex = idx end
end
function AltSystem:CreateMainFrame()
@ -66,20 +82,19 @@ function AltSystem:CreateMainFrame()
-------------------------
-- Skill dropdown
-------------------------
local skillOptions = {}
for _, skill in ipairs(AltSystem.Data.Skills) do
local levelMod = skill.modifier
local sign = levelMod >= 0 and "+" or ""
table.insert(skillOptions, {
text = skill.name .. " (" .. skill.level .. " " .. sign .. levelMod .. ")",
icon = skill.icon,
})
end
local skillOptions = BuildSkillOptions()
CreateDropdown(f, "AltSystemSkillDropdown", yPos, "Skill:", skillOptions, AltSystem.State.selectedSkillIndex,
local skillDropdown, getSkillIndex, setSkillIndex = CreateDropdown(
f, "AltSystemSkillDropdown", yPos, "Skill:", skillOptions,
AltSystem.State.selectedSkillIndex,
function(index)
AltSystem.State.selectedSkillIndex = index
end)
-- Store references for refreshing
AltSystem.SkillDropdown = skillDropdown
AltSystem.GetSkillIndex = getSkillIndex
AltSystem.SetSkillIndex = setSkillIndex
yPos = yPos - ROW_HEIGHT - 8
-------------------------
@ -149,7 +164,7 @@ function AltSystem:CreateMainFrame()
local attackBtn = CreateFrame("Button", "AltSystemAttackRollBtn", f, "UIPanelButtonTemplate")
attackBtn:SetSize(btnWidth, 28)
attackBtn:SetPoint("TOPLEFT", f, "TOPLEFT", PADDING, yPos)
attackBtn:SetText("Attack Roll")
attackBtn:SetText("Attack/Skill Roll")
local defenseBtn = CreateFrame("Button", "AltSystemDefenseRollBtn", f, "UIPanelButtonTemplate")
defenseBtn:SetSize(btnWidth, 28)
@ -182,9 +197,45 @@ function AltSystem:CreateMainFrame()
AltSystem:PerformRoll("defense")
end)
-- Refresh skills from TRP3 profile each time the window is shown
f:SetScript("OnShow", function()
AltSystem:RefreshSkillDropdown()
end)
f:Hide()
AltSystem.MainFrame = f
end
-- Refresh the skill dropdown with current TRP3 profile data
function AltSystem:RefreshSkillDropdown()
AltSystem.Data:RefreshSkills()
-- Reset selection to 1 (Unskilled) since the skill list may have changed
AltSystem.State.selectedSkillIndex = 1
if AltSystem.SetSkillIndex then
AltSystem.SetSkillIndex(1)
end
-- Rebuild the dropdown menu with the new skill list
if AltSystem.SkillDropdown then
local skillOptions = BuildSkillOptions()
AltSystem.SkillDropdown:SetupMenu(function(dropdown, rootDescription)
for i, option in ipairs(skillOptions) do
rootDescription:CreateRadio(
option.text,
function(data) return data == AltSystem.State.selectedSkillIndex end,
function(data)
AltSystem.State.selectedSkillIndex = data
if AltSystem.SetSkillIndex then
AltSystem.SetSkillIndex(data)
end
end,
i
)
end
end)
end
end
-- Create the frame on file load so it's ready when Init runs
AltSystem:CreateMainFrame()