From ffda3ed64e8942deb5b15fed187d2bbb75c78e8f Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Mon, 25 Sep 2023 22:43:40 +0900 Subject: [PATCH 01/30] create cctv module --- config/_file_loader.lua | 1 + config/expcore/roles.lua | 3 +- modules/gui/surveillance.lua | 171 +++++++++++++++++++++++++++++++++++ 3 files changed, 174 insertions(+), 1 deletion(-) create mode 100644 modules/gui/surveillance.lua diff --git a/config/_file_loader.lua b/config/_file_loader.lua index 32ce6fac..4969b6cc 100644 --- a/config/_file_loader.lua +++ b/config/_file_loader.lua @@ -91,6 +91,7 @@ return { 'modules.gui.server-ups', 'modules.gui.vlayer', 'modules.gui.research', + 'modules.gui.surveillance', 'modules.graftorio.require', -- graftorio diff --git a/config/expcore/roles.lua b/config/expcore/roles.lua index 2c320fc5..098ae815 100644 --- a/config/expcore/roles.lua +++ b/config/expcore/roles.lua @@ -231,7 +231,8 @@ Roles.new_role('Member','Mem') 'command/personal-logistic', 'command/auto-research', 'command/manual-train', - 'command/lawnmower' + 'command/lawnmower', + 'gui/surveillance' } local hours3, hours15 = 3*216000, 15*60 diff --git a/modules/gui/surveillance.lua b/modules/gui/surveillance.lua new file mode 100644 index 00000000..68836065 --- /dev/null +++ b/modules/gui/surveillance.lua @@ -0,0 +1,171 @@ +---- module cctv +-- @addon cctv + +local Gui = require 'expcore.gui' --- @dep expcore.gui +local Roles = require 'expcore.roles' --- @dep expcore.roles +local Event = require 'utils.event' --- @dep utils.event + +local cctv_container + +cctv_container = +Gui.element(function(event_trigger, parent) + local container = Gui.container(parent, event_trigger, 480) + + local player_list = {} + + for _, player in pairs(game.connected_players) do + table.insert(player_list, player.name) + end + + for i=1, 2 do + local scroll_table_1 = Gui.scroll_table(container, 400, 6, 'cctv_st_' .. i .. '1') + + scroll_table_1.add{ + type = 'drop-down', + name = 'cctv_display_' .. i .. 'p', + items = player_list, + selected_index = 1 + } + + scroll_table_1.add{ + type = 'drop-down', + name = 'cctv_display_' .. i .. 's', + items = {'Player', 'Static'}, + selected_index = 1 + } + + scroll_table_1.add{ + type = 'drop-down', + name = 'cctv_display_' .. i .. 'e', + items = {'Enable', 'Disable'}, + selected_index = 1 + } + + + local button_ds = + Gui.element{ + name = 'cctv_display_' .. i .. 'sl', + type = 'button', + caption = 'Set', + style = 'button' + }:on_click(function(player) + local frame = Gui.get_left_element(player, cctv_container) + frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].position = player.position + end):style{ + maximal_width = 36 + } + + local button_za = + Gui.element{ + name = 'cctv_display_' .. i .. 'mza', + type = 'button', + caption = '+', + style = 'button' + }:on_click(function(player) + local frame = Gui.get_left_element(player, cctv_container) + if frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].zoom < 2.0 then + frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].zoom = frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].zoom + 0.05 + end + end):style{ + maximal_width = 36 + } + + local button_zb = + Gui.element{ + name = 'cctv_display_' .. i .. 'mzb', + type = 'button', + caption = '-', + style = 'button' + }:on_click(function(player) + local frame = Gui.get_left_element(player, cctv_container) + if frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].zoom > 0.2 then + frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].zoom = frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].zoom - 0.05 + end + end):style{ + maximal_width = 36 + } + + button_ds(scroll_table_1) + button_za(scroll_table_1) + button_zb(scroll_table_1) + + local scroll_table_2 = Gui.scroll_table(container, 400, 1, 'cctv_st_' .. i .. '2') + container['cctv_st_' .. i .. '2'].vertical_scroll_policy = 'never' + + local frame = scroll_table_2.add{ + type = 'frame', + name = 'cctv_display_' .. i .. 'f', + direction = 'vertical' + } + + local camera = frame.add{ + type = 'camera', + name = 'cctv_display_' .. i .. 'm', + position = {x=0, y=0}, + surface_index = game.surfaces['nauvis'].index, + zoom = 0.75, + } + + camera.style.minimal_width = 400 + camera.style.minimal_height = 300 + end + + return container.parent +end) +:add_to_left_flow() + +Gui.left_toolbar_button('entity/radar', 'Surveillance GUI', cctv_container, function(player) + return Roles.player_allowed(player, 'gui/surveillance') +end) + +local function gui_update() + local player_list = {} + + for _, player in pairs(game.connected_players) do + table.insert(player_list, player.name) + end + + for _, player in pairs(game.connected_players) do + local frame = Gui.get_left_element(player, cctv_container) + for i=1, 2 do + frame.container['cctv_st_' .. i .. '1'].table['cctv_display_' .. i .. 'p'].items = player_list + end + end +end + +Event.add(defines.events.on_player_joined_game, function(_) + gui_update() +end) + +Event.add(defines.events.on_player_left_game, function(_) + gui_update() +end) + +Event.on_nth_tick(1, function() + for _, player in pairs(game.connected_players) do + local frame = Gui.get_left_element(player, cctv_container) + + for i=1, 2 do + local switch_index = frame.container['cctv_st_' .. i .. '1'].table['cctv_display_' .. i .. 's'].selected_index + + if switch_index == 1 then + local selected_index = frame.container['cctv_st_' .. i .. '1'].table['cctv_display_' .. i .. 'p'].selected_index + + if selected_index ~= nil or selected_index ~= 0 then + frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].position = game.players[selected_index].position + frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].surface_index = game.players[selected_index].surface_index + + else + frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].position = {x=0, y=0} + frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].surface_index = game.surfaces['nauvis'].index + end + + if frame.container['cctv_st_' .. i .. '1'].table['cctv_display_' .. i .. 'e'].selected_index == 1 then + frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].visible = true + else + frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].visible = false + end + end + end + end +end) From 19a620359fd0623a250369b0f5d6963356c659c0 Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Tue, 26 Sep 2023 22:47:29 +0900 Subject: [PATCH 02/30] update --- modules/gui/surveillance.lua | 78 ++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 44 deletions(-) diff --git a/modules/gui/surveillance.lua b/modules/gui/surveillance.lua index 68836065..8743b475 100644 --- a/modules/gui/surveillance.lua +++ b/modules/gui/surveillance.lua @@ -5,9 +5,7 @@ local Gui = require 'expcore.gui' --- @dep expcore.gui local Roles = require 'expcore.roles' --- @dep expcore.roles local Event = require 'utils.event' --- @dep utils.event -local cctv_container - -cctv_container = +local cctv_container = Gui.element(function(event_trigger, parent) local container = Gui.container(parent, event_trigger, 480) @@ -41,53 +39,30 @@ Gui.element(function(event_trigger, parent) selected_index = 1 } - - local button_ds = - Gui.element{ - name = 'cctv_display_' .. i .. 'sl', + local l = scroll_table_1.add{ type = 'button', - caption = 'Set', + name = 'cctv_display_' .. i .. 'l', + caption = 'set', style = 'button' - }:on_click(function(player) - local frame = Gui.get_left_element(player, cctv_container) - frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].position = player.position - end):style{ - maximal_width = 36 } - local button_za = - Gui.element{ - name = 'cctv_display_' .. i .. 'mza', + local a = scroll_table_1.add{ type = 'button', + name = 'cctv_display_' .. i .. 'a', caption = '+', style = 'button' - }:on_click(function(player) - local frame = Gui.get_left_element(player, cctv_container) - if frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].zoom < 2.0 then - frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].zoom = frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].zoom + 0.05 - end - end):style{ - maximal_width = 36 } - local button_zb = - Gui.element{ - name = 'cctv_display_' .. i .. 'mzb', + local b = scroll_table_1.add{ type = 'button', + name = 'cctv_display_' .. i .. 'b', caption = '-', style = 'button' - }:on_click(function(player) - local frame = Gui.get_left_element(player, cctv_container) - if frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].zoom > 0.2 then - frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].zoom = frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].zoom - 0.05 - end - end):style{ - maximal_width = 36 } - button_ds(scroll_table_1) - button_za(scroll_table_1) - button_zb(scroll_table_1) + l.style.maximal_width = 48 + a.style.maximal_width = 36 + b.style.maximal_width = 36 local scroll_table_2 = Gui.scroll_table(container, 400, 1, 'cctv_st_' .. i .. '2') container['cctv_st_' .. i .. '2'].vertical_scroll_policy = 'never' @@ -133,21 +108,36 @@ local function gui_update() end end -Event.add(defines.events.on_player_joined_game, function(_) - gui_update() +Event.add(defines.events.on_player_joined_game, gui_update) +Event.add(defines.events.on_player_left_game, gui_update) + +Event.add(defines.events.on_gui_click, function(event) + if event.element.name:sub(1, 13) == 'cctv_display_' then + local frame = Gui.get_left_element(game.players[event.player_index], cctv_container) + local i = event.element.name:sub(-2):sub(1, 1) + + if event.element.name:sub(-1) == 'l' then + frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].position = game.players[event.player_index].position + + elseif event.element.name:sub(-1) == 'a' then + if frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].zoom < 2.0 then + frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].zoom = frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].zoom + 0.05 + end + + elseif event.element.name:sub(-1) == 'b' then + if frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].zoom > 0.2 then + frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].zoom = frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].zoom - 0.05 + end + end + end end) -Event.add(defines.events.on_player_left_game, function(_) - gui_update() -end) - -Event.on_nth_tick(1, function() +Event.add(defines.events.on_tick, function(_) for _, player in pairs(game.connected_players) do local frame = Gui.get_left_element(player, cctv_container) for i=1, 2 do local switch_index = frame.container['cctv_st_' .. i .. '1'].table['cctv_display_' .. i .. 's'].selected_index - if switch_index == 1 then local selected_index = frame.container['cctv_st_' .. i .. '1'].table['cctv_display_' .. i .. 'p'].selected_index From 67fe9ef5334743caee884d1ab3e291059217cd0b Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Thu, 28 Sep 2023 00:38:13 +0900 Subject: [PATCH 03/30] width --- modules/gui/surveillance.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/gui/surveillance.lua b/modules/gui/surveillance.lua index 8743b475..3f1c25cf 100644 --- a/modules/gui/surveillance.lua +++ b/modules/gui/surveillance.lua @@ -25,14 +25,14 @@ Gui.element(function(event_trigger, parent) selected_index = 1 } - scroll_table_1.add{ + local s = scroll_table_1.add{ type = 'drop-down', name = 'cctv_display_' .. i .. 's', items = {'Player', 'Static'}, selected_index = 1 } - scroll_table_1.add{ + local e = scroll_table_1.add{ type = 'drop-down', name = 'cctv_display_' .. i .. 'e', items = {'Enable', 'Disable'}, @@ -60,9 +60,11 @@ Gui.element(function(event_trigger, parent) style = 'button' } - l.style.maximal_width = 48 - a.style.maximal_width = 36 - b.style.maximal_width = 36 + s.style.width = 96 + e.style.width = 96 + l.style.width = 48 + a.style.width = 36 + b.style.width = 36 local scroll_table_2 = Gui.scroll_table(container, 400, 1, 'cctv_st_' .. i .. '2') container['cctv_st_' .. i .. '2'].vertical_scroll_policy = 'never' From 722e17d5dfb37554d5c9aa69482c51c42c36441c Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Tue, 3 Oct 2023 01:28:47 +0900 Subject: [PATCH 04/30] update --- modules/gui/surveillance.lua | 234 ++++++++++++++++++----------------- 1 file changed, 121 insertions(+), 113 deletions(-) diff --git a/modules/gui/surveillance.lua b/modules/gui/surveillance.lua index 3f1c25cf..3e36fe65 100644 --- a/modules/gui/surveillance.lua +++ b/modules/gui/surveillance.lua @@ -1,91 +1,125 @@ ----- module cctv --- @addon cctv +---- module surveillance +-- @addon surveillance local Gui = require 'expcore.gui' --- @dep expcore.gui local Roles = require 'expcore.roles' --- @dep expcore.roles local Event = require 'utils.event' --- @dep utils.event -local cctv_container = +local cctv_container +local player_list = {} + +local cctv_player = +Gui.Element{ + type = 'drop-down', + name = 'cctv_player', + items = player_list, + selected_index = 1 +} + +local cctv_type = +Gui.Element{ + type = 'drop-down', + name = 'cctv_status', + items = {'Enable', 'Disable'}, + selected_index = 1 +}:style{ + width = 96 +}:on_click(function(_, element, _) + if element.selected_index == 1 then + element.parent.parent.cctv_display.visible = true + else + element.parent.parent.cctv_display.visible = false + end +end) + +local cctv_status = +Gui.Element{ + type = 'drop-down', + name = 'cctv_status', + items = {'Player', 'Static'}, + selected_index = 1 +}:style{ + width = 96 +}:on_click(function(_, element, _) + if element.selected_index == 1 then + element.parent.parent.cctv_display.visible = true + else + element.parent.parent.cctv_display.visible = false + end +end) + +local cctv_location = +Gui.Element{ + type = 'button', + caption = 'set' +}:style{ + width = 48 +}:on_click(function(player, element, _) + element.parent.parent.cctv_display.position = player.position +end) + +local zoom_in = +Gui.Element{ + type = 'button', + caption = '+' +}:style{ + width = 36 +}:on_click(function(_, element, _) + if element.parent.parent.cctv_display.zoom < 2.0 then + element.parent.parent.cctv_display.zoom = element.parent.parent.cctv_display.zoom + 0.05 + end +end) + +local zoom_out = +Gui.Element{ + type = 'button', + caption = '-' +}:style{ + width = 36 +}:on_click(function(_, element, _) + if element.parent.parent.cctv_display.zoom > 0.2 then + element.parent.parent.cctv_display.zoom = element.parent.parent.cctv_display.zoom - 0.05 + end +end) + +local camera_set = +Gui.Element(function(_, parent) + local camera_set = parent.add{type='flow'} + local buttons = Gui.scroll_table(camera_set, 400, 6, 'buttons') + + cctv_player(buttons) + cctv_type(buttons) + cctv_status(buttons) + cctv_location(buttons) + zoom_out(buttons) + zoom_in(buttons) + + local camera = camera_set.add{ + type = 'camera', + name = 'cctv_display', + position = {x=0, y=0}, + surface_index = game.surfaces['nauvis'].index, + zoom = 0.75, + } + + camera.style.minimal_width = 400 + camera.style.minimal_height = 300 + return camera_set +end) + +cctv_container = Gui.element(function(event_trigger, parent) local container = Gui.container(parent, event_trigger, 480) - - local player_list = {} + local scroll_table_1 = Gui.scroll_table(container, 400, 6, 'cctv_st_1') + local scroll_table_2 = Gui.scroll_table(container, 400, 6, 'cctv_st_2') + player_list = {} for _, player in pairs(game.connected_players) do table.insert(player_list, player.name) end - for i=1, 2 do - local scroll_table_1 = Gui.scroll_table(container, 400, 6, 'cctv_st_' .. i .. '1') - - scroll_table_1.add{ - type = 'drop-down', - name = 'cctv_display_' .. i .. 'p', - items = player_list, - selected_index = 1 - } - - local s = scroll_table_1.add{ - type = 'drop-down', - name = 'cctv_display_' .. i .. 's', - items = {'Player', 'Static'}, - selected_index = 1 - } - - local e = scroll_table_1.add{ - type = 'drop-down', - name = 'cctv_display_' .. i .. 'e', - items = {'Enable', 'Disable'}, - selected_index = 1 - } - - local l = scroll_table_1.add{ - type = 'button', - name = 'cctv_display_' .. i .. 'l', - caption = 'set', - style = 'button' - } - - local a = scroll_table_1.add{ - type = 'button', - name = 'cctv_display_' .. i .. 'a', - caption = '+', - style = 'button' - } - - local b = scroll_table_1.add{ - type = 'button', - name = 'cctv_display_' .. i .. 'b', - caption = '-', - style = 'button' - } - - s.style.width = 96 - e.style.width = 96 - l.style.width = 48 - a.style.width = 36 - b.style.width = 36 - - local scroll_table_2 = Gui.scroll_table(container, 400, 1, 'cctv_st_' .. i .. '2') - container['cctv_st_' .. i .. '2'].vertical_scroll_policy = 'never' - - local frame = scroll_table_2.add{ - type = 'frame', - name = 'cctv_display_' .. i .. 'f', - direction = 'vertical' - } - - local camera = frame.add{ - type = 'camera', - name = 'cctv_display_' .. i .. 'm', - position = {x=0, y=0}, - surface_index = game.surfaces['nauvis'].index, - zoom = 0.75, - } - - camera.style.minimal_width = 400 - camera.style.minimal_height = 300 - end + camera_set(scroll_table_1) + camera_set(scroll_table_2) return container.parent end) @@ -96,7 +130,7 @@ Gui.left_toolbar_button('entity/radar', 'Surveillance GUI', cctv_container, func end) local function gui_update() - local player_list = {} + player_list = {} for _, player in pairs(game.connected_players) do table.insert(player_list, player.name) @@ -104,58 +138,32 @@ local function gui_update() for _, player in pairs(game.connected_players) do local frame = Gui.get_left_element(player, cctv_container) - for i=1, 2 do - frame.container['cctv_st_' .. i .. '1'].table['cctv_display_' .. i .. 'p'].items = player_list - end + frame.container['cctv_st_1'].table.flow['buttons']['cctv_player'].items = player_list + frame.container['cctv_st_2'].table.flow['buttons']['cctv_player'].items = player_list end end Event.add(defines.events.on_player_joined_game, gui_update) Event.add(defines.events.on_player_left_game, gui_update) -Event.add(defines.events.on_gui_click, function(event) - if event.element.name:sub(1, 13) == 'cctv_display_' then - local frame = Gui.get_left_element(game.players[event.player_index], cctv_container) - local i = event.element.name:sub(-2):sub(1, 1) - - if event.element.name:sub(-1) == 'l' then - frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].position = game.players[event.player_index].position - - elseif event.element.name:sub(-1) == 'a' then - if frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].zoom < 2.0 then - frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].zoom = frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].zoom + 0.05 - end - - elseif event.element.name:sub(-1) == 'b' then - if frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].zoom > 0.2 then - frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].zoom = frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].zoom - 0.05 - end - end - end -end) - Event.add(defines.events.on_tick, function(_) for _, player in pairs(game.connected_players) do local frame = Gui.get_left_element(player, cctv_container) for i=1, 2 do - local switch_index = frame.container['cctv_st_' .. i .. '1'].table['cctv_display_' .. i .. 's'].selected_index + local scroll_table_name = 'cctv_st_' .. i + local switch_index = frame.container[scroll_table_name].table.flow['cctv_status'].selected_index + if switch_index == 1 then - local selected_index = frame.container['cctv_st_' .. i .. '1'].table['cctv_display_' .. i .. 'p'].selected_index + local selected_index = frame.container[scroll_table_name].table.flow['cctv_player'].selected_index if selected_index ~= nil or selected_index ~= 0 then - frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].position = game.players[selected_index].position - frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].surface_index = game.players[selected_index].surface_index + frame.container[scroll_table_name].table.flow['cctv_display'].position = game.players[selected_index].position + frame.container[scroll_table_name].table.flow['cctv_display'].surface_index = game.players[selected_index].surface_index else - frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].position = {x=0, y=0} - frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].surface_index = game.surfaces['nauvis'].index - end - - if frame.container['cctv_st_' .. i .. '1'].table['cctv_display_' .. i .. 'e'].selected_index == 1 then - frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].visible = true - else - frame.container['cctv_st_' .. i .. '2'].table['cctv_display_' .. i .. 'f']['cctv_display_' .. i .. 'm'].visible = false + frame.container[scroll_table_name].table.flow['cctv_display'].position = {x=0, y=0} + frame.container[scroll_table_name].table.flow['cctv_display'].surface_index = game.surfaces['nauvis'].index end end end From 99c3a40ce5943ba68075b0068048c7d8eeaf659a Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Tue, 3 Oct 2023 02:50:24 +0900 Subject: [PATCH 05/30] . --- modules/gui/surveillance.lua | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/gui/surveillance.lua b/modules/gui/surveillance.lua index 3e36fe65..2cd3777f 100644 --- a/modules/gui/surveillance.lua +++ b/modules/gui/surveillance.lua @@ -9,7 +9,7 @@ local cctv_container local player_list = {} local cctv_player = -Gui.Element{ +Gui.element{ type = 'drop-down', name = 'cctv_player', items = player_list, @@ -17,7 +17,7 @@ Gui.Element{ } local cctv_type = -Gui.Element{ +Gui.element{ type = 'drop-down', name = 'cctv_status', items = {'Enable', 'Disable'}, @@ -33,7 +33,7 @@ Gui.Element{ end) local cctv_status = -Gui.Element{ +Gui.element{ type = 'drop-down', name = 'cctv_status', items = {'Player', 'Static'}, @@ -49,7 +49,7 @@ Gui.Element{ end) local cctv_location = -Gui.Element{ +Gui.element{ type = 'button', caption = 'set' }:style{ @@ -59,7 +59,7 @@ Gui.Element{ end) local zoom_in = -Gui.Element{ +Gui.element{ type = 'button', caption = '+' }:style{ @@ -71,7 +71,7 @@ Gui.Element{ end) local zoom_out = -Gui.Element{ +Gui.element{ type = 'button', caption = '-' }:style{ @@ -83,7 +83,7 @@ Gui.Element{ end) local camera_set = -Gui.Element(function(_, parent) +Gui.element(function(_, parent) local camera_set = parent.add{type='flow'} local buttons = Gui.scroll_table(camera_set, 400, 6, 'buttons') @@ -138,8 +138,8 @@ local function gui_update() for _, player in pairs(game.connected_players) do local frame = Gui.get_left_element(player, cctv_container) - frame.container['cctv_st_1'].table.flow['buttons']['cctv_player'].items = player_list - frame.container['cctv_st_2'].table.flow['buttons']['cctv_player'].items = player_list + frame.container['cctv_st_1'].table.flow['buttons'][cctv_player.name].items = player_list + frame.container['cctv_st_2'].table.flow['buttons'][cctv_player.name].items = player_list end end @@ -152,10 +152,10 @@ Event.add(defines.events.on_tick, function(_) for i=1, 2 do local scroll_table_name = 'cctv_st_' .. i - local switch_index = frame.container[scroll_table_name].table.flow['cctv_status'].selected_index + local switch_index = frame.container[scroll_table_name].table.flow[cctv_status.name].selected_index if switch_index == 1 then - local selected_index = frame.container[scroll_table_name].table.flow['cctv_player'].selected_index + local selected_index = frame.container[scroll_table_name].table.flow[cctv_player.name].selected_index if selected_index ~= nil or selected_index ~= 0 then frame.container[scroll_table_name].table.flow['cctv_display'].position = game.players[selected_index].position From f08cc91bdd3ea078aa0f013727d204b85a98d27d Mon Sep 17 00:00:00 2001 From: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com> Date: Mon, 2 Oct 2023 18:54:12 +0100 Subject: [PATCH 06/30] Changed enough to prevent join errors --- modules/gui/surveillance.lua | 66 +++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/modules/gui/surveillance.lua b/modules/gui/surveillance.lua index 2cd3777f..b4087fa4 100644 --- a/modules/gui/surveillance.lua +++ b/modules/gui/surveillance.lua @@ -6,15 +6,16 @@ local Roles = require 'expcore.roles' --- @dep expcore.roles local Event = require 'utils.event' --- @dep utils.event local cctv_container -local player_list = {} local cctv_player = -Gui.element{ - type = 'drop-down', - name = 'cctv_player', - items = player_list, - selected_index = 1 -} +Gui.element(function(name, parent, player_list) + return parent.add{ + name = name, + type = 'drop-down', + items = player_list, + selected_index = #player_list > 0 and 1 + } +end) local cctv_type = Gui.element{ @@ -26,9 +27,9 @@ Gui.element{ width = 96 }:on_click(function(_, element, _) if element.selected_index == 1 then - element.parent.parent.cctv_display.visible = true + element.parent.parent.parent.cctv_display.visible = true else - element.parent.parent.cctv_display.visible = false + element.parent.parent.parent.cctv_display.visible = false end end) @@ -42,9 +43,9 @@ Gui.element{ width = 96 }:on_click(function(_, element, _) if element.selected_index == 1 then - element.parent.parent.cctv_display.visible = true + element.parent.parent.parent.cctv_display.visible = true else - element.parent.parent.cctv_display.visible = false + element.parent.parent.parent.cctv_display.visible = false end end) @@ -65,8 +66,9 @@ Gui.element{ }:style{ width = 36 }:on_click(function(_, element, _) - if element.parent.parent.cctv_display.zoom < 2.0 then - element.parent.parent.cctv_display.zoom = element.parent.parent.cctv_display.zoom + 0.05 + local display = element.parent.parent.parent.cctv_display + if display.zoom < 2.0 then + display.zoom = display.zoom + 0.05 end end) @@ -77,17 +79,18 @@ Gui.element{ }:style{ width = 36 }:on_click(function(_, element, _) - if element.parent.parent.cctv_display.zoom > 0.2 then - element.parent.parent.cctv_display.zoom = element.parent.parent.cctv_display.zoom - 0.05 + local display = element.parent.parent.parent.cctv_display + if display.zoom > 0.2 then + display.zoom = display.zoom - 0.05 end end) local camera_set = -Gui.element(function(_, parent) - local camera_set = parent.add{type='flow'} +Gui.element(function(_, parent, name, player_list) + local camera_set = parent.add{type='flow', direction="vertical", name=name} local buttons = Gui.scroll_table(camera_set, 400, 6, 'buttons') - cctv_player(buttons) + cctv_player(buttons, player_list) cctv_type(buttons) cctv_status(buttons) cctv_location(buttons) @@ -110,16 +113,14 @@ end) cctv_container = Gui.element(function(event_trigger, parent) local container = Gui.container(parent, event_trigger, 480) - local scroll_table_1 = Gui.scroll_table(container, 400, 6, 'cctv_st_1') - local scroll_table_2 = Gui.scroll_table(container, 400, 6, 'cctv_st_2') - player_list = {} + local player_list = {} for _, player in pairs(game.connected_players) do table.insert(player_list, player.name) end - camera_set(scroll_table_1) - camera_set(scroll_table_2) + camera_set(container, "cctv_st_1", player_list) + camera_set(container, "cctv_st_2", player_list) return container.parent end) @@ -130,7 +131,7 @@ Gui.left_toolbar_button('entity/radar', 'Surveillance GUI', cctv_container, func end) local function gui_update() - player_list = {} + local player_list = {} for _, player in pairs(game.connected_players) do table.insert(player_list, player.name) @@ -138,8 +139,8 @@ local function gui_update() for _, player in pairs(game.connected_players) do local frame = Gui.get_left_element(player, cctv_container) - frame.container['cctv_st_1'].table.flow['buttons'][cctv_player.name].items = player_list - frame.container['cctv_st_2'].table.flow['buttons'][cctv_player.name].items = player_list + frame.container['cctv_st_1'].buttons.table[cctv_player.name].items = player_list + frame.container['cctv_st_2'].buttons.table[cctv_player.name].items = player_list end end @@ -152,18 +153,19 @@ Event.add(defines.events.on_tick, function(_) for i=1, 2 do local scroll_table_name = 'cctv_st_' .. i - local switch_index = frame.container[scroll_table_name].table.flow[cctv_status.name].selected_index + local current_camera_set = frame.container[scroll_table_name] + local switch_index = current_camera_set.buttons.table[cctv_status.name].selected_index if switch_index == 1 then - local selected_index = frame.container[scroll_table_name].table.flow[cctv_player.name].selected_index + local selected_index = current_camera_set.buttons.table[cctv_player.name].selected_index if selected_index ~= nil or selected_index ~= 0 then - frame.container[scroll_table_name].table.flow['cctv_display'].position = game.players[selected_index].position - frame.container[scroll_table_name].table.flow['cctv_display'].surface_index = game.players[selected_index].surface_index + current_camera_set['cctv_display'].position = game.players[selected_index].position + current_camera_set['cctv_display'].surface_index = game.players[selected_index].surface_index else - frame.container[scroll_table_name].table.flow['cctv_display'].position = {x=0, y=0} - frame.container[scroll_table_name].table.flow['cctv_display'].surface_index = game.surfaces['nauvis'].index + current_camera_set['cctv_display'].position = {x=0, y=0} + current_camera_set['cctv_display'].surface_index = game.surfaces['nauvis'].index end end end From b2bcc945105c1adb038fc87cd481ab840ed197fc Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Tue, 3 Oct 2023 03:07:23 +0900 Subject: [PATCH 07/30] . --- modules/gui/surveillance.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/gui/surveillance.lua b/modules/gui/surveillance.lua index b4087fa4..10007042 100644 --- a/modules/gui/surveillance.lua +++ b/modules/gui/surveillance.lua @@ -87,7 +87,7 @@ end) local camera_set = Gui.element(function(_, parent, name, player_list) - local camera_set = parent.add{type='flow', direction="vertical", name=name} + local camera_set = parent.add{type='flow', direction='vertical', name=name} local buttons = Gui.scroll_table(camera_set, 400, 6, 'buttons') cctv_player(buttons, player_list) @@ -119,8 +119,8 @@ Gui.element(function(event_trigger, parent) table.insert(player_list, player.name) end - camera_set(container, "cctv_st_1", player_list) - camera_set(container, "cctv_st_2", player_list) + camera_set(container, 'cctv_st_1', player_list) + camera_set(container, 'cctv_st_2', player_list) return container.parent end) From 7577e3759994c68795a413eebd8ff211fdf5bacc Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Tue, 3 Oct 2023 03:11:17 +0900 Subject: [PATCH 08/30] remove cctv status visible check --- modules/gui/surveillance.lua | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/modules/gui/surveillance.lua b/modules/gui/surveillance.lua index 10007042..2e376512 100644 --- a/modules/gui/surveillance.lua +++ b/modules/gui/surveillance.lua @@ -41,13 +41,7 @@ Gui.element{ selected_index = 1 }:style{ width = 96 -}:on_click(function(_, element, _) - if element.selected_index == 1 then - element.parent.parent.parent.cctv_display.visible = true - else - element.parent.parent.parent.cctv_display.visible = false - end -end) +} local cctv_location = Gui.element{ From 3cfc1323006a18d0036f05ff6965b628c7fef189 Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Tue, 3 Oct 2023 03:19:56 +0900 Subject: [PATCH 09/30] resolution adjust --- modules/gui/surveillance.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/gui/surveillance.lua b/modules/gui/surveillance.lua index 2e376512..6892ab58 100644 --- a/modules/gui/surveillance.lua +++ b/modules/gui/surveillance.lua @@ -24,8 +24,8 @@ Gui.element{ items = {'Enable', 'Disable'}, selected_index = 1 }:style{ - width = 96 -}:on_click(function(_, element, _) + width = 80 +}:on_selection_changed(function(_, element, _) if element.selected_index == 1 then element.parent.parent.parent.cctv_display.visible = true else @@ -40,7 +40,7 @@ Gui.element{ items = {'Player', 'Static'}, selected_index = 1 }:style{ - width = 96 + width = 80 } local cctv_location = @@ -48,7 +48,7 @@ Gui.element{ type = 'button', caption = 'set' }:style{ - width = 48 + width = 40 }:on_click(function(player, element, _) element.parent.parent.cctv_display.position = player.position end) @@ -58,7 +58,7 @@ Gui.element{ type = 'button', caption = '+' }:style{ - width = 36 + width = 30 }:on_click(function(_, element, _) local display = element.parent.parent.parent.cctv_display if display.zoom < 2.0 then @@ -71,7 +71,7 @@ Gui.element{ type = 'button', caption = '-' }:style{ - width = 36 + width = 30 }:on_click(function(_, element, _) local display = element.parent.parent.parent.cctv_display if display.zoom > 0.2 then @@ -106,7 +106,7 @@ end) cctv_container = Gui.element(function(event_trigger, parent) - local container = Gui.container(parent, event_trigger, 480) + local container = Gui.container(parent, event_trigger, 400) local player_list = {} for _, player in pairs(game.connected_players) do From c38a25f859f28535456c4f4b4d604617af98ec10 Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Wed, 4 Oct 2023 11:48:37 +0900 Subject: [PATCH 10/30] . --- modules/gui/surveillance.lua | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/gui/surveillance.lua b/modules/gui/surveillance.lua index 6892ab58..ab5700e8 100644 --- a/modules/gui/surveillance.lua +++ b/modules/gui/surveillance.lua @@ -24,7 +24,7 @@ Gui.element{ items = {'Enable', 'Disable'}, selected_index = 1 }:style{ - width = 80 + width = 96 }:on_selection_changed(function(_, element, _) if element.selected_index == 1 then element.parent.parent.parent.cctv_display.visible = true @@ -40,7 +40,7 @@ Gui.element{ items = {'Player', 'Static'}, selected_index = 1 }:style{ - width = 80 + width = 96 } local cctv_location = @@ -48,9 +48,9 @@ Gui.element{ type = 'button', caption = 'set' }:style{ - width = 40 + width = 48 }:on_click(function(player, element, _) - element.parent.parent.cctv_display.position = player.position + element.parent.parent.parent.cctv_display.position = player.position end) local zoom_in = @@ -58,7 +58,7 @@ Gui.element{ type = 'button', caption = '+' }:style{ - width = 30 + width = 32 }:on_click(function(_, element, _) local display = element.parent.parent.parent.cctv_display if display.zoom < 2.0 then @@ -71,7 +71,7 @@ Gui.element{ type = 'button', caption = '-' }:style{ - width = 30 + width = 32 }:on_click(function(_, element, _) local display = element.parent.parent.parent.cctv_display if display.zoom > 0.2 then @@ -82,7 +82,7 @@ end) local camera_set = Gui.element(function(_, parent, name, player_list) local camera_set = parent.add{type='flow', direction='vertical', name=name} - local buttons = Gui.scroll_table(camera_set, 400, 6, 'buttons') + local buttons = Gui.scroll_table(camera_set, 480, 6, 'buttons') cctv_player(buttons, player_list) cctv_type(buttons) @@ -99,14 +99,14 @@ Gui.element(function(_, parent, name, player_list) zoom = 0.75, } - camera.style.minimal_width = 400 - camera.style.minimal_height = 300 + camera.style.minimal_width = 480 + camera.style.minimal_height = 360 return camera_set end) cctv_container = Gui.element(function(event_trigger, parent) - local container = Gui.container(parent, event_trigger, 400) + local container = Gui.container(parent, event_trigger, 480) local player_list = {} for _, player in pairs(game.connected_players) do From 6dc302c71e7397201482d53812ff3c01140ab0ef Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Wed, 4 Oct 2023 18:12:32 +0900 Subject: [PATCH 11/30] disable --- modules/gui/surveillance.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/gui/surveillance.lua b/modules/gui/surveillance.lua index ab5700e8..c1c79363 100644 --- a/modules/gui/surveillance.lua +++ b/modules/gui/surveillance.lua @@ -22,7 +22,7 @@ Gui.element{ type = 'drop-down', name = 'cctv_status', items = {'Enable', 'Disable'}, - selected_index = 1 + selected_index = 2 }:style{ width = 96 }:on_selection_changed(function(_, element, _) From 968ff603e4d016387f6097449e1b6fc8457145a4 Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Wed, 4 Oct 2023 18:18:28 +0900 Subject: [PATCH 12/30] . --- modules/gui/surveillance.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/gui/surveillance.lua b/modules/gui/surveillance.lua index c1c79363..6676c1bf 100644 --- a/modules/gui/surveillance.lua +++ b/modules/gui/surveillance.lua @@ -99,6 +99,7 @@ Gui.element(function(_, parent, name, player_list) zoom = 0.75, } + camera.visible = false camera.style.minimal_width = 480 camera.style.minimal_height = 360 return camera_set From 0a06dccaa7fa79f835d876413304b12663a2c4eb Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Thu, 5 Oct 2023 13:29:14 +0900 Subject: [PATCH 13/30] scroll --- modules/gui/surveillance.lua | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/modules/gui/surveillance.lua b/modules/gui/surveillance.lua index 6676c1bf..4a60ea43 100644 --- a/modules/gui/surveillance.lua +++ b/modules/gui/surveillance.lua @@ -16,6 +16,9 @@ Gui.element(function(name, parent, player_list) selected_index = #player_list > 0 and 1 } end) +:style{ + horizontally_stretchable = true +} local cctv_type = Gui.element{ @@ -100,22 +103,24 @@ Gui.element(function(_, parent, name, player_list) } camera.visible = false - camera.style.minimal_width = 480 - camera.style.minimal_height = 360 + camera.style.minimal_width = 400 + camera.style.minimal_height = 300 return camera_set end) cctv_container = Gui.element(function(event_trigger, parent) - local container = Gui.container(parent, event_trigger, 480) + local container = Gui.container(parent, event_trigger, 400) + local scroll = container.add{name='scroll', type='scroll-pane', direction='vertical'} + scroll.style.maximal_height = 664 local player_list = {} for _, player in pairs(game.connected_players) do table.insert(player_list, player.name) end - camera_set(container, 'cctv_st_1', player_list) - camera_set(container, 'cctv_st_2', player_list) + camera_set(scroll, 'cctv_st_1', player_list) + camera_set(scroll, 'cctv_st_2', player_list) return container.parent end) @@ -134,8 +139,8 @@ local function gui_update() for _, player in pairs(game.connected_players) do local frame = Gui.get_left_element(player, cctv_container) - frame.container['cctv_st_1'].buttons.table[cctv_player.name].items = player_list - frame.container['cctv_st_2'].buttons.table[cctv_player.name].items = player_list + frame.container.scroll['cctv_st_1'].buttons.table[cctv_player.name].items = player_list + frame.container.scroll['cctv_st_2'].buttons.table[cctv_player.name].items = player_list end end @@ -148,7 +153,7 @@ Event.add(defines.events.on_tick, function(_) for i=1, 2 do local scroll_table_name = 'cctv_st_' .. i - local current_camera_set = frame.container[scroll_table_name] + local current_camera_set = frame.container.scroll[scroll_table_name] local switch_index = current_camera_set.buttons.table[cctv_status.name].selected_index if switch_index == 1 then From 908c114ebfafb37f559344ea3d6850c71e313d05 Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Thu, 5 Oct 2023 13:30:25 +0900 Subject: [PATCH 14/30] size --- modules/gui/surveillance.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/gui/surveillance.lua b/modules/gui/surveillance.lua index 4a60ea43..5e57e184 100644 --- a/modules/gui/surveillance.lua +++ b/modules/gui/surveillance.lua @@ -103,14 +103,14 @@ Gui.element(function(_, parent, name, player_list) } camera.visible = false - camera.style.minimal_width = 400 - camera.style.minimal_height = 300 + camera.style.minimal_width = 480 + camera.style.minimal_height = 360 return camera_set end) cctv_container = Gui.element(function(event_trigger, parent) - local container = Gui.container(parent, event_trigger, 400) + local container = Gui.container(parent, event_trigger, 480) local scroll = container.add{name='scroll', type='scroll-pane', direction='vertical'} scroll.style.maximal_height = 664 local player_list = {} From 4a56b330cc02bb85f13509d99c17ab475c5cc329 Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Thu, 5 Oct 2023 13:30:43 +0900 Subject: [PATCH 15/30] . --- modules/gui/surveillance.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/gui/surveillance.lua b/modules/gui/surveillance.lua index 5e57e184..13d1f95b 100644 --- a/modules/gui/surveillance.lua +++ b/modules/gui/surveillance.lua @@ -112,7 +112,7 @@ cctv_container = Gui.element(function(event_trigger, parent) local container = Gui.container(parent, event_trigger, 480) local scroll = container.add{name='scroll', type='scroll-pane', direction='vertical'} - scroll.style.maximal_height = 664 + scroll.style.maximal_height = 816 local player_list = {} for _, player in pairs(game.connected_players) do From 484014475f695e595b47bd73e927c0ac841b9b61 Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Fri, 6 Oct 2023 22:38:14 +0900 Subject: [PATCH 16/30] fixed non prod module insertion with recipe --- config/module.lua | 2 +- modules/gui/module.lua | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/config/module.lua b/config/module.lua index 9b50224e..a2a8e906 100644 --- a/config/module.lua +++ b/config/module.lua @@ -1,6 +1,6 @@ return { -- type of machine to handle together - default_module_row_count = 4, + default_module_row_count = 6, module_slot_max = 4, machine_prod_disallow = { ['beacon'] = true diff --git a/modules/gui/module.lua b/modules/gui/module.lua index 74470348..06981ba1 100644 --- a/modules/gui/module.lua +++ b/modules/gui/module.lua @@ -74,14 +74,32 @@ local function apply_module(player, area, machine, module) if m_current_recipe ~= nil 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=module} end + entity.surface.create_entity{name='item-request-proxy', target=entity, position=entity.position, force=entity.force, modules=module} + entity.last_user = player + + else + local prod = false + + for k, _ in pairs(module) do + if k:sub(1, 12) == 'productivity' then + prod = true + end + end + + if not prod then + entity.surface.create_entity{name='item-request-proxy', target=entity, position=entity.position, force=entity.force, modules=module} + entity.last_user = player + end + end else entity.surface.create_entity{name='item-request-proxy', target=entity, position=entity.position, force=entity.force, modules=module} + entity.last_user = player end else entity.surface.create_entity{name='item-request-proxy', target=entity, position=entity.position, force=entity.force, modules=module} + entity.last_user = player end end end From 6eaf415107f0bb1cd3e214a9bbbe312148dae22d Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Sat, 7 Oct 2023 14:50:46 +0900 Subject: [PATCH 17/30] size --- modules/gui/surveillance.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/gui/surveillance.lua b/modules/gui/surveillance.lua index 13d1f95b..5ddfa37e 100644 --- a/modules/gui/surveillance.lua +++ b/modules/gui/surveillance.lua @@ -112,7 +112,7 @@ cctv_container = Gui.element(function(event_trigger, parent) local container = Gui.container(parent, event_trigger, 480) local scroll = container.add{name='scroll', type='scroll-pane', direction='vertical'} - scroll.style.maximal_height = 816 + scroll.style.maximal_height = 704 local player_list = {} for _, player in pairs(game.connected_players) do From f6714f75cb37127da40f0bbc1156e523eede8407 Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Sat, 7 Oct 2023 14:56:01 +0900 Subject: [PATCH 18/30] swap module --- modules/gui/module.lua | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/modules/gui/module.lua b/modules/gui/module.lua index 06981ba1..83ce4417 100644 --- a/modules/gui/module.lua +++ b/modules/gui/module.lua @@ -78,18 +78,12 @@ local function apply_module(player, area, machine, module) entity.last_user = player else - local prod = false - for k, _ in pairs(module) do - if k:sub(1, 12) == 'productivity' then - prod = true - end + k = k:gsub('productivity', 'effectivity') end - if not prod then - entity.surface.create_entity{name='item-request-proxy', target=entity, position=entity.position, force=entity.force, modules=module} - entity.last_user = player - end + entity.surface.create_entity{name='item-request-proxy', target=entity, position=entity.position, force=entity.force, modules=module} + entity.last_user = player end else From 0be43b0e1d9c9d58e9c5299fbfd1c547aa05204b Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Sat, 7 Oct 2023 14:58:54 +0900 Subject: [PATCH 19/30] . --- modules/gui/module.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/gui/module.lua b/modules/gui/module.lua index 83ce4417..e2512026 100644 --- a/modules/gui/module.lua +++ b/modules/gui/module.lua @@ -79,7 +79,7 @@ local function apply_module(player, area, machine, module) else for k, _ in pairs(module) do - k = k:gsub('productivity', 'effectivity') + module[k] = module[k]:gsub('productivity', 'effectivity') end entity.surface.create_entity{name='item-request-proxy', target=entity, position=entity.position, force=entity.force, modules=module} From fb3a789910445657e224c91d66f3b2cc1da4a710 Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Thu, 12 Oct 2023 00:10:13 +0900 Subject: [PATCH 20/30] selected_index --- modules/gui/surveillance.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/gui/surveillance.lua b/modules/gui/surveillance.lua index 5ddfa37e..262ca2c0 100644 --- a/modules/gui/surveillance.lua +++ b/modules/gui/surveillance.lua @@ -159,7 +159,7 @@ Event.add(defines.events.on_tick, function(_) if switch_index == 1 then local selected_index = current_camera_set.buttons.table[cctv_player.name].selected_index - if selected_index ~= nil or selected_index ~= 0 then + if selected_index > 0 then current_camera_set['cctv_display'].position = game.players[selected_index].position current_camera_set['cctv_display'].surface_index = game.players[selected_index].surface_index From 1c56aa9223d5fed001058c3f5f39f975d589c1c9 Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Fri, 13 Oct 2023 23:48:04 +0900 Subject: [PATCH 21/30] 1 decimal place on last location gps --- modules/commands/last-location.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/commands/last-location.lua b/modules/commands/last-location.lua index b020efc4..44763a17 100644 --- a/modules/commands/last-location.lua +++ b/modules/commands/last-location.lua @@ -15,5 +15,5 @@ Commands.new_command('last-location', 'Sends you the last location of a player') :add_param('player', false, 'player') :register(function(player, action_player) local action_player_name_color = format_chat_player_name(action_player) - player.print{'expcom-lastlocation.response', action_player_name_color, action_player.position.x, action_player.position.y} -end) \ No newline at end of file + player.print{'expcom-lastlocation.response', action_player_name_color, string.format('%.1f', action_player.position.x), string.format('%.1f', action_player.position.y)} +end) From 44c7cae563766d136342b9e567802eb9301a2478 Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Fri, 13 Oct 2023 23:51:01 +0900 Subject: [PATCH 22/30] deconstruction of tree and rocks when drive over them --- modules/addons/tree-decon.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/addons/tree-decon.lua b/modules/addons/tree-decon.lua index d4a2c206..c3d36920 100644 --- a/modules/addons/tree-decon.lua +++ b/modules/addons/tree-decon.lua @@ -96,4 +96,14 @@ Event.on_nth_tick(300, function() for key, _ in pairs(chache) do chache[key] = nil end -end) \ No newline at end of file +end) + +Event.add(defines.events.on_entity_damaged, function(event) + if not (event.damage_type.name == 'impact' and event.force) then + return + end + + if event.entity.type == 'tree' or event.entity.type == 'simple-entity' then + event.entity.destroy() + end +end) From 193f3e3b88e2aad86ed909df1adcd7a1b8f18d30 Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Sat, 14 Oct 2023 02:08:53 +0900 Subject: [PATCH 23/30] Update tree-decon.lua --- modules/addons/tree-decon.lua | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/modules/addons/tree-decon.lua b/modules/addons/tree-decon.lua index c3d36920..1f594366 100644 --- a/modules/addons/tree-decon.lua +++ b/modules/addons/tree-decon.lua @@ -99,11 +99,17 @@ Event.on_nth_tick(300, function() end) Event.add(defines.events.on_entity_damaged, function(event) - if not (event.damage_type.name == 'impact' and event.force) then + if not (event.damage_type.name == 'impact' and event.force) then + return + end + + if not (event.entity.type == 'tree' or event.entity.type == 'simple-entity') then + return + end + + if (not event.cause) or (event.cause.type ~= 'car')then return end - if event.entity.type == 'tree' or event.entity.type == 'simple-entity' then - event.entity.destroy() - end + event.entity.destroy() end) From fe1ee200e2ce36488e51dd17ef814101a7c01440 Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Sat, 14 Oct 2023 02:15:19 +0900 Subject: [PATCH 24/30] Update tree-decon.lua --- modules/addons/tree-decon.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/addons/tree-decon.lua b/modules/addons/tree-decon.lua index 1f594366..84194d7c 100644 --- a/modules/addons/tree-decon.lua +++ b/modules/addons/tree-decon.lua @@ -102,11 +102,11 @@ Event.add(defines.events.on_entity_damaged, function(event) if not (event.damage_type.name == 'impact' and event.force) then return end - + if not (event.entity.type == 'tree' or event.entity.type == 'simple-entity') then return end - + if (not event.cause) or (event.cause.type ~= 'car')then return end From b92beebda78561c8ec65cd054399674e4ffcbdbf Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Tue, 24 Oct 2023 18:24:07 +0900 Subject: [PATCH 25/30] two command --- config/_file_loader.lua | 1 + config/expcore/roles.lua | 4 +++- modules/commands/surface-clearing.lua | 34 +++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 modules/commands/surface-clearing.lua diff --git a/config/_file_loader.lua b/config/_file_loader.lua index 16ec66d8..aa1853cf 100644 --- a/config/_file_loader.lua +++ b/config/_file_loader.lua @@ -44,6 +44,7 @@ return { 'modules.commands.vlayer', 'modules.commands.enemy', 'modules.commands.waterfill', + 'modules.commands.surface-clearing', --- Addons 'modules.addons.chat-popups', diff --git a/config/expcore/roles.lua b/config/expcore/roles.lua index 42d31c34..b8a27f3b 100644 --- a/config/expcore/roles.lua +++ b/config/expcore/roles.lua @@ -230,7 +230,9 @@ Roles.new_role('Member','Mem') 'command/auto-research', 'command/manual-train', 'command/lawnmower', - 'command/waterfill' + 'command/waterfill', + 'command/clear-item-on-ground', + 'command/clear-blueprint' } local hours3, hours15 = 3*216000, 15*60 diff --git a/modules/commands/surface-clearing.lua b/modules/commands/surface-clearing.lua new file mode 100644 index 00000000..d8cb19ef --- /dev/null +++ b/modules/commands/surface-clearing.lua @@ -0,0 +1,34 @@ +--[[-- Commands Module - Clear Item On Ground + - Adds a command that clear item on ground so blueprint can deploy safely + @commands Clear Item On Ground +]] + +local Commands = require 'expcore.commands' --- @dep expcore.commands +require 'config.expcore.command_general_parse' + +Commands.new_command('clear-item-on-ground', 'Clear Item On Ground') +:add_param('range', false, 'integer-range', 1, 1000) +:register(function(player, range) + for _, e in pairs(player.surface.find_entities_filtered{position=player.position, radius=range, name='item-on-ground'}) do + if e.stack then + e.stack.clear() + end + end + + return Commands.success +end) + +--[[-- Commands Module - Clear Blueprint + - Adds a command that clear blueprint spamming or leftover + @commands Clear Blueprint +]] + +Commands.new_command('clear-blueprint', 'Clear Blueprint') +:add_param('range', false, 'integer-range', 1, 1000) +:register(function(player, range) + for _, e in pairs(player.surface.find_entities_filtered{position=player.position, radius=range, type='entity-ghost'}) do + e.destroy() + end + + return Commands.success +end) \ No newline at end of file From f64c936c9351b5882760ca20f039e20725179549 Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Tue, 24 Oct 2023 21:00:39 +0900 Subject: [PATCH 26/30] . --- modules/commands/surface-clearing.lua | 5 ----- 1 file changed, 5 deletions(-) diff --git a/modules/commands/surface-clearing.lua b/modules/commands/surface-clearing.lua index d8cb19ef..48f38750 100644 --- a/modules/commands/surface-clearing.lua +++ b/modules/commands/surface-clearing.lua @@ -18,11 +18,6 @@ Commands.new_command('clear-item-on-ground', 'Clear Item On Ground') return Commands.success end) ---[[-- Commands Module - Clear Blueprint - - Adds a command that clear blueprint spamming or leftover - @commands Clear Blueprint -]] - Commands.new_command('clear-blueprint', 'Clear Blueprint') :add_param('range', false, 'integer-range', 1, 1000) :register(function(player, range) From 0b9cbfb64c5af43b2edb55a736b28e7692ab0826 Mon Sep 17 00:00:00 2001 From: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com> Date: Thu, 21 Dec 2023 20:14:04 +0000 Subject: [PATCH 27/30] Fix broken module substitution --- modules/gui/module.lua | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/modules/gui/module.lua b/modules/gui/module.lua index e2512026..7cd5d94a 100644 --- a/modules/gui/module.lua +++ b/modules/gui/module.lua @@ -67,32 +67,35 @@ local function clear_module(player, area, machine) end end -local function apply_module(player, area, machine, module) +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 if config.machine_craft[machine] then local m_current_recipe = entity.get_recipe() if m_current_recipe ~= nil 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=module} + entity.surface.create_entity{name='item-request-proxy', target=entity, position=entity.position, force=entity.force, modules=modules} entity.last_user = player else - for k, _ in pairs(module) do - module[k] = module[k]:gsub('productivity', 'effectivity') + for k in pairs(modules) do + 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=module} + entity.surface.create_entity{name='item-request-proxy', target=entity, position=entity.position, force=entity.force, modules=modules} entity.last_user = player end else - entity.surface.create_entity{name='item-request-proxy', target=entity, position=entity.position, force=entity.force, modules=module} + entity.surface.create_entity{name='item-request-proxy', target=entity, position=entity.position, force=entity.force, modules=modules} entity.last_user = player end else - entity.surface.create_entity{name='item-request-proxy', target=entity, position=entity.position, force=entity.force, modules=module} + entity.surface.create_entity{name='item-request-proxy', target=entity, position=entity.position, force=entity.force, modules=modules} entity.last_user = player end end From c6d7a24ff595867bbe67503a7365e76c9e3d84d6 Mon Sep 17 00:00:00 2001 From: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com> Date: Thu, 21 Dec 2023 20:36:52 +0000 Subject: [PATCH 28/30] Allowed for fast decon toggle --- modules/addons/tree-decon.lua | 44 ++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/modules/addons/tree-decon.lua b/modules/addons/tree-decon.lua index 84194d7c..6e7934d1 100644 --- a/modules/addons/tree-decon.lua +++ b/modules/addons/tree-decon.lua @@ -7,14 +7,24 @@ local Roles = require 'expcore.roles' --- @dep expcore.roles local Gui = require 'expcore.gui' --- @dep expcore.gui local PlayerData = require 'expcore.player_data' --- @dep expcore.player_data --- Global queue used to store trees that need to be removed, also chache for player roles -local chache = {} +-- Global queue used to store trees that need to be removed, also cache for player roles +local cache = {} local tree_queue = { _head=0 } -Global.register({tree_queue, chache}, function(tbl) +Global.register({tree_queue, cache}, function(tbl) tree_queue = tbl[1] - chache = tbl[2] + cache = tbl[2] end) +local function get_permission(player_index) + if cache[player_index] == nil then + local player = game.players[player_index] + if Roles.player_allowed(player, 'fast-tree-decon') then cache[player_index] = 'fast' + elseif Roles.player_allowed(player, 'standard-decon') then cache[player_index] = 'standard' + else cache[player_index] = player.force end + end + + return cache[player_index] +end -- Left menu button to toggle between fast decon and normal decon marking local HasEnabledDecon = PlayerData.Settings:combine('HasEnabledDecon') @@ -36,20 +46,14 @@ Event.add(defines.events.on_marked_for_deconstruction, function(event) -- Check which type of decon a player is allowed local index = event.player_index if not index then return end - if chache[index] == nil then - local player = game.players[index] - if Roles.player_allowed(player, 'fast-tree-decon') then chache[index] = 'fast' - elseif Roles.player_allowed(player, 'standard-decon') then chache[index] = 'standard' - else chache[index] = player.force end - end -- Check what should happen to this entity local entity = event.entity - local allow = chache[index] if not entity or not entity.valid then return end -- Not allowed to decon this entity local last_user = entity.last_user + local allow = get_permission(index) if last_user and allow ~= 'standard' and allow ~= 'fast' then entity.cancel_deconstruction(allow) return @@ -58,7 +62,6 @@ Event.add(defines.events.on_marked_for_deconstruction, function(event) -- Allowed to decon this entity, but not fast if allow ~= 'fast' then return end - local player = game.get_player(index) if not HasEnabledDecon:get(player) then return end @@ -91,13 +94,14 @@ Event.add(defines.events.on_tick, function() tree_queue._head = head end) --- Clear the chache +-- Clear the cache Event.on_nth_tick(300, function() - for key, _ in pairs(chache) do - chache[key] = nil + for key, _ in pairs(cache) do + cache[key] = nil end end) +-- Clear trees when hit with a car Event.add(defines.events.on_entity_damaged, function(event) if not (event.damage_type.name == 'impact' and event.force) then return @@ -111,5 +115,13 @@ Event.add(defines.events.on_entity_damaged, function(event) return end - event.entity.destroy() + local driver = event.cause.get_driver() + if not driver then return end + + local allow = get_permission(driver.player.index) + if allow == "fast" and HasEnabledDecon:get(driver.player) then + event.entity.destroy() + else + event.entity.order_deconstruction(event.force, driver.player) + end end) From 73fc64782397fabe5a4c56c0debf355708b5c5bf Mon Sep 17 00:00:00 2001 From: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com> Date: Thu, 21 Dec 2023 21:29:58 +0000 Subject: [PATCH 29/30] Items are moved to spawn chests on clear --- modules/commands/surface-clearing.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/commands/surface-clearing.lua b/modules/commands/surface-clearing.lua index 48f38750..99e4254a 100644 --- a/modules/commands/surface-clearing.lua +++ b/modules/commands/surface-clearing.lua @@ -3,6 +3,7 @@ @commands Clear Item On Ground ]] +local copy_items_stack = _C.copy_items_stack --- @dep expcore.common local Commands = require 'expcore.commands' --- @dep expcore.commands require 'config.expcore.command_general_parse' @@ -11,6 +12,9 @@ Commands.new_command('clear-item-on-ground', 'Clear Item On Ground') :register(function(player, range) for _, e in pairs(player.surface.find_entities_filtered{position=player.position, radius=range, name='item-on-ground'}) do if e.stack then + -- calling move_items_stack(e.stack) will crash to desktop + -- https://forums.factorio.com/viewtopic.php?f=7&t=110322 + copy_items_stack{e.stack} e.stack.clear() end end From ab53c0d8eed2cd98af15d2ea5bad1f28c883b969 Mon Sep 17 00:00:00 2001 From: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com> Date: Thu, 21 Dec 2023 21:35:12 +0000 Subject: [PATCH 30/30] Fix missing comma from merge conflict --- config/expcore/roles.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/expcore/roles.lua b/config/expcore/roles.lua index a1d8ecdb..416e9f2d 100644 --- a/config/expcore/roles.lua +++ b/config/expcore/roles.lua @@ -232,7 +232,7 @@ Roles.new_role('Member','Mem') 'command/lawnmower', 'command/waterfill', 'command/clear-item-on-ground', - 'command/clear-blueprint' + 'command/clear-blueprint', 'gui/surveillance' }