TourGuide
[WoW-TourGuide.git] / OHFrame.lua
blobac579a04c55272c74304a65482b87fb32bd7bc3b
3 local TourGuide = TourGuide
4 local OptionHouse = DongleStub("OptionHouse-1.0")
5 local ww = WidgetWarlock
6 WidgetWarlock = nil
9 local ROWHEIGHT = 26
10 local ROWOFFSET = 4
11 local NUMROWS = math.floor(305/(ROWHEIGHT+4))
14 local offset = 0
16 local L = {
17 Accepted = "Accepted",
18 Complete = "|cffF07902Complete",
19 Finished = "|cff00ff00Finished",
23 local function OnShow()
24 offset = TourGuide.current - NUMROWS/2 - 1
25 if offset < 0 then offset = 0
26 elseif (offset + NUMROWS) > #TourGuide.actions then offset = #TourGuide.actions - NUMROWS end
27 TourGuide:UpdateOHPanel()
28 end
31 function TourGuide:CreateOHPanel()
32 local self = TourGuide
34 local frame = ww.SummonOptionHouseBaseFrame()
36 frame.rows = {}
37 for i=1,NUMROWS do
38 local row = CreateFrame("Button", nil, frame)
39 row:SetPoint("TOPLEFT", i == 1 and frame or frame.rows[i-1], i == 1 and "TOPLEFT" or "BOTTOMLEFT", 0, -ROWOFFSET)
40 row:SetWidth(630)
41 row:SetHeight(ROWHEIGHT)
43 local check = ww.SummonCheckBox(ROWHEIGHT, row, "TOPLEFT", ROWOFFSET, 0)
44 local icon = ww.SummonTexture(row, ROWHEIGHT, ROWHEIGHT, nil, "TOPLEFT", check, "TOPRIGHT", ROWOFFSET, 0)
45 local text = ww.SummonFontString(row, nil, nil, "GameFontNormal", nil, "LEFT", icon, "RIGHT", ROWOFFSET, 0)
47 check:SetScript("OnClick", function(f)
48 self.turnedin[text:GetText()] = f:GetChecked()
49 self:UpdateOHPanel()
50 self:UpdateStatusFrame()
51 end)
53 row.text = text
54 row.status = status
55 row.check = check
56 row.icon = icon
57 frame.rows[i] = row
58 end
60 frame:EnableMouseWheel()
61 frame:SetScript("OnMouseWheel", function(f, val)
62 offset = offset - val
63 if offset < 0 then offset = 0
64 elseif (offset + NUMROWS) > #self.actions then offset = #self.actions - NUMROWS end
65 self:UpdateOHPanel()
66 end)
68 self.OHFrame = frame
69 frame:SetScript("OnShow", OnShow)
70 OnShow()
71 return frame
72 end
75 function TourGuide:UpdateOHPanel()
76 if not self.OHFrame or not self.OHFrame:IsVisible() then return end
77 for i,row in ipairs(self.OHFrame.rows) do
78 local action, name, note, logi, complete, itemstarted = self:GetObjectiveInfo(i+offset)
79 local checked = self.turnedin[name] or (action == "ACCEPT" and logi) or (action == "COMPLETE" and complete)
81 row.icon:SetTexture(self.icons[action])
82 row.text:SetText(name)
83 row.check:SetChecked(checked)
84 end
85 end
88 local _, title = GetAddOnInfo("TourGuide")
89 local author, version = GetAddOnMetadata("TourGuide", "Author"), GetAddOnMetadata("TourGuide", "Version")
90 local oh = OptionHouse:RegisterAddOn("Tour Guide", title, author, version)
91 oh:RegisterCategory("Eversong Woods", TourGuide.CreateOHPanel)