Files
Bubberstation/code/_onclick/hud/hud.dm
SkyratBot 124ddd7cca [MIRROR] tgui Preferences Menu + total rewrite of the preferences backend (#8153)
* tgui Preferences Menu + total rewrite of the preferences backend

* nah, we dont need to ping those people

* trying to remove the funny stuff

* unmodularizing this

* prefs reset

* this may need to be reverted, who knows

* okay, this part

* perhaps

* EEEEEEEEE

* unsanitary

* E

* Stage 1 + loadout system

* more fixes

* E

* I mean, it launches?

* More fixes and reorganisation

* E

* customisation code is spaget.

* disable ERP prefs

* Update erp_preferences.dm

* Update erp_preferences.dm

* E

* Slowly getting there

* It may be time for help :)

* tri...colors... help

* preferences now pass preferences

* Update dna.dm

* Fuck this man

* missing savefile return, set_species works, removed dumb stuff from updateappearance

* https://github.com/Skyrat-SS13/Skyrat-tg/pull/8199

* https://github.com/Skyrat-SS13/Skyrat-tg/pull/8224

* https://github.com/tgstation/tgstation/pull/61519

* https://github.com/Skyrat-SS13/Skyrat-tg/pull/8278

* e

* le butonAZARAK HELLO

* hhh

* Proper recognition where it's due, MrMelbert!

* EEEE

* examine block

* Better gen hit sounds from whitedream

* final loadout touches, more bug fixes im sure to come

* i said there would be bugfixes

* Update LoadoutManager.js

* Missing preferences in the html menu

* LIVE TESTING PHASE BABY

* Update LoadoutManager.js

* EEE

* LAUNCH TEST FIRE

* Update job.dm

* Update new_player.dm

* 50gb DAY ONE PATCH

* EEE

* Update preferences.dm

* buggle fixes

* Update examine.dm

* >LOOC starts on

Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com>
Co-authored-by: jjpark-kb <55967837+jjpark-kb@users.noreply.github.com>
Co-authored-by: Gandalf <jzo123@hotmail.com>
Co-authored-by: Azarak <azarak10@gmail.com>
2021-09-23 00:40:37 +01:00

352 lines
12 KiB
Plaintext

