Skip to content

Commit

Permalink
Adds TGUI to the auxiliary console (vlggms#1995)
Browse files Browse the repository at this point in the history
* boop

* The linters forced me to change this into a worse version

fucking robots man

* admin-only debug options

* less clicking, more control to admins adding/removing LOB points

* satisfying the linter overlords

* slightly better

* less copypaste

* better variable handling, and better action control for admins

* better core unlocking, admins bypass TGUI checks

* more admin core stuff

* fancy core supression text, static core info

* hate

* actually, this works

* requested Cox's font

* adds gebura trim

* le fixes

* better admin LOB point manipulation

* okay single-quote

* boop

* admins completelly bypass TGUI checks, text fixes

* bweh, 80 characters limit my behated

* better logging

* selectable cores

* linters my beloved <3

* some flavoring, spicing even

* minor fixes

* the forbidden plushie update (revert later, probably)

* fix maybe?

* available > avaible
  • Loading branch information
Gboster-0 authored Apr 22, 2024
1 parent f52a0f0 commit 5ce7102
Show file tree
Hide file tree
Showing 3 changed files with 886 additions and 1 deletion.
365 changes: 364 additions & 1 deletion code/game/machinery/computer/abnormality_auxiliary.dm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
)
var/datum/suppression/selected_core_type = null

// toggles if the window being opened is TGUI or UI, players can toggle it in case TGUI fails to load
var/TGUI_mode = TRUE

/obj/machinery/computer/abnormality_auxiliary/Initialize()
. = ..()
GLOB.lobotomy_devices += src
Expand All @@ -25,8 +28,25 @@
GLOB.lobotomy_devices -= src
..()

/obj/machinery/computer/abnormality_auxiliary/ui_interact(mob/user)
/obj/machinery/computer/abnormality_auxiliary/AltClick(mob/user) // toggles if the UI is using TGUI or not
. = ..()
// If we dont close them, some things can be weird
SStgui.close_uis(src)
TGUI_mode = !TGUI_mode
say("[TGUI_mode ? "Turned on" : "Turned off"] TGUI mode")
playsound(get_turf(src), 'sound/machines/terminal_prompt_confirm.ogg', 50, TRUE)

/obj/machinery/computer/abnormality_auxiliary/ui_interact(mob/user, datum/tgui/ui)
. = ..()
if(TGUI_mode)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
to_chat(user, span_notice("If TGUI is failing to load, you can alt+click the console to switch to UI mode"))
ui = new(user, src, "AuxiliaryManagerConsole")
ui.open()
ui.set_autoupdate(TRUE)
return

var/dat
for(var/p in all_pages)
dat += "<A href='byond://?src=[REF(src)];set_page=[p]'>[p == page ? "<b><u>[p]</u></b>" : "[p]"]</A>"
Expand Down Expand Up @@ -81,6 +101,7 @@
. = ..()
if(.)
return .

if(ishuman(usr))
usr.set_machine(src)
add_fingerprint(usr)
Expand Down Expand Up @@ -135,3 +156,345 @@

#undef CORE_SUPPRESSIONS
#undef FACILITY_UPGRADES

// TGUI stuff onwards, all beware ye who enter

// gather all the assets needed for optional decorative stuff
/datum/asset/simple/sephirah
assets = list(
// upper layer

"SEPHIRAH.yellow.png" = icon('icons/obj/plushes.dmi', "malkuth"),
"SEPHIRAH.purple.png" = icon('icons/obj/plushes.dmi', "yesod"),
"SEPHIRAH.green.png" = icon('icons/obj/plushes.dmi', "netzach"),
"SEPHIRAH.orange.png" = icon('icons/obj/plushes.dmi', "hod"),

// middle layer

// command overriden
"SEPHIRAH.blue.png" = icon('icons/obj/plushes.dmi', "chesed"),
"SEPHIRAH.red.png" = icon('icons/obj/plushes.dmi', "gebura"),

// lower layer

// extraction overriden
"SEPHIRAH.white.png" = icon('icons/obj/plushes.dmi', "hokma"),

// icon overrides

"SEPHIRAH.AYIN.png" = icon('icons/obj/plushes.dmi', "ayin"), // fuck you *turns ayin into a sephirah*
"SEPHIRAH.TWINS.png" = icon('icons/obj/plushes.dmi', "lisa"),
"SEPHIRAH.BINAH.png" = icon('icons/obj/plushes.dmi', "binah"),

)

