4 Commits

7 changed files with 80 additions and 57 deletions

View File

@@ -76,7 +76,7 @@ class W3DHub
end end
def save_config(config = @config) def save_config(config = @config)
File.write(CONFIG_PATH, config.to_json) File.write(CONFIG_PATH, JSON.pretty_generate(config))
end end
end end
end end

View File

@@ -95,8 +95,8 @@ class W3DHub
# para game.name, width: 1.0, text_align: :center # para game.name, width: 1.0, text_align: :center
end end
def game_button.hit_element?(x, y) def game_button.hit_element?(x, y, elements = [])
self if hit?(x, y) elements << self if hit?(x, y)
end end
game_button.subscribe(:clicked_left_mouse_button) do game_button.subscribe(:clicked_left_mouse_button) do
@@ -123,7 +123,6 @@ class W3DHub
background_image_path = Cache.package_path(game.category, game.id, "background.png", "") background_image_path = Cache.package_path(game.category, game.id, "background.png", "")
if File.exist?(background_image_path) if File.exist?(background_image_path)
States::Interface.instance&.instance_variable_get(:"@interface_container")&.style&.background_image = get_image(background_image_path) States::Interface.instance&.instance_variable_get(:"@interface_container")&.style&.background_image = get_image(background_image_path)
States::Interface.instance&.instance_variable_get(:"@interface_container")&.style&.default[:background_image] = get_image(background_image_path)
end end
# Game Stuff # Game Stuff
@@ -387,10 +386,8 @@ class W3DHub
caption game.name, margin_top: 8 caption game.name, margin_top: 8
end end
def container.hit_element?(x, y) def container.hit_element?(x, y, elements = [])
return unless hit?(x, y) elements << self if hit?(x, y)
self
end end
container.subscribe(:clicked_left_mouse_button) do |element| container.subscribe(:clicked_left_mouse_button) do |element|

View File

@@ -54,10 +54,8 @@ class W3DHub
if @filters[app_id] if @filters[app_id]
img.style.color = 0xff_ffffff img.style.color = 0xff_ffffff
img.style.default[:color] = 0xff_ffffff
else else
img.style.color = 0xff_444444 img.style.color = 0xff_444444
img.style.default[:color] = 0xff_444444
end end
populate_server_list populate_server_list
@@ -271,9 +269,8 @@ class W3DHub
def stylize_selected_server(server_container) def stylize_selected_server(server_container)
server_container.style.background = @selected_color server_container.style.background = @selected_color
server_container.style.default[:background] = @selected_color server_container.style.hover.background = @selected_color
server_container.style.hover[:background] = @selected_color server_container.style.active.background = @selected_color
server_container.style.active[:background] = @selected_color
end end
def reorder_server_list def reorder_server_list
@@ -284,11 +281,11 @@ class W3DHub
end.reverse!.each_with_index do |child, i| end.reverse!.each_with_index do |child, i|
next if @selected_server_container && child == @selected_server_container next if @selected_server_container && child == @selected_server_container
child.style.hover[:background] = 0xaa_555566 child.style.hover.background = 0xaa_555566
child.style.hover[:active] = 0xaa_555588 child.style.active.background = 0xaa_555588
child.style.default[:background] = 0xaa_333333 if i.even? child.style.background = 0xaa_333333 if i.even?
child.style.default[:background] = 0x00_000000 if i.odd? child.style.background = 0x00_000000 if i.odd?
end end
@server_list_container.recalculate @server_list_container.recalculate
@@ -340,8 +337,8 @@ class W3DHub
end end
end end
def server_container.hit_element?(x, y) def server_container.hit_element?(x, y, elements = [])
self if hit?(x, y) elements << self if hit?(x, y)
end end
server_container.subscribe(:clicked_left_mouse_button) do server_container.subscribe(:clicked_left_mouse_button) do

View File

