Tweaks for Asterisk dialogs, IRC profile editor dialog functional.

This commit is contained in:
2022-06-14 09:07:40 -05:00
parent 3ca8ab656f
commit 014de7c6aa
4 changed files with 83 additions and 66 deletions

View File

@@ -21,17 +21,17 @@ class W3DHub
end end
stack(width: 1.0, fill: true, padding_left: 8, padding_right: 8) do 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: 66) do
para "Game or Mod Title:" para "Game or Mod Title:"
@game_title = edit_line "#{@game&.title}", width: 1.0 @game_title = edit_line "#{@game&.title}", width: 1.0, fill: true
end end
stack(width: 1.0, height: 60) do stack(width: 1.0, height: 66) do
para "Path to Executable:" para "Path to Executable:"
flow(width: 1.0) do flow(width: 1.0, fill: true) do
@game_path = edit_line "#{@game&.path}", width: 0.749 @game_path = edit_line "#{@game&.path}", fill: true, height: 1.0
button "Browse...", width: 0.25, enabled: W3DHub.unix?, tip: W3DHub.unix? ? "Browse for game executable" : "Not available on Windows" do button "Browse...", width: 128, height: 1.0, enabled: W3DHub.unix?, tip: W3DHub.unix? ? "Browse for game executable" : "Not available on Windows" do
path = W3DHub.ask_file path = W3DHub.ask_file
@game_path.value = path if !path.empty? && File.exist?(path) @game_path.value = path if !path.empty? && File.exist?(path)
end end

View File

