1 QuestHelper_File
["mapbutton.lua"] = "Development Version"
2 QuestHelper_Loadtime
["mapbutton.lua"] = GetTime()
7 This module contains code to place a button on the Map Frame, and provides the
8 functionality of that button.
10 Currently Functionality:
11 - Left click on button is equivalent to /qh hide
12 - Right-click on button shows Settings menu
13 - Button has tooltip to that effect
14 - Button serves as hook to detect when map is hidden, in order to hide active menus (if any).
17 4-20-2008 Nesher Created
18 4-24-2008 Smariot Added right-click menu
19 4-24-2008 Nesher Localized settings menu. Added hook to hide menus when World Map is hidden.
22 -------------------------------------------------------------------------------------
23 -- Display a Settings menu. Used from the map button's right-click, and from /qh settings.
24 function QuestHelper
:DoSettingsMenu()
25 local menu
= QuestHelper
:CreateMenu()
26 self
:CreateMenuTitle(menu
, QHText("MENU_SETTINGS"))
29 self
:CreateMenuItem(menu
, QHFormat("MENU_FLIGHT_TIMER", QuestHelper_Pref
.flight_time
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
30 :SetFunction(self
.ToggleFlightTimes
, self
)
33 self
:CreateMenuItem(menu
, QHFormat("MENU_ANT_TRAILS", QuestHelper_Pref
.show_ants
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
34 :SetFunction(self
.ToggleAnts
, self
)
37 self
:CreateMenuItem(menu
, QHFormat("MENU_OBJECTIVE_TIPS", QuestHelper_Pref
.tooltip
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
38 :SetFunction(self
.ToggleTooltip
, self
)
40 -- Cartographer Waypoints
41 if Cartographer_Waypoints
then
42 self
:CreateMenuItem(menu
, QHFormat("MENU_WAYPOINT_ARROW", QuestHelper_Pref
.cart_wp_new
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE"))..(TomTom
and " (Cartographer Waypoints)" or ""))
43 :SetFunction(self
.ToggleCartWP
, self
)
48 self
:CreateMenuItem(menu
, QHFormat("MENU_WAYPOINT_ARROW", QuestHelper_Pref
.tomtom_wp_new
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE"))..(Cartographer_Waypoints
and " (TomTom)" or ""))
49 :SetFunction(self
.ToggleTomTomWP
, self
)
52 -- Options regarding party members.
53 local submenu
= self
:CreateMenu()
54 self
:CreateMenuItem(submenu
, QHFormat("MENU_PARTY_SHARE", QuestHelper_Pref
.share
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
55 :SetFunction(self
.ToggleShare
, self
)
56 self
:CreateMenuItem(submenu
, QHFormat("MENU_PARTY_SOLO", QuestHelper_Pref
.solo
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
57 :SetFunction(self
.ToggleSolo
, self
)
58 self
:CreateMenuItem(menu
, QHText("MENU_PARTY")):SetSubmenu(submenu
)
61 self
:CreateMenuItem(menu
, QHFormat("MENU_MAP_BUTTON", QuestHelper_Pref
.map_button
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
62 :SetFunction(self
.ToggleMapButton
, self
)
65 submenu
= self
:CreateMenu()
66 for pct
= 50,120,10 do
67 local item
= self
:CreateMenuItem(submenu
, pct
.."%")
68 local tex
= self
:CreateIconTexture(item
, 10)
69 item
:SetFunction(QuestHelper
.genericSetScale
, QuestHelper
, "scale", "icon scale", .5, 3, pct
.."%")
70 item
:AddTexture(tex
, true)
71 tex
:SetVertexColor(1, 1, 1, QuestHelper_Pref
.scale
== pct
*0.01 and 1 or 0)
73 self
:CreateMenuItem(menu
, QHText("MENU_ICON_SCALE")):SetSubmenu(submenu
)
76 submenu
= self
:CreateMenu()
77 self
:PopulateHidden(submenu
)
78 self
:CreateMenuItem(menu
, QHText("HIDDEN_TITLE")):SetSubmenu(submenu
)
81 submenu
= self
:CreateMenu()
82 self
:CreateMenuItem(submenu
, QHFormat("MENU_QUEST_TRACKER", QuestHelper_Pref
.track
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
83 :SetFunction(self
.ToggleTrack
, self
)
84 self
:CreateMenuItem(submenu
, QHFormat("MENU_TRACKER_LEVEL", QuestHelper_Pref
.track_level
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
85 :SetFunction(self
.ToggleTrackLevel
, self
)
86 self
:CreateMenuItem(submenu
, QHFormat("MENU_TRACKER_QCOLOUR", QuestHelper_Pref
.track_qcolour
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
87 :SetFunction(self
.ToggleTrackQColour
, self
)
88 self
:CreateMenuItem(submenu
, QHFormat("MENU_TRACKER_OCOLOUR", QuestHelper_Pref
.track_ocolour
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
89 :SetFunction(self
.ToggleTrackOColour
, self
)
90 local submenu2
= self
:CreateMenu()
91 for pct
= 60,120,10 do
92 local item
= self
:CreateMenuItem(submenu2
, pct
.."%")
93 local tex
= self
:CreateIconTexture(item
, 10)
94 item
:SetFunction(self
.TrackerScale
, QuestHelper
, pct
.."%")
95 item
:AddTexture(tex
, true)
96 tex
:SetVertexColor(1, 1, 1, QuestHelper_Pref
.track_scale
== pct
*0.01 and 1 or 0)
98 self
:CreateMenuItem(submenu
, QHText("MENU_TRACKER_SCALE")):SetSubmenu(submenu2
)
99 self
:CreateMenuItem(submenu
, QHText("MENU_TRACKER_RESET"))
100 :SetFunction(self
.ResetTrackerPosition
, self
)
101 self
:CreateMenuItem(menu
, QHText("MENU_TRACKER_OPTIONS")):SetSubmenu(submenu
)
104 submenu
= self
:CreateMenu()
105 self
:CreateMenuItem(submenu
, QHFormat("MENU_ZONE_FILTER", QuestHelper_Pref
.filter_zone
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
106 :SetFunction(self
.Filter
, self
, "ZONE")
107 self
:CreateMenuItem(submenu
, QHFormat("MENU_DONE_FILTER", QuestHelper_Pref
.filter_done
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
108 :SetFunction(self
.Filter
, self
, "DONE")
109 self
:CreateMenuItem(submenu
, QHFormat("MENU_BLOCKED_FILTER", QuestHelper_Pref
.filter_blocked
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
110 :SetFunction(self
.Filter
, self
, "BLOCKED")
111 self
:CreateMenuItem(submenu
, QHFormat("MENU_WATCHED_FILTER", QuestHelper_Pref
.filter_watched
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
112 :SetFunction(self
.Filter
, self
, "WATCHED")
113 self
:CreateMenuItem(submenu
, QHFormat("MENU_LEVEL_FILTER", QuestHelper_Pref
.filter_level
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
114 :SetFunction(self
.Filter
, self
, "LEVEL")
115 submenu2
= self
:CreateMenu()
116 self
:CreateMenuItem(submenu
, QHText("MENU_LEVEL_OFFSET")):SetSubmenu(submenu2
)
119 local menu
= self
:CreateMenuItem(submenu2
, (offset
> 0 and "+" or "")..offset
)
120 menu
:SetFunction(self
.LevelOffset
, self
, offset
)
121 local tex
= self
:CreateIconTexture(item
, 10)
122 menu
:AddTexture(tex
, true)
123 tex
:SetVertexColor(1, 1, 1, QuestHelper_Pref
.level
== offset
and 1 or 0)
125 self
:CreateMenuItem(menu
, QHText("MENU_FILTERS")):SetSubmenu(submenu
)
127 submenu
= self
:CreateMenu()
128 for scale
= 0.2,2,0.2 do
129 local menu
= self
:CreateMenuItem(submenu
, (scale
*100).."%")
130 menu
:SetFunction(QuestHelper
.genericSetScale
, QuestHelper
, "perf_scale", "performance factor", .1, 5, scale
)
131 local tex
= self
:CreateIconTexture(item
, 10)
132 menu
:AddTexture(tex
, true)
133 tex
:SetVertexColor(1, 1, 1, QuestHelper_Pref
.perf_scale
== scale
and 1 or 0)
135 self
:CreateMenuItem(menu
, QHText("MENU_PERFORMANCE")):SetSubmenu(submenu
)
138 submenu
= self
:CreateMenu()
139 for loc
, tbl
in pairs(QuestHelper_Translations
) do
140 local item
= self
:CreateMenuItem(submenu
, (tbl
.LOCALE_NAME
or "???").." ["..loc
.."]")
141 local tex
= self
:CreateIconTexture(item
, 10)
142 item
:SetFunction(self
.SetLocale
, self
, loc
)
143 item
:AddTexture(tex
, true)
144 tex
:SetVertexColor(1, 1, 1, QuestHelper_Pref
.locale
== loc
and 1 or 0)
146 local item
= self
:CreateMenuItem(menu
, QHText("MENU_LOCALE"))
147 item
:AddTexture(self
:CreateIconTexture(item
, 25), true) -- Add Globe icon to locale menu.
148 item
:SetSubmenu(submenu
)
151 submenu
= self
:CreateMenu()
152 self
:CreateMenuItem(submenu
, QHText("MENU_HELP_SLASH")):SetFunction(self
.Help
, self
)
153 self
:CreateMenuItem(submenu
, QHText("MENU_HELP_CHANGES")):SetFunction(self
.ChangeLog
, self
)
154 self
:CreateMenuItem(submenu
, QHText("MENU_HELP_SUBMIT")):SetFunction(self
.Submit
, self
)
155 self
:CreateMenuItem(menu
, QHText("MENU_HELP")):SetSubmenu(submenu
)
160 -------------------------------------------------------------------------------------
161 -- Handle clicks on the button
162 function QuestHelperWorldMapButton_OnClick(self
, clicked
)
164 -- Left button toggles whether QuestHelper is displayed (and hence active)
165 if clicked
== "LeftButton" then
166 QuestHelper
:ToggleHide()
168 -- Refresh the tooltip to match. Presumably it's showing - how else could the button get clicked?
169 -- Note: if I'm wrong about my assumption, this could leave the tooltip stranded until user mouses
170 -- back over the button, but I don't think that's too serious.
171 QuestHelperWorldMapButton_OnEnter(self
)
172 elseif clicked
== "RightButton" and not QuestHelper_Pref
.hide
then
173 QuestHelper
:DoSettingsMenu()
177 -------------------------------------------------------------------------------------
178 -- Display or update the tooltip
179 function QuestHelperWorldMapButton_OnEnter(self
)
180 local theme
= QuestHelper
:GetColourTheme()
182 QuestHelper
.tooltip
:SetOwner(self
, "ANCHOR_BOTTOMLEFT", self
:GetWidth(), -5)
183 QuestHelper
.tooltip
:ClearLines()
184 QuestHelper
.tooltip
:AddLine(QHFormat("QH_BUTTON_TOOLTIP1", QHText(QuestHelper_Pref
.hide
and "QH_BUTTON_SHOW" or "QH_BUTTON_HIDE")),
185 unpack(theme
.tooltip
))
186 QuestHelper
.tooltip
:GetPrevLines():SetFont(QuestHelper
.font
.serif
, 12)
187 if not QuestHelper_Pref
.hide
then
188 -- Add the settings menu tooltip when it's available
189 QuestHelper
.tooltip
:AddLine(QHText("QH_BUTTON_TOOLTIP2"), unpack(theme
.tooltip
))
190 QuestHelper
.tooltip
:GetPrevLines():SetFont(QuestHelper
.font
.serif
, 12)
192 QuestHelper
.tooltip
:Show()
195 -------------------------------------------------------------------------------------
196 -- Handle when the world map gets hidden: hide the active menu if any.
197 function QuestHelper_WorldMapHidden()
198 if QuestHelper
.active_menu
then
199 QuestHelper
.active_menu
:DoHide()
200 if QuestHelper
.active_menu
.auto_release
then
201 QuestHelper
.active_menu
= nil
207 -------------------------------------------------------------------------------------
208 -- Set up the Map Button
209 function QuestHelper
:InitMapButton()
210 do return end -- disabled until I figure out where to put it
212 if not self
.MapButton
then
214 local button
= CreateFrame("Button", "QuestHelperWorldMapButton", WorldMapFrame
, "UIPanelButtonTemplate")
216 -- Assign the font QuestHelper selected for the currect locale.
217 if button
.GetFont
then
218 button
:SetFont(self
.font
.serif
, select(2, button
:GetFont()))
222 button
:SetText(QHText("QH_BUTTON_TEXT"))
223 local width
= button
:GetTextWidth() + 30
227 button
:SetWidth(width
)
230 -- Desaturate the button texture if QuestHelper is disabled.
231 -- This line is also in QuestHelper:ToggleHide
232 button
:GetNormalTexture():SetDesaturated(QuestHelper_Pref
.hide
)
234 -- Add event handlers to provide Tooltip
235 button
:SetScript("OnEnter", QuestHelperWorldMapButton_OnEnter
)
236 button
:SetScript("OnLeave", function(this
)
237 QuestHelper
.tooltip
:Hide()
241 button
:SetScript("OnClick", QuestHelperWorldMapButton_OnClick
)
242 button
:RegisterForClicks("LeftButtonUp", "RightButtonUp")
244 -- Add Hide handler, so we can dismiss any menus when map is closed
245 button
:SetScript("OnHide", QuestHelper_WorldMapHidden
)
247 -- Position it on the World Map frame
248 --~ if Cartographer then
249 --~ -- If Cartographer is in use, coordinate with their buttons.
250 -- Trouble is, this makes Cartographer's buttons conflict with the Zone Map dropdown.
251 -- Re-enable this if Cartographer ever learns to work with the Zone Map dropdown.
252 --~ Cartographer:AddMapButton(button, 3)
254 -- Otherwise, just put it in the upper right corner
255 button
:SetPoint("RIGHT", WorldMapPositioningGuide
, "RIGHT", -20, 0)
256 button
:SetPoint("BOTTOM", WorldMapZoomOutButton
, "BOTTOM", 0, 0)
259 -- Save the button so we can reference it later if need be
260 self
.MapButton
= button
262 -- User must be toggling the button. We've already got it, so just show it.
263 self
.MapButton
:Show()
267 ----------------------------------------------------------------------------------
268 -- Hide the map button
269 function QuestHelper
:HideMapButton()
270 if self
.MapButton
then
271 self
.MapButton
:Hide()