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

@@ -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