Merge branch 'master' of git://cams.pavlovian.net/questhelper
[QuestHelper.git] / mapbutton.lua
blob4e43800023eb85fe4d6195e76809f810d27f510e
1 QuestHelper_File["mapbutton.lua"] = "Development Version"
2 QuestHelper_Loadtime["mapbutton.lua"] = GetTime()
4 --[[
5 mapbutton.lua
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).
16 History:
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.
20 --]]
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 -- Flight Timer
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)
32 -- Ant Trails
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)
36 -- Objective Tooltips
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 and QHText("MENU_DISABLE") or QHText("MENU_ENABLE"))..(TomTom and " (Cartographer Waypoints)" or ""))
43 :SetFunction(self.ToggleCartWP, self)
44 end
46 -- TomTom
47 if TomTom then
48 self:CreateMenuItem(menu, QHFormat("MENU_WAYPOINT_ARROW", QuestHelper_Pref.tomtom_wp and QHText("MENU_DISABLE") or QHText("MENU_ENABLE"))..(Cartographer_Waypoints and " (TomTom)" or ""))
49 :SetFunction(self.ToggleTomTomWP, self)
50 end
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)
60 -- Map frame button
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)
64 -- Icon Scale
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)
72 end
73 self:CreateMenuItem(menu, QHText("MENU_ICON_SCALE")):SetSubmenu(submenu)
75 -- Hidden Objectives
76 submenu = self:CreateMenu()
77 self:PopulateHidden(submenu)
78 self:CreateMenuItem(menu, QHText("HIDDEN_TITLE")):SetSubmenu(submenu)
80 -- Tracker Options
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)
97 end
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)
103 -- Filters
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)
118 for offset = -5,5 do
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)
137 -- Locale
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)
150 -- Stuff to read.
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)
157 menu:ShowAtCursor()
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()
211 if not self.MapButton then
212 -- Create the button
213 local button = CreateFrame("Button", "QuestHelperWorldMapButton", WorldMapFrame, "UIPanelButtonTemplate")
215 -- Assign the font QuestHelper selected for the currect locale.
216 if button.GetFont then
217 button:SetFont(self.font.serif, select(2, button:GetFont()))
220 -- Set up the button
221 button:SetText(QHText("QH_BUTTON_TEXT"))
222 local width = button:GetTextWidth() + 30
223 if width < 110 then
224 width = 110
226 button:SetWidth(width)
227 button:SetHeight(22)
229 -- Desaturate the button texture if QuestHelper is disabled.
230 -- This line is also in QuestHelper:ToggleHide
231 button:GetNormalTexture():SetDesaturated(QuestHelper_Pref.hide)
233 -- Add event handlers to provide Tooltip
234 button:SetScript("OnEnter", QuestHelperWorldMapButton_OnEnter)
235 button:SetScript("OnLeave", function(this)
236 QuestHelper.tooltip:Hide()
237 end)
239 -- Add Click handler
240 button:SetScript("OnClick", QuestHelperWorldMapButton_OnClick)
241 button:RegisterForClicks("LeftButtonUp", "RightButtonUp")
243 -- Add Hide handler, so we can dismiss any menus when map is closed
244 button:SetScript("OnHide", QuestHelper_WorldMapHidden)
246 -- Position it on the World Map frame
247 --~ if Cartographer then
248 --~ -- If Cartographer is in use, coordinate with their buttons.
249 -- Trouble is, this makes Cartographer's buttons conflict with the Zone Map dropdown.
250 -- Re-enable this if Cartographer ever learns to work with the Zone Map dropdown.
251 --~ Cartographer:AddMapButton(button, 3)
252 --~ else
253 -- Otherwise, just put it in the upper right corner
254 button:SetPoint("RIGHT", WorldMapPositioningGuide, "RIGHT", -20, 0)
255 button:SetPoint("BOTTOM", WorldMapZoomOutButton, "BOTTOM", 0, 0)
256 -- end
258 -- Save the button so we can reference it later if need be
259 self.MapButton = button
260 else
261 -- User must be toggling the button. We've already got it, so just show it.
262 self.MapButton:Show()
266 ----------------------------------------------------------------------------------
267 -- Hide the map button
268 function QuestHelper:HideMapButton()
269 if self.MapButton then
270 self.MapButton:Hide()