Files
Bubberstation/code/modules/modular_computers/computers/item/computer_ui.dm
SkyratBot b1aefe3a74 [MIRROR] pdas now use their cells more [MDB IGNORE] (#23977)
* pdas now use their cells more (#78580)

## About The Pull Request

So one aspect of PDAs that I quite liked previously was managing and
upgrading your power.
This was lost when all cell parts got removed, mostly, and now I'd like
to re-add it.
PDAs and Tablets now use more power each second it's on
Programs being active/idle now take charge too.
And all this now takes ``seconds_per_tick`` into account.

Screenshots of APC use before and after having 6 programs open at once

![image](https://github.com/tgstation/tgstation/assets/53777086/14699ae7-19a7-4eb6-a211-5944cc1867d0)

![image](https://github.com/tgstation/tgstation/assets/53777086/804fedde-0d5a-43a9-9e61-34139257a16f)

PDA default power cells have a max charge of 1000, each cell use is
around ``1.00970340315`` power, which is ``1.01013789399`` w/ 2 programs
in idle and 1 active program (which is what PDAs are capable of). This
means it takes about 990 ticks to fully drain your power, or about 50
minutes, at max use.

This is completely blasted away the moment you put anything beyond a t1
cell inside of it, which is unfortunate but what can you do about tiered
parts being so poor.

The problem of no public PDA chargers are alleviated by
https://github.com/tgstation/tgstation/pull/78600

### Update

The PDA flashlight being on now also drains the battery 25% times
faster. PDA running out of charge now also turns the flashlight off.

## Why It's Good For The Game

You may or may not have to actually charge your PDA once in a round now,
maybe. I liked this part of tablets and would like to see it brought
back, managing your power to use your apps is important to ensure you're
not just using all apps 24/7

Because this also adds the functionality to add/remove power cells
again, it opens up to some minor little pranks/messing with people that
isn't completely destroying their tools, as well as some minor
upgradeability.

## Changelog

🆑
balance: You can now remove and replace power cells from PDAs (with
screwdriver).
balance: PDAs now drain their power cells harder, and also take into
account active programs & their flashlight being on.
balance: PDAs running out of charge now turn their flashlights off.
/🆑

* pdas now use their cells more

* reduce power usage

* Update computer.dm

---------

Co-authored-by: John Willard <53777086+JohnFulpWillard@users.noreply.github.com>
Co-authored-by: lessthanthree <83487515+lessthnthree@users.noreply.github.com>
2023-10-06 21:54:55 -07:00

234 lines
6.2 KiB
Plaintext

/**
* update_tablet_open_uis
*
* Will search the user to see if they have the tablet open.
* If they don't, we'll open a new UI depending on the tab the tablet is meant to be on.
* If they do, we'll update the interface and title, then update all static data and re-send assets.
*
* This is best called when you're actually changing the app, as we don't check
* if we're swapping to the current UI repeatedly.
* Args:
* user - The person whose UI we're updating.
*/
/obj/item/modular_computer/proc/update_tablet_open_uis(mob/user)
var/datum/tgui/active_ui = SStgui.get_open_ui(user, src)
if(!active_ui)
if(active_program)
active_ui = new(user, src, active_program.tgui_id, active_program.filedesc)
active_program.ui_interact(user, active_ui)
else
active_ui = new(user, src, "NtosMain")
return active_ui.open()
for (var/datum/tgui/window as anything in open_uis)
if(active_program)
window.interface = active_program.tgui_id
window.title = active_program.filedesc
active_program.ui_interact(user, window)
else
window.interface = "NtosMain"
window.send_assets()
update_static_data_for_all_viewers()
/obj/item/modular_computer/ui_state(mob/user)
if(inserted_pai && (user == inserted_pai.pai))
return GLOB.contained_state
return ..()
/obj/item/modular_computer/interact(mob/user)
if(enabled)
ui_interact(user)
else
turn_on(user)
// Operates TGUI
/obj/item/modular_computer/ui_interact(mob/user, datum/tgui/ui)
if(!enabled || !user.can_read(src, READING_CHECK_LITERACY))
if(ui)
ui.close()
return
// Robots don't really need to see the screen, their wireless connection works as long as computer is on.
if(!screen_on && !issilicon(user))
if(ui)
ui.close()
return
if(honkvirus_amount > 0) // EXTRA annoying, huh!
honkvirus_amount--
playsound(src, 'sound/items/bikehorn.ogg', 30, TRUE)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
update_tablet_open_uis(user)
/obj/item/modular_computer/ui_assets(mob/user)
var/list/data = list()
data += get_asset_datum(/datum/asset/simple/headers)
if(active_program)
data += active_program.ui_assets(user)
return data
/obj/item/modular_computer/ui_static_data(mob/user)
var/list/data = list()
if(active_program)
data += active_program.ui_static_data(user)
return data
data["show_imprint"] = istype(src, /obj/item/modular_computer/pda)
return data
/obj/item/modular_computer/ui_data(mob/user)
var/list/data = get_header_data()
if(active_program)
data += active_program.ui_data(user)
return data
data["pai"] = inserted_pai
data["has_light"] = has_light
data["light_on"] = light_on
data["comp_light_color"] = comp_light_color
data["login"] = list(
IDName = saved_identification || "Unknown",
IDJob = saved_job || "Unknown",
)
data["proposed_login"] = list(
IDName = computer_id_slot?.registered_name,
IDJob = computer_id_slot?.assignment,
)
data["removable_media"] = list()
if(inserted_disk)
data["removable_media"] += "Eject Disk"
var/datum/computer_file/program/ai_restorer/airestore_app = locate() in stored_files
if(airestore_app?.stored_card)
data["removable_media"] += "intelliCard"
data["programs"] = list()
for(var/datum/computer_file/program/program in stored_files)
data["programs"] += list(list(
"name" = program.filename,
"desc" = program.filedesc,
"header_program" = program.header_program,
"running" = !!(program in idle_threads),
"icon" = program.program_icon,
"alert" = program.alert_pending,
))
return data
// Handles user's GUI input
/obj/item/modular_computer/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
. = ..()
if(.)
return
if(ishuman(usr) && !allow_chunky)
var/mob/living/carbon/human/human_user = usr
if(human_user.check_chunky_fingers())
balloon_alert(human_user, "fingers are too big!")
return TRUE
switch(action)
if("PC_exit")
active_program.kill_program(usr)
return TRUE
if("PC_shutdown")
shutdown_computer()
return TRUE
if("PC_minimize")
if(!active_program)
return
active_program.background_program()
return TRUE
if("PC_killprogram")
var/prog = params["name"]
var/datum/computer_file/program/killed_program = find_file_by_name(prog)
if(!istype(killed_program))
return
killed_program.kill_program(usr)
to_chat(usr, span_notice("Program [killed_program.filename].[killed_program.filetype] with PID [rand(100,999)] has been killed."))
return TRUE
if("PC_runprogram")
open_program(usr, find_file_by_name(params["name"]))
return TRUE
if("PC_toggle_light")
toggle_flashlight()
return TRUE
if("PC_light_color")
var/mob/user = usr
var/new_color
while(!new_color)
new_color = input(user, "Choose a new color for [src]'s flashlight.", "Light Color",light_color) as color|null
if(!new_color)
return
if(is_color_dark(new_color, 50) ) //Colors too dark are rejected
to_chat(user, span_warning("That color is too dark! Choose a lighter one."))
new_color = null
set_flashlight_color(new_color)
return TRUE
if("PC_Eject_Disk")
var/param = params["name"]
var/mob/user = usr
switch(param)
if("Eject Disk")
if(!inserted_disk)
return
user.put_in_hands(inserted_disk)
inserted_disk = null
playsound(src, 'sound/machines/card_slide.ogg', 50)
return TRUE
if("intelliCard")
var/datum/computer_file/program/ai_restorer/airestore_app = locate() in stored_files
if(!airestore_app)
return
if(airestore_app.try_eject(user))
playsound(src, 'sound/machines/card_slide.ogg', 50)
return TRUE
if("ID")
if(RemoveID(user))
playsound(src, 'sound/machines/card_slide.ogg', 50)
return TRUE
if("PC_Imprint_ID")
imprint_id()
UpdateDisplay()
playsound(src, 'sound/machines/terminal_processing.ogg', 15, TRUE)
if("PC_Pai_Interact")
switch(params["option"])
if("eject")
if(!ishuman(usr))
return
remove_pai(usr)
if("interact")
inserted_pai.attack_self(usr)
return TRUE
if(active_program)
return active_program.ui_act(action, params, ui, state)
/obj/item/modular_computer/ui_host()
if(physical)
return physical
return src
/obj/item/modular_computer/ui_close(mob/user)
. = ..()
if(active_program)
active_program.ui_close(user)