2018-05-17 16:20:48 +02:00
|
|
|
-- Soft mod version of Blueprint Flipper and Turner https://mods.factorio.com/mods/Marthen/Blueprint_Flip_Turn
|
|
|
|
|
|
|
|
local Event = require 'utils.event'
|
2019-01-25 21:32:11 +02:00
|
|
|
local Global = require 'utils.global'
|
2018-05-20 17:29:05 +02:00
|
|
|
local Gui = require 'utils.gui'
|
2018-09-23 00:25:13 +02:00
|
|
|
local Game = require 'utils.game'
|
2018-05-17 16:20:48 +02:00
|
|
|
|
2019-01-25 21:32:11 +02:00
|
|
|
local player_filters = {}
|
|
|
|
|
|
|
|
Global.register(
|
|
|
|
{
|
|
|
|
player_filters = player_filters
|
|
|
|
},
|
|
|
|
function(tbl)
|
|
|
|
player_filters = tbl.player_filters
|
2019-01-31 01:17:55 +02:00
|
|
|
end
|
2019-01-25 21:32:11 +02:00
|
|
|
)
|
|
|
|
|
2018-05-17 16:20:48 +02:00
|
|
|
local function getBlueprintCursorStack(player)
|
|
|
|
local cursor = player.cursor_stack
|
|
|
|
if
|
|
|
|
cursor.valid_for_read and (cursor.name == 'blueprint' or cursor.name == 'blueprint-book') and
|
|
|
|
cursor.is_blueprint_setup()
|
|
|
|
then --check if is a blueprint, work in book as well
|
|
|
|
return cursor
|
|
|
|
end
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
2018-06-01 23:23:39 +02:00
|
|
|
local function flip_v(cursor)
|
|
|
|
local ents = cursor.get_blueprint_entities()
|
|
|
|
if ents then
|
|
|
|
for i = 1, #ents do
|
|
|
|
local dir = ents[i].direction or 0
|
|
|
|
if ents[i].name == 'curved-rail' then
|
|
|
|
ents[i].direction = (13 - dir) % 8
|
|
|
|
elseif ents[i].name == 'storage-tank' then
|
|
|
|
if ents[i].direction == 2 or ents[i].direction == 6 then
|
|
|
|
ents[i].direction = 4
|
2018-05-17 16:20:48 +02:00
|
|
|
else
|
2018-06-01 23:23:39 +02:00
|
|
|
ents[i].direction = 2
|
2018-05-17 16:20:48 +02:00
|
|
|
end
|
2018-06-01 23:23:39 +02:00
|
|
|
elseif ents[i].name == 'rail-signal' or ents[i].name == 'rail-chain-signal' then
|
|
|
|
if dir == 1 then
|
|
|
|
ents[i].direction = 7
|
|
|
|
elseif dir == 2 then
|
|
|
|
ents[i].direction = 6
|
|
|
|
elseif dir == 3 then
|
|
|
|
ents[i].direction = 5
|
|
|
|
elseif dir == 5 then
|
|
|
|
ents[i].direction = 3
|
|
|
|
elseif dir == 6 then
|
|
|
|
ents[i].direction = 2
|
|
|
|
elseif dir == 7 then
|
|
|
|
ents[i].direction = 1
|
2018-05-17 16:20:48 +02:00
|
|
|
end
|
2018-06-01 23:23:39 +02:00
|
|
|
elseif ents[i].name == 'train-stop' then
|
|
|
|
if dir == 2 then
|
|
|
|
ents[i].direction = 6
|
|
|
|
elseif dir == 6 then
|
|
|
|
ents[i].direction = 2
|
2018-05-17 16:20:48 +02:00
|
|
|
end
|
2018-06-01 23:23:39 +02:00
|
|
|
else
|
2018-05-17 16:20:48 +02:00
|
|
|
ents[i].direction = (12 - dir) % 8
|
|
|
|
end
|
2018-06-01 23:23:39 +02:00
|
|
|
ents[i].position.y = -ents[i].position.y
|
|
|
|
if ents[i].drop_position then
|
|
|
|
ents[i].drop_position.y = -ents[i].drop_position.y
|
|
|
|
end
|
|
|
|
if ents[i].pickup_position then
|
|
|
|
ents[i].pickup_position.y = -ents[i].pickup_position.y
|
|
|
|
end
|
|
|
|
end
|
|
|
|
cursor.set_blueprint_entities(ents)
|
|
|
|
end
|
|
|
|
if cursor.get_blueprint_tiles() ~= nil then
|
2019-01-25 21:32:11 +02:00
|
|
|
ents = cursor.get_blueprint_tiles()
|
2018-06-01 23:23:39 +02:00
|
|
|
for i = 1, #ents do
|
|
|
|
local dir = ents[i].direction or 0
|
|
|
|
ents[i].direction = (12 - dir) % 8
|
|
|
|
ents[i].position.y = -ents[i].position.y
|
2018-05-17 16:20:48 +02:00
|
|
|
end
|
2018-06-01 23:23:39 +02:00
|
|
|
cursor.set_blueprint_tiles(ents)
|
2018-05-17 16:20:48 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-01 23:23:39 +02:00
|
|
|
local function flip_h(cursor)
|
|
|
|
local ents = cursor.get_blueprint_entities()
|
|
|
|
if ents then
|
|
|
|
for i = 1, #ents do
|
|
|
|
local dir = ents[i].direction or 0
|
|
|
|
if ents[i].name == 'curved-rail' then
|
|
|
|
ents[i].direction = (9 - dir) % 8
|
|
|
|
elseif ents[i].name == 'storage-tank' then
|
|
|
|
if ents[i].direction == 2 or ents[i].direction == 6 then
|
|
|
|
ents[i].direction = 4
|
2018-05-17 16:20:48 +02:00
|
|
|
else
|
2018-06-01 23:23:39 +02:00
|
|
|
ents[i].direction = 2
|
2018-05-17 16:20:48 +02:00
|
|
|
end
|
2018-06-01 23:23:39 +02:00
|
|
|
elseif ents[i].name == 'rail-signal' or ents[i].name == 'rail-chain-signal' then
|
|
|
|
if dir == 0 then
|
|
|
|
ents[i].direction = 4
|
|
|
|
elseif dir == 1 then
|
|
|
|
ents[i].direction = 3
|
|
|
|
elseif dir == 3 then
|
|
|
|
ents[i].direction = 1
|
|
|
|
elseif dir == 4 then
|
|
|
|
ents[i].direction = 0
|
|
|
|
elseif dir == 5 then
|
|
|
|
ents[i].direction = 7
|
|
|
|
elseif dir == 7 then
|
|
|
|
ents[i].direction = 5
|
2018-05-17 16:20:48 +02:00
|
|
|
end
|
2018-06-01 23:23:39 +02:00
|
|
|
elseif ents[i].name == 'train-stop' then
|
|
|
|
if dir == 0 then
|
|
|
|
ents[i].direction = 4
|
|
|
|
elseif dir == 4 then
|
|
|
|
ents[i].direction = 0
|
2018-05-17 16:20:48 +02:00
|
|
|
end
|
2018-06-01 23:23:39 +02:00
|
|
|
else
|
2018-05-17 16:20:48 +02:00
|
|
|
ents[i].direction = (16 - dir) % 8
|
|
|
|
end
|
2018-06-01 23:23:39 +02:00
|
|
|
ents[i].position.x = -ents[i].position.x
|
|
|
|
if ents[i].drop_position then
|
|
|
|
ents[i].drop_position.x = -ents[i].drop_position.x
|
|
|
|
end
|
|
|
|
if ents[i].pickup_position then
|
|
|
|
ents[i].pickup_position.x = -ents[i].pickup_position.x
|
|
|
|
end
|
2018-05-17 16:20:48 +02:00
|
|
|
end
|
2018-06-01 23:23:39 +02:00
|
|
|
cursor.set_blueprint_entities(ents)
|
2018-05-17 16:20:48 +02:00
|
|
|
end
|
2018-06-01 23:23:39 +02:00
|
|
|
if cursor.get_blueprint_tiles() ~= nil then
|
2019-01-25 21:32:11 +02:00
|
|
|
ents = cursor.get_blueprint_tiles()
|
2018-06-01 23:23:39 +02:00
|
|
|
for i = 1, #ents do
|
|
|
|
local dir = ents[i].direction or 0
|
|
|
|
ents[i].direction = (16 - dir) % 8
|
|
|
|
ents[i].position.x = -ents[i].position.x
|
|
|
|
end
|
|
|
|
cursor.set_blueprint_tiles(ents)
|
2018-05-20 17:29:05 +02:00
|
|
|
end
|
2018-06-01 23:23:39 +02:00
|
|
|
end
|
2018-05-20 17:29:05 +02:00
|
|
|
|
2018-06-01 23:23:39 +02:00
|
|
|
local function build_filters(data)
|
2018-05-20 17:29:05 +02:00
|
|
|
local filters = {}
|
|
|
|
for _, filter in pairs(data) do
|
2018-05-21 19:22:07 +02:00
|
|
|
local from = filter.from.tooltip
|
|
|
|
local to = filter.to.tooltip
|
|
|
|
|
|
|
|
if from ~= '' and to ~= '' then
|
|
|
|
filters[from] = to
|
2018-05-20 17:29:05 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-01 23:23:39 +02:00
|
|
|
return filters
|
|
|
|
end
|
|
|
|
|
|
|
|
local function convert(cursor, filters)
|
|
|
|
local entities = cursor.get_blueprint_entities()
|
|
|
|
if not entities then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2018-05-20 17:29:05 +02:00
|
|
|
for _, e in ipairs(entities) do
|
|
|
|
local to_name = filters[e.name]
|
|
|
|
if to_name then
|
|
|
|
e.name = to_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
cursor.set_blueprint_entities(entities)
|
|
|
|
end
|
|
|
|
|
2018-05-21 19:22:07 +02:00
|
|
|
local valid_filters = {
|
|
|
|
'wooden-chest',
|
|
|
|
'iron-chest',
|
|
|
|
'steel-chest',
|
|
|
|
'storage-tank',
|
|
|
|
'transport-belt',
|
|
|
|
'fast-transport-belt',
|
|
|
|
'express-transport-belt',
|
|
|
|
'underground-belt',
|
|
|
|
'fast-underground-belt',
|
|
|
|
'express-underground-belt',
|
|
|
|
'splitter',
|
|
|
|
'fast-splitter',
|
|
|
|
'express-splitter',
|
|
|
|
'loader',
|
|
|
|
'fast-loader',
|
|
|
|
'express-loader',
|
|
|
|
'burner-inserter',
|
|
|
|
'inserter',
|
|
|
|
'long-handed-inserter',
|
|
|
|
'fast-inserter',
|
|
|
|
'filter-inserter',
|
|
|
|
'stack-inserter',
|
|
|
|
'stack-filter-inserter',
|
|
|
|
'small-electric-pole',
|
|
|
|
'medium-electric-pole',
|
|
|
|
'big-electric-pole',
|
|
|
|
'substation',
|
|
|
|
'pipe',
|
|
|
|
'pipe-to-ground',
|
|
|
|
'pump',
|
|
|
|
'curved-rail',
|
|
|
|
'straight-rail',
|
|
|
|
'train-stop',
|
|
|
|
'rail-signal',
|
|
|
|
'rail-chain-signal',
|
|
|
|
'logistic-chest-active-provider',
|
|
|
|
'logistic-chest-passive-provider',
|
|
|
|
'logistic-chest-storage',
|
|
|
|
'logistic-chest-buffer',
|
|
|
|
'logistic-chest-requester',
|
|
|
|
'roboport',
|
|
|
|
'small-lamp',
|
|
|
|
'arithmetic-combinator',
|
|
|
|
'decider-combinator',
|
|
|
|
'constant-combinator',
|
|
|
|
'power-switch',
|
|
|
|
'programmable-speaker',
|
|
|
|
'boiler',
|
|
|
|
'steam-engine',
|
|
|
|
'steam-turbine',
|
|
|
|
'solar-panel',
|
|
|
|
'accumulator',
|
|
|
|
'nuclear-reactor',
|
|
|
|
'heat-exchanger',
|
|
|
|
'heat-pipe',
|
|
|
|
'burner-mining-drill',
|
|
|
|
'electric-mining-drill',
|
|
|
|
'offshore-pump',
|
|
|
|
'pumpjack',
|
|
|
|
'stone-furnace',
|
|
|
|
'steel-furnace',
|
|
|
|
'electric-furnace',
|
|
|
|
'assembling-machine-1',
|
|
|
|
'assembling-machine-2',
|
|
|
|
'assembling-machine-3',
|
|
|
|
'oil-refinery',
|
|
|
|
'chemical-plant',
|
|
|
|
'centrifuge',
|
|
|
|
'lab',
|
|
|
|
'beacon',
|
|
|
|
'stone-wall',
|
|
|
|
'gate',
|
|
|
|
'gun-turret',
|
|
|
|
'laser-turret',
|
|
|
|
'flamethrower-turret',
|
|
|
|
'artillery-turret',
|
|
|
|
'radar',
|
|
|
|
'rocket-silo'
|
|
|
|
}
|
|
|
|
|
2018-05-22 00:48:50 +02:00
|
|
|
-- Gui implementation.
|
|
|
|
|
2018-05-20 17:29:05 +02:00
|
|
|
local main_button_name = Gui.uid_name()
|
|
|
|
local main_frame_name = Gui.uid_name()
|
|
|
|
local flip_h_button_name = Gui.uid_name()
|
|
|
|
local flip_v_button_name = Gui.uid_name()
|
|
|
|
local convert_button_name = Gui.uid_name()
|
2018-05-17 16:20:48 +02:00
|
|
|
|
2018-05-21 19:22:07 +02:00
|
|
|
local filter_button_name = Gui.uid_name()
|
|
|
|
local filter_element_name = Gui.uid_name()
|
|
|
|
local filters_table_name = Gui.uid_name()
|
|
|
|
local filter_table_close_button_name = Gui.uid_name()
|
|
|
|
local filter_table_clear_name = Gui.uid_name()
|
2018-05-22 00:48:50 +02:00
|
|
|
local clear_all_filters_name = Gui.uid_name()
|
2018-05-21 19:22:07 +02:00
|
|
|
|
2018-05-17 16:20:48 +02:00
|
|
|
local function player_joined(event)
|
2018-09-23 12:46:58 +02:00
|
|
|
local player = Game.get_player_by_index(event.player_index)
|
2018-05-17 16:20:48 +02:00
|
|
|
if not player or not player.valid then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if player.gui.top[main_button_name] ~= nil then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2018-05-20 17:29:05 +02:00
|
|
|
player.gui.top.add {name = main_button_name, type = 'sprite-button', sprite = 'item/blueprint'}
|
2018-05-17 16:20:48 +02:00
|
|
|
end
|
|
|
|
|
2018-05-21 19:22:07 +02:00
|
|
|
local function draw_filters_table(event)
|
|
|
|
local center = event.player.gui.center
|
2018-05-22 02:02:47 +02:00
|
|
|
|
|
|
|
if center[filters_table_name] then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2018-05-22 00:48:50 +02:00
|
|
|
local frame = center.add {type = 'frame', name = filters_table_name, direction = 'vertical', caption = 'Set Filter'}
|
2018-05-21 19:22:07 +02:00
|
|
|
|
2018-05-22 14:56:03 +02:00
|
|
|
local t = frame.add {type = 'table', column_count = 10}
|
2018-05-21 19:22:07 +02:00
|
|
|
t.style.horizontal_spacing = 0
|
|
|
|
t.style.vertical_spacing = 0
|
|
|
|
|
|
|
|
for _, v in ipairs(valid_filters) do
|
|
|
|
local flow = t.add {type = 'flow'}
|
|
|
|
local b = flow.add {type = 'sprite-button', name = filter_element_name, sprite = 'entity/' .. v, tooltip = v}
|
|
|
|
Gui.set_data(b, frame)
|
|
|
|
b.style = 'slot_button'
|
|
|
|
end
|
|
|
|
|
|
|
|
local flow = frame.add {type = 'flow'}
|
|
|
|
|
2018-05-22 00:48:50 +02:00
|
|
|
local close = flow.add {type = 'button', name = filter_table_close_button_name, caption = 'Close'}
|
2018-05-21 19:22:07 +02:00
|
|
|
Gui.set_data(close, frame)
|
|
|
|
|
2018-05-22 00:48:50 +02:00
|
|
|
local clear = flow.add {type = 'button', name = filter_table_clear_name, caption = 'Clear Filter'}
|
2018-05-21 19:22:07 +02:00
|
|
|
Gui.set_data(clear, frame)
|
|
|
|
|
|
|
|
event.player.opened = frame
|
|
|
|
|
|
|
|
Gui.set_data(frame, event.element)
|
|
|
|
end
|
|
|
|
|
2018-05-20 17:29:05 +02:00
|
|
|
local function toggle(event)
|
2018-05-22 14:56:03 +02:00
|
|
|
local p_filters = player_filters[event.player_index]
|
2018-05-22 12:22:47 +02:00
|
|
|
if not p_filters then
|
|
|
|
p_filters = {}
|
|
|
|
for i = 1, 9 do
|
|
|
|
p_filters[i] = {from = '', to = ''}
|
|
|
|
end
|
2018-05-22 14:56:03 +02:00
|
|
|
player_filters[event.player_index] = p_filters
|
2018-05-22 12:22:47 +02:00
|
|
|
end
|
2018-05-17 16:20:48 +02:00
|
|
|
|
2018-06-07 22:06:48 +02:00
|
|
|
local player = event.player
|
|
|
|
local left = player.gui.left
|
2018-05-17 16:20:48 +02:00
|
|
|
local main_frame = left[main_frame_name]
|
2018-05-22 12:22:47 +02:00
|
|
|
|
2018-05-17 16:20:48 +02:00
|
|
|
if main_frame and main_frame.valid then
|
2018-05-22 12:22:47 +02:00
|
|
|
local filters = Gui.get_data(main_frame)
|
|
|
|
|
|
|
|
for i, f in pairs(filters) do
|
|
|
|
p_filters[i].from = f.from.tooltip
|
|
|
|
p_filters[i].to = f.to.tooltip
|
|
|
|
end
|
|
|
|
|
2018-12-01 23:06:24 +02:00
|
|
|
Gui.remove_data_recursively(main_frame)
|
2018-05-17 16:20:48 +02:00
|
|
|
main_frame.destroy()
|
2018-06-07 22:06:48 +02:00
|
|
|
|
|
|
|
if player.opened_gui_type == defines.gui_type.custom then
|
|
|
|
local opened = player.opened
|
|
|
|
if opened and opened.valid and opened.name == filters_table_name then
|
2018-12-01 23:06:24 +02:00
|
|
|
Gui.remove_data_recursively(opened)
|
2018-06-07 22:06:48 +02:00
|
|
|
opened.destroy()
|
|
|
|
end
|
|
|
|
end
|
2018-05-17 16:20:48 +02:00
|
|
|
else
|
|
|
|
main_frame =
|
|
|
|
left.add {
|
|
|
|
type = 'frame',
|
|
|
|
name = main_frame_name,
|
|
|
|
direction = 'vertical',
|
|
|
|
caption = 'Blueprint Helper'
|
|
|
|
}
|
2018-05-20 17:29:05 +02:00
|
|
|
local scroll_pane =
|
|
|
|
main_frame.add {type = 'scroll-pane', direction = 'vertical', vertical_scroll_policy = 'auto'}
|
|
|
|
scroll_pane.style.maximal_height = 500
|
|
|
|
|
|
|
|
-- Flipper.
|
|
|
|
|
|
|
|
local flipper_frame = scroll_pane.add {type = 'frame', caption = 'Flipper', direction = 'vertical'}
|
|
|
|
|
2018-05-23 13:16:13 +02:00
|
|
|
local label =
|
|
|
|
flipper_frame.add {
|
2018-05-17 16:20:48 +02:00
|
|
|
type = 'label',
|
2018-06-04 01:42:06 +02:00
|
|
|
caption = [[
|
|
|
|
Place blueprint on buttons below to flip blueprint.
|
|
|
|
Obviously this wont work correctly with refineries or chemical plants.]]
|
2018-05-17 16:20:48 +02:00
|
|
|
}
|
2018-05-23 13:16:13 +02:00
|
|
|
label.style.single_line = false
|
2018-05-21 19:22:07 +02:00
|
|
|
|
|
|
|
local flow = flipper_frame.add {type = 'flow'}
|
|
|
|
|
|
|
|
flow.add {
|
2018-05-17 16:20:48 +02:00
|
|
|
type = 'button',
|
|
|
|
name = flip_h_button_name,
|
2018-06-01 23:23:39 +02:00
|
|
|
caption = 'Flip Horizontal ⇄'
|
2018-05-17 16:20:48 +02:00
|
|
|
}
|
2018-05-21 19:22:07 +02:00
|
|
|
flow.add {
|
2018-05-17 16:20:48 +02:00
|
|
|
type = 'button',
|
|
|
|
name = flip_v_button_name,
|
2018-06-01 23:23:39 +02:00
|
|
|
caption = 'Flip Vertical ⇵'
|
2018-05-17 16:20:48 +02:00
|
|
|
}
|
2018-05-20 17:29:05 +02:00
|
|
|
|
|
|
|
-- Converter.
|
|
|
|
|
|
|
|
local filter_frame = scroll_pane.add {type = 'frame', caption = 'Entity Converter', direction = 'vertical'}
|
|
|
|
|
2018-05-22 00:48:50 +02:00
|
|
|
filter_frame.add {
|
|
|
|
type = 'label',
|
|
|
|
-- The empty space is a hacky way to line this frame up with the above frame.
|
|
|
|
caption = 'Set filters then place blueprint on convert button to apply filters. '
|
|
|
|
}
|
2018-05-20 17:29:05 +02:00
|
|
|
|
2018-05-22 12:22:47 +02:00
|
|
|
local filter_table = filter_frame.add {type = 'table', column_count = 12}
|
2018-05-20 17:29:05 +02:00
|
|
|
|
|
|
|
local filters = {}
|
|
|
|
|
2018-05-22 12:22:47 +02:00
|
|
|
for i = 1, 9 do
|
2018-05-20 17:29:05 +02:00
|
|
|
local filler = filter_table.add {type = 'label'}
|
|
|
|
filler.style.minimal_width = 16
|
2018-05-22 12:22:47 +02:00
|
|
|
|
|
|
|
local from_tooltip = p_filters[i].from
|
|
|
|
local to_tooltip = p_filters[i].to
|
|
|
|
|
|
|
|
local from_filter =
|
|
|
|
filter_table.add({type = 'flow'}).add {
|
|
|
|
type = 'sprite-button',
|
|
|
|
name = filter_button_name,
|
|
|
|
tooltip = from_tooltip,
|
|
|
|
sprite = from_tooltip ~= '' and 'entity/' .. from_tooltip or nil
|
|
|
|
}
|
|
|
|
from_filter.style = 'slot_button'
|
|
|
|
|
|
|
|
filter_table.add {type = 'label', caption = '→'}
|
|
|
|
|
|
|
|
local to_filter =
|
|
|
|
filter_table.add({type = 'flow'}).add {
|
|
|
|
type = 'sprite-button',
|
|
|
|
name = filter_button_name,
|
|
|
|
tooltip = to_tooltip,
|
|
|
|
sprite = to_tooltip ~= '' and 'entity/' .. to_tooltip or nil
|
|
|
|
}
|
|
|
|
to_filter.style = 'slot_button'
|
|
|
|
|
|
|
|
table.insert(filters, {from = from_filter, to = to_filter})
|
2018-05-20 17:29:05 +02:00
|
|
|
end
|
|
|
|
|
2018-05-22 00:48:50 +02:00
|
|
|
local converter_buttons_flow = filter_frame.add {type = 'flow'}
|
|
|
|
|
|
|
|
local clear_button =
|
|
|
|
converter_buttons_flow.add {type = 'button', name = clear_all_filters_name, caption = 'Clear Filters'}
|
|
|
|
Gui.set_data(clear_button, filters)
|
|
|
|
|
|
|
|
local filter_button =
|
|
|
|
converter_buttons_flow.add {type = 'button', name = convert_button_name, caption = 'Convert'}
|
2018-05-20 17:29:05 +02:00
|
|
|
Gui.set_data(filter_button, filters)
|
|
|
|
|
2018-05-22 00:48:50 +02:00
|
|
|
main_frame.add {type = 'button', name = main_button_name, caption = 'Close'}
|
2018-05-22 12:22:47 +02:00
|
|
|
Gui.set_data(main_frame, filters)
|
2018-05-17 16:20:48 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-05-20 17:29:05 +02:00
|
|
|
Gui.on_click(main_button_name, toggle)
|
|
|
|
|
|
|
|
Gui.on_click(
|
|
|
|
flip_h_button_name,
|
|
|
|
function(event)
|
2018-06-01 23:23:39 +02:00
|
|
|
local player = event.player
|
|
|
|
|
|
|
|
local cursor = getBlueprintCursorStack(player)
|
|
|
|
if cursor then
|
|
|
|
flip_h(cursor)
|
|
|
|
else
|
|
|
|
player.print('Click the button with a blueprint or blueprint book.')
|
|
|
|
end
|
2018-05-18 02:14:09 +02:00
|
|
|
end
|
2018-05-20 17:29:05 +02:00
|
|
|
)
|
2018-05-18 02:14:09 +02:00
|
|
|
|
2018-05-20 17:29:05 +02:00
|
|
|
Gui.on_click(
|
|
|
|
flip_v_button_name,
|
|
|
|
function(event)
|
2018-06-01 23:23:39 +02:00
|
|
|
local player = event.player
|
|
|
|
|
|
|
|
local cursor = getBlueprintCursorStack(player)
|
|
|
|
if cursor then
|
|
|
|
flip_v(cursor)
|
|
|
|
else
|
|
|
|
player.print('Click the button with a blueprint or blueprint book.')
|
|
|
|
end
|
2018-05-17 16:20:48 +02:00
|
|
|
end
|
2018-05-20 17:29:05 +02:00
|
|
|
)
|
2018-05-17 16:20:48 +02:00
|
|
|
|
2018-05-21 19:22:07 +02:00
|
|
|
Gui.on_click(
|
|
|
|
filter_button_name,
|
|
|
|
function(event)
|
|
|
|
if event.button == defines.mouse_button_type.right then
|
|
|
|
local element = event.element
|
|
|
|
element.sprite = 'utility/pump_cannot_connect_icon'
|
|
|
|
element.tooltip = ''
|
|
|
|
else
|
|
|
|
draw_filters_table(event)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
|
|
|
Gui.on_click(
|
|
|
|
filter_element_name,
|
|
|
|
function(event)
|
|
|
|
local element = event.element
|
|
|
|
local frame = Gui.get_data(element)
|
|
|
|
local filter_button = Gui.get_data(frame)
|
|
|
|
|
2018-06-07 22:06:48 +02:00
|
|
|
if filter_button and filter_button.valid then
|
|
|
|
filter_button.sprite = element.sprite
|
|
|
|
filter_button.tooltip = element.tooltip
|
|
|
|
end
|
2018-05-21 19:22:07 +02:00
|
|
|
|
2018-12-01 23:06:24 +02:00
|
|
|
Gui.remove_data_recursively(frame)
|
2018-05-21 19:22:07 +02:00
|
|
|
frame.destroy()
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
|
|
|
Gui.on_click(
|
|
|
|
filter_table_close_button_name,
|
|
|
|
function(event)
|
|
|
|
local frame = Gui.get_data(event.element)
|
|
|
|
|
2018-12-01 23:06:24 +02:00
|
|
|
Gui.remove_data_recursively(frame)
|
2018-05-21 19:22:07 +02:00
|
|
|
frame.destroy()
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
|
|
|
Gui.on_click(
|
|
|
|
filter_table_clear_name,
|
|
|
|
function(event)
|
|
|
|
local frame = Gui.get_data(event.element)
|
|
|
|
local filter_button = Gui.get_data(frame)
|
|
|
|
|
|
|
|
filter_button.sprite = 'utility/pump_cannot_connect_icon'
|
|
|
|
filter_button.tooltip = ''
|
|
|
|
|
2018-12-01 23:06:24 +02:00
|
|
|
Gui.remove_data_recursively(frame)
|
2018-05-21 19:22:07 +02:00
|
|
|
frame.destroy()
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
2018-05-22 00:48:50 +02:00
|
|
|
Gui.on_click(
|
|
|
|
clear_all_filters_name,
|
|
|
|
function(event)
|
|
|
|
local filters = Gui.get_data(event.element)
|
|
|
|
|
|
|
|
for _, filter in ipairs(filters) do
|
|
|
|
local from = filter.from
|
|
|
|
local to = filter.to
|
|
|
|
|
|
|
|
from.sprite = 'utility/pump_cannot_connect_icon'
|
|
|
|
from.tooltip = ''
|
|
|
|
to.sprite = 'utility/pump_cannot_connect_icon'
|
|
|
|
to.tooltip = ''
|
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
2018-05-20 17:29:05 +02:00
|
|
|
Gui.on_click(
|
|
|
|
convert_button_name,
|
|
|
|
function(event)
|
2018-06-01 23:23:39 +02:00
|
|
|
local player = event.player
|
|
|
|
|
|
|
|
local cursor = getBlueprintCursorStack(player)
|
|
|
|
if not cursor then
|
|
|
|
player.print('Click the button with a blueprint or blueprint book.')
|
2018-06-07 14:55:01 +02:00
|
|
|
return
|
2018-06-01 23:23:39 +02:00
|
|
|
end
|
|
|
|
|
2018-05-20 17:29:05 +02:00
|
|
|
local data = Gui.get_data(event.element)
|
2018-06-01 23:23:39 +02:00
|
|
|
local filters = build_filters(data)
|
|
|
|
|
|
|
|
if next(filters) == nil then
|
|
|
|
player.print('No filters have been set')
|
|
|
|
end
|
|
|
|
|
|
|
|
convert(cursor, filters)
|
2018-05-17 16:20:48 +02:00
|
|
|
end
|
2018-05-20 17:29:05 +02:00
|
|
|
)
|
2018-05-17 16:20:48 +02:00
|
|
|
|
2018-05-21 19:22:07 +02:00
|
|
|
Gui.on_custom_close(
|
|
|
|
filters_table_name,
|
|
|
|
function(event)
|
|
|
|
local element = event.element
|
2018-12-01 23:06:24 +02:00
|
|
|
Gui.remove_data_recursively(element)
|
2018-05-21 19:22:07 +02:00
|
|
|
element.destroy()
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
2018-12-16 03:28:00 +02:00
|
|
|
Gui.allow_player_to_toggle_top_element_visibility(main_button_name)
|
|
|
|
|
2018-05-17 16:20:48 +02:00
|
|
|
Event.add(defines.events.on_player_joined_game, player_joined)
|