/obj/machinery/computer/abnormality_auxiliary/ui_assets(mob/user)
return list(
get_asset_datum(/datum/asset/simple/sephirah),
)

/obj/machinery/computer/abnormality_auxiliary/ui_data(mob/user)
. = ..()
var/list/data = list()

// start facility upgrade info
data["Upgrade_points"] = round(SSlobotomy_corp.lob_points, 0.1)

// preferably this would be in static, but the cost and avaibility needs to be updated whenever an action is performed

var/list/bullet_upgrades = list()
var/list/real_bullet_upgrades = list()
var/list/agent_upgrades = list()
var/list/abnormality_upgrades = list()
var/list/you_didnt_give_it_a_proper_category_dammit_upgrades = list()

for(var/thing in SSlobotomy_corp.upgrades)
var/datum/facility_upgrade/upgrade = thing
if(!upgrade.CanShowUpgrade())
continue

var/available = TRUE
if(upgrade.value >= upgrade.max_value)
available = FALSE

var/modified_upgrade_name
if(upgrade.value == 0) // if the upgrade is just a toggle, there's no point in showing its value now, is there?
modified_upgrade_name = upgrade.name
else
modified_upgrade_name = "[upgrade.name] ([upgrade.value])"


var/list/upgrade_data = list(list(
"name" = modified_upgrade_name,
"ref" = REF(upgrade),
"cost" = upgrade.cost,
"available" = available,
))


var/upgrade_category = upgrade.category
switch(upgrade_category) // sort them into different lists depending on what category they fit in
if("Bullets")
bullet_upgrades += upgrade_data

if("Bullet Upgrades")
real_bullet_upgrades += upgrade_data

if("Agent")
agent_upgrades += upgrade_data

if("Abnormalities")
abnormality_upgrades += upgrade_data

else
you_didnt_give_it_a_proper_category_dammit_upgrades += upgrade_data

data["bullet_upgrades"] = bullet_upgrades
data["real_bullet_upgrades"] = real_bullet_upgrades
data["agent_upgrades"] = agent_upgrades
data["abnormality_upgrades"] = abnormality_upgrades
data["misc_upgrades"] = you_didnt_give_it_a_proper_category_dammit_upgrades
// end facility upgrade info

return data


/obj/machinery/computer/abnormality_auxiliary/ui_static_data(mob/user)
. = ..()
var/list/data = list()

// start core suppression info
data["current_suppression"] = FALSE // if the type check fails, we send FALSE instead
if(istype(SSlobotomy_corp.core_suppression))
var/core_suppression_name = SSlobotomy_corp.core_suppression.name

data["current_suppression"] = core_suppression_name
data["selected_core_color"] = "red"
var/icon_override = FALSE // normally the assets are fetched via the color of the core being supressed, this overrides it
switch(core_suppression_name) // we choose the core's color once its locked in place here, the mother of all switches
// upper layer
if(CONTROL_CORE_SUPPRESSION)
data["selected_core_color"] = "yellow"

if(INFORMATION_CORE_SUPPRESSION)
data["selected_core_color"] = "purple"

if(SAFETY_CORE_SUPPRESSION)
data["selected_core_color"] = "green"

if(TRAINING_CORE_SUPPRESSION)
data["selected_core_color"] = "orange"

// middle layer

if(COMMAND_CORE_SUPPRESSION)
data["selected_core_color"] = "yellow"
icon_override = "TWINS"

if(WELFARE_CORE_SUPPRESSION)
data["selected_core_color"] = "blue"

