Had wrong file ignored.
[QuestHelper.git] / mapbutton.lua
blobeb45d4e214e198a0929240f69bc22eeb7f790a43
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 -- Map frame button
52 self:CreateMenuItem(menu, QHFormat("MENU_MAP_BUTTON", QuestHelper_Pref.map_button and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
53 :SetFunction(self.ToggleMapButton, self)
55 -- Icon Scale
56 local submenu = self:CreateMenu()
57 for pct = 50,120,10 do
58 local item = self:CreateMenuItem(submenu, pct.."%")
59 local tex = self:CreateIconTexture(item, 10)
60 item:SetFunction(QuestHelper.genericSetScale, QuestHelper, "scale", "icon scale", .5, 3, pct.."%")
61 item:AddTexture(tex, true)
62 tex:SetVertexColor(1, 1, 1, QuestHelper_Pref.scale == pct*0.01 and 1 or 0)
63 end
64 self:CreateMenuItem(menu, QHText("MENU_ICON_SCALE")):SetSubmenu(submenu)
66 -- Hidden Objectives
67 submenu = self:CreateMenu()
68 self:PopulateHidden(submenu)
69 self:CreateMenuItem(menu, QHText("HIDDEN_TITLE")):SetSubmenu(submenu)
71 -- Tracker Options
72 submenu = self:CreateMenu()
73 self:CreateMenuItem(submenu, QHFormat("MENU_QUEST_TRACKER", QuestHelper_Pref.track and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
74 :SetFunction(self.ToggleTrack, self)
75 self:CreateMenuItem(submenu, QHFormat("MENU_TRACKER_LEVEL", QuestHelper_Pref.track_level and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
76 :SetFunction(self.ToggleTrackLevel, self)
77 self:CreateMenuItem(submenu, QHFormat("MENU_TRACKER_QCOLOUR", QuestHelper_Pref.track_qcolour and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
78 :SetFunction(self.ToggleTrackQColour, self)
79 local submenu2 = self:CreateMenu()
80 for pct = 60,120,10 do
81 local item = self:CreateMenuItem(submenu2, pct.."%")
82 local tex = self:CreateIconTexture(item, 10)
83 item:SetFunction(self.TrackerScale, QuestHelper, pct.."%")
84 item:AddTexture(tex, true)
85 tex:SetVertexColor(1, 1, 1, QuestHelper_Pref.track_scale == pct*0.01 and 1 or 0)
86 end
87 self:CreateMenuItem(submenu, QHText("MENU_TRACKER_SCALE")):SetSubmenu(submenu2)
88 self:CreateMenuItem(menu, QHText("MENU_TRACKER_OPTIONS")):SetSubmenu(submenu)
90 -- Filters
91 submenu = self:CreateMenu()
92 self:CreateMenuItem(submenu, QHFormat("MENU_ZONE_FILTER", QuestHelper_Pref.filter_zone and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
93 :SetFunction(self.Filter, self, "ZONE")
94 self:CreateMenuItem(submenu, QHFormat("MENU_DONE_FILTER", QuestHelper_Pref.filter_done and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
95 :SetFunction(self.Filter, self, "DONE")
96 self:CreateMenuItem(submenu, QHFormat("MENU_BLOCKED_FILTER", QuestHelper_Pref.filter_blocked and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
97 :SetFunction(self.Filter, self, "BLOCKED")
98 self:CreateMenuItem(submenu, QHFormat("MENU_LEVEL_FILTER", QuestHelper_Pref.filter_level and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
99 :SetFunction(self.Filter, self, "LEVEL")
100 submenu2 = self:CreateMenu()
101 self:CreateMenuItem(submenu, QHText("MENU_LEVEL_OFFSET")):SetSubmenu(submenu2)
103 for offset = -5,5 do
104 local menu = self:CreateMenuItem(submenu2, (offset > 0 and "+" or "")..offset)
105 menu:SetFunction(self.LevelOffset, self, offset)
106 local tex = self:CreateIconTexture(item, 10)
107 menu:AddTexture(tex, true)
108 tex:SetVertexColor(1, 1, 1, QuestHelper_Pref.level == offset and 1 or 0)
110 self:CreateMenuItem(menu, QHText("MENU_FILTERS")):SetSubmenu(submenu)
112 submenu = self:CreateMenu()
113 for scale = 0.2,2,0.2 do
114 local menu = self:CreateMenuItem(submenu, (scale*100).."%")
115 menu:SetFunction(QuestHelper.genericSetScale, QuestHelper, "perf_scale", "performance factor", .1, 5, scale)
116 local tex = self:CreateIconTexture(item, 10)
117 menu:AddTexture(tex, true)
118 tex:SetVertexColor(1, 1, 1, QuestHelper_Pref.perf_scale == scale and 1 or 0)
120 self:CreateMenuItem(menu, QHText("MENU_PERFORMANCE")):SetSubmenu(submenu)
122 -- Locale
123 submenu = self:CreateMenu()
124 for loc, tbl in pairs(QuestHelper_Translations) do
125 local item = self:CreateMenuItem(submenu, (tbl.LOCALE_NAME or "???").." ["..loc.."]")
126 local tex = self:CreateIconTexture(item, 10)
127 item:SetFunction(self.SetLocale, self, loc)
128 item:AddTexture(tex, true)
129 tex:SetVertexColor(1, 1, 1, QuestHelper_Pref.locale == loc and 1 or 0)
131 local item = self:CreateMenuItem(menu, QHText("MENU_LOCALE"))
132 item:AddTexture(self:CreateIconTexture(item, 25), true) -- Add Globe icon to locale menu.
133 item:SetSubmenu(submenu)
135 menu:ShowAtCursor()
138 -------------------------------------------------------------------------------------
139 -- Handle clicks on the button
140 function QuestHelperWorldMapButton_OnClick(self, clicked)
142 -- Left button toggles whether QuestHelper is displayed (and hence active)
143 if clicked == "LeftButton" then
144 QuestHelper:ToggleHide()
146 -- Refresh the tooltip to match. Presumably it's showing - how else could the button get clicked?
147 -- Note: if I'm wrong about my assumption, this could leave the tooltip stranded until user mouses
148 -- back over the button, but I don't think that's too serious.
149 QuestHelperWorldMapButton_OnEnter(self)
150 elseif clicked == "RightButton" and not QuestHelper_Pref.hide then
151 QuestHelper:DoSettingsMenu()
155 -------------------------------------------------------------------------------------
156 -- Display or update the tooltip
157 function QuestHelperWorldMapButton_OnEnter(self)
158 local theme = QuestHelper:GetColourTheme()
160 QuestHelper.tooltip:SetOwner(self, "ANCHOR_BOTTOMLEFT", self:GetWidth(), -5)
161 QuestHelper.tooltip:ClearLines()
162 QuestHelper.tooltip:AddLine(QHFormat("QH_BUTTON_TOOLTIP1", QHText(QuestHelper_Pref.hide and "QH_BUTTON_SHOW" or "QH_BUTTON_HIDE")),
163 unpack(theme.tooltip))
164 QuestHelper.tooltip:GetPrevLines():SetFont(QuestHelper.font.serif, 12)
165 if not QuestHelper_Pref.hide then
166 -- Add the settings menu tooltip when it's available
167 QuestHelper.tooltip:AddLine(QHText("QH_BUTTON_TOOLTIP2"), unpack(theme.tooltip))
168 QuestHelper.tooltip:GetPrevLines():SetFont(QuestHelper.font.serif, 12)
170 QuestHelper.tooltip:Show()
173 -------------------------------------------------------------------------------------
174 -- Handle when the world map gets hidden: hide the active menu if any.
175 function QuestHelper_WorldMapHidden()
176 if QuestHelper.active_menu then
177 QuestHelper.active_menu:DoHide()
178 if QuestHelper.active_menu.auto_release then
179 QuestHelper.active_menu = nil
185 -------------------------------------------------------------------------------------
186 -- Set up the Map Button
187 function QuestHelper:InitMapButton()
189 if not self.MapButton then
190 -- Create the button
191 local button = CreateFrame("Button", "QuestHelperWorldMapButton", WorldMapFrame, "UIPanelButtonTemplate")
193 -- Assign the font QuestHelper selected for the currect locale.
194 button:SetFont(self.font.serif, select(2, button:GetFont()))
196 -- Set up the button
197 button:SetText(QHText("QH_BUTTON_TEXT"))
198 local width = button:GetTextWidth() + 30
199 if width < 110 then
200 width = 110
202 button:SetWidth(width)
203 button:SetHeight(22)
205 -- Desaturate the button texture if QuestHelper is disabled.
206 -- This line is also in QuestHelper:ToggleHide
207 button:GetNormalTexture():SetDesaturated(QuestHelper_Pref.hide)
209 -- Add event handlers to provide Tooltip
210 button:SetScript("OnEnter", QuestHelperWorldMapButton_OnEnter)
211 button:SetScript("OnLeave", function(this)
212 QuestHelper.tooltip:Hide()
213 end)
215 -- Add Click handler
216 button:SetScript("OnClick", QuestHelperWorldMapButton_OnClick)
217 button:RegisterForClicks("LeftButtonUp", "RightButtonUp")
219 -- Add Hide handler, so we can dismiss any menus when map is closed
220 button:SetScript("OnHide", QuestHelper_WorldMapHidden)
222 -- Position it on the World Map frame
223 --~ if Cartographer then
224 --~ -- If Cartographer is in use, coordinate with their buttons.
225 -- Trouble is, this makes Cartographer's buttons conflict with the Zone Map dropdown.
226 -- Re-enable this if Cartographer ever learns to work with the Zone Map dropdown.
227 --~ Cartographer:AddMapButton(button, 3)
228 --~ else
229 -- Otherwise, just put it in the upper right corner
230 button:SetPoint("RIGHT", WorldMapPositioningGuide, "RIGHT", -20, 0)
231 button:SetPoint("BOTTOM", WorldMapZoomOutButton, "BOTTOM", 0, 0)
232 -- end
234 -- Save the button so we can reference it later if need be
235 self.MapButton = button
236 else
237 -- User must be toggling the button. We've already got it, so just show it.
238 self.MapButton:Show()
242 ----------------------------------------------------------------------------------
243 -- Hide the map button
244 function QuestHelper:HideMapButton()
245 if self.MapButton then
246 self.MapButton:Hide()