From d36211cb5ecbee6319015cddc8fd271d542601da Mon Sep 17 00:00:00 2001 From: Cyberarm Date: Wed, 9 Dec 2020 09:18:52 -0600 Subject: [PATCH] New tacnet interface functional --- lib/page.rb | 16 +++++++--- lib/pages/tacnet.rb | 68 ++++++++++++++++++++++++++++++++++------ lib/states/new_editor.rb | 6 ++-- lib/tacnet.rb | 2 +- lib/theme.rb | 2 +- 5 files changed, 76 insertions(+), 18 deletions(-) diff --git a/lib/page.rb b/lib/page.rb index eefc765..a2c2f7d 100644 --- a/lib/page.rb +++ b/lib/page.rb @@ -5,12 +5,18 @@ module TAC attr_reader :menu_bar, :status_bar, :body - def initialize(host:, header_bar_label:, menu_bar:, status_bar:, body:) + def initialize(host:) @host = host - @header_bar_label = header_bar_label - @menu_bar = menu_bar - @status_bar = status_bar - @body = body + @header_bar_label = host.header_bar_label + @menu_bar = host.menu_bar + @status_bar = host.status_bar + @body = host.body + + @options = {} + end + + def options=(options) + @options = options end def page(klass) diff --git a/lib/pages/tacnet.rb b/lib/pages/tacnet.rb index 34853fe..9398334 100644 --- a/lib/pages/tacnet.rb +++ b/lib/pages/tacnet.rb @@ -5,20 +5,70 @@ module TAC header_bar("TimeCrafters Auxiliary Configuration Network") menu_bar.clear do - label "Hostname" - hostname = edit_line "192.168.49.1", width: 0.33, height: 1.0 - label "Port" - port = edit_line "192.168.49.1", width: 0.33, height: 1.0 - button "Connect", height: 1.0 do - status_bar.clear do - label "Connecting to #{hostname.value}:#{port.value}" + @connect_menu = flow(width: 1.0, height: 1.0) do + label "Hostname", text_size: 28 + hostname = edit_line window.backend.settings.hostname, width: 0.33, height: 1.0, text_size: 28 + label "Port", text_size: 28 + port = edit_line window.backend.settings.port, width: 0.33, height: 1.0, text_size: 28 + button "Connect", height: 1.0, text_size: 28 do + if hostname.value != window.backend.settings.hostname || port.value.to_i != window.backend.settings.port + window.backend.settings_changed! + end + + window.backend.settings.hostname = hostname.value + window.backend.settings.port = port.value.to_i + + window.backend.tacnet.connect(hostname.value, port.value.to_i) + end + end + + @disconnect_menu = flow(width: 1.0, height: 1.0) do + button "Disconnect", height: 1.0, text_size: 28 do + window.backend.tacnet.close end end end status_bar.clear do - image "#{TAC::ROOT_PATH}/media/icons/signal3.png", height: 1.0 - label "TACNET: Connected Pkt Sent: 00314 Pkt Received: 00313", text_size: 26 + @tacnet_icon = image "#{TAC::ROOT_PATH}/media/icons/signal3.png", height: 26 + @status_label = label "TACNET: Not Connected", text_size: 26 + end + + body.clear do + @full_status_label = label "" + end + end + + def update + case window.backend.tacnet.status + when :connected + sent = "#{window.backend.tacnet.client.packets_sent}".rjust(4, '0') + received = "#{window.backend.tacnet.client.packets_received}".rjust(4, '0') + @status_label.value = "TACNET: Connected Pkt Sent: #{sent} Pkt Received: #{received}" + @full_status_label.value = window.backend.tacnet.full_status + @tacnet_icon.style.color = TAC::Palette::TACNET_CONNECTED + @connect_menu.hide + @disconnect_menu.show + + when :connecting + @status_label.value = "TACNET: Connecting..." + @tacnet_icon.style.color = TAC::Palette::TACNET_CONNECTING + @connect_menu.hide + @disconnect_menu.show + + when :connection_error + @status_label.value = "TACNET: Connection Error" + @full_status_label.value = window.backend.tacnet.full_status + @tacnet_icon.style.color = TAC::Palette::TACNET_CONNECTION_ERROR + @connect_menu.show + @disconnect_menu.hide + + when :not_connected + @status_label.value = "TACNET: Not Connected" + @full_status_label.value = "" + @tacnet_icon.style.color = 0xff_ffffff + @connect_menu.show + @disconnect_menu.hide end end end diff --git a/lib/states/new_editor.rb b/lib/states/new_editor.rb index b64529a..d884b09 100644 --- a/lib/states/new_editor.rb +++ b/lib/states/new_editor.rb @@ -1,5 +1,6 @@ class NewEditor < CyberarmEngine::GuiState include CyberarmEngine::Theme # get access to deep_merge method + attr_reader :header_bar, :header_bar_label, :navigation, :content, :menu_bar, :status_bar, :body def setup @window_width = 0 @@ -129,7 +130,7 @@ class NewEditor < CyberarmEngine::GuiState request_recalculate end - def page(klass) + def page(klass, options = {}) @menu_bar.clear @status_bar.clear @body.clear @@ -146,9 +147,10 @@ class NewEditor < CyberarmEngine::GuiState @page.blur if @page - @pages[klass] = klass.new(host: self, header_bar_label: @header_bar_label, menu_bar: @menu_bar, status_bar: @status_bar, body: @body) unless @pages[klass] + @pages[klass] = klass.new(host: self) unless @pages[klass] @page = @pages[klass] + @page.options = options @page.setup @page.focus end diff --git a/lib/tacnet.rb b/lib/tacnet.rb index 5560d75..3775ef8 100644 --- a/lib/tacnet.rb +++ b/lib/tacnet.rb @@ -60,7 +60,7 @@ module TAC end def client - @connection.client if connected? + @connection.client end def puts(packet) diff --git a/lib/theme.rb b/lib/theme.rb index 418a8e7..40cfc60 100644 --- a/lib/theme.rb +++ b/lib/theme.rb @@ -17,7 +17,7 @@ module TAC } }, EditLine: { - caret_color: Gosu::Color.new(0xff_434343), + caret_color: Gosu::Color.new(0xff_88ef90), }, ToggleButton: { width: 18,