From e0e649c92234224fed9011869899a1bb07b4f25e Mon Sep 17 00:00:00 2001 From: Cyberarm Date: Wed, 24 Nov 2021 21:50:56 -0600 Subject: [PATCH] Changes, made server browser refresh button have a hard 30 second minimum refresh interval, settings are now saved! --- lib/pages/download_manager.rb | 16 ++++-- lib/pages/games.rb | 4 +- lib/pages/server_browser.rb | 9 +++- lib/pages/settings.rb | 96 ++++++++++++++++++++++++++++++----- lib/states/boot.rb | 7 ++- lib/window.rb | 6 +++ locales/en.yml | 1 + 7 files changed, 115 insertions(+), 24 deletions(-) diff --git a/lib/pages/download_manager.rb b/lib/pages/download_manager.rb index 0c06dc2..86a9cc4 100644 --- a/lib/pages/download_manager.rb +++ b/lib/pages/download_manager.rb @@ -7,7 +7,13 @@ class W3DHub @download_package_info ||= {} @task = Store.application_manager.current_task - return unless @task + unless @task + body.clear do + tagline "No operations pending.", width: 1.0, text_align: :center, margin: 128 + end + + return + end body.clear do stack(width: 1.0, height: 1.0) do @@ -16,11 +22,11 @@ class W3DHub background @task.application.color flow(width: 0.70, height: 1.0) do - image "#{GAME_ROOT_PATH}/media/icons/#{@task.app_id}.png", height: 1.0 + @application_image = image "#{GAME_ROOT_PATH}/media/icons/#{@task.app_id}.png", height: 1.0 stack(margin_left: 8) do - $bug_1 = tagline "#{@task.application.name}" - $bug_2 = inscription "Version: #{@task.channel.current_version} (#{@task.channel.id})" + @application_name_label = tagline "#{@task.application.name}" + @application_version_label = inscription "Version: #{@task.channel.current_version} (#{@task.channel.id})" end end @@ -29,7 +35,7 @@ class W3DHub flow(width: 0.30, height: 1.0) do stack(width: 0.499, height: 1.0) do para "Download Speed", width: 1.0, text_align: :center - inscription "10 MB/s", width: 1.0, text_align: :center + @download_speed_label = inscription "0 b/s", width: 1.0, text_align: :center end stack(width: 0.5, height: 1.0) do diff --git a/lib/pages/games.rb b/lib/pages/games.rb index a4fb6b4..d70dc57 100644 --- a/lib/pages/games.rb +++ b/lib/pages/games.rb @@ -70,7 +70,7 @@ class W3DHub end # Game Stuff - flow(width: 1.0, height: 0.89) do + flow(width: 1.0, height: 0.88) do # background 0xff_9999ff # Game options @@ -124,7 +124,7 @@ class W3DHub end # Play buttons - flow(width: 1.0, height: 0.08) do + flow(width: 1.0, height: 0.09, padding_top: 6) do # background 0xff_551100 if Store.application_manager.installed?(game.id, channel.id) diff --git a/lib/pages/server_browser.rb b/lib/pages/server_browser.rb index 864e482..81468d9 100644 --- a/lib/pages/server_browser.rb +++ b/lib/pages/server_browser.rb @@ -51,7 +51,7 @@ class W3DHub populate_server_list end - button get_image("#{GAME_ROOT_PATH}/media/ui_icons/return.png"), image_height: 1.0, margin_left: 16, padding_left: 2, padding_right: 2, padding_top: 2, padding_bottom: 2 do + button get_image("#{GAME_ROOT_PATH}/media/ui_icons/return.png"), tip: I18n.t(:"server_browser.refresh"), image_height: 1.0, margin_left: 16, padding_left: 2, padding_right: 2, padding_top: 2, padding_bottom: 2 do fetch_server_list end end @@ -306,13 +306,18 @@ class W3DHub end def fetch_server_list + unless Gosu.milliseconds - Store.server_list_last_fetch >= 30_000 # 30 seconds + populate_server_list # Fake it + return + end + Thread.new do begin list = Api.server_list(2) if list Store.server_list = list.sort_by! { |s| s&.status&.players&.size }.reverse - + Store.server_list_last_fetch = Gosu.milliseconds main_thread_queue << proc { populate_server_list } end diff --git a/lib/pages/settings.rb b/lib/pages/settings.rb index dd49f02..dc12aeb 100644 --- a/lib/pages/settings.rb +++ b/lib/pages/settings.rb @@ -3,42 +3,110 @@ class W3DHub class Settings < Page def setup body.clear do - stack(width: 1.0, height: 1.0, padding: 64, scroll: true) do + stack(width: 1.0, height: 1.0, padding: 16, scroll: true) do para "Language" - para "Select the UI language you'd like to use in the W3D Hub Launcher. You should restart the launcher after changing this setting before the ui will update", width: 1.0 - list_box items: ["English", "French", "German"], width: 1.0 + flow(width: 1.0) do + para "Launcher Language", width: 0.249 + stack(width: 0.75) do + @language_menu = list_box items: I18n.available_locales.map { |l| expand_language_code(l.to_s) }, choose: expand_language_code(Store.settings[:language]), width: 1.0 + inscription "Select the UI language you'd like to use in the W3D Hub Launcher. You should restart the launcher after changing this setting before the UI will update" + end + end para "Folder Paths", margin_top: 32 - stack(width: 1.0, height: 0.35) do - flow(width: 1.0, height: 0.5) do + stack(width: 1.0) do + flow(width: 1.0) do para "App Install Folder", width: 0.249 - stack(width: 0.75, height: 1.0) do - edit_line Store.settings[:app_install_dir], width: 1.0 + stack(width: 0.75) do + @app_install_dir_input = edit_line Store.settings[:app_install_dir], width: 1.0 inscription "The folder into which new games and apps will be installed by the launcher" end end - flow(width: 1.0, height: 0.5) do + flow(width: 1.0, margin_top: 16) do para "Package Cache Folder", width: 0.249 - stack(width: 0.75, height: 1.0) do - edit_line Store.settings[:package_cache_dir], width: 1.0 + stack(width: 0.75) do + @package_cache_dir_input = edit_line Store.settings[:package_cache_dir], width: 1.0 inscription "A folder which will be used to cache downloaded packages used to install games and apps" end end end - para "Diagnostics" - check_box "Enable Automatic Error Reporting", text_size: 16 - inscription "If this is enabled the launcher will automatically report errors to the development team, along with basic information about your machine, such as operating system.", width: 1.0 + if true # W3DHub.unix? + para "Wine", margin_top: 32 + flow(width: 1.0) do + para "Wine Command", width: 0.249 + stack(width: 0.75) do + @wine_command_input = edit_line Store.settings[:wine_command], width: 1.0 + inscription "Command to use to for Windows compatiblity layer" + end + end + + flow(width: 1.0, margin_top: 16) do + para "Wine Prefix", width: 0.249 + stack(width: 0.75) do + @wine_prefix_toggle = toggle_button checked: Store.settings[:wine_prefix] + inscription "Whether each game gets its own prefix. Uses global/default prefix by default." + end + end + end + + button "Save" do + old_language = Store.settings[:language] + Store.settings[:language] = language_code(@language_menu.value) + + Store.settings[:app_install_dir] = @app_install_dir_input.value + Store.settings[:package_cache_dir_input] = @package_cache_dir_input.value + + Store.settings[:wine_command] = @wine_command_input.value + Store.settings[:wine_prefix] = @wine_prefix_toggle.value - button "Save", margin_top: 32 do Store.settings.save_settings + + begin + I18n.locale = Store.settings[:language] + rescue I18n::InvalidLocale + I18n.locale = :en + end + + if old_language == Store.settings[:language] + page(Pages::Games) + else + # pop back to Boot state which will immediately push a new instance of Interface + pop_state + end end end end end + + def language_code(string) + case string.downcase.strip + when "german" + "de" + when "french" + "fr" + when "spanish" + "es" + else + "en" + end + end + + def expand_language_code(string) + case string.downcase.strip + when "en" + "English" + when "de" + "German" + when "fr" + "French" + else + raise "Unknown language error" + end + end end end end diff --git a/lib/states/boot.rb b/lib/states/boot.rb index efe5868..5a6187f 100644 --- a/lib/states/boot.rb +++ b/lib/states/boot.rb @@ -120,7 +120,12 @@ class W3DHub begin list = Api.server_list(2) - Store.server_list = list.sort_by! { |s| s&.status&.players&.size }.reverse if list + if list + Store.server_list = list.sort_by! { |s| s&.status&.players&.size }.reverse + end + + Store.server_list_last_fetch = Gosu.milliseconds + @tasks[:server_list][:complete] = true rescue => e # Something went wrong! diff --git a/lib/window.rb b/lib/window.rb index b8431c1..f2f6dc1 100644 --- a/lib/window.rb +++ b/lib/window.rb @@ -9,6 +9,12 @@ class W3DHub Store.settings.save_settings + begin + I18n.locale = Store.settings[:language] + rescue I18n::InvalidLocale + I18n.locale = :en + end + push_state(W3DHub::States::Boot) end diff --git a/locales/en.yml b/locales/en.yml index 0ae11c0..30fdbe8 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -27,6 +27,7 @@ en: fetching_news: Fetching news... channel: Channel server_browser: + refresh: Refresh join_server: Join Server game: Game map: Map