WIP: Adding IRC support to Direct Connect system, using new v/h_align option for centering dialogs

This commit is contained in:
2022-06-13 21:43:13 -05:00
parent 7e59c984ff
commit 3ca8ab656f
11 changed files with 172 additions and 139 deletions

View File

@@ -10,6 +10,7 @@ gem "async", "~>1.30.1"
gem "async-http" gem "async-http"
gem "async-websocket" gem "async-websocket"
gem "thread-local" gem "thread-local"
gem "ircparser"
# group :windows_packaging do # group :windows_packaging do
# gem "rake" # gem "rake"

View File

@@ -1,27 +1,40 @@
class W3DHub class W3DHub
class Asterisk class Asterisk
class IRCProfile class IRCProfile
attr_accessor :name, :nickname, :password, :server_hostname, :server_port, :server_bot attr_accessor :name,
:username, :nickname, :password,
:server_hostname, :server_port, :server_ssl, :server_verify_ssl,
:bot_username, :bot_auth_username, :bot_auth_password
def initialize(hash = nil) def initialize(hash = nil)
return unless hash return unless hash
@name = hash[:name] @name = hash[:name]
@username = hash[:username] || hash[:nickname]
@nickname = hash[:nickname] @nickname = hash[:nickname]
@password = hash[:password] @password = hash[:password]
@server_hostname = hash[:server_hostname] @server_hostname = hash[:server_hostname]
@server_port = hash[:server_port] @server_port = hash[:server_port]
@server_bot = hash[:server_bot] @server_ssl = hash[:server_ssl]
@server_verify_ssl = hash[:server_verify_ssl]
@bot_username = hash[:bot_username]
@bot_auth_username = hash[:bot_auth_username]
@bot_auth_password = hash[:bot_auth_password]
end end
def to_json(options) def to_json(options)
{ {
name: @name, name: @name,
username: @username,
nickname: @nickname, nickname: @nickname,
password: @password, password: @password,
server_hostname: @server_hostname, server_hostname: @server_hostname,
server_port: @server_port, server_port: @server_port,
server_bot: @server_bot server_ssl: @server_ssl,
server_verify_ssl: @server_verify_ssl,
bot_username: @bot_username,
bot_auth_username: @bot_auth_username,
bot_auth_password: @bot_auth_password
}.to_json(options) }.to_json(options)
end end
end end

View File

@@ -7,9 +7,9 @@ class W3DHub
theme W3DHub::THEME theme W3DHub::THEME
background 0xee_444444 background 0xaa_444444
stack(width: 1.0, height: 1.0, margin: 256, background: 0xee_222222) do stack(width: 1.0, max_width: 760, height: 1.0, max_height: 256, v_align: :center, h_align: :center, background: 0xff_222222) do
# Title bar # Title bar
flow(width: 1.0, height: 32, padding: 8) do flow(width: 1.0, height: 32, padding: 8) do
background 0x88_000000 background 0x88_000000
@@ -74,10 +74,6 @@ class W3DHub
@save_button.enabled = valid? @save_button.enabled = valid?
end end
def close
pop_state
end
def button_down(id) def button_down(id)
super super

View File

