Skip to content

Commit

Permalink
Финальные штрихи
Browse files Browse the repository at this point in the history
  • Loading branch information
FaDeOkno committed Aug 3, 2024
1 parent bda2223 commit 3f751f3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
47 changes: 43 additions & 4 deletions Content.Client/ADT/Language/UI/LanguageMenuWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public sealed partial class LanguageMenuWindow : DefaultWindow
private readonly SharedLanguageSystem _language;

private readonly List<EntryState> _entries = new();
private readonly List<Option> _optionLists = new();

public LanguageMenuWindow()
{
Expand All @@ -41,12 +42,37 @@ public void UpdateState(LanguageMenuStateMessage state)
{
CurrentLanguageLabel.Text = Loc.GetString("language-menu-current-language", ("language", _language.GetLanguage(state.CurrentLanguage).LocalizedName));

OptionsList.RemoveAllChildren();
_entries.Clear();
//OptionsList.RemoveAllChildren();
List<string> options = state.Options;
List<Option> optionList = _optionLists;
foreach (var entry in _entries)
{
if (state.Options.Contains(entry.Language))
{
options.Remove(entry.Language);
continue;
}
else
{
_entries.Remove(entry);

foreach (var item in optionList)
{
if (item.LanguageId == entry.Language)
{
_optionLists.Remove(item);
OptionsList.RemoveChild(item.PanelContainer);
}
}
}
}

foreach (var language in state.Options)
if (options.Count > 0)
{
AddLanguageEntry(language);
foreach (var language in options)
{
AddLanguageEntry(language);
}
}

// Disable the button for the currently chosen language
Expand Down Expand Up @@ -124,6 +150,12 @@ private void AddLanguageEntry(string language)
OptionsList.AddChild(wrapper);

_entries.Add(state);

var option = new Option();
option.LanguageId = state.Language;
option.PanelContainer = wrapper;

_optionLists.Add(option);
}

private void OnLanguageChosen(string id)
Expand All @@ -140,4 +172,11 @@ private struct EntryState
public string Language;
public Button? Button;
}

private struct Option
{
public string LanguageId;
public PanelContainer PanelContainer;
}

}
8 changes: 4 additions & 4 deletions Content.Server/ADT/Language/LanguageSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ private void ObfuscateSyllables(StringBuilder builder, string message, LanguageP
{
var ch = char.ToLower(message[i]);
// A word ends when one of the following is found: a space, a sentence end, or EOM
if (char.IsWhiteSpace(ch) || (ch is '.' or '!' or '?') || i == message.Length - 1)
if (char.IsWhiteSpace(ch) || (ch is '.' or '!' or '?' or '~' or '-' or ',') || i == message.Length - 1)
{
var wordLength = i - wordBeginIndex;
var wordLength = i + 1 - wordBeginIndex;
if (wordLength > 0)
{
var newWordLength = PseudoRandomNumber(hashCode, 1, 4);
Expand Down Expand Up @@ -125,9 +125,9 @@ private void ObfuscatePhrases(StringBuilder builder, string message, LanguagePro
for (var i = 0; i < message.Length; i++)
{
var ch = char.ToLower(message[i]);
if ((ch is '.' or '!' or '?') || i == message.Length - 1)
if ((ch is '.' or '!' or '?' or '~' or '-' or ',') || i == message.Length - 1)
{
var length = i - sentenceBeginIndex;
var length = i + 1 - sentenceBeginIndex;
if (length > 0)
{
var newLength = (int) Math.Clamp(Math.Cbrt(length) - 1, 1, 4); // 27+ chars for 2 phrases, 64+ for 3, 125+ for 4.
Expand Down

0 comments on commit 3f751f3

Please sign in to comment.