VuhDoPanelConfigTools.lua 5.53 KB
Newer Older
humfras's avatar
humfras committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
local _;
VUHDO_GLOBAL_ICONS = { };

local GI_SCAN_MAX = 200001;
VUHDO_GI_SCAN_IDX = GI_SCAN_MAX;

local GetSpellInfo = GetSpellInfo;
local pairs = pairs;


--
function VUHDO_removeFromModel(aPanelNum, anOrderNum)
	tremove(VUHDO_PANEL_MODELS[aPanelNum], anOrderNum);
	VUHDO_initDynamicPanelModels();
end



--
function VUHDO_insertIntoModel(aPanelNum, anOrderNum, anIsLeft, aModelId)
	tinsert(VUHDO_PANEL_MODELS[aPanelNum], anOrderNum + (anIsLeft and 0 or 1), aModelId)
	VUHDO_initDynamicPanelModels();
end



--
function VUHDO_rewritePanelModels()
	for tCnt = 1, VUHDO_MAX_PANELS do
		VUHDO_PANEL_SETUP[tCnt]["MODEL"]["groups"] = VUHDO_PANEL_MODELS[tCnt];
	end
end



--
function VUHDO_tableCount(anArray)
	local tCount = 0;
	for _ in pairs(anArray) do tCount = tCount + 1; end
	return tCount;
end



--
function VUHDO_getModelSafeName(anUnsafeName)
	return strtrim(gsub(anUnsafeName or "", "[.#]", " "));
end



--
function VUHDO_getOrCreateGroupOrderPanel(aParentPanelNum, aPanelNum)
	local tName = "Vd" .. aParentPanelNum .. "GrpOrd" .. aPanelNum;
	if not _G[tName] then
		local tPanel = CreateFrame("Frame", tName, _G["Vd" .. aParentPanelNum], "VuhDoGrpOrdTemplate");
		VUHDO_fixFrameLevels(false, tPanel, 2, tPanel:GetChildren());
	end

	return _G[tName];
end



--
function VUHDO_getOrCreateGroupSelectPanel(aParentPanelNum, aPanelNum)
	local tName = "Vd" .. aParentPanelNum .. "GrpSel" .. aPanelNum;
	if not _G[tName] then
		local tPanel = CreateFrame("Frame", tName, _G["Vd" .. aParentPanelNum], "VuhDoGrpSelTemplate");
		VUHDO_fixFrameLevels(false, tPanel, 2, tPanel:GetChildren());
	end

	return _G[tName];
end



--
local sGroupOrderBarsRight = { };
function VUHDO_getConfigOrderBarRight(aPanelNum, anOrderNum)
	local tIndex = aPanelNum * 100 + anOrderNum;
	if not sGroupOrderBarsRight[tIndex] then
		local tPanel = VUHDO_getOrCreateGroupOrderPanel(aPanelNum, anOrderNum);
		sGroupOrderBarsRight[tIndex] = _G[tPanel:GetName() .. "InsTxuR"];
	end

	return sGroupOrderBarsRight[tIndex];
end



--
local sGroupOrderBarsLeft = { };
function VUHDO_getConfigOrderBarLeft(aPanelNum, anOrderNum)
	local tIndex = aPanelNum * 100 + anOrderNum;
	if not sGroupOrderBarsLeft[tIndex] then
		local tPanel = VUHDO_getOrCreateGroupOrderPanel(aPanelNum, anOrderNum);
		sGroupOrderBarsLeft[tIndex] = _G[tPanel:GetName() .. "InsTxuL"];
	end

	return sGroupOrderBarsLeft[tIndex];
end



--
local tSpellNameById;
function VUHDO_resolveSpellId(aSpellName)
	if tonumber(aSpellName or "x") then
		tSpellNameById = GetSpellInfo(tonumber(aSpellName));
		if tSpellNameById then
			return tSpellNameById;
		end
	end
	return aSpellName;
end



