From ffda3ed64e8942deb5b15fed187d2bbb75c78e8f Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Mon, 25 Sep 2023 22:43:40 +0900 Subject: [PATCH 01/17] 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/17] 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/17] 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/17] 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/17] . --- 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/17] 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/17] . --- 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/17] 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/17] 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/17] . --- 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/17] 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/17] . --- 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/17] 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/17] 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/17] . --- 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 6eaf415107f0bb1cd3e214a9bbbe312148dae22d Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Sat, 7 Oct 2023 14:50:46 +0900 Subject: [PATCH 16/17] 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 fb3a789910445657e224c91d66f3b2cc1da4a710 Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Thu, 12 Oct 2023 00:10:13 +0900 Subject: [PATCH 17/17] 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