From 451568003a2e5bde9d9d8355aebdbb5ba60b141b Mon Sep 17 00:00:00 2001 From: Cyberarm Date: Thu, 5 Jan 2023 08:42:29 -0600 Subject: [PATCH] Remove no longer needed clipboard and ffi gems, use new CyberarmEngine::GuiState#needs_repaint? method to only paint when needed- should avoid wasting CPU/GPU time (gain a bit more battery life?), make TACNET connection error visually change UI and also trigger a TACNET dialog when not on the TACNET page --- Gemfile | 2 -- lib/pages/simulator.rb | 1 + lib/states/boot.rb | 6 +++--- lib/states/editor.rb | 41 ++++++++++++++++++++++++++++++----------- lib/window.rb | 10 ++++++++++ 5 files changed, 44 insertions(+), 16 deletions(-) diff --git a/Gemfile b/Gemfile index 98b8945..4fa6bd1 100644 --- a/Gemfile +++ b/Gemfile @@ -2,8 +2,6 @@ source "https://rubygems.org" gem "cyberarm_engine" gem "gosu_notifications" -gem "ffi" -gem "clipboard" group :packaging do gem "ocra" diff --git a/lib/pages/simulator.rb b/lib/pages/simulator.rb index 8657596..9e167fe 100644 --- a/lib/pages/simulator.rb +++ b/lib/pages/simulator.rb @@ -77,6 +77,7 @@ robot.forward 100" @simulation.update unless @simulation.robots.all? { |robot| robot.queue.empty? } # Only update clock if simulation is running + current_state.request_repaint @simulation_status.value = "Time: #{(@simulation.simulation_time).round(1)} seconds" end end diff --git a/lib/states/boot.rb b/lib/states/boot.rb index b25f687..4ff062d 100644 --- a/lib/states/boot.rb +++ b/lib/states/boot.rb @@ -11,9 +11,9 @@ module TAC @title_font = CyberarmEngine::Text.new(TAC::NAME, z: 100, size: 72, border: true, border_size: 2, border_color: 0xff_000000, font: THEME[:TextBlock][:font], static: true) @logo = Gosu::Image.new("#{TAC::ROOT_PATH}/media/logo.png") - @title_animator = CyberarmEngine::Animator.new(start_time: 0, duration: 750, from: 0.0, to: 1.0, tween: :swing_from_to) - @logo_animator = CyberarmEngine::Animator.new(start_time: 750, duration: 1_000, from: 0.0, to: 1.0, tween: :swing_to) - @transition_animator = CyberarmEngine::Animator.new(start_time: 2_250, duration: 750, from: 0, to: 255, tween: :ease_out) + @title_animator = CyberarmEngine::Animator.new(start_time: Gosu.milliseconds + 0, duration: 750, from: 0.0, to: 1.0, tween: :swing_from_to) + @logo_animator = CyberarmEngine::Animator.new(start_time: Gosu.milliseconds + 750, duration: 1_000, from: 0.0, to: 1.0, tween: :swing_to) + @transition_animator = CyberarmEngine::Animator.new(start_time: Gosu.milliseconds + 2_250, duration: 750, from: 0, to: 255, tween: :ease_out) @transition_color = Gosu::Color.new(0x00_111111) @next_state = Editor diff --git a/lib/states/editor.rb b/lib/states/editor.rb index 1bd6855..854e346 100644 --- a/lib/states/editor.rb +++ b/lib/states/editor.rb @@ -8,6 +8,8 @@ class Editor < CyberarmEngine::GuiState @window_width = 0 @window_height = 0 + @last_tacnet_status = nil + @pages = {} @page = nil @@ -34,9 +36,9 @@ class Editor < CyberarmEngine::GuiState @header_bar = flow(width: 1.0, height: 36) do background 0xff_006000 - @header_bar_label = label TAC::NAME, width: 1.0, text_align: :center, text_size: 32, font: TAC::THEME_BOLD_FONT + @header_bar_label = label TAC::NAME, fill: true, text_align: :center, text_size: 32, font: TAC::THEME_BOLD_FONT, margin_left: BORDERLESS ? 36 * 3 : 0 - @window_controls = flow(x: window.width - 36 * 2, y: 0, height: 1.0) do + @window_controls = flow(width: 36 * 3, height: 1.0) do button get_image("#{TAC::ROOT_PATH}/media/icons/minus.png"), tip: "Minimize", image_height: 1.0 do window.minimize if window.respond_to?(:minimize) end @@ -138,15 +140,32 @@ class Editor < CyberarmEngine::GuiState @page.update if @page - case window.backend.tacnet.status - when :not_connected - @tacnet_button.style.color = Gosu::Color::WHITE - when :connecting - @tacnet_button.style.color = TAC::Palette::TACNET_CONNECTING - when :connected - @tacnet_button.style.color = TAC::Palette::TACNET_CONNECTED - when :connection_error - @tacnet_button.style.color = TAC::Palette::TACNET_CONNECTION_ERROR + if @last_tacnet_status != window.backend.tacnet.status + @last_tacnet_status = window.backend.tacnet.status + + case window.backend.tacnet.status + when :not_connected, :connected + @tacnet_button.style.color = Gosu::Color::WHITE + @header_bar.style.background = 0xff_006000 + when :connecting + @tacnet_button.style.color = TAC::Palette::TACNET_CONNECTING + @header_bar.style.background = TAC::Palette::TACNET_CONNECTING + when :connection_error + @tacnet_button.style.color = TAC::Palette::TACNET_CONNECTION_ERROR + @header_bar.style.background = TAC::Palette::TACNET_CONNECTION_ERROR + + unless @page.is_a?(TAC::Pages::TACNET) + push_state(TAC::Dialog::TACNETDialog, title: "TACNET Connection Error", message: window.backend.tacnet.full_status) + end + end + + @tacnet_button.style.default[:color] = @tacnet_button.style.color + @header_bar.style.default[:background] = @header_bar.style.background + + @tacnet_button.recalculate + @header_bar.recalculate + + request_repaint end window.width = Gosu.available_width / 2 if window.width < Gosu.available_width / 2 diff --git a/lib/window.rb b/lib/window.rb index 5293c3c..cba393f 100644 --- a/lib/window.rb +++ b/lib/window.rb @@ -11,6 +11,8 @@ module TAC if ARGV.join.include?("--game-clock-remote-display") push_state(PracticeGameClock::View, remote_control_mode: true) + elsif ARGV.join.include?("--intro") + push_state(CyberarmEngine::IntroState, forward: TAC::States::Boot) else push_state(TAC::States::Boot) end @@ -29,6 +31,14 @@ module TAC @notification_manager.update end + def needs_redraw? + if current_state.is_a?(Editor) + current_state.needs_repaint? || @notification_manager.instance_variable_get(:@drivers).size.positive? + else + true + end + end + def toast(title, message = nil) @notification_manager.create_notification( priority: GosuNotifications::Notification::PRIORITY_HIGH,