TourGuide
[WoW-TourGuide.git] / OHFrame.lua
blob56756e376da39fe51c453ad871811c0e49b5784b
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, elapsed = 0, 0
13 local rows = {}
14 local frame, fader
17 local function OnShow()
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 frame:SetAlpha(0)
24 elapsed = 0
25 fader:Show()
26 end
29 function TourGuide:CreateObjectivePanel()
30 fader = CreateFrame("Frame")
31 fader:Hide()
32 fader:SetScript("OnUpdate", function(self, elap)
33 elapsed = elapsed + elap
34 if elapsed > 1 then
35 self:Hide()
36 frame:SetAlpha(1)
37 else frame:SetAlpha(elapsed) end
38 end)
40 frame = ww.SummonOptionHouseBaseFrame()
42 for i=1,NUMROWS do
43 local row = CreateFrame("Button", nil, frame)
44 row:SetPoint("TOPLEFT", i == 1 and frame or rows[i-1], i == 1 and "TOPLEFT" or "BOTTOMLEFT", 0, -ROWOFFSET)
45 row:SetWidth(630)
46 row:SetHeight(ROWHEIGHT)
48 local check = ww.SummonCheckBox(ROWHEIGHT, row, "TOPLEFT", ROWOFFSET, 0)
49 local icon = ww.SummonTexture(row, ROWHEIGHT, ROWHEIGHT, nil, "TOPLEFT", check, "TOPRIGHT", ROWOFFSET, 0)
50 local text = ww.SummonFontString(row, nil, nil, "GameFontNormal", nil, "LEFT", icon, "RIGHT", ROWOFFSET, 0)
51 local detail = ww.SummonFontString(row, nil, nil, "GameFontNormal", nil, "RIGHT", -ROWOFFSET, 0)
52 detail:SetPoint("LEFT", text, "RIGHT", ROWOFFSET*3, 0)
53 detail:SetJustifyH("RIGHT")
54 detail:SetTextColor(240/255, 121/255, 2/255)
56 check:SetScript("OnClick", function(f) self:SetTurnedIn(row.i, f:GetChecked()) end)
58 row.text = text
59 row.detail = detail
60 row.check = check
61 row.icon = icon
62 rows[i] = row
63 end
65 frame:EnableMouseWheel()
66 frame:SetScript("OnMouseWheel", function(f, val)
67 offset = offset - val
68 if (offset + NUMROWS) > #self.actions then offset = #self.actions - NUMROWS end
69 if offset < 0 then offset = 0 end
70 self:UpdateOHPanel()
71 end)
73 frame:SetScript("OnShow", OnShow)
74 OnShow()
75 return frame
76 end
79 local accepted = {}
80 function TourGuide:UpdateOHPanel()
81 if not frame or not frame:IsVisible() then return end
83 for i in pairs(accepted) do accepted[i] = nil end
85 for i=1,offset-1 do
86 local action, name, note, logi, complete, hasitem, turnedin, fullquestname = self:GetObjectiveInfo(i + offset)
87 if name then
88 local shortname = name:gsub("%s%(Part %d+%)", "")
89 if action == "ACCEPT" and not turnedin and (accepted[name] or not accepted[shortname]) then
90 accepted[name] = true
91 accepted[shortname] = true
92 end
93 end
94 end
96 for i,row in ipairs(rows) do
97 row.i = i + offset
98 local action, name, note, logi, complete, hasitem, turnedin, fullquestname = self:GetObjectiveInfo(i + offset)
99 if not name then row:Hide()
100 else
101 row:Show()
103 local shortname = name:gsub("%s%(Part %d+%)", "")
104 logi = not turnedin and (accepted[name] or not accepted[shortname]) and logi
105 complete = not turnedin and (accepted[name] or not accepted[shortname]) and complete
106 local checked = turnedin or action == "ACCEPT" and logi or action == "COMPLETE" and complete
108 if action == "ACCEPT" and logi then
109 accepted[name] = true
110 accepted[shortname] = true
113 row.icon:SetTexture(self.icons[action])
114 row.text:SetText(name)
115 row.detail:SetText(note)
116 row.check:SetChecked(checked)