Skip to content

Commit aed12cd

Browse files
committed
shitcode)
1 parent 2d741a1 commit aed12cd

File tree

13 files changed

+329
-0
lines changed

13 files changed

+329
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!--© SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt-->
2+
<DefaultWindow xmlns="https://spacestation14.io"
3+
MinSize="200 200">
4+
<BoxContainer Orientation="Vertical" Margin="8">
5+
<BoxContainer Name="Prompts" Orientation="Vertical"/>
6+
<BoxContainer Orientation="Vertical"
7+
HorizontalExpand="True"
8+
VerticalExpand="True">
9+
<BoxContainer MinHeight="20"></BoxContainer>
10+
<Button Name="OkButton"
11+
Text="{Loc 'quick-dialog-ui-confirm'}"
12+
StyleClasses="OpenBoth"
13+
MaxWidth="120"
14+
HorizontalAlignment="Center"
15+
VerticalExpand="False"
16+
HorizontalExpand="False">
17+
</Button>
18+
</BoxContainer>
19+
</BoxContainer>
20+
</DefaultWindow>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt
2+
using Content.Shared.Administration;
3+
using Robust.Client.AutoGenerated;
4+
using Robust.Client.UserInterface.Controls;
5+
using Robust.Client.UserInterface.CustomControls;
6+
using Robust.Client.UserInterface.XAML;
7+
8+
namespace Content.Client.SS220.DialogWindowDescUI;
9+
10+
[GenerateTypedNameReferences]
11+
public sealed partial class DialogWindowDesc : DefaultWindow
12+
{
13+
private List<(string, LineEdit)> _promptLines;
14+
15+
private bool _finished;
16+
17+
public Action<Dictionary<string, string>>? OnConfirmed;
18+
19+
public Action? OnCancelled;
20+
21+
public DialogWindowDesc(string title, string dsscEntty, List<QuickDialogEntry> entries, bool ok = true)
22+
{
23+
RobustXamlLoader.Load(this);
24+
25+
Title = title;
26+
27+
OkButton.Visible = ok;
28+
29+
_promptLines = new(entries.Count);
30+
31+
for (int i = 0; i < entries.Count; i++)
32+
{
33+
var entry = entries[i];
34+
35+
var box = new BoxContainer();
36+
box.AddChild(new Label() { Text = entry.Prompt, Align = Label.AlignMode.Center, HorizontalExpand = true});
37+
Prompts.AddChild(box);
38+
39+
var boxDesc = new BoxContainer();
40+
boxDesc.AddChild(new Label() { Text = dsscEntty, Align = Label.AlignMode.Center, FontColorOverride = Color.Gray, HorizontalExpand = true });
41+
Prompts.AddChild(boxDesc);
42+
43+
var boxEmpty = new BoxContainer();
44+
boxEmpty.AddChild(new BoxContainer() {MinHeight=20});
45+
Prompts.AddChild(boxEmpty);
46+
47+
var boxEdit = new BoxContainer();
48+
var edit = new LineEdit() { HorizontalExpand = true };
49+
boxEdit.AddChild(edit);
50+
51+
_promptLines.Add((entry.FieldId, edit));
52+
Prompts.AddChild(boxEdit);
53+
}
54+
55+
OkButton.OnPressed += _ => Confirm();
56+
57+
OnClose += () =>
58+
{
59+
if (!_finished)
60+
OnCancelled?.Invoke();
61+
};
62+
63+
_promptLines[0].Item2.GrabKeyboardFocus();
64+
65+
MinWidth *= 2; // Just double it.
66+
67+
OpenCentered();
68+
}
69+
70+
private void Confirm()
71+
{
72+
var results = new Dictionary<string, string>();
73+
foreach (var (field, edit) in _promptLines)
74+
{
75+
results[field] = edit.Text;
76+
}
77+
78+
_finished = true;
79+
OnConfirmed?.Invoke(results);
80+
Close();
81+
}
82+
}
83+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt
2+
using Content.Client.SS220.DialogWindowDescUI;
3+
using Content.Shared.Administration;
4+
5+
namespace Content.Client.SS220.QuickDialog;
6+
7+
public sealed class QuickDialogSystem : EntitySystem
8+
{
9+
/// <inheritdoc/>
10+
public override void Initialize()
11+
{
12+
SubscribeNetworkEvent<QuickDialogDescOpenEvent>(OpenDialog);
13+
}
14+
15+
private void OpenDialog(QuickDialogDescOpenEvent ev)
16+
{
17+
var ok = (ev.Buttons & QuickDialogButtonFlag.OkButton) != 0;
18+
var window = new DialogWindowDesc(ev.Title, ev.Description, ev.Prompts, ok: ok);
19+
20+
window.OnConfirmed += responses =>
21+
{
22+
RaiseNetworkEvent(new QuickDialogResponseEvent(ev.DialogId,
23+
responses,
24+
QuickDialogButtonFlag.OkButton));
25+
};
26+
27+
window.OnCancelled += () =>
28+
{
29+
RaiseNetworkEvent(new QuickDialogResponseEvent(ev.DialogId,
30+
new(),
31+
QuickDialogButtonFlag.CancelButton));
32+
};
33+
}
34+
}
35+

