PageRenderTime 146ms CodeModel.GetById 41ms app.highlight 32ms RepoModel.GetById 68ms app.codeStats 0ms

/Tukui/modules/loot/rollframe.lua

http://github.com/Asphyxia/Tukui
Lua | 342 lines | 283 code | 55 blank | 4 comment | 28 complexity | 8770b018c667d4256885dbddedb31c61 MD5 | raw file
  1local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2--[[
  3		this is an edited version of teksloot
  4		all credits of this mod goes to tekhub
  5--]]
  6
  7if C["loot"].rolllootframe ~= true then return end
  8
  9local backdrop = {
 10	bgFile = C["media"].blank, tile = true, tileSize = 0,
 11	edgeFile = C["media"].blank, edgeSize = T.mult,
 12	insets = {left = -T.mult, right = -T.mult, top = -T.mult, bottom = -T.mult},
 13}
 14
 15local function ClickRoll(frame)
 16	RollOnLoot(frame.parent.rollid, frame.rolltype)
 17end
 18
 19
 20local function HideTip() GameTooltip:Hide() end
 21local function HideTip2() GameTooltip:Hide(); ResetCursor() end
 22
 23
 24local rolltypes = {"need", "greed", "disenchant", [0] = "pass"}
 25local function SetTip(frame)
 26	GameTooltip:SetOwner(frame, "ANCHOR_RIGHT")
 27	GameTooltip:SetText(frame.tiptext)
 28	if frame:IsEnabled() == 0 then GameTooltip:AddLine("|cffff3333Cannot roll") end
 29	for name,roll in pairs(frame.parent.rolls) do if roll == rolltypes[frame.rolltype] then GameTooltip:AddLine(name, 1, 1, 1) end end
 30	GameTooltip:Show()
 31end
 32
 33
 34local function SetItemTip(frame)
 35	if not frame.link then return end
 36	GameTooltip:SetOwner(frame, "ANCHOR_TOPLEFT")
 37	GameTooltip:SetHyperlink(frame.link)
 38	if IsShiftKeyDown() then GameTooltip_ShowCompareItem() end
 39	if IsModifiedClick("DRESSUP") then ShowInspectCursor() else ResetCursor() end
 40end
 41
 42
 43local function ItemOnUpdate(self)
 44	if IsShiftKeyDown() then GameTooltip_ShowCompareItem() end
 45	CursorOnUpdate(self)
 46end
 47
 48
 49local function LootClick(frame)
 50	if IsControlKeyDown() then DressUpItemLink(frame.link)
 51	elseif IsShiftKeyDown() then ChatEdit_InsertLink(frame.link) end
 52end
 53
 54
 55local cancelled_rolls = {}
 56local function OnEvent(frame, event, rollid)
 57	cancelled_rolls[rollid] = true
 58	if frame.rollid ~= rollid then return end
 59
 60	frame.rollid = nil
 61	frame.time = nil
 62	frame:Hide()
 63end
 64
 65
 66local function StatusUpdate(frame)
 67	local t = GetLootRollTimeLeft(frame.parent.rollid)
 68	local perc = t / frame.parent.time
 69	frame.spark:Point("CENTER", frame, "LEFT", perc * frame:GetWidth(), 0)
 70	frame:SetValue(t)
 71end
 72
 73
 74local function CreateRollButton(parent, ntex, ptex, htex, rolltype, tiptext, ...)
 75	local f = CreateFrame("Button", nil, parent)
 76	f:SetPoint(...)
 77	f:Width(28)
 78	f:Height(28)
 79	f:SetNormalTexture(ntex)
 80	if ptex then f:SetPushedTexture(ptex) end
 81	f:SetHighlightTexture(htex)
 82	f.rolltype = rolltype
 83	f.parent = parent
 84	f.tiptext = tiptext
 85	f:SetScript("OnEnter", SetTip)
 86	f:SetScript("OnLeave", HideTip)
 87	f:SetScript("OnClick", ClickRoll)
 88	f:SetMotionScriptsWhileDisabled(true)
 89	local txt = f:CreateFontString(nil, nil)
 90	txt:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
 91	txt:SetPoint("CENTER", 0, rolltype == 2 and 1 or rolltype == 0 and -1.2 or 0)
 92	return f, txt
 93end
 94
 95
 96local function CreateRollFrame()
 97	local frame = CreateFrame("Frame", nil, UIParent)
 98	frame:Width(328)
 99	frame:Height(22)
