Finally implemented GameServer#time_elapsed and #time_remaining helper methods, stubbed ApplicationSettings dialog

This commit is contained in:
2026-10-15 00:42:15 -05:00
parent a67c0cf073
commit 936b1ae5d9
8 changed files with 120 additions and 15 deletions

View File

@@ -38,8 +38,10 @@ module W3DHubLauncher
def self.join_server(app, server, password: nil, token: nil, multi: false) def self.join_server(app, server, password: nil, token: nil, multi: false)
parameters = [] parameters = []
playername = MemCache[:settings].preferences.nickname
parameters << format("+connect %s:%s", server.address, server.port) 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("+password \"%s\"", password) if password
parameters << format("+userkey \"%s\"", token) if token parameters << format("+userkey \"%s\"", token) if token
parameters << "+multi" if multi parameters << "+multi" if multi

View File

@@ -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 <c=f80>%COMMAND%</c> 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

View File

@@ -1,6 +1,6 @@
module W3DHubLauncher module W3DHubLauncher
class Dialog class Dialog
class Settings < W3DHubLauncher::Dialog class LauncherSettings < W3DHubLauncher::Dialog
def setup def setup
super 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 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 flow(width: 1.0, height: item_height, margin_top: PADDING) do
tagline "Nickname", height: 1.0, text_v_align: :center tagline "Nickname", height: 1.0, text_v_align: :center
@nickname = edit_line settings&.preferences&.nickname || Etc.getlogin, fill: true @nickname = edit_line settings&.preferences&.nickname || Etc.getlogin, fill: true
end end
inscription "Nickname to use when joining servers.", margin_left: PADDING inscription "Nickname to use when joining servers.", margin_left: PADDING

View File

@@ -220,10 +220,14 @@ module W3DHubLauncher
menu(parent: btn) do menu(parent: btn) do
menu_item("v#{application.version}", enabled: false, disabled: { color: 0xdd_ffffff }, tip: "Installed application version") menu_item("v#{application.version}", enabled: false, disabled: { color: 0xdd_ffffff }, tip: "Installed application version")
stack(width: 1.0, height: 2, background: 0xff_bbbbbb) 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") 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) 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? if @current_app.servicable?
menu_item("Repair Installation", tip: "Attempt to fix and repair installation") do 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| Worker::Api.repair_application(@current_app.id, @current_channel.id) do |result, status|

View File

@@ -120,7 +120,7 @@ module W3DHubLauncher
name_label&.value = game_server.name name_label&.value = game_server.name
name_label&.tip = 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&.value = game_server.current_map
map_label&.tip = 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) players_label&.value = format("%d / %d", game_server.player_count, game_server.max_players)
@@ -161,7 +161,7 @@ module W3DHubLauncher
# server name # server name
caption server.name, tag: :name_label, text_wrap: :none, tip: server.name caption server.name, tag: :name_label, text_wrap: :none, tip: server.name
# server info # 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
end end

View File

@@ -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| 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(parent: btn) do
menu_item("Settings") do menu_item("Settings") do
dialog(Dialog::Settings) dialog(Dialog::LauncherSettings)
end end
menu_item("About") do menu_item("About") do
dialog(Dialog::About) dialog(Dialog::About)
@@ -225,11 +225,11 @@ module W3DHubLauncher
end end
stack(width: 1.0 / 3, margin_left: HALF_PADDING) do stack(width: 1.0 / 3, margin_left: HALF_PADDING) do
caption "Time", text_wrap: :none, tip: "Time", width: 1.0 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 end
stack(width: 1.0 / 3, margin_left: HALF_PADDING) do stack(width: 1.0 / 3, margin_left: HALF_PADDING) do
caption "Time Left", text_wrap: :none, tip: "Time Left", width: 1.0 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
end end

View File

@@ -27,8 +27,8 @@ module W3DHubLauncher
@player_count = data["status"]["numplayers"] || 0 @player_count = data["status"]["numplayers"] || 0
@max_players = data["status"]["maxplayers"] @max_players = data["status"]["maxplayers"]
@match_start_time = data["status"]["started"] @match_start_time = Time.parse(data["status"]["started"])
@estimated_end_time = data["status"]["estimatedEndTime"] @estimated_end_time = data["status"]["estimatedEndTime"] ? Time.parse(data["status"]["estimatedEndTime"]) : nil
@match_remaining_time = data["status"]["remaining"] @match_remaining_time = data["status"]["remaining"]
# status teams data # status teams data
@@ -54,7 +54,25 @@ module W3DHubLauncher
# TODO: implement :) # TODO: implement :)
def time_elapsed 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 end
def password? def password?

View File

@@ -42,7 +42,8 @@ require_relative "lib/dialogs/downloads"
require_relative "lib/dialogs/server" require_relative "lib/dialogs/server"
require_relative "lib/dialogs/account" require_relative "lib/dialogs/account"
require_relative "lib/dialogs/import_application" 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/boot"
require_relative "lib/states/interface" require_relative "lib/states/interface"
require_relative "lib/window" require_relative "lib/window"