From 2948b02f12d47d5e63eaed1632004183698b870d Mon Sep 17 00:00:00 2001 From: cyberarm Date: Wed, 29 Sep 2021 13:41:44 -0500 Subject: [PATCH] Dual screen game clock now working --- lib/game_clock/clock.rb | 4 +-- lib/game_clock/clock_proxy.rb | 2 +- lib/game_clock/remote_control.rb | 5 ++-- lib/game_clock/theme.rb | 45 +----------------------------- lib/game_clock/view.rb | 17 +++++++---- lib/pages/game_clock.rb | 12 +++++++- lib/window.rb | 7 ++++- timecrafters_configuration_tool.rb | 2 ++ 8 files changed, 36 insertions(+), 58 deletions(-) diff --git a/lib/game_clock/clock.rb b/lib/game_clock/clock.rb index 507d699..fb283ca 100644 --- a/lib/game_clock/clock.rb +++ b/lib/game_clock/clock.rb @@ -4,13 +4,13 @@ module TAC CLOCK_SIZE = Gosu.screen_height TITLE_SIZE = 128 - attr_reader :title + attr_reader :title, :controller def initialize @title = CyberarmEngine::Text.new("FIRST TECH CHALLENGE", size: TITLE_SIZE, text_shadow: true, y: 10, color: Gosu::Color::GRAY) @title.x = $window.width / 2 - @title.width / 2 - @text = CyberarmEngine::Text.new(":1234567890", size: CLOCK_SIZE, text_shadow: true, shadow_size: 2, shadow_color: Gosu::Color::GRAY) + @text = CyberarmEngine::Text.new(":1234567890", size: CLOCK_SIZE, text_border: true, border_size: 2, border_color: Gosu::Color::GRAY) @text.width # trigger font-eager loading @title.z, @text.z = -1, -1 diff --git a/lib/game_clock/clock_proxy.rb b/lib/game_clock/clock_proxy.rb index 684890f..0fd8982 100644 --- a/lib/game_clock/clock_proxy.rb +++ b/lib/game_clock/clock_proxy.rb @@ -32,7 +32,7 @@ module TAC end def abort_clock - $window.current_state&.get_sample("media/fogblast.wav")&.play if @clock.active? + @clock.controller&.play_sound(:abort_match) if @clock.active? @clock.controller = nil end diff --git a/lib/game_clock/remote_control.rb b/lib/game_clock/remote_control.rb index 39c7284..9e57f2b 100644 --- a/lib/game_clock/remote_control.rb +++ b/lib/game_clock/remote_control.rb @@ -116,10 +116,9 @@ module TAC RemoteControl.connection.puts(ClockNet::PacketHandler.packet_abort_clock) end - button "Shutdown", width: 1.0, **DANGEROUS_BUTTON do + button "Shutdown", width: 1.0, **TAC::THEME_DANGER_BUTTON do RemoteControl.connection.puts(ClockNet::PacketHandler.packet_shutdown) sleep 1 # let packet escape before closing - exit end end @@ -222,7 +221,7 @@ module TAC @randomizer_label = title "Not Visible" end - button "Randomizer", width: 1.0, **DANGEROUS_BUTTON do + button "Randomizer", width: 1.0, **TAC::THEME_DANGER_BUTTON do @randomizer_visible = !@randomizer_visible RemoteControl.connection.puts(ClockNet::PacketHandler.packet_randomizer_visible(@randomizer_visible)) diff --git a/lib/game_clock/theme.rb b/lib/game_clock/theme.rb index e436cf5..be9242a 100644 --- a/lib/game_clock/theme.rb +++ b/lib/game_clock/theme.rb @@ -1,36 +1,5 @@ module TAC class PracticeGameClock - module Palette - TACNET_CONNECTED = Gosu::Color.new(0xff_008000) - TACNET_CONNECTING = Gosu::Color.new(0xff_ff8800) - TACNET_CONNECTION_ERROR = Gosu::Color.new(0xff_800000) - TACNET_NOT_CONNECTED = Gosu::Color.new(0xff_222222) - - TIMECRAFTERS_PRIMARY = Gosu::Color.new(0xff_008000) - TIMECRAFTERS_SECONDARY = Gosu::Color.new(0xff_006000) - TIMECRAFTERS_TERTIARY = Gosu::Color.new(0xff_00d000) - - BLUE_ALLIANCE = Gosu::Color.new(0xff_000080) - RED_ALLIANCE = Gosu::Color.new(0xff_800000) - - TACNET_PRIMARY = Gosu::Color.new(0xff000080) - TACNET_SECONDARY = Gosu::Color.new(0xff000060) - - GROUPS_PRIMARY = Gosu::Color.new(0xff_444444) - GROUPS_SECONDARY = Gosu::Color.new(0xff_444444) - - ACTIONS_PRIMARY = Gosu::Color.new(0xff_4444aa) - ACTIONS_SECONDARY = Gosu::Color.new(0xff_040404) - - VARIABLES_PRIMARY = Gosu::Color.new(0xff_660066) - VARIABLES_SECONDARY = Gosu::Color.new(0xff_440044) - - EDITOR_PRIMARY = Gosu::Color.new(0xff_446688) - EDITOR_SECONDARY = Gosu::Color.new(0xff_224466) - - ALERT = TACNET_CONNECTING - end - THEME = { TextBlock: { font: "Canterell", @@ -55,19 +24,7 @@ module TAC ToggleButton: { width: 18, checkmark_image: "#{File.expand_path("..", __dir__)}/media/icons/checkmark.png", - }, - } - - DANGEROUS_BUTTON = { - background: 0xff_800000, - border_thickness: 1, - border_color: Gosu::Color.new(0xff_111111), - hover: { - background: 0xff_600000, - }, - active: { - background: 0xff_f00000, - } + } } end end diff --git a/lib/game_clock/view.rb b/lib/game_clock/view.rb index 422325e..1f478f0 100644 --- a/lib/game_clock/view.rb +++ b/lib/game_clock/view.rb @@ -11,6 +11,7 @@ module TAC @escape_counter = 0 @background_image = get_image("#{ROOT_PATH}/media/background.png") + @menu_background = 0xaa004000 @mouse = Mouse.new(window) @clock = Clock.new @clock.controller = nil @@ -26,7 +27,7 @@ module TAC @menu_container = flow width: 1.0 do stack(width: 0.35, padding: 5) do - background 0x55004159 + background @menu_background title "Match", width: 1.0, text_align: :center button "Start Match", width: 1.0, margin_bottom: 50 do @@ -54,7 +55,7 @@ module TAC @clock_proxy.abort_clock end - button "Close", width: 1.0, **DANGEROUS_BUTTON do + button "Close", width: 1.0, **TAC::THEME_DANGER_BUTTON do if window.instance_variable_get(:"@states").size == 1 window.close else @@ -67,7 +68,7 @@ module TAC end stack width: 0.4, padding_left: 50 do - background 0x55004159 + background @menu_background flow do label "♫ Now playing:" @@ -135,7 +136,7 @@ module TAC end stack width: 1.0 do - button "Randomizer", width: 1.0, **DANGEROUS_BUTTON do + button "Randomizer", width: 1.0, **TAC::THEME_DANGER_BUTTON do unless @clock.active? push_state(Randomizer) end @@ -226,8 +227,12 @@ module TAC if @escape_counter >= 3 @server&.close - window.fullscreen = false - window.pop_state + if window.instance_variable_get(:"@states").size == 1 + window.close + else + window.fullscreen = false + window.pop_state + end end else @escape_counter = 0 diff --git a/lib/pages/game_clock.rb b/lib/pages/game_clock.rb index 0df68fe..9d27ca3 100644 --- a/lib/pages/game_clock.rb +++ b/lib/pages/game_clock.rb @@ -20,7 +20,17 @@ module TAC window.fullscreen = true end - button "Dual Screen Game Clock", width: 1.0, enabled: false do + button "Dual Screen Game Clock", width: 1.0 do + # Spawn game clock window + $clock_pid = Process.spawn( + RbConfig.ruby, + "#{ROOT_PATH}/timecrafters_configuration_tool.rb", + "--game-clock-remote-display" + ) + + + # switch to remote control + push_state(PracticeGameClock::RemoteControl::NetConnect) end title "Remote", width: 1.0, text_align: :center, margin_top: 32 diff --git a/lib/window.rb b/lib/window.rb index 9b05f31..cfe48d9 100644 --- a/lib/window.rb +++ b/lib/window.rb @@ -1,6 +1,7 @@ module TAC class Window < CyberarmEngine::Window attr_reader :backend, :notification_manager + def initialize(**args) super(**args) @@ -8,7 +9,11 @@ module TAC @backend = Backend.new @notification_manager = GosuNotifications::NotificationManager.new(window: self, edge: :bottom) - push_state(TAC::States::Boot) + if ARGV.join.include?("--game-clock-remote-display") + push_state(PracticeGameClock::View, remote_control_mode: true) + else + push_state(TAC::States::Boot) + end end def draw diff --git a/timecrafters_configuration_tool.rb b/timecrafters_configuration_tool.rb index 39da3a9..6311b32 100644 --- a/timecrafters_configuration_tool.rb +++ b/timecrafters_configuration_tool.rb @@ -77,3 +77,5 @@ BORDERLESS = ARGV.include?("--borderless") if not defined?(Ocra) TAC::Window.new(width: (Gosu.screen_width * 0.8).round, height: (Gosu.screen_height * 0.8).round, resizable: true, borderless: BORDERLESS).show end + +Process.wait($clock_pid) if $clock_pid