@@ -15,70 +15,62 @@ class W3DHub
background 0x88_000000 background 0x88_000000
# tagline "<b>#{I18n.t(:"server_browser.direct_connect")}</b>", fill: true, text_align: :center # 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 tagline @profile ? "Update IRC Profile" : "Add IRC Profile", width: 1.0, fill: true, text_align: :center
end end
stack(width: 1.0, fill: true, padding_left: 8, padding_right: 8) do 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: 66) do
para "IRC Nickname:" para "IRC Nickname:"
@irc_nickname = edit_line "#{@profile&.nickname}", width: 1.0 @nickname = edit_line "#{@profile&.nickname}", width: 1.0, fill: true
end end
stack(width: 1.0, height: 60) do stack(width: 1.0, height: 66) do
flow(width: 1.0, height: 1.0) do flow(width: 1.0, height: 1.0) do
stack(width: 0.5, height: 1.0) do stack(width: 0.5, height: 1.0) do
para "IRC Username:" para "IRC Username (Optional):"
@irc_username = edit_line "#{@profile&.username}", width: 1.0 @username = edit_line "#{@profile&.username}", width: 1.0, fill: true
end end
stack(width: 0.5, height: 1.0) do stack(width: 0.5, height: 1.0) do
para "IRC Server Password:" para "IRC Server Password (Optional):"
@irc_password = edit_line @profile ? Base64.strict_decode64(@profile.password) : "", width: 1.0, type: :password @password = edit_line @profile ? Base64.strict_decode64(@profile.password) : "", width: 1.0, fill: true, type: :password
end end
end end
end end
stack(width: 1.0, height: 60) do stack(width: 1.0, height: 66, margin_top: 32) do
flow(width: 1.0, height: 1.0) do flow(width: 1.0, height: 1.0) do
stack(width: 0.75, height: 1.0) do stack(width: 0.75, height: 1.0) do
para "IRC Server IP or Hostname:" para "IRC Server IP or Hostname:"
@irc_hostname = edit_line "#{@profile&.server_hostname}", width: 1.0 @server_hostname = edit_line "#{@profile&.server_hostname}", width: 1.0, fill: true
end end
stack(width: 0.249, height: 1.0) do stack(width: 0.249, height: 1.0) do
para "IRC Server Port:" para "IRC Server Port:"
@irc_port = edit_line "#{@profile&.server_port || '6667'}", width: 1.0 @server_port = edit_line "#{@profile&.server_port || '6667'}", width: 1.0, fill: true
end end
end end
end end
flow(width: 1.0, height: 60, margin_top: 8) do flow(width: 1.0, height: 66, margin_top: 8) do
flow(width: 0.5, height: 60) do @server_ssl = check_box "IRC Server Use SSL", checked: @profile&.server_ssl, text_size: 18, width: 0.5, height: 66
para "IRC Server Use SSL:", margin_top: 8 @server_verify_ssl = check_box "IRC Verify Server SSL Certificate", checked: @profile ? @profile.server_verify_ssl : true, text_size: 18, width: 0.5, height: 66
@irc_bot = check_box "#{@profile&.server_bot}"
end end
stack(width: 1.0, height: 66) do
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:" para "Brenbot Bot Name:"
@irc_bot = edit_line "#{@profile&.server_bot}", width: 1.0 @bot_username = edit_line "#{@profile&.bot_username}", width: 1.0, fill: true
end end
flow(width: 1.0, height: 60) do flow(width: 1.0, height: 66) do
stack(width: 0.5, height: 60) do stack(width: 0.5, height: 66) do
para "Brenbot Auth Username:" para "Brenbot Auth Username:"
@irc_bot = edit_line "#{@profile&.server_bot}", width: 1.0 @bot_auth_username = edit_line "#{@profile&.bot_auth_username}", width: 1.0, fill: true
end end
stack(width: 0.5, height: 60) do stack(width: 0.5, height: 66) do
para "Brenbot Auth Password:" para "Brenbot Auth Password:"
@irc_password = edit_line @profile ? Base64.strict_decode64(@profile.password) : "", width: 1.0, type: :password @bot_auth_password = edit_line @profile ? Base64.strict_decode64(@profile.bot_auth_password) : "", width: 1.0, fill: true, type: :password
end end
end end
@@ -95,11 +87,16 @@ class W3DHub
pop_state pop_state
@options[:save_callback].call( @options[:save_callback].call(
@profile, @profile,
@irc_nickname.value, @nickname.value,
@irc_password.value, @username.value,
@irc_hostname.value, @password.value,
@irc_port.value, @server_hostname.value,
@irc_bot.value @server_port.value,
@server_ssl.value,
@server_verify_ssl.value,
@bot_username.value,
@bot_auth_username.value,
@bot_auth_password.value
) )
end end
end end
@@ -132,18 +129,19 @@ class W3DHub
def valid? def valid?
generated_name = IRCProfileForm.generate_profile_name( generated_name = IRCProfileForm.generate_profile_name(
@irc_nickname.value, @nickname.value,
@irc_hostname.value, @server_hostname.value,
@irc_port.value, @server_port.value,
@irc_bot.value @bot_username.value
) )
existing_profile = W3DHub::Store[:asterisk_config].irc_profiles.find { |profile| profile.name == generated_name } existing_profile = W3DHub::Store[:asterisk_config].irc_profiles.find { |profile| profile.name == generated_name }
@irc_nickname.value.length.positive? && @nickname.value.length.positive? &&
@irc_password.value.length.positive? && # May be optional? @server_hostname.value.length.positive? &&
@irc_hostname.value.length.positive? && @server_port.value.length.positive? &&
@irc_port.value.length.positive? && @bot_username.value.length.positive? &&
@irc_bot.value.length.positive? @bot_auth_username.value.length.positive? &&
@bot_auth_password.value.length.positive?
end end
def self.generate_profile_name(nickname, hostname, port, bot) def self.generate_profile_name(nickname, hostname, port, bot)

View File

@@ -21,9 +21,9 @@ class W3DHub
end end
stack(width: 1.0, fill: true, padding_left: 8, padding_right: 8) do stack(width: 1.0, fill: true, padding_left: 8, padding_right: 8) do
stack(width: 1.0, height: 65) do stack(width: 1.0, height: 66) do
para "Server Profile Name:" para "Server Profile Name:"
@server_name = edit_line "#{@server_profile&.name}", width: 1.0 @server_name = edit_line "#{@server_profile&.name}", width: 1.0, fill: true
@server_name.subscribe(:changed) do |label| @server_name.subscribe(:changed) do |label|
@save_button.enabled = label.value.length.positive? @save_button.enabled = label.value.length.positive?
end end

View File

