Fixed game ordering, added ApplicationManager class that'll manage installing/repairing/removing games

This commit is contained in:
2021-11-14 19:52:27 -06:00
parent b7ccdb2ad3
commit 7fd38cd92d
9 changed files with 120 additions and 39 deletions

View File

@@ -9,6 +9,7 @@ class W3DHub
@games = []
games.each { |hash| @games << Game.new(hash) }
@games.sort_by! { |a| a.slot }.reverse
end
def games
@@ -16,11 +17,13 @@ class W3DHub
end
class Game
attr_reader :id, :name, :type, :category, :studio_id, :channels, :web_links, :color
attr_reader :slot, :id, :name, :type, :category, :studio_id, :channels, :web_links, :color
def initialize(hash)
@data = hash
@slot = slot_index(@data[:id])
@id = @data[:id]
@name = @data[:name]
@type = @data[:type]
@@ -37,6 +40,23 @@ class W3DHub
@color = "ff#{color}".to_i(16)
end
private def slot_index(app_id)
case app_id
when "ren"
1
when "ecw"
2
when "ia"
3
when "apb"
4
when "tsr"
5
else
-10
end
end
class Channel
attr_reader :id, :name, :user_level, :current_version

View File

@@ -0,0 +1,49 @@
class W3DHub
class ApplicationManager
def install(app_id)
puts "Installation Request: #{app_id}"
end
def import(app_id, path)
puts "Import Request: #{app_id} -> #{path}"
end
def settings(app_id)
puts "Settings Request: #{app_id}"
end
def repair(app_id)
puts "Repair Installation Request: #{app_id}"
end
def uninstall(app_id)
puts "Uninstall Request: #{app_id}"
end
def show_folder(app_id, type)
puts "Show Folder Request: #{app_id} -> #{type.inspect}"
case type
when :installation
when :user_data
when :screenshots
else
warn "Unknown folder type: #{type.inspect}"
end
end
def installed?(app_id)
false
end
# No application tasks are being done
def idle?
true
end
# Whether some operation is in progress
def busy?
!idle?
end
end
end

View File

@@ -61,7 +61,7 @@ class W3DHub
# background 0xff_444411
game.channels.each do |channel|
button "#{channel.name}", text_size: 14, padding_top: 2, padding_bottom: 2, padding_left: 4, padding_right: 4
button "#{channel.name}", text_size: 14, padding_top: 2, padding_bottom: 2, padding_left: 4, padding_right: 4, margin: 0, margin_right: 4
end
end
@@ -81,9 +81,30 @@ class W3DHub
# end
# end
if window.application_manager.installed?(game.id)
Hash.new.tap { |hash|
hash["Game Settings"] = { icon: "gear", block: proc { window.application_manager.settings(game.id) } }
if game.id != "ren"
hash["Repair Installation"] = { icon: "wrench", block: proc { window.application_manager.repair(game.id) } }
hash["Uninstall"] = { icon: "trashCan", block: proc { window.application_manager.uninstall(game.id) } }
end
hash["Install Folder"] = { icon: nil, block: proc { window.application_manager.show_folder(game.id, :installation) } }
hash["User Data Folder"] = { icon: nil, block: proc { window.application_manager.show_folder(game.id, :user_data) } }
hash["View Screenshots"] = { icon: nil, block: proc { window.application_manager.show_folder(game.id, :screenshots) } }
}.each do |key, hash|
flow(width: 1.0, height: 22, margin_bottom: 8) do
image "#{GAME_ROOT_PATH}/media/ui_icons/#{hash[:icon]}.png", width: 0.11 if hash[:icon]
image EMPTY_IMAGE, width: 0.11 unless hash[:icon]
link key, text_size: 18 do
hash[:block]&.call
end
end
end
end
game.web_links.each do |item|
flow(width: 1.0, height: 22, margin_bottom: 8) do
image EMPTY_IMAGE, width: 0.11
image "#{GAME_ROOT_PATH}/media/ui_icons/share1.png", width: 0.11
link item.name, text_size: 18 do
Launchy.open(item.uri)
end
@@ -107,10 +128,20 @@ class W3DHub
# item.block&.call(game)
# end
# end
button "<b>Install</b>", margin_left: 24
button "<b>Import</b>", margin_left: 24
button "<b>Play Now</b>", margin_left: 24
button "<b>Single Player</b>", margin_left: 24
if window.application_manager.installed?(game.id)
button "<b>Play Now</b>", margin_left: 24
button "<b>Single Player</b>", margin_left: 24
else
unless game.id == "ren"
button "<b>Install</b>", margin_left: 24 do
window.application_manager.install(game.id)
end
end
button "<b>Import</b>", margin_left: 24 do
window.application_manager.import(game.id, "?")
end
end
end
end
@@ -133,20 +164,6 @@ class W3DHub
if news
news.items[0..9].each do |item|
# Cache Image
# ext = File.basename(item.image).split(".").last
# path = "#{CACHE_PATH}/#{Digest::SHA2.hexdigest(item.image)}.#{ext}"
# next if File.exist?(path)
# response = Excon.get(item.image)
# if response.status == 200
# File.open(path, "wb") do |f|
# f.write(response.body)
# end
# end
Cache.fetch(item.image)
end

