Added .rubocop.yml config, filters for Server Browser now functional, game select button on Games page now overrides the hover color if its selected

This commit is contained in:
2021-11-18 14:25:37 -06:00
parent 662e5c2b0c
commit ea1a7e8b13
4 changed files with 93 additions and 67 deletions

8
.rubocop.yml Normal file
View File

@@ -0,0 +1,8 @@
Style/StringLiterals:
EnforcedStyle: double_quotes
Metrics/MethodLength:
Max: 40
Style/EmptyMethod:
EnforcedStyle: expanded

View File

@@ -2,7 +2,7 @@ class W3DHub
class Pages
class Games < Page
def setup
@@game_news ||= {}
@game_news ||= {}
@focused_game ||= window.applications.games.first
body.clear do
@@ -15,7 +15,7 @@ class W3DHub
end
end
populate_game_page(window.applications.games.first, window.applications.games.first.channels.first)
populate_game_page(@focused_game, @focused_game.channels.first)
populate_games_list
end
@@ -27,7 +27,8 @@ class W3DHub
selected = game == @focused_game
game_button = stack(width: 1.0, border_thickness_left: 4,
border_color_left: selected ? 0xff_00acff : 0x00_000000, hover: { background: 0xff_444444 },
border_color_left: selected ? 0xff_00acff : 0x00_000000,
hover: { background: selected ? game.color : 0xff_444444 },
padding_top: 4, padding_bottom: 4) do
background game.color if selected
@@ -61,10 +62,10 @@ class W3DHub
# background 0xff_444411
inscription "Channel"
list_box(items: game.channels.map { |c| c.name }, choose: channel.name, enabled: game.channels.count > 1,
margin_top: 0, margin_bottom: 0,
width: 128, padding_left: 1, padding_top: 1, padding_right: 1, padding_bottom: 1, text_size: 14) do |value|
populate_game_page(game, game.channels.find{ |c| c.name == value })
list_box(items: game.channels.map(&:name), choose: channel.name, enabled: game.channels.count > 1,
margin_top: 0, margin_bottom: 0, width: 128,
padding_left: 1, padding_top: 1, padding_right: 1, padding_bottom: 1, text_size: 14) do |value|
populate_game_page(game, game.channels.find { |c| c.name == value })
end
end
@@ -148,7 +149,9 @@ class W3DHub
end
end
unless @@game_news[game.id]
if @game_news[game.id]
populate_game_news(game)
else
Thread.new do
fetch_game_news(game)
main_thread_queue << proc { populate_game_news(game) }
@@ -157,8 +160,6 @@ class W3DHub
@game_news_container.clear do
title "Fetching News...", padding: 8
end
else
populate_game_news(game)
end
end
@@ -170,14 +171,14 @@ class W3DHub
Cache.fetch(item.image)
end
@@game_news[game.id] = news
@game_news[game.id] = news
end
end
def populate_game_news(game)
return unless @focused_game == game
if (feed = @@game_news[game.id])
if (feed = @game_news[game.id])
@game_news_container.clear do
feed.items.sort_by { |i| i.timestamp }.reverse[0..9].each do |item|
flow(width: 0.5, height: 128, margin: 4) do

View File

