diff --git a/lib/application_helper.rb b/lib/application_helper.rb index c996db2..5ede12f 100644 --- a/lib/application_helper.rb +++ b/lib/application_helper.rb @@ -38,8 +38,10 @@ module W3DHubLauncher def self.join_server(app, server, password: nil, token: nil, multi: false) parameters = [] + playername = MemCache[:settings].preferences.nickname + parameters << format("+connect %s:%s", server.address, server.port) - parameters << format("+netplayername \"%s\"", "cyberarm") + parameters << format("+netplayername \"%s\"", playername) parameters << format("+password \"%s\"", password) if password parameters << format("+userkey \"%s\"", token) if token parameters << "+multi" if multi diff --git a/lib/dialogs/application_settings.rb b/lib/dialogs/application_settings.rb new file mode 100644 index 0000000..c61fe0b --- /dev/null +++ b/lib/dialogs/application_settings.rb @@ -0,0 +1,80 @@ +module W3DHubLauncher + class Dialog + class ApplicationSettings < W3DHubLauncher::Dialog + def setup + super + + # settings application + @application = @options[:application] + # mannifest application + @app = @options[:app] + + @channel = @app.channels.find { |c| c.id == @application.channel } + + stack(width: 0.75, max_width: 1280, height: 0.75, max_height: 600, style_class: [:dialog]) do + flow(width: 1.0, background_nine_slice: NINE_SLICE_ROUNDED_TOP, background_nine_slice_from_edge: NINE_SLICE_EDGE, background_nine_slice_color: 0) do + banner "Application Settings", width: 1.0, text_align: :center + title "#{@app.name} (#{@channel.name})", width: 1.0, text_align: :center + end + + item_height = 40 + PADDING + + stack(width: 1.0, fill: true, scroll: true, margin_left: PADDING, margin_right: PADDING, padding: HALF_PADDING, background_nine_slice: NINE_SLICE_ROUNDED, background_nine_slice_from_edge: NINE_SLICE_EDGE, background_nine_slice_color: ALPHA_BLACK) do + flow(width: 1.0, height: item_height, margin_top: HALF_PADDING) do + tagline "Wine prefix path", height: 1.0, text_v_align: :center + @wine_prefix_path = edit_line @application.wine_prefix_path, fill: true + button "Browse..." + end + inscription "Location of wine prefix to use. Leave blank to use default.", margin_left: PADDING + + flow(width: 1.0, height: item_height, margin_top: PADDING) do + tagline "Launch Command", height: 1.0, text_v_align: :center + @launch_command = edit_line @application.launch_command, fill: true + end + inscription "Command arguments to use when launching application. Use %COMMAND% for default.", margin_left: PADDING + end + + flow(width: 1.0, padding: PADDING, background_nine_slice: NINE_SLICE_ROUNDED_BOTTOM, background_nine_slice_from_edge: NINE_SLICE_EDGE, background_nine_slice_color: 0) do + button "Close" do + pop_state + end + + flow(fill: true) + + button "Save", **CTA_BUTTON_THEME do |btn| + btn.enabled = false + + settings = MemCache[:settings] + + # TODO: Save the things! + # update user preferences + # settings.preferences.nickname = @nickname.value.strip + # settings.preferences.launcher_package_cache_directory = @launcher_package_cache_directory.value.strip + # settings.preferences.application_installation_directory = @application_installation_directory.value.strip + # settings.preferences.wine_prefix_path = @wine_prefix_path.value.strip + # settings.preferences.wine_command = @wine_command.value.strip + # settings.preferences.winetricks_command = @winetricks_command.value.strip + # + # Worker::Api.update_settings(settings) do |result| + # if result.okay? + # on_main_thread(proc { + # MemCache[:settings] = settings + # pop_state + # }) + # else + # # FIXME: Somehow something went wrong... show an error message. + # btn.enabled = true + # end + # end + end + end + end + end + + # FIXME: Check settings for validity before saving + def valid? + true + end + end + end +end diff --git a/lib/dialogs/settings.rb b/lib/dialogs/launcher_settings.rb similarity index 95% rename from lib/dialogs/settings.rb rename to lib/dialogs/launcher_settings.rb index 90874d1..aab7bb8 100644 --- a/lib/dialogs/settings.rb +++ b/lib/dialogs/launcher_settings.rb @@ -1,6 +1,6 @@ module W3DHubLauncher class Dialog - class Settings < W3DHubLauncher::Dialog + class LauncherSettings < W3DHubLauncher::Dialog def setup super @@ -14,8 +14,8 @@ module W3DHubLauncher stack(width: 1.0, fill: true, scroll: true, margin_left: PADDING, margin_right: PADDING, padding: HALF_PADDING, background_nine_slice: NINE_SLICE_ROUNDED, background_nine_slice_from_edge: NINE_SLICE_EDGE, background_nine_slice_color: ALPHA_BLACK) do flow(width: 1.0, height: item_height, margin_top: PADDING) do - tagline "Nickname", height: 1.0, text_v_align: :center - @nickname = edit_line settings&.preferences&.nickname || Etc.getlogin, fill: true + tagline "Nickname", height: 1.0, text_v_align: :center + @nickname = edit_line settings&.preferences&.nickname || Etc.getlogin, fill: true end inscription "Nickname to use when joining servers.", margin_left: PADDING diff --git a/lib/pages/games.rb b/lib/pages/games.rb index 8da77f0..ea98def 100644 --- a/lib/pages/games.rb +++ b/lib/pages/games.rb @@ -220,10 +220,14 @@ module W3DHubLauncher menu(parent: btn) do menu_item("v#{application.version}", enabled: false, disabled: { color: 0xdd_ffffff }, tip: "Installed application version") stack(width: 1.0, height: 2, background: 0xff_bbbbbb) - menu_item("Installation Folder", tip: "Open application installation folder:\n#{application.installation_path}") + menu_item("Installation Folder", tip: "Open application installation folder:\n#{application.installation_path}") do + SDL.OpenURL("file://#{application.installation_path}") + end menu_item("Screenshots Folder", tip: "Open application installation folder:\n#{Dir.home}/Documents/W3D Hub/#{application.id}-#{application.channel}/Screenshots") stack(width: 1.0, height: 2, background: 0xff_bbbbbb) - menu_item("Application Settings", tip: "Edit application launch options") + menu_item("Application Settings", tip: "Edit application launch options") do + dialog(Dialog::ApplicationSettings, application: application, app: @current_app) + end if @current_app.servicable? menu_item("Repair Installation", tip: "Attempt to fix and repair installation") do Worker::Api.repair_application(@current_app.id, @current_channel.id) do |result, status| diff --git a/lib/pages/server_browser.rb b/lib/pages/server_browser.rb index fe5fc7f..f826f68 100644 --- a/lib/pages/server_browser.rb +++ b/lib/pages/server_browser.rb @@ -120,7 +120,7 @@ module W3DHubLauncher name_label&.value = game_server.name name_label&.tip = game_server.name - info_label&.value = "#{game_server.channel} • #{game_server.region} • #{game_server.time_elapsed} / #{game_server.match_remaining_time}" + info_label&.value = "#{game_server.channel} • #{game_server.region} • #{game_server.time_elapsed} / #{game_server.time_remaining}" map_label&.value = game_server.current_map map_label&.tip = game_server.current_map players_label&.value = format("%d / %d", game_server.player_count, game_server.max_players) @@ -161,7 +161,7 @@ module W3DHubLauncher # server name caption server.name, tag: :name_label, text_wrap: :none, tip: server.name # server info - inscription "#{server.channel} • #{server.region} • #{server.time_elapsed} / #{server.match_remaining_time}", tag: :info_label, text_wrap: :none, margin_top: -HALF_PADDING + inscription "#{server.channel} • #{server.region} • #{server.time_elapsed} / #{server.time_remaining}", tag: :info_label, text_wrap: :none, margin_top: -HALF_PADDING end end diff --git a/lib/states/interface.rb b/lib/states/interface.rb index ac047ee..dec7b85 100644 --- a/lib/states/interface.rb +++ b/lib/states/interface.rb @@ -18,7 +18,7 @@ module W3DHubLauncher button(safe_get_image("#{ROOT_PATH}/media/logo.png"), image_height: 1.0, background: 0, border_color: 0, hover: { background: 0 }, active: { background: 0, color: 0xff_ffffff }) do |btn| menu(parent: btn) do menu_item("Settings") do - dialog(Dialog::Settings) + dialog(Dialog::LauncherSettings) end menu_item("About") do dialog(Dialog::About) @@ -225,11 +225,11 @@ module W3DHubLauncher end stack(width: 1.0 / 3, margin_left: HALF_PADDING) do caption "Time", text_wrap: :none, tip: "Time", width: 1.0 - inscription "00:00:00", text_wrap: :none, width: 1.0, tip: "00:00:00" + inscription server.time_elapsed, text_wrap: :none, width: 1.0, tip: server.time_elapsed end stack(width: 1.0 / 3, margin_left: HALF_PADDING) do caption "Time Left", text_wrap: :none, tip: "Time Left", width: 1.0 - inscription server.match_remaining_time, text_wrap: :none, width: 1.0, tip: server.match_remaining_time + inscription server.time_remaining, text_wrap: :none, width: 1.0, tip: server.time_remaining end end diff --git a/lib/worker/api/game_server.rb b/lib/worker/api/game_server.rb index 7694cb8..675846a 100644 --- a/lib/worker/api/game_server.rb +++ b/lib/worker/api/game_server.rb @@ -27,8 +27,8 @@ module W3DHubLauncher @player_count = data["status"]["numplayers"] || 0 @max_players = data["status"]["maxplayers"] - @match_start_time = data["status"]["started"] - @estimated_end_time = data["status"]["estimatedEndTime"] + @match_start_time = Time.parse(data["status"]["started"]) + @estimated_end_time = data["status"]["estimatedEndTime"] ? Time.parse(data["status"]["estimatedEndTime"]) : nil @match_remaining_time = data["status"]["remaining"] # status teams data @@ -54,7 +54,25 @@ module W3DHubLauncher # TODO: implement :) def time_elapsed - "00:00" + elapsed_seconds = Time.now.utc.to_i - @match_start_time.utc.to_i + + hours = (elapsed_seconds / 60.0 / 60.0).floor % 100 + minutes = (elapsed_seconds / 60.0).floor % 60 + seconds = (elapsed_seconds).floor % 60 + + format("%02d:%02d:%02d", hours, minutes, seconds) + end + + def time_remaining + return "∞" unless @estimated_end_time + + remaining_seconds = @estimated_end_time.utc.to_i - Time.now.utc.to_i + + hours = (remaining_seconds / 60.0 / 60.0).floor % 100 + minutes = (remaining_seconds / 60.0).floor % 60 + seconds = (remaining_seconds).floor % 60 + + format("%02d:%02d:%02d", hours, minutes, seconds) end def password? diff --git a/w3d_hub_linux_launcher.rb b/w3d_hub_linux_launcher.rb index dc6cdbe..17b2f65 100644 --- a/w3d_hub_linux_launcher.rb +++ b/w3d_hub_linux_launcher.rb @@ -42,7 +42,8 @@ require_relative "lib/dialogs/downloads" require_relative "lib/dialogs/server" require_relative "lib/dialogs/account" require_relative "lib/dialogs/import_application" -require_relative "lib/dialogs/settings" +require_relative "lib/dialogs/launcher_settings" +require_relative "lib/dialogs/application_settings" require_relative "lib/states/boot" require_relative "lib/states/interface" require_relative "lib/window"