2019-11-11 14:55:09 +01:00
|
|
|
--[[
|
|
|
|
FJEI - Factorio "Just enough items"
|
2019-11-11 16:53:00 +01:00
|
|
|
An item recipe browser - MewMew
|
2019-11-11 14:55:09 +01:00
|
|
|
]]
|
|
|
|
|
|
|
|
local Gui = require "modules.fjei.gui"
|
2019-11-11 17:31:30 +01:00
|
|
|
local Functions = require "modules.fjei.functions"
|
2019-11-11 14:55:09 +01:00
|
|
|
|
|
|
|
local function on_player_joined_game(event)
|
|
|
|
local player = game.players[event.player_index]
|
2019-11-11 21:10:40 +01:00
|
|
|
if not global.fjei.player_data[player.index] then global.fjei.player_data[player.index] = {} end
|
2019-11-11 20:13:38 +01:00
|
|
|
Functions.set_crafting_machines(player.force.name)
|
|
|
|
Functions.set_base_item_list(player.force.name)
|
2019-11-11 14:55:09 +01:00
|
|
|
Gui.draw_top_toggle_button(player)
|
|
|
|
end
|
|
|
|
|
2019-11-11 16:53:00 +01:00
|
|
|
local function on_player_left_game(event)
|
|
|
|
local player = game.players[event.player_index]
|
2019-11-11 21:10:40 +01:00
|
|
|
global.fjei.player_data[player.index].history = nil
|
2019-11-11 16:53:00 +01:00
|
|
|
global.fjei.player_data[player.index].filtered_list = nil
|
|
|
|
global.fjei.player_data[player.index] = nil
|
|
|
|
end
|
|
|
|
|
2019-11-11 20:13:38 +01:00
|
|
|
local function on_research_finished(event)
|
|
|
|
local force_name = event.research.force.name
|
|
|
|
Functions.set_crafting_machines(force_name)
|
|
|
|
Functions.set_base_item_list(force_name)
|
|
|
|
for _, player in pairs(game.connected_players) do
|
|
|
|
global.fjei.player_data[player.index].filtered_list = nil
|
|
|
|
Gui.refresh_main_window(player)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-11-11 14:55:09 +01:00
|
|
|
local function on_gui_click(event)
|
|
|
|
local element = event.element
|
|
|
|
if not element then return end
|
|
|
|
if not element.valid then return end
|
2019-11-11 16:53:00 +01:00
|
|
|
local player = game.players[event.player_index]
|
2019-11-11 21:10:40 +01:00
|
|
|
if Gui.gui_click_actions(element, player, event.button) then return end
|
|
|
|
|
|
|
|
if element.parent.name ~= "fjei_main_window_item_list_table" then return end
|
|
|
|
if element.type ~= "sprite" then return end
|
|
|
|
|
|
|
|
Gui.open_recipe(element, player, event.button)
|
2019-11-11 16:53:00 +01:00
|
|
|
end
|
2019-11-11 14:55:09 +01:00
|
|
|
|
2019-11-11 16:53:00 +01:00
|
|
|
local function on_gui_text_changed(event)
|
|
|
|
local element = event.element
|
|
|
|
if not element then return end
|
|
|
|
if not element.valid then return end
|
|
|
|
if element.name ~= "fjei_main_window_search_textfield" then return end
|
|
|
|
local player = game.players[event.player_index]
|
|
|
|
if element.text == "" then
|
|
|
|
global.fjei.player_data[player.index].active_filter = false
|
|
|
|
else
|
|
|
|
global.fjei.player_data[player.index].active_filter = element.text
|
|
|
|
end
|
2019-11-11 17:31:30 +01:00
|
|
|
Functions.set_filtered_list(player)
|
2019-11-11 16:53:00 +01:00
|
|
|
Gui.refresh_main_window(player)
|
2019-11-11 14:55:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local function on_init()
|
|
|
|
global.fjei = {}
|
2019-11-11 16:53:00 +01:00
|
|
|
global.fjei.player_data = {}
|
2019-11-11 14:55:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local event = require "utils.event"
|
|
|
|
event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
2019-11-11 16:53:00 +01:00
|
|
|
event.add(defines.events.on_player_left_game, on_player_left_game)
|
2019-11-11 20:13:38 +01:00
|
|
|
event.add(defines.events.on_research_finished, on_research_finished)
|
2019-11-11 14:55:09 +01:00
|
|
|
event.add(defines.events.on_gui_click, on_gui_click)
|
2019-11-11 16:53:00 +01:00
|
|
|
event.add(defines.events.on_gui_text_changed, on_gui_text_changed)
|
2019-11-11 14:55:09 +01:00
|
|
|
event.on_init(on_init)
|