add reveal tipp button for doc reveal's

This commit is contained in:
Alexander Weber 2017-06-05 16:07:01 +02:00
parent 991f5cf86c
commit 533c86977d
2 changed files with 61 additions and 0 deletions

View File

@ -394,6 +394,25 @@ local function crafting_callback(state)
inf_state:listbox(12, 2, 5.7, 1.3, "item_groups",nil, true)
inf_area:setVisible(false)
-- Reveal tipps button
if smart_inventory.doc_items_mod then
local reveal_button = state:button(7, 4.2, 2, 0.5, "reveal_tipp", "Reveal tipps")
reveal_button:onClick(function(self, state, player)
local all_revealed = ui_tools.filter_by_revealed(ui_tools.root_list_all, player)
local top_revealed = ui_tools.filter_by_top_reveal(all_revealed, player)
state.param.crafting_recipes_preview_selected = 1
state.param.crafting_recipes_preview_listentry = top_revealed[1]
update_crafting_preview(state)
state.param.crafting_grouped_items = ui_tools.get_list_grouped(top_revealed)
-- reset group selection if proposal mode is changed
if state.param.survival_proposal_mode ~= "tipp" then
state.param.survival_proposal_mode = "tipp"
state:get("groups_sel"):setSelected(1)
end
update_group_selection(state, true)
end)
end
-- Lookup
create_lookup_inv(state, player)
state:image(10, 4, 1, 1,"lookup_icon", "default_bookshelf_slot.png")

View File

@ -149,6 +149,48 @@ function ui_tools.filter_by_revealed(list, playername)
return filtered_list
end
-----------------------------------------------------
-- Get all revealed items available
-----------------------------------------------------
function ui_tools.filter_by_top_reveal(list, playername)
-- rate the items
local rating = {}
local top_rating = 0
for _, entry in ipairs(list) do
-- only not revealed could be in tipp
if not doc_addon.is_revealed_item(entry.item, playername) then
-- check item is in recipes
if cache.citems[entry.item] and cache.citems[entry.item].in_craft_recipe then
for _, recipe in ipairs(cache.citems[entry.item].in_craft_recipe) do
if crecipes.crecipes[recipe] then
-- result is not revealed
if not doc_addon.is_revealed_item(crecipes.crecipes[recipe].out_item.name, playername) then
-- count them
if not rating[entry.item] then
rating[entry.item] = 1
else
rating[entry.item] = rating[entry.item] + 1
end
if rating[entry.item] > top_rating then
top_rating = rating[entry.item]
end
end
end
end
end
end
end
-- return top rated
local filtered_list = {}
for _, entry in ipairs(list) do
if rating[entry.item] == top_rating then
table.insert(filtered_list, entry)
end
end
return filtered_list
end
-----------------------------------------------------
-- Select tight groups only to display info about item
-----------------------------------------------------