update changes
[QuestHelper.git] / mapbutton.lua
blob474cf3a3ab6867190d53b5fb06e3c0852535f2eb
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 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)
36 end
38 -- TomTom
39 if TomTom then
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)
42 end
45 -- Flight Timer
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)
49 -- Ant Trails
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)
53 -- Objective Tooltips
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 --[[
58 -- Options regarding party members.
59 local submenu = self:CreateMenu()
60 self:CreateMenuItem(submenu, QHFormat("MENU_PARTY_SHARE", QuestHelper_Pref.share and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
61 :SetFunction(self.ToggleShare, self)
62 self:CreateMenuItem(submenu, QHFormat("MENU_PARTY_SOLO", QuestHelper_Pref.solo and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
63 :SetFunction(self.ToggleSolo, self)
64 self:CreateMenuItem(menu, QHText("MENU_PARTY")):SetSubmenu(submenu)]]
66 -- Map frame button
67 --[[self:CreateMenuItem(menu, QHFormat("MENU_MAP_BUTTON", QuestHelper_Pref.map_button and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
68 :SetFunction(self.ToggleMapButton, self)]]
70 -- Icon Scale
71 submenu = self:CreateMenu()
72 for pct = 50,120,10 do
73 local item = self:CreateMenuItem(submenu, pct.."%")
74 local tex = self:CreateIconTexture(item, 10)
75 item:SetFunction(QuestHelper.genericSetScale, QuestHelper, "scale", "icon scale", .5, 3, pct.."%")
76 item:AddTexture(tex, true)
77 tex:SetVertexColor(1, 1, 1, QuestHelper_Pref.scale == pct*0.01 and 1 or 0)
78 end
79 self:CreateMenuItem(menu, QHText("MENU_ICON_SCALE")):SetSubmenu(submenu)
81 -- Hidden Objectives
82 submenu = self:CreateMenu()
83 QH_PopulateHidden(submenu)
84 self:CreateMenuItem(menu, QHText("HIDDEN_TITLE")):SetSubmenu(submenu)
86 -- Tracker Options
87 submenu = self:CreateMenu()
88 self:CreateMenuItem(submenu, QHFormat("MENU_QUEST_TRACKER", QuestHelper_Pref.track and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
89 :SetFunction(self.ToggleTrack, self)
90 --[[
91 self:CreateMenuItem(submenu, QHFormat("MENU_TRACKER_LEVEL", QuestHelper_Pref.track_level and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
92 :SetFunction(self.ToggleTrackLevel, self)
93 self:CreateMenuItem(submenu, QHFormat("MENU_TRACKER_QCOLOUR", QuestHelper_Pref.track_qcolour and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
94 :SetFunction(self.ToggleTrackQColour, self)
95 self:CreateMenuItem(submenu, QHFormat("MENU_TRACKER_OCOLOUR", QuestHelper_Pref.track_ocolour and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
96 :SetFunction(self.ToggleTrackOColour, self)
98 local submenu2 = self:CreateMenu()
99 for pct = 60,120,10 do
100 local item = self:CreateMenuItem(submenu2, pct.."%")
101 local tex = self:CreateIconTexture(item, 10)
102 item:SetFunction(self.TrackerScale, QuestHelper, pct.."%")
103 item:AddTexture(tex, true)
104 tex:SetVertexColor(1, 1, 1, QuestHelper_Pref.track_scale == pct*0.01 and 1 or 0)
106 self:CreateMenuItem(submenu, QHText("MENU_TRACKER_SCALE")):SetSubmenu(submenu2)
107 self:CreateMenuItem(submenu, QHText("MENU_TRACKER_RESET"))
108 :SetFunction(self.ResetTrackerPosition, self)
109 self:CreateMenuItem(menu, QHText("MENU_TRACKER_OPTIONS")):SetSubmenu(submenu)
111 -- Filters
112 submenu = self:CreateMenu()
113 self:CreateMenuItem(submenu, QHFormat("MENU_ZONE_FILTER", QuestHelper_Pref.filter_zone and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
114 :SetFunction(self.Filter, self, "ZONE")
115 self:CreateMenuItem(submenu, QHFormat("MENU_DONE_FILTER", QuestHelper_Pref.filter_done and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
116 :SetFunction(self.Filter, self, "DONE")
117 self:CreateMenuItem(submenu, QHFormat("MENU_BLOCKED_FILTER", QuestHelper_Pref.filter_blocked and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
118 :SetFunction(self.Filter, self, "BLOCKED")
119 self:CreateMenuItem(submenu, QHFormat("MENU_WATCHED_FILTER", QuestHelper_Pref.filter_watched and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
120 :SetFunction(self.Filter, self, "WATCHED")
121 self:CreateMenuItem(submenu, QHFormat("MENU_LEVEL_FILTER", QuestHelper_Pref.filter_level and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
122 :SetFunction(self.Filter, self, "LEVEL")
123 submenu2 = self:CreateMenu()
124 self:CreateMenuItem(submenu, QHText("MENU_LEVEL_OFFSET")):SetSubmenu(submenu2)
126 for offset = -5,5 do
127 local menu = self:CreateMenuItem(submenu2, (offset > 0 and "+" or "")..offset)
128 menu:SetFunction(self.LevelOffset, self, offset)
129 local tex = self:CreateIconTexture(item, 10)
130 menu:AddTexture(tex, true)
131 tex:SetVertexColor(1, 1, 1, QuestHelper_Pref.level == offset and 1 or 0)
133 self:CreateMenuItem(menu, QHText("MENU_FILTERS")):SetSubmenu(submenu)
135 submenu = self:CreateMenu()
136 for scale = 0.2,2,0.2 do
137 local menu = self:CreateMenuItem(submenu, (scale*100).."%")
138 menu:SetFunction(QuestHelper.genericSetScale, QuestHelper, "perf_scale", "performance factor", .1, 5, scale)
139 local tex = self:CreateIconTexture(item, 10)
140 menu:AddTexture(tex, true)
141 tex:SetVertexColor(1, 1, 1, QuestHelper_Pref.perf_scale == scale and 1 or 0)
143 self:CreateMenuItem(menu, QHText("MENU_PERFORMANCE")):SetSubmenu(submenu)
145 -- Locale
146 submenu = self:CreateMenu()
147 for loc, tbl in pairs(QuestHelper_Translations) do
148 local item = self:CreateMenuItem(submenu, (tbl.LOCALE_NAME or "???").." ["..loc.."]")
149 local tex = self:CreateIconTexture(item, 10)
150 item:SetFunction(self.SetLocale, self, loc)
151 item:AddTexture(tex, true)
152 tex:SetVertexColor(1, 1, 1, QuestHelper_Pref.locale == loc and 1 or 0)
154 local item = self:CreateMenuItem(menu, QHText("MENU_LOCALE"))
155 --item:AddTexture(self:CreateIconTexture(item, 25), true) -- Add Globe icon to locale menu.
156 item:SetSubmenu(submenu)
158 -- Stuff to read.
159 submenu = self:CreateMenu()
160 self:CreateMenuItem(submenu, QHText("MENU_HELP_SLASH")):SetFunction(self.Help, self)
161 self:CreateMenuItem(submenu, QHText("MENU_HELP_CHANGES")):SetFunction(self.ChangeLog, self)
162 self:CreateMenuItem(submenu, QHText("MENU_HELP_SUBMIT")):SetFunction(self.Submit, self)
163 self:CreateMenuItem(menu, QHText("MENU_HELP")):SetSubmenu(submenu)
165 menu:ShowAtCursor()
168 -------------------------------------------------------------------------------------
169 -- Handle clicks on the button
170 function QuestHelperWorldMapButton_OnClick(self, clicked)
172 -- Left button toggles whether QuestHelper is displayed (and hence active)
173 if clicked == "LeftButton" then
174 QuestHelper:ToggleHide()
176 -- Refresh the tooltip to match. Presumably it's showing - how else could the button get clicked?
177 -- Note: if I'm wrong about my assumption, this could leave the tooltip stranded until user mouses
178 -- back over the button, but I don't think that's too serious.
179 QuestHelperWorldMapButton_OnEnter(self)
180 elseif clicked == "RightButton" and not QuestHelper_Pref.hide then
181 QuestHelper:DoSettingsMenu()
185 -------------------------------------------------------------------------------------
186 -- Display or update the tooltip
187 function QuestHelperWorldMapButton_OnEnter(self)
188 local theme = QuestHelper:GetColourTheme()
190 QuestHelper.tooltip:SetOwner(self, "ANCHOR_BOTTOMLEFT", self:GetWidth(), -5)
191 QuestHelper.tooltip:ClearLines()
192 QuestHelper.tooltip:AddLine(QHFormat("QH_BUTTON_TOOLTIP1", QHText(QuestHelper_Pref.hide and "QH_BUTTON_SHOW" or "QH_BUTTON_HIDE")),
193 unpack(theme.tooltip))
194 QuestHelper.tooltip:GetPrevLines():SetFont(QuestHelper.font.serif, 12)
195 if not QuestHelper_Pref.hide then
196 -- Add the settings menu tooltip when it's available
197 QuestHelper.tooltip:AddLine(QHText("QH_BUTTON_TOOLTIP2"), unpack(theme.tooltip))
198 QuestHelper.tooltip:GetPrevLines():SetFont(QuestHelper.font.serif, 12)
200 QuestHelper.tooltip:Show()
203 -------------------------------------------------------------------------------------
204 -- Handle when the world map gets hidden: hide the active menu if any.
205 function QuestHelper_WorldMapHidden()
206 if QuestHelper.active_menu then
207 QuestHelper.active_menu:DoHide()
208 if QuestHelper.active_menu.auto_release then
209 QuestHelper.active_menu = nil
215 -------------------------------------------------------------------------------------
216 -- Set up the Map Button
217 function QuestHelper:InitMapButton()
219 if not self.MapButton then
220 -- Create the button
221 local button = CreateFrame("Button", "QuestHelperWorldMapButton", WorldMapButton, "UIPanelButtonTemplate")
223 -- Assign the font QuestHelper selected for the currect locale.
224 if button.GetFont then
225 button:SetFont(self.font.serif, select(2, button:GetFont()))
228 -- Set up the button
229 button:SetText(QHText("QH_BUTTON_TEXT"))
230 local width = button:GetTextWidth() + 30
231 if width < 110 then
232 width = 110
234 button:SetWidth(width)
235 button:SetHeight(22)
237 -- Desaturate the button texture if QuestHelper is disabled.
238 -- This line is also in QuestHelper:ToggleHide
239 button:GetNormalTexture():SetDesaturated(QuestHelper_Pref.hide)
241 -- Add event handlers to provide Tooltip
242 button:SetScript("OnEnter", QuestHelperWorldMapButton_OnEnter)
243 button:SetScript("OnLeave", function(this)
244 QuestHelper.tooltip:Hide()
245 end)
247 -- Add Click handler
248 button:SetScript("OnClick", QuestHelperWorldMapButton_OnClick)
249 button:RegisterForClicks("LeftButtonUp", "RightButtonUp")
251 -- Add Hide handler, so we can dismiss any menus when map is closed
252 button:SetScript("OnHide", QuestHelper_WorldMapHidden)
254 -- Position it on the World Map frame
255 --~ if Cartographer then
256 --~ -- If Cartographer is in use, coordinate with their buttons.
257 -- Trouble is, this makes Cartographer's buttons conflict with the Zone Map dropdown.
258 -- Re-enable this if Cartographer ever learns to work with the Zone Map dropdown.
259 --~ Cartographer:AddMapButton(button, 3)
260 --~ else
261 -- Otherwise, just put it in the upper right corner
262 button:SetPoint("TOPRIGHT", WorldMapButton, "TOPRIGHT", -10, -10)
263 button:SetFrameLevel(WorldMapButton:GetFrameLevel()+1)
264 button:SetFrameStrata("FULLSCREEN")
265 -- end
267 -- Save the button so we can reference it later if need be
268 self.MapButton = button
269 else
270 -- User must be toggling the button. We've already got it, so just show it.
271 self.MapButton:Show()
275 ----------------------------------------------------------------------------------
276 -- Hide the map button
277 function QuestHelper:HideMapButton()
278 if self.MapButton then
279 self.MapButton:Hide()