Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

изменение лейблера и лейблов #13531

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions code/datums/components/label.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
The label component.

This component is used to manage labels applied by the hand labeler.

Atoms can only have one instance of this component, and therefore only one label at a time.
This is to avoid having names like "Backpack (label1) (label2) (label3)". This is annoying and abnoxious to read.

When a player clicks the atom with a hand labeler to apply a label, this component gets applied to it.
If the labeler is off, the component will be removed from it, and the label will be removed from its name.
*/
/datum/component/label
dupe_mode = COMPONENT_DUPE_UNIQUE_PASSARGS
/// The name of the label the player is applying to the parent.
var/label_name

/datum/component/label/Initialize(_label_name)
if(!isatom(parent))
return COMPONENT_INCOMPATIBLE

label_name = _label_name
apply_label()

/datum/component/label/RegisterWithParent()
RegisterSignal(parent, COMSIG_PARENT_ATTACKBY, PROC_REF(OnAttackby))

/datum/component/label/UnregisterFromParent()
UnregisterSignal(parent, list(COMSIG_PARENT_ATTACKBY, COMSIG_PARENT_EXAMINE))

/**
This proc will fire after the parent is hit by a hand labeler which is trying to apply another label.
Since the parent already has a label, it will remove the old one from the parent's name, and apply the new one.
*/
/datum/component/label/InheritComponent(datum/component/label/new_comp , i_am_original, _label_name)
remove_label()
if(new_comp)
label_name = new_comp.label_name
else
label_name = _label_name
apply_label()

/**
This proc will trigger when any object is used to attack the parent.

If the attacking object is not a hand labeler, it will return.
If the attacking object is a hand labeler it will restore the name of the parent to what it was before this component was added to it, and the component will be deleted.

Arguments:
* source: The parent.
* attacker: The object that is hitting the parent.
* user: The mob who is wielding the attacking object.
*/
/datum/component/label/proc/OnAttackby(datum/source, obj/item/attacker, mob/user)
SIGNAL_HANDLER

// If the attacking object is not a hand labeler or its mode is 1 (has a label ready to apply), return.
// The hand labeler should be off (mode is 0), in order to remove a label.
var/obj/item/device/tagger/labeler = attacker
if(!istype(labeler))
return

remove_label()
to_chat(user, "<span class='warning'>You remove the label from [parent].</span>")
qdel(src) // Remove the component from the object.

/// Applies a label to the name of the parent in the format of: "parent_name (label)"
/datum/component/label/proc/apply_label()
var/atom/owner = parent
owner.name += " ([label_name])"

/// Removes the label from the parent's name
/datum/component/label/proc/remove_label()
var/atom/owner = parent
owner.name = replacetext(owner.name, "([label_name])", "") // Remove the label text from the parent's name, wherever it's located.
owner.name = trim(owner.name) // Shave off any white space from the beginning or end of the parent's name.
Comment on lines +67 to +75
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Задумка хорошая, реализация хромает. Это плохая компонента, в том смысле, что мы всё равно меняем оригинальный name - поведение не инкапсулировано. replacetext можно было бы и так в лейблере прописать, без оверхеда компоненты.

Если хочется именно компонентой, то беглым поиском нашел https://github.com/tgstation/tgstation/blob/master/code/datums/components/rename.dm

Еще меня смущает сам реплейстекст оригинального имени, скобки не только с лейблером могут быть связаны. С другой стороны, можно принять, что все скобки в названии по умолчанию это уже лейблы, и возможность зайти в начале раунда и "удалить" лейблы у всех плат могла бы быть фичей.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Как альтернатива тгшной компоненте, в компоненте можно было бы просто строку лейблов хранить, и выводить при examine объекта или в подсказках по наведению, не трогая name объекта.

Name объекта всё еще будет видно без лейблов в контекстном меню правого клика, но мы когда нибудь от него откажемся.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

хотя и в этом случае будет проще и лаконичнее добавить var/labels к объекту, чем городить компоненту.

38 changes: 29 additions & 9 deletions code/modules/recycling/sortingmachinery.dm
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,8 @@
else if(href_list["autocateg"])
autocategory = !autocategory
else if(href_list["label_text"])
var/T = sanitize(input("Введите текст бирки:", "Маркировщик", label, null) as text)
if(T)
label = T
var/T = sanitize(input("Введите текст бирки:", "Маркировщик", label, null) as text)
label = T
else if(href_list["change_mode"])
mode++
if(mode > modes.len)
Expand Down Expand Up @@ -456,9 +455,6 @@
openwindow(user)

/obj/item/device/tagger/proc/label(obj/target, mob/user)
if(!label || !length(label))
to_chat(user, "<span class='notice'>Нет текста на бирке.</span>")
return
if(length(target.name) + length(label) > 64)
to_chat(user, "<span class='notice'>Текст бирки слишком большой.</span>")
return
Expand All @@ -472,9 +468,22 @@
to_chat(user, "<span class='notice'>The label can't stick to the [target.name]. (Try using a pen)</span>")
return

user.visible_message("<span class='notice'>[user] labels [target] as [label].</span>", \
"<span class='notice'>You label [target] as [label].</span>")
target.name = "[target.name] ([label])"
if(!label || !length(label))
remove_label(target, user)
return

var/datum/component/label/labelcomponent = target.GetComponent(/datum/component/label)
if(labelcomponent)
if(labelcomponent.label_name == label)
to_chat(user, "<span class='warning'>It already has the same label.</span>")
return

user.visible_message("<span class='notice'>[user] labels [target] as \"[label]\".</span>", "<span class='notice'>You label [target] as \"[label]\".</span>")

log_admin("[user] has labeled [target.name] with label \"[label]\". (CKEY: ([user.ckey]))")

target.AddComponent(/datum/component/label, label)


/obj/item/device/tagger/proc/get_category(obj/target)
if(istype(target, /obj/item/weapon/reagent_containers/food))
Expand All @@ -495,6 +504,17 @@
return "Разное"


/obj/item/device/tagger/proc/remove_label(atom/A, mob/user)
var/datum/component/label/label = A.GetComponent(/datum/component/label)
if(label)
user.visible_message("<span class='notice'>[user] removes label from [A].</span>", "<span class='notice'>You remove the label from [A].</span>")
label.remove_label()
log_admin("[user] has removed label from [A.name]. (CKEY: ([user.ckey]))")
return
else
to_chat(user, "<span class='notice'>There is no label to remove.</span>")
return

/obj/machinery/disposal/deliveryChute
name = "Delivery chute"
desc = "A chute for big and small packages alike!"
Expand Down
1 change: 1 addition & 0 deletions taucetistation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@
#include "code\datums\components\footstep.dm"
#include "code\datums\components\forcefield.dm"
#include "code\datums\components\gnawing.dm"
#include "code\datums\components\label.dm"
#include "code\datums\components\logout_spawner.dm"
#include "code\datums\components\magic_item.dm"
#include "code\datums\components\mechanic_description.dm"
Expand Down
Loading