My first Addon coding help

I’m trying to build my first custom addon. So far I have been able to create a window with a close button. But, I’m trying to incorporate a block of test with a checkmark and scrollbar. The concept would be I would have short 1-2 sentense texts associated with a check box. When I performed the action, i could check the box and move on. Kind of like a custom leveling tool. The scroll bar would help allow to scroll down through all of the upcoming or previously performed checked steps.

Does anyone have a simple code to perform this? so far i’m using the following .lua coding:

local MyAddon = CreateFrame(“frame”,“MyAddonFrame”)
MyAddon:SetBackdrop({
bgFile=“Interface\DialogFrame\UI-DialogBox-Background”,
edgeFile=“Interface\DialogFrame\UI-DialogBox-Border”,
tile=1, tileSize=32, edgeSize=32,
insets={left=11, right=12, top=12, bottom=11}
})
MyAddon:SetWidth(220)
MyAddon:SetHeight(400)
MyAddon:SetPoint(“CENTER”,UIParent)
MyAddon:EnableMouse(true)
MyAddon:SetMovable(true)
MyAddon:RegisterForDrag(“LeftButton”)
MyAddon:SetScript(“OnDragStart”, function(self) self:StartMoving() end)
MyAddon:SetScript(“OnDragStop”, function(self) self:StopMovingOrSizing() end)
MyAddon:SetFrameStrata(“FULLSCREEN_DIALOG”)

local button = CreateFrame(“button”,“MyAddonButton”, MyAddon, “UIPanelButtonTemplate”)
button:SetHeight(24)
button:SetWidth(60)
button:SetPoint(“BOTTOM”, MyAddon, “BOTTOM”, 0, 10)
button:SetText(“Close”)
button:SetScript(“OnClick”, function(self) self:GetParent():Hide() end)

I’ve tried using various scroll bars, but none seem to work. Then, I run the problem of not knowing how to code a 1-2 sentence message associated with a check box.

Anyone with some addon coding experience able to help?

Because you are combining checkboxes into text you start to make things a bit more complicated.

This is very basic using some build-in templates and functions but it’s a reasonable base for simple scroll lists made up of rows of a set height.

Basic outline of what’s happening:
Create a table of entries you want to display.

Create the frame, add the number of “rows” you want to your list to have made up of the widgets the row needs (in this case, a checkbox and a fontstring (text area)). Add a scroll frame (in this case a basic looking thumb wheel) to calculate the position in the table relative to the thumb.

Create the “rows”. I’ve used the CreateButton function which also adds the OnClick functionality for the checkbox.

Add a function to fill the row entries from the table. The FauxScroll determines relative position in the list based on the height of a row.

(I added a slash command so you can toggle the visibility of the frame without reloading).

local CheckList = { -- table of entries and storage to checked status
	{ checked=false, text="Text Entry 1"},
	{ checked=false, text="Text Entry 2"},
	{ checked=false, text="Text Entry 3"},
	{ checked=false, text="Text Entry 4"},
	{ checked=false, text="Text Entry 5"},
	{ checked=false, text="Text Entry 6"},
	{ checked=false, text="Text Entry 7"},
	{ checked=false, text="Text Entry 8"},
	{ checked=false, text="Text Entry 9"},
	{ checked=false, text="Text Entry 10"},
	{ checked=false, text="Text Entry 12"},
	{ checked=false, text="Text Entry 13"},
	{ checked=false, text="Text Entry 14"},
	{ checked=false, text="Text Entry 15"},
	{ checked=false, text="Text Entry 16"},
	{ checked=false, text="Text Entry 17"},
	{ checked=false, text="Text Entry 18"},
	{ checked=false, text="Text Entry 19"},
}

local NumButtons = 10 -- No. of "rows" in the scrolling list

