View Single Post
05-05-13, 08:20 PM   #15
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I don't provide any support or tutoring via PM, as that defeats the point of having a community forum, so I'm just replying here.

Originally Posted by Anja
<link>

that was my last update stand, thanks for your help!!
I rewrote your frame creation code using only Lua (no XML). Not tested in an actual raid, but the window shows up fine in-game with no errors. Remove the reference to Raidstring.xml in your TOC file, and replace the contents of your Lua file with this.

Code:
local f = CreateFrame("Frame", "Raidstring", UIParent)
f:SetPoint("CENTER")
f:SetSize(400, 125)
f:Hide()

f:SetBackdrop({
	bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background", tileSize = 32, tile = true,
	edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border", edgeSize = 32,
	insets = { left = 11, right = 12, top = 12, bottom = 11 }
})

f.Header = f:CreateTexture(nil, "ARTWORK")
f.Header:SetPoint("CENTER", f, "TOP")
f.Header:SetSize(139, 40)
f.Header:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header")
f.Header:SetTexCoord(58/256, 196/256, 0, 39/64)

f.HeaderText = f:CreateFontString(nil, "OVERLAY", "GameFontNormal")
f.HeaderText:SetPoint("CENTER", f.Header)
f.HeaderText:SetText("Raidstring")

f:EnableMouse(true)
f:SetMovable(true)
f.TitleRegion = f:CreateTitleRegion()
f.TitleRegion:SetAllPoints(f.Header)

f.EditBox = CreateFrame("EditBox", "$parentEditBox", f, "InputBoxTemplate")
f.EditBox:SetPoint("TOP", f.Header, "BOTTOM")
f.EditBox:SetSize(300, 16)
f.EditBox:SetAltArrowKeyMode(false)
f.EditBox:SetAutoFocus(false)
f.EditBox:SetFontObject(GameFontHighlightSmall)
--f.EditBox:SetHistoryLines(0)
f.EditBox:SetMaxLetters(0) -- no limit

f.EditBox:SetScript("OnEnterPressed", function()
	f:Hide()
	f:SortRaid(self:GetText())
end)
f.EditBox:SetScript("OnEscapePressed", function()
	f:Hide()
end)

f.CloseButton = CreateFrame("Button", "$parentCloseButton", f, "OptionsButtonTemplate")
f.CloseButton:SetPoint("BOTTOM", 0, 20)
f.CloseButton:SetText(APPLY)
f.CloseButton:SetScript("OnClick", function()
	f:Hide()
	f:SortRaid(self:GetText())
end)

f:SetScript("OnHide", function()
	f.EditBox:ClearHistory()
end)

------------------------------------------------------------------------

local current, numInGroup = {}, {}

local function UpdateRaidState()
	wipe(numInGroup)
	wipe(current)
	for i = 1, GetNumGroupMembers() do
		local name, rank, subgroup, level, class, fileName, zone, online, isDead, role, isML = GetRaidRosterInfo(i)
		current[name] = { index = i, group = subgroup }
		numInGroup[subgroup] = (numInGroup[subgroup] or 0) + 1
	end
end

function f:SortRaid(str)
	if not str or strlen(str) == 0 or not IsInRaid() then
		return
	end
	if not UnitIsGroupLeader("player") and not UnitIsGroupAssistant("player") then
		return DEFAULT_CHAT_FRAME:AddMessage(format("%sRaidString:|r %s", NORMAL_FONT_COLOR_CODE, "You must be raid leader or promoted to sort the raid!"))
	end

	-- Get a snapshot of the current raid layout:
	UpdateRaidState()

	local wanted = {}
	-- Build a map of the desired raid layout:
	for name, group in string.gmatch(str, "([^&:]+):(%d+)") do
		-- Ignore named players not in the raid.
		if current[name] then
			wanted[name] = group
		end
	end

	-- Look for players not in the wanted group and move them:
	for name, group in pairs(wanted) do
		if current[name].group ~= group then
			if numInGroup[group] then
				if not numInGroup[group] or numInGroup[group] < 5 then
					-- Just move them:
					SetRaidSubgroup(current[name].index, group)
				else
					-- Look for someone to swap with:
					for xname, xdata in pairs(current) do
						if xdata.group == group and wanted[xname] ~= group then
							-- Do the swap:
							SwapRaidSubgroup(current[name].index, xdata.index)
							-- Update the snapshot:
							UpdateRaidState()
						end
					end
				end
			else
				SetRaidSubgroup(current[name].index, group)
			end
		end
	end
end

------------------------------------------------------------------------

SLASH_RAIDSTRING1 = "/rs"

SlashCmdList["RAIDSTRING"] = function()
	if not IsInRaid() then
		return
	end
	local name = UnitName("player")
	local realm = GetRealmName()
	local guild = IsInGuild and GetGuildInfo("player") or ""

	local xml = "<RaidInfo><Info>Raidassist</Info><Password>W2Any"..realm.."dEAv"..name.."2AxaS</Password><Realm>"..realm.."</Realm><Guild>"..guild.."</Guild><Name>"..name.."</Name><PlayerInfos>"
	for i = 1, GetNumGroupMembers() do
		local localizedClass, englishClass = UnitClass("raid"..i)
		local name, online = UnitName("raid"..i)
		xml = xml.."<key"..i.."><name>"..name.."</name><class>"..englishClass.."</class></key"..i..">"
	end
	xml = xml.."</PlayerInfos></RaidInfo>"

	f.EditBox:SetText(xml)
	f.EditBox:HighlightText()
	f:Show()
end

------------------------------------------------------------------------

SLASH_MAKERAID1 = "/rm"

SlashCmdList["MAKERAID"] = function()
	f:Show()
end
__________________
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.

Last edited by Phanx : 05-13-13 at 10:27 PM.
  Reply With Quote