Made purge command reset the locale of the saved data, and added files for 0.44 release.
[QuestHelper.git] / mapbutton.lua
blobe414b7d55dabb06072075e97c6469f4b6faffab5
1 --[[
2 mapbutton.lua
4 This module contains code to place a button on the Map Frame, and provides the
5 functionality of that button.
7 Currently Functionality:
8 - Left click on button is equivalent to /qh hide
9 - Button has tooltip to that effect
11 History:
12 4-20-2008 Created Nesher
13 --]]
15 -------------------------------------------------------------------------------------
16 -- Handle clicks on the button
17 function QuestHelperWorldMapButton_OnClick(self, clicked)
19 -- Left button toggles whether QuestHelper is displayed (and hence active)
20 if clicked == "LeftButton" then
21 QuestHelper:ToggleHide()
23 -- Refresh the tooltip to match. Presumably it's showing - how else could the button get clicked?
24 -- Note: if I'm wrong about my assumption, this could leave the tooltip stranded until user mouses
25 -- back over the button, but I don't think that's too serious.
26 QuestHelperWorldMapButton_OnEnter(self)
27 elseif clicked == "RightButton" and not QuestHelper_Pref.hide then
28 -- This is a substitute until a proper menu is created.
29 local menu = QuestHelper:CreateMenu()
30 QuestHelper:CreateMenuTitle(menu, "Settings")
32 -- Flight Timer
33 QuestHelper:CreateMenuItem(menu, QuestHelper_Pref.flight_time and "Disable Flight Timer" or "Enable Flight Timer"):SetFunction(QuestHelper.ToggleFlightTimes, QuestHelper)
35 -- Ant Trails
36 QuestHelper:CreateMenuItem(menu, QuestHelper_Pref.show_ants and "Disable Ant Trails" or "Enable Ant Trails"):SetFunction(QuestHelper.ToggleAnts, QuestHelper)
38 -- Cartographer Waypoints
39 if Cartographer_Waypoints then
40 QuestHelper:CreateMenuItem(menu, QuestHelper_Pref.cart_wp and "Disable Waypoint Arrow" or "Enable Waypoint Arrow"):SetFunction(QuestHelper.ToggleCartWP, QuestHelper)
41 end
43 -- Icon Scale
44 local submenu = QuestHelper:CreateMenu()
45 for pct = 50,120,10 do
46 QuestHelper:CreateMenuItem(submenu, pct.."%"):SetFunction(QuestHelper.SetIconScale, QuestHelper, pct.."%")
47 end
48 QuestHelper:CreateMenuItem(menu, "Icon Scale"):SetSubmenu(submenu)
50 -- Filters
51 submenu = QuestHelper:CreateMenu()
52 QuestHelper:CreateMenuItem(submenu, QuestHelper_Pref.filter_zone and "Disable Zone Filter" or "Enable Zone Filter"):SetFunction(QuestHelper.Filter, QuestHelper, "ZONE")
53 QuestHelper:CreateMenuItem(submenu, QuestHelper_Pref.filter_done and "Disable Done Filter" or "Enable Done Filter"):SetFunction(QuestHelper.Filter, QuestHelper, "DONE")
54 QuestHelper:CreateMenuItem(submenu, QuestHelper_Pref.filter_level and "Disable Level Filter" or "Enable Level Filter"):SetFunction(QuestHelper.Filter, QuestHelper, "LEVEL")
55 local submenu2 = QuestHelper:CreateMenu()
56 QuestHelper:CreateMenuItem(submenu, "Level Filter Offset"):SetSubmenu(submenu2)
57 for offset = -5,5 do
58 local menu = QuestHelper:CreateMenuItem(submenu2, (offset > 0 and "+" or "")..offset)
59 menu:SetFunction(QuestHelper.LevelOffset, QuestHelper, offset)
60 local tex = QuestHelper:CreateIconTexture(item, 10)
61 menu:AddTexture(tex, true)
62 tex:SetVertexColor(1, 1, 1, QuestHelper_Pref.level == offset and 1 or 0)
63 end
64 QuestHelper:CreateMenuItem(menu, "Filters"):SetSubmenu(submenu)
66 -- Locale
67 submenu = QuestHelper:CreateMenu()
68 for loc, tbl in pairs(QuestHelper_Translations) do
69 QuestHelper:CreateMenuItem(submenu, (tbl.LOCALE_NAME or "???").." ["..loc.."]"):SetFunction(QuestHelper.SetLocale, QuestHelper, loc)
70 end
71 QuestHelper:CreateMenuItem(menu, "Locale"):SetSubmenu(submenu)
73 menu:ShowAtCursor()
74 end
75 end
77 -------------------------------------------------------------------------------------
78 -- Display or update the tooltip
79 function QuestHelperWorldMapButton_OnEnter(self)
80 local theme = QuestHelper:GetColourTheme()
82 QuestHelper.tooltip:SetOwner(self, "ANCHOR_BOTTOMLEFT", self:GetWidth(), -5)
83 QuestHelper.tooltip:ClearLines()
84 QuestHelper.tooltip:AddLine(QHFormat("QH_BUTTON_TOOLTIP1", QHText(QuestHelper_Pref.hide and "QH_BUTTON_SHOW" or "QH_BUTTON_HIDE")),
85 unpack(theme.tooltip))
86 QuestHelper.tooltip:GetPrevLines():SetFont(QuestHelper.font.serif, 12)
87 QuestHelper.tooltip:Show()
88 end
90 -------------------------------------------------------------------------------------
91 -- Set up the Map Button
92 function QuestHelper_InitMapButton()
93 -- Create the button
94 local button = CreateFrame("Button", "QuestHelperWorldMapButton", WorldMapFrame, "UIPanelButtonTemplate")
96 -- Set up the button
97 button:SetText(QHText("QH_BUTTON_TEXT"))
98 local width = button:GetTextWidth() + 30
99 if width < 110 then
100 width = 110
102 button:SetWidth(width)
103 button:SetHeight(22)
105 -- Desaturate the button texture if QuestHelper is disabled.
106 -- This line is also in QuestHelper:ToggleHide
107 button:GetNormalTexture():SetDesaturated(QuestHelper_Pref.hide)
109 -- Add event handlers to provide Tooltip
110 button:SetScript("OnEnter", QuestHelperWorldMapButton_OnEnter)
111 button:SetScript("OnLeave", function(this)
112 QuestHelper.tooltip:Hide()
113 end)
115 -- Add Click handler
116 button:SetScript("OnClick", QuestHelperWorldMapButton_OnClick)
117 button:RegisterForClicks("LeftButtonUp", "RightButtonUp")
119 -- Position it on the World Map frame
120 --~ if Cartographer then
121 --~ -- If Cartographer is in use, coordinate with their buttons.
122 -- Trouble is, this makes Cartographer's buttons conflict with the Zone Map dropdown.
123 -- Re-enable this if Cartographer ever learns to work with the Zone Map dropdown.
124 --~ Cartographer:AddMapButton(button, 3)
125 --~ else
126 -- Otherwise, just put it in the upper right corner
127 button:SetPoint("RIGHT", WorldMapPositioningGuide, "RIGHT", -20, 0)
128 button:SetPoint("BOTTOM", WorldMapZoomOutButton, "BOTTOM", 0, 0)
129 -- end
131 -- Save the button so we can reference it later if need be
132 QuestHelper.MapButton = button