-
-
Notifications
You must be signed in to change notification settings - Fork 417
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
Closed
изменение лейблера и лейблов #13531
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
Еще меня смущает сам реплейстекст оригинального имени, скобки не только с лейблером могут быть связаны. С другой стороны, можно принять, что все скобки в названии по умолчанию это уже лейблы, и возможность зайти в начале раунда и "удалить" лейблы у всех плат могла бы быть фичей.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Как альтернатива тгшной компоненте, в компоненте можно было бы просто строку лейблов хранить, и выводить при examine объекта или в подсказках по наведению, не трогая name объекта.
Name объекта всё еще будет видно без лейблов в контекстном меню правого клика, но мы когда нибудь от него откажемся.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
хотя и в этом случае будет проще и лаконичнее добавить
var/labels
к объекту, чем городить компоненту.