Skip to content

Commit

Permalink
improve antag requirements
Browse files Browse the repository at this point in the history
* gameroletimers cvar affects antag roles now too

* added tooltip of required time and locked role text
  • Loading branch information
AruMoon committed Jun 21, 2023
1 parent 86d6533 commit cf72d18
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public bool IsAllowed(AntagPrototype antag, [NotNullWhen(false)] out string? rea
{
reason = null;

if (!_cfg.GetCVar(CCVars.GameRoleTimers))
return true;

var player = _playerManager.LocalPlayer?.Session;

if (player == null) return true;
Expand Down
30 changes: 17 additions & 13 deletions Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -478,23 +478,23 @@ public HumanoidProfileEditor(IClientPreferencesManager preferencesManager, IProt

foreach (var antag in prototypeManager.EnumeratePrototypes<AntagPrototype>().OrderBy(a => Loc.GetString(a.Name)))
{
bool check = false;
if(playTime.IsAllowed(antag, out var reason))
var selector = new AntagPreferenceSelector(antag);

if (!playTime.IsAllowed(antag, out var reason))
{
check = true;
selector.LockRequirements(antag, reason);
}

if (!antag.SetPreference)
{
continue;
}

var selector = new AntagPreferenceSelector(antag,check);
selector.Preference = false;
_antagList.AddChild(selector);
_antagPreferences.Add(selector);



selector.PreferenceChanged += preference =>
{
Expand Down Expand Up @@ -1329,7 +1329,7 @@ private sealed class AntagPreferenceSelector : Control
{
public AntagPrototype Antag { get; }
private readonly CheckBox _checkBox;

public bool Preference
{
get => _checkBox.Pressed;
Expand All @@ -1338,7 +1338,7 @@ public bool Preference
public bool Locked = false;
public event Action<bool>? PreferenceChanged;

public AntagPreferenceSelector(AntagPrototype antag, bool check)
public AntagPreferenceSelector(AntagPrototype antag)
{
Antag = antag;

Expand All @@ -1359,11 +1359,15 @@ public AntagPreferenceSelector(AntagPrototype antag, bool check)
_checkBox
}
});
if (check == false)
{
Locked = true;
_checkBox.Disabled = true;
}

}

public void LockRequirements(AntagPrototype antag, string requirements)
{
Locked = true;
_checkBox.Disabled = true;
_checkBox.Text = Loc.GetString("antag-timer-locked", ("antag", Loc.GetString(antag.Name)));
_checkBox.ToolTip = requirements;
}

private void OnCheckBoxToggled(BaseButton.ButtonToggledEventArgs args)
Expand Down
1 change: 1 addition & 0 deletions Resources/Locale/en-US/job/role-timers.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ role-timer-role-insufficient = You require {TOSTRING($time, "0")} more minutes w
role-timer-role-too-high = You require {TOSTRING($time, "0")} fewer minutes with {$job} to play this role. (Are you trying to play a trainee role?)
role-timer-locked = Locked (hover for details)
antag-timer-locked = {$antag}. Locked (hover for details)
1 change: 1 addition & 0 deletions Resources/Locale/ru-RU/job/role-timers.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ role-timer-overall-too-high = Требуется на { TOSTRING($time, "0") }
role-timer-role-insufficient = Требуется ещё { TOSTRING($time, "0") } минут игры в качестве { $job } для этой роли.
role-timer-role-too-high = Требуется на { TOSTRING($time, "0") } меньше минут игры в качестве { $job } для этой роли. (Вы пытаетесь играть за роль для новичков?)
role-timer-locked = Закрыто (наведите курсор для подробностей)
antag-timer-locked = { $antag }. Закрыт (наведите курсор для подробностей)

0 comments on commit cf72d18

Please sign in to comment.