local function MakeCheckButton(parent, text) local checkButton = CreateFrame("CheckButton", nil, parent, "SettingsCheckBoxTemplate") checkButton.text = checkButton:CreateFontString(nil, "ARTWORK", "GameFontNormal") checkButton.text:SetText(text) checkButton.text:SetPoint("LEFT", checkButton, "RIGHT", 4, 0) checkButton:SetSize(21, 20) checkButton:SetHitRectInsets(0, -200, 0, 0) checkButton.HoverBackground = nil return checkButton end local function HasDropdownTemplate() return C_XMLUtil and C_XMLUtil.GetTemplateInfo and C_XMLUtil.GetTemplateInfo("WowStyle1DropdownTemplate") end local function CreateColorSwatch(parent) local button = CreateFrame("Button", nil, parent) button:SetSize(20, 20) button.border = button:CreateTexture(nil, "BACKGROUND") button.border:SetAllPoints() button.border:SetColorTexture(0.15, 0.15, 0.15, 1) button.color = button:CreateTexture(nil, "OVERLAY") button.color:SetPoint("TOPLEFT", 2, -2) button.color:SetPoint("BOTTOMRIGHT", -2, 2) function button:SetColor(r, g, b) self.color:SetColorTexture(r, g, b, 1) end return button end local function OpenBarColorPicker() local r, g, b = Professor:GetBarColor() local function Apply(nr, ng, nb) if not nr then return end Professor:SetBarColor(nr, ng, nb) end if ColorPickerFrame and ColorPickerFrame.SetupColorPickerAndShow then ColorPickerFrame:SetupColorPickerAndShow({ r = r, g = g, b = b, hasOpacity = false, swatchFunc = function() Apply(ColorPickerFrame:GetColorRGB()) end, cancelFunc = function(previous) if previous then Apply(previous.r, previous.g, previous.b) else Apply(ColorPickerFrame:GetPreviousValues()) end end, }) return end if not ColorPickerFrame then return end ColorPickerFrame.func = function() Apply(ColorPickerFrame:GetColorRGB()) end ColorPickerFrame.swatchFunc = ColorPickerFrame.func ColorPickerFrame.cancelFunc = function(previous) if previous then Apply(previous.r, previous.g, previous.b) end end ColorPickerFrame.hasOpacity = false if ColorPickerFrame.SetColorRGB then ColorPickerFrame:SetColorRGB(r, g, b) end ColorPickerFrame:Show() end function Professor:CreateProfessionDropdown(parent) local dropdown = CreateFrame("DropdownButton", "ProfessorProfessionDropdown", parent, "WowStyle1DropdownTemplate") dropdown:SetWidth(220) dropdown:SetDefaultText("None") dropdown:SetupMenu(function(_, rootDescription) rootDescription:CreateRadio("None", function() return Professor:GetSelectedKey() == nil end, function() Professor:SetSelected(nil) end) for _, prof in ipairs(Professor:GetKnownProfessions()) do local key = prof.slot rootDescription:CreateRadio(prof.name, function() return Professor:GetSelectedKey() == key end, function() Professor:SetSelected(key) end) end end) return dropdown end function Professor:CreateSettings() if self.CategoryID then return end local optionsFrame = CreateFrame("Frame", nil, nil, "VerticalLayoutFrame") optionsFrame.spacing = 8 local category = Settings.RegisterCanvasLayoutCategory(optionsFrame, "Professor") self.CategoryID = category:GetID() self.SettingsCategory = category Settings.RegisterAddOnCategory(category) local layoutIndex = 0 local function NextIndex() layoutIndex = layoutIndex + 1 return layoutIndex end local header = CreateFrame("Frame", nil, optionsFrame) header:SetSize(150, 50) local headerText = header:CreateFontString(nil, "ARTWORK", "GameFontHighlightHuge") headerText:SetPoint("TOPLEFT", 7, -22) headerText:SetText("Professor") local divider = header:CreateTexture(nil, "ARTWORK") divider:SetAtlas("Options_HorizontalDivider", true) divider:SetPoint("BOTTOMLEFT", -50) header.layoutIndex = NextIndex() header.bottomPadding = 10 local professionRow = CreateFrame("Frame", nil, optionsFrame) professionRow:SetSize(420, 32) professionRow.layoutIndex = NextIndex() local professionLabel = professionRow:CreateFontString(nil, "ARTWORK", "GameFontNormal") professionLabel:SetPoint("LEFT", 7, 0) professionLabel:SetText("Profession") if HasDropdownTemplate() then self.settingsDropdown = self:CreateProfessionDropdown(professionRow) self.settingsDropdown:SetPoint("LEFT", professionLabel, "RIGHT", 16, 0) else local fallback = professionRow:CreateFontString(nil, "ARTWORK", "GameFontHighlight") fallback:SetPoint("LEFT", professionLabel, "RIGHT", 16, 0) fallback:SetText("Use /professor cycle or a keybind to choose a profession.") self.settingsDropdownLabel = fallback end local colorRow = CreateFrame("Frame", nil, optionsFrame) colorRow:SetSize(420, 28) colorRow.layoutIndex = NextIndex() local colorLabel = colorRow:CreateFontString(nil, "ARTWORK", "GameFontNormal") colorLabel:SetPoint("LEFT", 7, 0) colorLabel:SetText("Bar color") self.settingsColorSwatch = CreateColorSwatch(colorRow) self.settingsColorSwatch:SetPoint("LEFT", colorLabel, "RIGHT", 16, 0) self.settingsColorSwatch:SetScript("OnClick", OpenBarColorPicker) local alwaysText = MakeCheckButton(optionsFrame, "Always show text") alwaysText.layoutIndex = NextIndex() alwaysText:SetScript("OnClick", function(button) ProfessorDB.alwaysShowText = button:GetChecked() and true or false Professor:Refresh() end) self.settingsAlwaysText = alwaysText optionsFrame:Layout() self:UpdateSettingsControls() end function Professor:UpdateSettingsControls() if self.settingsAlwaysText then self.settingsAlwaysText:SetChecked(ProfessorDB.alwaysShowText) end if self.settingsColorSwatch then self.settingsColorSwatch:SetColor(self:GetBarColor()) end if self.settingsDropdown then if self.settingsDropdown.GenerateMenu then self.settingsDropdown:GenerateMenu() end if self.settingsDropdown.SetDefaultText then self.settingsDropdown:SetDefaultText(self:GetSelectedLabel()) end end if self.settingsDropdownLabel then self.settingsDropdownLabel:SetText(self:GetSelectedLabel()) end end