From 722e17d5dfb37554d5c9aa69482c51c42c36441c Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Tue, 3 Oct 2023 01:28:47 +0900 Subject: [PATCH] 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