Can now join a server and launch installed games (Play Now does nothing special yet)

This commit is contained in:
2021-11-19 15:48:13 -06:00
parent ec81959947
commit 89f7f4ab6a
9 changed files with 141 additions and 40 deletions

View File

@@ -83,6 +83,17 @@ class W3DHub
end end
end end
def join_server(app_id, channel, server, password = nil)
if installed?(app_id, channel) && window.settings[:server_list_username].to_s.length.positive?
run(
app_id, channel,
"+connect #{server.address}:#{server.port}",
"+netplayername \"#{window.settings[:server_list_username]}\"",
password ? "+password \"#{password}\"" : ""
)
end
end
def installed!(task) def installed!(task)
# install_dir # install_dir
# installed_version # installed_version

View File

@@ -1,7 +1,7 @@
class W3DHub class W3DHub
class ApplicationManager class ApplicationManager
class Importer < Task class Importer < Task
def initialize(app_id, channel, path) def initialize(app_id, channel, path = nil)
super(app_id, channel) super(app_id, channel)
@path = path @path = path

View File

@@ -5,54 +5,40 @@ class W3DHub
body.clear do body.clear do
stack(width: 1.0, height: 1.0, padding: 8) do stack(width: 1.0, height: 1.0, padding: 8) do
stack(width: 1.0, height: 0.15) do stack(width: 1.0, height: 0.15) do
tagline "<b>Welcome to the W3D Hub Launcher</b>" tagline "<b>Welcome to the #{W3DHub::NAME}</b>"
para "The W3D Hub launcher is a one-stop shop for your W3D gamings needs, providing game downloads and automatic updating, an intregrated server browser, centralized management of in-game options and many other features." para "The #{W3DHub::NAME} is a one-stop shop for your W3D gaming needs, providing game downloads, automatic updating, an integrated server browser, and centralized management of in-game options."
end end
flow(width: 1.0, height: 0.1, margin_top: 24) do flow(width: 1.0, height: 0.15, margin_bottom: 24) do
flow(width: 0.375, height: 1.0) do flow(width: (1.0 - 0.27) / 2, height: 1.0) do
end end
flow(width: 0.25, height: 1.0) do flow(width: 0.27, height: 1.0) do
image "#{GAME_ROOT_PATH}/media/icons/apb.png", height: 1.0 image "#{GAME_ROOT_PATH}/media/icons/w3dhub.png", height: 1.0, hover: { color: 0xaa_ffffff }, tip: "W3D Hub Forums" do
image "#{GAME_ROOT_PATH}/media/icons/ren.png", height: 1.0, margin_left: 32 Launchy.open("https://w3dhub.com/forum/")
image "#{GAME_ROOT_PATH}/media/icons/tsr.png", height: 1.0, margin_left: 32 end
image "#{GAME_ROOT_PATH}/media/icons/w3dhub.png", height: 1.0, margin_left: 32 image "#{GAME_ROOT_PATH}/media/social_media_icons/discord.png", hover: { color: 0xaa_ffffff }, height: 1.0, margin_left: 32, tip: "W3D Hub Discord Server" do
Launchy.open("https://discord.com/invite/GYhW7eV")
end
image "#{GAME_ROOT_PATH}/media/social_media_icons/facebook.png", hover: { color: 0xaa_ffffff }, height: 1.0, margin_left: 32, tip: "W3D Hub Facebook Page" do
Launchy.open("https://www.facebook.com/w3dhub")
end end
flow(width: 0.375, height: 1.0) do
end end
end end
stack(width: 1.0, height: 0.6, scroll: true) do stack(width: 1.0, height: 0.55, scroll: true) do
tagline "<b>Latest Updates</b>" tagline "<b>Latest Updates</b>"
para "<b>Beta 12</b>", margin_left: 16 para "Hello World " * 100
para "- Server Browser: Added detailed information for selection server", margin_left: 32
para "<b>Beta 11.6</b>", margin_left: 16, margin_top: 16
para "- Localisation: Added Korean translations (unknown author)", margin_left: 32
para "- Localisation: Added Spanish translations (thanks to Silverlight and URKA)", margin_left: 32
para "- Localisation: Added Spanish translations (thanks to darkyuri-cz)", margin_left: 32
para "<b>Beta 11.0</b>", margin_left: 16, margin_top: 16
para "- Localisation: Added partial Chinese (Simplified) translations and Polish (thanks to DoDoCat and TrollekPL on the W3D Hub forums for providing translations)", margin_left: 32
para "- Performance: Reduced CPU and GPU usage during game installs and updates", margin_left: 32
para "- Settings: Added new setting menu for the launcher - click on the [gear] icon in the titlebar. Incluudes:", margin_left: 32
para "- Manually choose language, rather than using default based on OS", margin_left: 48
para "- Choose package cache folder location", margin_left: 48
para "- Choose default folder into which games are installed", margin_left: 48
para "- Server Browser: Now receives push notifications so it shows changes to maps, player counts, etc. as soon as they are available", margin_left: 32
para "- Server Browser: Now lists servers with players in above empty ones", margin_left: 32
para "- Server Browser: Game filter options are now saved", margin_left: 32
end end
stack(width: 1.0, height: 0.15) do stack(width: 1.0, height: 0.15, margin_top: 16) do
tagline "<b>Help & Support</b>" tagline "<b>Help & Support</b>"
flow(width: 1.0) do flow(width: 1.0) do
para "For help and support using this launcher or playing any W3D Hub game visit the" para "For help and support using this launcher or playing any W3D Hub game visit the"
link("W3D Hub forums", text_size: 16) { Launchy.open("https://w3dhub.com/forum/") } link("W3D Hub forums", text_size: 16) { Launchy.open("https://w3dhub.com/forum/") }
para "or join us in" para "or join us in"
link("[discord]#tech-support", text_size: 16) { Launchy.open("https://w3dhub.com/forum/") } image "#{GAME_ROOT_PATH}/media/social_media_icons/discord.png", height: 16, padding_top: 4
link("#tech-support", text_size: 16) { Launchy.open("https://discord.com/invite/GYhW7eV") }
para "on the W3D Hub Discord server" para "on the W3D Hub Discord server"
end end
end end

