Thread Tools Display Modes
02-10-10, 10:59 AM   #1
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
Originally Posted by Vrul View Post
[code]
Edit:

Instead of creating a separate function for each frame's "OnClick" handler why not just do:

Code:
local function setLoc(self)
	for i = 1, #cityList do
		_G["MageTaxi_City" .. i]:SetChecked(false)
	end
	dest = cityList[self.id]
	self:SetChecked(true)
end
 
function MageTaxi_createGUI()
	-- other code
	for i = 1, #cityList do
		cb = CreateFrame("CHECKBUTTON", "MageTaxi_City" .. i, f, "UIRadioButtonTemplate")
		if i == 1 then
			cb:SetPoint("TOPLEFT", f, "TOPLEFT", 40, -45)
		else
			cb:SetPoint("TOP", "MageTaxi_City" .. (i - 1), "BOTTOM", 0, -10)
		end
		cb.id = i
		cb:SetScript("OnClick", setLoc) -- line 149
	end
end
Isn't just passing i doing the same thing, or am I not following this logic correctly?

Final thing, you are concatenating the i variable in your setLoc function, don't you mean this?
Code:
i = i:GetName()
Why would I want the name of a number?

And the most neat way is this:

Code:
cb:SetScript("OnClick", setLoc)
Which will get called like this:

Code:
setLoc(...)
Which is what we want.
... is still somewhat confusing to me. I understand that it's all arguments that are passed, but cb:SetScript("OnClick", setLoc) isn't passing anything, so how would I get the i value?

Still learning as I go along.
  Reply With Quote
02-10-10, 11:36 AM   #2
nightcracker
A Molten Giant
 
nightcracker's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 716
Originally Posted by ChaosInc View Post
Isn't just passing i doing the same thing, or am I not following this logic correctly?


Why would I want the name of a number?



... is still somewhat confusing to me. I understand that it's all arguments that are passed, but cb:SetScript("OnClick", setLoc) isn't passing anything, so how would I get the i value?

Still learning as I go along.
NOW I see what you want to do.... Here it comes:

Code:
function MageTaxi:SetFaction()
    if UnitFactionGroup("player") == "Alliance" then
        cityList = {
            [1] = "Stormwind",
            [2] = "Ironforge",
            [3] = "Darnassus",
            [4] = "Exodar",
            [5] = "Theramore",
            [6] = "Shattrath",
            [7] = "Dalaran",
        }
    else
        cityList = {
            [1] = "Undercity",
            [2] = "Orgrimmar",
            [3] = "Thunder Bluff",
            [4] = "Silvermoon",
            [5] = "Stonard",
            [6] = "Shattrath",
            [7] = "Dalaran"
        }
    end;
        dest = cityList[1]
end

local function setLoc(i)
    for num= 1,#cityList do
        _G["MageTaxi_City".. num]:SetChecked(false)  -- line 91
    end
    dest = cityList[i]
    _G["MageTaxi_City".. i]:SetChecked(true)
end
 
function MageTaxi_createGUI()
    for i = 1,#cityList do
        cb = CreateFrame("CHECKBUTTON", "MageTaxi_City"..i, f, "UIRadioButtonTemplate")
		if i == 1 then
			cb:SetPoint("TOPLEFT", f, "TOPLEFT", 40, -45)
		else
			cb:SetPoint("TOP", "MageTaxi_City".. (i-1), "BOTTOM", 0, -10)
		end
		cb:SetScript("OnClick", function() setLoc(i) end) -- line 149
    end
end
__________________
Three things are certain,
Death, taxes and site not found,
You, victim of one.
  Reply With Quote
02-10-10, 12:11 PM   #3
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
Thanks, I realized the fix last night already, but good to see it verified (and it works btw).

One thing though that I've run into that maybe someone can help me with. I have ZERO understanding of string manipulation and it has me painted into a corner atm.

Code:
cityList = {
	[3] = "ThunderBluff",
}

b = CreateFrame("BUTTON", "MageTaxi_Port"..i, f, "SecureActionButtonTemplate")
	b:SetPoint("RIGHT", "MageTaxi_City"..i, "LEFT", 0, 0)
	b:SetHeight(18)
	b:SetWidth(18)
	b.texture = b:CreateTexture("MageTaxi_Spell"..i)
	b.texture:SetAllPoints(b)
	b.texture:SetTexture("Interface\\Icons\\Spell_Arcane_Portal".. cityList[i])
	b:SetAttribute("type", "spell")
	b:SetAttribute("spell", "Portal: ".. cityList[i])
fs = b:CreateFontString("MageTaxi_Text"..i)
	fs:SetFontObject("GameFontGreenSmall")
	fs:SetJustifyH("LEFT")
	s:SetText(cityList[i])
	fs:SetPoint("LEFT", "MageTaxi_City"..i, "RIGHT", 0,0)
Only things that really matter are the orange spots. The issue is with Thunder Bluff. The icon name puts it as "ThunderBluff" (no space), but I still want it to appear as "Thunder Bluff" in the font string. Is there a way to do this without having to assign a temp var for difference?
  Reply With Quote
