From e344a492e005ec74ae844325ec36d849bccba537 Mon Sep 17 00:00:00 2001 From: Cyberarm Date: Thu, 15 Oct 2026 11:34:17 -0500 Subject: [PATCH] JOIN button now pulls up a dialog with the auto selected game server to confirm player wants to join that server; TODO: If only one server exists then join that one directly, if multiple exist the offer the 'best' three or something, don't crash if we somehow get a server update without the server list being nil --- lib/application_helper.rb | 4 ++-- lib/dialogs/server.rb | 34 ++++++++++++++++++++-------------- lib/pages/games.rb | 34 ++++++++++++++++++---------------- lib/window.rb | 2 ++ 4 files changed, 42 insertions(+), 32 deletions(-) diff --git a/lib/application_helper.rb b/lib/application_helper.rb index 5ede12f..4ce40b6 100644 --- a/lib/application_helper.rb +++ b/lib/application_helper.rb @@ -57,12 +57,12 @@ module W3DHubLauncher channel = MemCache[:applications].find { |appl| appl.id == app.id }&.channels&.find { |c| c.id == app.channel } return nil unless channel - server_options = MemCache[:servers].select do |server| + server_options = (MemCache[:servers]&.select do |server| server.game == app.id && server.channel == channel.server_channel && !server.password? && server.player_count < server.max_players - end.sort_by do |s| + end || []).sort_by do |s| [s.player_count, -s.ping] end.reverse diff --git a/lib/dialogs/server.rb b/lib/dialogs/server.rb index 7892967..60da834 100644 --- a/lib/dialogs/server.rb +++ b/lib/dialogs/server.rb @@ -4,32 +4,38 @@ module W3DHubLauncher def setup super + application = @options[:application] + server = @options[:server] + stack(width: 1.0, max_width: 600, height: 1.0, max_height: 600, style_class: [:dialog]) do flow(width: 1.0, background_nine_slice: NINE_SLICE_ROUNDED_TOP, background_nine_slice_from_edge: NINE_SLICE_EDGE, background_nine_slice_color: 0) do - banner "Downloads", width: 1.0, text_align: :center + banner "Join Server", width: 1.0, text_align: :center + title server.name, width: 1.0, text_align: :center end stack(style_class: [:dialog_container]) do - 50.times do - stack(width: 1.0, margin_top: HALF_PADDING, margin_bottom: HALF_PADDING) do - flow(width: 1.0) do - para "PACKAGE_NAME.mix" - flow(fill: true) - para ["Downloading...", "Pending...", "Done.", "Patching...", "Unpacking..."].sample - end - progress(width: 1.0, fraction: rand) - end - end + caption "Ping: #{server.ping}ms" + caption "Region: #{server.region}" + caption "Players: #{server.player_count} / #{server.max_players}", margin_bottom: HALF_PADDING + + caption "Current Map: #{server.current_map}" + caption "Next Map: #{server.next_map}", margin_bottom: HALF_PADDING + + caption "Time Elapsed: #{server.time_elapsed}" + caption "Time Remaining: #{server.time_remaining}" end flow(width: 1.0, padding: PADDING, background_nine_slice: NINE_SLICE_ROUNDED_BOTTOM, background_nine_slice_from_edge: NINE_SLICE_EDGE, background_nine_slice_color: 0) do - flow(fill: true) - - button "Close", **CTA_BUTTON_THEME do + button "Cancel" do pop_state end flow(fill: true) + + button "Join", **CTA_BUTTON_THEME do + pop_state + ApplicationHelper.join_server(application, server) + end end end end diff --git a/lib/pages/games.rb b/lib/pages/games.rb index ea98def..fd3d17d 100644 --- a/lib/pages/games.rb +++ b/lib/pages/games.rb @@ -194,28 +194,30 @@ module W3DHubLauncher flow(width: 1.0, height: 60) do if application - if @current_channel.update_available?(application.version) - button "Update", tip: "Update application from v#{application.version} to v#{@current_channel.version}", fill: true, height: 1.0, background_nine_slice: NINE_SLICE_ROUNDED_LEFT, **UPDATE_BUTTON_THEME do |btn| - btn.enabled = false + if @current_channel.update_available?(application.version) + button "Update", tip: "Update application from v#{application.version} to v#{@current_channel.version}", fill: true, height: 1.0, background_nine_slice: NINE_SLICE_ROUNDED_LEFT, **UPDATE_BUTTON_THEME do |btn| + btn.enabled = false - Worker::Api.update_application(@current_app.id, @current_channel.id) do |result, status| - handle_task_update(result, status) - end - end - else - button "JOIN", tip: "Join most populated or lowest ping server", fill: true, height: 1.0, background_nine_slice: NINE_SLICE_ROUNDED_LEFT, **CTA_BUTTON_THEME do |btn| - server = ApplicationHelper.play_now_server(application) - - if server - ApplicationHelper.join_server(application, server) - else - puts "No server available." - end + Worker::Api.update_application(@current_app.id, @current_channel.id) do |result, status| + handle_task_update(result, status) end end + else + button "JOIN", tip: "Join most populated or lowest ping server", fill: true, height: 1.0, background_nine_slice: NINE_SLICE_ROUNDED_LEFT, **CTA_BUTTON_THEME do |btn| + server = ApplicationHelper.play_now_server(application) + + if server + dialog(Dialog::Server, application: application, server: server) + else + puts "No server available." + end + end + end + button safe_get_image("#{ROOT_PATH}/media/icons/singleplayer.png"), tip: "Single player", image_height: 1.0, background_nine_slice: NINE_SLICE_SQUARE, **CTA_BUTTON_THEME do ApplicationHelper.run(application) end + button safe_get_image("#{ROOT_PATH}/media/icons/gear.png"), tip: "Options", image_height: 1.0, background_nine_slice: NINE_SLICE_ROUNDED_RIGHT, **CTA_BUTTON_THEME do |btn| menu(parent: btn) do menu_item("v#{application.version}", enabled: false, disabled: { color: 0xdd_ffffff }, tip: "Installed application version") diff --git a/lib/window.rb b/lib/window.rb index 0ee0d43..5beb1f1 100644 --- a/lib/window.rb +++ b/lib/window.rb @@ -21,6 +21,7 @@ module W3DHubLauncher if existing_game_server MemCache[:servers][MemCache[:servers].index(existing_game_server)] = game_server else + MemCache[:servers] ||= [] MemCache[:servers] << game_server end end @@ -32,6 +33,7 @@ module W3DHubLauncher if existing_game_server MemCache[:servers][MemCache[:servers].index(existing_game_server)] = game_server else + MemCache[:servers] ||= [] MemCache[:servers] << game_server end end