local function ListUpdate(self) -- Update the "rows" starting with the current position of the
	local parent = self:GetParent() -- of the thumb relative to the top of the list - GetOffset()
	local numOptions = #CheckList
	local offset = FauxScrollFrame_GetOffset(self)
	if not offset then offset = 0 end
	local index, button
	for i=1, NumButtons do
		button = parent.ListButtons[i]
		index = offset + i -- relative table entry to row entry
		button.EntryId = nil
		if CheckList[index] then
			button.Text:SetText(CheckList[index].text)
			button.EntryId = index -- so each button knows it table entry for OnClick
			button.CheckBox:SetChecked(CheckList[index].checked) -- check/unchek the box
			button.CheckBox:GetScript("OnClick")(button.CheckBox)-- call the OnClick handler
			button:Show()
		else
			button:Hide()
		end
	end
	FauxScrollFrame_Update(self, numOptions, NumButtons, parent.ButtonHeight)
end

local function CreateButton(parent, id, width, height) -- Create a list item (row) with a checkbox and text
	f = CreateFrame("CheckButton", "$parentButton"..id, parent) -- $parent is replaced with the parent frame name
	f:SetSize(width, height)
	f.CheckBox = CreateFrame("CheckButton", "$parentCheck", f, "UICheckButtonTemplate")
	f.CheckBox:SetPoint("LEFT", 5, 0)
	f.Text = f:CreateFontString()
	f.Text:SetFontObject(GameFontNormalSmall)
	f.Text:SetPoint("TOPLEFT", 6, -1)
	f.Text:SetPoint("BOTTOMRIGHT", -1, 1)
	f.CheckBox:SetScript("OnClick", function(self) -- fade/unfade a text depending on its checkbutton status
		CheckList[self:GetParent().EntryId].checked = self:GetChecked()
		if self:GetChecked() then
			self:GetParent().Text:SetAlpha(0.5)
		else
			self:GetParent().Text:SetAlpha(1)
		end
	end)
	return f
end

local f = CreateFrame("Frame","WaffleshockFrame") -- Frames should have globaly unique names
f:SetBackdrop({
bgFile="Interface/DialogFrame/UI-DialogBox-Background",
edgeFile="Interface/DialogFrame/UI-DialogBox-Border",
tile=1, tileSize=32, edgeSize=32,
insets={left=11, right=12, top=12, bottom=11}
})
f:SetWidth(220)
f:SetHeight(400)
f:SetPoint("CENTER",UIParent)
f:EnableMouse(true)
f:SetMovable(true)
f:SetUserPlaced(true)
f:RegisterForDrag("LeftButton")
f:SetScript("OnDragStart", function(self) self:StartMoving() end)
f:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
f:SetFrameStrata("FULLSCREEN_DIALOG")

f.Close = CreateFrame("Button","$parentClose", f)
f.Close:SetHeight(24)
f.Close:SetWidth(25)
f.Close:SetPoint("TOPRIGHT", -10, -10)
f.Close:SetNormalTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Up")
f.Close:SetPushedTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Down")
f.Close:SetHighlightTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Highlight", "ADD")
f.Close:SetScript("OnClick", function(self) self:GetParent():Hide() end)

f.ButtonHeight = 360/NumButtons --360/10 = Frame height minus some space / # buttons
f.ListButtons = {} -- Add the "rows"
for i=1, NumButtons do
	tinsert(f.ListButtons, CreateButton(f, i, 195, f.ButtonHeight)) -- 195 width minus space for scrollbar, 
	if i == 1 then
		f.ListButtons[i]:SetPoint("TOPLEFT", 5, -26)
	else
		f.ListButtons[i]:SetPoint("TOP", f.ListButtons[i-1], "BOTTOM")
	end
end
f.List = CreateFrame("ScrollFrame","$parentList", f, "FauxScrollFrameTemplate") -- add the scrolling thumb widget
f.List:SetPoint("TOPLEFT", 10, -35)
f.List:SetSize(175, 350)
f.List:SetScript("OnVerticalScroll", function(self, offset) -- Faux anything built into the Blizzard UI
	FauxScrollFrame_OnVerticalScroll(self, offset, f.ButtonHeight, ListUpdate)
end)
ListUpdate(f.List) -- initialise the list

-- Slash command to show/hide the frame. Use /wf
_G["SLASH_Waffleshocked1"] = "/wf"
SlashCmdList["Waffleshocked"] = function(msg)
	WaffleshockFrame:SetShown(not WaffleshockFrame:IsShown())
end
1 Like

Amazing! thank you man! this was exactly the help i needed.
Looks like i thought an easy first project was a little bigger of a bite than i could chew. lol