View Single Post
01-25-13, 10:09 PM   #3
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
AceGUI... oh god, why? Seriously, for your first addon and something so simple, you'll learn a lot more, and end up with a better addon, if you just use the native frame API instead of AceGUI.

A few other things:

If you're using AceAddon (though, again, for something so simple, there's no need, and I would recommend avoiding libraries for your first addon until you are more familiar with the WoW API) you don't need to make a separate frame for handling events; just use AceEvent and embed it in your addon.

Don't make the only reference to your addon object a global variable. Make it local, and if you need global access, make a separate global.

Don't include "Addon version N loaded!" messages at startup. The user already knows they installed your addon, and does not need (or want) to be reminded every time they log into the game. If you think "but it's just one line of text, ignore it!" consider what it looks like when you have 10, 25, 50, or more addons all doing it.

Here is a quick (and drycoded) conversion of your code to the native API:

Code:
local Roller = CreateFrame("Frame", "Roller", UIParent)
Roller:SetPoint("CENTER")
Roller:SetSize(500, 150)
Roller:SetBackdrop(GameTooltip:GetBackdrop())
Roller:SetBackdropColor(0, 0, 0)
Roller:SetBackdropBorderColor(1, 1, 1)
Roller:Hide()

local Title = Roller:CreateFontString("$parentTitle", "OVERLAY", "GameFontNormal")
Title:SetPoint("TOPLEFT", Roller, 12, -12)
Title:SetText("Roller 0.1")
Roller.Title = Title

local Text = Roller:CreateFontString("$parentText", "OVERLAY", "GameFontHighlightSmall")
Text:SetPoint("TOPLEFT", Title, "BOTTOMLEFT")
Text:SetPoint("RIGHT")
Text:SetHeight(32)
Text:SetJustifyH("LEFT")
Text:SetJustifyV("TOP")
Text:SetText("Type an emote in the box and then press the button...")
Roller.Text = Text

local EmoteBox = CreateFrame("EditBox", "$parentEditBox", Roller, "InputBoxTemplate")
EmoteBox:SetPoint("TOPLEFT", Text, "BOTTOMLEFT", -4, -24)
EmoteBox:SetWidth(200)
Roller.EmoteBox = EmoteBox

local EmoteLabel = EmoteBox:CreateFontString("$parentLabel", "OVERLAY", "GameFontHighlightSmall")
EmoteLabel:SetPoint("BOTTOMLEFT", EmoteBox, "TOPLEFT")
EmoteLabel:SetText("Action:")
EmoteBox.Label = EmoteLabel

EmoteBox:SetScript("OnEnterPressed", function(self)
	local text = self:GetText()
	-- do something with the text here
end)

local RollButton = CreateFrame("Button", "$parentRollButton", Roller, "UIPanelButtonTemplate")
RollButton:SetPoint("TOPLEFT", EmoteBox, "BOTTOMLEFT", 0, -12)
RollButton:SetWidth(200)
RollButton:SetText("Roll!")
Roller.RollButton = RollButton

RollButton:SetScript("OnClick", function(self, mouseButton)
	-- do something with the click here
end)

local CloseButton = CreateFrame("Button", "$parentCloseButton", Roller, "UIPanelCloseButton")
CloseButton:SetPoint("TOPRIGHT", -12, -12)
CloseButton:SetScript("OnClick", function(self)
	self:GetParent():Hide()
end)

SLASH_ROLLER1 = "/roller"
SlashCmdList.ROLLER = function(cmd)
	if Roller:IsShown() then
		Roller:Hide()
	else
		Roller:Show()
	end
end
I left out the RollerGM frame since your code seemed like just a placeholder that didn't actually do anything yet, but there are native templates for checkboxes, dropdowns, etc. too when you get to that part.

I also left the editbox's OnEnterPressed script (mostly) empty since I couldn't figure out what your pseudo-code was supposed to be doing. If you describe that more clearly I can write something up for you.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote