local L = DressToKillLocals local frame = CreateFrame("Frame", "DressToKillOptionsFrame", UIParent) frame.name = L["Dress to Kill"] frame:Hide() frame:SetScript("OnShow", function(frame) -- Initialize the system DressToKill:Initialize() local editbox, dropdown, reset, save, delete local title = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge") title:SetPoint("TOPLEFT", frame, "TOPLEFT", 15, -15) title:SetPoint("BOTTOMRIGHT", frame, "TOPRIGHT", 10, -45) title:SetJustifyH("LEFT") title:SetJustifyV("TOP") title:SetText(L["Dress to Kill"]) --[[ local check = CreateFrame("CheckButton", "DressToKillEnableButton", frame, "UICheckButtonTemplate") check:SetPoint("TOPLEFT", frame, "TOPLEFT", 15, -50) check:SetWidth(24) check:SetHeight(24) check:SetChecked(AddonLoaderSV.silent) AddonLoaderCheckButtonText:SetText("Hide Loading Messages") AddonLoaderCheckButtonText:SetPoint("LEFT", check, "RIGHT") check:SetScript("OnClick", function() AddonLoaderSV.silent = not AddonLoaderSV.silent check:SetChecked(AddonLoaderSV.silent) end) --]] local explain = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal") explain:SetTextColor(1,1,1) explain:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, 0) explain:SetPoint("RIGHT", frame, "RIGHT", -15, 0) explain:SetJustifyH("LEFT") explain:SetJustifyV("TOP") explain:SetHeight(100) explain:SetText(L["Dress to Kill is a simple addon which takes the guesswork out of building equipment sets for your character. Rather than use a complicated library to scan your items for potential bonuses it sacrifices speed for optimal results. It will scan through your inventory trying items on until it find the most effective mix. You can customize the way equipment is evaluated through a custom evaluation function or you can simply use one of the built in functions."]) local function dropdown_onclick() local selected = this.value if selected == "__NEW__" then -- Make a new entry StaticPopup_Show("DRESSTOKILL_NEW_FUNCTION") else DressToKill.profile.selected = selected UIDropDownMenu_SetSelectedValue(dropdown, selected) editbox:SetText(DressToKill.profile.weightFuncs[selected].handler) DressToKillDeleteButton:Enable() end end local function initdropdown() local sort = {} for k,v in pairs(DressToKill.profile.weightFuncs) do table.insert(sort, k) end table.sort(sort) local info = UIDropDownMenu_CreateInfo() for idx,name in ipairs(sort) do info.text = name info.value = name info.func = dropdown_onclick info.checked = false UIDropDownMenu_AddButton(info) end info.text = L["New weight function"] info.value = "__NEW__" info.func = dropdown_onclick info.checked = false UIDropDownMenu_AddButton(info) end local dropdownlabel = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal") dropdownlabel:SetPoint("TOPLEFT", explain, "BOTTOMLEFT", 0, -10) dropdownlabel:SetText("Weight Function:") dropdownlabel:SetHeight(15) dropdownlabel:SetWidth(100) dropdown = CreateFrame("Frame", "DressToKillDropDown", frame, "UIDropDownMenuTemplate") dropdown:EnableMouse(true) dropdown:SetPoint("LEFT", dropdownlabel, "RIGHT") UIDropDownMenu_Initialize(dropdown, initdropdown) UIDropDownMenu_SetSelectedValue(dropdown, DressToKill.profile.selected) UIDropDownMenu_SetWidth(dropdown, 160) UIDropDownMenu_JustifyText(dropdown, "LEFT") editbox = CreateFrame("EditBox", "DressToKillEditBox", frame) editbox:SetPoint("TOPLEFT", dropdownlabel, "BOTTOMLEFT", 0, -15) editbox:SetPoint("RIGHT", -15, 0) editbox:SetPoint("BOTTOM", 0, 45) editbox:SetFont("Interface\\AddOns\\DressToKill\\fonts\\VeraMono.ttf", 12) editbox:SetTextInsets(8,8,8,8) editbox:SetBackdrop({ bgFile = "Interface\\ChatFrame\\ChatFrameBackground", edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", edgeSize = 16, insets = {left = 4, right = 4, top = 4, bottom = 4} }) editbox:SetBackdropColor(.1,.1,.1,.3) editbox:SetBackdropBorderColor(.5,.5,.5) editbox:SetMultiLine(true) editbox:SetAutoFocus(false) editbox:ClearFocus() editbox:SetScript("OnEscapePressed", function(self) self:ClearFocus() end) local selected = DressToKill.profile.selected if selected then editbox:SetText(DressToKill.profile.weightFuncs[selected].handler or "") else editbox:SetText("-- Select an existing weight function from the above dropdown or create a new function.") end IndentationLib.enable(editbox) reset = CreateFrame("Button", "DressToKillResetButton", frame, "UIPanelButtonTemplate2") reset:SetText(L["Reset"]) reset:SetWidth(80) reset:SetPoint("TOPRIGHT", editbox, "BOTTOMRIGHT", 0, -5) reset:SetScript("OnClick", function(self) local selected = DressToKill.profile.selected local handler = DressToKill.profile.weightFuncs[selected].handler editbox:SetText(handler) self:Disable() end) reset.counter = 0 reset:SetScript("OnUpdate", function(self, elapsed) self.counter = self.counter + elapsed if self.counter > 0.2 then self.counter = 0 -- Do check local selected = DressToKill.profile.selected if not selected then self:Disable() return end local source = DressToKill.profile.weightFuncs[selected].handler if editbox:GetText() ~= source then self:Enable() else self:Disable() end end end) save = CreateFrame("Button", "DressToKillSaveButton", frame, "UIPanelButtonTemplate2") save:SetText(L["Save"]) save:SetWidth(80) save:SetPoint("RIGHT", reset, "LEFT", -3, 0) save:SetScript("OnClick", function(self) local selected = DressToKill.profile.selected local entry = DressToKill.profile.weightFuncs[selected] entry.handler = editbox:GetText() self:Disable() end) save.counter = 0 save:SetScript("OnUpdate", function(self, elapsed) self.counter = self.counter + elapsed if self.counter > 0.2 then self.counter = 0 -- Do check local selected = DressToKill.profile.selected if not selected then self:Disable() return end local source = DressToKill.profile.weightFuncs[selected].handler if editbox:GetText() ~= source then self:Enable() else self:Disable() end end end) delete = CreateFrame("Button", "DressToKillDeleteButton", frame, "UIPanelButtonTemplate2") delete:SetText(L["Delete"]) delete:SetWidth(80) delete:SetPoint("RIGHT", save, "LEFT", -3, 0) delete:SetScript("OnClick", function(self) local selected = DressToKill.profile.selected DressToKill.profile.selected = nil DressToKill.profile.weightFuncs[selected] = nil UIDropDownMenu_Initialize(dropdown, initdropdown) UIDropDownMenu_SetSelectedValue(dropdown, nil) editbox:SetText("") self:Disable() end) local function OnAccept() local name = this:GetParent():GetName().."EditBox" local button = getglobal(name) local text = button:GetText() DressToKill.profile.selected = text DressToKill.profile.weightFuncs[text] = { handler = "" } UIDropDownMenu_Initialize(dropdown, initdropdown) UIDropDownMenu_SetSelectedValue(dropdown, text) editbox:SetText([[ --This function receives a single parameter --'link', which is the link of the item --being tested. Example usage to max --the player's health: -- -- return UnitHealthMax("player")]]) end -- Create a static popup StaticPopupDialogs["DRESSTOKILL_NEW_FUNCTION"] = { text = TEXT("Enter the name of the function you'd like to create"), button1 = TEXT(OKAY), button2 = TEXT(CANCEL), OnAccept = OnAccept, timeout = 0, whileDead = 1, exclusive = 1, showAlert = 1, hideOnEscape = 1, hasEditBox = 1, maxLetters = 32, OnShow = function() getglobal(this:GetName().."Button1"):Disable(); getglobal(this:GetName().."EditBox"):SetFocus(); end, OnHide = function() if ( ChatFrameEditBox:IsVisible() ) then ChatFrameEditBox:SetFocus(); end getglobal(this:GetName().."EditBox"):SetText(""); end, EditBoxOnEnterPressed = function() if ( getglobal(this:GetParent():GetName().."Button1"):IsEnabled() == 1 ) then OnAccept() this:GetParent():Hide() end end, EditBoxOnTextChanged = function () local editBox = getglobal(this:GetParent():GetName().."EditBox"); local txt = editBox:GetText() if #txt > 0 and not DressToKill.profile.weightFuncs[txt] then getglobal(this:GetParent():GetName().."Button1"):Enable(); else getglobal(this:GetParent():GetName().."Button1"):Disable(); end end, EditBoxOnEscapePressed = function() this:GetParent():Hide(); ClearCursor(); end } frame:SetScript("OnShow", nil) end ) InterfaceOptions_AddCategory(frame) local debugframe = CreateFrame("Frame", "DressToKillDebugFrame", UIParent) debugframe.name = L["Debug Log"] debugframe.parent = L["Dress to Kill"] debugframe:Hide() local scrollframe = CreateFrame("ScrollingMessageFrame", "DressToKillDebugScrollFrame", debugframe) scrollframe:SetPoint("TOPLEFT", 10, -10) scrollframe:SetPoint("BOTTOMRIGHT", -10, 45) scrollframe:SetFontObject("ChatFontNormal") scrollframe:SetJustifyH("LEFT") scrollframe:SetFading(false) scrollframe:EnableMouseWheel(true) scrollframe:SetInsertMode("BOTTOM") scrollframe:SetMaxLines(99999) scrollframe:AddMessage("Dress to Kill v." .. (GetAddOnMetadata("TomTom", "Version") or "unknown")) local function scroll(self, delta) if delta > 0 then if IsShiftKeyDown() then self:ScrollToTop() elseif IsControlKeyDown() then self:PageUp() else self:ScrollUp() end elseif delta < 0 then if IsShiftKeyDown() then self:ScrollToBottom() elseif IsControlKeyDown() then self:PageDown() else self:ScrollDown() end end end scrollframe:SetScript("OnHyperlinkClick", function(self, ...) ChatFrame_OnHyperlinkShow(...) end) scrollframe:SetScript("OnMouseWheel", scroll) InterfaceOptions_AddCategory(debugframe) debugframe:SetScript("OnShow", function(frame) debugframe:SetScript("OnShow", nil) -- Copied from Chatter by Antiarc local PaneBackdrop = { bgFile = [[Interface\DialogFrame\UI-DialogBox-Background]], edgeFile = [[Interface\DialogFrame\UI-DialogBox-Border]], tile = true, tileSize = 16, edgeSize = 16, insets = { left = 3, right = 3, top = 5, bottom = 3 } } local InsetBackdrop = { bgFile = [[Interface\DialogFrame\UI-DialogBox-Background]], edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]], tile = true, tileSize = 16, edgeSize = 16, insets = { left = 3, right = 3, top = 5, bottom = 3 } } local frame = CreateFrame("Frame", "DressToKillCopyFrame", UIParent) table.insert(UISpecialFrames, "DressToKillCopyFrame") frame:SetBackdrop(PaneBackdrop) frame:SetBackdropColor(0,0,0,1) frame:SetWidth(500) frame:SetHeight(200) frame:SetPoint("CENTER", UIParent, "CENTER") frame:Hide() frame:SetFrameStrata("DIALOG") local scrollArea = CreateFrame("ScrollFrame", "DressToKillCopyScroll", frame, "UIPanelScrollFrameTemplate") scrollArea:SetPoint("TOPLEFT", frame, "TOPLEFT", 8, -30) scrollArea:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -30, 8) local editBox = CreateFrame("EditBox", nil, frame) editBox:SetMultiLine(true) editBox:SetMaxLetters(99999) editBox:EnableMouse(true) editBox:SetAutoFocus(false) editBox:SetFontObject(ChatFontNormal) editBox:SetWidth(400) editBox:SetHeight(270) editBox:SetScript("OnEscapePressed", function() frame:Hide() end) scrollArea:SetScrollChild(editBox) local lines = {} local function getlines(...) local ct = 1 for i = select("#", ...), 1, -1 do local region = select(i, ...) if region:GetObjectType() == "FontString" then lines[ct] = tostring(region:GetText()) ct = ct + 1 end end return ct - 1 end local close = CreateFrame("Button", nil, frame, "UIPanelCloseButton") close:SetPoint("TOPRIGHT", frame, "TOPRIGHT") local copylog = CreateFrame("Button", "DressToKillCopyLogButton", DressToKillDebugScrollFrame, "UIPanelButtonTemplate2") copylog:SetText(L["Copy Log"]) copylog:SetWidth(80) copylog:SetPoint("TOPRIGHT", scrollframe, "BOTTOMRIGHT", 0, -5) copylog:SetScript("OnClick", function(self) lines = {} local _, size = DressToKillDebugScrollFrame:GetFont() FCF_SetChatWindowFontSize(DressToKillDebugScrollFrame, 0.01) local lineCt = getlines(DressToKillDebugScrollFrame:GetRegions()) local text = table.concat(lines, "\n", 1, lineCt) FCF_SetChatWindowFontSize(DressToKillDebugScrollFrame, size) DressToKillCopyFrame:Show() editBox:SetText(text) editBox:HighlightText(0) end) end)