if(DISCIPLINARY_CORE_SUPPRESSION)
data["selected_core_color"] = "red"

// bottom layer
if(EXTRACTION_CORE_SUPPRESSION)
data["selected_core_color"] = "yellow"
icon_override = "BINAH"

if(RECORDS_CORE_SUPPRESSION)
data["selected_core_color"] = "white"

// literal hell layer

// should divide them and give them colors later, but no clue what they could have for now
if(DAY46_CORE_SUPPRESSION, DAY47_CORE_SUPPRESSION, DAY48_CORE_SUPPRESSION, DAY49_CORE_SUPPRESSION, DAY50_CORE_SUPPRESSION)
data["selected_core_color"] = "white"
icon_override = "AYIN"

// you didnt set a proper core layer
else
data["selected_core_color"] = "red"

if(icon_override)
data["selected_core_icon"] = "SEPHIRAH.[icon_override].png"
else
data["selected_core_icon"] = "SEPHIRAH.[data["selected_core_color"]].png"

if(ispath(selected_core_type))
data["selected_core_name"] = initial(selected_core_type.name)
data["selected_core_description"] = initial(selected_core_type.desc)
data["selected_core_goal"] = initial(selected_core_type.goal_text)
data["selected_core_reward"] = initial(selected_core_type.reward_text)

var/list/available_suppressions = list()
for(var/core_type in SSlobotomy_corp.available_core_suppressions)
var/datum/suppression/core_suppression = core_type
available_suppressions += list(list(
"name" = core_suppression.name,
"ref" = REF(core_suppression),
))

data["available_suppressions"] = available_suppressions

var/list/pre_made_core_suppressions = subtypesof(/datum/suppression)
var/list/all_core_suppressions = list()
for(var/core_type in pre_made_core_suppressions)
var/datum/suppression/core_suppression = core_type
all_core_suppressions += list(list(
"name" = core_suppression.name,
"ref" = REF(core_suppression),
))

data["all_core_suppressions"] = all_core_suppressions
// end core suppression info

var/is_admin
if(user.client.holder)
is_admin = TRUE
else
is_admin = FALSE

data["is_admin"] = is_admin // used to determine if we unlock special admin-only options

return data


/obj/machinery/computer/abnormality_auxiliary/ui_act(action, list/params)
. = ..()
if(. && !usr.client.holder) // the usr.client.holder check allows admins to bypass the typical TGUI proximity checks
return

switch(action)
if("Select Core Suppression") // selects a core suppression
var/core_suppression = locate(params["selected_core"]) in SSlobotomy_corp.available_core_suppressions
if(!ispath(core_suppression) || !(core_suppression in SSlobotomy_corp.available_core_suppressions))
return

selected_core_type = core_suppression
say("[initial(selected_core_type.name)] has been selected!")
playsound(get_turf(src), 'sound/machines/terminal_prompt_confirm.ogg', 50, TRUE)
update_static_data_for_all_viewers()

if("Activate Core Suppression") // activates the currently selected core suppression
if(!ispath(selected_core_type) || !(selected_core_type in SSlobotomy_corp.available_core_suppressions))
return
if(istype(SSlobotomy_corp.core_suppression))
CRASH("[src] has attempted to activate a core suppression via TGUI whilst its not possible!")

log_action(usr,
message_override = "[usr] has started the [initial(selected_core_type.name)] core suppression"
)

say("[initial(selected_core_type.name)] protocol activated, good luck manager.")
SSlobotomy_corp.core_suppression = new selected_core_type
SSlobotomy_corp.core_suppression.legitimate = TRUE
SSlobotomy_corp.available_core_suppressions = list()
selected_core_type = null
playsound(get_turf(src), 'sound/machines/terminal_prompt_confirm.ogg', 50, TRUE)
addtimer(CALLBACK(SSlobotomy_corp.core_suppression, TYPE_PROC_REF(/datum/suppression, Run)), 2 SECONDS)
update_static_data_for_all_viewers()

