Skip to content

Commit

Permalink
game master phone
Browse files Browse the repository at this point in the history
  • Loading branch information
morrowwolf committed Oct 26, 2023
1 parent 4451121 commit 6ef0aac
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 21 deletions.
5 changes: 4 additions & 1 deletion code/__DEFINES/dcs/signals/atom/signals_atom.dm
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,16 @@
#define COMSIG_ATOM_VV_MODIFY_TRANSFORM "atom_vv_modify_transform"

/// From /mob/living/carbon/human/UnarmedAttack()
#define COMSIG_ATOM_HUMAN_ATTACK_HAND "atom_human_attack_hand"
#define COMSIG_ATOM_BEFORE_HUMAN_ATTACK_HAND "atom_before_human_attack_hand"
#define COMPONENT_CANCEL_ATTACK_HAND (1<<0)

/// From /mob/proc/click_adjacent()
#define COMSIG_ATOM_MOB_ATTACKBY "atom_mob_attackby"
#define COMPONENT_CANCEL_ATTACKBY (1<<0)

/// From /atom/proc/attack_hand()
#define COMSIG_ATOM_ATTACK_HAND "atom_attack_hand"

/// From /datum/component/phone/proc/picked_up_call() and /datum/component/phone/proc/post_call_phone()
#define COMSIG_ATOM_PHONE_PICKED_UP "atom_phone_picked_up"
/// From /datum/component/phone/proc/recall_handset()
Expand Down
3 changes: 2 additions & 1 deletion code/_onclick/human.dm
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
to_chat(src, SPAN_NOTICE("You try to move your [temp.display_name], but cannot!"))
return

if(SEND_SIGNAL(A, COMSIG_ATOM_HUMAN_ATTACK_HAND, src, click_parameters) & COMPONENT_CANCEL_HUMAN_ATTACK_HAND)
if(SEND_SIGNAL(A, COMSIG_ATOM_BEFORE_HUMAN_ATTACK_HAND, src, click_parameters) & COMPONENT_CANCEL_HUMAN_ATTACK_HAND)
return

A.attack_hand(src, click_parameters)
Expand All @@ -89,6 +89,7 @@
return HANDLE_CLICK_PASS_THRU

/atom/proc/attack_hand(mob/user)
SEND_SIGNAL(src, COMSIG_ATOM_ATTACK_HAND, user)
return

/mob/living/carbon/human/MouseDrop_T(atom/dropping, mob/user)
Expand Down
75 changes: 68 additions & 7 deletions code/datums/components/phone.dm
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ GLOBAL_LIST_EMPTY_TYPED(phones, /datum/component/phone)
RegisterSignal(phone_handset, COMSIG_PARENT_PREQDELETED, PROC_REF(override_delete))

RegisterSignal(src.holder, COMSIG_ATOM_MOB_ATTACKBY, PROC_REF(item_used_on_phone))
RegisterSignal(src.holder, COMSIG_ATOM_HUMAN_ATTACK_HAND, PROC_REF(use_phone))
RegisterSignal(src.holder, COMSIG_ATOM_BEFORE_HUMAN_ATTACK_HAND, PROC_REF(use_phone))

if(istype(src.holder, /obj/item))
RegisterSignal(src.holder, COMSIG_ITEM_PICKUP, PROC_REF(holder_picked_up))
Expand Down Expand Up @@ -322,7 +322,7 @@ GLOBAL_LIST_EMPTY_TYPED(phones, /datum/component/phone)

SEND_SIGNAL(holder, COMSIG_ATOM_PHONE_STOPPED_RINGING)

ringing_loop.stop()
ringing_loop?.stop()

handle_reset_call_message(timeout, recursed)

Expand Down Expand Up @@ -358,7 +358,7 @@ GLOBAL_LIST_EMPTY_TYPED(phones, /datum/component/phone)

/// Handles any messages that our handset 'hears' and passes to us. Passes the message to this phone and any connected phone via handle_hear()
/datum/component/phone/proc/handle_speak(message, datum/language/message_language, mob/speaker, direct_talking = TRUE)
if(message_language.flags & SIGNLANG)
if(message_language?.flags & SIGNLANG)
return

if(!calling_phone)
Expand Down Expand Up @@ -434,12 +434,14 @@ GLOBAL_LIST_EMPTY_TYPED(phones, /datum/component/phone)

switch(action)
if("call_phone")
if(calling_phone)
return TRUE
call_phone(ui.user, params["phone_id"])
. = TRUE
return TRUE