/*
The hud datum
Used to show and hide huds for all the different mob types,
including inventories and item quick actions.
*/
// The default UI style is the first one in the list
GLOBAL_LIST_INIT(available_ui_styles, list(
"Midnight" = 'icons/hud/screen_midnight.dmi',
"Retro" = 'icons/hud/screen_retro.dmi',
"Plasmafire" = 'icons/hud/screen_plasmafire.dmi',
"Slimecore" = 'icons/hud/screen_slimecore.dmi',
"Operative" = 'icons/hud/screen_operative.dmi',
"Clockwork" = 'icons/hud/screen_clockwork.dmi',
"Glass" = 'icons/hud/screen_glass.dmi'
))
/proc/ui_style2icon(ui_style)
return GLOB.available_ui_styles[ui_style] || GLOB.available_ui_styles[GLOB.available_ui_styles[1]]
/datum/hud
var/mob/mymob
var/hud_shown = TRUE //Used for the HUD toggle (F12)
var/hud_version = HUD_STYLE_STANDARD //Current displayed version of the HUD
var/inventory_shown = FALSE //Equipped item inventory
var/hotkey_ui_hidden = FALSE //This is to hide the buttons that can be used via hotkeys. (hotkeybuttons list of buttons)
var/atom/movable/screen/ling/chems/lingchemdisplay
var/atom/movable/screen/ling/sting/lingstingdisplay
var/atom/movable/screen/ammo_counter //SKYRAT EDIT ADDITION
var/atom/movable/screen/blobpwrdisplay
var/atom/movable/screen/alien_plasma_display
var/atom/movable/screen/alien_queen_finder
var/atom/movable/screen/combo/combo_display
var/atom/movable/screen/action_intent
var/atom/movable/screen/zone_select
var/atom/movable/screen/pull_icon
var/atom/movable/screen/rest_icon
var/atom/movable/screen/throw_icon
var/atom/movable/screen/module_store_icon
var/list/static_inventory = list() //the screen objects which are static
var/list/toggleable_inventory = list() //the screen objects which can be hidden
var/list/atom/movable/screen/hotkeybuttons = list() //the buttons that can be used via hotkeys
var/list/infodisplay = list() //the screen objects that display mob info (health, alien plasma, etc...)
var/list/screenoverlays = list() //the screen objects used as whole screen overlays (flash, damageoverlay, etc...)
var/list/inv_slots[SLOTS_AMT] // /atom/movable/screen/inventory objects, ordered by their slot ID.
var/list/hand_slots // /atom/movable/screen/inventory/hand objects, assoc list of "[held_index]" = object
var/list/atom/movable/screen/plane_master/plane_masters = list() // see "appearance_flags" in the ref, assoc list of "[plane]" = object
///Assoc list of controller groups, associated with key string group name with value of the plane master controller ref
var/list/atom/movable/plane_master_controller/plane_master_controllers = list()
///UI for screentips that appear when you mouse over things
var/atom/movable/screen/screentip/screentip_text
/// Whether or not screentips are enabled.
/// This is updated by the preference for cheaper reads than would be
/// had with a proc call, especially on one of the hottest procs in the
/// game (MouseEntered).
var/screentips_enabled = TRUE
/// The color to use for the screentips.
/// This is updated by the preference for cheaper reads than would be
/// had with a proc call, especially on one of the hottest procs in the
/// game (MouseEntered).
var/screentip_color
var/atom/movable/screen/movable/action_button/hide_toggle/hide_actions_toggle
var/action_buttons_hidden = FALSE
var/atom/movable/screen/healths
var/atom/movable/screen/healthdoll
var/atom/movable/screen/internals
var/atom/movable/screen/wanted/wanted_lvl
var/atom/movable/screen/spacesuit
// subtypes can override this to force a specific UI style
var/ui_style
/datum/hud/New(mob/owner)
mymob = owner
if (!ui_style)
// will fall back to the default if any of these are null
ui_style = ui_style2icon(owner.client?.prefs?.read_preference(/datum/preference/choiced/ui_style))
hide_actions_toggle = new
hide_actions_toggle.InitialiseIcon(src)
if(mymob.client)
hide_actions_toggle.locked = mymob.client.prefs.read_preference(/datum/preference/toggle/buttons_locked)
hand_slots = list()
for(var/mytype in subtypesof(/atom/movable/screen/plane_master))
var/atom/movable/screen/plane_master/instance = new mytype()
plane_masters["[instance.plane]"] = instance
instance.backdrop(mymob)
var/datum/preferences/preferences = owner?.client?.prefs
screentip_color = preferences?.read_preference(/datum/preference/color/screentip_color)
screentips_enabled = preferences?.read_preference(/datum/preference/toggle/enable_screentips)
screentip_text = new(null, src)
static_inventory += screentip_text
for(var/mytype in subtypesof(/atom/movable/plane_master_controller))
var/atom/movable/plane_master_controller/controller_instance = new mytype(src)
plane_master_controllers[controller_instance.name] = controller_instance
owner.overlay_fullscreen("see_through_darkness", /atom/movable/screen/fullscreen/see_through_darkness)
/datum/hud/Destroy()
if(mymob.hud_used == src)
mymob.hud_used = null
QDEL_NULL(hide_actions_toggle)
QDEL_NULL(module_store_icon)
QDEL_LIST(static_inventory)
inv_slots.Cut()
action_intent = null
zone_select = null
pull_icon = null
QDEL_LIST(toggleable_inventory)
//SKYRAT EDIT ADDITION BEGIN - ERP_SLOT_SYSTEM
QDEL_LIST(ERP_toggleable_inventory) // Destroy ERP stuff
//SKYRAT EDIT ADDITION END
QDEL_LIST(hotkeybuttons)
throw_icon = null
QDEL_LIST(infodisplay)
healths = null
healthdoll = null
wanted_lvl = null
internals = null
spacesuit = null
lingchemdisplay = null
lingstingdisplay = null
blobpwrdisplay = null
alien_plasma_display = null
alien_queen_finder = null
combo_display = null
QDEL_LIST_ASSOC_VAL(plane_masters)
QDEL_LIST_ASSOC_VAL(plane_master_controllers)
QDEL_LIST(screenoverlays)
mymob = null
QDEL_NULL(screentip_text)
return ..()
/mob/proc/create_mob_hud()
if(!client || hud_used)
return
hud_used = new hud_type(src)
update_sight()
SEND_SIGNAL(src, COMSIG_MOB_HUD_CREATED)
//Version denotes which style should be displayed. blank or 0 means "next version"
/datum/hud/proc/show_hud(version = 0, mob/viewmob)
if(!ismob(mymob))
return FALSE
var/mob/screenmob = viewmob || mymob
if(!screenmob.client)
return FALSE
screenmob.client.screen = list()
screenmob.client.apply_clickcatcher()
var/display_hud_version = version
if(!display_hud_version) //If 0 or blank, display the next hud version
display_hud_version = hud_version + 1
if(display_hud_version > HUD_VERSIONS) //If the requested version number is greater than the available versions, reset back to the first version
display_hud_version = 1
switch(display_hud_version)
if(HUD_STYLE_STANDARD) //Default HUD
hud_shown = TRUE //Governs behavior of other procs
if(static_inventory.len)
screenmob.client.screen += static_inventory
if(toggleable_inventory.len && screenmob.hud_used && screenmob.hud_used.inventory_shown)
screenmob.client.screen += toggleable_inventory
//SKYRAT EDIT ADDITION BEGIN - ERP_SLOT_SYSTEM
if(ERP_toggleable_inventory.len && screenmob.hud_used && screenmob.hud_used.ERP_inventory_shown && screenmob.client?.prefs?.read_preference(/datum/preference/toggle/erp/sex_toy))
screenmob.client.screen += ERP_toggleable_inventory
//SKYRAT EDIT ADDITION END
if(hotkeybuttons.len && !hotkey_ui_hidden)
screenmob.client.screen += hotkeybuttons
if(infodisplay.len)
screenmob.client.screen += infodisplay
screenmob.client.screen += hide_actions_toggle
if(action_intent)
action_intent.screen_loc = initial(action_intent.screen_loc) //Restore intent selection to the original position
if(HUD_STYLE_REDUCED) //Reduced HUD
hud_shown = FALSE //Governs behavior of other procs
if(static_inventory.len)
screenmob.client.screen -= static_inventory
if(toggleable_inventory.len)
screenmob.client.screen -= toggleable_inventory
//SKYRAT EDIT ADDITION BEGIN - ERP_SLOT_SYSTEM
if(ERP_toggleable_inventory.len && screenmob.hud_used && screenmob.hud_used.ERP_inventory_shown && screenmob.client?.prefs?.read_preference(/datum/preference/toggle/erp/sex_toy))
screenmob.client.screen -= ERP_toggleable_inventory
//SKYRAT EDIT ADDITION END
if(hotkeybuttons.len)
screenmob.client.screen -= hotkeybuttons
if(infodisplay.len)
screenmob.client.screen += infodisplay
//These ones are a part of 'static_inventory', 'toggleable_inventory' or 'hotkeybuttons' but we want them to stay
for(var/h in hand_slots)
var/atom/movable/screen/hand = hand_slots[h]
if(hand)
screenmob.client.screen += hand
if(action_intent)
screenmob.client.screen += action_intent //we want the intent switcher visible
action_intent.screen_loc = ui_acti_alt //move this to the alternative position, where zone_select usually is.
if(HUD_STYLE_NOHUD) //No HUD
hud_shown = FALSE //Governs behavior of other procs
if(static_inventory.len)
screenmob.client.screen -= static_inventory
if(toggleable_inventory.len)
screenmob.client.screen -= toggleable_inventory
//SKYRAT EDIT ADDITION BEGIN - ERP_SLOT_SYSTEM
if(toggleable_inventory.len && screenmob.hud_used && screenmob.hud_used.ERP_inventory_shown && screenmob.client?.prefs?.read_preference(/datum/preference/toggle/erp/sex_toy))
screenmob.client.screen -= ERP_toggleable_inventory
//SKYRAT EDIT ADDITION END
if(hotkeybuttons.len)
screenmob.client.screen -= hotkeybuttons
if(infodisplay.len)
screenmob.client.screen -= infodisplay
hud_version = display_hud_version
persistent_inventory_update(screenmob)
screenmob.update_action_buttons(1)
reorganize_alerts(screenmob)
screenmob.reload_fullscreen()
update_parallax_pref(screenmob)
// ensure observers get an accurate and up-to-date view
if (!viewmob)
plane_masters_update()
for(var/M in mymob.observers)
show_hud(hud_version, M)
else if (viewmob.hud_used)
viewmob.hud_used.plane_masters_update()
return TRUE
/datum/hud/proc/plane_masters_update()
// Plane masters are always shown to OUR mob, never to observers
for(var/thing in plane_masters)
var/atom/movable/screen/plane_master/PM = plane_masters[thing]
PM.backdrop(mymob)
mymob.client.screen += PM
/datum/hud/human/show_hud(version = 0,mob/viewmob)
. = ..()
if(!.)
return
var/mob/screenmob = viewmob || mymob
hidden_inventory_update(screenmob)
/datum/hud/robot/show_hud(version = 0, mob/viewmob)
. = ..()
if(!.)
return
update_robot_modules_display()
/datum/hud/proc/hidden_inventory_update()
return
/datum/hud/proc/persistent_inventory_update(mob/viewer)
if(!mymob)
return
/datum/hud/proc/update_ui_style(new_ui_style)
// do nothing if overridden by a subtype or already on that style
if (initial(ui_style) || ui_style == new_ui_style)
return
for(var/atom/item in static_inventory + toggleable_inventory + hotkeybuttons + infodisplay + screenoverlays + inv_slots)
if (item.icon == ui_style)
item.icon = new_ui_style
//SKYRAT EDIT ADDITION BEGIN - ERP_SLOT_SYSTEM
for(var/atom/item in ERP_toggleable_inventory)
if (item.icon == ui_style)
item.icon = new_ui_style
//SKYRAT EDIT ADDITION END
ui_style = new_ui_style
build_hand_slots()
hide_actions_toggle.InitialiseIcon(src)
//Triggered when F12 is pressed (Unless someone changed something in the DMF)
/mob/verb/button_pressed_F12()
set name = "F12"
set hidden = TRUE
if(hud_used && client)
hud_used.show_hud() //Shows the next hud preset
to_chat(usr, span_info("Switched HUD mode. Press F12 to toggle."))
else
to_chat(usr, span_warning("This mob type does not use a HUD."))
//(re)builds the hand ui slots, throwing away old ones
//not really worth jugglying existing ones so we just scrap+rebuild
//9/10 this is only called once per mob and only for 2 hands
/datum/hud/proc/build_hand_slots()
for(var/h in hand_slots)
var/atom/movable/screen/inventory/hand/H = hand_slots[h]
if(H)
static_inventory -= H
hand_slots = list()
var/atom/movable/screen/inventory/hand/hand_box
for(var/i in 1 to mymob.held_items.len)
hand_box = new /atom/movable/screen/inventory/hand()
hand_box.name = mymob.get_held_index_name(i)
hand_box.icon = ui_style
hand_box.icon_state = "hand_[mymob.held_index_to_dir(i)]"
hand_box.screen_loc = ui_hand_position(i)
hand_box.held_index = i
hand_slots["[i]"] = hand_box
hand_box.hud = src
static_inventory += hand_box
hand_box.update_appearance()
var/i = 1
for(var/atom/movable/screen/swap_hand/SH in static_inventory)
SH.screen_loc = ui_swaphand_position(mymob,!(i % 2) ? 2: 1)
i++
for(var/atom/movable/screen/human/equip/E in static_inventory)
E.screen_loc = ui_equip_position(mymob)
if(ismob(mymob) && mymob.hud_used == src)
show_hud(hud_version)
/datum/hud/proc/update_locked_slots()
return