Merge branch 'master' into flightpoint-rewrite
[QuestHelper.git] / help.lua
blobebab4ca3c513cfc72bae73b796053d60f453fc18
1 function QuestHelper:SetIconScale(input)
2 if input == "" then
3 self:TextOut("Current icon scale is "..self:HighlightText(math.floor(QuestHelper_Pref.scale*100+0.5).."%")..".")
4 else
5 local scale = tonumber(input)
7 if not scale then
8 local _, _, x = string.find(input, "^%s*([%d%.]+)%s*%%%s*$")
9 scale = tonumber(x)
10 if not scale then
11 self:TextOut("I don't know how to interpret your input.")
12 return
13 end
14 scale = scale * 0.01
15 end
17 if scale < 0.5 then
18 self:TextOut("I won't accept a scale less than 50%.")
19 elseif scale > 3 then
20 self:TextOut("I won't accept a scale more than 300%.")
21 else
22 QuestHelper_Pref.scale = scale
23 self:TextOut("Icon scale set to "..self:HighlightText(math.floor(scale*100+0.5).."%")..".")
24 end
25 end
26 end
28 function QuestHelper:SetLocale(loc)
29 if not loc or loc == "" then
30 self:TextOut(QHText("LOCALE_LIST_BEGIN"))
31 for loc in pairs(QuestHelper_Translations) do
32 self:TextOut(string.format(" %s%s", self:HighlightText(loc), loc == QuestHelper_Pref.locale and " *" or ""))
33 end
34 elseif QuestHelper_Translations[loc] then
35 QuestHelper_Pref.locale = loc
36 QHFormatSetLocale(loc)
37 self:TextOut(QHFormat("LOCALE_CHANGED", loc))
38 else
39 self:TextOut(QHFormat("LOCALE_UNKNOWN", tostring(loc) or "UNKNOWN"))
40 end
41 end
43 function QuestHelper:ToggleHide()
44 local current_objective = self.minimap_dodad.objective
46 QuestHelper_Pref.hide = not QuestHelper_Pref.hide
47 if QuestHelper_Pref.hide then
48 self.map_overlay:Hide()
49 self.minimap_dodad:SetObjective(nil)
50 self.minimap_dodad.objective = current_objective
51 self:TextOut("QuestHelper is now |cffff0000hidden|r.")
52 else
53 self.map_overlay:Show()
54 self.minimap_dodad.objective = nil
55 self.minimap_dodad:SetObjective(current_objective)
56 self:TextOut("QuestHelper is now |cff00ff00shown|r.")
57 end
58 end
60 function QuestHelper:ToggleShare()
61 QuestHelper_Pref.share = not QuestHelper_Pref.share
62 if QuestHelper_Pref.share then
63 if QuestHelper_Pref.solo then
64 self:TextOut("Objective sharing will been |cff00ff00enabled|r when you disable solo mode.")
65 else
66 self:TextOut("Objective sharing has been |cff00ff00enabled|r.")
67 self:EnableSharing()
68 end
69 else
70 self:TextOut("Objective sharing has been |cffff0000disabled|r.")
71 if QuestHelper_Pref.solo then
72 self:TextOut("Objective sharing won't be reenabled when you disable solo mode.")
73 else
74 self:DisableSharing()
75 end
76 end
77 end
79 function QuestHelper:ToggleSolo()
80 QuestHelper_Pref.solo = not QuestHelper_Pref.solo
81 if QuestHelper_Pref.solo then
82 if QuestHelper_Pref.share then
83 self:DisableSharing()
84 self:TextOut("Objective sharing has been temporarly |cffff0000disabled|r.")
85 end
86 self:TextOut("Solo mode has been |cff00ff00enabled|r.")
87 else
88 self:TextOut("Solo mode has been |cffff0000disabled|r.")
89 if QuestHelper_Pref.share then
90 self:EnableSharing()
91 self:TextOut("Objective sharing has been re|cff00ff00enabled|r.")
92 end
93 end
94 end
96 function QuestHelper:ToggleComm()
97 if QuestHelper_Pref.comm then
98 QuestHelper_Pref.comm = false
99 self:TextOut("Communication display has been |cffff0000disabled|r.")
100 else
101 QuestHelper_Pref.comm = true
102 self:TextOut("Communication display has been |cff00ff00enabled|r.")
106 function QuestHelper:ToggleAnts()
107 if QuestHelper_Pref.show_ants then
108 QuestHelper_Pref.show_ants = false
109 self:TextOut("Ant trails have been |cffff0000disabled|r.")
110 else
111 QuestHelper_Pref.show_ants = true
112 self:TextOut("Ant trails have been |cff00ff00enabled|r.")
116 function QuestHelper:LevelOffset(offset)
117 local level = tonumber(offset)
118 if level then
119 if level > 0 then
120 self:TextOut("Allowing quests up to "..self:HighlightText(level).." level"..(level==1 and " " or "s ")..self:HighlightText("above").." you.")
121 elseif level < 0 then
122 self:TextOut("Only allowing quests "..self:HighlightText(-level).." level"..(level==-1 and " " or "s ")..self:HighlightText("below").." you.")
123 else
124 self:TextOut("Only allowing quests "..self:HighlightText("at or below").." your current level.")
127 if not QuestHelper_Pref.filter_level then
128 self:TextOut("Note: This won't have any effect until you turn the level filter on.")
131 if QuestHelper_Pref.level ~= level then
132 QuestHelper_Pref.level = level
133 self.defered_quest_scan = true
135 elseif offset == "" then
136 if QuestHelper_Pref.level <= 0 then
137 self:TextOut("Level offset is currently set to "..self:HighlightText(QuestHelper_Pref.level)..".")
138 else
139 self:TextOut("Level offset is currently set to "..self:HighlightText("+"..QuestHelper_Pref.level)..".")
142 if self.party_levels then for n, l in ipairs(self.party_levels) do
143 self:TextOut("Your effective level in a "..self:HighlightText(n).." player quest is "..self:HighlightText(string.format("%.1f", l))..".")
144 end end
146 if QuestHelper_Pref.solo then
147 self:TextOut("Peers aren't considered in your effective level, because you're playing solo.")
149 else
150 self:TextOut("Expected a level offset.")
154 function QuestHelper:Filter(input)
155 input = string.upper(input)
156 if input == "ZONE" then
157 QuestHelper_Pref.filter_zone = not QuestHelper_Pref.filter_zone
158 self:TextOut("Filter "..self:HighlightText("zone").." set to "..self:HighlightText(QuestHelper_Pref.filter_zone and "active" or "inactive")..".")
159 elseif input == "DONE" then
160 QuestHelper_Pref.filter_done = not QuestHelper_Pref.filter_done
161 self:TextOut("Filter "..self:HighlightText("done").." set to "..self:HighlightText(QuestHelper_Pref.filter_done and "active" or "inactive")..".")
162 elseif input == "LEVEL" then
163 QuestHelper_Pref.filter_level = not QuestHelper_Pref.filter_level
164 self:TextOut("Filter "..self:HighlightText("level").." set to "..self:HighlightText(QuestHelper_Pref.filter_level and "active" or "inactive")..".")
165 elseif input == "" then
166 self:TextOut("Filter "..self:HighlightText("zone")..": "..self:HighlightText(QuestHelper_Pref.filter_zone and "active" or "inactive"))
167 self:TextOut("Filter "..self:HighlightText("level")..": "..self:HighlightText(QuestHelper_Pref.filter_level and "active" or "inactive"))
168 self:TextOut("Filter "..self:HighlightText("done")..": "..self:HighlightText(QuestHelper_Pref.filter_done and "active" or "inactive"))
169 else
170 self:TextOut("Don't know what you want filtered, expect "..self:HighlightText("zone")..", "..self:HighlightText("done")..", or "..self:HighlightText("level")..".")
174 function QuestHelper:ToggleCartWP()
175 QuestHelper_Pref.cart_wp = not QuestHelper_Pref.cart_wp
176 if QuestHelper_Pref.cart_wp then
177 if Cartographer_Waypoints then
178 self:TextOut("Will use "..self:HighlightText("Cartographer Waypoints").." to show objectives.")
179 else
180 self:TextOut("Would use "..self:HighlightText("Cartographer Waypoints").." to show objectives, except it doesn't seem to be present.")
182 else
183 self:HideCartographerWaypoint()
184 self:TextOut("Won't use "..self:HighlightText("Cartographer Waypoints").." to show objectives.")
188 function QuestHelper:WantPathingReset()
189 self:TextOut("Will reset world graph.")
190 self.defered_graph_reset = true
193 function QuestHelper:PrintVersion()
194 self:TextOut("Version: "..self:HighlightText(GetAddOnMetadata("QuestHelper", "Version") or "Unknown"))
197 local function RecycleStatusString(fmt, used, free)
198 return string.format(fmt, QuestHelper:ProgressString(string.format("%d/%d", used, used+free), ((used+free == 0) and 1) or (1-used/(used+free))))
201 function QuestHelper:RecycleInfo()
202 self:TextOut(RecycleStatusString("Using %s lua tables.", self.used_tables, #self.free_tables))
203 self:TextOut(RecycleStatusString("Using %s texture objects.", self.used_textures, #self.free_textures))
204 self:TextOut(RecycleStatusString("Using %s font objects.", self.used_text, #self.free_text))
205 self:TextOut(RecycleStatusString("Using %s frame objects.", self.used_frames, #self.free_frames))
208 local commands =
210 {"VERSION",
211 "Displays QuestHelper's version.", {}, QuestHelper.PrintVersion, QuestHelper},
213 {"RECALC",
214 "Recalculates the world graph and locations for any active objectives.", {}, QuestHelper.WantPathingReset, QuestHelper},
216 {"FILTER",
217 "Automatically ignores/unignores objectives based on criteria.",
218 {{"/qh filter zone", "Toggle showing objectives outside the current zone"},
219 {"/qh filter done", "Toggle showing objectives for uncompleted quests."},
220 {"/qh filter level", "Toggle showing objectives that are probably too hard."}}, QuestHelper.Filter, QuestHelper},
222 {"SCALE",
223 "Scales the map icons used by QuestHelper. Will accept values between 50% and 300%.",
224 {{"/qh scale 1", "Uses the default icon size."},
225 {"/qh scale 2", "Makes icons twice their default size."},
226 {"/qh scale 80%", "Makes icons slightly smaller than their default size."}}, QuestHelper.SetIconScale, QuestHelper},
228 {"NAG",
229 "Tells you if you have anything that's missing from the static database.",
230 {{"/qh nag", "Prints just the summary of changes."},
231 {"/qh nag verbose", "Prints the specific changes that were found."}}, QuestHelper.Nag, QuestHelper},
233 {"LEVEL",
234 "Adjusts the level offset used by the level filter. Naturally, the level filter must be turned on to have an effect.",
235 {{"/qh level", "See information related to the level filter."},
236 {"/qh level 0", "Only allow objectives at below your current level."},
237 {"/qh level +2", "Allow objectives up to two levels above your current level."},
238 {"/qh level -1", "Only allow objectives below your current level."}}, QuestHelper.LevelOffset, QuestHelper},
240 {"POS",
241 "Prints the player's current position. Exists mainly for my own personal convenience.",
242 {}, function (qh) qh:TextOut(qh:LocationString(qh.i, qh.x, qh.y)) end, QuestHelper},
244 {"HIDDEN",
245 "Compiles a list of objectives that QuestHelper is hiding from you. Depending on the reason, you can also unhide the objective.",
246 {}, QuestHelper.ShowHidden, QuestHelper},
248 {"FIND",
249 "Search for an item, location, or npc.",
250 {{"/qh find item rune of teleport", "Finds a reagent vendor."},
251 {"/qh find npc bragok", "Finds the Ratchet flight point."},
252 {"/qh find loc stormwind 50 60", "Finds the Stormwind auction house."}}, QuestHelper.PerformSearch, QuestHelper},
254 {"COMM",
255 "Toggles showing of the communication between QuestHelper users. Exists mainly for my own personal convenience.",
256 {}, QuestHelper.ToggleComm, QuestHelper},
258 {"RECYCLE",
259 "Displays how many unused entities QuestHelper is tracking, so that it can reuse them in the future instead of creating new ones in the future.",
260 {}, QuestHelper.RecycleInfo, QuestHelper},
262 {"CARTWP",
263 "Toggles displaying the current objective using Cartographer Waypoints.",
264 {}, QuestHelper.ToggleCartWP, QuestHelper},
266 {"SHARE",
267 "Toggles objective sharing between QuestHelper users.",
268 {}, QuestHelper.ToggleShare, QuestHelper},
270 {"HIDE",
271 "Hides QuestHelper's modifications to the minimap and world map, and pauses routing calculations.",
272 {}, QuestHelper.ToggleHide, QuestHelper},
274 {"ANTS",
275 "Toggles the world map ant trails on and off.",
276 {}, QuestHelper.ToggleAnts, QuestHelper},
278 {"SOLO",
279 "Toggles solo mode. When enabled, assumes you're playing alone, even when in a party.",
280 {}, QuestHelper.ToggleSolo, QuestHelper},
282 {"LOCALE",
283 "Select the locale to use for displayed messages.",
284 {}, QuestHelper.SetLocale, QuestHelper}
287 function QuestHelper:SlashCommand(input)
288 local _, _, command, argument = string.find(input, "^%s*([^%s]-)%s+(.-)%s*$")
289 if not command then
290 command, argument = input, ""
293 command = string.upper(command)
295 for i, data in ipairs(commands) do
296 if data[1] == command then
297 local st = self:CreateTable()
299 for i = 5,#data do table.insert(st, data[5]) end
300 table.insert(st, argument)
302 if type(data[4]) == "function" then
303 data[4](unpack(st))
304 else
305 self:TextOut(data[1].." is not yet implemented.")
308 self:ReleaseTable(st)
309 return
313 if command == "HELP" then
314 argument = string.upper(argument)
316 for i, data in ipairs(commands) do
317 if data[1] == argument then
318 DEFAULT_CHAT_FRAME:AddMessage(data[1], 1.0, 0.8, 0.4)
319 DEFAULT_CHAT_FRAME:AddMessage(" "..data[2], 1.0, 0.6, 0.2)
320 if #data[3] > 0 then
321 DEFAULT_CHAT_FRAME:AddMessage(#data[3] == 1 and " Example:" or " Examples:", 1.0, 0.6, 0.2)
322 for i, pair in ipairs(data[3]) do
323 DEFAULT_CHAT_FRAME:AddMessage(" "..pair[1], 1.0, 1.0, 1.0)
324 DEFAULT_CHAT_FRAME:AddMessage(" "..pair[2], 1.0, 0.6, 0.2)
327 return
332 DEFAULT_CHAT_FRAME:AddMessage("Available Commands:", 1.0, 0.6, 0.2)
334 for i, data in ipairs(commands) do
335 DEFAULT_CHAT_FRAME:AddMessage(" "..string.lower(data[1]), 1.0, 0.6, 0.2)
339 SLASH_QuestHelper1 = "/qh"
340 SLASH_QuestHelper2 = "/questhelper"
341 SlashCmdList["QuestHelper"] = function (text) QuestHelper:SlashCommand(text) end