Files
Bubberstation/code/modules/modular_computers/file_system/programs/ntdownloader.dm
SkyratBot cb3b675bae [MIRROR] Tablets don't close their UI when changing program (and some fixes) [MDB IGNORE] (#19600)
* Tablets don't close their UI when changing program (and some fixes) (#73635)

## About The Pull Request

- Tablets now refresh their page when changing programs, this means the
UI will no longer close and reopen itself several times (or even have
several UIs open if shit broke hard enough).
- Removed tablet's attack self because interact already does everything
it had to do.
- Header programs now close when minimized (as there's no button to
close them in the main menu.
- Removed a lot of program UI stuff, it's now handled by the PC itself,
such as header data and ui host.
- Cut off asset sending from TGUI into it's own proc so I can re-send
assets when changing programs
- Added an ejection button for machine computers
- Fixed ID not ejecting into the user's hand when using 'Eject ID'
- Fixes a minor runtime when opening the MODsuit application without a
MODsuit already connected.

## Why It's Good For The Game

Fixes some bugs that I found with tablets

UIS now won't be flickering as bad in front of them, or have
inconsistent placement (like when you move your main menu UI, go to
Messenger, then it's back to the center of the screen).

Video of it in action

https://user-images.githubusercontent.com/53777086/221301417-78321149-0c10-475e-bd29-79f5a4ba0597.mp4

## Changelog

🆑
fix: Being in an application now properly uses the tablet's battery.
fix: Messenger and Themify apps now close when minimized, so don't count
towards the running app limit.
fix: Tablet UIs will now no longer spam open/close the UI when changing
applications
fix: Using the Eject ID button on tablets now ejects into your hand.
fix: Computers now have an Eject ID button
refactor: Cut down a lot of copy paste in tablet & program code, now
it's mostly done by the tablet.
/🆑

* Tablets don't close their UI when changing program (and some fixes)

* Update contractor_tablet.dm

* wew

---------

Co-authored-by: John Willard <53777086+JohnFulpWillard@users.noreply.github.com>
Co-authored-by: Zonespace <41448081+Zonespace27@users.noreply.github.com>
Co-authored-by: Gandalf <9026500+Gandalf2k15@users.noreply.github.com>
2023-03-10 06:09:10 +00:00

172 lines
5.8 KiB
Plaintext

/datum/computer_file/program/ntnetdownload
filename = "ntsoftwarehub"
filedesc = "NT Software Hub"
program_icon_state = "generic"
extended_desc = "This program allows downloads of software from official NT repositories"
undeletable = TRUE
size = 4
requires_ntnet = TRUE
requires_ntnet_feature = NTNET_SOFTWAREDOWNLOAD
available_on_ntnet = FALSE
ui_header = "downloader_finished.gif"
tgui_id = "NtosNetDownloader"
program_icon = "download"
var/datum/computer_file/program/downloaded_file = null
var/hacked_download = FALSE
var/download_completion = FALSE //GQ of downloaded data.
var/download_netspeed = 0
var/downloaderror = ""
var/list/main_repo
var/list/antag_repo
var/list/show_categories = list(
PROGRAM_CATEGORY_CREW,
PROGRAM_CATEGORY_ENGI,
PROGRAM_CATEGORY_SCI,
PROGRAM_CATEGORY_SUPL,
PROGRAM_CATEGORY_MISC,
)
/datum/computer_file/program/ntnetdownload/on_start()
. = ..()
main_repo = SSmodular_computers.available_station_software
antag_repo = SSmodular_computers.available_antag_software
/datum/computer_file/program/ntnetdownload/proc/begin_file_download(filename)
if(downloaded_file)
return FALSE
var/datum/computer_file/program/PRG = SSmodular_computers.find_ntnet_file_by_name(filename)
if(!PRG || !istype(PRG))
return FALSE
// Attempting to download antag only program, but without having emagged/syndicate computer. No.
if(PRG.available_on_syndinet && !(computer.obj_flags & EMAGGED))
return FALSE
if(!computer || !computer.can_store_file(PRG))
return FALSE
ui_header = "downloader_running.gif"
if(PRG in main_repo)
generate_network_log("Began downloading file [PRG.filename].[PRG.filetype] from NTNet Software Repository.")
hacked_download = FALSE
else if(PRG in antag_repo)
generate_network_log("Began downloading file **ENCRYPTED**.[PRG.filetype] from unspecified server.")
hacked_download = TRUE
else
generate_network_log("Began downloading file [PRG.filename].[PRG.filetype] from unspecified server.")
hacked_download = FALSE
downloaded_file = PRG.clone()
/datum/computer_file/program/ntnetdownload/proc/abort_file_download()
if(!downloaded_file)
return
generate_network_log("Aborted download of file [hacked_download ? "**ENCRYPTED**" : "[downloaded_file.filename].[downloaded_file.filetype]"].")
downloaded_file = null
download_completion = FALSE
ui_header = "downloader_finished.gif"
/datum/computer_file/program/ntnetdownload/proc/complete_file_download()
if(!downloaded_file)
return
generate_network_log("Completed download of file [hacked_download ? "**ENCRYPTED**" : "[downloaded_file.filename].[downloaded_file.filetype]"].")
if(!computer || !computer.store_file(downloaded_file))
// The download failed
downloaderror = "I/O ERROR - Unable to save file. Check whether you have enough free space on your hard drive and whether your hard drive is properly connected. If the issue persists contact your system administrator for assistance."
downloaded_file = null
download_completion = FALSE
ui_header = "downloader_finished.gif"
/datum/computer_file/program/ntnetdownload/process_tick(delta_time)
if(!downloaded_file)
return
if(download_completion >= downloaded_file.size)
complete_file_download()
// Download speed according to connectivity state. NTNet server is assumed to be on unlimited speed so we're limited by our local connectivity
download_netspeed = 0
// Speed defines are found in misc.dm
switch(ntnet_status)
if(1)
download_netspeed = NTNETSPEED_LOWSIGNAL
if(2)
download_netspeed = NTNETSPEED_HIGHSIGNAL
if(3)
download_netspeed = NTNETSPEED_ETHERNET
download_completion += download_netspeed
/datum/computer_file/program/ntnetdownload/ui_act(action, params)
. = ..()
if(.)
return
switch(action)
if("PRG_downloadfile")
if(!downloaded_file)
begin_file_download(params["filename"])
return TRUE
if("PRG_reseterror")
if(downloaderror)
download_completion = FALSE
download_netspeed = FALSE
downloaded_file = null
downloaderror = ""
return TRUE
return FALSE
/datum/computer_file/program/ntnetdownload/ui_data(mob/user)
var/list/data = list()
var/list/access = computer.GetAccess()
data["downloading"] = !!downloaded_file
data["error"] = downloaderror || FALSE
// Download running. Wait please..
if(downloaded_file)
data["downloadname"] = downloaded_file.filename
data["downloaddesc"] = downloaded_file.filedesc
data["downloadsize"] = downloaded_file.size
data["downloadspeed"] = download_netspeed
data["downloadcompletion"] = round(download_completion, 0.1)
data["disk_size"] = computer.max_capacity
data["disk_used"] = computer.used_capacity
data["emagged"] = (computer.obj_flags & EMAGGED)
var/list/repo = antag_repo | main_repo
var/list/program_categories = list()
for(var/datum/computer_file/program/programs as anything in repo)
if(!(programs.category in program_categories))
program_categories.Add(programs.category)
data["programs"] += list(list(
"icon" = programs.program_icon,
"filename" = programs.filename,
"filedesc" = programs.filedesc,
"fileinfo" = programs.extended_desc,
"category" = programs.category,
"installed" = !!computer.find_file_by_name(programs.filename),
"compatible" = check_compatibility(programs),
"size" = programs.size,
"access" = (computer.obj_flags & EMAGGED) && programs.available_on_syndinet ? TRUE : programs.can_run(user,transfer = TRUE, access = access),
"verifiedsource" = programs.available_on_ntnet,
))
data["categories"] = show_categories & program_categories
return data
/datum/computer_file/program/ntnetdownload/proc/check_compatibility(datum/computer_file/program/P)
var/hardflag = computer.hardware_flag
if(P?.is_supported_by_hardware(hardware_flag = hardflag, loud = FALSE))
return TRUE
return FALSE
/datum/computer_file/program/ntnetdownload/kill_program(forced)
abort_file_download()
return ..()