@@ -2,7 +2,13 @@ class W3DHub
class Pages
class ServerBrowser < Page
def setup
@@server_list ||= []
@server_list ||= []
@selected_server ||= nil
@selected_color = 0xff_666655
@filters = {}
@filter_region = "Any" # "Any", "North America", "Europe"
window.applications.games.each { |game| @filters[game.id] = true }
body.clear do
stack(width: 1.0, height: 1.0, padding: 8) do
@@ -12,49 +18,32 @@ class W3DHub
flow(width: 1.0, height: 0.06) do
flow(width: 0.75, height: 1.0) do
image "#{GAME_ROOT_PATH}/media/icons/ren.png", height: 1.0 do |img|
if img.style.color == 0xff_444444
img.style.color = 0xff_ffffff
img.style.default[:color] = 0xff_ffffff
else
img.style.color = 0xff_444444
img.style.default[:color] = 0xff_444444
@filters.each do |app_id, enabled|
app = window.applications.games.find { |a| a.id == app_id }
image "#{GAME_ROOT_PATH}/media/icons/#{app_id}.png", tip: "#{app.name}", height: 1.0,
border_thickness_bottom: 1, border_color_bottom: 0x00_000000,
color: enabled ? 0xff_ffffff : 0xff_444444, hover: { border_color_bottom: 0xff_aaaaaa }, margin_right: 32 do |img|
@filters[app_id] = !@filters[app_id]
if @filters[app_id]
img.style.color = 0xff_ffffff
img.style.default[:color] = 0xff_ffffff
else
img.style.color = 0xff_444444
img.style.default[:color] = 0xff_444444
end
populate_server_list
end
end
image "#{GAME_ROOT_PATH}/media/icons/ecw.png", height: 1.0, margin_left: 32 do |img|
if img.style.color == 0xff_444444
img.style.color = 0xff_ffffff
img.style.default[:color] = 0xff_ffffff
else
img.style.color = 0xff_444444
img.style.default[:color] = 0xff_444444
end end
image "#{GAME_ROOT_PATH}/media/icons/ia.png", height: 1.0, margin_left: 32 do |img|
if img.style.color == 0xff_444444
img.style.color = 0xff_ffffff
img.style.default[:color] = 0xff_ffffff
else
img.style.color = 0xff_444444
img.style.default[:color] = 0xff_444444
end end
image "#{GAME_ROOT_PATH}/media/icons/apb.png", height: 1.0, margin_left: 32 do |img|
if img.style.color == 0xff_444444
img.style.color = 0xff_ffffff
img.style.default[:color] = 0xff_ffffff
else
img.style.color = 0xff_444444
img.style.default[:color] = 0xff_444444
end end
image "#{GAME_ROOT_PATH}/media/icons/tsr.png", height: 1.0, margin_left: 32, margin_right: 32 do |img|
if img.style.color == 0xff_444444
img.style.color = 0xff_ffffff
img.style.default[:color] = 0xff_ffffff
else
img.style.color = 0xff_444444
img.style.default[:color] = 0xff_444444
end end
para "Region"
list_box items: ["Any", "North America", "Europe"], width: 0.25
list_box items: ["Any", "North America", "Europe"], width: 0.25 do |value|
@filter_region = value
populate_server_list
end
end
flow(width: 0.249, height: 1.0) do
@@ -108,8 +97,17 @@ class W3DHub
end
def populate_server_list
@server_list_container.scroll_top = 0
@server_list_container.clear do
@@server_list.each_with_index do |server, i|
i = -1
@server_list.each do |server|
next unless @filters[server.game]
next unless server.region == @filter_region || @filter_region == "Any"
i += 1
server_container = flow(width: 1.0, height: 48, hover: { background: 0xff_555566 }, active: { background: 0xff_555588 }) do
background 0xff_333333 if i.odd?
@@ -132,14 +130,16 @@ class W3DHub
inscription "#{server&.status&.player_count}/#{server&.status&.max_players}"
end
case rand(0..478)
when 0..60
image "#{GAME_ROOT_PATH}/media/ui_icons/signal3.png", width: 0.05, color: 0xff_008000
when 61..160
image "#{GAME_ROOT_PATH}/media/ui_icons/signal2.png", width: 0.05, color: 0xff_804000
else
image "#{GAME_ROOT_PATH}/media/ui_icons/signal1.png", width: 0.05, color: 0xff_800000
end
# case rand(0..478)
# when 0..60
# image "#{GAME_ROOT_PATH}/media/ui_icons/signal3.png", width: 0.05, color: 0xff_008000
# when 61..160
# image "#{GAME_ROOT_PATH}/media/ui_icons/signal2.png", width: 0.05, color: 0xff_804000
# else
# image "#{GAME_ROOT_PATH}/media/ui_icons/signal1.png", width: 0.05, color: 0xff_800000
# end
image "#{GAME_ROOT_PATH}/media/ui_icons/question.png", width: 0.05, color: 0xff_444444
end
def server_container.hit_element?(x, y)
@@ -147,6 +147,23 @@ class W3DHub
end
server_container.subscribe(:clicked_left_mouse_button) do
if @selected_server
@selected_server.style.background = @selected_server.style.server_item_background
@selected_server.style.default[:background] = @selected_server.style.server_item_background
@selected_server.style.hover[:background] = @selected_server.style.server_item_hover_background
@selected_server.style.active[:background] = @selected_server.style.server_item_active_background
end
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
server_container.style.hover[:background] = @selected_color
server_container.style.active[:background] = @selected_color
@selected_server = server_container
populate_server_info(server)
end
end
@@ -196,7 +213,7 @@ class W3DHub
flow(width: 1.0, height: 0.65, scroll: true) do
stack(width: 0.5) do
server.status.players.select { |ply| ply.team == 0 }.each do |player|
server.status.players.select { |ply| ply.team == 0 }.sort_by { |ply| ply.score }.reverse.each do |player|
flow(width: 1.0, height: 18) do
stack(width: 0.6, height: 1.0) do
inscription player.nick, text_size: 14, text_wrap: :none
@@ -210,7 +227,7 @@ class W3DHub
end
stack(width: 0.5, border_thickness_left: 2, border_color_left: 0xff_000000) do
server.status.players.select { |ply| ply.team == 1 }.each do |player|
server.status.players.select { |ply| ply.team == 1 }.sort_by { |ply| ply.score }.reverse.each do |player|
flow(width: 1.0, height: 18) do
stack(width: 0.6, height: 1.0) do
inscription player.nick, text_size: 14, text_wrap: :none
@@ -233,7 +250,7 @@ class W3DHub
list = Api.server_list(2)
if list
@@server_list = list.sort_by! { |s| s&.status&.players.size }.reverse
@server_list = list.sort_by! { |s| s&.status&.players.size }.reverse
main_thread_queue << proc { populate_server_list }
@@ -241,7 +258,7 @@ class W3DHub
rescue => e
# Something went wrong!
pp e
@@server_list = []
@server_list = []
end
end
end

View File

@@ -22,7 +22,7 @@ class W3DHub
flow(width: 1.0, height: 0.05, padding_left: 16, padding_right: 16, padding_bottom: 8, padding_top: 8) do
@status_label = caption "Starting #{NAME}...", width: 0.5
inscription "W3D Hub Launcher #{W3DHub::VERSION}", width: 0.5, text_align: :right
inscription "#{NAME} #{W3DHub::VERSION}", width: 0.5, text_align: :right
end
end
end