@@ -7,21 +7,33 @@ class W3DHub
theme W3DHub::THEME theme W3DHub::THEME
background 0xcc_000000 background 0xaa_444444
stack(width: 1.0, height: 248, margin: 48, padding: 16) do stack(width: 1.0, max_width: 760, height: 1.0, max_height: 560, v_align: :center, h_align: :center, background: 0xff_222222) do
caption @game ? "Update IRC Profile" : "Add IRC Profile", width: 1.0, text_align: :center # Title bar
flow(width: 1.0, height: 32, padding: 8) do
background 0x88_000000
# tagline "<b>#{I18n.t(:"server_browser.direct_connect")}</b>", fill: true, text_align: :center
tagline @profile ? "Update IRC Profile" : "Add IRC Profile", width: 1.0, text_align: :center
end
stack(width: 1.0, fill: true, padding_left: 8, padding_right: 8) do
stack(width: 1.0, height: 60) do stack(width: 1.0, height: 60) do
flow(width: 1.0, height: 1.0) do
stack(width: 0.6, height: 1.0) do
para "IRC Nickname:" para "IRC Nickname:"
@irc_nickname = edit_line "#{@profile&.nickname}", width: 1.0 @irc_nickname = edit_line "#{@profile&.nickname}", width: 1.0
end end
stack(width: 0.4, height: 1.0) do stack(width: 1.0, height: 60) do
para "IRC Password:" flow(width: 1.0, height: 1.0) do
@irc_password = edit_line "#{@profile ? Base64.strict_decode64(@profile.password) : ''}", width: 1.0#, type: :password stack(width: 0.5, height: 1.0) do
para "IRC Username:"
@irc_username = edit_line "#{@profile&.username}", width: 1.0
end
stack(width: 0.5, height: 1.0) do
para "IRC Server Password:"
@irc_password = edit_line @profile ? Base64.strict_decode64(@profile.password) : "", width: 1.0, type: :password
end end
end end
end end
@@ -34,23 +46,52 @@ class W3DHub
end end
stack(width: 0.249, height: 1.0) do stack(width: 0.249, height: 1.0) do
para "IRC Port:" para "IRC Server Port:"
@irc_port = edit_line "#{@profile&.server_port || '6667'}", width: 1.0 @irc_port = edit_line "#{@profile&.server_port || '6667'}", width: 1.0
end end
end end
end end
stack(width: 1.0, height: 60) do flow(width: 1.0, height: 60, margin_top: 8) do
para "IRC Bot Name:" flow(width: 0.5, height: 60) do
para "IRC Server Use SSL:", margin_top: 8
@irc_bot = check_box "#{@profile&.server_bot}"
end
flow(width: 0.5, height: 60) do
para "IRC Verify Server SSL Certificate:", margin_top: 8
@irc_bot = check_box "#{@profile&.server_bot}"
end
end
stack(width: 1.0, height: 60, margin_top: 32) do
para "Brenbot Bot Name:"
@irc_bot = edit_line "#{@profile&.server_bot}", width: 1.0 @irc_bot = edit_line "#{@profile&.server_bot}", width: 1.0
end end
flow(width: 1.0, margin_top: 8) do flow(width: 1.0, height: 60) do
button "Cancel", width: 0.5, margin_right: 4 do stack(width: 0.5, height: 60) do
para "Brenbot Auth Username:"
@irc_bot = edit_line "#{@profile&.server_bot}", width: 1.0
end
stack(width: 0.5, height: 60) do
para "Brenbot Auth Password:"
@irc_password = edit_line @profile ? Base64.strict_decode64(@profile.password) : "", width: 1.0, type: :password
end
end
flow(fill: true)
flow(width: 1.0, margin_top: 8, height: 40, padding_bottom: 8) do
button "Cancel", fill: true, margin_right: 4 do
pop_state pop_state
end end
@save_button = button "Save", width: 0.5, margin_left: 4, enabled: false do flow(fill: true)
@save_button = button "Save", fill: true, margin_left: 4, enabled: false do
pop_state pop_state
@options[:save_callback].call( @options[:save_callback].call(
@profile, @profile,
@@ -64,14 +105,15 @@ class W3DHub
end end
end end
end end
end
# def draw def draw
# previous_state&.draw previous_state&.draw
# Gosu.flush Gosu.flush
# super super
# end end
def update def update
super super
@@ -79,10 +121,6 @@ class W3DHub
@save_button.enabled = valid? @save_button.enabled = valid?
end end
def close
pop_state
end
def button_down(id) def button_down(id)
super super

View File

@@ -7,9 +7,9 @@ class W3DHub
theme W3DHub::THEME theme W3DHub::THEME
background 0xee_444444 background 0xaa_444444
stack(width: 1.0, height: 1.0, margin: 256, background: 0xee_222222) do stack(width: 1.0, max_width: 760, height: 1.0, max_height: 256, v_align: :center, h_align: :center, background: 0xff_222222) do
# Title bar # Title bar
flow(width: 1.0, height: 32, padding: 8) do flow(width: 1.0, height: 32, padding: 8) do
background 0x88_000000 background 0x88_000000
@@ -58,10 +58,6 @@ class W3DHub
super super
end end
def close
pop_state
end
def button_down(id) def button_down(id)
super super

View File

@@ -65,7 +65,7 @@ class W3DHub
flow(fill: true) flow(fill: true)
button "Direct Connect", height: 1.0, padding_top: 4, padding_bottom: 4, enabled: false, tip: "Directly connect to a game server (under development)" do button "Direct Connect", height: 1.0, padding_top: 4, padding_bottom: 4, enabled: W3DHUB_DEBUG && W3DHUB_DEVELOPER, tip: "Directly connect to a game server (under development)" do
push_state(W3DHub::States::DirectConnectDialog) push_state(W3DHub::States::DirectConnectDialog)
end end
end end

View File

@@ -8,7 +8,7 @@ class W3DHub
background 0xee_444444 background 0xee_444444
stack(width: 1.0, height: 1.0, margin: 128, background: 0xee_222222) do stack(width: 1.0, max_width: 720, height: 1.0, max_height: 480, v_align: :center, h_align: :center, background: 0xee_222222) do
flow(width: 1.0, height: 0.1, padding: 8) do flow(width: 1.0, height: 0.1, padding: 8) do
background 0x88_000000 background 0x88_000000

View File

@@ -9,7 +9,7 @@ class W3DHub
background 0xee_444444 background 0xee_444444
stack(width: 1.0, height: 1.0, margin: 128, background: 0xee_222222) do stack(width: 1.0, max_width: 720, height: 1.0, max_height: 512, v_align: :center, h_align: :center, background: 0xee_222222) do
# Title bar # Title bar
flow(width: 1.0, height: 32, padding: 8) do flow(width: 1.0, height: 32, padding: 8) do
background 0x88_000000 background 0x88_000000
@@ -138,22 +138,22 @@ class W3DHub
para "IRC Profile:" para "IRC Profile:"
flow(width: 1.0, fill: true) do flow(width: 1.0, fill: true) do
@irc_profiles_list = list_box items: ["None"], fill: true, height: 1.0, enabled: false @irc_profiles_list = list_box items: W3DHub::Store[:asterisk_config].irc_profiles.map {| pf| pf.name }.insert(0, "None"), fill: true, height: 1.0
@irc_profiles_list.subscribe(:changed) do |list| @irc_profiles_list.subscribe(:changed) do |list|
@changes_made = true if @server_profiles_list.value.length.positive? @changes_made = true if @server_profiles_list.value.length.positive?
valid_for_multiplayer? valid_for_multiplayer?
end end
button get_image("#{GAME_ROOT_PATH}/media/ui_icons/plus.png"), image_height: 1.0, tip: "Add IRC profile", enabled: false do button get_image("#{GAME_ROOT_PATH}/media/ui_icons/plus.png"), image_height: 1.0, tip: "Add IRC profile" do
push_state(Asterisk::States::IRCProfileForm, save_callback: method(:save_irc_profile)) push_state(Asterisk::States::IRCProfileForm, save_callback: method(:save_irc_profile))
end end
@irc_delete_button = button get_image("#{GAME_ROOT_PATH}/media/ui_icons/minus.png"), image_height: 1.0, tip: "Remove selected IRC profile", enabled: false do @irc_delete_button = button get_image("#{GAME_ROOT_PATH}/media/ui_icons/minus.png"), image_height: 1.0, tip: "Remove selected IRC profile" do
push_state(ConfirmDialog, message: "") push_state(ConfirmDialog, message: "")
end end
@irc_edit_button = button get_image("#{GAME_ROOT_PATH}/media/ui_icons/gear.png"), image_height: 1.0, tip: "Edit selected IRC profile", enabled: false do @irc_edit_button = button get_image("#{GAME_ROOT_PATH}/media/ui_icons/gear.png"), image_height: 1.0, tip: "Edit selected IRC profile" do
push_state(Asterisk::States::IRCProfileForm, editing: W3DHub::Store[:asterisk_config].irc_profiles.find { |pf| pf.name == @irc_profiles_list.value }, save_callback: method(:save_irc_profile)) push_state(Asterisk::States::IRCProfileForm, editing: W3DHub::Store[:asterisk_config].irc_profiles.find { |pf| pf.name == @irc_profiles_list.value }, save_callback: method(:save_irc_profile))
end end
end end
@@ -206,11 +206,9 @@ class W3DHub
end end
def draw def draw
if window.current_state == self
previous_state&.draw previous_state&.draw
Gosu.flush Gosu.flush
end
super super
end end
@@ -250,7 +248,8 @@ class W3DHub
updated.launch_arguments = @launch_arguments.value updated.launch_arguments = @launch_arguments.value
updated.irc_profile = @irc_profiles_list.value updated.irc_profile = @irc_profiles_list.value
else else
profile = Asterisk::ServerProfile.new({ profile = Asterisk::ServerProfile.new(
{
name: name, name: name,
nickname: @server_nickname.value, nickname: @server_nickname.value,
password: Base64.strict_encode64(@server_password.value), password: Base64.strict_encode64(@server_password.value),
@@ -260,7 +259,8 @@ class W3DHub
game: @games_list.value, game: @games_list.value,
launch_arguments: @launch_arguments.value, launch_arguments: @launch_arguments.value,
irc_profile: @irc_profiles_list.value irc_profile: @irc_profiles_list.value
}) }
)
W3DHub::Store[:asterisk_config].server_profiles << profile W3DHub::Store[:asterisk_config].server_profiles << profile
end end

View File

@@ -8,10 +8,7 @@ class W3DHub
background 0xee_444444 background 0xee_444444
flow(width: 1.0, height: 1.0) do stack(width: 1.0, max_width: 720, height: 1.0, max_height: 480, v_align: :center, h_align: :center, background: 0xee_222222) do
flow(fill: true, height: 1.0)
stack(width: 1.0, height: 1.0, max_width: MAX_PAGE_WIDTH, margin: 128, background: 0xee_222222) do
flow(width: 1.0, height: 32, padding: 8) do flow(width: 1.0, height: 32, padding: 8) do
background 0x88_000000 background 0x88_000000
@@ -30,9 +27,6 @@ class W3DHub
end end
end end
end end
flow(fill: true, height: 1.0)
end
end end
def draw def draw

View File

@@ -8,10 +8,7 @@ class W3DHub
background 0xee_444444 background 0xee_444444
flow(width: 1.0, height: 1.0) do stack(width: 1.0, max_width: 720, height: 1.0, max_height: 256, v_align: :center, h_align: :center, background: 0xee_222222) do
flow(fill: true, height: 1.0)
stack(width: 1.0, max_width: MAX_PAGE_WIDTH, height: 1.0, margin: 128, background: 0xee_222222) do
flow(width: 1.0, height: 32, padding: 8) do flow(width: 1.0, height: 32, padding: 8) do
background 0x88_000000 background 0x88_000000
@@ -42,9 +39,6 @@ class W3DHub
end end
end end
flow(fill: true, height: 1.0)
end
@prompt_entry.subscribe(:changed) do @prompt_entry.subscribe(:changed) do
if @options[:valid_callback] if @options[:valid_callback]
if @options[:valid_callback].call(@prompt_entry.value) if @options[:valid_callback].call(@prompt_entry.value)

View File

@@ -21,6 +21,7 @@ class W3DHub
# push_state(W3DHub::States::Welcome) # push_state(W3DHub::States::Welcome)
push_state(W3DHub::States::Boot) push_state(W3DHub::States::Boot)
# push_state(W3DHub::States::DirectConnectDialog) # push_state(W3DHub::States::DirectConnectDialog)
# push_state(W3DHub::Asterisk::States::IRCProfileForm)
end end
def update def update