if("toggle_do_not_disturb")
toggle_do_not_disturb(ui.user)
. = TRUE
return TRUE

/datum/component/phone/ui_data(mob/user)
var/list/data = list()
Expand Down Expand Up @@ -496,10 +498,17 @@ GLOBAL_LIST_EMPTY_TYPED(phones, /datum/component/phone)
return FALSE
src.virtual_user = virtual_user

RegisterSignal(src.holder, COMSIG_ATOM_ATTACK_HAND, PROC_REF(use_phone))

return TRUE

/datum/component/phone/virtual/use_phone(atom/phone, mob/living/carbon/human/user, click_parameters)
INVOKE_ASYNC(src, PROC_REF(tgui_interact), user)

/datum/component/phone/virtual/picked_up_call(mob/living/carbon/human/user)
to_chat(user, SPAN_PURPLE("[icon2html(src, user)] Picked up a call from [calling_phone.phone_id]."))
to_chat(user, SPAN_PURPLE("[icon2html(holder, user)] Picked up a call from [calling_phone.phone_id]."))

RegisterSignal(virtual_user.mob, COMSIG_DEAD_SPEAK, PROC_REF(handle_virtual_speak))

/datum/component/phone/virtual/other_phone_picked_up_call()
if(!calling_phone)
Expand All @@ -509,6 +518,7 @@ GLOBAL_LIST_EMPTY_TYPED(phones, /datum/component/phone)
deltimer(timeout_timer_id)
timeout_timer_id = null

RegisterSignal(virtual_user.mob, COMSIG_DEAD_SPEAK, PROC_REF(handle_virtual_speak))
to_chat(virtual_user, SPAN_PURPLE("[icon2html(calling_phone.holder, virtual_user)] [calling_phone.phone_id] has picked up."))

/datum/component/phone/virtual/phone_available()
Expand All @@ -523,6 +533,10 @@ GLOBAL_LIST_EMPTY_TYPED(phones, /datum/component/phone)

return TRUE

/datum/component/phone/virtual/reset_call(timeout = FALSE, recursed = FALSE)
. = ..()
UnregisterSignal(virtual_user.mob, COMSIG_DEAD_SPEAK)

/datum/component/phone/virtual/handle_reset_call_message(timeout = FALSE, recursed = FALSE)
if(recursed)
to_chat(virtual_user, SPAN_PURPLE("[icon2html(holder, virtual_user)] [calling_phone.phone_id] has hung up on you."))
Expand All @@ -534,6 +548,14 @@ GLOBAL_LIST_EMPTY_TYPED(phones, /datum/component/phone)
/datum/component/phone/virtual/getting_call(datum/component/phone/incoming_call)
calling_phone = incoming_call
SEND_SIGNAL(holder, COMSIG_ATOM_PHONE_RINGING)
playsound_client(virtual_user, 'sound/machines/telephone/telephone_ring.ogg', vol = 50)
addtimer(CALLBACK(src, PROC_REF(delayed_client_sound)), (10 SECONDS))

/datum/component/phone/virtual/proc/delayed_client_sound()
if(!calling_phone || !calling_phone.timeout_timer_id)
return

playsound_client(virtual_user, 'sound/machines/telephone/telephone_ring.ogg', vol = 50)

/datum/component/phone/virtual/post_call_phone(mob/user, calling_phone_id)
to_chat(user, SPAN_PURPLE("[icon2html(holder, user)] Dialing [calling_phone_id].."))
Expand All @@ -545,7 +567,7 @@ GLOBAL_LIST_EMPTY_TYPED(phones, /datum/component/phone)
reset_call() // I don't think this will be possible given like... we don't have a handset but just in case
return

/datum/component/phone/virtual/handle_hear(message, datum/language/message_language, mob/speaker)
/datum/component/phone/virtual/handle_hear(message, datum/language/message_language, mob/speaker, direct_talking)
if(!calling_phone)
return

Expand All @@ -559,12 +581,51 @@ GLOBAL_LIST_EMPTY_TYPED(phones, /datum/component/phone)

virtual_user.mob.hear_radio(message, "says", message_language, part_a = "<span class='purple'><span class='name'>", part_b = "</span><span class='message'> ", vname = name_override, speaker = speaker, command = 3, no_paygrade = TRUE)

/// Used to fake the other side of our phone connection as a virtual user
/datum/component/phone/virtual/proc/handle_virtual_speak(mob/speaker, message)
SIGNAL_HANDLER

if(!calling_phone)
return

