vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --[[ MovableBags.lua |
2 | Author: Pos |
||
3 | Version 1.1a |
||
4 | |||
5 | 24/12/2004 - Initial Release |
||
6 | 24/12/2004 - Updated to include bank bags |
||
7 | 25/12/2004 - bug fixes and streamlined code |
||
8 | 01/01/2005 - fix for dead areas on screen |
||
9 | 02/01/2005 - Better Default Positions |
||
10 | 13/01/2005 - Fixed up by CTMod developers |
||
11 | ]] |
||
12 | |||
13 | MOVABLEBAGS_NUMBAGS = 11; |
||
14 | MOVABLEBAGS_LOWID = 0; |
||
15 | MOVABLEBAGS_HIGHID = 10; |
||
16 | MovableBags_Config = { }; |
||
17 | |||
18 | -- 0-4 are the normal bags, 5-10 are bank bags |
||
19 | MovableBags_DefaultPositions = { |
||
20 | [-2] = { "BOTTOMRIGHT", "UIParent", "BOTTOMRIGHT", -250, 650 }, |
||
21 | [0] = { "BOTTOMRIGHT", "UIParent", "BOTTOMRIGHT", -50, 300 }, |
||
22 | [1] = { "BOTTOMRIGHT", "UIParent", "BOTTOMRIGHT", -250, 300 }, |
||
23 | [2] = { "BOTTOMRIGHT", "UIParent", "BOTTOMRIGHT", -450, 300 }, |
||
24 | [3] = { "BOTTOMRIGHT", "UIParent", "BOTTOMRIGHT", -50, 500 }, |
||
25 | [4] = { "BOTTOMRIGHT", "UIParent", "BOTTOMRIGHT", -250, 500 }, |
||
26 | [5] = { "TOPLEFT", "UIParent", "TOPLEFT", 50, -650 }, |
||
27 | [6] = { "TOPLEFT", "UIParent", "TOPLEFT", 250, -650 }, |
||
28 | [7] = { "TOPLEFT", "UIParent", "TOPLEFT", 450, -650 }, |
||
29 | [8] = { "TOPLEFT", "UIParent", "TOPLEFT", 650, -650 }, |
||
30 | [9] = { "TOPLEFT", "UIParent", "TOPLEFT", 400, -50 }, |
||
31 | [10] = { "TOPLEFT", "UIParent", "TOPLEFT", 400, -300 }, |
||
32 | }; |
||
33 | |||
34 | function MovableBags_updateContainerFrameAnchors() |
||
35 | movablebags_oldupdateContainerFrameAnchors(); |
||
36 | |||
37 | for i=1, NUM_CONTAINER_FRAMES, 1 do |
||
38 | local containerFrame = getglobal("ContainerFrame"..i); |
||
39 | local id = containerFrame:GetID(); |
||
40 | if ( MovableBags_DefaultPositions[id] ) then |
||
41 | containerFrame:ClearAllPoints(); |
||
42 | containerFrame:SetPoint("TOPRIGHT","Bag"..id.."Mover","TOPRIGHT",34,0); |
||
43 | end |
||
44 | end |
||
45 | end |
||
46 | |||
47 | --called to update the visibility of the movers, depending on locked status and visibility of the bags |
||
48 | function MovableBags_UpdateVisible() |
||
49 | local i = 0; |
||
50 | MovableBags_HideAll(); |
||
51 | |||
52 | if(MovableBags_Config.Mode == "Locked") then |
||
53 | --no checking if bags are visible to show movers |
||
54 | return; |
||
55 | end |
||
56 | |||
57 | for i=1, NUM_CONTAINER_FRAMES, 1 do |
||
58 | local containerFrame = getglobal("ContainerFrame"..i); |
||
59 | local id = containerFrame:GetID(); |
||
60 | if ( MovableBags_DefaultPositions[id] ) then |
||
61 | local mover = getglobal("Bag"..id.."Mover"); |
||
62 | if (containerFrame:IsVisible() ) then |
||
63 | mover:Show(); |
||
64 | end |
||
65 | end |
||
66 | end |
||
67 | end |
||
68 | |||
69 | function MovableBags_HideAll() |
||
70 | for k, v in MovableBags_DefaultPositions do |
||
71 | local mover = getglobal("Bag"..k.."Mover"); |
||
72 | mover:Hide(); |
||
73 | end |
||
74 | end |
||
75 | |||
76 | --hooks into the containerframes on show/hide, to show/hide the movers |
||
77 | function MovableBags_ContainerFrame_OnHide() |
||
78 | movablebags_oldContainerFrame_OnHide(); |
||
79 | if ( this:GetID() < MOVABLEBAGS_NUMBAGS ) then |
||
80 | local mover = getglobal("Bag"..this:GetID().."Mover"); |
||
81 | if ( not mover and this:GetID() == KEYRING_CONTAINER ) then |
||
82 | MovableBags_UpdateVisible(); |
||
83 | return; |
||
84 | end |
||
85 | mover:Hide(); |
||
86 | end |
||
87 | end |
||
88 | |||
89 | function MovableBags_ContainerFrame_OnShow() |
||
90 | movablebags_oldContainerFrame_OnShow(); |
||
91 | if ( this:GetID() < MOVABLEBAGS_NUMBAGS and MovableBags_Config.Mode == "Movable") then |
||
92 | local mover = getglobal("Bag"..this:GetID().."Mover"); |
||
93 | if ( not mover and this:GetID() == KEYRING_CONTAINER ) then |
||
94 | local shownContainerID = IsBagOpen(KEYRING_CONTAINER); |
||
95 | mover = getglobal("Bag"..shownContainerID.."Mover"); |
||
96 | end |
||
97 | mover:Show(); |
||
98 | end |
||
99 | end |
||
100 | |||
101 | function MovableBags_OnLoad() |
||
102 | this:RegisterEvent("VARIABLES_LOADED"); |
||
103 | this:RegisterEvent("UNIT_NAME_UPDATE"); |
||
104 | |||
105 | |||
106 | |||
107 | end |
||
108 | |||
109 | function MovableBags_OnEvent() |
||
110 | if (event == "VARIABLES_LOADED") then |
||
111 | |||
112 | SlashCmdList["MOVABLEBAGS"] = MovableBags_SlashHandler; |
||
113 | SLASH_MOVABLEBAGS1 = "/movablebags"; |
||
114 | SLASH_MOVABLEBAGS2 = "/bags"; |
||
115 | |||
116 | MovableBags_UpdateVisible(); |
||
117 | --function hooks |
||
118 | --hooking in VARIABLES_LOADED so if something else hooks the functions, hopefully they do it before me, so they dont interfere |
||
119 | movablebags_oldupdateContainerFrameAnchors = updateContainerFrameAnchors; |
||
120 | updateContainerFrameAnchors = MovableBags_updateContainerFrameAnchors; |
||
121 | |||
122 | movablebags_oldContainerFrame_OnShow = ContainerFrame_OnShow; |
||
123 | ContainerFrame_OnShow = MovableBags_ContainerFrame_OnShow; |
||
124 | |||
125 | movablebags_oldContainerFrame_OnHide = ContainerFrame_OnHide; |
||
126 | ContainerFrame_OnHide = MovableBags_ContainerFrame_OnHide; |
||
127 | return; |
||
128 | end |
||
129 | end |
||
130 | |||
131 | |||
132 | function MovableBags_SlashHandler(arg) |
||
133 | arg = string.lower(arg); |
||
134 | |||
135 | if (arg == "lock") then |
||
136 | MovableBags_Config.Mode = "Locked"; |
||
137 | MovableBags_UpdateVisible(); |
||
138 | DEFAULT_CHAT_FRAME:AddMessage("Bags are now LOCKED"); |
||
139 | elseif (arg == "unlock") then |
||
140 | MovableBags_Config.Mode = "Movable"; |
||
141 | MovableBags_UpdateVisible(); |
||
142 | DEFAULT_CHAT_FRAME:AddMessage("Bags are now UNLOCKED"); |
||
143 | elseif (arg == "reset") then |
||
144 | for i=0,10,1 do |
||
145 | local mover = getglobal("Bag"..i.."Mover"); |
||
146 | local pos = MovableBags_DefaultPositions[i]; |
||
147 | mover:ClearAllPoints(); |
||
148 | mover:SetPoint(pos[1],pos[2],pos[3],pos[4],pos[5]); |
||
149 | end |
||
150 | else |
||
151 | DEFAULT_CHAT_FRAME:AddMessage("Usage: /movablebags unlock | lock | reset"); |
||
152 | DEFAULT_CHAT_FRAME:AddMessage("unlock lets you move the bags around independantly of each other (default)"); |
||
153 | DEFAULT_CHAT_FRAME:AddMessage("lock locks the bags into the position you last moved them to"); |
||
154 | DEFAULT_CHAT_FRAME:AddMessage("Reset will return all bags to the default positions"); |
||
155 | DEFAULT_CHAT_FRAME:AddMessage("Bags are currently "..MovableBags_Config.Mode); |
||
156 | end |
||
157 | |||
158 | end |
||
159 | |||
160 | function MovableBags_Function(modId) |
||
161 | local val = CT_Mods[modId]["modStatus"]; |
||
162 | if ( val == "on" ) then |
||
163 | CT_Print("<CTMod> Bags are now movable.", 1.0, 1.0, 0); |
||
164 | for i=0,10,1 do |
||
165 | getglobal("Bag"..i.."Mover"):Show(); |
||
166 | end |
||
167 | MovableBags_Config.Mode = "Movable"; |
||
168 | MovableBags_UpdateVisible(); |
||
169 | else |
||
170 | CT_Print("<CTMod> Bags are now locked to their positions.", 1.0, 1.0, 0); |
||
171 | for i=0,10,1 do |
||
172 | getglobal("Bag"..i.."Mover"):Hide(); |
||
173 | end |
||
174 | MovableBags_Config.Mode = "Locked"; |
||
175 | end |
||
176 | end |
||
177 | function MovableBags_InitFunction(modId) |
||
178 | local val = CT_Mods[modId]["modStatus"]; |
||
179 | if ( val == "on" ) then |
||
180 | for i=0,10,1 do |
||
181 | getglobal("Bag"..i.."Mover"):Show(); |
||
182 | end |
||
183 | MovableBags_Config.Mode = "Movable"; |
||
184 | MovableBags_UpdateVisible(); |
||
185 | else |
||
186 | for i=0,10,1 do |
||
187 | getglobal("Bag"..i.."Mover"):Hide(); |
||
188 | end |
||
189 | MovableBags_Config.Mode = "Locked"; |
||
190 | end |
||
191 | end |
||
192 | |||
193 | function MovableBags_ResetPositions() |
||
194 | CT_Print("<CTMod> Bag positions have been reset.", 1, 1, 0); |
||
195 | for i=0,10,1 do |
||
196 | local mover = getglobal("Bag"..i.."Mover"); |
||
197 | local pos = MovableBags_DefaultPositions[i]; |
||
198 | mover:ClearAllPoints(); |
||
199 | mover:SetPoint(pos[1],pos[2],pos[3],pos[4],pos[5]); |
||
200 | end |
||
201 | end |
||
202 | |||
203 | if ( CT_RegisterMod ) then |
||
204 | CT_RegisterMod("Movable Bags", "Unlocks bags", 5, "Interface\\Icons\\INV_Misc_Bag_10", "Allows you to move your bags wherever you want them.\nMove by holding and dragging the bag nameplate.", "off", nil, MovableBags_Function, MovableBags_InitFunction); |
||
205 | CT_RegisterMod("Reset Bags", "Resets bags", 5, "Interface\\Icons\\INV_Misc_Bag_10_Green", "Resets the bag position to the default positions.", "switch", nil, MovableBags_ResetPositions); |
||
206 | end |