UX improvements to Server Browser

This commit is contained in:
2024-02-29 16:36:06 -06:00
parent 85d408fad7
commit a512669a2d
3 changed files with 33 additions and 30 deletions

View File

@@ -22,16 +22,16 @@ class W3DHub
def update(hash) def update(hash)
if @status if @status
@status.instance_variable_set(:@name, hash[:name]) @status.name = hash[:name]
@status.instance_variable_set(:@password, hash[:password] || false) @status.password = hash[:password] || false
@status.instance_variable_set(:@map, hash[:map]) @status.map = hash[:map]
@status.instance_variable_set(:@max_players, hash[:maxplayers]) @status.max_players = hash[:maxplayers]
@status.instance_variable_set(:@player_count, hash[:numplayers] || 0) @status.player_count = hash[:numplayers] || 0
@status.instance_variable_set(:@started, hash[:started]) @status.started = hash[:started]
@status.instance_variable_set(:@remaining, hash[:remaining]) @status.remaining = hash[:remaining]
@status.instance_variable_set(:@teams, hash[:teams]&.map { |t| Team.new(t) }) if hash[:teams] @status.teams = hash[:teams]&.map { |t| Team.new(t) } if hash[:teams]
@status.instance_variable_set(:@players, hash[:players]&.select { |t| t[:nick] != "Nod" && t[:nick] != "GDI" }&.map { |t| Player.new(t) }) if hash[:players] @status.players = hash[:players]&.select { |t| t[:nick] != "Nod" && t[:nick] != "GDI" }&.map { |t| Player.new(t) } if hash[:players]
send_ping send_ping
@@ -47,8 +47,6 @@ class W3DHub
W3DHub::BackgroundWorker.foreground_parallel_job( W3DHub::BackgroundWorker.foreground_parallel_job(
lambda do lambda do
@ping = -1
W3DHub.command("ping #{@address} #{W3DHub.windows? ? '-n 3' : '-c 3'}") do |line| W3DHub.command("ping #{@address} #{W3DHub.windows? ? '-n 3' : '-c 3'}") do |line|
if W3DHub.windows? && line =~ /Minimum|Maximum|Maximum/i if W3DHub.windows? && line =~ /Minimum|Maximum|Maximum/i
@ping = line.strip.split(",").last.split("=").last.sub("ms", "").to_i @ping = line.strip.split(",").last.split("=").last.sub("ms", "").to_i
@@ -57,6 +55,8 @@ class W3DHub
end end
end end
@ping = -1 if @ping.zero?
@ping @ping
end, end,
lambda do |_| lambda do |_|
@@ -67,7 +67,7 @@ class W3DHub
end end
class Status class Status
attr_reader :name, :password, :map, :max_players, :player_count, :started, :remaining, :teams, :players attr_accessor :name, :password, :map, :max_players, :player_count, :started, :remaining, :teams, :players
def initialize(hash) def initialize(hash)
@data = hash @data = hash
@@ -86,7 +86,7 @@ class W3DHub
end end
class Team class Team
attr_reader :id, :name, :score, :kills, :deaths attr_accessor :id, :name, :score, :kills, :deaths
def initialize(hash) def initialize(hash)
@data = hash @data = hash
@@ -100,7 +100,7 @@ class W3DHub
end end
class Player class Player
attr_reader :nick, :team, :score, :kills, :deaths attr_accessor :nick, :team, :score, :kills, :deaths
def initialize(hash) def initialize(hash)
@data = hash @data = hash

View File

@@ -203,7 +203,12 @@ class W3DHub
def run(app_id, channel, *args) def run(app_id, channel, *args)
if (app_data = installed?(app_id, channel)) if (app_data = installed?(app_id, channel))
pid = Process.spawn("#{dxvk_command(app_id, channel)}#{mangohud_command(app_id, channel)}#{wine_command(app_id, channel)}\"#{app_data[:install_path]}\" -launcher #{args.join(' ')}") install_directory = app_data[:install_directory]
exe_path = app_id == "ecw" ? "#{install_directory}/game500.exe" : "#{install_directory}/game.exe"
exe_path.gsub!("/", "\\") if W3DHub.windows?
exe_path.gsub!("\\", "/") if W3DHub.unix?
pid = Process.spawn("#{dxvk_command(app_id, channel)}#{mangohud_command(app_id, channel)}#{wine_command(app_id, channel)}\"#{exe_path}\" -launcher #{args.join(' ')}")
Process.detach(pid) Process.detach(pid)
end end
end end
@@ -317,7 +322,7 @@ class W3DHub
if (install_path = reg["InstallDir"]) if (install_path = reg["InstallDir"])
install_path.gsub!("\\", "/") install_path.gsub!("\\", "/")
exe_path = app_id == "ecw" ? "#{install_path}/game750.exe" : "#{install_path}/game.exe" exe_path = app_id == "ecw" ? "#{install_path}/game500.exe" : "#{install_path}/game.exe"
if File.exist?(exe_path) if File.exist?(exe_path)
installed_version = app_id == "ren" ? "1.0.0.0" : reg["InstalledVersion"] installed_version = app_id == "ren" ? "1.0.0.0" : reg["InstalledVersion"]
@@ -404,6 +409,8 @@ class W3DHub
# wine_prefix # optional # wine_prefix # optional
install_directory = Cache.install_path(task.application, task.channel) install_directory = Cache.install_path(task.application, task.channel)
install_directory.gsub!("\\", "/")
application_data = { application_data = {
name: task.application.name, name: task.application.name,
install_directory: install_directory, install_directory: install_directory,

View File

@@ -270,10 +270,6 @@ class W3DHub
end end
def stylize_selected_server(server_container) def stylize_selected_server(server_container)
server_container.style.server_item_background = server_container.style.default[:background]
server_container.style.server_item_hover_background = server_container.style.hover[:background]
server_container.style.server_item_active_background = server_container.style.active[:background]
server_container.style.background = @selected_color server_container.style.background = @selected_color
server_container.style.default[:background] = @selected_color server_container.style.default[:background] = @selected_color
@@ -285,10 +281,15 @@ class W3DHub
@server_list_container.children.sort_by! do |child| @server_list_container.children.sort_by! do |child|
s = Store.server_list.find { |s| s.id == child.style.tag } s = Store.server_list.find { |s| s.id == child.style.tag }
[s&.status&.player_count, s&.id] [s.status.player_count, s.id]
end.reverse!.each_with_index do |child, i| end.reverse!.each_with_index do |child, i|
child.style.background = 0xff_333333 if i.even? next if @selected_server_container && child == @selected_server_container
child.style.background = 0 if i.odd?
child.style.hover[:background] = 0xaa_555566
child.style.hover[:active] = 0xaa_555588
child.style.default[:background] = 0xaa_333333 if i.even?
child.style.default[:background] = 0x00_000000 if i.odd?
end end
@server_list_container.recalculate @server_list_container.recalculate
@@ -341,19 +342,14 @@ class W3DHub
end end
server_container.subscribe(:clicked_left_mouse_button) do server_container.subscribe(:clicked_left_mouse_button) do
if @selected_server_container
@selected_server_container.style.background = @selected_server_container.style.server_item_background
@selected_server_container.style.default[:background] = @selected_server_container.style.server_item_background
@selected_server_container.style.hover[:background] = @selected_server_container.style.server_item_hover_background
@selected_server_container.style.active[:background] = @selected_server_container.style.server_item_active_background
end
stylize_selected_server(server_container) stylize_selected_server(server_container)
@selected_server_container = server_container @selected_server_container = server_container
@selected_server = server @selected_server = server
reorder_server_list if @selected_server_container
BackgroundWorker.foreground_job( BackgroundWorker.foreground_job(
-> { fetch_server_details(server) }, -> { fetch_server_details(server) },
->(result) { populate_server_info(server) if server == @selected_server } ->(result) { populate_server_info(server) if server == @selected_server }