View File

@@ -87,9 +87,7 @@ class W3DHub
end
end
ext = File.basename(@host.account.avatar_uri).split(".").last
path = "#{CACHE_PATH}/#{Digest::SHA2.hexdigest(@host.account.avatar_uri)}.#{ext}"
image path, height: 1.0
image Cache.path(@host.account.avatar_uri), height: 1.0
end
end

View File

@@ -163,7 +163,7 @@ class W3DHub
end
stack(width: 1.0, height: 0.25) do
button "<b>Join Server</b>"
button "<b>Join Server</b>", enabled: window.application_manager.installed?(server.game)
end
stack(width: 1.0, height: 0.55, margin_top: 16) do

View File

@@ -22,7 +22,7 @@ class W3DHub
flow(width: 1.0, height: 0.05, padding_left: 16, padding_right: 16, padding_bottom: 8, padding_top: 8) do
@status_label = caption "Starting #{NAME}...", width: 0.5
inscription "W3D Hub Launcher 0.14.0.0", width: 0.5, text_align: :right
inscription "W3D Hub Launcher #{W3DHub::VERSION}", width: 0.5, text_align: :right
end
end
end

View File

@@ -110,7 +110,7 @@ class W3DHub
page(W3DHub::Pages::DownloadManager)
end
inscription "Version 0.14.0.0", margin_left: 16
inscription "Version #{W3DHub::VERSION}", margin_left: 16
end
end

View File

@@ -1,17 +1,24 @@
class W3DHub
class Window < CyberarmEngine::Window
attr_reader :settings
attr_reader :settings, :application_manager
def setup
self.caption = "#{W3DHub::NAME}"
@settings = Settings.new
@application_manager = ApplicationManager.new
@settings.save_settings
push_state(W3DHub::States::Boot)
end
def close
@settings.save_settings
super if @application_manager.idle?
end
def button_down(id)
super

View File

@@ -16,6 +16,7 @@ require_relative "lib/version"
require_relative "lib/window"
require_relative "lib/cache"
require_relative "lib/settings"
require_relative "lib/application_manager"
require_relative "lib/states/boot"
require_relative "lib/states/interface"
@@ -26,14 +27,6 @@ require_relative "lib/api/news"
require_relative "lib/api/server_list_server"
require_relative "lib/api/account"
# require_relative "lib/game"
# require_relative "lib/games/renegade"
# require_relative "lib/games/expansive_civilian_warfare"
# require_relative "lib/games/interim_apex"
# require_relative "lib/games/ra_a_path_beyond"
# require_relative "lib/games/ts_reborn"
# W3DHub::Game.load_games
require_relative "lib/page"
require_relative "lib/pages/games"
require_relative "lib/pages/server_browser"
@@ -42,7 +35,4 @@ require_relative "lib/pages/login"
require_relative "lib/pages/settings"
require_relative "lib/pages/download_manager"
# require_relative "lib/renegade_server"
# require_relative "lib/renegade_player"
W3DHub::Window.new(width: 980, height: 720, borderless: false).show