TOC and embed updates across the board
[WoW-TourGuide.git] / OHFrame.lua
blobf2418d95e87931c1195f226fccd66d34422c2c64
3 local TourGuide = TourGuide
4 local ww = WidgetWarlock
7 local ROWHEIGHT = 26
8 local ROWOFFSET = 4
9 local NUMROWS = math.floor(305/(ROWHEIGHT+4))
12 local offset = 0
13 local rows = {}
14 local frame
17 local function OnShow(self)
18 offset = TourGuide.current - NUMROWS/2 - 1
19 if offset < 0 then offset = 0
20 elseif (offset + NUMROWS) > #TourGuide.actions then offset = #TourGuide.actions - NUMROWS end
21 TourGuide:UpdateOHPanel()
23 self:SetAlpha(0)
24 self:SetScript("OnUpdate", ww.FadeIn)
25 end
28 function TourGuide:CreateObjectivePanel()
29 frame = CreateFrame("Frame", nil, UIParent)
31 for i=1,NUMROWS do
32 local row = CreateFrame("Button", nil, frame)
33 row:SetPoint("TOPLEFT", i == 1 and frame or rows[i-1], i == 1 and "TOPLEFT" or "BOTTOMLEFT", 0, -ROWOFFSET)
34 row:SetWidth(630)
35 row:SetHeight(ROWHEIGHT)
37 local check = ww.SummonCheckBox(ROWHEIGHT, row, "TOPLEFT", ROWOFFSET, 0)
38 local icon = ww.SummonTexture(row, nil, ROWHEIGHT, ROWHEIGHT, nil, "TOPLEFT", check, "TOPRIGHT", ROWOFFSET, 0)
39 local text = ww.SummonFontString(row, nil, "GameFontNormal", nil, "LEFT", icon, "RIGHT", ROWOFFSET, 0)
40 local detail = ww.SummonFontString(row, nil, "GameFontNormal", nil, "RIGHT", -ROWOFFSET, 0)
41 detail:SetPoint("LEFT", text, "RIGHT", ROWOFFSET*3, 0)
42 detail:SetJustifyH("RIGHT")
43 detail:SetTextColor(240/255, 121/255, 2/255)
45 check:SetScript("OnClick", function(f) self:SetTurnedIn(row.i, f:GetChecked()) end)
47 row.text = text
48 row.detail = detail
49 row.check = check
50 row.icon = icon
51 rows[i] = row
52 end
54 frame:EnableMouseWheel()
55 frame:SetScript("OnMouseWheel", function(f, val)
56 offset = offset - val
57 if (offset + NUMROWS) > #self.actions then offset = #self.actions - NUMROWS end
58 if offset < 0 then offset = 0 end
59 self:UpdateOHPanel()
60 end)
62 frame:SetScript("OnShow", OnShow)
63 ww.SetFadeTime(frame, 0.5)
64 OnShow(frame)
65 return frame
66 end
69 local accepted = {}
70 function TourGuide:UpdateOHPanel()
71 if not frame or not frame:IsVisible() then return end
73 for i in pairs(accepted) do accepted[i] = nil end
75 for i=1,offset-1 do
76 local action, name, note, logi, complete, hasitem, turnedin, fullquestname = self:GetObjectiveInfo(i + offset)
77 if name then
78 local shortname = name:gsub("%s%(Part %d+%)", "")
79 if action == "ACCEPT" and not turnedin and (accepted[name] or not accepted[shortname]) then
80 accepted[name] = true
81 accepted[shortname] = true
82 end
83 end
84 end
86 for i,row in ipairs(rows) do
87 row.i = i + offset
88 local action, name, note, logi, complete, hasitem, turnedin, fullquestname = self:GetObjectiveInfo(i + offset)
89 if not name then row:Hide()
90 else
91 row:Show()
93 local shortname = name:gsub("%s%(Part %d+%)", "")
94 logi = not turnedin and (accepted[name] or not accepted[shortname]) and logi
95 complete = not turnedin and (accepted[name] or not accepted[shortname]) and complete
96 local checked = turnedin or action == "ACCEPT" and logi or action == "COMPLETE" and complete
98 if action == "ACCEPT" and logi then
99 accepted[name] = true
100 accepted[shortname] = true
103 row.icon:SetTexture(self.icons[action])
104 row.text:SetText(name)
105 row.detail:SetText(note)
106 row.check:SetChecked(checked)