if("Buy Upgrade") // Buys an upgrade, looking for a parameter that is given to the upgrade thats being bought on the TGUI side
var/datum/facility_upgrade/U = locate(params["selected_upgrade"]) in SSlobotomy_corp.upgrades
if(!istype(U) || !U.CanUpgrade())
return

log_action(usr,
message_override = "[usr] has purchased the [U.name] facility upgrade"
)
U.Upgrade()
playsound(get_turf(src), 'sound/machines/terminal_prompt_confirm.ogg', 50, TRUE)

// admin-only actions, remember to put a if(!log_action) check with a proper return
if("Unlock Core Suppressions")
if(!log_action(usr, admin_action = TRUE,
message_override = "[usr] has used admin powers to manipulate the available cores in the auxiliary console"
))
update_static_data_for_all_viewers()
return

var/core_to_unlock = params["core_unlock"]

if(core_to_unlock != 1)
var/list/all_cores = subtypesof(/datum/suppression)
var/selected_core = locate(params["core_unlock"]) in all_cores

SSlobotomy_corp.available_core_suppressions += selected_core

else // unlock all of them if the core to unlock is not specified
SSlobotomy_corp.available_core_suppressions = subtypesof(/datum/suppression)

update_static_data_for_all_viewers()

if("Disable Core Suppression")
if(istype(SSlobotomy_corp.core_suppression) || !LAZYLEN(SSlobotomy_corp.available_core_suppressions))
message_admins("[usr] has tried to disable all core suppressions but there were none, all admins laugh at them!")
return

if(!log_action(usr, admin_action = TRUE,
message_override = "[usr] has used admin powers to disable all core suppressions!"
))
update_static_data_for_all_viewers()
return

SSlobotomy_corp.ResetPotentialSuppressions()
update_static_data_for_all_viewers()

if("End Core Suppression")
if(!log_action(usr, admin_action = TRUE,
message_override = "[usr] has used admin powers to end the current core suppression (persistence not saved)"
))
update_static_data_for_all_viewers()
return

SSlobotomy_corp.core_suppression.legitimate = FALSE // let admins mess around without worrying about persistence
SSlobotomy_corp.core_suppression.End()
update_static_data_for_all_viewers()

if("Change LOB Points")
var/amount = params["LOB_amount"]
if(!log_action(usr, admin_action = TRUE,
message_override = "[usr] has used admin powers to [amount > 0 ? "add" : "remove"] [amount] LOB point[(amount > 1 || amount < -1) ? "s" : ""] in the auxiliary console"
))
update_static_data_for_all_viewers()
return

SSlobotomy_corp.lob_points += amount

else // something bad happened, refresh the data and it hopefully fixes itself
update_static_data_for_all_viewers()

/**
* Logs interactions with the console
*
* arguments:
* (required) console_user = the user that is using the console (usr)
* (optional) admin_action = if the current action should be restricted for only admins
* (optional/required) message_override = if set on any value other than FALSE, the logging message will be replaced by it
*/
/obj/machinery/computer/abnormality_auxiliary/proc/log_action(mob/console_user, admin_action = FALSE, message_override = FALSE)
if(!console_user)
CRASH("user not provided in (/obj/machinery/computer/abnormality_auxiliary/proc/log_action)")

if(!admin_action)
if(message_override)
log_game(message_override)
message_admins(message_override)
return TRUE
else // if you are going to use it on non-admin actions, you need a message because we have actually no clue whats happening
CRASH("message_override not set up on a non-admin action within the TGUI auxiliary console whilst its mandatory!")

var/is_admin = console_user.client.holder
if(!is_admin)
message_admins("[usr] has used an admin-only option in the auxiliary console TGUI whilst not an admin!")
return FALSE

if(message_override)
log_game(message_override)
message_admins(message_override)
return TRUE

log_game("[usr] has used admin powers to trigger an admin-only action in the auxiliary console")
message_admins("[usr] has used admin powers to trigger an admin-only action in the auxiliary console")
return TRUE
Loading

0 comments on commit 5ce7102

Please sign in to comment.