mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2025-12-16 09:12:35 +00:00
Inital Import of asterisk_gosu into launcher, non-functional.
This commit is contained in:
@@ -8,7 +8,7 @@ class W3DHub
|
||||
end
|
||||
|
||||
def execute_task
|
||||
path = ask_file
|
||||
path = W3DHub.ask_file
|
||||
|
||||
unless File.exist?(path) && !File.directory?(path)
|
||||
fail!("File #{path.inspect} does not exist or is a directory")
|
||||
@@ -21,30 +21,6 @@ class W3DHub
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def ask_file(title: "Open File", filter: "*game*.exe")
|
||||
if W3DHub.unix?
|
||||
# search for command
|
||||
cmds = %w{ zenity matedialog qarma kdialog }
|
||||
|
||||
command = cmds.find do |cmd|
|
||||
cmd if system("which #{cmd}")
|
||||
end
|
||||
|
||||
path = case File.basename(command)
|
||||
when "zenity", "matedialog", "qarma"
|
||||
`#{command} --file-selection --title "#{title}" --file-filter "#{filter}"`
|
||||
when "kdialog"
|
||||
`#{command} --title "#{title}" --getopenfilename . "#{filter}"`
|
||||
else
|
||||
raise "No known command found for system file selection dialog!"
|
||||
end
|
||||
|
||||
path.strip
|
||||
else
|
||||
raise NotImplementedError
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
83
lib/asterisk/config.rb
Normal file
83
lib/asterisk/config.rb
Normal file
@@ -0,0 +1,83 @@
|
||||
class W3DHub
|
||||
class Asterisk
|
||||
class Config
|
||||
CONFIG_PATH = "#{GAME_ROOT_PATH}/data/asterisk.json"
|
||||
|
||||
attr_reader :settings, :server_profiles, :games, :irc_profiles
|
||||
|
||||
def initialize
|
||||
@config = nil
|
||||
|
||||
save_new_config unless load_config
|
||||
load_config unless @config
|
||||
end
|
||||
|
||||
def save_new_config
|
||||
hash = {
|
||||
settings: {
|
||||
theme: :default,
|
||||
|
||||
server_profile: "",
|
||||
game: "",
|
||||
launch_arguments: "",
|
||||
irc_profile: "None",
|
||||
|
||||
nickname: "",
|
||||
password: "",
|
||||
server_hostname: "",
|
||||
server_port: "",
|
||||
|
||||
preload_app: "",
|
||||
enable_preload_app: false,
|
||||
|
||||
post_launch_app: "",
|
||||
enable_post_launch_app: false,
|
||||
},
|
||||
|
||||
server_profiles: [],
|
||||
|
||||
games: [],
|
||||
|
||||
irc_profiles: []
|
||||
}
|
||||
|
||||
save_config(hash)
|
||||
end
|
||||
|
||||
def load_config
|
||||
return false unless File.exist?(CONFIG_PATH)
|
||||
|
||||
begin
|
||||
hash = JSON.parse(File.read(CONFIG_PATH), symbolize_names: true)
|
||||
|
||||
@config ||= {}
|
||||
|
||||
@config[:settings] = @settings = Settings.new(hash[:settings])
|
||||
|
||||
@config[:server_profiles] = @server_profiles = []
|
||||
hash[:server_profiles].each { |profile| @server_profiles << ServerProfile.new(profile) }
|
||||
|
||||
@config[:games] = @games = []
|
||||
hash[:games].each { |game| @games << Game.new(game) }
|
||||
|
||||
@config[:irc_profiles] = @irc_profiles = []
|
||||
hash[:irc_profiles].each { |profile| @irc_profiles << IRCProfile.new(profile) }
|
||||
|
||||
rescue JSON::ParserError
|
||||
puts "Config corrupted"
|
||||
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
def hard_reset!
|
||||
save_new_config
|
||||
load_config
|
||||
end
|
||||
|
||||
def save_config(config = @config)
|
||||
File.write(CONFIG_PATH, config.to_json)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
21
lib/asterisk/game.rb
Normal file
21
lib/asterisk/game.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
class W3DHub
|
||||
class Asterisk
|
||||
class Game
|
||||
attr_accessor :title, :path
|
||||
|
||||
def initialize(hash = nil)
|
||||
return unless hash
|
||||
|
||||
@title = hash[:title]
|
||||
@path = hash[:path]
|
||||
end
|
||||
|
||||
def to_json(options)
|
||||
{
|
||||
title: @title,
|
||||
path: @path
|
||||
}.to_json(options)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
29
lib/asterisk/irc_profile.rb
Normal file
29
lib/asterisk/irc_profile.rb
Normal file
@@ -0,0 +1,29 @@
|
||||
class W3DHub
|
||||
class Asterisk
|
||||
class IRCProfile
|
||||
attr_accessor :name, :nickname, :password, :server_hostname, :server_port, :server_bot
|
||||
|
||||
def initialize(hash = nil)
|
||||
return unless hash
|
||||
|
||||
@name = hash[:name]
|
||||
@nickname = hash[:nickname]
|
||||
@password = hash[:password]
|
||||
@server_hostname = hash[:server_hostname]
|
||||
@server_port = hash[:server_port]
|
||||
@server_bot = hash[:server_bot]
|
||||
end
|
||||
|
||||
def to_json(options)
|
||||
{
|
||||
name: @name,
|
||||
nickname: @nickname,
|
||||
password: @password,
|
||||
server_hostname: @server_hostname,
|
||||
server_port: @server_port,
|
||||
server_bot: @server_bot
|
||||
}.to_json(options)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
38
lib/asterisk/server_profile.rb
Normal file
38
lib/asterisk/server_profile.rb
Normal file
@@ -0,0 +1,38 @@
|
||||
class W3DHub
|
||||
class Asterisk
|
||||
class ServerProfile
|
||||
attr_accessor :name, :nickname, :password,
|
||||
:game, :launch_arguments,
|
||||
:server_profile, :server_hostname, :server_port,
|
||||
:irc_profile
|
||||
|
||||
def initialize(hash = nil)
|
||||
return unless hash
|
||||
|
||||
@name = hash[:name]
|
||||
@nickname = hash[:nickname]
|
||||
@password = hash[:password]
|
||||
@server_profile = hash[:server_profile]
|
||||
@server_hostname = hash[:server_hostname]
|
||||
@server_port = hash[:server_port]
|
||||
@game = hash[:game]
|
||||
@launch_arguments = hash[:launch_arguments]
|
||||
@irc_profile = hash[:irc_profile]
|
||||
end
|
||||
|
||||
def to_json(options)
|
||||
{
|
||||
name: @name,
|
||||
nickname: @nickname,
|
||||
password: @password,
|
||||
server_profile: @server_profile,
|
||||
server_hostname: @server_hostname,
|
||||
server_port: @server_port,
|
||||
game_title: @game_title,
|
||||
launch_arguments: @launch_arguments,
|
||||
irc_profile: @irc_profile
|
||||
}.to_json(options)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
26
lib/asterisk/settings.rb
Normal file
26
lib/asterisk/settings.rb
Normal file
@@ -0,0 +1,26 @@
|
||||
class W3DHub
|
||||
class Asterisk
|
||||
class Settings
|
||||
attr_accessor :theme, :preload_app, :enable_preload_app, :post_launch_app, :enable_post_launch_app
|
||||
|
||||
def initialize(hash)
|
||||
@theme = hash[:theme].to_sym
|
||||
|
||||
@preload_app = hash[:preload_app]
|
||||
@enable_preload_app = hash[:enable_preload_app]
|
||||
@post_launch_app = hash[:post_launch_app]
|
||||
@enable_post_launch_app = hash[:enable_post_launch_app]
|
||||
end
|
||||
|
||||
def to_json(options)
|
||||
{
|
||||
theme: @theme,
|
||||
preload_app: @preload_app,
|
||||
enable_preload_app: @enable_preload_app,
|
||||
post_launch_app: @post_launch_app,
|
||||
enable_post_launch_app: @enable_post_launch_app
|
||||
}.to_json(options)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
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
|
||||
@@ -43,4 +43,28 @@ class W3DHub
|
||||
def self.home_directory
|
||||
File.expand_path("~")
|
||||
end
|
||||
|
||||
def self.ask_file(title: "Open File", filter: "*game*.exe")
|
||||
if W3DHub.unix?
|
||||
# search for command
|
||||
cmds = %w{ zenity matedialog qarma kdialog }
|
||||
|
||||
command = cmds.find do |cmd|
|
||||
cmd if system("which #{cmd}")
|
||||
end
|
||||
|
||||
path = case File.basename(command)
|
||||
when "zenity", "matedialog", "qarma"
|
||||
`#{command} --file-selection --title "#{title}" --file-filter "#{filter}"`
|
||||
when "kdialog"
|
||||
`#{command} --title "#{title}" --getopenfilename . "#{filter}"`
|
||||
else
|
||||
raise "No known command found for system file selection dialog!"
|
||||
end
|
||||
|
||||
path.strip
|
||||
else
|
||||
raise NotImplementedError
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,6 +3,7 @@ class W3DHub
|
||||
class DirectConnectDialog < CyberarmEngine::GuiState
|
||||
def setup
|
||||
window.show_cursor = true
|
||||
W3DHub::Store[:asterisk_config] ||= Asterisk::Config.new
|
||||
|
||||
theme(W3DHub::THEME)
|
||||
|
||||
@@ -23,28 +24,28 @@ class W3DHub
|
||||
para "Server profiles", text_align: :center, width: 1.0
|
||||
|
||||
flow(width: 1.0, fill: true) do
|
||||
list = [""] # window.config.server_profiles.count.positive? ? window.config.server_profiles.map { |pf| pf.name }.insert(0, "") : [""]
|
||||
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 = window.config.server_profiles.find { |pf| pf.name == list.value }
|
||||
populate_from_server_profile(profile ? profile : window.config.settings)
|
||||
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(ServerProfileForm, save_callback: method(:save_server_profile))
|
||||
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/gear.png"), image_height: 1.0, tip: "Edit and save selected profile" do
|
||||
push_state(ServerProfileForm, editing: window.config.server_profiles.find { |pf| pf.name == @server_profiles_list.value }, save_callback: method(:save_server_profile))
|
||||
@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
|
||||
@@ -98,7 +99,7 @@ class W3DHub
|
||||
para "Game or Mod:"
|
||||
|
||||
flow(width: 1.0, fill: true) do
|
||||
list = [""] # window.config.games.count.positive? ? window.config.games.map { |g| g.title } : [""]
|
||||
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|
|
||||
@@ -110,7 +111,7 @@ class W3DHub
|
||||
end
|
||||
|
||||
button get_image("#{GAME_ROOT_PATH}/media/ui_icons/plus.png"), image_height: 1.0, tip: "Add game" do
|
||||
push_state(GameForm, save_callback: method(:save_game))
|
||||
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
|
||||
@@ -118,7 +119,7 @@ class W3DHub
|
||||
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(GameForm, editing: window.config.games.find { |g| g.title == @games_list.value }, save_callback: method(:save_game))
|
||||
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
|
||||
@@ -137,23 +138,23 @@ class W3DHub
|
||||
para "IRC Profile:"
|
||||
|
||||
flow(width: 1.0, fill: true) do
|
||||
@irc_profiles_list = list_box items: ["None"], fill: true, height: 1.0
|
||||
@irc_profiles_list = list_box items: ["None"], fill: true, height: 1.0, enabled: false
|
||||
@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(IRCProfileForm, save_callback: method(:save_irc_profile))
|
||||
button get_image("#{GAME_ROOT_PATH}/media/ui_icons/plus.png"), image_height: 1.0, tip: "Add IRC profile", enabled: false 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
|
||||
@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
|
||||
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" do
|
||||
push_state(IRCProfileForm, editing: window.config.irc_profiles.find { |pf| pf.name == @irc_profiles_list.value }, save_callback: method(:save_irc_profile))
|
||||
@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
|
||||
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
|
||||
end
|
||||
@@ -176,13 +177,150 @@ class W3DHub
|
||||
end
|
||||
end
|
||||
|
||||
def draw
|
||||
previous_state&.draw
|
||||
def update
|
||||
super
|
||||
|
||||
Gosu.flush
|
||||
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
|
||||
end
|
||||
|
||||
def draw
|
||||
if window.current_state == self
|
||||
previous_state&.draw
|
||||
|
||||
Gosu.flush
|
||||
end
|
||||
|
||||
super
|
||||
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 if @games_list.items.find { |game| game == profile.game }
|
||||
@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 = @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 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 save_irc_profile(updated, nickname, password, hostname, port, bot)
|
||||
generated_name = Asterisk::States::IRCProfileForm.generate_profile_name(nickname, hostname, port, bot)
|
||||
|
||||
if updated
|
||||
updated.name = generated_name
|
||||
updated.nickname = nickname
|
||||
updated.password = Base64.strict_encode64(password)
|
||||
updated.server_hostname = hostname
|
||||
updated.server_port = port
|
||||
updated.server_bot = bot
|
||||
else
|
||||
profile = Asterisk::IRCProfile.new({
|
||||
name: generated_name,
|
||||
nickname: nickname,
|
||||
password: Base64.strict_encode64(password),
|
||||
server_hostname: hostname,
|
||||
server_port: port,
|
||||
server_bot: bot
|
||||
})
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user