@@ -9,7 +9,7 @@ class W3DHub
background 0xee_444444 background 0xee_444444
stack(width: 1.0, max_width: 720, height: 1.0, max_height: 512, v_align: :center, h_align: :center, background: 0xee_222222) do stack(width: 1.0, max_width: 720, height: 1.0, max_height: 540, 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
@@ -20,7 +20,7 @@ class W3DHub
end end
stack(width: 1.0, fill: true, scroll: true) do stack(width: 1.0, fill: true, scroll: true) do
stack(width: 1.0, height: 60, margin_left: 8, margin_right: 8) do stack(width: 1.0, height: 66, margin_left: 8, margin_right: 8) do
para "Server profiles", text_align: :center, width: 1.0 para "Server profiles", text_align: :center, width: 1.0
flow(width: 1.0, fill: true) do flow(width: 1.0, fill: true) do
@@ -51,7 +51,7 @@ class W3DHub
end end
stack(width: 1.0, fill: true, margin_top: 8, padding: 8, border_color: 0xff_111111, border_thickness: 1) do stack(width: 1.0, fill: true, margin_top: 8, padding: 8, border_color: 0xff_111111, border_thickness: 1) do
flow(width: 1.0, height: 60) do flow(width: 1.0, height: 66) do
stack(width: 0.5, height: 1.0) do stack(width: 0.5, height: 1.0) do
para "Nickname:" para "Nickname:"
@server_nickname = edit_line "", width: 1.0, fill: true @server_nickname = edit_line "", width: 1.0, fill: true
@@ -73,7 +73,7 @@ class W3DHub
end end
end end
flow(width: 1.0, height: 60) do flow(width: 1.0, height: 66) do
stack(width: 0.5, height: 1.0) do stack(width: 0.5, height: 1.0) do
para "Server IP or Hostname:" para "Server IP or Hostname:"
@server_hostname = edit_line "", width: 1.0, fill: true @server_hostname = edit_line "", width: 1.0, fill: true
@@ -95,7 +95,7 @@ class W3DHub
end end
end end
stack(width: 1.0, height: 60) do stack(width: 1.0, height: 66) do
para "Game or Mod:" para "Game or Mod:"
flow(width: 1.0, fill: true) do flow(width: 1.0, fill: true) do
@@ -124,7 +124,7 @@ class W3DHub
end end
end end
stack(width: 1.0, height: 60) do stack(width: 1.0, height: 66) do
para "Launch arguments (Optional):" para "Launch arguments (Optional):"
@launch_arguments = edit_line "", width: 1.0, fill: true @launch_arguments = edit_line "", width: 1.0, fill: true
@launch_arguments.subscribe(:changed) do |e| @launch_arguments.subscribe(:changed) do |e|
@@ -134,7 +134,7 @@ class W3DHub
end end
end end
stack(width: 1.0, height: 60) do stack(width: 1.0, height: 66) do
para "IRC Profile:" para "IRC Profile:"
flow(width: 1.0, fill: true) do flow(width: 1.0, fill: true) do
@@ -293,24 +293,43 @@ class W3DHub
@games_list.choose = title @games_list.choose = title
end end
def save_irc_profile(updated, nickname, password, hostname, port, bot) def save_irc_profile(
generated_name = Asterisk::States::IRCProfileForm.generate_profile_name(nickname, hostname, port, bot) updated, nickname, username, password,
server_hostname, server_port, server_ssl, server_verify_ssl,
bot_username, bot_auth_username, bot_auth_password
)
generated_name = Asterisk::States::IRCProfileForm.generate_profile_name(
nickname,
server_hostname,
server_port,
bot_username
)
if updated if updated
updated.name = generated_name updated.name = generated_name
updated.nickname = nickname updated.nickname = nickname
updated.username = username
updated.password = Base64.strict_encode64(password) updated.password = Base64.strict_encode64(password)
updated.server_hostname = hostname updated.server_hostname = hserver_hostname
updated.server_port = port updated.server_port = hserver_port
updated.server_bot = bot updated.server_ssl = server_ssl
updated.server_verify_ssl = server_verify_ssl
updated.bot_username = bot_username
updated.bot_auth_username = bot_auth_username
updated.bot_auth_password = Base64.strict_encode64(bot_auth_password)
else else
profile = Asterisk::IRCProfile.new({ profile = Asterisk::IRCProfile.new({
name: generated_name, name: generated_name,
nickname: nickname, nickname: nickname,
username: username,
password: Base64.strict_encode64(password), password: Base64.strict_encode64(password),
server_hostname: hostname, server_hostname: server_hostname,
server_port: port, server_port: server_port,
server_bot: bot server_ssl: server_ssl,
server_verify_ssl: server_verify_ssl,
bot_username: bot_username,
bot_auth_username: bot_auth_username,
bot_auth_password: Base64.strict_encode64(bot_auth_password)
}) })
W3DHub::Store[:asterisk_config].irc_profiles << profile W3DHub::Store[:asterisk_config].irc_profiles << profile