1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-22 03:38:48 +02:00
This commit is contained in:
MewMew 2019-11-11 14:55:09 +01:00
parent d9190241ba
commit 8f80d0bd1c
2 changed files with 86 additions and 0 deletions

44
modules/fjei/gui.lua Normal file
View File

@ -0,0 +1,44 @@
local height = 600
local width = 400
local column_count = 8
local line_count = 12
local items_per_page = column_count * line_count
local Public = {}
local function draw_main_window(player)
local item_list = global.fjei.item_list
if player.gui.left["fjei_main_window"] then player.gui.left["fjei_main_window"].destroy() end
local frame = player.gui.left.add({type = "frame", name = "fjei_main_window", caption = "search"})
frame.style.minimal_height = height
frame.style.minimal_width = width
frame.style.padding = 2
local t = frame.add({type = "table", name = "fjei_main_window_table", column_count = column_count})
for i = 1, items_per_page, 1 do
local sprite = t.add({type = "sprite", sprite = item_list[i].sprite, tooltip = item_list[i].name})
sprite.style.maximal_width = 28
sprite.style.maximal_height = 28
sprite.style.margin = 4
end
end
function Public.draw_top_toggle_button(player)
if player.gui.top["fjei_toggle_button"] then return end
local button = player.gui.top.add({type = "sprite-button", name = "fjei_toggle_button", sprite = "virtual-signal/signal-J"})
button.style.minimal_height = 38
button.style.minimal_width = 38
button.style.padding = -2
end
function Public.toggle_main_window(element, player)
if element.name ~= "fjei_toggle_button" then return end
if player.gui.left.fjei_main_window then
player.gui.left.fjei_main_window.destroy()
else
draw_main_window(player)
end
return true
end
return Public

42
modules/fjei/main.lua Normal file
View File

@ -0,0 +1,42 @@
--[[
FJEI - Factorio "Just enough items"
An item recipe browser
]]
local Gui = require "modules.fjei.gui"
local function set_item_list()
global.fjei.item_list = {}
local list = global.fjei.item_list
local i = 1
for name, prototype in pairs(game.recipe_prototypes) do
list[i] = {name = name, sprite = "recipe/" .. name}
i = i + 1
end
table.sort(list, function (a, b) return a.name < b.name end)
end
local function on_player_joined_game(event)
local player = game.players[event.player_index]
set_item_list()
Gui.draw_top_toggle_button(player)
end
local function on_gui_click(event)
local element = event.element
if not element then return end
if not element.valid then return end
local player = game.players[event.player_index]
if Gui.toggle_main_window(element, player) then return end
end
local function on_init()
global.fjei = {}
end
local event = require "utils.event"
event.add(defines.events.on_player_joined_game, on_player_joined_game)
event.add(defines.events.on_gui_click, on_gui_click)
event.on_init(on_init)