mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2025-12-16 17:22:35 +00:00
Inital Import of asterisk_gosu into launcher, non-functional.
This commit is contained in:
102
lib/asterisk/states/game_form.rb
Normal file
102
lib/asterisk/states/game_form.rb
Normal file
@@ -0,0 +1,102 @@
|
||||
class W3DHub
|
||||
class Asterisk
|
||||
class States
|
||||
class GameForm < CyberarmEngine::GuiState
|
||||
def setup
|
||||
@game = @options[:editing]
|
||||
|
||||
theme W3DHub::THEME
|
||||
|
||||
background 0xee_444444
|
||||
|
||||
stack(width: 1.0, height: 1.0, margin: 256, 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
|
||||
tagline @game ? "Update Game" : "Add Game", 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
|
||||
para "Game or Mod Title:"
|
||||
@game_title = edit_line "#{@game&.title}", width: 1.0
|
||||
end
|
||||
|
||||
stack(width: 1.0, height: 60) do
|
||||
para "Path to Executable:"
|
||||
|
||||
flow(width: 1.0) do
|
||||
@game_path = edit_line "#{@game&.path}", width: 0.749
|
||||
button "Browse...", width: 0.25, enabled: W3DHub.unix?, tip: W3DHub.unix? ? "Browse for game executable" : "Not available on Windows" do
|
||||
path = W3DHub.ask_file
|
||||
@game_path.value = path if !path.empty? && File.exist?(path)
|
||||
end
|
||||
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(
|
||||
@game,
|
||||
@game_path.value,
|
||||
@game_title.value
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def draw
|
||||
previous_state&.draw
|
||||
|
||||
Gosu.flush
|
||||
|
||||
super
|
||||
end
|
||||
|
||||
def update
|
||||
super
|
||||
|
||||
@save_button.enabled = valid?
|
||||
end
|
||||
|
||||
def close
|
||||
pop_state
|
||||
end
|
||||
|
||||
def button_down(id)
|
||||
super
|
||||
|
||||
case id
|
||||
when Gosu::KB_ESCAPE
|
||||
pop_state
|
||||
end
|
||||
end
|
||||
|
||||
def valid?
|
||||
existing_game = W3DHub::Store[:asterisk_config].games.find { |g| g.title == @game_title.value }
|
||||
existing_game = nil if existing_game == @game
|
||||
|
||||
@game_title.value.length.positive? &&
|
||||
@game_path.value.length.positive? &&
|
||||
File.exist?(@game_path.value) &&
|
||||
!existing_game
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
117
lib/asterisk/states/irc_profile_form.rb
Normal file
117
lib/asterisk/states/irc_profile_form.rb
Normal file
@@ -0,0 +1,117 @@
|
||||
class W3DHub
|
||||
class Asterisk
|
||||
class States
|
||||
class IRCProfileForm < CyberarmEngine::GuiState
|
||||
def setup
|
||||
@profile = @options[:editing]
|
||||
|
||||
theme W3DHub::THEME
|
||||
|
||||
background 0xcc_000000
|
||||
|
||||
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, 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
|
||||
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
|
||||
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
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# def draw
|
||||
# previous_state&.draw
|
||||
|
||||
# Gosu.flush
|
||||
|
||||
# super
|
||||
# end
|
||||
|
||||
def update
|
||||
super
|
||||
|
||||
@save_button.enabled = valid?
|
||||
end
|
||||
|
||||
def close
|
||||
pop_state
|
||||
end
|
||||
|
||||
def button_down(id)
|
||||
super
|
||||
|
||||
case id
|
||||
when Gosu::KB_ESCAPE
|
||||
pop_state
|
||||
end
|
||||
end
|
||||
|
||||
def valid?
|
||||
generated_name = IRCProfileForm.generate_profile_name(
|
||||
@irc_nickname.value,
|
||||
@irc_hostname.value,
|
||||
@irc_port.value,
|
||||
@irc_bot.value
|
||||
)
|
||||
existing_profile = W3DHub::Store[:asterisk_config].irc_profiles.find { |profile| profile.name == generated_name }
|
||||
|
||||
@irc_nickname.value.length.positive? &&
|
||||
@irc_password.value.length.positive? && # May be optional?
|
||||
@irc_hostname.value.length.positive? &&
|
||||
@irc_port.value.length.positive? &&
|
||||
@irc_bot.value.length.positive?
|
||||
end
|
||||
|
||||
def self.generate_profile_name(nickname, hostname, port, bot)
|
||||
"#{bot}@#{hostname}:#{port} as #{nickname}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
76
lib/asterisk/states/server_profile_form.rb
Normal file
76
lib/asterisk/states/server_profile_form.rb
Normal file
@@ -0,0 +1,76 @@
|
||||
class W3DHub
|
||||
class Asterisk
|
||||
class States
|
||||
class ServerProfileForm < CyberarmEngine::GuiState
|
||||
def setup
|
||||
@server_profile = @options[:editing]
|
||||
|
||||
theme W3DHub::THEME
|
||||
|
||||
background 0xee_444444
|
||||
|
||||
stack(width: 1.0, height: 1.0, margin: 256, 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
|
||||
tagline @server_profile ? "Update Server Profile" : "Add Server 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: 65) do
|
||||
para "Server Profile Name:"
|
||||
@server_name = edit_line "#{@server_profile&.name}", width: 1.0
|
||||
@server_name.subscribe(:changed) do |label|
|
||||
@save_button.enabled = label.value.length.positive?
|
||||
end
|
||||
end
|
||||
|
||||
flow(fill: true)
|
||||
|
||||
flow(width: 1.0, 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 do
|
||||
pop_state
|
||||
@options[:save_callback].call(
|
||||
@server_profile,
|
||||
@server_name.value
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def draw
|
||||
previous_state&.draw
|
||||
|
||||
Gosu.flush
|
||||
|
||||
super
|
||||
end
|
||||
|
||||
def close
|
||||
pop_state
|
||||
end
|
||||
|
||||
def button_down(id)
|
||||
super
|
||||
|
||||
case id
|
||||
when Gosu::KB_ESCAPE
|
||||
pop_state
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user