Misspelled my email address.
[QuestHelper.git] / mapbutton.lua
blob58d0687666c08f3da1748d94d9e29a6454d20c3a
1 QuestHelper_File["mapbutton.lua"] = "Development Version"
3 --[[
4 mapbutton.lua
6 This module contains code to place a button on the Map Frame, and provides the
7 functionality of that button.
9 Currently Functionality:
10 - Left click on button is equivalent to /qh hide
11 - Right-click on button shows Settings menu
12 - Button has tooltip to that effect
13 - Button serves as hook to detect when map is hidden, in order to hide active menus (if any).
15 History:
16 4-20-2008 Nesher Created
17 4-24-2008 Smariot Added right-click menu
18 4-24-2008 Nesher Localized settings menu. Added hook to hide menus when World Map is hidden.
19 --]]
21 -------------------------------------------------------------------------------------
22 -- Display a Settings menu. Used from the map button's right-click, and from /qh settings.
23 function QuestHelper:DoSettingsMenu()
24 local menu = QuestHelper:CreateMenu()
25 self:CreateMenuTitle(menu, QHText("MENU_SETTINGS"))
27 -- Flight Timer
28 self:CreateMenuItem(menu, QHFormat("MENU_FLIGHT_TIMER", QuestHelper_Pref.flight_time and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
29 :SetFunction(self.ToggleFlightTimes, self)
31 -- Ant Trails
32 self:CreateMenuItem(menu, QHFormat("MENU_ANT_TRAILS", QuestHelper_Pref.show_ants and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
33 :SetFunction(self.ToggleAnts, self)
35 -- Objective Tooltips
36 self:CreateMenuItem(menu, QHFormat("MENU_OBJECTIVE_TIPS", QuestHelper_Pref.show_ants and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
37 :SetFunction(self.ToggleTooltip, self)
39 -- Cartographer Waypoints
40 if Cartographer_Waypoints then
41 self:CreateMenuItem(menu, QHFormat("MENU_WAYPOINT_ARROW", QuestHelper_Pref.cart_wp and QHText("MENU_DISABLE") or QHText("MENU_ENABLE"))..(TomTom and " (Cartographer Waypoints)" or ""))
42 :SetFunction(self.ToggleCartWP, self)
43 end
45 -- TomTom
46 if TomTom then
47 self:CreateMenuItem(menu, QHFormat("MENU_WAYPOINT_ARROW", QuestHelper_Pref.tomtom_wp and QHText("MENU_DISABLE") or QHText("MENU_ENABLE"))..(Cartographer_Waypoints and " (TomTom)" or ""))
48 :SetFunction(self.ToggleTomTomWP, self)
49 end
51 -- Options regarding party members.
52 local submenu = self:CreateMenu()
53 self:CreateMenuItem(submenu, QHFormat("MENU_PARTY_SHARE", QuestHelper_Pref.share and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
54 :SetFunction(self.ToggleShare, self)
55 self:CreateMenuItem(submenu, QHFormat("MENU_PARTY_SOLO", QuestHelper_Pref.solo and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
56 :SetFunction(self.ToggleSolo, self)
57 self:CreateMenuItem(menu, QHText("MENU_PARTY")):SetSubmenu(submenu)
59 -- Map frame button
60 self:CreateMenuItem(menu, QHFormat("MENU_MAP_BUTTON", QuestHelper_Pref.map_button and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
61 :SetFunction(self.ToggleMapButton, self)
63 -- Icon Scale
64 submenu = self:CreateMenu()
65 for pct = 50,120,10 do
66 local item = self:CreateMenuItem(submenu, pct.."%")
67 local tex = self:CreateIconTexture(item, 10)
68 item:SetFunction(QuestHelper.genericSetScale, QuestHelper, "scale", "icon scale", .5, 3, pct.."%")
69 item:AddTexture(tex, true)
70 tex:SetVertexColor(1, 1, 1, QuestHelper_Pref.scale == pct*0.01 and 1 or 0)
71 end
72 self:CreateMenuItem(menu, QHText("MENU_ICON_SCALE")):SetSubmenu(submenu)
74 -- Hidden Objectives
75 submenu = self:CreateMenu()
76 self:PopulateHidden(submenu)
77 self:CreateMenuItem(menu, QHText("HIDDEN_TITLE")):SetSubmenu(submenu)
79 -- Tracker Options
80 submenu = self:CreateMenu()
81 self:CreateMenuItem(submenu, QHFormat("MENU_QUEST_TRACKER", QuestHelper_Pref.track and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
82 :SetFunction(self.ToggleTrack, self)
83 self:CreateMenuItem(submenu, QHFormat("MENU_TRACKER_LEVEL", QuestHelper_Pref.track_level and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
84 :SetFunction(self.ToggleTrackLevel, self)
85 self:CreateMenuItem(submenu, QHFormat("MENU_TRACKER_QCOLOUR", QuestHelper_Pref.track_qcolour and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
86 :SetFunction(self.ToggleTrackQColour, self)
87 self:CreateMenuItem(submenu, QHFormat("MENU_TRACKER_OCOLOUR", QuestHelper_Pref.track_ocolour and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
88 :SetFunction(self.ToggleTrackOColour, self)
89 local submenu2 = self:CreateMenu()
90 for pct = 60,120,10 do
91 local item = self:CreateMenuItem(submenu2, pct.."%")
92 local tex = self:CreateIconTexture(item, 10)
93 item:SetFunction(self.TrackerScale, QuestHelper, pct.."%")
94 item:AddTexture(tex, true)
95 tex:SetVertexColor(1, 1, 1, QuestHelper_Pref.track_scale == pct*0.01 and 1 or 0)
96 end
97 self:CreateMenuItem(submenu, QHText("MENU_TRACKER_SCALE")):SetSubmenu(submenu2)
98 self:CreateMenuItem(submenu, QHText("MENU_TRACKER_RESET"))
99 :SetFunction(self.ResetTrackerPosition, self)
100 self:CreateMenuItem(menu, QHText("MENU_TRACKER_OPTIONS")):SetSubmenu(submenu)
102 -- Filters
103 submenu = self:CreateMenu()
104 self:CreateMenuItem(submenu, QHFormat("MENU_ZONE_FILTER", QuestHelper_Pref.filter_zone and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
105 :SetFunction(self.Filter, self, "ZONE")
106 self:CreateMenuItem(submenu, QHFormat("MENU_DONE_FILTER", QuestHelper_Pref.filter_done and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
107 :SetFunction(self.Filter, self, "DONE")
108 self:CreateMenuItem(submenu, QHFormat("MENU_BLOCKED_FILTER", QuestHelper_Pref.filter_blocked and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
109 :SetFunction(self.Filter, self, "BLOCKED")
110 self:CreateMenuItem(submenu, QHFormat("MENU_LEVEL_FILTER", QuestHelper_Pref.filter_level and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
111 :SetFunction(self.Filter, self, "LEVEL")
112 submenu2 = self:CreateMenu()
113 self:CreateMenuItem(submenu, QHText("MENU_LEVEL_OFFSET")):SetSubmenu(submenu2)
115 for offset = -5,5 do
116 local menu = self:CreateMenuItem(submenu2, (offset > 0 and "+" or "")..offset)
117 menu:SetFunction(self.LevelOffset, self, offset)
118 local tex = self:CreateIconTexture(item, 10)
119 menu:AddTexture(tex, true)
120 tex:SetVertexColor(1, 1, 1, QuestHelper_Pref.level == offset and 1 or 0)
122 self:CreateMenuItem(menu, QHText("MENU_FILTERS")):SetSubmenu(submenu)
124 submenu = self:CreateMenu()
125 for scale = 0.2,2,0.2 do
126 local menu = self:CreateMenuItem(submenu, (scale*100).."%")
127 menu:SetFunction(QuestHelper.genericSetScale, QuestHelper, "perf_scale", "performance factor", .1, 5, scale)
128 local tex = self:CreateIconTexture(item, 10)
129 menu:AddTexture(tex, true)
130 tex:SetVertexColor(1, 1, 1, QuestHelper_Pref.perf_scale == scale and 1 or 0)
132 self:CreateMenuItem(menu, QHText("MENU_PERFORMANCE")):SetSubmenu(submenu)
134 -- Locale
135 submenu = self:CreateMenu()
136 for loc, tbl in pairs(QuestHelper_Translations) do
137 local item = self:CreateMenuItem(submenu, (tbl.LOCALE_NAME or "???").." ["..loc.."]")
138 local tex = self:CreateIconTexture(item, 10)
139 item:SetFunction(self.SetLocale, self, loc)
140 item:AddTexture(tex, true)
141 tex:SetVertexColor(1, 1, 1, QuestHelper_Pref.locale == loc and 1 or 0)
143 local item = self:CreateMenuItem(menu, QHText("MENU_LOCALE"))
144 item:AddTexture(self:CreateIconTexture(item, 25), true) -- Add Globe icon to locale menu.
145 item:SetSubmenu(submenu)
147 -- Stuff to read.
148 submenu = self:CreateMenu()
149 self:CreateMenuItem(submenu, QHText("MENU_HELP_SLASH")):SetFunction(self.Help, self)
150 self:CreateMenuItem(submenu, QHText("MENU_HELP_CHANGES")):SetFunction(self.ChangeLog, self)
151 self:CreateMenuItem(submenu, QHText("MENU_HELP_SUBMIT")):SetFunction(self.Submit, self)
152 self:CreateMenuItem(menu, QHText("MENU_HELP")):SetSubmenu(submenu)
154 menu:ShowAtCursor()
157 -------------------------------------------------------------------------------------
158 -- Handle clicks on the button
159 function QuestHelperWorldMapButton_OnClick(self, clicked)
161 -- Left button toggles whether QuestHelper is displayed (and hence active)
162 if clicked == "LeftButton" then
163 QuestHelper:ToggleHide()
165 -- Refresh the tooltip to match. Presumably it's showing - how else could the button get clicked?
166 -- Note: if I'm wrong about my assumption, this could leave the tooltip stranded until user mouses
167 -- back over the button, but I don't think that's too serious.
168 QuestHelperWorldMapButton_OnEnter(self)
169 elseif clicked == "RightButton" and not QuestHelper_Pref.hide then
170 QuestHelper:DoSettingsMenu()
174 -------------------------------------------------------------------------------------
175 -- Display or update the tooltip
176 function QuestHelperWorldMapButton_OnEnter(self)
177 local theme = QuestHelper:GetColourTheme()
179 QuestHelper.tooltip:SetOwner(self, "ANCHOR_BOTTOMLEFT", self:GetWidth(), -5)
180 QuestHelper.tooltip:ClearLines()
181 QuestHelper.tooltip:AddLine(QHFormat("QH_BUTTON_TOOLTIP1", QHText(QuestHelper_Pref.hide and "QH_BUTTON_SHOW" or "QH_BUTTON_HIDE")),
182 unpack(theme.tooltip))
183 QuestHelper.tooltip:GetPrevLines():SetFont(QuestHelper.font.serif, 12)
184 if not QuestHelper_Pref.hide then
185 -- Add the settings menu tooltip when it's available
186 QuestHelper.tooltip:AddLine(QHText("QH_BUTTON_TOOLTIP2"), unpack(theme.tooltip))
187 QuestHelper.tooltip:GetPrevLines():SetFont(QuestHelper.font.serif, 12)
189 QuestHelper.tooltip:Show()
192 -------------------------------------------------------------------------------------
193 -- Handle when the world map gets hidden: hide the active menu if any.
194 function QuestHelper_WorldMapHidden()
195 if QuestHelper.active_menu then
196 QuestHelper.active_menu:DoHide()
197 if QuestHelper.active_menu.auto_release then
198 QuestHelper.active_menu = nil
204 -------------------------------------------------------------------------------------
205 -- Set up the Map Button
206 function QuestHelper:InitMapButton()
208 if not self.MapButton then
209 -- Create the button
210 local button = CreateFrame("Button", "QuestHelperWorldMapButton", WorldMapFrame, "UIPanelButtonTemplate")
212 -- Assign the font QuestHelper selected for the currect locale.
213 button:SetFont(self.font.serif, select(2, button:GetFont()))
215 -- Set up the button
216 button:SetText(QHText("QH_BUTTON_TEXT"))
217 local width = button:GetTextWidth() + 30
218 if width < 110 then
219 width = 110
221 button:SetWidth(width)
222 button:SetHeight(22)
224 -- Desaturate the button texture if QuestHelper is disabled.
225 -- This line is also in QuestHelper:ToggleHide
226 button:GetNormalTexture():SetDesaturated(QuestHelper_Pref.hide)
228 -- Add event handlers to provide Tooltip
229 button:SetScript("OnEnter", QuestHelperWorldMapButton_OnEnter)
230 button:SetScript("OnLeave", function(this)
231 QuestHelper.tooltip:Hide()
232 end)
234 -- Add Click handler
235 button:SetScript("OnClick", QuestHelperWorldMapButton_OnClick)
236 button:RegisterForClicks("LeftButtonUp", "RightButtonUp")
238 -- Add Hide handler, so we can dismiss any menus when map is closed
239 button:SetScript("OnHide", QuestHelper_WorldMapHidden)
241 -- Position it on the World Map frame
242 --~ if Cartographer then
243 --~ -- If Cartographer is in use, coordinate with their buttons.
244 -- Trouble is, this makes Cartographer's buttons conflict with the Zone Map dropdown.
245 -- Re-enable this if Cartographer ever learns to work with the Zone Map dropdown.
246 --~ Cartographer:AddMapButton(button, 3)
247 --~ else
248 -- Otherwise, just put it in the upper right corner
249 button:SetPoint("RIGHT", WorldMapPositioningGuide, "RIGHT", -20, 0)
250 button:SetPoint("BOTTOM", WorldMapZoomOutButton, "BOTTOM", 0, 0)
251 -- end
253 -- Save the button so we can reference it later if need be
254 self.MapButton = button
255 else
256 -- User must be toggling the button. We've already got it, so just show it.
257 self.MapButton:Show()
261 ----------------------------------------------------------------------------------
262 -- Hide the map button
263 function QuestHelper:HideMapButton()
264 if self.MapButton then
265 self.MapButton:Hide()