View Single Post
05-15-12, 12:42 AM   #20
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Well, here is one problem:

Originally Posted by lerb View Post
Code:
		local function Grid_AddBorder(f)
			CreateBorderLight(frame, LeUI.media.bordersize, LeUI.bordercolor, LeUI.bordercolor, LeUI.bordercolor, 2)
Here is a more commented version of what should, theoretically, be working code:

Lua Code:
  1. local function SkinGrid()
  2.     print("SkinGrid")
  3.  
  4.     -- IMPORTANT: If Grid2 gives each of its parts a cluttery global name,
  5.     -- leave this line commented. Otherwise, uncomment it and adjust as
  6.     -- needed:
  7.  
  8.     -- local GridFrame = Grid and Grid:GetModule("GridFrame")
  9.  
  10.     if GridFrame and GridFrame.registeredFrames then
  11.         -- Grid is already loaded. Go ahead and skin the frames.
  12.         print("Grid is loaded!")
  13.  
  14.         -- This function will be used to override the default border
  15.         -- coloring method on a Grid frame.
  16.         local function Grid_SetBackdropBorderColor(frame, r, g, b, a)
  17.             if a and a == 0 then
  18.                 -- Instead of hiding the border when it's not showing a
  19.                 -- status, we want to reset it to the default color.
  20.                 frame:SetBorderColor()
  21.             else
  22.                 -- Otherwise, we want to ignore the status's alpha value
  23.                 -- and always show the border at 100% opacity.
  24.                 frame:SetBorderColor(r, g, b)
  25.             end
  26.         end
  27.  
  28.         -- This function adds a border to a single frame.
  29.         local function Grid_AddBorder(frame)
  30.             -- Check if we already added a border to this frame:
  31.             if not frame.SetBorderColor then
  32.                 -- Tell Grid the border is very small, so it will adjust
  33.                 -- the insets on the frame accordingly:
  34.  
  35.                 -- IMPORTANT: You will need to find the equivalent
  36.                 -- function in Grid2 and change/uncomment this line:
  37.  
  38.                 -- frame:SetBorderSize(0.1)
  39.  
  40.                 -- Actually add the border:
  41.                 CreateBorderChat(frame,
  42.                     LeUI.media.bordersize,
  43.                     LeUI.bordercolor,
  44.                     LeUI.bordercolor,
  45.                     LeUI.bordercolor,
  46.                     2)
  47.  
  48.                 -- Hook the frame's border coloring method:
  49.  
  50.                 -- IMPORTANT: Find out if this is necessary with Grid2
  51.                 -- and/or !Beautycase, and uncomment this line if so:
  52.  
  53.                 -- frame.SetBackdropBorderColor = Grid_SetBackdropBorderColor
  54.  
  55.  
  56.  
  57.                 -- Disable Grid's method for changing the border size:
  58.  
  59.                 -- IMPORTANT: Find the equiavlent function in Grid2 and
  60.                 -- change/uncomment this line:
  61.  
  62.                 -- frame.SetBorderSize = noop
  63.             end
  64.         end
  65.  
  66.         -- Loop through all of the frames that have already been created
  67.         -- and add a border to each one:
  68.         for frameName in pairs(GridFrame.registeredFrames) do
  69.             Grid_AddBorder(_G[frameName])
  70.             print("Added border to", frameName, "in SkinGrid.")
  71.         end
  72.  
  73.         -- Hook Grid's RegisterFrame method to catch new frames when
  74.         -- they are created in the future:
  75.         hooksecurefunc(GridFrame, "RegisterFrame", function(frame)
  76.             Grid_AddBorder(frame)
  77.             print("Added border to", frame:GetName(), "in RegisterFrame hook.")
  78.         end
  79.  
  80.         -- Return true, since the function successfully ran.
  81.         return true
  82.     end
  83. end
  84.  
  85. if not SkinGrid() then
  86.     print("Grid not loaded.")
  87.     -- A nil return value indicates that Grid was not loaded yet,
  88.     -- so we need to watch for that:
  89.     local f = CreateFrame("Frame")
  90.     f:RegisterEvent("ADDON_LOADED")
  91.     f:RegisterEvent("PLAYER_LOGIN")
  92.     f:SetScript("OnEvent", function()
  93.         if SkinGrid() then
  94.             -- Grid is now loaded, and has been skinned.
  95.             -- Stop listening for addon loading events.
  96.             print("Grid is now loaded. Stop listening.")
  97.             f:UnregisterAllEvents()
  98.             f:SetScript("OnEvent", nil)
  99.             SkinGrid = nil
  100.         else
  101.             -- If SkinGrid() returned nil again, that means Grid is
  102.             -- still not loaded, so we should keep listening.
  103.             print("Grid is still not loaded. Keep listening.")
  104.         end
  105.     end)
  106. end

Comments beginning with "IMPORTANT:" indicate sections that may need to be changed depending on how !Beautycase and/or Grid2 work internally. The code should work as-is, but if something doesn't work, those are the sections you should check first.

Not tested in-game, so may contain syntax errors.

Last edited by Phanx : 05-15-12 at 12:44 AM.
  Reply With Quote