mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
Module GUI (#301)
* Update module.lua * Update module.lua * Update module.lua * Update module.lua * Update module.lua * Update module.lua * Update module.lua * Update module.lua * Update module.lua * Update module.lua * Update module.lua * Update module.lua
This commit is contained in:
@@ -1,31 +1,52 @@
|
|||||||
return {
|
return {
|
||||||
-- type of machine to handle together
|
-- type of machine to handle together
|
||||||
default_module_row_count = 6,
|
default_module_row_count = 9,
|
||||||
module_slot_max = 4,
|
module_slot_max = 4,
|
||||||
machine_prod_disallow = {
|
|
||||||
['beacon'] = true
|
|
||||||
},
|
|
||||||
machine_craft = {
|
|
||||||
['assembling-machine-2'] = true,
|
|
||||||
['assembling-machine-3'] = true,
|
|
||||||
['electric-furnace'] = true,
|
|
||||||
['oil-refinery'] = true,
|
|
||||||
['chemical-plant'] = true,
|
|
||||||
['centrifuge'] = true,
|
|
||||||
['rocket-silo'] = true
|
|
||||||
},
|
|
||||||
machine = {
|
machine = {
|
||||||
['electric-mining-drill'] = 'effectivity-module',
|
['electric-mining-drill'] = {
|
||||||
['pumpjack'] = 'effectivity-module',
|
['module'] = 'effectivity-module',
|
||||||
['assembling-machine-2'] = 'productivity-module',
|
['prod'] = true
|
||||||
['assembling-machine-3'] = 'productivity-module-3',
|
},
|
||||||
['electric-furnace'] = 'productivity-module-3',
|
['pumpjack'] = {
|
||||||
['beacon'] = 'speed-module-3',
|
['module'] = 'effectivity-module',
|
||||||
['oil-refinery'] = 'productivity-module-3',
|
['prod'] = true
|
||||||
['chemical-plant'] = 'productivity-module-3',
|
},
|
||||||
['centrifuge'] = 'productivity-module-3',
|
['assembling-machine-2'] = {
|
||||||
['lab'] = 'productivity-module-3',
|
['module'] = 'productivity-module',
|
||||||
['rocket-silo'] = 'productivity-module-3'
|
['prod'] = true
|
||||||
|
},
|
||||||
|
['assembling-machine-3'] = {
|
||||||
|
['module'] = 'productivity-module-3',
|
||||||
|
['prod'] = true
|
||||||
|
},
|
||||||
|
['electric-furnace'] = {
|
||||||
|
['module'] = 'productivity-module-3',
|
||||||
|
['prod'] = true
|
||||||
|
},
|
||||||
|
['beacon'] = {
|
||||||
|
['module'] = 'speed-module-3',
|
||||||
|
['prod'] = false
|
||||||
|
},
|
||||||
|
['oil-refinery'] = {
|
||||||
|
['module'] = 'productivity-module-3',
|
||||||
|
['prod'] = true
|
||||||
|
},
|
||||||
|
['chemical-plant'] = {
|
||||||
|
['module'] = 'productivity-module-3',
|
||||||
|
['prod'] = true
|
||||||
|
},
|
||||||
|
['centrifuge'] = {
|
||||||
|
['module'] = 'productivity-module-3',
|
||||||
|
['prod'] = true
|
||||||
|
},
|
||||||
|
['lab'] = {
|
||||||
|
['module'] = 'productivity-module-3',
|
||||||
|
['prod'] = true
|
||||||
|
},
|
||||||
|
['rocket-silo'] = {
|
||||||
|
['module'] = 'productivity-module-3',
|
||||||
|
['prod'] = true
|
||||||
|
}
|
||||||
},
|
},
|
||||||
module_allowed = {
|
module_allowed = {
|
||||||
['advanced-circuit'] = true,
|
['advanced-circuit'] = true,
|
||||||
|
|||||||
@@ -11,19 +11,34 @@ local SelectionModuleArea = 'ModuleArea'
|
|||||||
--- align an aabb to the grid by expanding it
|
--- align an aabb to the grid by expanding it
|
||||||
local function aabb_align_expand(aabb)
|
local function aabb_align_expand(aabb)
|
||||||
return {
|
return {
|
||||||
left_top = {x = math.floor(aabb.left_top.x), y = math.floor(aabb.left_top.y)},
|
left_top = {
|
||||||
right_bottom = {x = math.ceil(aabb.right_bottom.x), y = math.ceil(aabb.right_bottom.y)}
|
x = math.floor(aabb.left_top.x),
|
||||||
|
y = math.floor(aabb.left_top.y)
|
||||||
|
},
|
||||||
|
right_bottom = {
|
||||||
|
x = math.ceil(aabb.right_bottom.x),
|
||||||
|
y = math.ceil(aabb.right_bottom.y)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
local module_container
|
local module_container
|
||||||
|
|
||||||
local machine_name = {}
|
local machine_name = {}
|
||||||
|
|
||||||
for k, _ in pairs(config.machine) do
|
for k, _ in pairs(config.machine) do
|
||||||
table.insert(machine_name, k)
|
table.insert(machine_name, k)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local prod_module_names = {}
|
||||||
|
|
||||||
|
local function get_module_name()
|
||||||
|
for name, item in pairs(game.item_prototypes) do
|
||||||
|
if item.module_effects and item.module_effects.productivity and item.module_effects.productivity.bonus > 0 then
|
||||||
|
prod_module_names[#prod_module_names + 1] = name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local elem_filter = {
|
local elem_filter = {
|
||||||
name = {{
|
name = {{
|
||||||
filter = 'name',
|
filter = 'name',
|
||||||
@@ -32,31 +47,32 @@ local elem_filter = {
|
|||||||
normal = {{
|
normal = {{
|
||||||
filter = 'type',
|
filter = 'type',
|
||||||
type = 'module'
|
type = 'module'
|
||||||
|
}, {
|
||||||
|
filter = 'name',
|
||||||
|
name = prod_module_names,
|
||||||
|
mode = 'and',
|
||||||
|
invert = true
|
||||||
}},
|
}},
|
||||||
prod = {{
|
prod = {{
|
||||||
filter = 'type',
|
filter = 'type',
|
||||||
type = 'module'
|
type = 'module'
|
||||||
}, {
|
|
||||||
filter = 'name',
|
|
||||||
name = 'productivity',
|
|
||||||
invert = true
|
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
local function clear_module(player, area, machine)
|
local function clear_module(player, area, machine)
|
||||||
for _, entity in pairs(player.surface.find_entities_filtered{area=area, name=machine, force=player.force}) do
|
for _, entity in pairs(player.surface.find_entities_filtered{area=area, name=machine, force=player.force}) do
|
||||||
for _, r in pairs(player.surface.find_entities_filtered{position=entity.position, name='item-request-proxy', force=player.force}) do
|
for _, r in pairs(player.surface.find_entities_filtered{position=entity.position, name='item-request-proxy', force=player.force}) do
|
||||||
if r ~= nil then
|
if r then
|
||||||
r.destroy{raise_destroy=true}
|
r.destroy{raise_destroy=true}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local m_current_module = entity.get_module_inventory()
|
local m_current_module = entity.get_module_inventory()
|
||||||
|
|
||||||
if m_current_module ~= nil then
|
if m_current_module then
|
||||||
local m_current_module_content = m_current_module.get_contents()
|
local m_current_module_content = m_current_module.get_contents()
|
||||||
|
|
||||||
if m_current_module_content ~= nil then
|
if m_current_module_content then
|
||||||
for k, m in pairs(m_current_module_content) do
|
for k, m in pairs(m_current_module_content) do
|
||||||
player.surface.spill_item_stack(entity.bounding_box.left_top, {name=k, count=m}, true, player.force, false)
|
player.surface.spill_item_stack(entity.bounding_box.left_top, {name=k, count=m}, true, player.force, false)
|
||||||
end
|
end
|
||||||
@@ -69,33 +85,24 @@ end
|
|||||||
|
|
||||||
local function apply_module(player, area, machine, modules)
|
local function apply_module(player, area, machine, modules)
|
||||||
for _, entity in pairs(player.surface.find_entities_filtered{area=area, name=machine, force=player.force}) do
|
for _, entity in pairs(player.surface.find_entities_filtered{area=area, name=machine, force=player.force}) do
|
||||||
if config.machine_craft[machine] then
|
local m_current_recipe
|
||||||
local m_current_recipe = entity.get_recipe()
|
|
||||||
|
|
||||||
if m_current_recipe ~= nil then
|
if entity.prototype.crafting_speed then
|
||||||
|
m_current_recipe= entity.get_recipe()
|
||||||
|
end
|
||||||
|
|
||||||
|
if m_current_recipe then
|
||||||
if config.module_allowed[m_current_recipe.name] then
|
if config.module_allowed[m_current_recipe.name] then
|
||||||
entity.surface.create_entity{name='item-request-proxy', target=entity, position=entity.position, force=entity.force, modules=modules}
|
entity.surface.create_entity{name='item-request-proxy', target=entity, position=entity.position, force=entity.force, modules=modules['n']}
|
||||||
entity.last_user = player
|
entity.last_user = player
|
||||||
|
|
||||||
else
|
else
|
||||||
for k in pairs(modules) do
|
entity.surface.create_entity{name='item-request-proxy', target=entity, position=entity.position, force=entity.force, modules=modules['p']}
|
||||||
if k:find('productivity') then
|
|
||||||
modules[k:gsub('productivity', 'effectivity')] = modules[k]
|
|
||||||
modules[k] = nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
entity.surface.create_entity{name='item-request-proxy', target=entity, position=entity.position, force=entity.force, modules=modules}
|
|
||||||
entity.last_user = player
|
entity.last_user = player
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
entity.surface.create_entity{name='item-request-proxy', target=entity, position=entity.position, force=entity.force, modules=modules}
|
entity.surface.create_entity{name='item-request-proxy', target=entity, position=entity.position, force=entity.force, modules=modules['n']}
|
||||||
entity.last_user = player
|
|
||||||
end
|
|
||||||
|
|
||||||
else
|
|
||||||
entity.surface.create_entity{name='item-request-proxy', target=entity, position=entity.position, force=entity.force, modules=modules}
|
|
||||||
entity.last_user = player
|
entity.last_user = player
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -105,34 +112,44 @@ end
|
|||||||
Selection.on_selection(SelectionModuleArea, function(event)
|
Selection.on_selection(SelectionModuleArea, function(event)
|
||||||
local area = aabb_align_expand(event.area)
|
local area = aabb_align_expand(event.area)
|
||||||
local player = game.get_player(event.player_index)
|
local player = game.get_player(event.player_index)
|
||||||
|
|
||||||
if player == nil then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local frame = Gui.get_left_element(player, module_container)
|
local frame = Gui.get_left_element(player, module_container)
|
||||||
|
local scroll_table = frame.container.scroll.table
|
||||||
|
|
||||||
for i=1, config.default_module_row_count do
|
for i=1, config.default_module_row_count do
|
||||||
local m_machine = frame.container.scroll.table['module_mm_' .. i .. '_0'].elem_value
|
local mma = scroll_table['module_mm_' .. i .. '_0'].elem_value
|
||||||
|
|
||||||
if m_machine ~= nil then
|
if mma then
|
||||||
local m_module = {}
|
local mm = {
|
||||||
|
['n'] = {},
|
||||||
|
['p'] = {}
|
||||||
|
}
|
||||||
|
|
||||||
for j=1, config.module_slot_max do
|
for j=1, game.entity_prototypes[mma].module_inventory_size, 1 do
|
||||||
local mmo = frame.container.scroll.table['module_mm_' .. i .. '_' .. j].elem_value
|
local mmo = scroll_table['module_mm_' .. i .. '_' .. j].elem_value
|
||||||
|
|
||||||
|
if mmo then
|
||||||
|
if mm['n'][mmo] then
|
||||||
|
mm['n'][mmo] = mm['n'][mmo] + 1
|
||||||
|
mm['p'][mmo] = mm['p'][mmo] + 1
|
||||||
|
|
||||||
if mmo ~= nil then
|
|
||||||
if m_module[mmo] == nil then
|
|
||||||
m_module[mmo] = 1
|
|
||||||
else
|
else
|
||||||
m_module[mmo] = m_module[mmo] + 1
|
mm['n'][mmo] = 1
|
||||||
|
mm['p'][mmo] = 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if m_module ~= nil then
|
for k, v in pairs(mm['p']) do
|
||||||
clear_module(player, area, m_machine)
|
if k:find('productivity') then
|
||||||
apply_module(player, area, m_machine, m_module)
|
local module_name = k:gsub('productivity', 'effectivity')
|
||||||
|
mm['p'][module_name] = (mm['p'][module_name] or 0) + v
|
||||||
|
mm['p'][k] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if mm then
|
||||||
|
clear_module(player, area, mma)
|
||||||
|
apply_module(player, area, mma, mm)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -140,31 +157,34 @@ end)
|
|||||||
|
|
||||||
local function row_set(player, element)
|
local function row_set(player, element)
|
||||||
local frame = Gui.get_left_element(player, module_container)
|
local frame = Gui.get_left_element(player, module_container)
|
||||||
|
local scroll_table = frame.container.scroll.table
|
||||||
|
|
||||||
if frame.container.scroll.table[element .. '0'].elem_value ~= nil then
|
if scroll_table[element .. '0'].elem_value then
|
||||||
for i=1, config.module_slot_max do
|
for i=1, config.module_slot_max do
|
||||||
if i <= game.entity_prototypes[frame.container.scroll.table[element .. '0'].elem_value].module_inventory_size then
|
if i <= game.entity_prototypes[scroll_table[element .. '0'].elem_value].module_inventory_size then
|
||||||
frame.container.scroll.table[element .. i].enabled = true
|
if config.machine[scroll_table[element .. '0'].elem_value].prod then
|
||||||
frame.container.scroll.table[element .. i].elem_value = config.machine[frame.container.scroll.table[element .. '0'].elem_value]
|
scroll_table[element .. i].elem_filters = elem_filter.prod
|
||||||
|
|
||||||
else
|
else
|
||||||
frame.container.scroll.table[element .. i].enabled = false
|
scroll_table[element .. i].elem_filters = elem_filter.normal
|
||||||
frame.container.scroll.table[element .. i].elem_value = nil
|
|
||||||
end
|
end
|
||||||
frame.container.scroll.table[element .. i].elem_filters = elem_filter.normal
|
|
||||||
|
scroll_table[element .. i].enabled = true
|
||||||
|
scroll_table[element .. i].elem_value = config.machine[scroll_table[element .. '0'].elem_value].module
|
||||||
|
|
||||||
|
else
|
||||||
|
scroll_table[element .. i].enabled = false
|
||||||
|
scroll_table[element .. i].elem_value = nil
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
local mf = elem_filter.normal
|
local mf = elem_filter.normal
|
||||||
|
|
||||||
if config.machine_prod_disallow[element.elem_value] ~= nil then
|
|
||||||
if config.machine_prod_disallow[element.elem_value] then
|
|
||||||
mf = elem_filter.prod
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
for i=1, config.module_slot_max do
|
for i=1, config.module_slot_max do
|
||||||
frame.container.scroll.table[element .. i].enabled = true
|
scroll_table[element .. i].enabled = false
|
||||||
frame.container.scroll.table[element .. i].elem_filters = mf
|
scroll_table[element .. i].elem_filters = mf
|
||||||
frame.container.scroll.table[element .. i].elem_value = nil
|
scroll_table[element .. i].elem_value = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -204,7 +224,8 @@ Gui.element(function(definition, parent)
|
|||||||
type = 'choose-elem-button',
|
type = 'choose-elem-button',
|
||||||
elem_type = 'item',
|
elem_type = 'item',
|
||||||
elem_filters = elem_filter.normal,
|
elem_filters = elem_filter.normal,
|
||||||
style = 'slot_button'
|
style = 'slot_button',
|
||||||
|
enabled = false
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -227,3 +248,6 @@ Event.add(defines.events.on_gui_elem_changed, function(event)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
Event.on_init(get_module_name)
|
||||||
|
Event.on_load(get_module_name)
|
||||||
|
|||||||
Reference in New Issue
Block a user