--
local tText, tTextById, tLabel;
function VUHDO_newOptionsSpellEditBoxCheckId(anEditBox)
	tLabel = _G[anEditBox:GetName() .. "Hint"];
	tText = anEditBox:GetText();
	tTextById = VUHDO_resolveSpellId(tText);

	if tText ~= tTextById then
		tTextById = strsub(tTextById, 1, 20);
		tLabel:SetText(tTextById);
	else
		tLabel:SetText("");
	end
end



--
local VUHDO_USED_BUFFS = { };
function VUHDO_updateGlobalIconList()
	table.wipe(VUHDO_USED_BUFFS);

	-- Add custom debuffs
	for _, tName in pairs(VUHDO_CONFIG["CUSTOM_DEBUFF"]["STORED"]) do
		VUHDO_USED_BUFFS[tName] = true;
	end

147 148 149 150 151
	-- Add spell traces
	for _, tName in pairs(VUHDO_CONFIG["SPELL_TRACE"]["STORED"]) do
		VUHDO_USED_BUFFS[tName] = true;
	end

humfras's avatar
humfras committed
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
	-- Add bouquet item buffs
	for _, tItems in pairs(VUHDO_BOUQUETS["STORED"]) do
		tItems = VUHDO_decompressIfCompressed(tItems);
		for _, tItem in pairs(tItems) do
		  --  tItem["name"] can be nil for some reason (maybe on compressing bouquets?)
			if tItem["name"] and not VUHDO_BOUQUET_BUFFS_SPECIAL[tItem["name"]] then
				VUHDO_USED_BUFFS[tItem["name"]] = true;
			end
		end
	end

	-- Add standard icons
	for _, tValues in pairs(VUHDO_CUSTOM_ICONS) do
		if tValues[2] then
			VUHDO_USED_BUFFS[tValues[1]] = true;
			VUHDO_GLOBAL_ICONS[tValues[1]] = tValues[2];
		end
	end

	-- Add standard ignore debuffs
	for tName, _  in pairs(VUHDO_DEBUFF_BLACKLIST) do
		VUHDO_USED_BUFFS[tName] = true;
	end

	-- Remove obsolete
	for tName, _ in pairs(VUHDO_GLOBAL_ICONS) do
		if not VUHDO_USED_BUFFS[tName] then
			VUHDO_GLOBAL_ICONS[tName] = nil;
		end
	end

	-- Add new
	for tName, _ in pairs(VUHDO_USED_BUFFS) do
		if (VUHDO_GLOBAL_ICONS[tName] == nil) then
			if tonumber(tName) then
				local _, _, tIcon = GetSpellInfo(tonumber(tName));
				VUHDO_GLOBAL_ICONS[tName] = tIcon;
			else
				VUHDO_GLOBAL_ICONS[tName] = "";
			end
		end
	end
end



--
local function VUHDO_tableContains(aTable, aValue)
	for _, tValue in pairs(aTable) do
		if tValue == aValue then return true; end
	end

	return false;
end



--
local tStep = 50;
local tRef;
local tName, _, tIcon;
local function VUHDO_scanNextGlobalIcons()
	if not VUHDO_tableContains(VUHDO_GLOBAL_ICONS, "") then
		return;
	end
	tRef = VUHDO_GLOBAL_ICONS;
	for tCnt = VUHDO_GI_SCAN_IDX + tStep , VUHDO_GI_SCAN_IDX, -1 do
		tName, _, tIcon = GetSpellInfo(tCnt);
		if tRef[tName] == "" then tRef[tName] = tIcon; end
	end

	VUHDO_GI_SCAN_IDX = VUHDO_GI_SCAN_IDX - tStep;

	if VUHDO_GI_SCAN_IDX < 1 then VUHDO_GI_SCAN_IDX = GI_SCAN_MAX; end
end



--
function VUHDO_optionsOnUpdate(self, aTimeDelta)
	VUHDO_scanNextGlobalIcons();
	VUHDO_updateRequestsInProgress();
end



--
function VUHDO_getGlobalIcon(aDeBuffName)
	if not aDeBuffName then return nil; end
	return GetSpellBookItemTexture(aDeBuffName) or VUHDO_GLOBAL_ICONS[aDeBuffName];
end