@@ -78,7 +78,7 @@ class W3DHub
end end
def save_settings def save_settings
File.write(SETTINGS_FILE_PATH, @settings.to_json) File.write(SETTINGS_FILE_PATH, JSON.pretty_generate(@settings))
end end
def save_application_cache(json) def save_application_cache(json)

View File

@@ -230,7 +230,7 @@ class W3DHub
Api.on_thread(:_applications) do |applications| Api.on_thread(:_applications) do |applications|
if applications if applications
Store.applications = applications Store.applications = applications
Store.settings.save_application_cache(applications.data.to_json) Store.settings.save_application_cache(JSON.pretty_generate(applications.data))
@tasks[:applications][:complete] = true @tasks[:applications][:complete] = true
else else
# FIXME: Failed to retreive! # FIXME: Failed to retreive!

View File

@@ -45,7 +45,6 @@ class W3DHub
c = W3DHub::THEME[:Button][:border_color] c = W3DHub::THEME[:Button][:border_color]
@prompt_entry.style.border_color = c @prompt_entry.style.border_color = c
@prompt_entry.style.default[:border_color] = c
@prompt_entry.style.hover[:border_color] = c @prompt_entry.style.hover[:border_color] = c
@prompt_entry.style.active[:border_color] = c @prompt_entry.style.active[:border_color] = c
@@ -54,7 +53,6 @@ class W3DHub
c = 0xff_ff0000 c = 0xff_ff0000
@prompt_entry.style.border_color = c @prompt_entry.style.border_color = c
@prompt_entry.style.default[:border_color] = c
@prompt_entry.style.hover[:border_color] = c @prompt_entry.style.hover[:border_color] = c
@prompt_entry.style.active[:border_color] = c @prompt_entry.style.active[:border_color] = c

View File

