View Single Post
07-31-16, 02:19 PM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,323
I have this running in my development addon.

Lua Code:
  1. local tostring=tostring;
  2.  
  3. local ProxyLookup={};
  4. local ProxyMeta={__index={
  5.     Print=function(self,...)
  6.         local frame=ProxyLookup[self];
  7.         if frame then
  8.             local msg="";
  9.             for i=1,select("#",...) do msg=(msg~="" and msg.." " or "")..tostring(select(i,...)); end
  10.             frame:AddMessage(msg);
  11.             if not frame:IsShown() then FCF_StartAlertFlash(frame); end
  12.         end
  13.     end;
  14.  
  15.     Show=function(self)
  16.         local frame=ProxyLookup[self];
  17.         if frame then
  18.             local tab=_G[frame:GetName().."Tab"];
  19.             if not tab:IsShown() then
  20.                 frame:Show();
  21.                 tab:Show();
  22.                 FCF_DockFrame(frame,#FCFDock_GetChatFrames(GENERAL_CHAT_DOCK)+1,nil);
  23.             end
  24.         end
  25.     end;
  26.     Hide=function(self)
  27.         local frame=ProxyLookup[self];
  28.         if frame then
  29.             local tab=_G[frame:GetName().."Tab"];
  30.             if tab:IsShown() then-- Mimic FCF_Close(), but don't release frame
  31.                 FCF_UnDockFrame(frame);
  32.                 HideUIPanel(frame);
  33.                 tab:Hide();
  34.                 FCF_FlagMinimizedPositionReset(frame);
  35.                 if frame.minFrame and frame.minFrame:IsShown() then frame.minFrame:Hide(); end
  36.             end
  37.         end
  38.     end;
  39.  
  40.     SetShown=function(self,show)
  41.         local frame=ProxyLookup[self];
  42.         if frame then self[show and "Show" or "Hide"](self); end
  43.     end;
  44.     IsShown=function()
  45.         local frame=ProxyLookup[self];
  46.         if frame then return _G[frame:GetName().."Tab"]:IsShown(); end
  47.     end;
  48.  
  49.     Close=function(self)
  50.         local frame=ProxyLookup[self];
  51.         if frame then FCF_Close(frame); end
  52.     end;
  53. }};
  54.  
  55. hooksecurefunc("FCF_Close",function(frame,other)
  56.     frame=other or frame;
  57.     local proxy=ProxyLookup[frame];
  58.     if proxy then ProxyLookup[proxy],ProxyLookup[frame]=nil,nil; end
  59. end);
  60.  
  61. function CreateDebugMessageFrame(name,r,g,b,a)
  62.     local frame=FCF_OpenTemporaryWindow("SYSTEM");
  63.     ChatFrame_RemoveMessageGroup(frame,"SYSTEM");
  64.  
  65.     FCF_SetWindowName(frame,name,true);
  66.     if r and g and b then FCF_SetWindowColor(frame,r,g,b,true); end
  67.     if a then FCF_SetWindowAlpha(frame,a,true); end
  68.  
  69.     local proxy=setmetatable({},ProxyMeta);
  70.     ProxyLookup[proxy],ProxyLookup[frame]=frame,proxy;
  71.     return proxy;
  72. end
  73.  
  74. function CreateDebugPrint(...)
  75.     local frame=CreateDebugMessageFrame(...);
  76.     return function(...) return frame:Print(...); end,frame;
  77. end

Two global functions are available in this API, CreateDebugMessageFrame() and CreateDebugPrint(). The first returns a proxy object that can be used to print to and show/hide the frame as well as release the chat window to the default UI (closing it). The second quickly creates the frame and returns just the print handler function you can call to print to the window.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote