Displays help using the same code used to display the change log.
[QuestHelper.git] / mapbutton.lua
blobf6e1d7d339da783944f5907ec212d5fdccba1415
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 -- Cartographer Waypoints
36 if Cartographer_Waypoints then
37 self:CreateMenuItem(menu, QHFormat("MENU_WAYPOINT_ARROW", QuestHelper_Pref.cart_wp and QHText("MENU_DISABLE") or QHText("MENU_ENABLE"))..(TomTom and " (Cartographer Waypoints)" or ""))
38 :SetFunction(self.ToggleCartWP, self)
39 end
41 -- TomTom
42 if TomTom then
43 self:CreateMenuItem(menu, QHFormat("MENU_WAYPOINT_ARROW", QuestHelper_Pref.tomtom_wp and QHText("MENU_DISABLE") or QHText("MENU_ENABLE"))..(Cartographer_Waypoints and " (TomTom)" or ""))
44 :SetFunction(self.ToggleTomTomWP, self)
45 end
47 -- Map frame button
48 self:CreateMenuItem(menu, QHFormat("MENU_MAP_BUTTON", QuestHelper_Pref.map_button and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
49 :SetFunction(self.ToggleMapButton, self)
51 -- Icon Scale
52 local submenu = self:CreateMenu()
53 for pct = 50,120,10 do
54 local item = self:CreateMenuItem(submenu, pct.."%")
55 local tex = self:CreateIconTexture(item, 10)
56 item:SetFunction(self.SetIconScale, QuestHelper, pct.."%")
57 item:AddTexture(tex, true)
58 tex:SetVertexColor(1, 1, 1, QuestHelper_Pref.scale == pct*0.01 and 1 or 0)
59 end
60 self:CreateMenuItem(menu, QHText("MENU_ICON_SCALE")):SetSubmenu(submenu)
62 -- Hidden Objectives
63 submenu = self:CreateMenu()
64 self:PopulateHidden(submenu)
65 self:CreateMenuItem(menu, QHText("HIDDEN_TITLE")):SetSubmenu(submenu)
67 -- Filters
68 submenu = self:CreateMenu()
69 self:CreateMenuItem(submenu, QHFormat("MENU_ZONE_FILTER", QuestHelper_Pref.filter_zone and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
70 :SetFunction(self.Filter, self, "ZONE")
71 self:CreateMenuItem(submenu, QHFormat("MENU_DONE_FILTER", QuestHelper_Pref.filter_done and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
72 :SetFunction(self.Filter, self, "DONE")
73 self:CreateMenuItem(submenu, QHFormat("MENU_BLOCKED_FILTER", QuestHelper_Pref.filter_blocked and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
74 :SetFunction(self.Filter, self, "BLOCKED")
75 self:CreateMenuItem(submenu, QHFormat("MENU_LEVEL_FILTER", QuestHelper_Pref.filter_level and QHText("MENU_DISABLE") or QHText("MENU_ENABLE")))
76 :SetFunction(self.Filter, self, "LEVEL")
77 local submenu2 = self:CreateMenu()
78 self:CreateMenuItem(submenu, QHText("MENU_LEVEL_OFFSET")):SetSubmenu(submenu2)
80 for offset = -5,5 do
81 local menu = self:CreateMenuItem(submenu2, (offset > 0 and "+" or "")..offset)
82 menu:SetFunction(self.LevelOffset, self, offset)
83 local tex = self:CreateIconTexture(item, 10)
84 menu:AddTexture(tex, true)
85 tex:SetVertexColor(1, 1, 1, QuestHelper_Pref.level == offset and 1 or 0)
86 end
87 self:CreateMenuItem(menu, QHText("MENU_FILTERS")):SetSubmenu(submenu)
89 submenu = self:CreateMenu()
90 for scale = 0.2,2,0.2 do
91 local menu = self:CreateMenuItem(submenu, (scale*100).."%")
92 menu:SetFunction(self.SetPerfFactor, self, scale)
93 local tex = self:CreateIconTexture(item, 10)
94 menu:AddTexture(tex, true)
95 tex:SetVertexColor(1, 1, 1, QuestHelper_Pref.perf_scale == scale and 1 or 0)
96 end
97 self:CreateMenuItem(menu, QHText("MENU_PERFORMANCE")):SetSubmenu(submenu)
99 -- Locale
100 submenu = self:CreateMenu()
101 for loc, tbl in pairs(QuestHelper_Translations) do
102 local item = self:CreateMenuItem(submenu, (tbl.LOCALE_NAME or "???").." ["..loc.."]")
103 local tex = self:CreateIconTexture(item, 10)
104 item:SetFunction(self.SetLocale, self, loc)
105 item:AddTexture(tex, true)
106 tex:SetVertexColor(1, 1, 1, QuestHelper_Pref.locale == loc and 1 or 0)
108 local item = self:CreateMenuItem(menu, QHText("MENU_LOCALE"))
109 item:AddTexture(self:CreateIconTexture(item, 25), true) -- Add Globe icon to locale menu.
110 item:SetSubmenu(submenu)
112 menu:ShowAtCursor()
115 -------------------------------------------------------------------------------------
116 -- Handle clicks on the button
117 function QuestHelperWorldMapButton_OnClick(self, clicked)
119 -- Left button toggles whether QuestHelper is displayed (and hence active)
120 if clicked == "LeftButton" then
121 QuestHelper:ToggleHide()
123 -- Refresh the tooltip to match. Presumably it's showing - how else could the button get clicked?
124 -- Note: if I'm wrong about my assumption, this could leave the tooltip stranded until user mouses
125 -- back over the button, but I don't think that's too serious.
126 QuestHelperWorldMapButton_OnEnter(self)
127 elseif clicked == "RightButton" and not QuestHelper_Pref.hide then
128 QuestHelper:DoSettingsMenu()
132 -------------------------------------------------------------------------------------
133 -- Display or update the tooltip
134 function QuestHelperWorldMapButton_OnEnter(self)
135 local theme = QuestHelper:GetColourTheme()
137 QuestHelper.tooltip:SetOwner(self, "ANCHOR_BOTTOMLEFT", self:GetWidth(), -5)
138 QuestHelper.tooltip:ClearLines()
139 QuestHelper.tooltip:AddLine(QHFormat("QH_BUTTON_TOOLTIP1", QHText(QuestHelper_Pref.hide and "QH_BUTTON_SHOW" or "QH_BUTTON_HIDE")),
140 unpack(theme.tooltip))
141 QuestHelper.tooltip:GetPrevLines():SetFont(QuestHelper.font.serif, 12)
142 if not QuestHelper_Pref.hide then
143 -- Add the settings menu tooltip when it's available
144 QuestHelper.tooltip:AddLine(QHText("QH_BUTTON_TOOLTIP2"), unpack(theme.tooltip))
145 QuestHelper.tooltip:GetPrevLines():SetFont(QuestHelper.font.serif, 12)
147 QuestHelper.tooltip:Show()
150 -------------------------------------------------------------------------------------
151 -- Handle when the world map gets hidden: hide the active menu if any.
152 function QuestHelper_WorldMapHidden()
153 if QuestHelper.active_menu then
154 QuestHelper.active_menu:DoHide()
155 if QuestHelper.active_menu.auto_release then
156 QuestHelper.active_menu = nil
162 -------------------------------------------------------------------------------------
163 -- Set up the Map Button
164 function QuestHelper:InitMapButton()
166 if not self.MapButton then
167 -- Create the button
168 local button = CreateFrame("Button", "QuestHelperWorldMapButton", WorldMapFrame, "UIPanelButtonTemplate")
170 -- Assign the font QuestHelper selected for the currect locale.
171 button:SetFont(self.font.serif, select(2, button:GetFont()))
173 -- Set up the button
174 button:SetText(QHText("QH_BUTTON_TEXT"))
175 local width = button:GetTextWidth() + 30
176 if width < 110 then
177 width = 110
179 button:SetWidth(width)
180 button:SetHeight(22)
182 -- Desaturate the button texture if QuestHelper is disabled.
183 -- This line is also in QuestHelper:ToggleHide
184 button:GetNormalTexture():SetDesaturated(QuestHelper_Pref.hide)
186 -- Add event handlers to provide Tooltip
187 button:SetScript("OnEnter", QuestHelperWorldMapButton_OnEnter)
188 button:SetScript("OnLeave", function(this)
189 QuestHelper.tooltip:Hide()
190 end)
192 -- Add Click handler
193 button:SetScript("OnClick", QuestHelperWorldMapButton_OnClick)
194 button:RegisterForClicks("LeftButtonUp", "RightButtonUp")
196 -- Add Hide handler, so we can dismiss any menus when map is closed
197 button:SetScript("OnHide", QuestHelper_WorldMapHidden)
199 -- Position it on the World Map frame
200 --~ if Cartographer then
201 --~ -- If Cartographer is in use, coordinate with their buttons.
202 -- Trouble is, this makes Cartographer's buttons conflict with the Zone Map dropdown.
203 -- Re-enable this if Cartographer ever learns to work with the Zone Map dropdown.
204 --~ Cartographer:AddMapButton(button, 3)
205 --~ else
206 -- Otherwise, just put it in the upper right corner
207 button:SetPoint("RIGHT", WorldMapPositioningGuide, "RIGHT", -20, 0)
208 button:SetPoint("BOTTOM", WorldMapZoomOutButton, "BOTTOM", 0, 0)
209 -- end
211 -- Save the button so we can reference it later if need be
212 self.MapButton = button
213 else
214 -- User must be toggling the button. We've already got it, so just show it.
215 self.MapButton:Show()
219 ----------------------------------------------------------------------------------
220 -- Hide the map button
221 function QuestHelper:HideMapButton()
222 if self.MapButton then
223 self.MapButton:Hide()