Content.Server/Administration/QuickDialogSystem.OpenDialog.cs

+29
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,33 @@ public void OpenDialog<T1, T2, T3, T4>(ICommonSession session, string title, str
173173
cancelAction ?? (() => { })
174174
);
175175
}
176+
177+
//SS220-RenameStart - start
178+
[PublicAPI]
179+
public void OpenDialog<T1>(ICommonSession session, string title, string description, string prompt, Action<T1> okAction,
180+
Action? cancelAction = null)
181+
{
182+
OpenDialogInternal(
183+
session,
184+
title,
185+
description,
186+
new List<QuickDialogEntry>
187+
{
188+
new("1", TypeToEntryType(typeof(T1)), prompt)
189+
},
190+
QuickDialogButtonFlag.OkButton | QuickDialogButtonFlag.CancelButton,
191+
(ev =>
192+
{
193+
if (TryParseQuickDialog<T1>(TypeToEntryType(typeof(T1)), ev.Responses["1"], out var v1))
194+
okAction.Invoke(v1);
195+
else
196+
{
197+
session.Channel.Disconnect("Replied with invalid quick dialog data.");
198+
cancelAction?.Invoke();
199+
}
200+
}),
201+
cancelAction ?? (() => { })
202+
);
203+
}
204+
//SS220-RenameStart - end
176205
}

Content.Server/Administration/QuickDialogSystem.cs

+22
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,28 @@ private void OpenDialogInternal(ICommonSession session, string title, List<Quick
103103
_openDialogsByUser[session.UserId].Add(did);
104104
}
105105

