public
Description: WoW Powerleveling addon
Homepage: http://www.tekkub.net/
Clone URL: git://github.com/tekkub/tourguide.git
Click here to lend your support to: tourguide and make a donation at www.pledgie.com !
tourguide / ObjectivesFrame.lua
100644 229 lines (173 sloc) 7.925 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
local TourGuide = TourGuide
local L = TourGuide.Locale
local ww = WidgetWarlock
 
 
local ROWHEIGHT = 30
local ROWOFFSET = 6
local NUMROWS = math.floor(305/ROWHEIGHT)
 
 
local offset = 0
local rows = {}
local scrollbar, upbutt, downbutt, title, completed
 
 
local frame = CreateFrame("Frame", "TourGuideObjectives", UIParent)
TourGuide.objectiveframe = frame
frame:SetFrameStrata("DIALOG")
frame:SetWidth(630) frame:SetHeight(305+28)
frame:SetPoint("TOPRIGHT", TourGuide.statusframe, "BOTTOMRIGHT")
frame:SetBackdrop({
  bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
  edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
  edgeSize = 16,
  insets = {left = 5, right = 5, top = 5, bottom = 5},
  tile = true, tileSize = 16,
})
frame:SetBackdropColor(0.09, 0.09, 0.19, 1)
frame:SetBackdropBorderColor(0.5, 0.5, 0.5, 0.5)
frame:Hide()
frame:SetScript("OnShow", function() TourGuide:CreateObjectivePanel() end)
table.insert(UISpecialFrames, "TourGuideObjectives")
 
 
local function OnShow(self)
  local newval = math.max(0, (TourGuide.current or 0) - NUMROWS/2 - 1)
 
  scrollbar:SetMinMaxValues(0, math.max(#TourGuide.actions - NUMROWS, 1))
  scrollbar:SetValue(newval)
 
  TourGuide:UpdateOHPanel()
 
  self:SetAlpha(0)
  self:SetScript("OnUpdate", ww.FadeIn)
end
 
 
local function HideTooltip() GameTooltip:Hide() end
 
local function ShowTooltip(f)
  if f.text:GetStringWidth() <= f:GetWidth() then return end
 
  GameTooltip:SetOwner(f, "ANCHOR_RIGHT")
  GameTooltip:SetText(f.text:GetText(), nil, nil, nil, nil, true)
end
 
 
local function CreateButton(parent, ...)
  local b = CreateFrame("Button", nil, parent)
  if select("#", ...) > 0 then b:SetPoint(...) end
  b:SetWidth(80) b:SetHeight(22)
 
  -- Fonts --
  b:SetDisabledFontObject(GameFontDisable)
  b:SetHighlightFontObject(GameFontHighlight)
  b:SetTextFontObject(GameFontNormal)
 
  -- Textures --
  b:SetNormalTexture("Interface\\Buttons\\UI-Panel-Button-Up")
  b:SetPushedTexture("Interface\\Buttons\\UI-Panel-Button-Down")
  b:SetHighlightTexture("Interface\\Buttons\\UI-Panel-Button-Highlight")
  b:SetDisabledTexture("Interface\\Buttons\\UI-Panel-Button-Disabled")
  b:GetNormalTexture():SetTexCoord(0, 0.625, 0, 0.6875)
  b:GetPushedTexture():SetTexCoord(0, 0.625, 0, 0.6875)
  b:GetHighlightTexture():SetTexCoord(0, 0.625, 0, 0.6875)
  b:GetDisabledTexture():SetTexCoord(0, 0.625, 0, 0.6875)
  b:GetHighlightTexture():SetBlendMode("ADD")
 
  return b
end
 
 
function TourGuide:CreateObjectivePanel()
  local guidebutton = CreateButton(frame, "BOTTOMRIGHT", -6, 6)
  guidebutton:SetText("Guides")
  guidebutton:SetScript("OnClick", function() frame:Hide(); LibStub("OptionHouse-1.1"):Open("Tour Guide", "Guides") end)
 
  local configbutton = CreateButton(frame, "RIGHT", guidebutton, "LEFT")
  configbutton:SetText("Config")
  configbutton:SetScript("OnClick", function() frame:Hide(); LibStub("OptionHouse-1.1"):Open("Tour Guide", "Config") end)
 
  if tekDebug then
    local b = CreateButton(frame, "RIGHT", configbutton, "LEFT")
    b:SetText("Debug All")
    b:SetScript("OnClick", function() frame:Hide(); self:DebugGuideSequence(true) LibStub("OptionHouse-1.1"):Open("tekDebug", "TourGuide") end)
  end
 
  title = ww.SummonFontString(frame, nil, "SubZoneTextFont", nil, "BOTTOM", frame, "TOP")
  local fontname, fontheight, fontflags = title:GetFont()
  title:SetFont(fontname, 18, fontflags)
 
  completed = ww.SummonFontString(frame, nil, "NumberFontNormalLarge", nil, "BOTTOMLEFT", 10, 10)
 
  scrollbar, upbutt, downbutt = ww.ConjureScrollBar(frame)
  scrollbar:SetPoint("TOPRIGHT", frame, -7, -21)
  scrollbar:SetPoint("BOTTOM", frame, 0, 22+22)
  scrollbar:SetScript("OnValueChanged", function(f, val) self:UpdateOHPanel(val) end)
 
  upbutt:SetScript("OnClick", function(f)
    scrollbar:SetValue(offset - NUMROWS + 1)
    PlaySound("UChatScrollButton")
  end)
 
  downbutt:SetScript("OnClick", function(f)
    scrollbar:SetValue(offset + NUMROWS - 1)
    PlaySound("UChatScrollButton")
  end)
 
  local bg = {bgFile = "Interface/Tooltips/UI-Tooltip-Background"}
  for i=1,NUMROWS do
    local row = CreateFrame("Button", nil, frame)
    row:SetPoint("TOPLEFT", i == 1 and frame or rows[i-1], i == 1 and "TOPLEFT" or "BOTTOMLEFT", 0, i == 1 and -3 or 0)
    row:SetWidth(630-24)
    row:SetHeight(ROWHEIGHT)
    row:SetBackdrop(bg)
 
    local check = ww.SummonCheckBox(ROWHEIGHT-ROWOFFSET, row, "LEFT", ROWOFFSET, 0)
    local icon = ww.SummonTexture(row, nil, ROWHEIGHT-ROWOFFSET, ROWHEIGHT-ROWOFFSET, nil, "LEFT", check, "RIGHT", ROWOFFSET, 0)
    local text = ww.SummonFontString(row, nil, "GameFontNormal", nil, "LEFT", icon, "RIGHT", ROWOFFSET, 0)
 
    local detailhover = CreateFrame("Button", nil, row)
    detailhover:SetHeight(ROWHEIGHT-ROWOFFSET)
    detailhover:SetPoint("LEFT", text, "RIGHT", ROWOFFSET*3, 0)
    detailhover:SetPoint("RIGHT", scrollbar, "LEFT", -ROWOFFSET, 0)
    detailhover:SetScript("OnEnter", ShowTooltip)
    detailhover:SetScript("OnLeave", HideTooltip)
 
    local detail = ww.SummonFontString(detailhover, nil, "GameFontNormal", nil)
    detail:SetAllPoints(detailhover)
    detail:SetJustifyH("RIGHT")
    detail:SetTextColor(240/255, 121/255, 2/255)
    detailhover.text = detail
 
    check:SetScript("OnClick", function(f) self:SetTurnedIn(row.i, f:GetChecked()) end)
 
    row.text = text
    row.detail = detail
    row.check = check
    row.icon = icon
    rows[i] = row
  end
 
  frame:EnableMouseWheel()
  frame:SetScript("OnMouseWheel", function(f, val)
    scrollbar:SetValue(offset - val)
  end)
 
  frame:SetScript("OnShow", OnShow)
  ww.SetFadeTime(frame, 0.5)
  OnShow(frame)
  return frame
end
 
 
local accepted = {}
function TourGuide:UpdateOHPanel(value)
  if not frame or not frame:IsVisible() then return end
 
  title:SetText(self.db.char.currentguide or "No Guide Loaded")
  local r,g,b = self.ColorGradient((self.current-1)/#self.actions)
  completed:SetText(string.format("|cff%02x%02x%02x%d%% complete", r*255, g*255, b*255, (self.current-1)/#self.actions*100))
 
  self.guidechanged = nil
  if value then offset = math.floor(value) end
  if (offset + NUMROWS) > #self.actions then offset = #self.actions - NUMROWS end
  if offset < 0 then offset = 0 end
 
  if offset == 0 then upbutt:Disable() else upbutt:Enable() end
  if offset == (#self.actions - NUMROWS) then downbutt:Disable() else downbutt:Enable() end
 
  for i in pairs(accepted) do accepted[i] = nil end
 
  for i in pairs(self.actions) do
    local action, name = self:GetObjectiveInfo(i)
    local _, _, quest, part = name:find(L.PART_FIND)
    if quest and not accepted[quest] and not self:GetObjectiveStatus(i) then accepted[quest] = name end
  end
 
  for i,row in ipairs(rows) do
    row.i = i + offset
    local action, name = self:GetObjectiveInfo(i + offset)
    if not name then row:Hide()
    else
      local turnedin, logi, complete = self:GetObjectiveStatus(i + offset)
      local optional, intown = self:GetObjectiveTag("O", i + offset), self:GetObjectiveTag("T", i + offset)
      row:Show()
 
      if intown then row:SetBackdropColor(0,0.5,0,0.5) else row:SetBackdropColor(0,0,0,0) end
 
      local shortname = name:gsub(L.PART_GSUB, "")
      logi = not turnedin and (not accepted[shortname] or (accepted[shortname] == name)) and logi
      complete = not turnedin and (not accepted[shortname] or (accepted[shortname] == name)) and complete
      local checked = turnedin or action == "ACCEPT" and logi or action == "COMPLETE" and complete
 
      row.icon:SetTexture(self.icons[action])
      if action ~= "ACCEPT" and action ~= "TURNIN" then row.icon:SetTexCoord(4/48, 44/48, 4/48, 44/48) end
      row.text:SetText(name..(optional and " |cff808080(Optional)" or ""))
      row.detail:SetText(self:GetObjectiveTag("N", i + offset))
      row.check:SetChecked(checked)
 
      if (TourGuide.current > (i + offset)) and optional and not checked then
        row.text:SetTextColor(0.5, 0.5, 0.5)
--~         row.check:SetChecked(true)
        row.check:Disable()
      else
        row.text:SetTextColor(1, 0.82, 0)
        row.check:Enable()
      end
 
      if self.db.char.currentguide == "No Guide" then row.check:Disable() end
    end
  end
end