mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2025-12-16 09:12:35 +00:00
UX improvements to Server Browser
This commit is contained in:
@@ -22,16 +22,16 @@ class W3DHub
|
||||
|
||||
def update(hash)
|
||||
if @status
|
||||
@status.instance_variable_set(:@name, hash[:name])
|
||||
@status.instance_variable_set(:@password, hash[:password] || false)
|
||||
@status.instance_variable_set(:@map, hash[:map])
|
||||
@status.instance_variable_set(:@max_players, hash[:maxplayers])
|
||||
@status.instance_variable_set(:@player_count, hash[:numplayers] || 0)
|
||||
@status.instance_variable_set(:@started, hash[:started])
|
||||
@status.instance_variable_set(:@remaining, hash[:remaining])
|
||||
@status.name = hash[:name]
|
||||
@status.password = hash[:password] || false
|
||||
@status.map = hash[:map]
|
||||
@status.max_players = hash[:maxplayers]
|
||||
@status.player_count = hash[:numplayers] || 0
|
||||
@status.started = hash[:started]
|
||||
@status.remaining = hash[:remaining]
|
||||
|
||||
@status.instance_variable_set(:@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.teams = hash[:teams]&.map { |t| Team.new(t) } if hash[:teams]
|
||||
@status.players = hash[:players]&.select { |t| t[:nick] != "Nod" && t[:nick] != "GDI" }&.map { |t| Player.new(t) } if hash[:players]
|
||||
|
||||
send_ping
|
||||
|
||||
@@ -47,8 +47,6 @@ class W3DHub
|
||||
|
||||
W3DHub::BackgroundWorker.foreground_parallel_job(
|
||||
lambda do
|
||||
@ping = -1
|
||||
|
||||
W3DHub.command("ping #{@address} #{W3DHub.windows? ? '-n 3' : '-c 3'}") do |line|
|
||||
if W3DHub.windows? && line =~ /Minimum|Maximum|Maximum/i
|
||||
@ping = line.strip.split(",").last.split("=").last.sub("ms", "").to_i
|
||||
@@ -57,6 +55,8 @@ class W3DHub
|
||||
end
|
||||
end
|
||||
|
||||
@ping = -1 if @ping.zero?
|
||||
|
||||
@ping
|
||||
end,
|
||||
lambda do |_|
|
||||
@@ -67,7 +67,7 @@ class W3DHub
|
||||
end
|
||||
|
||||
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)
|
||||
@data = hash
|
||||
@@ -86,7 +86,7 @@ class W3DHub
|
||||
end
|
||||
|
||||
class Team
|
||||
attr_reader :id, :name, :score, :kills, :deaths
|
||||
attr_accessor :id, :name, :score, :kills, :deaths
|
||||
|
||||
def initialize(hash)
|
||||
@data = hash
|
||||
@@ -100,7 +100,7 @@ class W3DHub
|
||||
end
|
||||
|
||||
class Player
|
||||
attr_reader :nick, :team, :score, :kills, :deaths
|
||||
attr_accessor :nick, :team, :score, :kills, :deaths
|
||||
|
||||
def initialize(hash)
|
||||
@data = hash
|
||||
|
||||
@@ -203,7 +203,12 @@ class W3DHub
|
||||
|
||||
def run(app_id, channel, *args)
|
||||
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)
|
||||
end
|
||||
end
|
||||
@@ -317,7 +322,7 @@ class W3DHub
|
||||
if (install_path = reg["InstallDir"])
|
||||
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)
|
||||
installed_version = app_id == "ren" ? "1.0.0.0" : reg["InstalledVersion"]
|
||||
@@ -404,6 +409,8 @@ class W3DHub
|
||||
# wine_prefix # optional
|
||||
|
||||
install_directory = Cache.install_path(task.application, task.channel)
|
||||
install_directory.gsub!("\\", "/")
|
||||
|
||||
application_data = {
|
||||
name: task.application.name,
|
||||
install_directory: install_directory,
|
||||
|
||||
@@ -270,10 +270,6 @@ class W3DHub
|
||||
end
|
||||
|
||||
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.default[:background] = @selected_color
|
||||
@@ -285,10 +281,15 @@ class W3DHub
|
||||
@server_list_container.children.sort_by! do |child|
|
||||
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|
|
||||
child.style.background = 0xff_333333 if i.even?
|
||||
child.style.background = 0 if i.odd?
|
||||
next if @selected_server_container && child == @selected_server_container
|
||||
|
||||
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
|
||||
|
||||
@server_list_container.recalculate
|
||||
@@ -341,19 +342,14 @@ class W3DHub
|
||||
end
|
||||
|
||||
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)
|
||||
|
||||
@selected_server_container = server_container
|
||||
|
||||
@selected_server = server
|
||||
|
||||
reorder_server_list if @selected_server_container
|
||||
|
||||
BackgroundWorker.foreground_job(
|
||||
-> { fetch_server_details(server) },
|
||||
->(result) { populate_server_info(server) if server == @selected_server }
|
||||
|
||||
Reference in New Issue
Block a user