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-websocket"
gem "thread-local"
gem "ircparser"
# group :windows_packaging do
# gem "rake"

View File

@@ -1,27 +1,40 @@
class W3DHub
class Asterisk
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)
return unless hash
@name = hash[:name]
@username = hash[:username] || hash[:nickname]
@nickname = hash[:nickname]
@password = hash[:password]
@server_hostname = hash[:server_hostname]
@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
def to_json(options)
{
name: @name,
username: @username,
nickname: @nickname,
password: @password,
server_hostname: @server_hostname,
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)
end
end

View File

@@ -7,9 +7,9 @@ class W3DHub
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
flow(width: 1.0, height: 32, padding: 8) do
background 0x88_000000
@@ -74,10 +74,6 @@ class W3DHub
@save_button.enabled = valid?
end
def close
pop_state
end
def button_down(id)
super

View File

@@ -7,71 +7,113 @@ class W3DHub
theme W3DHub::THEME
background 0xcc_000000
background 0xaa_444444
stack(width: 1.0, height: 248, margin: 48, padding: 16) do
caption @game ? "Update IRC Profile" : "Add IRC Profile", width: 1.0, text_align: :center
stack(width: 1.0, max_width: 760, height: 1.0, max_height: 560, v_align: :center, h_align: :center, background: 0xff_222222) do
# Title bar
flow(width: 1.0, height: 32, padding: 8) do
background 0x88_000000
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:"
@irc_nickname = edit_line "#{@profile&.nickname}", width: 1.0
end
stack(width: 0.4, height: 1.0) do
para "IRC Password:"
@irc_password = edit_line "#{@profile ? Base64.strict_decode64(@profile.password) : ''}", width: 1.0#, type: :password
end
end
# 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, height: 60) do
flow(width: 1.0, height: 1.0) do
stack(width: 0.75, height: 1.0) do
para "IRC Server IP or Hostname:"
@irc_hostname = edit_line "#{@profile&.server_hostname}", width: 1.0
end
stack(width: 0.249, height: 1.0) do
para "IRC Port:"
@irc_port = edit_line "#{@profile&.server_port || '6667'}", width: 1.0
end
end
end
stack(width: 1.0, height: 60) do
para "IRC Bot Name:"
@irc_bot = edit_line "#{@profile&.server_bot}", width: 1.0
end
flow(width: 1.0, margin_top: 8) do
button "Cancel", width: 0.5, margin_right: 4 do
pop_state
stack(width: 1.0, fill: true, padding_left: 8, padding_right: 8) do
stack(width: 1.0, height: 60) do
para "IRC Nickname:"
@irc_nickname = edit_line "#{@profile&.nickname}", width: 1.0
end
@save_button = button "Save", width: 0.5, margin_left: 4, enabled: false do
pop_state
@options[:save_callback].call(
@profile,
@irc_nickname.value,
@irc_password.value,
@irc_hostname.value,
@irc_port.value,
@irc_bot.value
)
stack(width: 1.0, height: 60) do
flow(width: 1.0, height: 1.0) do
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
stack(width: 1.0, height: 60) do
flow(width: 1.0, height: 1.0) do
stack(width: 0.75, height: 1.0) do
para "IRC Server IP or Hostname:"
@irc_hostname = edit_line "#{@profile&.server_hostname}", width: 1.0
end
stack(width: 0.249, height: 1.0) do
para "IRC Server Port:"
@irc_port = edit_line "#{@profile&.server_port || '6667'}", width: 1.0
end
end
end
flow(width: 1.0, height: 60, margin_top: 8) do
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
end
flow(width: 1.0, height: 60) 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
end
flow(fill: true)
@save_button = button "Save", fill: true, margin_left: 4, enabled: false do
pop_state
@options[:save_callback].call(
@profile,
@irc_nickname.value,
@irc_password.value,
@irc_hostname.value,
@irc_port.value,
@irc_bot.value
)
end
end
end
end
end
# def draw
# previous_state&.draw
def draw
previous_state&.draw
# Gosu.flush
Gosu.flush
# super
# end
super
end
def update
super
@@ -79,10 +121,6 @@ class W3DHub
@save_button.enabled = valid?
end
def close
pop_state
end
def button_down(id)
super

View File

@@ -7,9 +7,9 @@ class W3DHub
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
flow(width: 1.0, height: 32, padding: 8) do
background 0x88_000000
@@ -58,10 +58,6 @@ class W3DHub
super
end
def close
pop_state
end
def button_down(id)
super

View File

@@ -65,7 +65,7 @@ class W3DHub
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)
end
end

View File

@@ -8,7 +8,7 @@ class W3DHub
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
background 0x88_000000

View File

