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 !
tekkub (author)
Thu Jul 10 23:31:17 -0700 2008
commit  e893252f8a7943837ba5327d2b7258d35aa0891c
tree    313a425a5f0ec10d61564f1b9ad99f2782cfcc54
parent  a940aab26ff84b6eb6eadf46d0b45801086c6f35
tourguide / StatusFrame.lua
100755 147 lines (118 sloc) 5.003 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
local bg = {
  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,
}
 
local ICONSIZE, CHECKSIZE, GAP = 16, 16, 8
local FIXEDWIDTH = ICONSIZE + CHECKSIZE + GAP*4 - 4
 
local TourGuide = TourGuide
local ww = WidgetWarlock
local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
local dataobj = ldb:GetDataObjectByName("TourGuide")
 
 
local function GetQuadrant(frame)
  local x,y = frame:GetCenter()
  if not x or not y then return "BOTTOMLEFT", "BOTTOM", "LEFT" end
  local hhalf = (x > UIParent:GetWidth()/2) and "RIGHT" or "LEFT"
  local vhalf = (y > UIParent:GetHeight()/2) and "TOP" or "BOTTOM"
  return vhalf..hhalf, vhalf, hhalf
end
 
 
local f = CreateFrame("Button", nil, UIParent)
TourGuide.statusframe = f
f:SetPoint("BOTTOMRIGHT", QuestWatchFrame, "TOPRIGHT", -60, -15)
f:SetHeight(24)
f:SetFrameStrata("LOW")
f:EnableMouse(true)
f:RegisterForClicks("anyUp")
f:SetBackdrop(bg)
f:SetBackdropColor(0.09, 0.09, 0.19, 0.5)
f:SetBackdropBorderColor(0.5, 0.5, 0.5, 0.5)
 
local check = ww.SummonCheckBox(CHECKSIZE, f, "LEFT", GAP, 0)
local icon = ww.SummonTexture(f, "ARTWORK", ICONSIZE, ICONSIZE, nil, "LEFT", check, "RIGHT", GAP-4, 0)
local text = ww.SummonFontString(f, "OVERLAY", "GameFontNormalSmall", nil, "RIGHT", -GAP-4, 0)
text:SetPoint("LEFT", icon, "RIGHT", GAP-4, 0)
 
 
local f2 = CreateFrame("Frame", nil, UIParent)
local f2anchor = "RIGHT"
f2:SetHeight(32)
f2:SetWidth(100)
local text2 = ww.SummonFontString(f2, "OVERLAY", "GameFontNormalSmall", nil, "RIGHT", -GAP-4, 0)
local icon2 = ww.SummonTexture(f2, "ARTWORK", ICONSIZE, ICONSIZE, nil, "RIGHT", text2, "LEFT", -GAP+4, 0)
local check2 = ww.SummonCheckBox(CHECKSIZE, f2, "RIGHT", icon2, "LEFT", -GAP+4, 0)
check2:SetChecked(true)
f2:Hide()
 
 
local elapsed, oldsize, newsize
f2:SetScript("OnUpdate", function(self, el)
  elapsed = elapsed + el
  if elapsed > 1 then
    self:Hide()
    icon:SetAlpha(1)
    text:SetAlpha(1)
    f:SetWidth(newsize)
  else
    self:SetPoint(f2anchor, f, f2anchor, 0, elapsed*40)
    self:SetAlpha(1 - elapsed)
    text:SetAlpha(elapsed)
    icon:SetAlpha(elapsed)
    f:SetWidth(oldsize + (newsize-oldsize)*elapsed)
  end
end)
 
 
function TourGuide:PositionStatusFrame()
  if self.db.profile.statusframepoint then
    f:ClearAllPoints()
    f:SetPoint(self.db.profile.statusframepoint, self.db.profile.statusframex, self.db.profile.statusframey)
  end
end
 
 
ldb.RegisterCallback(TourGuide, "LibDataBroker_AttributeChanged_TourGuide_text", function(event, name, attr, value, dataobj)
  oldsize = f:GetWidth()
  icon:SetAlpha(0)
  text:SetAlpha(0)
  elapsed = 0
  f2:SetWidth(f:GetWidth())
  f2anchor = select(3, GetQuadrant(f))
  f2:ClearAllPoints()
  f2:SetPoint(f2anchor, f, f2anchor, 0, 0)
  f2:SetAlpha(1)
  text2:SetText(text:GetText())
 
  text:SetText(value)
  check:SetChecked(false)
  check:SetButtonState("NORMAL")
  if TourGuide.db.char.currentguide == "No Guide" then check:Disable() else check:Enable() end
  if i == 1 then f:SetWidth(FIXEDWIDTH + text:GetWidth()) end
  newsize = FIXEDWIDTH + text:GetWidth()
 
  f2:Show()
end)
 
 
ldb.RegisterCallback(TourGuide, "LibDataBroker_AttributeChanged_TourGuide_icon", function(event, name, attr, value, dataobj)
  local oldtexture = icon:GetTexture()
  icon2:SetTexture(oldtexture)
  if oldtexture and oldtexture:match("Interface\\Icons") then icon2:SetTexCoord(4/48, 44/48, 4/48, 44/48) else icon2:SetTexCoord(0,1,0,1) end
 
  icon:SetTexture(value)
  if value and value:match("Interface\\Icons") then icon:SetTexCoord(4/48, 44/48, 4/48, 44/48) else icon:SetTexCoord(0,1,0,1) end
end)
 
 
f:SetScript("OnClick", dataobj.OnClick)
f:SetScript("OnLeave", dataobj.OnLeave)
f:SetScript("OnEnter", dataobj.OnEnter)
check:SetScript("OnClick", function(self, btn) TourGuide:SetTurnedIn() end)
 
 
local function GetUIParentAnchor(frame)
  local w, h, x, y = UIParent:GetWidth(), UIParent:GetHeight(), frame:GetCenter()
  local hhalf, vhalf = (x > w/2) and "RIGHT" or "LEFT", (y > h/2) and "TOP" or "BOTTOM"
  local dx = hhalf == "RIGHT" and math.floor(frame:GetRight() + 0.5) - w or math.floor(frame:GetLeft() + 0.5)
  local dy = vhalf == "TOP" and math.floor(frame:GetTop() + 0.5) - h or math.floor(frame:GetBottom() + 0.5)
 
  return vhalf..hhalf, dx, dy
end
 
 
f:RegisterForDrag("LeftButton")
f:SetMovable(true)
f:SetClampedToScreen(true)
f:SetScript("OnDragStart", function(frame)
  if TourGuide.objectiveframe:IsVisible() then HideUIPanel(TourGuide.objectiveframe) end
  dataobj.OnLeave(frame)
  frame:StartMoving()
end)
f:SetScript("OnDragStop", function(frame)
  frame:StopMovingOrSizing()
  TourGuide:Debug(1, "Status frame moved", GetUIParentAnchor(frame))
  TourGuide.db.profile.statusframepoint, TourGuide.db.profile.statusframex, TourGuide.db.profile.statusframey = GetUIParentAnchor(frame)
  frame:ClearAllPoints()
  frame:SetPoint(TourGuide.db.profile.statusframepoint, TourGuide.db.profile.statusframex, TourGuide.db.profile.statusframey)
  dataobj.OnEnter(frame)
end)