106+
//SS220-RenameStart - start
107+
private void OpenDialogInternal(ICommonSession session, string title, string description, List<QuickDialogEntry> entries, QuickDialogButtonFlag buttons, Action<QuickDialogResponseEvent> okAction, Action cancelAction)
108+
{
109+
var did = GetDialogId();
110+
RaiseNetworkEvent(
111+
new QuickDialogDescOpenEvent(
112+
title,
113+
description,
114+
entries,
115+
did,
116+
buttons),
117+
session
118+
);
119+
120+
_openDialogs.Add(did, (okAction, cancelAction));
121+
if (!_openDialogsByUser.ContainsKey(session.UserId))
122+
_openDialogsByUser.Add(session.UserId, new List<int>());
123+
124+
_openDialogsByUser[session.UserId].Add(did);
125+
}
126+
//SS220-RenameStart - end
127+
106128
private bool TryParseQuickDialog<T>(QuickDialogEntryType entryType, string input, [NotNullWhen(true)] out T? output)
107129
{
108130
switch (entryType)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt
2+
namespace Content.Server.SS220.RenameStart;
3+
4+
/// <summary>
5+
/// This is used for change the entity name once the player starts controlling
6+
/// </summary>
7+
[RegisterComponent]
8+
public sealed partial class RenameStartComponent : Component
9+
{
10+
[DataField]
11+
public int MinChar = 2;
12+
13+
[DataField]
14+
public int MaxChar = 36;
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt
2+
using System.Text.RegularExpressions;
3+
using Content.Server.Administration;
4+
using Content.Server.Administration.Systems;
5+
using Content.Shared.Administration;
6+
using Robust.Shared.Player;
7+
8+
namespace Content.Server.SS220.RenameStart;
9+
10+
/// <summary>
11+
/// This handles opens the ui to change your name at the beginning of the game. Renaming is necessary for such roles as a clown with a “custom” name
12+
/// </summary>
13+
public sealed class RenameStartSystem : EntitySystem
14+
{
15+
[Dependency] private readonly QuickDialogSystem _quickDialog = default!;
16+
[Dependency] private readonly MetaDataSystem _meta = default!;
17+
[Dependency] private readonly AdminFrozenSystem _frozen = default!;
18+
private static readonly Regex Expressions = new("[^А-Яа-яёЁ0-9' \\-?!,.]");
19+
/// <inheritdoc/>
20+
public override void Initialize()
21+
{
22+
SubscribeLocalEvent<RenameStartComponent, PlayerAttachedEvent>(OnPlayerAttached);
23+
}
24+
25+
private void OnPlayerAttached(Entity<RenameStartComponent> ent, ref PlayerAttachedEvent args)
26+
{
27+
_frozen.FreezeAndMute(ent.Owner); //prevent players from changing their name after showing up with their initial name
28+
29+
ChangeName(ent.Owner);
30+
}
31+
32+
private void ChangeName(EntityUid entOwner)
33+
{
34+
if(!TryComp<ActorComponent>(entOwner, out var actorComp))
35+
return;
36+
37+
if(!TryComp<RenameStartComponent>(entOwner, out var renameComp))
38+
return;
39+
40+
_quickDialog.OpenDialog(actorComp.PlayerSession,
41+
Loc.GetString("rename-window-title"),
42+
description: Loc.GetString("rename-window-desc"),
43+
Loc.GetString("rename-window-promt"),
44+
(LongString newName) =>
45+
{
46+
if (newName.String.Length <= renameComp.MinChar ||
47+
newName.String.Length >= renameComp.MaxChar ||
48+
Expressions.IsMatch(newName.String))
49+
{
50+
ChangeName(entOwner);
51+
return;
52+
}
53+
54+
_meta.SetEntityName(entOwner, newName);
55+
56+
RemComp<AdminFrozenComponent>(entOwner);
57+
58+
RemComp<RenameStartComponent>(entOwner);
59+
60+
}, () =>
61+
{
62+
RemComp<AdminFrozenComponent>(entOwner);
63+
64+
RemComp<RenameStartComponent>(entOwner);
65+
});
66+
}
67+
}

Content.Shared/Administration/QuickDialogOpenEvent.cs

+40
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,46 @@ public QuickDialogOpenEvent(string title, List<QuickDialogEntry> prompts, int di
3737
}
3838
}
3939

40+
//SS220-RenameStart - start
41+
[Serializable, NetSerializable]
42+
public sealed class QuickDialogDescOpenEvent : EntityEventArgs
43+
{
44+
/// <summary>
45+
/// The title of the dialog.
46+
/// </summary>
47+
public string Title;
48+
49+
/// <summary>
50+
/// The title of the dialog.
51+
/// </summary>
52+
public string Description;
53+
54+
/// <summary>
55+
/// The internal dialog ID.
56+
/// </summary>
57+
public int DialogId;
58+
59+
/// <summary>
60+
/// The prompts to show the user.
61+
/// </summary>
62+
public List<QuickDialogEntry> Prompts;
63+
64+
/// <summary>
65+
/// The buttons presented for the user.
66+
/// </summary>
67+
public QuickDialogButtonFlag Buttons = QuickDialogButtonFlag.OkButton | QuickDialogButtonFlag.CancelButton;
68+
69+
public QuickDialogDescOpenEvent(string title, string description, List<QuickDialogEntry> prompts, int dialogId, QuickDialogButtonFlag buttons)
70+
{
71+
Title = title;
72+
Description = description;
73+
Prompts = prompts;
74+
Buttons = buttons;
75+
DialogId = dialogId;
76+
}
77+
}
78+
//SS220-RenameStart - end
79+
4080
/// <summary>
4181
/// A networked event raised when the client replies to a quick dialog.
4282
/// </summary>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
quick-dialog-ui-confirm = Подтвердить
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
rename-window-title = Переименование
2+
rename-window-promt = Выберите свое новое имя
3+
rename-window-desc =
4+
Ваше имя не должно нарушать 4 пункт правил:
5+
Ваш персонаж - находится на передовой космической станции.
6+
Клоуну и миму предоставляется более широкое поле для мемных имён
7+
Имена синтетиков так же имеют свою специфику. Ознакомьтесь с ними на вики.

Resources/Prototypes/Roles/Jobs/Civilian/clown.yml

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
special:
1919
- !type:AddComponentSpecial
2020
components:
21+
- type: RenameStart #SS220-RenameStart
2122
- type: Clumsy
2223
clumsyDamage:
2324
types: #literally just picked semi random valus. i tested this once and tweaked it.

Resources/Prototypes/Roles/Jobs/Civilian/mime.yml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
components:
2121
- type: MimePowers
2222
- type: FrenchAccent
23+
- type: RenameStart #SS220-RenameStart
2324

2425
- type: startingGear
2526
id: MimeGear

Resources/Prototypes/Roles/Jobs/Science/borg.yml

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
supervisors: job-supervisors-rd
1919
jobEntity: StationAiBrain
2020
applyTraits: false
21+
special:
22+
- !type:AddComponentSpecial
23+
components:
24+
- type: RenameStart #SS220-RenameStart
2125

2226
- type: job
2327
id: Borg
@@ -32,3 +36,7 @@
3236
supervisors: job-supervisors-rd
3337
jobEntity: PlayerBorgGeneric
3438
applyTraits: false
39+
special:
40+
- !type:AddComponentSpecial
41+
components:
42+
- type: RenameStart #SS220-RenameStart

0 commit comments

Comments
 (0)