Thread Tools Display Modes
08-02-12, 12:41 PM   #1
Brainn
A Frostmaul Preserver
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 263
Request: Var SetEmpty

Code:
RDX.RegisterFeature({
	name = "Variable: SetEmpty";
	title = "Vars SetEmpty";
	category = VFLI.i18n("Variables");
	multiple = true;
	test = true;
	IsPossible = function(state)
		if not state:Slot("DesignFrame") then return nil; end
		if not state:Slot("EmitPaintPreamble") then return nil; end
		return true;
	end;
	ExposeFeature = function(desc, state, errs)		
		if not desc then VFL.AddError(errs, VFLI.i18n("No descriptor.")); return nil; end
		if not RDX._CheckVariableNameValidity(desc.name, state, errs) then return nil; end
		if not RDXDAL.FindSet(desc.set) then
			VFL.AddError(errs, VFLI.i18n("Invalid set pointer."));
			return nil;
		end
		state:AddSlot("Var_" .. desc.name);
		state:AddSlot("BoolVar_" .. desc.name .. "_flag");
		return true;
	end;
	ApplyFeature = function(desc, state)
		-- Add edit to menu
		if desc.set and desc.set.class == "file" and desc.showlink and not string.find(desc.set.file, "Builtin") then
			local path = desc.set.file; local afname = desc.name;
			state:GetContainingWindowState():Attach("Menu", true, function(win, mnu)
				table.insert(mnu, {
					text = VFLI.i18n("Edit File Set: ") .. afname;
					OnClick = function()
						VFL.poptree:Release();
						RDXDB.OpenObject(path, "Edit", VFLDIALOG);
					end;
				});
			end);
		end
		-- On closure, acquire the set locally
		state:Attach(state:Slot("EmitClosure"), true, function(code)
			code:AppendCode([[
local ]] .. desc.name .. [[ = RDXDAL.FindSet(]] .. Serialize(desc.set) .. [[);
if not ]] .. desc.name .. [[:IsOpen() then ]] .. desc.name .. [[:Open(); end
]]);
		end);
		-- On paint preamble, create flag and grade variables
		state:Attach(state:Slot("EmitPaintPreamble"), true, function(code)
		if desc.test then
			code:AppendCode([[
local ]] .. desc.name .. [[_flag = true;
]]);
		else
			code:AppendCode([[
local ]] .. desc.name .. [[_flag = ]] .. desc.name .. [[:IsEmpty();
]]);
		end
		end);
		-- Event hint: update on sort.
		local set = RDXDAL.FindSet(desc.set);
		local mux = state:GetContainingWindowState():GetSlotValue("Multiplexer");
		mux:Event_SetDeltaMask(set, 2); -- mask 2 = generic repaint
	end;
	UIFromDescriptor = function(desc, parent, state)
		local ui = VFLUI.CompoundFrame:new(parent);

		local name = VFLUI.LabeledEdit:new(ui, 100); name:Show();
		name:SetText(VFLI.i18n("Variable Name"));
		if desc and desc.name then name.editBox:SetText(desc.name); end
		ui:InsertFrame(name);

		local chk_showlink = VFLUI.Checkbox:new(ui); chk_showlink:Show();
		chk_showlink:SetText(VFLI.i18n("Show link to edit this filterfile from window. Only working for set class file"));
		if desc and desc.showlink then chk_showlink:SetChecked(true); else chk_showlink:SetChecked(); end
		ui:InsertFrame(chk_showlink);

		local sf = RDXDAL.SetFinder:new(ui); sf:Show();
		ui:InsertFrame(sf); 
		if desc and desc.set then sf:SetDescriptor(desc.set); end

		function ui:GetDescriptor()
			return {
				feature = "Variable: SetEmpty";
				name = name.editBox:GetText();
				showlink = chk_showlink:GetChecked();
				set = sf:GetDescriptor();
			};
		end

		return ui;
	end;
	CreateDescriptor = function()
		return { feature = "Variable: SetEmpty"; name = "setempty"; };
	end;
});
returns true if the specified set does not contain any units.
i have been using this a long time now to show/hide a texture if my earthshield buff is not active on anyone in the raid, the only problem i have with this is it is sometimes not updating if i overwrite someone elses earthshield, i believe this propably has something to do with some event missing for update or some problem in the basic set engine. maybe you can look into it sigg, but you should put it somewhere onto the list of 1000000 things with very low priority
  Reply With Quote
08-06-12, 12:07 PM   #2
sigg
Featured Artist
 
sigg's Avatar
Featured
Join Date: Aug 2008
Posts: 1,251
Add into RDX9

__________________
RDX manager
Sigg
  Reply With Quote

WoWInterface » Featured Projects » OpenRDX » OpenRDX Support » OpenRDX: Feature Requests » Request: Var SetEmpty

Thread Tools
Display Modes

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