View File

@@ -47,9 +47,18 @@ class W3DHub
end end
flow(width: 0.249, height: 1.0) do flow(width: 0.249, height: 1.0) do
inscription "Nickname:" inscription "Nickname:", width: 0.32
inscription "Cyberarm" @nickname_label = inscription "#{window.settings[:server_list_username]}", width: 0.6
image "#{GAME_ROOT_PATH}/media/ui_icons/wrench.png", height: 16 image "#{GAME_ROOT_PATH}/media/ui_icons/wrench.png", height: 16, hover: { color: 0xaa_ffffff }, tip: "Set nickname" do
# Prompt for player name
prompt_for_nickname(
accept_callback: proc do |entry|
@nickname_label.value = entry
window.settings[:server_list_username] = entry
window.settings.save_settings
end
)
end
end end
end end
@@ -180,7 +189,33 @@ class W3DHub
end end
stack(width: 1.0, height: 0.25) do stack(width: 1.0, height: 0.25) do
button "<b>Join Server</b>", enabled: window.application_manager.installed?(server.game, window.applications.games.find { |g| g.id == server.game }.channels.first) game_installed = window.application_manager.installed?(server.game, window.applications.games.find { |g| g.id == server.game }.channels.first.id)
button "<b>Join Server</b>", enabled: !game_installed.nil? do
# Check for nickname
# prompt for nickname
# !abort unless nickname set
# Launch game
if window.settings[:server_list_username].to_s.length.zero?
prompt_for_nickname(
accept_callback: proc do |entry|
@nickname_label.value = entry
window.settings[:server_list_username] = entry
window.settings.save_settings
window.application_manager.join_server(
server.game,
window.applications.games.find { |g| g.id == server.game }.channels.first.id, server
)
end
)
else
window.application_manager.join_server(
server.game,
window.applications.games.find { |g| g.id == server.game }.channels.first.id, server
)
end
end
end end
stack(width: 1.0, height: 0.55, margin_top: 16) do stack(width: 1.0, height: 0.55, margin_top: 16) do
@@ -281,6 +316,18 @@ class W3DHub
"C&C Renegade" "C&C Renegade"
end end
end end
def prompt_for_nickname(accept_callback: nil, cancel_callback: nil)
push_state(
W3DHub::States::PromptDialog,
title: "Set Nickname",
message: "Set a nickname that will be used when joining a server:",
prefill: window.settings[:server_list_username],
accept_callback: accept_callback,
cancel_callback: cancel_callback,
valid_callback: proc { |entry| entry.length.positive? }
)
end
end end
end end
end end

View File

@@ -8,7 +8,7 @@ class W3DHub
wine_command: "wine", wine_command: "wine",
create_wine_prefixes: true, create_wine_prefixes: true,
allow_diagnostic_reports: false, allow_diagnostic_reports: false,
server_list_username: nil, server_list_username: "",
account: {}, account: {},
applications: {}, applications: {},
games: {} games: {}
@@ -53,6 +53,10 @@ class W3DHub
@settings.dig(*args) @settings.dig(*args)
end end
def []=(key, value)
@settings[key] = value
end
def load_settings def load_settings
@settings = JSON.parse(File.read(SETTINGS_FILE_PATH), symbolize_names: true) @settings = JSON.parse(File.read(SETTINGS_FILE_PATH), symbolize_names: true)
end end

View File

@@ -0,0 +1,52 @@
class W3DHub
class States
class PromptDialog < CyberarmEngine::GuiState
def setup
window.show_cursor = true
theme(W3DHub::THEME)
background 0xee_444444
stack(width: 1.0, height: 1.0, margin: 128, background: 0xee_222222) do
flow(width: 1.0, height: 0.1, padding: 8) do
background 0x88_000000
image "#{GAME_ROOT_PATH}/media/ui_icons/question.png", width: 0.04, align: :center, color: 0xff_ff8800
tagline "<b>#{@options[:title]}</b>", width: 0.9, text_align: :center
end
stack(width: 1.0, height: 0.78, padding: 16) do
para @options[:message], width: 1.0
@prompt_entry = edit_line @options[:prefill].to_s, margin_top: 24, width: 1.0, focus: true
end
flow(width: 1.0, height: 0.1, padding: 8) do
button "Cancel", width: 0.25 do
pop_state
@options[:cancel_callback]&.call(@prompt_entry.value)
end
stack(width: 0.5)
button "Accept", width: 0.25 do
if @options[:valid_callback]&.call(@prompt_entry.value)
pop_state
@options[:accept_callback]&.call(@prompt_entry.value)
end
end
end
end
end
def draw
previous_state&.draw
Gosu.flush
super
end
end
end
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@@ -38,6 +38,7 @@ require_relative "lib/application_manager/tasks/importer"
require_relative "lib/states/boot" require_relative "lib/states/boot"
require_relative "lib/states/interface" require_relative "lib/states/interface"
require_relative "lib/states/message_dialog" require_relative "lib/states/message_dialog"
require_relative "lib/states/prompt_dialog"
require_relative "lib/api" require_relative "lib/api"
require_relative "lib/api/service_status" require_relative "lib/api/service_status"