100	frame:SetBackdrop(backdrop)
101	frame:SetBackdropColor(0.1, 0.1, 0.1, 1)
102	frame:SetScript("OnEvent", OnEvent)
103	frame:RegisterEvent("CANCEL_LOOT_ROLL")
104	frame:Hide()
105
106	local button = CreateFrame("Button", nil, frame)
107	button:SetPoint("LEFT", -24, 0)
108	button:Width(22)
109	button:Height(22)
110	button:SetScript("OnEnter", SetItemTip)
111	button:SetScript("OnLeave", HideTip2)
112	button:SetScript("OnUpdate", ItemOnUpdate)
113	button:SetScript("OnClick", LootClick)
114
115	frame.button = button
116
117	local buttonborder = CreateFrame("Frame", nil, button)
118	buttonborder:Width(22)
119	buttonborder:Height(22)
120	buttonborder:SetPoint("CENTER", button, "CENTER")
121	buttonborder:SetBackdrop(backdrop)
122	buttonborder:SetBackdropColor(1, 1, 1, 0)
123	
124	local buttonborder2 = CreateFrame("Frame", nil, button)
125	buttonborder2:Width(24)
126	buttonborder2:Height(24)
127	buttonborder2:SetFrameLevel(buttonborder:GetFrameLevel()+1)
128	buttonborder2:SetPoint("CENTER", button, "CENTER")
129	buttonborder2:SetBackdrop(backdrop)
130	buttonborder2:SetBackdropColor(0, 0, 0, 0)
131	buttonborder2:SetBackdropBorderColor(0,0,0,1)
132	
133
134	frame.buttonborder = buttonborder
135
136	local tfade = frame:CreateTexture(nil, "BORDER")
137	tfade:Point("TOPLEFT", frame, "TOPLEFT", 4, 0)
138	tfade:Point("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -4, 0)
139	tfade:SetTexture("Interface\\ChatFrame\\ChatFrameBackground")
140	tfade:SetBlendMode("ADD")
141	tfade:SetGradientAlpha("VERTICAL", .1, .1, .1, 0, .1, .1, .1, 0)
142
143	local status = CreateFrame("StatusBar", nil, frame)
144	status:Width(326)
145	status:Height(20)
146	status:SetPoint("CENTER", frame, "CENTER", 0, 0)
147	status:SetScript("OnUpdate", StatusUpdate)
148	status:SetFrameLevel(status:GetFrameLevel()-1)
149	status:SetStatusBarTexture(C["media"].normTex)
150	status:SetStatusBarColor(.8, .8, .8, .9)
151	status.parent = frame
152	frame.status = status
153
154	local spark = frame:CreateTexture(nil, "OVERLAY")
155	spark:Width(14)
156	spark:Height(25)
157	spark:SetTexture("Interface\\CastingBar\\UI-CastingBar-Spark")
158	spark:SetBlendMode("ADD")
159	status.spark = spark
160
161	local need, needtext = CreateRollButton(frame, "Interface\\Buttons\\UI-GroupLoot-Dice-Up", "Interface\\Buttons\\UI-GroupLoot-Dice-Highlight", "Interface\\Buttons\\UI-GroupLoot-Dice-Down", 1, NEED, "LEFT", frame.button, "RIGHT", T.Scale(5), T.Scale(-1))
162	local greed, greedtext = CreateRollButton(frame, "Interface\\Buttons\\UI-GroupLoot-Coin-Up", "Interface\\Buttons\\UI-GroupLoot-Coin-Highlight", "Interface\\Buttons\\UI-GroupLoot-Coin-Down", 2, GREED, "LEFT", need, "RIGHT", 0, T.Scale(-1))
163	local de, detext
164	de, detext = CreateRollButton(frame, "Interface\\Buttons\\UI-GroupLoot-DE-Up", "Interface\\Buttons\\UI-GroupLoot-DE-Highlight", "Interface\\Buttons\\UI-GroupLoot-DE-Down", 3, ROLL_DISENCHANT, "LEFT", greed, "RIGHT", 0, T.Scale(-1))
165	local pass, passtext = CreateRollButton(frame, "Interface\\Buttons\\UI-GroupLoot-Pass-Up", nil, "Interface\\Buttons\\UI-GroupLoot-Pass-Down", 0, PASS, "LEFT", de or greed, "RIGHT", 0, T.Scale(2.2))
166	frame.needbutt, frame.greedbutt, frame.disenchantbutt = need, greed, de
167	frame.need, frame.greed, frame.pass, frame.disenchant = needtext, greedtext, passtext, detext
168
169	local bind = frame:CreateFontString()
170	bind:Point("LEFT", pass, "RIGHT", 3, 1)
171	bind:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
172	frame.fsbind = bind
173
174	local loot = frame:CreateFontString(nil, "ARTWORK")
175	loot:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
176	loot:Point("LEFT", bind, "RIGHT", 0, 0)
177	loot:Point("RIGHT", frame, "RIGHT", -5, 0)
178	loot:Height(10)
179	loot:Width(200)
180	loot:SetJustifyH("LEFT")
181	frame.fsloot = loot
182
183	frame.rolls = {}
184
185	return frame
186end
187
188
189local anchor = CreateFrame("Button", "TukuiRollAnchor", UIParent)
190anchor:Width(300) 
191anchor:Height(22)
192anchor:SetBackdrop(backdrop)
193anchor:SetBackdropColor(0.25, 0.25, 0.25, 1)
194local label = anchor:CreateFontString(nil, "ARTWORK")
195label:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
196label:SetAllPoints(anchor)
197label:SetText(L.move_roll)
198anchor:SetMovable(true)
199anchor:EnableMouse(false)
200anchor:SetTemplate("Default")
201anchor:SetAlpha(0)
202anchor:SetBackdropBorderColor(1, 0, 0, 1)
203
204local frames = {}
205
206local f = CreateRollFrame() -- Create one for good measure
207f:Point("BOTTOMLEFT", next(frames) and frames[#frames] or anchor, "TOPLEFT", 0, 4)
208table.insert(frames, f)
209
210local function GetFrame()
211	for i,f in ipairs(frames) do
212		if not f.rollid then return f end
213	end
214
215	local f = CreateRollFrame()
216	f:Point("BOTTOMLEFT", next(frames) and frames[#frames] or anchor, "TOPLEFT", 0, 4)
217	table.insert(frames, f)
218	return f
219end
220
221
222local function START_LOOT_ROLL(rollid, time)
223	if cancelled_rolls[rollid] then return end
224
225	local f = GetFrame()
226	f.rollid = rollid
227	f.time = time
228	for i in pairs(f.rolls) do f.rolls[i] = nil end
229	f.need:SetText(0)
230	f.greed:SetText(0)
231	f.pass:SetText(0)
232	f.disenchant:SetText(0)
233
234	local texture, name, count, quality, bop, canNeed, canGreed, canDisenchant = GetLootRollItemInfo(rollid)
235	f.button:SetNormalTexture(texture)
236	f.button.link = GetLootRollItemLink(rollid)
237
238	if canNeed then f.needbutt:Enable() else f.needbutt:Disable() end
239	if canGreed then f.greedbutt:Enable() else f.greedbutt:Disable() end
240	if canDisenchant then f.disenchantbutt:Enable() else f.disenchantbutt:Disable() end
241	SetDesaturation(f.needbutt:GetNormalTexture(), not canNeed)
242	SetDesaturation(f.greedbutt:GetNormalTexture(), not canGreed)
243	SetDesaturation(f.disenchantbutt:GetNormalTexture(), not canDisenchant)
244
245
246	f.fsbind:SetText(bop and "BoP" or "BoE")
247	f.fsbind:SetVertexColor(bop and 1 or .3, bop and .3 or 1, bop and .1 or .3)
248
249	local color = ITEM_QUALITY_COLORS[quality]
250	f.fsloot:SetVertexColor(color.r, color.g, color.b)
251	f.fsloot:SetText(name)
252
253	f:SetBackdropBorderColor(color.r, color.g, color.b, 1)
254	f.buttonborder:SetBackdropBorderColor(color.r, color.g, color.b, 1)
255	f.status:SetStatusBarColor(color.r, color.g, color.b, .7)
256
257	f.status:SetMinMaxValues(0, time)
258	f.status:SetValue(time)
259
260	f:SetPoint("CENTER", WorldFrame, "CENTER")
261	f:Show()
262end
263
264
265local locale = GetLocale()
266local rollpairs = locale == "deDE" and {
267	["(.*) passt automatisch bei (.+), weil [ersi]+ den Gegenstand nicht benutzen kann.$"]  = "pass",
268	["(.*) würfelt nicht für: (.+|r)$"] = "pass",
269	["(.*) hat für (.+) 'Gier' ausgewählt"] = "greed",
270	["(.*) hat für (.+) 'Bedarf' ausgewählt"] = "need",
271	["(.*) hat für '(.+)' Entzauberung gewählt."]  = "disenchant",
272} or locale == "frFR" and {
273	["(.*) a passé pour : (.+) parce qu'((il)|(elle)) ne peut pas ramasser cette objet.$"]  = "pass",
274	["(.*) a passé pour : (.+)"]  = "pass",
275	["(.*) a choisi Cupidité pour : (.+)"] = "greed",
276	["(.*) a choisi Besoin pour : (.+)"]  = "need",
277	["(.*) a choisi Désenchantement pour : (.+)"]  = "disenchant",
278} or locale == "zhTW" and {
279	["(.*)自動放棄:(.+),因為"]  = "pass",
280	["(.*)放棄了:(.+)"] = "pass",
281	["(.*)選擇了貪婪優先:(.+)"] = "greed",
282	["(.*)選擇了需求優先:(.+)"] = "need",
283	["(.*)選擇分解:(.+)"] = "disenchant",
284} or locale == "ruRU" and {
285	["(.*) автоматически передает предмет (.+), поскольку не может его забрать"] = "pass",
286	["(.*) пропускает розыгрыш предмета \"(.+)\", поскольку не может его забрать"] = "pass",
287	["(.*) отказывается от предмета (.+)%."]  = "pass",
288	["Разыгрывается: (.+)%. (.*): \"Не откажусь\""] = "greed",
289	["Разыгрывается: (.+)%. (.*): \"Мне это нужно\""] = "need",
290	["Разыгрывается: (.+)%. (.*): \"Распылить\""] = "disenchant",
291} or locale == "koKR" and {
292	["(.+)님이 획득할 수 없는 아이템이어서 자동으로 주사위 굴리기를 포기했습니다: (.+)"] = "pass",
293	["(.+)님이 주사위 굴리기를 포기했습니다: (.+)"] = "pass",
294	["(.+)님이 차비를 선택했습니다: (.+)"] = "greed",
295	["(.+)님이 입찰을 선택했습니다: (.+)"] = "need",
296	["(.+)님이 마력 추출을 선택했습니다: (.+)"] = "disenchant",
297} or {
298	["^(.*) automatically passed on: (.+) because s?he cannot loot that item.$"] = "pass",
299	["^(.*) passed on: (.+|r)$"]  = "pass",
300	["(.*) has selected Greed for: (.+)"] = "greed",
301	["(.*) has selected Need for: (.+)"]  = "need",
302	["(.*) has selected Disenchant for: (.+)"]  = "disenchant",
303}
304local function ParseRollChoice(msg)
305	for i,v in pairs(rollpairs) do
306		local _, _, playername, itemname = string.find(msg, i)
307		if locale == "ruRU" and (v == "greed" or v == "need" or v == "disenchant")  then 
308			local temp = playername
309			playername = itemname
310			itemname = temp
311		end 
312		if playername and itemname and playername ~= "Everyone" then return playername, itemname, v end
313	end
314end
315
316local function CHAT_MSG_LOOT(msg)
317	local playername, itemname, rolltype = ParseRollChoice(msg)
318	if playername and itemname and rolltype then
319		for _,f in ipairs(frames) do
320			if f.rollid and f.button.link == itemname and not f.rolls[playername] then
321				f.rolls[playername] = rolltype
322				f[rolltype]:SetText(tonumber(f[rolltype]:GetText()) + 1)
323				return
324			end
325		end
326	end
327end
328
329anchor:RegisterEvent("ADDON_LOADED")
330anchor:SetScript("OnEvent", function(frame, event, addon)
331	if addon ~= "Tukui" then return end
332
333	anchor:UnregisterEvent("ADDON_LOADED")
334	anchor:RegisterEvent("START_LOOT_ROLL")
335	anchor:RegisterEvent("CHAT_MSG_LOOT")
336	UIParent:UnregisterEvent("START_LOOT_ROLL")
337	UIParent:UnregisterEvent("CANCEL_LOOT_ROLL")
338
339	anchor:SetScript("OnEvent", function(frame, event, ...) if event == "CHAT_MSG_LOOT" then return CHAT_MSG_LOOT(...) else return START_LOOT_ROLL(...) end end)
340
341	anchor:Point("CENTER", UIParent, "CENTER", 0, -100)
342end)