avoid a crash
[QuestHelper.git] / routing_hidden.lua
blob2fbd8aea51a3825b2c6e163b7801032d5ec9d022
1 QuestHelper_File["routing_hidden.lua"] = "Development Version"
2 QuestHelper_Loadtime["routing_hidden.lua"] = GetTime()
4 local NodeChainIgnored = {
5 name = "routing_core_internal_node_ignored",
6 no_exception = true,
7 no_disable = true,
8 friendly_reason = QHText("DEPENDS_ON"),
11 function QH_PopulateHidden(menu)
12 local part_of_cluster = {}
14 local ignore_reasons = {}
16 QH_Route_TraverseClusters(
17 function (clust)
18 local igcount = {}
20 for _, v in ipairs(clust) do
21 part_of_cluster[v] = true
23 QH_Route_IgnoredReasons_Node(v, function (reason)
24 igcount[reason] = (igcount[reason] or 0) + 1
25 end)
26 end
28 QH_Route_IgnoredReasons_Cluster(clust, function (reason)
29 igcount[reason] = #clust
30 end)
32 for k, v in pairs(igcount) do
33 if not ignore_reasons[clust[1]] then ignore_reasons[clust[1]] = {} end
34 table.insert(ignore_reasons[clust[1]], {reason = k, partial = (v ~= #clust), items = clust})
35 end
37 if not ignore_reasons[clust[1]] then
38 if QH_Route_Ignored_Cluster(clust) then
39 ignore_reasons[clust[1]] = {{reason = NodeChainIgnored, partial = false, items = clust}} -- hmm what
40 end
41 end
42 end
45 QH_Route_TraverseNodes(
46 function (node)
47 if part_of_cluster[node] then return end
49 QH_Route_IgnoredReasons_Node(node, function(reason)
50 if not ignore_reasons[node] then ignore_reasons[node] = {} end
51 table.insert(ignore_reasons[node], {reason = reason, partial = false, items = {node}})
52 end)
53 end
56 local ignore_sorty = {}
58 for k, v in pairs(ignore_reasons) do
59 table.insert(ignore_sorty, {objective = k, ignores = v})
60 end
62 table.sort(ignore_sorty, function (a, b)
63 if a.objective.type_quest and b.objective.type_quest then
64 --if a.objective.type_quest.level ~= b.objective.type_quest.level then return a.objective.type_quest.level < b.objective.type_quest.level end
65 return a.objective.type_quest.title < b.objective.type_quest.title
66 elseif a.objective.type_quest then return true
67 elseif b.objective.type_quest then return false
68 else
69 -- meh
70 return false
71 end
72 end)
73 -- we'll sort this eventually
75 for _, v in ipairs(ignore_sorty) do
76 local ignored = QuestHelper:CreateMenuItem(menu, v.objective.map_desc[1])
78 local ignored_menu = QuestHelper:CreateMenu()
79 ignored:SetSubmenu(ignored_menu)
82 local no_exception = false
83 for _, ign in ipairs(v.ignores) do
84 if ign.reason.no_exception then
85 no_exception = true
86 end
87 end
89 if not no_exception then
90 local show = QuestHelper:CreateMenuItem(ignored_menu, QHText("HIDDEN_SHOW"))
91 show:SetFunction(function ()
92 for _, ign in ipairs(v.ignores) do
93 for _, v in ipairs(ign.items) do
94 ign.reason:AddException(v)
95 end
96 end
97 QH_Route_Filter_Rescan() -- DO IT ALL
98 end)
99 else
100 local show = QuestHelper:CreateMenuItem(ignored_menu, QHText("HIDDEN_SHOW_NO"))
103 for _, ign in ipairs(v.ignores) do
104 local thisitem = QuestHelper:CreateMenuItem(ignored_menu, ign.reason.friendly_reason)
106 if not ign.reason.no_exception or not ign.reason.no_disable then
107 local deign_menu = QuestHelper:CreateMenu()
108 thisitem:SetSubmenu(deign_menu)
110 if not ign.reason.no_exception then
111 local exception = QuestHelper:CreateMenuItem(deign_menu, QHText("HIDDEN_EXCEPTION"))
112 exception:SetFunction(function ()
113 for _, v in ipairs(ign.items) do
114 ign.reason:AddException(v)
116 QH_Route_Filter_Rescan(ign.reason.name)
117 end)
120 if not ign.reason.no_disable then
121 local disable = QuestHelper:CreateMenuItem(deign_menu, QHFormat("DISABLE_FILTER", ign.reason.friendly_name))
122 disable:SetFunction(function () ign.reason:Disable() QH_Route_Filter_Rescan(ign.reason.name) end)
129 function QH_Hidden_Menu()
130 local menu = QuestHelper:CreateMenu()
131 QuestHelper:CreateMenuTitle(menu, QHText("HIDDEN_TITLE"))
133 QH_PopulateHidden(menu)
135 menu:ShowAtCursor()