Textdoc
Zipdoc
Writeurl
Txtshare
Online Calc
Loading…
--UTIL-- function isnumber(value) return tonumber(value) and true or false end --CHECK-- function tag_check(check_name, check_icon, check_position, return_id) log("TAG: " .. serpent.line(check_name) .. " | " .. serpent.line(check_icon)) if check_icon and check_icon.type == "virtual" and (check_icon.name == "signal-waypoint" or check_icon.name == "signal-orange-dot") then return true end for _, v in pairs(global.tag_catalog) do if v.name == check_name and icon_check(v.icon, check_icon) and v.position.x == check_position.x and v.position.y == check_position.y then if return_id then return _ else return true end end end if return_id then return nil else return false end end --ADD-- function tag_add(unit_name, unit_icon, unit_position) if not tag_check(unit_name, unit_icon, unit_position) then table.insert(global.tag_catalog, {name = unit_name, icon = unit_icon, position = unit_position}) --JOURNAL-- for _, v in pairs(game.players) do local scroll_pane = v.gui.screen.tagbook_window_frame.journal_frame.journal_flow.journal_scroll_pane journal_add(scroll_pane, unit_name, unit_icon, unit_position) --SEARCH-- local search_text = v.gui.screen.tagbook_window_frame.search_frame.search_flow.search_textfield.text local search_icon = v.gui.screen.tagbook_window_frame.search_frame.search_flow.search_elem_button.elem_value scroll_pane_search(scroll_pane, search_text, search_icon, elements_position.flow, elements_position.name, elements_position.icon) --SORT-- local switch = v.gui.screen.tagbook_window_frame.search_frame.search_flow.search_switch_button.sprite if switch == "tagbook-search-switch-text-button" then scroll_pane_sort_by_text(scroll_pane, elements_position.flow, elements_position.name, elements_position.icon) else scroll_pane_sort_by_icon(scroll_pane, elements_position.flow, elements_position.name, elements_position.icon) end --EVENT-- script.raise_event(mod_get_event("catalog_added").id, {name = unit_name, icon = unit_icon, position = unit_position}) return true end else return false end end --EDIT-- function tag_edit(unit_name, unit_icon, unit_position, new_name, new_icon) local id = tag_check(unit_name, unit_icon, unit_position, true) if isnumber(id) then global.tag_catalog[id].name = new_name global.tag_catalog[id].icon = new_icon for _, v in pairs(game.players) do local scroll_pane = v.gui.screen.tagbook_window_frame.journal_frame.journal_flow.journal_scroll_pane journal_edit(scroll_pane, new_name, new_icon, unit_position, unit_name, unit_icon) --SEARCH-- local search_text = v.gui.screen.tagbook_window_frame.search_frame.search_flow.search_textfield.text local search_icon = v.gui.screen.tagbook_window_frame.search_frame.search_flow.search_elem_button.elem_value scroll_pane_search(scroll_pane, current_text, current_icon, elements_position.flow, elements_position.name, elements_position.icon) --SORT-- local switch = v.gui.screen.tagbook_window_frame.search_frame.search_flow.search_switch_button.sprite if switch == "tagbook-search-switch-text-button" then scroll_pane_sort_by_text(scroll_pane, elements_position.flow, elements_position.name, elements_position.icon) else scroll_pane_sort_by_icon(scroll_pane, elements_position.flow, elements_position.name, elements_position.icon) end end script.raise_event(mod_get_event("catalog_edited").id, {name = new_name, icon = new_icon, position = unit_position, old_name = unit_name, old_icon = unit_icon, current_id = id}) return true else return false end end --REMOVE-- function tag_remove(unit_name, unit_icon, unit_position) local id = tag_check(unit_name, unit_icon, unit_position, true) if isnumber(id) then table.remove(global.tag_catalog, id) for _, v in pairs(game.players) do local scroll_pane = v.gui.screen.tagbook_window_frame.journal_frame.journal_flow.journal_scroll_pane journal_remove(scroll_pane, unit_name, unit_icon, unit_position) --SEARCH-- local search_text = v.gui.screen.tagbook_window_frame.search_frame.search_flow.search_textfield.text local search_icon = v.gui.screen.tagbook_window_frame.search_frame.search_flow.search_elem_button.elem_value scroll_pane_search(scroll_pane, current_text, current_icon, elements_position.flow, elements_position.name, elements_position.icon) --SORT-- local switch = v.gui.screen.tagbook_window_frame.search_frame.search_flow.search_switch_button.sprite if switch == "train-schedule-search-switch-text-button" then scroll_pane_sort_by_text(scroll_pane, elements_position.flow, elements_position.name, elements_position.icon) else scroll_pane_sort_by_icon(scroll_pane, elements_position.flow, elements_position.name, elements_position.icon) end end script.raise_event(mod_get_event("catalog_removed").id, {name = unit_name, icon = unit_icon, position = unit_position, current_id = id}) return true else return false end end