Added confirm dialog, clicking uninstall game now triggers confirmation

This commit is contained in:
2021-11-25 19:08:20 -06:00
parent e7ada9d800
commit 4e30075f6b
4 changed files with 63 additions and 4 deletions

View File

@@ -123,8 +123,8 @@ class W3DHub
# /apis/w3dhub/1/get-news
# Client sends an Authorization header bearer token which is received from logging in (Optional)
# Client requests news for a specific application/game e.g.: data={"category":"ia"}
# Response is a JSON hash with a "highlighted" and "news" keys; the "news" on seems to be the desired one
# Client requests news for a specific application/game e.g.: data={"category":"ia"} ("launcher-home" retrieves the weekly hub updates)
# Response is a JSON hash with a "highlighted" and "news" keys; the "news" one seems to be the desired one
def self.news(category)
response = W3DHUB_API_CONNECTION.post(
path: "apis/w3dhub/1/get-news",

View File

@@ -84,11 +84,20 @@ class W3DHub
end
def uninstall(app_id, channel)
puts "Uninstall Request: #{app_idchannel}"
puts "Uninstall Request: #{app_id} #{channel}"
return false if !installed?(app_id, channel) || installing?(app_id, channel)
@tasks.push(Uninstaller.new(app_id, channel))
return false unless (game = Store.applications.games.find { |g| g.id == app_id})
push_state(
States::ConfirmDialog,
title: "Uninstall #{game.name}?",
message: "Are you sure you want to uninstall #{game.name} (#{channel})?",
accept_callback: proc {
@tasks.push(Uninstaller.new(app_id, channel))
}
)
end
def show_folder(app_id, channel, type)

View File

@@ -0,0 +1,49 @@
class W3DHub
class States
class ConfirmDialog < CyberarmEngine::GuiState
def setup
window.show_cursor = true
theme(W3DHub::THEME)
background 0xee_444444
stack(width: 1.0, height: 1.0, margin: 128, 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
def draw
previous_state&.draw
Gosu.flush
super
end
end
end
end

View File

@@ -44,6 +44,7 @@ require_relative "lib/states/boot"
require_relative "lib/states/interface"
require_relative "lib/states/message_dialog"
require_relative "lib/states/prompt_dialog"
require_relative "lib/states/confirm_dialog"
require_relative "lib/api"
require_relative "lib/api/service_status"