From d340e94d467df8f63fad4d17e5435b0acbca32e3 Mon Sep 17 00:00:00 2001 From: Cyberarm Date: Sun, 31 Jan 2021 13:32:02 -0600 Subject: [PATCH] Use scrolling in editor, fixed border in editor, started work on presets, jump to group/action/variable from search is mostly working (may add highlighted background and scroll to in future) --- lib/pages/configurations.rb | 4 +- lib/pages/editor.rb | 58 ++++++++++++++++++---- lib/pages/presets.rb | 78 +++++++++++++++++++++++++++++- lib/pages/search.rb | 18 ++++--- lib/tacnet/packet_handler.rb | 6 ++- timecrafters_configuration_tool.rb | 2 +- 6 files changed, 143 insertions(+), 23 deletions(-) diff --git a/lib/pages/configurations.rb b/lib/pages/configurations.rb index 2c3ff5b..6d00201 100644 --- a/lib/pages/configurations.rb +++ b/lib/pages/configurations.rb @@ -13,8 +13,6 @@ module TAC populate_configs }) end - - # label "Manage Configurations", text_size: 36 end status_bar.clear do @@ -23,7 +21,7 @@ module TAC end body.clear do - @configs_list = stack width: 1.0 do + @configs_list = stack width: 1.0, height: 1.0, scroll: true do end end diff --git a/lib/pages/editor.rb b/lib/pages/editor.rb index 1e297d7..08bd5e8 100644 --- a/lib/pages/editor.rb +++ b/lib/pages/editor.rb @@ -7,7 +7,13 @@ module TAC @active_action = nil menu_bar.clear do - title "Editing configuration: #{window.backend.config.name}" + if @options[:group_is_preset] + title "Editing group preset: #{@options[:group].name}" + elsif @options[:action_is_preset] + title "Editing action preset: #{@options[:action].name}" + else + title "Editing configuration: #{window.backend.config.name}" + end end status_bar.clear do @@ -24,8 +30,8 @@ module TAC body.clear do flow(width: 1.0, height: 1.0) do - stack width: 0.33333, height: 1.0, border_thickness: 1, border_color: [0, Gosu::Color::BLACK, 0, 0] do - flow(width: 1.0) do + stack width: 0.33333, height: 1.0, border_thickness_right: 1, border_color: [0, Gosu::Color::BLACK, 0, 0] do + @groups_menu = flow(width: 1.0) do label "Groups", text_size: THEME_SUBHEADING_TEXT_SIZE button get_image("#{TAC::ROOT_PATH}/media/icons/plus.png"), image_width: THEME_ICON_SIZE, tip: "Add group" do @@ -53,12 +59,12 @@ module TAC end end - @groups_list = stack width: 1.0 do + @groups_list = stack width: 1.0, scroll: true do end end - stack width: 0.33333, height: 1.0, border_thickness: 1, border_color: [0, Gosu::Color::BLACK, 0, 0] do - flow(width: 1.0) do + stack width: 0.33333, height: 1.0, border_thickness_right: 1, border_color: [0, Gosu::Color::BLACK, 0, 0] do + @actions_menu = flow(width: 1.0) do label "Actions", text_size: THEME_SUBHEADING_TEXT_SIZE button get_image("#{TAC::ROOT_PATH}/media/icons/plus.png"), image_width: THEME_ICON_SIZE, tip: "Add action" do @@ -91,12 +97,12 @@ module TAC end end - @actions_list = stack width: 1.0 do + @actions_list = stack width: 1.0, scroll: true do end end stack width: 0.331, height: 1.0 do - flow(width: 1.0) do + @variables_menu = flow(width: 1.0) do label "Variables", text_size: THEME_SUBHEADING_TEXT_SIZE button get_image("#{TAC::ROOT_PATH}/media/icons/plus.png"), image_width: THEME_ICON_SIZE, tip: "Add variable" do if @active_action @@ -107,13 +113,41 @@ module TAC end end - @variables_list = stack width: 1.0 do + @variables_list = stack width: 1.0, scroll: true do end end end end populate_groups_list + + if @options[:group] + @active_group = @options[:group] + @active_group_label.value = @active_group.name + + populate_actions_list(@active_group) + + if @options[:action] + @active_action = @options[:action] + @active_action_label.value = @active_action.name + + populate_variables_list(@active_action) + + if @options[:variable] + # Scroll into view? + end + end + end + + body.root.subscribe(:window_size_changed) do + set_list_heights + end + end + + def set_list_heights + @groups_list.style.height = body.height - @groups_menu.height + @actions_list.style.height = body.height - @actions_menu.height + @variables_list.style.height = body.height - @variables_menu.height end def create_group(name) @@ -221,6 +255,8 @@ module TAC end end end + + set_list_heights end def populate_actions_list(group) @@ -258,6 +294,8 @@ module TAC end end end + + set_list_heights end def populate_variables_list(action) @@ -283,6 +321,8 @@ module TAC end end end + + set_list_heights end end end diff --git a/lib/pages/presets.rb b/lib/pages/presets.rb index da76e17..48a510d 100644 --- a/lib/pages/presets.rb +++ b/lib/pages/presets.rb @@ -4,8 +4,84 @@ module TAC def setup header_bar("Manage Presets") + status_bar.clear do + tagline "Group Presets", width: 0.495 + tagline "Action Presets", width: 0.495 + end + body.clear do - label "Not Yet Implemented" + flow(width: 1.0, height: 1.0) do + @group_presets = stack(width: 0.49995, height: 1.0, scroll: true, border_thickness_right: 1, border_color: [0, Gosu::Color::BLACK, 0, 0]) do + end + + @action_presets = stack(width: 0.49995, height: 1.0, scroll: true) do + end + end + end + + populate_group_presets + populate_action_presets + end + + def populate_group_presets + @group_presets.clear do + window.backend.config.presets.groups.each_with_index do |group, i| + flow(width: 1.0, **THEME_ITEM_CONTAINER_PADDING) do + background i.even? ? THEME_EVEN_COLOR : THEME_ODD_COLOR + + button group.name, width: 0.895 + + button get_image("#{TAC::ROOT_PATH}/media/icons/gear.png"), image_width: THEME_ICON_SIZE, tip: "Edit group" do + push_state( + Dialog::NamePromptDialog, + title: "Rename Group", + renaming: group, + list: window.backend.config.presets.groups, + callback_method: method(:update_group) + ) + end + + button get_image("#{TAC::ROOT_PATH}/media/icons/trashcan.png"), image_width: THEME_ICON_SIZE, tip: "Delete group", **THEME_DANGER_BUTTON do + push_state( + Dialog::ConfirmDialog, + title: "Are you sure?", + message: "Delete group and all of its actions and variables?", + callback_method: proc { delete_group(group) } + ) + end + end + end + end + end + + def populate_action_presets + @action_presets.clear do + window.backend.config.presets.actions.each_with_index do |action, i| + flow(width: 1.0, **THEME_ITEM_CONTAINER_PADDING) do + background i.even? ? THEME_EVEN_COLOR : THEME_ODD_COLOR + + button action.name, width: 0.895 + + button get_image("#{TAC::ROOT_PATH}/media/icons/gear.png"), image_width: THEME_ICON_SIZE, tip: "Edit group" do + push_state( + Dialog::NamePromptDialog, + title: "Rename Group", + renaming: group, + list: window.backend.config.presets.groups, + callback_method: method(:update_group) + ) + end + + button get_image("#{TAC::ROOT_PATH}/media/icons/trashcan.png"), image_width: THEME_ICON_SIZE, tip: "Delete group", **THEME_DANGER_BUTTON do + push_state( + Dialog::ConfirmDialog, + title: "Are you sure?", + message: "Delete group and all of its actions and variables?", + callback_method: proc { delete_group(group) } + ) + end + end + end end end end diff --git a/lib/pages/search.rb b/lib/pages/search.rb index 23ecfdc..fecd7e4 100644 --- a/lib/pages/search.rb +++ b/lib/pages/search.rb @@ -10,16 +10,18 @@ module TAC unless search.value.strip.empty? search_results = search_config(search.value.downcase.strip) + status_bar.clear do + if search_results.results.size.zero? + subtitle "No results for: \"#{search.value.strip}\"" + else + subtitle "Search results for: \"#{search.value.strip}\"" + end + end + body.clear do flow(width: 1.0, height: 1.0) do - stack(width: 0.495, height: 1.0) do + stack(width: 0.495, height: 1.0, scroll: true) do shared_index = 0 - if search_results.results.size.zero? - subtitle "No results for: \"#{search.value.strip}\"" - else - subtitle "Search results for: \"#{search.value.strip}\"" - end - if search_results.groups.size.positive? title "Groups" @@ -70,7 +72,7 @@ module TAC end end - stack(width: 0.495, height: 1.0) do + stack(width: 0.495, height: 1.0, scroll: true) do if search_results.group_presets.size.positive? title "Group Presets" diff --git a/lib/tacnet/packet_handler.rb b/lib/tacnet/packet_handler.rb index 210485d..88e6c95 100644 --- a/lib/tacnet/packet_handler.rb +++ b/lib/tacnet/packet_handler.rb @@ -60,6 +60,8 @@ module TAC if @host_is_a_connection title, message = packet.body.split(Packet::PROTOCOL_SEPERATOR, 2) $window.push_state(TAC::Dialog::TACNETDialog, title: title, message: message) + else + log.e(TAG, "Remote error: #{title}: #{message}") end end @@ -75,7 +77,9 @@ module TAC $window.backend.load_config(config_name) else $window.push_state(TAC::Dialog::AlertDialog, title: "Invalid Config", message: "Supported config spec: v#{TAC::CONFIG_SPEC_VERSION} got v#{data.dig(:config, :spec_version)}") - end + end + else + raise "Invalid Config!" end rescue JSON::ParserError => e diff --git a/timecrafters_configuration_tool.rb b/timecrafters_configuration_tool.rb index 50c40f9..86f89db 100644 --- a/timecrafters_configuration_tool.rb +++ b/timecrafters_configuration_tool.rb @@ -50,5 +50,5 @@ require_relative "lib/tacnet/server" USE_REDESIGN = ARGV.include?("--redesign") if not defined?(Ocra) - TAC::Window.new(width: (Gosu.screen_width * 0.8).round, height: (Gosu.screen_height * 0.8).round, resizable: true, borderless: USE_REDESIGN).show + TAC::Window.new(width: (Gosu.screen_width * 0.8).round, height: (Gosu.screen_height * 0.8).round, resizable: true, borderless: false).show end