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 self
:CreateMenuItem(menu
, QHText("SETTINGS_MENU_INCOMPLETE")):SetFunction(QH_Incomplete
)
30 arrowmenu
= self
:CreateMenu()
31 QH_Arrow_PopulateMenu(arrowmenu
)
32 self
:CreateMenuItem(menu
, QHText("SETTINGS_ARROWLINK_ARROW")):SetSubmenu(arrowmenu
)
34 -- Cartographer Waypoints
35 if Cartographer_Waypoints
then
36 self
:CreateMenuItem(menu
, QHFormat("SETTINGS_MENU_CARTWP", QuestHelper_Pref
.cart_wp_new
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
37 :SetFunction(self
.ToggleCartWP
, self
)
42 self
:CreateMenuItem(menu
, QHFormat("SETTINGS_MENU_TOMTOM", QuestHelper_Pref
.tomtom_wp_new
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
43 :SetFunction(self
.ToggleTomTomWP
, self
)
48 self
:CreateMenuItem(menu
, QHFormat("MENU_FLIGHT_TIMER", QuestHelper_Pref
.flight_time
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
49 :SetFunction(self
.ToggleFlightTimes
, self
)
52 self
:CreateMenuItem(menu
, QHFormat("MENU_ANT_TRAILS", QuestHelper_Pref
.show_ants
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
53 :SetFunction(self
.ToggleAnts
, self
)
56 self
:CreateMenuItem(menu
, QHFormat("MENU_OBJECTIVE_TIPS", QuestHelper_Pref
.tooltip
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
57 :SetFunction(self
.ToggleTooltip
, self
)
59 -- Options regarding party members.
60 local submenu
= self
:CreateMenu()
61 self
:CreateMenuItem(submenu
, QHFormat("MENU_PARTY_SHARE", QuestHelper_Pref
.share
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
62 :SetFunction(self
.ToggleShare
, self
)
63 self
:CreateMenuItem(submenu
, QHFormat("MENU_PARTY_SOLO", QuestHelper_Pref
.solo
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
64 :SetFunction(self
.ToggleSolo
, self
)
65 self
:CreateMenuItem(menu
, QHText("MENU_PARTY")):SetSubmenu(submenu
)
68 --[[self:CreateMenuItem(menu, QHFormat("MENU_MAP_BUTTON", QuestHelper_Pref.map_button and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
69 :SetFunction(self.ToggleMapButton, self)]]
72 submenu
= self
:CreateMenu()
73 for pct
= 50,120,10 do
74 local item
= self
:CreateMenuItem(submenu
, pct
.."%")
75 local tex
= self
:CreateIconTexture(item
, 10)
76 item
:SetFunction(QuestHelper
.genericSetScale
, QuestHelper
, "scale", "icon scale", .5, 3, pct
.."%")
77 item
:AddTexture(tex
, true)
78 tex
:SetVertexColor(1, 1, 1, QuestHelper_Pref
.scale
== pct
*0.01 and 1 or 0)
80 self
:CreateMenuItem(menu
, QHText("MENU_ICON_SCALE")):SetSubmenu(submenu
)
83 submenu
= self
:CreateMenu()
84 QH_PopulateHidden(submenu
)
85 self
:CreateMenuItem(menu
, QHText("HIDDEN_TITLE")):SetSubmenu(submenu
)
88 submenu
= self
:CreateMenu()
89 self
:CreateMenuItem(submenu
, QHFormat("MENU_QUEST_TRACKER", QuestHelper_Pref
.track
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
90 :SetFunction(self
.ToggleTrack
, self
)
92 self:CreateMenuItem(submenu, QHFormat("MENU_TRACKER_LEVEL", QuestHelper_Pref.track_level and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
93 :SetFunction(self.ToggleTrackLevel, self)
94 self:CreateMenuItem(submenu, QHFormat("MENU_TRACKER_QCOLOUR", QuestHelper_Pref.track_qcolour and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
95 :SetFunction(self.ToggleTrackQColour, self)
96 self:CreateMenuItem(submenu, QHFormat("MENU_TRACKER_OCOLOUR", QuestHelper_Pref.track_ocolour and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
97 :SetFunction(self.ToggleTrackOColour, self)
99 local submenu2
= self
:CreateMenu()
100 for pct
= 60,120,10 do
101 local item
= self
:CreateMenuItem(submenu2
, pct
.."%")
102 local tex
= self
:CreateIconTexture(item
, 10)
103 item
:SetFunction(self
.TrackerScale
, QuestHelper
, pct
.."%")
104 item
:AddTexture(tex
, true)
105 tex
:SetVertexColor(1, 1, 1, QuestHelper_Pref
.track_scale
== pct
*0.01 and 1 or 0)
107 self
:CreateMenuItem(submenu
, QHText("MENU_TRACKER_SCALE")):SetSubmenu(submenu2
)
108 self
:CreateMenuItem(submenu
, QHText("MENU_TRACKER_RESET"))
109 :SetFunction(self
.ResetTrackerPosition
, self
)
110 self
:CreateMenuItem(menu
, QHText("MENU_TRACKER_OPTIONS")):SetSubmenu(submenu
)
113 submenu
= self
:CreateMenu()
114 self
:CreateMenuItem(submenu
, QHFormat("MENU_ZONE_FILTER", QuestHelper_Pref
.filter_zone
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
115 :SetFunction(self
.Filter
, self
, "ZONE")
116 self
:CreateMenuItem(submenu
, QHFormat("MENU_DONE_FILTER", QuestHelper_Pref
.filter_done
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
117 :SetFunction(self
.Filter
, self
, "DONE")
118 self
:CreateMenuItem(submenu
, QHFormat("MENU_BLOCKED_FILTER", QuestHelper_Pref
.filter_blocked
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
119 :SetFunction(self
.Filter
, self
, "BLOCKED")
120 self
:CreateMenuItem(submenu
, QHFormat("MENU_WATCHED_FILTER", QuestHelper_Pref
.filter_watched
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
121 :SetFunction(self
.Filter
, self
, "WATCHED")
122 self
:CreateMenuItem(submenu
, QHFormat("MENU_LEVEL_FILTER", QuestHelper_Pref
.filter_level
and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
123 :SetFunction(self
.Filter
, self
, "LEVEL")
124 submenu2
= self
:CreateMenu()
125 self
:CreateMenuItem(submenu
, QHText("MENU_LEVEL_OFFSET")):SetSubmenu(submenu2
)
128 local menu
= self
:CreateMenuItem(submenu2
, (offset
> 0 and "+" or "")..offset
)
129 menu
:SetFunction(self
.LevelOffset
, self
, offset
)
130 local tex
= self
:CreateIconTexture(item
, 10)
131 menu
:AddTexture(tex
, true)
132 tex
:SetVertexColor(1, 1, 1, QuestHelper_Pref
.level
== offset
and 1 or 0)
134 self
:CreateMenuItem(menu
, QHText("MENU_FILTERS")):SetSubmenu(submenu
)
136 submenu
= self
:CreateMenu()
137 for scale
= 0.2,2,0.2 do
138 local menu
= self
:CreateMenuItem(submenu
, (scale
*100).."%")
139 menu
:SetFunction(QuestHelper
.genericSetScale
, QuestHelper
, "perf_scale_2", "performance factor", .1, 5, scale
)
140 local tex
= self
:CreateIconTexture(item
, 10)
141 menu
:AddTexture(tex
, true)
142 tex
:SetVertexColor(1, 1, 1, QuestHelper_Pref
.perf_scale_2
== scale
and 1 or 0)
144 self
:CreateMenuItem(menu
, QHText("MENU_PERFORMANCE")):SetSubmenu(submenu
)
147 submenu
= self
:CreateMenu()
148 for loc
, tbl
in pairs(QuestHelper_Translations
) do
149 local item
= self
:CreateMenuItem(submenu
, (tbl
.LOCALE_NAME
or "???").." ["..loc
.."]")
150 local tex
= self
:CreateIconTexture(item
, 10)
151 item
:SetFunction(self
.SetLocale
, self
, loc
)
152 item
:AddTexture(tex
, true)
153 tex
:SetVertexColor(1, 1, 1, QuestHelper_Pref
.locale
== loc
and 1 or 0)
155 local item
= self
:CreateMenuItem(menu
, QHText("MENU_LOCALE"))
156 --item:AddTexture(self:CreateIconTexture(item, 25), true) -- Add Globe icon to locale menu.
157 item
:SetSubmenu(submenu
)
160 submenu
= self
:CreateMenu()
161 self
:CreateMenuItem(submenu
, QHText("MENU_HELP_SLASH")):SetFunction(self
.Help
, self
)
162 self
:CreateMenuItem(submenu
, QHText("MENU_HELP_CHANGES")):SetFunction(self
.ChangeLog
, self
)
163 self
:CreateMenuItem(submenu
, QHText("MENU_HELP_SUBMIT")):SetFunction(self
.Submit
, self
)
164 self
:CreateMenuItem(menu
, QHText("MENU_HELP")):SetSubmenu(submenu
)
169 -------------------------------------------------------------------------------------
170 -- Handle clicks on the button
171 function QuestHelperWorldMapButton_OnClick(self
, clicked
)
173 -- Left button toggles whether QuestHelper is displayed (and hence active)
174 if clicked
== "LeftButton" then
175 QuestHelper
:ToggleHide()
177 -- Refresh the tooltip to match. Presumably it's showing - how else could the button get clicked?
178 -- Note: if I'm wrong about my assumption, this could leave the tooltip stranded until user mouses
179 -- back over the button, but I don't think that's too serious.
180 QuestHelperWorldMapButton_OnEnter(self
)
181 elseif clicked
== "RightButton" and not QuestHelper_Pref
.hide
then
182 QuestHelper
:DoSettingsMenu()
186 -------------------------------------------------------------------------------------
187 -- Display or update the tooltip
188 function QuestHelperWorldMapButton_OnEnter(self
)
189 local theme
= QuestHelper
:GetColourTheme()
191 QuestHelper
.tooltip
:SetOwner(self
, "ANCHOR_BOTTOMLEFT", self
:GetWidth(), -5)
192 QuestHelper
.tooltip
:ClearLines()
193 QuestHelper
.tooltip
:AddLine(QHFormat("QH_BUTTON_TOOLTIP1", QHText(QuestHelper_Pref
.hide
and "QH_BUTTON_SHOW" or "QH_BUTTON_HIDE")),
194 unpack(theme
.tooltip
))
195 QuestHelper
.tooltip
:GetPrevLines():SetFont(QuestHelper
.font
.serif
, 12)
196 if not QuestHelper_Pref
.hide
then
197 -- Add the settings menu tooltip when it's available
198 QuestHelper
.tooltip
:AddLine(QHText("QH_BUTTON_TOOLTIP2"), unpack(theme
.tooltip
))
199 QuestHelper
.tooltip
:GetPrevLines():SetFont(QuestHelper
.font
.serif
, 12)
201 QuestHelper
.tooltip
:Show()
204 -------------------------------------------------------------------------------------
205 -- Handle when the world map gets hidden: hide the active menu if any.
206 function QuestHelper_WorldMapHidden()
207 if QuestHelper
.active_menu
then
208 QuestHelper
.active_menu
:DoHide()
209 if QuestHelper
.active_menu
.auto_release
then
210 QuestHelper
.active_menu
= nil
216 -------------------------------------------------------------------------------------
217 -- Set up the Map Button
218 function QuestHelper
:InitMapButton()
220 if not self
.MapButton
then
222 local button
= CreateFrame("Button", "QuestHelperWorldMapButton", WorldMapButton
, "UIPanelButtonTemplate")
224 -- Assign the font QuestHelper selected for the currect locale.
225 if button
.GetFont
then
226 button
:SetFont(self
.font
.serif
, select(2, button
:GetFont()))
230 button
:SetText(QHText("QH_BUTTON_TEXT"))
231 local width
= button
:GetTextWidth() + 30
235 button
:SetWidth(width
)
238 -- Desaturate the button texture if QuestHelper is disabled.
239 -- This line is also in QuestHelper:ToggleHide
240 button
:GetNormalTexture():SetDesaturated(QuestHelper_Pref
.hide
)
242 -- Add event handlers to provide Tooltip
243 QH_Hook(button
, "OnEnter", QuestHelperWorldMapButton_OnEnter
)
244 QH_Hook(button
, "OnLeave", function(this
)
245 QuestHelper
.tooltip
:Hide()
249 QH_Hook(button
, "OnClick", QuestHelperWorldMapButton_OnClick
)
250 button
:RegisterForClicks("LeftButtonUp", "RightButtonUp")
252 -- Add Hide handler, so we can dismiss any menus when map is closed
253 QH_Hook(button
, "OnHide", QuestHelper_WorldMapHidden
)
255 -- Position it on the World Map frame
256 --~ if Cartographer then
257 --~ -- If Cartographer is in use, coordinate with their buttons.
258 -- Trouble is, this makes Cartographer's buttons conflict with the Zone Map dropdown.
259 -- Re-enable this if Cartographer ever learns to work with the Zone Map dropdown.
260 --~ Cartographer:AddMapButton(button, 3)
262 -- Otherwise, just put it in the upper right corner
263 button
:SetPoint("TOPRIGHT", WorldMapButton
, "TOPRIGHT", -10, -10)
264 button
:SetFrameLevel(WorldMapButton
:GetFrameLevel()+1)
265 button
:SetFrameStrata("FULLSCREEN")
268 -- Save the button so we can reference it later if need be
269 self
.MapButton
= button
271 -- User must be toggling the button. We've already got it, so just show it.
272 self
.MapButton
:Show()
276 ----------------------------------------------------------------------------------
277 -- Hide the map button
278 function QuestHelper
:HideMapButton()
279 if self
.MapButton
then
280 self
.MapButton
:Hide()