Files
wwdpublic/Content.Client/Renamable/RenamableWindow.xaml.cs
Timfa 8f1a56923e Renamable Component (#1821)
<!--
This is a semi-strict format, you can add/remove sections as needed but
the order/format should be kept the same
Remove these comments before submitting
-->

# Description

<!--
Explain this PR in as much detail as applicable

Some example prompts to consider:
How might this affect the game? The codebase?
What might be some alternatives to this?
How/Who does this benefit/hurt [the game/codebase]?
-->

Adds a component (added to MobSoliconBase) which allows you to rename an
entity in-game via a verb.

---

# TODO

<!--
A list of everything you have to do before this PR is "complete"
You probably won't have to complete everything before merging but it's
good to leave future references
-->

- [x] Make the Verb appear
- [x] Successfully open the UI
- [x] Apply input as entity name

---

<!--
This is default collapsed, readers click to expand it and see all your
media
The PR media section can get very large at times, so this is a good way
to keep it clean
The title is written using HTML tags
The title must be within the <summary> tags or you won't see it
-->

<details><summary><h1>Media</h1></summary>
<p>

![Example Media Embed](https://example.com/thisimageisntreal.png)

</p>
</details>

---

# Changelog

<!--
You can add an author after the `🆑` to change the name that appears
in the changelog (ex: `🆑 Death`)
Leaving it blank will default to your GitHub display name
This includes all available types for the changelog
-->

🆑
- tweak: Allow renaming robots and pAI

---------

Signed-off-by: Timfa <timfalken@hotmail.com>
Co-authored-by: sleepyyapril <123355664+sleepyyapril@users.noreply.github.com>
(cherry picked from commit 3014a0db4560e9949e690caaa49f46866bc20079)
2025-02-28 16:26:43 +03:00

49 lines
1.1 KiB
C#

using Robust.Client.UserInterface.CustomControls;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.XAML;
namespace Content.Client.Renamable;
[GenerateTypedNameReferences]
public sealed partial class RenamableWindow : DefaultWindow
{
public event Action<string>? OnNameChanged;
/// <summary>
/// Is the user currently entering text into the control?
/// </summary>
private bool _focused;
// TODO LineEdit Make this a bool on the LineEdit control
private string _name = string.Empty;
public RenamableWindow()
{
RobustXamlLoader.Load(this);
NameLineEdit.OnTextEntered += args =>
{
_name = args.Text;
OnNameChanged?.Invoke(_name);
};
NameLineEdit.OnFocusEnter += _ => _focused = true;
NameLineEdit.OnFocusExit += _ =>
{
_focused = false;
NameLineEdit.Text = _name;
};
}
public void SetCurrentName(string label)
{
if (label == _name)
return;
_name = label;
if (!_focused)
NameLineEdit.Text = label;
}
}