Adding magic localization table, deDE locale strings from decimad
[WoW-TourGuide.git] / OHFrame.lua
blob8a709fafd042a1174f6e0dd6d9ca120b0d0ffe53
3 local TourGuide = TourGuide
4 local L = TourGuide.Locale
5 local ww = WidgetWarlock
8 local ROWHEIGHT = 26
9 local ROWOFFSET = 4
10 local NUMROWS = math.floor(305/(ROWHEIGHT+4))
13 local offset = 0
14 local rows = {}
15 local frame, scrollbar, upbutt, downbutt
18 local function OnShow(self)
19 scrollbar:SetMinMaxValues(0, math.max(#TourGuide.actions - NUMROWS, 1))
20 scrollbar:SetValue((TourGuide.current or 0) - NUMROWS/2 - 1)
22 if TourGuide.guidechanged then TourGuide:UpdateOHPanel() end
24 self:SetAlpha(0)
25 self:SetScript("OnUpdate", ww.FadeIn)
26 end
29 local function HideTooltip() GameTooltip:Hide() end
31 local function ShowTooltip(f)
32 if f.text:GetStringWidth() <= f:GetWidth() then return end
34 GameTooltip:SetOwner(f, "ANCHOR_RIGHT")
35 GameTooltip:SetText(f.text:GetText(), nil, nil, nil, nil, true)
36 end
39 function TourGuide:CreateObjectivePanel()
40 frame = CreateFrame("Frame", nil, UIParent)
41 frame:SetFrameStrata("DIALOG")
43 scrollbar, upbutt, downbutt = ww.ConjureScrollBar(frame, true)
44 scrollbar:SetPoint("TOPRIGHT", frame, "TOPRIGHT", 0, -19)
45 scrollbar:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", 0, 16)
46 scrollbar:SetScript("OnValueChanged", function(f, val) self:UpdateOHPanel(val) end)
48 upbutt:SetScript("OnClick", function(f)
49 scrollbar:SetValue(offset - NUMROWS + 1)
50 PlaySound("UChatScrollButton")
51 end)
53 downbutt:SetScript("OnClick", function(f)
54 scrollbar:SetValue(offset + NUMROWS - 1)
55 PlaySound("UChatScrollButton")
56 end)
58 local function LevelCorrection(f) f:SetFrameLevel(frame:GetFrameLevel()+1); f:SetScript("OnShow", nil) end
59 for i=1,NUMROWS do
60 local row = CreateFrame("Button", nil, frame)
61 row:SetPoint("TOPLEFT", i == 1 and frame or rows[i-1], i == 1 and "TOPLEFT" or "BOTTOMLEFT", 0, -ROWOFFSET)
62 row:SetWidth(630)
63 row:SetHeight(ROWHEIGHT)
65 local check = ww.SummonCheckBox(ROWHEIGHT, row, "TOPLEFT", ROWOFFSET, 0)
66 local icon = ww.SummonTexture(row, nil, ROWHEIGHT, ROWHEIGHT, nil, "TOPLEFT", check, "TOPRIGHT", ROWOFFSET, 0)
67 local text = ww.SummonFontString(row, nil, "GameFontNormal", nil, "LEFT", icon, "RIGHT", ROWOFFSET, 0)
69 local detailhover = CreateFrame("Button", nil, frame)
70 detailhover:SetHeight(ROWHEIGHT)
71 detailhover:SetPoint("LEFT", text, "RIGHT", ROWOFFSET*3, 0)
72 detailhover:SetPoint("RIGHT", scrollbar, "LEFT", -ROWOFFSET-7, 0)
73 detailhover:SetScript("OnEnter", ShowTooltip)
74 detailhover:SetScript("OnLeave", HideTooltip)
75 detailhover:SetScript("OnShow", LevelCorrection)
77 local detail = ww.SummonFontString(detailhover, nil, "GameFontNormal", nil)
78 detail:SetAllPoints(detailhover)
79 detail:SetJustifyH("RIGHT")
80 detail:SetTextColor(240/255, 121/255, 2/255)
81 detailhover.text = detail
83 check:SetScript("OnClick", function(f) self:SetTurnedIn(row.i, f:GetChecked()) end)
85 row.text = text
86 row.detail = detail
87 row.check = check
88 row.icon = icon
89 rows[i] = row
90 end
92 frame:EnableMouseWheel()
93 frame:SetScript("OnMouseWheel", function(f, val)
94 scrollbar:SetValue(offset - val)
95 end)
97 frame:SetScript("OnShow", OnShow)
98 ww.SetFadeTime(frame, 0.5)
99 OnShow(frame)
100 return frame
104 local accepted = {}
105 function TourGuide:UpdateOHPanel(value)
106 if not frame or not frame:IsVisible() then return end
108 self.guidechanged = nil
109 if value then offset = math.floor(value) end
110 if (offset + NUMROWS) > #self.actions then offset = #self.actions - NUMROWS end
111 if offset < 0 then offset = 0 end
113 if offset == 0 then upbutt:Disable() else upbutt:Enable() end
114 if offset == (#self.actions - NUMROWS) then downbutt:Disable() else downbutt:Enable() end
116 for i in pairs(accepted) do accepted[i] = nil end
118 for i in pairs(self.actions) do
119 local action, name = self:GetObjectiveInfo(i)
120 local _, _, quest, part = name:find(L.PART_FIND)
121 if quest and not accepted[quest] and not self:GetObjectiveStatus(i) then accepted[quest] = name end
124 for i,row in ipairs(rows) do
125 row.i = i + offset
126 local action, name = self:GetObjectiveInfo(i + offset)
127 if not name then row:Hide()
128 else
129 local turnedin, logi, complete = self:GetObjectiveStatus(i + offset)
130 row:Show()
132 local shortname = name:gsub(L.PART_GSUB, "")
133 logi = not turnedin and (not accepted[shortname] or (accepted[shortname] == name)) and logi
134 complete = not turnedin and (not accepted[shortname] or (accepted[shortname] == name)) and complete
135 local checked = turnedin or action == "ACCEPT" and logi or action == "COMPLETE" and complete
137 row.icon:SetTexture(self.icons[action])
138 if action ~= "ACCEPT" and action ~= "TURNIN" then row.icon:SetTexCoord(4/48, 44/48, 4/48, 44/48) end
139 row.text:SetText(name)
140 row.detail:SetText(self:GetObjectiveTag("N", i + offset))
141 row.check:SetChecked(checked)