@@ -23,6 +23,7 @@ class W3DHub
@service_status = @options[:service_status] @service_status = @options[:service_status]
@applications = @options[:applications] @applications = @options[:applications]
@account_expire = Gosu.milliseconds
@applications_expire = Gosu.milliseconds + APPLICATIONS_UPDATE_INTERVAL # ten minutes @applications_expire = Gosu.milliseconds + APPLICATIONS_UPDATE_INTERVAL # ten minutes
@server_list_expire = Gosu.milliseconds + SERVER_LIST_UPDATE_INTERVAL # 5 minutes @server_list_expire = Gosu.milliseconds + SERVER_LIST_UPDATE_INTERVAL # 5 minutes
@@ -59,25 +60,21 @@ class W3DHub
link I18n.t(:"interface.servers").upcase, text_size: 34, font: BOLD_FONT, margin_left: 12 do link I18n.t(:"interface.servers").upcase, text_size: 34, font: BOLD_FONT, margin_left: 12 do
@interface_container.style.background_image = DEFAULT_BACKGROUND_IMAGE @interface_container.style.background_image = DEFAULT_BACKGROUND_IMAGE
@interface_container.style.default[:background_image] = DEFAULT_BACKGROUND_IMAGE
page(W3DHub::Pages::ServerBrowser) page(W3DHub::Pages::ServerBrowser)
end end
link I18n.t(:"interface.community").upcase, text_size: 34, font: BOLD_FONT, margin_left: 12 do link I18n.t(:"interface.community").upcase, text_size: 34, font: BOLD_FONT, margin_left: 12 do
@interface_container.style.background_image = DEFAULT_BACKGROUND_IMAGE @interface_container.style.background_image = DEFAULT_BACKGROUND_IMAGE
@interface_container.style.default[:background_image] = DEFAULT_BACKGROUND_IMAGE
page(W3DHub::Pages::Community) page(W3DHub::Pages::Community)
end end
link I18n.t(:"interface.downloads").upcase, text_size: 34, font: BOLD_FONT, margin_left: 12 do link I18n.t(:"interface.downloads").upcase, text_size: 34, font: BOLD_FONT, margin_left: 12 do
@interface_container.style.background_image = DEFAULT_BACKGROUND_IMAGE @interface_container.style.background_image = DEFAULT_BACKGROUND_IMAGE
@interface_container.style.default[:background_image] = DEFAULT_BACKGROUND_IMAGE
page(W3DHub::Pages::DownloadManager) page(W3DHub::Pages::DownloadManager)
end end
link I18n.t(:"interface.settings").upcase, text_size: 34, font: BOLD_FONT, margin_left: 12 do link I18n.t(:"interface.settings").upcase, text_size: 34, font: BOLD_FONT, margin_left: 12 do
@interface_container.style.background_image = DEFAULT_BACKGROUND_IMAGE @interface_container.style.background_image = DEFAULT_BACKGROUND_IMAGE
@interface_container.style.default[:background_image] = DEFAULT_BACKGROUND_IMAGE
page(W3DHub::Pages::Settings) page(W3DHub::Pages::Settings)
end end
end end
@@ -132,6 +129,13 @@ class W3DHub
end end
hide_application_taskbar hide_application_taskbar
every(3_000) do
# NOTE: each method called, internally checks whether it should act.
refresh_account_token
refresh_applications
refresh_server_list
end
end end
def draw def draw
@@ -146,36 +150,6 @@ class W3DHub
@page&.update @page&.update
update_interface_task_status(@interface_task_update_pending) if @interface_task_update_pending update_interface_task_status(@interface_task_update_pending) if @interface_task_update_pending
if Gosu.milliseconds >= @applications_expire
@applications_expire = Gosu.milliseconds + 30_000
Api.on_thread(:_applications) do |applications|
if applications
@applications_expire = Gosu.milliseconds + APPLICATIONS_UPDATE_INTERVAL # ten minutes
Store.applications = applications
# TODO: Signal Games and ServerBrowser that applications have been updated
end
end
end
if Gosu.milliseconds >= @server_list_expire
@server_list_expire = Gosu.milliseconds + 30_000
Api.on_thread(:server_list, 2) do |list|
if list
@server_list_expire = Gosu.milliseconds + SERVER_LIST_UPDATE_INTERVAL # five minutes
Store.server_list_last_fetch = Gosu.milliseconds
Api::ServerListUpdater.instance.refresh_server_list(list)
BackgroundWorker.foreground_job(-> {}, ->(_) { States::Interface.instance&.update_server_browser(nil, :refresh_all) })
end
end
end
end end
def button_down(id) def button_down(id)
@@ -274,6 +248,63 @@ class W3DHub
end end
end end
end end
def refresh_account_token
return if Gosu.milliseconds < @account_expire
return unless account = Store.account
@account_expire = Gosu.milliseconds + 30_000
if (account.access_token_expiry - Time.now) / 60 <= 60 * 3 # Refresh if token expires within 3 hours
logger.info(LOG_TAG) { "Refreshing user login..." }
Api.on_thread(:refresh_user_login, account.refresh_token) do |refreshed_account|
if refreshed_account
Store.account = refreshed_account
Store.settings[:account][:data] = refreshed_account
else
Store.settings[:account] = {}
end
Store.settings.save_settings
end
end
end
def refresh_applications
return if Gosu.milliseconds < @applications_expire
@applications_expire = Gosu.milliseconds + 30_000
Api.on_thread(:_applications) do |applications|
if applications
@applications_expire = Gosu.milliseconds + APPLICATIONS_UPDATE_INTERVAL # ten minutes
Store.applications = applications
# TODO: Signal Games and ServerBrowser that applications have been updated
end
end
end
def refresh_server_list
return if Gosu.milliseconds < @server_list_expire
@server_list_expire = Gosu.milliseconds + 30_000
Api.on_thread(:server_list, 2) do |list|
if list
@server_list_expire = Gosu.milliseconds + SERVER_LIST_UPDATE_INTERVAL # five minutes
Store.server_list_last_fetch = Gosu.milliseconds
Api::ServerListUpdater.instance.refresh_server_list(list)
BackgroundWorker.foreground_job(-> {}, ->(_) { States::Interface.instance&.update_server_browser(nil, :refresh_all) })
end
end
end
end end
end end
end end