/Tukui/modules/skins/bags.lua

http://github.com/Asphyxia/Tukui · Lua · 347 lines · 288 code · 48 blank · 11 comment · 55 complexity · ba5f8bf1666beb10ba780ce01e5f2b72 MD5 · raw file

  1. local T, C, L = unpack( select( 2, ... ) )
  2. if C["bags"].enable == true then return end
  3. local function LoadSkin()
  4. local QUEST_ITEM_STRING = select( 10, GetAuctionItemClasses() )
  5. local function UpdateBorderColors( button )
  6. button:SetBackdropBorderColor( unpack( C["media"].bordercolor ) )
  7. if button.type and button.type == QUEST_ITEM_STRING then
  8. button:SetBackdropBorderColor( 1, 0.2, 0.2 )
  9. elseif button.quality and button.quality > 1 then
  10. local r, g, b = GetItemQualityColor( button.quality )
  11. button:SetBackdropBorderColor( r, g, b )
  12. end
  13. end
  14. local function SkinButton( button )
  15. if not button.skinned then
  16. button:StripTextures()
  17. button:SetTemplate( "Default", true )
  18. button:StyleButton()
  19. local icon = _G[button:GetName() .. "IconTexture"]
  20. icon:ClearAllPoints()
  21. icon:Point( "TOPLEFT", 2, -2 )
  22. icon:Point( "BOTTOMRIGHT", -2, 2 )
  23. icon:SetTexCoord( .08, .92, .08, .92 )
  24. if _G[button:GetName() .. "IconQuestTexture"] then
  25. _G[button:GetName() .. "IconQuestTexture"]:Kill()
  26. end
  27. button.skinned = true
  28. end
  29. end
  30. local function SkinBagButtons( container, button )
  31. SkinButton( button )
  32. local texture, _, _, _, _, _, itemLink = GetContainerItemInfo( container:GetID(), button:GetID() )
  33. local isQuestItem = GetContainerItemQuestInfo( container:GetID(), button:GetID() )
  34. _G[button:GetName() .. "IconTexture"]:SetTexture( texture )
  35. button.type = nil
  36. button.quality = nil
  37. button.ilink = itemLink
  38. if button.ilink then
  39. button.name, _, button.quality, _, _, button.type = GetItemInfo( button.ilink )
  40. end
  41. if isQuestItem then
  42. button.type = QUEST_ITEM_STRING
  43. end
  44. UpdateBorderColors( button )
  45. end
  46. local function SkinBags()
  47. for i = 1, NUM_CONTAINER_FRAMES, 1 do
  48. local container = _G["ContainerFrame" .. i]
  49. if container and not container.backdrop then
  50. container:SetFrameStrata( "HIGH" )
  51. container:StripTextures( true )
  52. container:CreateBackdrop( "Transparent" )
  53. --container.backdrop:Point( "TOPLEFT", 2, -2 )
  54. --container.backdrop:Point( "BOTTOMRIGHT", -2, 2 )
  55. --T.SkinCloseButton( _G[container:GetName() .. "CloseButton"] )
  56. container.backdrop:Point("TOPLEFT", 6, -2)
  57. container.backdrop:Point("BOTTOMRIGHT", -4, 4)
  58. T.SkinCloseButton(_G[container:GetName().."CloseButton"])
  59. _G[container:GetName().."CloseButton"]:Point("TOPRIGHT",container.backdrop,"TOPRIGHT",0,3)
  60. container:HookScript( "OnShow", function( self )
  61. if self and self.size then
  62. for b = 1, self.size, 1 do
  63. local button = _G[self:GetName() .. "Item" .. b]
  64. SkinBagButtons( self, button )
  65. end
  66. end
  67. end )
  68. if i == 1 then
  69. BackpackTokenFrame:StripTextures( true )
  70. for i = 1, MAX_WATCHED_TOKENS do
  71. _G["BackpackTokenFrameToken" .. i].icon:SetTexCoord( .08, .92, .08, .92 )
  72. _G["BackpackTokenFrameToken" .. i]:CreateBackdrop( "Default" )
  73. _G["BackpackTokenFrameToken" .. i].backdrop:Point( "TOPLEFT", _G["BackpackTokenFrameToken" .. i].icon, "TOPLEFT", -2, 2 )
  74. _G["BackpackTokenFrameToken" .. i].backdrop:Point( "BOTTOMRIGHT", _G["BackpackTokenFrameToken" .. i].icon, "BOTTOMRIGHT", 2, -2 )
  75. _G["BackpackTokenFrameToken" .. i].icon:Point("LEFT", _G["BackpackTokenFrameToken" .. i].count, "RIGHT", 2, 0 )
  76. end
  77. end
  78. end
  79. if container and container.size then
  80. for b = 1, container.size, 1 do
  81. local button = _G[container:GetName() .. "Item" .. b]
  82. SkinBagButtons( container, button )
  83. end
  84. end
  85. end
  86. end
  87. -- Backpack + Bags bar
  88. for i = 0, 3 do
  89. local backpack = MainMenuBarBackpackButton
  90. local bags = _G["CharacterBag"..i.."Slot"]
  91. local bags2 = _G["CharacterBag"..(i-1).."Slot"]
  92. backpack:StyleButton(true)
  93. bags:StyleButton(true)
  94. T.SkinButton(backpack)
  95. T.SkinButton(bags)
  96. backpack:SetParent(UIParent)
  97. bags:SetParent(backpack)
  98. if TukuiCubeRight then
  99. backpack:ClearAllPoints()
  100. backpack:Point("BOTTOMRIGHT", TukuiInfoRight, "TOPRIGHT", 0, 130)
  101. backpack:Hide() -- Show/Hide bags when clicking on the right cube
  102. TukuiCubeRight:EnableMouse(true)
  103. TukuiCubeRight:SetScript("OnMouseDown", function(self)
  104. if MainMenuBarBackpackButton:IsShown() then
  105. MainMenuBarBackpackButton:Hide()
  106. else
  107. MainMenuBarBackpackButton:Show()
  108. end
  109. end)
  110. elseif C.chat.background then
  111. backpack:SetSize(30,30)
  112. backpack:ClearAllPoints()
  113. backpack:Point("BOTTOMRIGHT", TukuiChatBackgroundRight, "BOTTOMLEFT", -5, 0)
  114. else
  115. backpack:Hide()
  116. end
  117. bags:ClearAllPoints()
  118. if i == 0 then
  119. bags:Point("BOTTOM", backpack,"TOP", 0, 4)
  120. else
  121. bags:Point("BOTTOM", bags2, "TOP", 0, 4)
  122. end
  123. bags:SetSize(backpack:GetWidth(), backpack:GetHeight())
  124. local icons = { "MainMenuBarBackpackButtonIconTexture", "CharacterBag0SlotIconTexture",
  125. "CharacterBag1SlotIconTexture", "CharacterBag2SlotIconTexture", "CharacterBag3SlotIconTexture",}
  126. for _, object in pairs(icons) do
  127. _G[object]:SetTexCoord(.08, .92, .08, .92)
  128. _G[object]:ClearAllPoints()
  129. _G[object]:SetAllPoints()
  130. _G[object]:Point("TOPLEFT", 2, -2)
  131. _G[object]:Point("BOTTOMRIGHT", -2, 2)
  132. end
  133. end
  134. hooksecurefunc( "BankFrameItemButton_Update", function( button )
  135. if not BankFrame.backdrop then
  136. BankFrame:StripTextures( true )
  137. BankFrame:CreateBackdrop( "Transparent" )
  138. BankFrame.backdrop:Point( "TOPLEFT", 0, 0 )
  139. BankFrame.backdrop:Point( "BOTTOMRIGHT", -4, 70 )
  140. T.SkinButton( BankFramePurchaseButton, true )
  141. T.SkinCloseButton( BankCloseButton )
  142. BankFrame.backdrop2 = CreateFrame( "Frame", nil, BankFrame )
  143. BankFrame.backdrop2:SetTemplate( "Default" )
  144. BankFrame.backdrop2:Point( "TOPLEFT", BankFrameItem1, "TOPLEFT", -8, 8 )
  145. BankFrame.backdrop2:Point( "BOTTOMRIGHT", BankFrameItem28, "BOTTOMRIGHT", 8, -8 )
  146. BankFrame.backdrop3 = CreateFrame( "Frame", nil, BankFrame )
  147. BankFrame.backdrop3:SetTemplate( "Default" )
  148. BankFrame.backdrop3:Point( "TOPLEFT", BankFrameBag1, "TOPLEFT", -8, 8 )
  149. BankFrame.backdrop3:Point( "BOTTOMRIGHT", BankFrameBag7, "BOTTOMRIGHT", 8, -8 )
  150. end
  151. SkinButton( button )
  152. local inventoryID = button:GetInventorySlot()
  153. local textureName = GetInventoryItemTexture( "player", inventoryID )
  154. if( textureName ) then
  155. _G[button:GetName() .. "IconTexture"]:SetTexture( textureName )
  156. elseif( button.isBag ) then
  157. local _, slotTextureName = GetInventorySlotInfo( strsub( button:GetName(), 10 ) )
  158. _G[button:GetName() .. "IconTexture"]:SetTexture( slotTextureName )
  159. end
  160. if not button.isBag then
  161. local texture, _, _, _, _, _, itemLink = GetContainerItemInfo( BANK_CONTAINER, button:GetID() )
  162. local isQuestItem = GetContainerItemQuestInfo( BANK_CONTAINER, button:GetID() )
  163. button.type = nil
  164. button.ilink = itemLink
  165. button.quality = nil
  166. if button.ilink then
  167. button.name, _, button.quality, _, _, button.type = GetItemInfo( button.ilink )
  168. end
  169. if isQuestItem then
  170. button.type = QUEST_ITEM_STRING
  171. end
  172. UpdateBorderColors( button )
  173. end
  174. local highlight = _G[button:GetName() .. "HighlightFrameTexture"]
  175. if highlight and not highlight.skinned then
  176. highlight:SetTexture(0,1,0,0.3)
  177. highlight.SetTexture = T.dummy
  178. highlight:ClearAllPoints()
  179. highlight:Point( "TOPLEFT", 2, -2 )
  180. highlight:Point( "BOTTOMRIGHT", -2, 2 )
  181. highlight.skinned = true
  182. end
  183. end )
  184. hooksecurefunc( "updateContainerFrameAnchors", function()
  185. local frame, xOffset, yOffset, screenHeight, freeScreenHeight, leftMostPoint, column
  186. local screenWidth = GetScreenWidth()
  187. local containerScale = 1
  188. local leftLimit = 0
  189. if( BankFrame:IsShown() ) then
  190. leftLimit = BankFrame:GetRight() - 25
  191. end
  192. while( containerScale > CONTAINER_SCALE ) do
  193. screenHeight = GetScreenHeight() / containerScale
  194. xOffset = CONTAINER_OFFSET_X / containerScale
  195. yOffset = CONTAINER_OFFSET_Y / containerScale
  196. freeScreenHeight = screenHeight - yOffset
  197. leftMostPoint = screenWidth - xOffset
  198. column = 1
  199. local frameHeight
  200. for index, frameName in ipairs( ContainerFrame1.bags ) do
  201. frameHeight = _G[frameName]:GetHeight()
  202. if( freeScreenHeight < frameHeight ) then
  203. column = column + 1
  204. leftMostPoint = screenWidth - ( column * CONTAINER_WIDTH * containerScale ) - xOffset
  205. freeScreenHeight = screenHeight - yOffset
  206. end
  207. freeScreenHeight = freeScreenHeight - frameHeight - VISIBLE_CONTAINER_SPACING
  208. end
  209. if( leftMostPoint < leftLimit ) then
  210. containerScale = containerScale - 0.01
  211. else
  212. break
  213. end
  214. end
  215. if( containerScale < CONTAINER_SCALE ) then
  216. containerScale = CONTAINER_SCALE
  217. end
  218. screenHeight = GetScreenHeight() / containerScale;
  219. -- Adjust the start anchor for bags depending on the multibars
  220. xOffset = CONTAINER_OFFSET_X / containerScale;
  221. yOffset = CONTAINER_OFFSET_Y / containerScale;
  222. -- freeScreenHeight determines when to start a new column of bags
  223. freeScreenHeight = screenHeight - yOffset;
  224. column = 0;
  225. local bagsPerColumn = 0
  226. for index, frameName in ipairs(ContainerFrame1.bags) do
  227. frame = _G[frameName];
  228. frame:SetScale(1);
  229. if ( index == 1 ) then
  230. -- First bag
  231. frame:SetPoint("BOTTOMRIGHT", TukuiInfoRight, "BOTTOMRIGHT", 4, TukuiInfoRight:GetHeight()+2 );
  232. bagsPerColumn = bagsPerColumn + 1
  233. elseif ( freeScreenHeight < frame:GetHeight() ) then
  234. -- Start a new column
  235. column = column + 1;
  236. freeScreenHeight = screenHeight - yOffset;
  237. if column > 1 then
  238. frame:SetPoint("BOTTOMRIGHT", ContainerFrame1.bags[(index - bagsPerColumn) - 1], "BOTTOMLEFT", -(CONTAINER_SPACING -6), 0 );
  239. else
  240. frame:SetPoint("BOTTOMRIGHT", ContainerFrame1.bags[index - bagsPerColumn], "BOTTOMLEFT", -(CONTAINER_SPACING -6 ), 0 );
  241. end
  242. bagsPerColumn = 0
  243. else
  244. -- Anchor to the previous bag
  245. frame:SetPoint("BOTTOMRIGHT", ContainerFrame1.bags[index - 1], "TOPRIGHT", 0, CONTAINER_SPACING);
  246. bagsPerColumn = bagsPerColumn + 1
  247. end
  248. freeScreenHeight = freeScreenHeight - frame:GetHeight() - VISIBLE_CONTAINER_SPACING;
  249. end
  250. end)
  251. local bags = CreateFrame( "Frame" )
  252. bags:RegisterEvent( "BAG_UPDATE" )
  253. bags:RegisterEvent( "ITEM_LOCK_CHANGED" )
  254. bags:RegisterEvent( "BAG_CLOSED")
  255. bags:SetScript( "OnEvent", SkinBags )
  256. SkinBags()
  257. end
  258. local SearchBags = function(self)
  259. local Search = string.lower(self:GetText())
  260. for i = 1, NUM_CONTAINER_FRAMES, 1 do
  261. local Container = _G["ContainerFrame"..i]
  262. if Container and Container.size then
  263. for b = 1, Container.size, 1 do
  264. local Button = _G[Container:GetName().."Item"..b]
  265. local ItemLink = select(7, GetContainerItemInfo(Container:GetID(), Button:GetID()))
  266. if ItemLink then
  267. local ItemName = string.lower(GetItemInfo(ItemLink))
  268. if string.find(ItemName, Search) then
  269. _G[Button:GetName().."IconTexture"]:SetDesaturated(false)
  270. else
  271. _G[Button:GetName().."IconTexture"]:SetDesaturated(true)
  272. end
  273. end
  274. end
  275. end
  276. end
  277. end
  278. local OnEscapePressed = function(self)
  279. self:SetAutoFocus(false)
  280. self:ClearFocus()
  281. SearchBags(self)
  282. end
  283. -- Bar
  284. local frame = CreateFrame("Frame", nil, ContainerFrame1)
  285. frame:CreatePanel(nil, 164, 16, "TOP", ContainerFrame1, "TOP", 2, -28)
  286. frame:SetFrameLevel(ContainerFrame1:GetFrameLevel() + 1)
  287. frame:SetFrameStrata("HIGH")
  288. -- Editbox
  289. frame.edit = CreateFrame("Editbox", nil, frame)
  290. frame.edit:Point("TOPLEFT", 2, 0)
  291. frame.edit:Point("BOTTOMRIGHT", -2, -1)
  292. frame.edit:SetFrameLevel(frame:GetFrameLevel() + 1)
  293. frame.edit:SetMaxLetters(20)
  294. frame.edit:SetAutoFocus(false)
  295. frame.edit:SetFont(C.media.font, 12)
  296. frame.edit:SetScript("OnEscapePressed", OnEscapePressed)
  297. frame.edit:SetScript("OnEnterPressed", OnEscapePressed)
  298. frame.edit:SetScript("OnTextChanged", SearchBags)
  299. tinsert( T.SkinFuncs["Tukui"], LoadSkin )