Skip to content

Commit

Permalink
Refactor /obj/screen to /atom/movable/screen (#19852)
Browse files Browse the repository at this point in the history
Part of backend stuff required for #19188. Should probably be test
merged.

---------

Co-authored-by: Cody Brittain <[email protected]>
  • Loading branch information
Generalcamo and Cody Brittain authored Sep 21, 2024
1 parent 3c474b7 commit dc61052
Show file tree
Hide file tree
Showing 88 changed files with 732 additions and 676 deletions.
2 changes: 1 addition & 1 deletion code/__HELPERS/game.dm
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
// Same as above but for alien candidates.

/proc/ScreenText(obj/O, maptext="", screen_loc="CENTER-7,CENTER-7", maptext_height=480, maptext_width=480)
if(!isobj(O)) O = new /obj/screen/text()
if(!isobj(O)) O = new /atom/movable/screen/text()
O.maptext = maptext
O.maptext_height = maptext_height
O.maptext_width = maptext_width
Expand Down
8 changes: 4 additions & 4 deletions code/_onclick/click.dm
Original file line number Diff line number Diff line change
Expand Up @@ -383,26 +383,26 @@

var/global/list/click_catchers

/obj/screen/click_catcher
/atom/movable/screen/click_catcher
icon = 'icons/mob/screen_gen.dmi'
icon_state = "click_catcher"
plane = CLICKCATCHER_PLANE
mouse_opacity = MOUSE_OPACITY_OPAQUE
screen_loc = "CENTER-7,CENTER-7"

/obj/screen/click_catcher/Destroy()
/atom/movable/screen/click_catcher/Destroy()
SHOULD_CALL_PARENT(FALSE)
return QDEL_HINT_LETMELIVE

/proc/create_click_catcher()
. = list()
for(var/i = 0, i<15, i++)
for(var/j = 0, j<15, j++)
var/obj/screen/click_catcher/CC = new()
var/atom/movable/screen/click_catcher/CC = new()
CC.screen_loc = "NORTH-[i],EAST-[j]"
. += CC

/obj/screen/click_catcher/Click(location, control, params)
/atom/movable/screen/click_catcher/Click(location, control, params)
var/list/modifiers = params2list(params)
if(modifiers["middle"] && istype(usr, /mob/living/carbon))
var/mob/living/carbon/C = usr
Expand Down
110 changes: 55 additions & 55 deletions code/_onclick/hud/ability_screen_objects.dm
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/obj/screen/movable/ability_master
/atom/movable/screen/movable/ability_master
name = "Abilities"
icon = 'icons/mob/screen_spells.dmi'
icon_state = "grey_spell_ready"
var/list/obj/screen/ability/ability_objects = list()
var/list/atom/movable/screen/ability/ability_objects = list()
var/showing = FALSE // If we're 'open' or not.

var/open_state = "master_open" // What the button looks like when it's 'open', showing the other buttons.
Expand All @@ -12,13 +12,13 @@

var/mob/my_mob // The mob that possesses this hud object.

/obj/screen/movable/ability_master/Initialize(mapload, owner)
/atom/movable/screen/movable/ability_master/Initialize(mapload, owner)
. = ..()
if(owner)
my_mob = owner
update_abilities(0, owner)

/obj/screen/movable/ability_master/Destroy()
/atom/movable/screen/movable/ability_master/Destroy()
//Get rid of the ability objects.
remove_all_abilities()
ability_objects.Cut()
Expand All @@ -32,21 +32,21 @@

. = ..()

/obj/screen/movable/ability_master/MouseDrop()
/atom/movable/screen/movable/ability_master/MouseDrop()
if(showing)
return

return ..()

/obj/screen/movable/ability_master/Click()
/atom/movable/screen/movable/ability_master/Click()
if(!ability_objects.len) // If we're empty for some reason.
return

toggle_open()

/obj/screen/movable/ability_master/proc/toggle_open(var/forced_state = 0, var/mob/user = usr)
/atom/movable/screen/movable/ability_master/proc/toggle_open(var/forced_state = 0, var/mob/user = usr)
if(showing && (forced_state != 2)) // We are closing the ability master, hide the abilities.
for(var/obj/screen/ability/O in ability_objects)
for(var/atom/movable/screen/ability/O in ability_objects)
if(my_mob && my_mob.client)
my_mob.client.screen -= O
showing = FALSE
Expand All @@ -60,7 +60,7 @@
overlays.Add(open_state)
update_icon()

/obj/screen/movable/ability_master/proc/open_ability_master(var/mob/user = usr)
/atom/movable/screen/movable/ability_master/proc/open_ability_master(var/mob/user = usr)
var/list/screen_loc_xy = splittext(screen_loc,",")

//Create list of X offsets
Expand All @@ -74,36 +74,36 @@
var/y_pix = screen_loc_Y[2]

for(var/i = 1; i <= ability_objects.len; i++)
var/obj/screen/ability/A = ability_objects[i]
var/atom/movable/screen/ability/A = ability_objects[i]
var/xpos = x_position + (x_position < 8 ? 1 : -1)*(i%7)
var/ypos = y_position + (y_position < 8 ? round(i/7) : -round(i/7))
A.screen_loc = "[encode_screen_X(xpos, user)]:[x_pix],[encode_screen_Y(ypos, user)]:[y_pix]"
if(my_mob && my_mob.client)
my_mob.client.screen += A

/obj/screen/movable/ability_master/proc/update_abilities(forced = 0, mob/user)
/atom/movable/screen/movable/ability_master/proc/update_abilities(forced = 0, mob/user)
update_icon()
if(user && user.client)
if(!(src in user.client.screen))
user.client.screen += src
var/i = 1
for(var/obj/screen/ability/ability in ability_objects)
for(var/atom/movable/screen/ability/ability in ability_objects)
ability.update_icon(forced)
ability.index = i
ability.maptext = "[ability.index]" // Slot number
i++

/obj/screen/movable/ability_master/update_icon()
/atom/movable/screen/movable/ability_master/update_icon()
if(ability_objects.len)
set_invisibility(0)
else
set_invisibility(101)

/obj/screen/movable/ability_master/proc/add_ability(var/name_given)
/atom/movable/screen/movable/ability_master/proc/add_ability(var/name_given)
if(!name)
return

var/obj/screen/ability/new_button = new /obj/screen/ability
var/atom/movable/screen/ability/new_button = new /atom/movable/screen/ability
new_button.ability_master = src
new_button.name = name_given
new_button.ability_icon_state = name_given
Expand All @@ -112,7 +112,7 @@
if(my_mob.client)
toggle_open(2) //forces the icons to refresh on screen

/obj/screen/movable/ability_master/proc/remove_ability(var/obj/screen/ability/ability)
/atom/movable/screen/movable/ability_master/proc/remove_ability(var/atom/movable/screen/ability/ability)
if(!ability)
return
ability_objects.Remove(ability)
Expand All @@ -123,46 +123,46 @@
toggle_open(showing + 1)
update_icon()

/obj/screen/movable/ability_master/proc/remove_all_abilities()
for(var/obj/screen/ability/A in ability_objects)
/atom/movable/screen/movable/ability_master/proc/remove_all_abilities()
for(var/atom/movable/screen/ability/A in ability_objects)
remove_ability(A)

/obj/screen/movable/ability_master/proc/remove_all_psionic_abilities()
for(var/obj/screen/ability/obj_based/psionic/A in ability_objects)
/atom/movable/screen/movable/ability_master/proc/remove_all_psionic_abilities()
for(var/atom/movable/screen/ability/obj_based/psionic/A in ability_objects)
remove_ability(A)

/obj/screen/movable/ability_master/proc/get_ability_by_name(name_to_search)
for(var/obj/screen/ability/A in ability_objects)
/atom/movable/screen/movable/ability_master/proc/get_ability_by_name(name_to_search)
for(var/atom/movable/screen/ability/A in ability_objects)
if(A.name == name_to_search)
return A
return

/obj/screen/movable/ability_master/proc/get_ability_by_proc_ref(proc_ref)
for(var/obj/screen/ability/verb_based/V in ability_objects)
/atom/movable/screen/movable/ability_master/proc/get_ability_by_proc_ref(proc_ref)
for(var/atom/movable/screen/ability/verb_based/V in ability_objects)
if(V.verb_to_call == proc_ref)
return V
return

/obj/screen/movable/ability_master/proc/get_ability_by_instance(var/obj/instance/)
for(var/obj/screen/ability/obj_based/O in ability_objects)
/atom/movable/screen/movable/ability_master/proc/get_ability_by_instance(var/obj/instance/)
for(var/atom/movable/screen/ability/obj_based/O in ability_objects)
if(O.object == instance)
return O
return

///////////ACTUAL ABILITIES////////////
//This is what you click to do things//
///////////////////////////////////////
/obj/screen/ability
/atom/movable/screen/ability
icon = 'icons/mob/screen_spells.dmi'
icon_state = "grey_spell_base"
maptext_x = 3
var/background_base_state = "grey"
var/ability_icon_state = null
var/index = 0

var/obj/screen/movable/ability_master/ability_master
var/atom/movable/screen/movable/ability_master/ability_master

/obj/screen/ability/Destroy()
/atom/movable/screen/ability/Destroy()
if(ability_master)
ability_master.ability_objects -= src
if(ability_master.my_mob && ability_master.my_mob.client)
Expand All @@ -172,13 +172,13 @@
ability_master = null
. = ..()

/obj/screen/ability/update_icon()
/atom/movable/screen/ability/update_icon()
overlays.Cut()
icon_state = "[background_base_state]_spell_base"

overlays += ability_icon_state

/obj/screen/ability/Click(var/location, var/control, var/params)
/atom/movable/screen/ability/Click(var/location, var/control, var/params)
if(!usr)
return

Expand All @@ -189,22 +189,22 @@

activate()

/obj/screen/ability/MouseDrop(var/atom/A)
/atom/movable/screen/ability/MouseDrop(var/atom/A)
if(!A || A == src)
return
if(istype(A, /obj/screen/ability))
var/obj/screen/ability/ability = A
if(istype(A, /atom/movable/screen/ability))
var/atom/movable/screen/ability/ability = A
if(ability.ability_master && ability.ability_master == src.ability_master)
ability_master.ability_objects.Swap(src.index, ability.index)
ability_master.toggle_open(2) // To update the UI.


// Makes the ability be triggered. The subclasses of this are responsible for carrying it out in whatever way it needs to.
/obj/screen/ability/proc/activate()
/atom/movable/screen/ability/proc/activate()
LOG_DEBUG("[src] had activate() called.")

// This checks if the ability can be used.
/obj/screen/ability/proc/can_activate()
/atom/movable/screen/ability/proc/can_activate()
return TRUE

/client/verb/activate_ability(var/slot as num)
Expand All @@ -218,30 +218,30 @@
return // No abilities.
if(slot > mob.ability_master.ability_objects.len || slot <= 0)
return // Out of bounds.
var/obj/screen/ability/A = mob.ability_master.ability_objects[slot]
var/atom/movable/screen/ability/A = mob.ability_master.ability_objects[slot]
A.activate()

//////////Verb Abilities//////////
//Buttons to trigger verbs/procs//
//////////////////////////////////

/obj/screen/ability/verb_based
/atom/movable/screen/ability/verb_based
var/verb_to_call = null
var/object_used = null
var/arguments_to_use = list()

/obj/screen/ability/verb_based/activate()
/atom/movable/screen/ability/verb_based/activate()
if(object_used && verb_to_call)
call(object_used,verb_to_call)(arguments_to_use)

/obj/screen/movable/ability_master/proc/add_verb_ability(var/object_given, var/verb_given, var/name_given, var/ability_icon_given, var/arguments)
/atom/movable/screen/movable/ability_master/proc/add_verb_ability(var/object_given, var/verb_given, var/name_given, var/ability_icon_given, var/arguments)
if(!object_given)
message_admins("ERROR: add_verb_ability() was not given an object in its arguments.")
if(!verb_given)
message_admins("ERROR: add_verb_ability() was not given a verb/proc in its arguments.")
if(get_ability_by_proc_ref(verb_given))
return // Duplicate
var/obj/screen/ability/verb_based/A = new /obj/screen/ability/verb_based()
var/atom/movable/screen/ability/verb_based/A = new /atom/movable/screen/ability/verb_based()
A.ability_master = src
A.object_used = object_given
A.verb_to_call = verb_given
Expand All @@ -254,18 +254,18 @@
toggle_open(2) //forces the icons to refresh on screen

//Changeling Abilities
/obj/screen/ability/verb_based/changeling
/atom/movable/screen/ability/verb_based/changeling
icon_state = "ling_spell_base"
background_base_state = "ling"

/obj/screen/movable/ability_master/proc/add_ling_ability(var/object_given, var/verb_given, var/name_given, var/ability_icon_given, var/arguments)
/atom/movable/screen/movable/ability_master/proc/add_ling_ability(var/object_given, var/verb_given, var/name_given, var/ability_icon_given, var/arguments)
if(!object_given)
message_admins("ERROR: add_ling_ability() was not given an object in its arguments.")
if(!verb_given)
message_admins("ERROR: add_ling_ability() was not given a verb/proc in its arguments.")
if(get_ability_by_proc_ref(verb_given))
return // Duplicate
var/obj/screen/ability/verb_based/changeling/A = new /obj/screen/ability/verb_based/changeling()
var/atom/movable/screen/ability/verb_based/changeling/A = new /atom/movable/screen/ability/verb_based/changeling()
A.ability_master = src
A.object_used = object_given
A.verb_to_call = verb_given
Expand All @@ -282,31 +282,31 @@
//Buttons to trigger objects//
//////////////////////////////

/obj/screen/ability/obj_based
/atom/movable/screen/ability/obj_based
var/obj/object

/obj/screen/ability/obj_based/activate()
/atom/movable/screen/ability/obj_based/activate()
if(object)
object.Click()

/// Psionics.
/obj/screen/ability/obj_based/psionic
/atom/movable/screen/ability/obj_based/psionic
icon_state = "nano_spell_base"
background_base_state = "nano"
var/singleton/psionic_power/connected_power

/obj/screen/ability/obj_based/psionic/Destroy()
/atom/movable/screen/ability/obj_based/psionic/Destroy()
connected_power = null
return ..()

/obj/screen/movable/ability_master/proc/add_psionic_ability(var/obj/object_given, var/ability_icon_given, var/singleton/psionic_power/P, var/mob/user)
/atom/movable/screen/movable/ability_master/proc/add_psionic_ability(var/obj/object_given, var/ability_icon_given, var/singleton/psionic_power/P, var/mob/user)
if(!object_given)
message_admins("ERROR: add_psionic_ability() was not given an object in its arguments.")
if(!P)
message_admins("Psionic ability added without connected psionic power singleton!")
if(get_ability_by_instance(object_given))
return // Duplicate
var/obj/screen/ability/obj_based/psionic/A = new /obj/screen/ability/obj_based/psionic()
var/atom/movable/screen/ability/obj_based/psionic/A = new /atom/movable/screen/ability/obj_based/psionic()
A.ability_master = src
A.object = object_given
A.ability_icon_state = ability_icon_given
Expand All @@ -316,27 +316,27 @@
if(my_mob.client)
toggle_open(2, user) //forces the icons to refresh on screen

/obj/screen/ability/obj_based/psionic/get_examine_text(mob/user)
/atom/movable/screen/ability/obj_based/psionic/get_examine_text(mob/user)
. = ..()
. += SPAN_NOTICE("<font size=4>This ability is <b>[connected_power.name]</b>.</font>")
. += SPAN_NOTICE("[connected_power.desc]")

/// Technomancer.
/obj/screen/ability/obj_based/technomancer
/atom/movable/screen/ability/obj_based/technomancer
icon_state = "wiz_spell_base"
background_base_state = "wiz"

/obj/screen/ability/obj_based/technomancer/activate()
/atom/movable/screen/ability/obj_based/technomancer/activate()
if(ability_master.my_mob.incapacitated())
return
. = ..()

/obj/screen/movable/ability_master/proc/add_technomancer_ability(var/obj/object_given, var/ability_icon_given)
/atom/movable/screen/movable/ability_master/proc/add_technomancer_ability(var/obj/object_given, var/ability_icon_given)
if(!object_given)
message_admins("ERROR: add_technomancer_ability() was not given an object in its arguments.")
if(get_ability_by_instance(object_given))
return // Duplicate
var/obj/screen/ability/obj_based/technomancer/A = new /obj/screen/ability/obj_based/technomancer()
var/atom/movable/screen/ability/obj_based/technomancer/A = new /atom/movable/screen/ability/obj_based/technomancer()
A.ability_master = src
A.object = object_given
A.ability_icon_state = ability_icon_given
Expand Down
Loading

0 comments on commit dc61052

Please sign in to comment.