@@ -9,7 +9,7 @@ class W3DHub
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
flow(width: 1.0, height: 32, padding: 8) do
background 0x88_000000
@@ -138,22 +138,22 @@ class W3DHub
para "IRC Profile:"
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|
@changes_made = true if @server_profiles_list.value.length.positive?
valid_for_multiplayer?
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))
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: "")
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))
end
end
@@ -206,11 +206,9 @@ class W3DHub
end
def draw
if window.current_state == self
previous_state&.draw
previous_state&.draw
Gosu.flush
end
Gosu.flush
super
end
@@ -222,7 +220,7 @@ class W3DHub
@server_port.value = profile.server_port
@games_list.choose = profile.game if @games_list.items.find { |game| game == profile.game }
@launch_arguments.value = profile.launch_arguments
@launch_arguments.value = profile.launch_arguments
@irc_profiles_list.choose = profile.irc_profile if @irc_profiles_list.items.find { |irc| irc == profile.irc_profile }
end
@@ -250,17 +248,19 @@ class W3DHub
updated.launch_arguments = @launch_arguments.value
updated.irc_profile = @irc_profiles_list.value
else
profile = Asterisk::ServerProfile.new({
name: name,
nickname: @server_nickname.value,
password: Base64.strict_encode64(@server_password.value),
server_profile: @server_profiles_list.value,
server_hostname: @server_hostname.value,
server_port: @server_port.value,
game: @games_list.value,
launch_arguments: @launch_arguments.value,
irc_profile: @irc_profiles_list.value
})
profile = Asterisk::ServerProfile.new(
{
name: name,
nickname: @server_nickname.value,
password: Base64.strict_encode64(@server_password.value),
server_profile: @server_profiles_list.value,
server_hostname: @server_hostname.value,
server_port: @server_port.value,
game: @games_list.value,
launch_arguments: @launch_arguments.value,
irc_profile: @irc_profiles_list.value
}
)
W3DHub::Store[:asterisk_config].server_profiles << profile
end

View File

@@ -8,30 +8,24 @@ class W3DHub
background 0xee_444444
flow(width: 1.0, height: 1.0) do
flow(fill: true, height: 1.0)
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: 32, padding: 8) do
background 0x88_000000
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
background 0x88_000000
image "#{GAME_ROOT_PATH}/media/ui_icons/warning.png", width: 32, align: :center, color: 0xff_ff8800
image "#{GAME_ROOT_PATH}/media/ui_icons/warning.png", width: 32, align: :center, color: 0xff_ff8800
tagline "<b>#{@options[:title]}</b>", width: 0.9, text_align: :center
end
stack(width: 1.0, fill: true, padding: 16) do
para @options[:message], width: 1.0
end
stack(width: 1.0, height: 40, padding: 8) do
button "Okay", width: 1.0 do
pop_state
end
end
tagline "<b>#{@options[:title]}</b>", width: 0.9, text_align: :center
end
flow(fill: true, height: 1.0)
stack(width: 1.0, fill: true, padding: 16) do
para @options[:message], width: 1.0
end
stack(width: 1.0, height: 40, padding: 8) do
button "Okay", width: 1.0 do
pop_state
end
end
end
end

View File

@@ -8,41 +8,35 @@ class W3DHub
background 0xee_444444
flow(width: 1.0, height: 1.0) do
flow(fill: true, height: 1.0)
stack(width: 1.0, max_width: 720, height: 1.0, max_height: 256, v_align: :center, h_align: :center, background: 0xee_222222) do
flow(width: 1.0, height: 32, padding: 8) do
background 0x88_000000
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
background 0x88_000000
image "#{GAME_ROOT_PATH}/media/ui_icons/question.png", width: 32, align: :center, color: 0xff_ff8800
image "#{GAME_ROOT_PATH}/media/ui_icons/question.png", width: 32, align: :center, color: 0xff_ff8800
tagline "<b>#{@options[:title]}</b>", fill: true, text_align: :center
end
tagline "<b>#{@options[:title]}</b>", fill: true, text_align: :center
stack(width: 1.0, fill: true, padding: 16) do
para @options[:message], width: 1.0
@prompt_entry = edit_line @options[:prefill].to_s, margin_top: 24, width: 1.0, autofocus: true, focus: true, type: @options[:input_type] == :password ? :password : :text
end
flow(width: 1.0, height: 40, padding: 8) do
button "Cancel", width: 0.25 do
pop_state
@options[:cancel_callback]&.call(@prompt_entry.value)
end
stack(width: 1.0, fill: true, padding: 16) do
para @options[:message], width: 1.0
@prompt_entry = edit_line @options[:prefill].to_s, margin_top: 24, width: 1.0, autofocus: true, focus: true, type: @options[:input_type] == :password ? :password : :text
end
stack(fill: true)
flow(width: 1.0, height: 40, padding: 8) do
button "Cancel", width: 0.25 do
@accept_button = button "Accept", width: 0.25 do
if @options[:valid_callback]&.call(@prompt_entry.value)
pop_state
@options[:cancel_callback]&.call(@prompt_entry.value)
end
stack(fill: true)
@accept_button = button "Accept", width: 0.25 do
if @options[:valid_callback]&.call(@prompt_entry.value)
pop_state
@options[:accept_callback]&.call(@prompt_entry.value)
end
@options[:accept_callback]&.call(@prompt_entry.value)
end
end
end
flow(fill: true, height: 1.0)
end
@prompt_entry.subscribe(:changed) do

View File

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