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"))
28 arrowmenu
= self
:CreateMenu()
29 QH_Arrow_PopulateMenu(arrowmenu
)
30 self
:CreateMenuItem(menu
, QHText("SETTINGS_ARROWLINK_ARROW")):SetSubmenu(arrowmenu
)
32 -- Cartographer Waypoints
33 if Cartographer_Waypoints
then
34 self
:CreateMenuItem(menu
, QHFormat("SETTINGS_MENU_CARTWP", QuestHelper_Pref
.cart_wp_new
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
35 :SetFunction(self
.ToggleCartWP
, self
)
40 self
:CreateMenuItem(menu
, QHFormat("SETTINGS_MENU_TOMTOM", QuestHelper_Pref
.tomtom_wp_new
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
41 :SetFunction(self
.ToggleTomTomWP
, self
)
46 self
:CreateMenuItem(menu
, QHFormat("MENU_FLIGHT_TIMER", QuestHelper_Pref
.flight_time
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
47 :SetFunction(self
.ToggleFlightTimes
, self
)
50 self
:CreateMenuItem(menu
, QHFormat("MENU_ANT_TRAILS", QuestHelper_Pref
.show_ants
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
51 :SetFunction(self
.ToggleAnts
, self
)
54 self
:CreateMenuItem(menu
, QHFormat("MENU_OBJECTIVE_TIPS", QuestHelper_Pref
.tooltip
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
55 :SetFunction(self
.ToggleTooltip
, self
)
57 -- Options regarding party members.
58 local submenu
= self
:CreateMenu()
59 self
:CreateMenuItem(submenu
, QHFormat("MENU_PARTY_SHARE", QuestHelper_Pref
.share
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
60 :SetFunction(self
.ToggleShare
, self
)
61 self
:CreateMenuItem(submenu
, QHFormat("MENU_PARTY_SOLO", QuestHelper_Pref
.solo
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
62 :SetFunction(self
.ToggleSolo
, self
)
63 self
:CreateMenuItem(menu
, QHText("MENU_PARTY")):SetSubmenu(submenu
)
66 --[[self:CreateMenuItem(menu, QHFormat("MENU_MAP_BUTTON", QuestHelper_Pref.map_button and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
67 :SetFunction(self.ToggleMapButton, self)]]
70 submenu
= self
:CreateMenu()
71 for pct
= 50,120,10 do
72 local item
= self
:CreateMenuItem(submenu
, pct
.."%")
73 local tex
= self
:CreateIconTexture(item
, 10)
74 item
:SetFunction(QuestHelper
.genericSetScale
, QuestHelper
, "scale", "icon scale", .5, 3, pct
.."%")
75 item
:AddTexture(tex
, true)
76 tex
:SetVertexColor(1, 1, 1, QuestHelper_Pref
.scale
== pct
*0.01 and 1 or 0)
78 self
:CreateMenuItem(menu
, QHText("MENU_ICON_SCALE")):SetSubmenu(submenu
)
81 submenu
= self
:CreateMenu()
82 QH_PopulateHidden(submenu
)
83 self
:CreateMenuItem(menu
, QHText("HIDDEN_TITLE")):SetSubmenu(submenu
)
86 submenu
= self
:CreateMenu()
87 self
:CreateMenuItem(submenu
, QHFormat("MENU_QUEST_TRACKER", QuestHelper_Pref
.track
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
88 :SetFunction(self
.ToggleTrack
, self
)
90 self:CreateMenuItem(submenu, QHFormat("MENU_TRACKER_LEVEL", QuestHelper_Pref.track_level and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
91 :SetFunction(self.ToggleTrackLevel, self)
92 self:CreateMenuItem(submenu, QHFormat("MENU_TRACKER_QCOLOUR", QuestHelper_Pref.track_qcolour and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
93 :SetFunction(self.ToggleTrackQColour, self)
94 self:CreateMenuItem(submenu, QHFormat("MENU_TRACKER_OCOLOUR", QuestHelper_Pref.track_ocolour and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
95 :SetFunction(self.ToggleTrackOColour, self)
97 local submenu2
= self
:CreateMenu()
98 for pct
= 60,120,10 do
99 local item
= self
:CreateMenuItem(submenu2
, pct
.."%")
100 local tex
= self
:CreateIconTexture(item
, 10)
101 item
:SetFunction(self
.TrackerScale
, QuestHelper
, pct
.."%")
102 item
:AddTexture(tex
, true)
103 tex
:SetVertexColor(1, 1, 1, QuestHelper_Pref
.track_scale
== pct
*0.01 and 1 or 0)
105 self
:CreateMenuItem(submenu
, QHText("MENU_TRACKER_SCALE")):SetSubmenu(submenu2
)
106 self
:CreateMenuItem(submenu
, QHText("MENU_TRACKER_RESET"))
107 :SetFunction(self
.ResetTrackerPosition
, self
)
108 self
:CreateMenuItem(menu
, QHText("MENU_TRACKER_OPTIONS")):SetSubmenu(submenu
)
111 submenu
= self
:CreateMenu()
112 self
:CreateMenuItem(submenu
, QHFormat("MENU_ZONE_FILTER", QuestHelper_Pref
.filter_zone
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
113 :SetFunction(self
.Filter
, self
, "ZONE")
114 self
:CreateMenuItem(submenu
, QHFormat("MENU_DONE_FILTER", QuestHelper_Pref
.filter_done
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
115 :SetFunction(self
.Filter
, self
, "DONE")
116 self
:CreateMenuItem(submenu
, QHFormat("MENU_BLOCKED_FILTER", QuestHelper_Pref
.filter_blocked
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
117 :SetFunction(self
.Filter
, self
, "BLOCKED")
118 self
:CreateMenuItem(submenu
, QHFormat("MENU_WATCHED_FILTER", QuestHelper_Pref
.filter_watched
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
119 :SetFunction(self
.Filter
, self
, "WATCHED")
120 self
:CreateMenuItem(submenu
, QHFormat("MENU_LEVEL_FILTER", QuestHelper_Pref
.filter_level
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
121 :SetFunction(self
.Filter
, self
, "LEVEL")
122 submenu2
= self
:CreateMenu()
123 self
:CreateMenuItem(submenu
, QHText("MENU_LEVEL_OFFSET")):SetSubmenu(submenu2
)
126 local menu
= self
:CreateMenuItem(submenu2
, (offset
> 0 and "+" or "")..offset
)
127 menu
:SetFunction(self
.LevelOffset
, self
, offset
)
128 local tex
= self
:CreateIconTexture(item
, 10)
129 menu
:AddTexture(tex
, true)
130 tex
:SetVertexColor(1, 1, 1, QuestHelper_Pref
.level
== offset
and 1 or 0)
132 self
:CreateMenuItem(menu
, QHText("MENU_FILTERS")):SetSubmenu(submenu
)
134 submenu
= self
:CreateMenu()
135 for scale
= 0.2,2,0.2 do
136 local menu
= self
:CreateMenuItem(submenu
, (scale
*100).."%")
137 menu
:SetFunction(QuestHelper
.genericSetScale
, QuestHelper
, "perf_scale_2", "performance factor", .1, 5, scale
)
138 local tex
= self
:CreateIconTexture(item
, 10)
139 menu
:AddTexture(tex
, true)
140 tex
:SetVertexColor(1, 1, 1, QuestHelper_Pref
.perf_scale_2
== scale
and 1 or 0)
142 self
:CreateMenuItem(menu
, QHText("MENU_PERFORMANCE")):SetSubmenu(submenu
)
145 submenu
= self
:CreateMenu()
146 for loc
, tbl
in pairs(QuestHelper_Translations
) do
147 local item
= self
:CreateMenuItem(submenu
, (tbl
.LOCALE_NAME
or "???").." ["..loc
.."]")
148 local tex
= self
:CreateIconTexture(item
, 10)
149 item
:SetFunction(self
.SetLocale
, self
, loc
)
150 item
:AddTexture(tex
, true)
151 tex
:SetVertexColor(1, 1, 1, QuestHelper_Pref
.locale
== loc
and 1 or 0)
153 local item
= self
:CreateMenuItem(menu
, QHText("MENU_LOCALE"))
154 --item:AddTexture(self:CreateIconTexture(item, 25), true) -- Add Globe icon to locale menu.
155 item
:SetSubmenu(submenu
)
158 submenu
= self
:CreateMenu()
159 self
:CreateMenuItem(submenu
, QHText("MENU_HELP_SLASH")):SetFunction(self
.Help
, self
)
160 self
:CreateMenuItem(submenu
, QHText("MENU_HELP_CHANGES")):SetFunction(self
.ChangeLog
, self
)
161 self
:CreateMenuItem(submenu
, QHText("MENU_HELP_SUBMIT")):SetFunction(self
.Submit
, self
)
162 self
:CreateMenuItem(menu
, QHText("MENU_HELP")):SetSubmenu(submenu
)
167 -------------------------------------------------------------------------------------
168 -- Handle clicks on the button
169 function QuestHelperWorldMapButton_OnClick(self
, clicked
)
171 -- Left button toggles whether QuestHelper is displayed (and hence active)
172 if clicked
== "LeftButton" then
173 QuestHelper
:ToggleHide()
175 -- Refresh the tooltip to match. Presumably it's showing - how else could the button get clicked?
176 -- Note: if I'm wrong about my assumption, this could leave the tooltip stranded until user mouses
177 -- back over the button, but I don't think that's too serious.
178 QuestHelperWorldMapButton_OnEnter(self
)
179 elseif clicked
== "RightButton" and not QuestHelper_Pref
.hide
then
180 QuestHelper
:DoSettingsMenu()
184 -------------------------------------------------------------------------------------
185 -- Display or update the tooltip
186 function QuestHelperWorldMapButton_OnEnter(self
)
187 local theme
= QuestHelper
:GetColourTheme()
189 QuestHelper
.tooltip
:SetOwner(self
, "ANCHOR_BOTTOMLEFT", self
:GetWidth(), -5)
190 QuestHelper
.tooltip
:ClearLines()
191 QuestHelper
.tooltip
:AddLine(QHFormat("QH_BUTTON_TOOLTIP1", QHText(QuestHelper_Pref
.hide
and "QH_BUTTON_SHOW" or "QH_BUTTON_HIDE")),
192 unpack(theme
.tooltip
))
193 QuestHelper
.tooltip
:GetPrevLines():SetFont(QuestHelper
.font
.serif
, 12)
194 if not QuestHelper_Pref
.hide
then
195 -- Add the settings menu tooltip when it's available
196 QuestHelper
.tooltip
:AddLine(QHText("QH_BUTTON_TOOLTIP2"), unpack(theme
.tooltip
))
197 QuestHelper
.tooltip
:GetPrevLines():SetFont(QuestHelper
.font
.serif
, 12)
199 QuestHelper
.tooltip
:Show()
202 -------------------------------------------------------------------------------------
203 -- Handle when the world map gets hidden: hide the active menu if any.
204 function QuestHelper_WorldMapHidden()
205 if QuestHelper
.active_menu
then
206 QuestHelper
.active_menu
:DoHide()
207 if QuestHelper
.active_menu
.auto_release
then
208 QuestHelper
.active_menu
= nil
214 -------------------------------------------------------------------------------------
215 -- Set up the Map Button
216 function QuestHelper
:InitMapButton()
218 if not self
.MapButton
then
220 local button
= CreateFrame("Button", "QuestHelperWorldMapButton", WorldMapButton
, "UIPanelButtonTemplate")
222 -- Assign the font QuestHelper selected for the currect locale.
223 if button
.GetFont
then
224 button
:SetFont(self
.font
.serif
, select(2, button
:GetFont()))
228 button
:SetText(QHText("QH_BUTTON_TEXT"))
229 local width
= button
:GetTextWidth() + 30
233 button
:SetWidth(width
)
236 -- Desaturate the button texture if QuestHelper is disabled.
237 -- This line is also in QuestHelper:ToggleHide
238 button
:GetNormalTexture():SetDesaturated(QuestHelper_Pref
.hide
)
240 -- Add event handlers to provide Tooltip
241 QH_Hook(button
, "OnEnter", QuestHelperWorldMapButton_OnEnter
)
242 QH_Hook(button
, "OnLeave", function(this
)
243 QuestHelper
.tooltip
:Hide()
247 QH_Hook(button
, "OnClick", QuestHelperWorldMapButton_OnClick
)
248 button
:RegisterForClicks("LeftButtonUp", "RightButtonUp")
250 -- Add Hide handler, so we can dismiss any menus when map is closed
251 QH_Hook(button
, "OnHide", QuestHelper_WorldMapHidden
)
253 -- Position it on the World Map frame
254 --~ if Cartographer then
255 --~ -- If Cartographer is in use, coordinate with their buttons.
256 -- Trouble is, this makes Cartographer's buttons conflict with the Zone Map dropdown.
257 -- Re-enable this if Cartographer ever learns to work with the Zone Map dropdown.
258 --~ Cartographer:AddMapButton(button, 3)
260 -- Otherwise, just put it in the upper right corner
261 button
:SetPoint("TOPRIGHT", WorldMapButton
, "TOPRIGHT", -10, -10)
262 button
:SetFrameLevel(WorldMapButton
:GetFrameLevel()+1)
263 button
:SetFrameStrata("FULLSCREEN")
266 -- Save the button so we can reference it later if need be
267 self
.MapButton
= button
269 -- User must be toggling the button. We've already got it, so just show it.
270 self
.MapButton
:Show()
274 ----------------------------------------------------------------------------------
275 -- Hide the map button
276 function QuestHelper
:HideMapButton()
277 if self
.MapButton
then
278 self
.MapButton
:Hide()