handle_hear(message, null, speaker, TRUE)

log_say("TELEPHONE: [key_name(speaker)] on Phone '[phone_id]' to '[calling_phone.phone_id]' said '[message]'")

for(var/mob/dead/observer/cycled_observer in GLOB.player_list)
if((cycled_observer.client) && (cycled_observer.client.prefs) && (cycled_observer.client.prefs.toggles_chat & CHAT_GHOSTRADIO))
var/ghost_message = "<span class='purple'><span class='name'>Game Master</span> on '[phone_id]' to '[calling_phone.phone_id]': <span class='body'>\"[message]\"</span></span>"
cycled_observer.show_message(ghost_message, SHOW_MESSAGE_AUDIBLE)

calling_phone.handle_hear(message, null, speaker, TRUE)

return COMPONENT_OVERRIDE_DEAD_SPEAK

// TGUI section

/datum/component/phone/virtual/ui_status(mob/user, datum/ui_state/state)
return UI_INTERACTIVE

/datum/component/phone/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
. = ..()
if(.)
return

switch(action)
if("hang_up")
reset_call()
return TRUE
if("pick_up")
if(!calling_phone)
return
picked_up_call(ui.user)
calling_phone.other_phone_picked_up_call()
return TRUE

/datum/component/phone/virtual/ui_data(mob/user)
. = ..()

.["virtual_phone"] = TRUE
.["being_called"] = calling_phone?.timeout_timer_id ? TRUE : FALSE
.["active_call"] = calling_phone ? TRUE : FALSE
.["calling_phone_id"] = "[calling_phone?.phone_id]"
9 changes: 6 additions & 3 deletions code/modules/admin/game_master/game_master.dm
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ GLOBAL_VAR_INIT(radio_communication_clarity, 100)

/// Communication stuff

var/atom/game_master_phone
var/atom/movable/game_master_phone

/// End Communication stuff

Expand All @@ -92,8 +92,8 @@ GLOBAL_VAR_INIT(radio_communication_clarity, 100)

current_submenus = list()

game_master_phone = new()
game_master_phone.AddComponent(/datum/component/phone/virtual, "Game Master", "white", "Company Command", null, PHONE_DO_NOT_DISTURB_FORCED, list(), list(FACTION_MARINE, FACTION_COLONIST, FACTION_WY), null, using_client)
game_master_phone = new(null)
game_master_phone.AddComponent(/datum/component/phone/virtual, "Game Master", "white", "Company Command", null, PHONE_DO_NOT_DISTURB_ON, list(FACTION_MARINE, FACTION_COLONIST, FACTION_WY), list(FACTION_MARINE, FACTION_COLONIST, FACTION_WY), null, using_client)

using_client.click_intercept = src

Expand Down Expand Up @@ -176,6 +176,9 @@ GLOBAL_VAR_INIT(radio_communication_clarity, 100)
return

//Communication Section
if("use_game_master_phone")
game_master_phone.attack_hand(ui.user)

if("set_communication_clarity")
var/new_clarity = text2num(params["clarity"])
if(!isnum(new_clarity))
Expand Down
2 changes: 1 addition & 1 deletion tgui/packages/tgui/interfaces/GameMaster.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const GameMaster = (props, context) => {
<Flex grow direction="column">
<Flex.Item>
<Button
content="Game Master Phone (SoonTM)"
content="Game Master Phone"
onClick={() => {
act('use_game_master_phone');
}}
Expand Down
33 changes: 25 additions & 8 deletions tgui/packages/tgui/interfaces/PhoneMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,31 @@ const GeneralPanel = (props, context) => {
</Stack.Item>
{data.virtual_phone && (
<Stack.Item>
<Button
content="Hang Up"
color="red"
fluid
textAlign="center"
disabled={!active_call}
onClick={() => act('hang_up')}
/>
<Stack vertical fill>
<Stack.Item>
<Section title={data.calling_phone_id || 'Phone Control'} />
</Stack.Item>
<Stack.Item>
<Button
content="Pick Up"
color="good"
fluid
textAlign="center"
disabled={!data.being_called}
onClick={() => act('pick_up')}
/>
</Stack.Item>
<Stack.Item>
<Button
content="Hang Up"
color="red"
fluid
textAlign="center"
disabled={!data.active_call}
onClick={() => act('hang_up')}
/>
</Stack.Item>
</Stack>
</Stack.Item>
)}
</Stack>
Expand Down

0 comments on commit 6ef0aac

Please sign in to comment.