02-10-10, 12:19 PM   #4
nightcracker
A Molten Giant
 
nightcracker's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 716
Originally Posted by ChaosInc View Post
Thanks, I realized the fix last night already, but good to see it verified (and it works btw).

One thing though that I've run into that maybe someone can help me with. I have ZERO understanding of string manipulation and it has me painted into a corner atm.

Code:
cityList = {
	[3] = "ThunderBluff",
}

b = CreateFrame("BUTTON", "MageTaxi_Port"..i, f, "SecureActionButtonTemplate")
	b:SetPoint("RIGHT", "MageTaxi_City"..i, "LEFT", 0, 0)
	b:SetHeight(18)
	b:SetWidth(18)
	b.texture = b:CreateTexture("MageTaxi_Spell"..i)
	b.texture:SetAllPoints(b)
	b.texture:SetTexture("Interface\\Icons\\Spell_Arcane_Portal".. cityList[i])
	b:SetAttribute("type", "spell")
	b:SetAttribute("spell", "Portal: ".. cityList[i])
fs = b:CreateFontString("MageTaxi_Text"..i)
	fs:SetFontObject("GameFontGreenSmall")
	fs:SetJustifyH("LEFT")
	s:SetText(cityList[i])
	fs:SetPoint("LEFT", "MageTaxi_City"..i, "RIGHT", 0,0)
Only things that really matter are the orange spots. The issue is with Thunder Bluff. The icon name puts it as "ThunderBluff" (no space), but I still want it to appear as "Thunder Bluff" in the font string. Is there a way to do this without having to assign a temp var for difference?
lua Code:
  1. s:SetText(gsub(cityList[i], "([a-z]+)([A-Z][a-z]+)", "%1 %2"))

I really like that I've done my regex homework so I can solve problems like this
__________________
Three things are certain,
Death, taxes and site not found,
You, victim of one.

Last edited by nightcracker : 02-10-10 at 12:22 PM.
  Reply With Quote
02-10-10, 04:31 PM   #5
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
Originally Posted by nightcracker View Post
lua Code:
  1. s:SetText(gsub(cityList[i], "([a-z]+)([A-Z][a-z]+)", "%1 %2"))

I really like that I've done my regex homework so I can solve problems like this
Worked like a charm. Now mind explaining it to me? LOL
  Reply With Quote
02-10-10, 07:16 PM   #6
ArrchDK
A Fallenroot Satyr
 
ArrchDK's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 25
Originally Posted by ChaosInc View Post
Worked like a charm. Now mind explaining it to me? LOL
Info on gsub

The second argument ("([a-z]+)([A-Z][a-z]+)") looks for a lower case letter ([a-z]) followed by an uppercase letter ([A-Z]) followed by a lower case letter ([a-z]). So in the case of ThunderBluff, it would find "rBl" as the pattern. Something like LookingForGroup would find "gFo" and "rGr". It then substitutes it with the third argument ("%1 %2"). In this case, it is substituting the first letter (%1) and the second letter (%2), combined would be (%1%2) with (%1 %2); essentially adding a space inbetween them. So "rBl" becomes "r Bl" in the string, making "ThunderBluff" change to "Thunder Bluff"

I hope that's easier to understand than it is to explain =/
  Reply With Quote
02-10-10, 07:35 PM   #7
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Originally Posted by ArrchDK View Post
Info on gsub

The second argument ("([a-z]+)([A-Z][a-z]+)") looks for a lower case letter ([a-z]) followed by an uppercase letter ([A-Z]) followed by a lower case letter ([a-z]). So in the case of ThunderBluff, it would find "rBl" as the pattern. Something like LookingForGroup would find "gFo" and "rGr". It then substitutes it with the third argument ("%1 %2"). In this case, it is substituting the first letter (%1) and the second letter (%2), combined would be (%1%2) with (%1 %2); essentially adding a space inbetween them. So "rBl" becomes "r Bl" in the string, making "ThunderBluff" change to "Thunder Bluff"

I hope that's easier to understand than it is to explain =/
That's a better explanation than I could have given.

To be completely accurate, it's searching for a string of lowercase letters of length >=1 both before and after the single capital letter; but it's true that you don't really need that. Removing the + signs would make it behave exactly as described.

As it is, "ThunderBluff" yields one match: "hunderBluff", which in turn matches the subpatterns as "(hunder)(Bluff)" and therefore %1 == "hunder" and %2 == "Bluff", resulting in gsub replacing all instances of "hunderBluff" with "hunder Bluff", with a final result of "Thunder Bluff" since there's only one instance of that.

In any case, I think: "(%l)(%u)" would work just as well; but it doesn't really matter much.

Last edited by Akryn : 02-10-10 at 07:49 PM.
  Reply With Quote
02-10-10, 09:56 PM   #8
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
Originally Posted by ChaosInc View Post
Isn't just passing i doing the same thing, or am I not following this logic correctly?
Passing i requires the function setLoc and an additional separate function for each city button. Saving i into the frame allows you to just have the one function shared by all the buttons. It is just an efficiency thing, why create 8 functions to accomplish the same thing you can do with just 1.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Grr, I hate it when I miss stuff...


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off