mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2025-12-16 17:22:35 +00:00
Moved dialogs into subfolder, refactored dialogs to use new Dialog class, removed pre-redesign Interface and Game states/pages
This commit is contained in:
41
lib/states/dialogs/confirm_dialog.rb
Normal file
41
lib/states/dialogs/confirm_dialog.rb
Normal file
@@ -0,0 +1,41 @@
|
||||
class W3DHub
|
||||
class States
|
||||
class ConfirmDialog < Dialog
|
||||
def setup
|
||||
window.show_cursor = true
|
||||
|
||||
theme(W3DHub::THEME)
|
||||
|
||||
background 0xee_444444
|
||||
|
||||
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
|
||||
|
||||
image "#{GAME_ROOT_PATH}/media/ui_icons/question.png", width: 0.04, align: :center, color: 0xaa_ff0000
|
||||
|
||||
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, text_align: :center
|
||||
end
|
||||
|
||||
flow(width: 1.0, height: 0.1, padding: 8) do
|
||||
button "Cancel", width: 0.25 do
|
||||
pop_state
|
||||
@options[:cancel_callback]&.call
|
||||
end
|
||||
|
||||
stack(width: 0.5)
|
||||
|
||||
button "Confirm", width: 0.25, background: 0xff_800000, hover: { background: 0xff_d00000 }, active: { background: 0xff_600000, color: 0xff_ffffff } do
|
||||
pop_state
|
||||
@options[:accept_callback]&.call
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
434
lib/states/dialogs/direct_connect_dialog.rb
Normal file
434
lib/states/dialogs/direct_connect_dialog.rb
Normal file
@@ -0,0 +1,434 @@
|
||||
class W3DHub
|
||||
class States
|
||||
class DirectConnectDialog < Dialog
|
||||
def setup
|
||||
window.show_cursor = true
|
||||
W3DHub::Store[:asterisk_config] ||= Asterisk::Config.new
|
||||
|
||||
theme(W3DHub::THEME)
|
||||
|
||||
background 0xee_444444
|
||||
|
||||
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
|
||||
flow(width: 1.0, height: 32, padding: 8) do
|
||||
background 0x88_000000
|
||||
|
||||
image "#{GAME_ROOT_PATH}/media/ui_icons/export.png", width: 32, align: :center, color: 0xaa_ffffff
|
||||
|
||||
tagline "<b>#{I18n.t(:"server_browser.direct_connect")}</b>", fill: true, text_align: :center
|
||||
end
|
||||
|
||||
stack(width: 1.0, fill: true, scroll: true) do
|
||||
stack(width: 1.0, height: 66, margin_left: 8, margin_right: 8) do
|
||||
para "Server profiles", text_align: :center, width: 1.0
|
||||
|
||||
flow(width: 1.0, fill: true) do
|
||||
list = W3DHub::Store[:asterisk_config].server_profiles.count.positive? ? W3DHub::Store[:asterisk_config].server_profiles.map { |pf| pf.name }.insert(0, "") : [""]
|
||||
|
||||
@server_profiles_list = list_box items: list, fill: true, height: 1.0
|
||||
@server_profiles_list.subscribe(:changed) do |list|
|
||||
list.items.delete("") if list.value != ""
|
||||
|
||||
profile = W3DHub::Store[:asterisk_config].server_profiles.find { |pf| pf.name == list.value }
|
||||
populate_from_server_profile(profile ? profile : W3DHub::Store[:asterisk_config].settings)
|
||||
|
||||
valid_for_multiplayer?
|
||||
end
|
||||
|
||||
button get_image("#{GAME_ROOT_PATH}/media/ui_icons/plus.png"), image_height: 1.0, tip: "Create new profile" do
|
||||
push_state(Asterisk::States::ServerProfileForm, save_callback: method(:save_server_profile))
|
||||
end
|
||||
|
||||
@server_delete_button = button get_image("#{GAME_ROOT_PATH}/media/ui_icons/minus.png"), image_height: 1.0, tip: "Remove selected profile" do
|
||||
push_state(ConfirmDialog, message: "Purge server profile")
|
||||
end
|
||||
|
||||
@server_edit_button = button get_image("#{GAME_ROOT_PATH}/media/ui_icons/save.png"), image_height: 1.0, tip: "Edit and save selected profile" do
|
||||
push_state(Asterisk::States::ServerProfileForm, editing: W3DHub::Store[:asterisk_config].server_profiles.find { |pf| pf.name == @server_profiles_list.value }, save_callback: method(:save_server_profile))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
stack(width: 1.0, fill: true, margin_top: 8, padding: 8, border_color: 0xff_111111, border_thickness: 1) do
|
||||
flow(width: 1.0, height: 66) do
|
||||
stack(width: 0.5, height: 1.0) do
|
||||
para "Nickname:"
|
||||
@server_nickname = edit_line "", width: 1.0, fill: true
|
||||
@server_nickname.subscribe(:changed) do |e|
|
||||
@changes_made = true if @server_profiles_list.value.length.positive?
|
||||
|
||||
valid_for_multiplayer?
|
||||
end
|
||||
end
|
||||
|
||||
stack(width: 0.5, height: 1.0) do
|
||||
para "Server Password:"
|
||||
@server_password = edit_line "", width: 1.0, fill: true, margin_left: 4, type: :password
|
||||
@server_password.subscribe(:changed) do |e|
|
||||
@changes_made = true if @server_profiles_list.value.length.positive?
|
||||
|
||||
valid_for_multiplayer?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
flow(width: 1.0, height: 66) do
|
||||
stack(width: 0.5, height: 1.0) do
|
||||
para "Server IP or Hostname:"
|
||||
@server_hostname = edit_line "", width: 1.0, fill: true
|
||||
@server_hostname.subscribe(:changed) do |e|
|
||||
@changes_made = true if @server_profiles_list.value.length.positive?
|
||||
|
||||
valid_for_multiplayer?
|
||||
end
|
||||
end
|
||||
|
||||
stack(width: 0.5, height: 1.0) do
|
||||
para "Server Port:"
|
||||
@server_port = edit_line "", width: 1.0, fill: true, margin_left: 4
|
||||
@server_port.subscribe(:changed) do |e|
|
||||
@changes_made = true if @server_profiles_list.value.length.positive?
|
||||
|
||||
valid_for_multiplayer?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
stack(width: 1.0, height: 66) do
|
||||
para "Game or Mod:"
|
||||
|
||||
flow(width: 1.0, fill: true) do
|
||||
list = W3DHub::Store[:asterisk_config].games.count.positive? ? W3DHub::Store[:asterisk_config].games.map { |g| g.title } : [""]
|
||||
|
||||
@games_list = list_box items: list, fill: true, height: 1.0
|
||||
@games_list.subscribe(:changed) do |list|
|
||||
list.items.delete("") if list.value != ""
|
||||
|
||||
@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 game" do
|
||||
push_state(Asterisk::States::GameForm, save_callback: method(:save_game))
|
||||
end
|
||||
|
||||
@game_delete_button = button get_image("#{GAME_ROOT_PATH}/media/ui_icons/minus.png"), image_height: 1.0, tip: "Remove selected game" do
|
||||
push_state(ConfirmDialog, title: "Are you sure?", message: "Remove game: #{@games_list.value}?", accept_callback: -> { delete_game(game_from_title(@games_list.value)) })
|
||||
|
||||
end
|
||||
|
||||
@game_edit_button = button get_image("#{GAME_ROOT_PATH}/media/ui_icons/gear.png"), image_height: 1.0, tip: "Edit selected game" do
|
||||
push_state(Asterisk::States::GameForm, editing: W3DHub::Store[:asterisk_config].games.find { |g| g.title == @games_list.value }, save_callback: method(:save_game))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
stack(width: 1.0, height: 66) do
|
||||
para "Launch arguments (Optional):"
|
||||
@launch_arguments = edit_line "", width: 1.0, fill: true
|
||||
@launch_arguments.subscribe(:changed) do |e|
|
||||
@changes_made = true if @server_profiles_list.value.length.positive?
|
||||
|
||||
valid_for_multiplayer?
|
||||
end
|
||||
end
|
||||
|
||||
stack(width: 1.0, height: 66) do
|
||||
para "IRC Profile (Optional):"
|
||||
|
||||
flow(width: 1.0, fill: true) do
|
||||
@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" 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" do
|
||||
push_state(ConfirmDialog, title: "Are you sure?", message: "Delete IRC Profile: #{@irc_profiles_list.value}?", accept_callback: -> { delete_irc_profile(irc_profile_from_name(@irc_profiles_list.value)) })
|
||||
end
|
||||
|
||||
@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: irc_profile_from_name(@irc_profiles_list.value), save_callback: method(:save_irc_profile))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
flow(width: 1.0, height: 40, padding: 8) do
|
||||
button "Cancel", width: 0.25 do
|
||||
pop_state
|
||||
end
|
||||
|
||||
stack(fill: true)
|
||||
|
||||
@connect_button = button "Connect", width: 0.25 do
|
||||
pop_state
|
||||
|
||||
join_server(game_from_title(@games_list.value).path, @server_nickname.value, @server_hostname.value, @server_port.value, @server_password.value, @launch_arguments.value)
|
||||
|
||||
handle_irc
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
super
|
||||
|
||||
if @server_profiles_list.value == ""
|
||||
@server_delete_button.enabled = false
|
||||
@server_edit_button.enabled = false
|
||||
else
|
||||
@server_delete_button.enabled = true
|
||||
@server_edit_button.enabled = true
|
||||
end
|
||||
|
||||
if @games_list.value == ""
|
||||
@game_delete_button.enabled = false
|
||||
@game_edit_button.enabled = false
|
||||
else
|
||||
@game_delete_button.enabled = true
|
||||
@game_edit_button.enabled = true
|
||||
end
|
||||
|
||||
if @irc_profiles_list.value == "None"
|
||||
@irc_delete_button.enabled = false
|
||||
@irc_edit_button.enabled = false
|
||||
else
|
||||
@irc_delete_button.enabled = true
|
||||
@irc_edit_button.enabled = true
|
||||
end
|
||||
|
||||
if @games_list.value.empty? || @server_nickname.value.empty? || @server_hostname.value.empty? || @server_port.value.empty?
|
||||
@connect_button.enabled = false
|
||||
else
|
||||
@connect_button.enabled = true
|
||||
end
|
||||
end
|
||||
|
||||
def populate_from_server_profile(profile)
|
||||
@server_nickname.value = profile.nickname
|
||||
@server_password.value = Base64.strict_decode64(profile.password)
|
||||
@server_hostname.value = profile.server_hostname
|
||||
@server_port.value = profile.server_port
|
||||
|
||||
@games_list.choose = profile.game_title if @games_list.items.find { |game| game == profile.game_title }
|
||||
@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
|
||||
|
||||
def valid_for_singleplayer?
|
||||
@single_player_button&.enabled = @games_list.value != ""
|
||||
end
|
||||
|
||||
def valid_for_multiplayer?
|
||||
@join_server_button&.enabled = @games_list.value != "" &&
|
||||
@server_nickname.value.length.positive? &&
|
||||
@server_hostname.value.length.positive? &&
|
||||
@server_port.value.length.positive?
|
||||
end
|
||||
|
||||
def save_server_profile(updated, name)
|
||||
if updated
|
||||
updated.name = name
|
||||
updated.nickname = @server_nickname.value
|
||||
updated.password = Base64.strict_encode64(@server_password.value)
|
||||
updated.server_profile = @server_profiles_list.value
|
||||
updated.server_hostname = @server_hostname.value
|
||||
updated.server_port = @server_port.value
|
||||
updated.game_title = @games_list.value
|
||||
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
|
||||
}
|
||||
)
|
||||
|
||||
W3DHub::Store[:asterisk_config].server_profiles << profile
|
||||
end
|
||||
|
||||
W3DHub::Store[:asterisk_config].save_config
|
||||
|
||||
@server_profiles_list.items = W3DHub::Store[:asterisk_config].server_profiles.map {|profile| profile.name }
|
||||
@server_profiles_list.items << "" if @server_profiles_list.items.empty?
|
||||
@server_profiles_list.choose = name
|
||||
|
||||
@changes_made = false
|
||||
end
|
||||
|
||||
def game_from_title(title)
|
||||
W3DHub::Store[:asterisk_config].games.find { |g| title == g.title }
|
||||
end
|
||||
|
||||
def save_game(updated, path, title)
|
||||
if updated
|
||||
updated.path = path
|
||||
updated.title = title
|
||||
else
|
||||
game = Asterisk::Game.new({
|
||||
path: path,
|
||||
title: title
|
||||
})
|
||||
|
||||
W3DHub::Store[:asterisk_config].games << game
|
||||
end
|
||||
|
||||
W3DHub::Store[:asterisk_config].save_config
|
||||
|
||||
@games_list.items = W3DHub::Store[:asterisk_config].games.map {|g| g.title }
|
||||
@games_list.choose = title
|
||||
end
|
||||
|
||||
def delete_game(game)
|
||||
index = W3DHub::Store[:asterisk_config].games.index(game) || 0
|
||||
|
||||
W3DHub::Store[:asterisk_config].games.delete(game)
|
||||
|
||||
W3DHub::Store[:asterisk_config].save_config
|
||||
|
||||
@games_list.items = W3DHub::Store[:asterisk_config].games.map {|g| g.title }
|
||||
@games_list.choose = W3DHub::Store[:asterisk_config].games[index - 1 > 0 ? index - 1 : 0].title
|
||||
end
|
||||
|
||||
def irc_profile_from_name(name)
|
||||
W3DHub::Store[:asterisk_config].irc_profiles.find { |pf| name == pf.name }
|
||||
end
|
||||
|
||||
def save_irc_profile(
|
||||
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
|
||||
updated.name = generated_name
|
||||
updated.nickname = nickname
|
||||
updated.username = username
|
||||
updated.password = Base64.strict_encode64(password)
|
||||
updated.server_hostname = server_hostname
|
||||
updated.server_port = server_port
|
||||
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
|
||||
profile = Asterisk::IRCProfile.new({
|
||||
name: generated_name,
|
||||
nickname: nickname,
|
||||
username: username,
|
||||
password: Base64.strict_encode64(password),
|
||||
server_hostname: server_hostname,
|
||||
server_port: server_port,
|
||||
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
|
||||
end
|
||||
|
||||
W3DHub::Store[:asterisk_config].save_config
|
||||
|
||||
@irc_profiles_list.items = W3DHub::Store[:asterisk_config].irc_profiles.map {| pf| pf.name }.insert(0, "None")
|
||||
@irc_profiles_list.choose = generated_name
|
||||
end
|
||||
|
||||
def delete_irc_profile(profile)
|
||||
index = W3DHub::Store[:asterisk_config].irc_profiles.index(profile) || 0
|
||||
|
||||
W3DHub::Store[:asterisk_config].irc_profiles.delete(profile)
|
||||
|
||||
W3DHub::Store[:asterisk_config].save_config
|
||||
|
||||
@irc_profiles_list.items = W3DHub::Store[:asterisk_config].irc_profiles.map {| pf| pf.name }.insert(0, "None")
|
||||
@irc_profiles_list.choose = W3DHub::Store[:asterisk_config].irc_profiles[index - 1 > 0 ? index - 1 : 0].name
|
||||
end
|
||||
|
||||
def wine_command
|
||||
return "" if W3DHub.windows?
|
||||
|
||||
"#{Store.settings[:wine_command]} "
|
||||
end
|
||||
|
||||
# TODO
|
||||
def mangohud_command
|
||||
return "" if W3DHub.windows?
|
||||
|
||||
# TODO: Add game specific options
|
||||
# OPENGL?
|
||||
if false && system("which mangohud")
|
||||
"MANGOHUD=1 MANGOHUD_DLSYM=1 DXVK_HUD=1 mangohud "
|
||||
else
|
||||
""
|
||||
end
|
||||
end
|
||||
|
||||
# TODO
|
||||
def dxvk_command
|
||||
return "" if W3DHub.windows?
|
||||
|
||||
# Vulkan
|
||||
# SETTING && WINE WILL USE DXVK?
|
||||
if false && true#system()
|
||||
_setting = "full"
|
||||
"DXVK_HUD=#{_setting} "
|
||||
else
|
||||
""
|
||||
end
|
||||
end
|
||||
|
||||
def run(game_path, *args)
|
||||
pid = Process.spawn("#{dxvk_command}#{mangohud_command}#{wine_command}\"#{game_path}\" #{args.join(' ')}")
|
||||
Process.detach(pid)
|
||||
end
|
||||
|
||||
def join_server(game_path, nickname, server_address, server_port, server_password, launch_arguments)
|
||||
server_password = nil if server_password.empty?
|
||||
launch_arguments = nil if launch_arguments.empty?
|
||||
|
||||
run(
|
||||
game_path,
|
||||
"-launcher +connect #{server_address}:#{server_port} +netplayername #{nickname}#{server_password ? " +password \"#{server_password}\"" : ""}#{launch_arguments ? " #{launch_arguments}" : ''}"
|
||||
)
|
||||
end
|
||||
|
||||
def handle_irc
|
||||
return unless (profile = irc_profile_from_name(@irc_profiles_list.value))
|
||||
|
||||
Thread.new do
|
||||
sleep 15
|
||||
|
||||
W3DHub::Asterisk::IRCClient.new(profile)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
33
lib/states/dialogs/message_dialog.rb
Normal file
33
lib/states/dialogs/message_dialog.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
class W3DHub
|
||||
class States
|
||||
class MessageDialog < Dialog
|
||||
def setup
|
||||
window.show_cursor = true
|
||||
|
||||
theme(W3DHub::THEME)
|
||||
|
||||
background 0xee_444444
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
70
lib/states/dialogs/prompt_dialog.rb
Normal file
70
lib/states/dialogs/prompt_dialog.rb
Normal file
@@ -0,0 +1,70 @@
|
||||
class W3DHub
|
||||
class States
|
||||
class PromptDialog < Dialog
|
||||
def setup
|
||||
window.show_cursor = true
|
||||
|
||||
theme(W3DHub::THEME)
|
||||
|
||||
background 0xee_444444
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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(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
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@prompt_entry.subscribe(:changed) do
|
||||
if @options[:valid_callback]
|
||||
if @options[:valid_callback].call(@prompt_entry.value)
|
||||
c = W3DHub::THEME[:Button][:border_color]
|
||||
|
||||
@prompt_entry.style.border_color = c
|
||||
@prompt_entry.style.default[:border_color] = c
|
||||
@prompt_entry.style.hover[:border_color] = c
|
||||
@prompt_entry.style.active[:border_color] = c
|
||||
|
||||
@accept_button.enabled = true
|
||||
else
|
||||
c = 0xff_ff0000
|
||||
|
||||
@prompt_entry.style.border_color = c
|
||||
@prompt_entry.style.default[:border_color] = c
|
||||
@prompt_entry.style.hover[:border_color] = c
|
||||
@prompt_entry.style.active[:border_color] = c
|
||||
|
||||
@accept_button.enabled = false
|
||||
end
|
||||
|
||||
@prompt_entry.set_border_color
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user