Фичи для педалей (#202)

This commit is contained in:
Aviu00
2023-07-16 11:32:42 +03:00
committed by Aviu00
parent 65ef100acd
commit 3f8ff32206
21 changed files with 337 additions and 32 deletions

View File

@@ -19,11 +19,11 @@ namespace Content.Client.Administration.Systems
OnBwoinkTextMessageRecieved?.Invoke(this, message);
}
public void Send(NetUserId channelId, string text)
public void Send(NetUserId channelId, string text, bool isAdmin)
{
// Reuse the channel ID as the 'true sender'.
// Server will ignore this and if someone makes it not ignore this (which is bad, allows impersonation!!!), that will help.
RaiseNetworkEvent(new BwoinkTextMessage(channelId, channelId, text));
RaiseNetworkEvent(new BwoinkTextMessage(channelId, channelId, text, isAdmin));
SendInputTextUpdated(channelId, false);
}

View File

@@ -4,6 +4,9 @@
x:Class="Content.Client.Options.UI.Tabs.AdminSettingsTab">
<BoxContainer Orientation="Vertical">
<BoxContainer Orientation="Vertical" Margin="5 0 0 0" VerticalExpand="True">
<BoxContainer Orientation="Horizontal" Margin="4 10 4 0">
<CheckBox Name="DeadChatAdminCheckbox" Text="Отображать сообщения в гост чате как админские" />
</BoxContainer>
<BoxContainer Orientation="Horizontal" Margin="0 3 0 0">
<Label Text="Громкость звука ахелпа" HorizontalExpand="True"/>
<Control MinSize="8 0" />
@@ -28,10 +31,6 @@
StyleClasses="Caution"
HorizontalExpand="True"
HorizontalAlignment="Right" />
<Button Name="DefaultButton"
Text="{Loc 'ui-options-default'}"
TextAlign="Center"
HorizontalAlignment="Right" />
<Control MinSize="2 0" />
<Button Name="ApplyButton"
Text="{Loc 'ui-options-apply'}"

View File

@@ -1,7 +1,7 @@
using Content.Shared.CCVar;
using Content.Shared.White;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Configuration;
using Range = Robust.Client.UserInterface.Controls.Range;
@@ -18,28 +18,72 @@ public sealed partial class AdminSettingsTab : Control
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
LoadData();
Reset();
ApplyButton.OnPressed += OnApplyButtonPressed;
ResetButton.OnPressed += OnResetButtonPressed;
DeadChatAdminCheckbox.OnToggled += OnDeadChatAdminToggled;
AhelpSoundVolume.OnValueChanged += OnAhelpVolumeChanged;
}
protected override void Dispose(bool disposing)
{
ApplyButton.OnPressed -= OnApplyButtonPressed;
ResetButton.OnPressed -= OnResetButtonPressed;
DeadChatAdminCheckbox.OnToggled -= OnDeadChatAdminToggled;
AhelpSoundVolume.OnValueChanged -= OnAhelpVolumeChanged;
base.Dispose(disposing);
}
private void LoadData()
private void OnApplyButtonPressed(BaseButton.ButtonEventArgs args)
{
var bwoinkVolume = _cfg.GetCVar(WhiteCVars.BwoinkVolume);
AhelpSoundVolume.Value = bwoinkVolume;
AhelpSoundVolumeLabel.Text = ((int) bwoinkVolume).ToString();
_cfg.SetCVar(WhiteCVars.BwoinkVolume, LV100ToDB(AhelpSoundVolume.Value));
_cfg.SetCVar(WhiteCVars.DeadChatAdmin, DeadChatAdminCheckbox.Pressed);
_cfg.SaveToFile();
UpdateChanges();
}
private void OnResetButtonPressed(BaseButton.ButtonEventArgs args)
{
Reset();
}
private void Reset()
{
DeadChatAdminCheckbox.Pressed = _cfg.GetCVar(WhiteCVars.DeadChatAdmin);
AhelpSoundVolume.Value = DBToLV100(_cfg.GetCVar(WhiteCVars.BwoinkVolume));
UpdateChanges();
}
private void UpdateChanges()
{
var isAhelpSoundVolumeSame =
Math.Abs(AhelpSoundVolume.Value - DBToLV100(_cfg.GetCVar(WhiteCVars.BwoinkVolume))) < 0.01f;
var isDeadChatAdminSame = DeadChatAdminCheckbox.Pressed == _cfg.GetCVar(WhiteCVars.DeadChatAdmin);
var isEverythingSame = isAhelpSoundVolumeSame && isDeadChatAdminSame;
ApplyButton.Disabled = isEverythingSame;
ResetButton.Disabled = isEverythingSame;
AhelpSoundVolumeLabel.Text =
Loc.GetString("ui-options-volume-percent", ("volume", AhelpSoundVolume.Value / 100));
}
private void OnAhelpVolumeChanged(Range newValue)
{
_cfg.SetCVar(WhiteCVars.BwoinkVolume, LV100ToDB(newValue.Value));
AhelpSoundVolumeLabel.Text = ((int)newValue.Value).ToString();
UpdateChanges();
}
private void OnDeadChatAdminToggled(BaseButton.ButtonToggledEventArgs obj)
{
UpdateChanges();
}
private float DBToLV100(float db)
{
return MathF.Pow(10, db / 10) * 100;
}
private float LV100ToDB(float lv100)

View File

@@ -143,8 +143,9 @@ public sealed class AHelpUIController: UIController, IOnSystemChanged<BwoinkSyst
return;
}
float bwoinkVolume = _clientAdminManager.IsActive() ? adminBwoinkVolume : defaultBwoinkVolume;
var isAdmin = _adminManager.IsActive();
var notify = !isAdmin || !message.IsAdmin;
float bwoinkVolume = isAdmin ? adminBwoinkVolume : defaultBwoinkVolume;
var audioParams = new AudioParams()
{
@@ -152,7 +153,7 @@ public sealed class AHelpUIController: UIController, IOnSystemChanged<BwoinkSyst
};
if (localPlayer.UserId != message.TrueSender)
if (localPlayer.UserId != message.TrueSender && notify)
{
if (_aHelpSound != null)
_audio.PlayGlobal(_aHelpSound, Filter.Local(), false, audioParams);
@@ -161,7 +162,7 @@ public sealed class AHelpUIController: UIController, IOnSystemChanged<BwoinkSyst
EnsureUIHelper();
if (!UIHelper!.IsOpen)
if (!UIHelper!.IsOpen && notify)
{
UnreadAHelpReceived();
}
@@ -192,7 +193,7 @@ public sealed class AHelpUIController: UIController, IOnSystemChanged<BwoinkSyst
UIHelper = isAdmin ? new AdminAHelpUIHandler(ownerUserId) : new UserAHelpUIHandler(ownerUserId);
UIHelper.DiscordRelayChanged(_discordRelayActive);
UIHelper.SendMessageAction = (userId, textMessage) => _bwoinkSystem?.Send(userId, textMessage);
UIHelper.SendMessageAction = (userId, textMessage) => _bwoinkSystem?.Send(userId, textMessage, isAdmin);
UIHelper.InputTextChanged += (channel, text) => _bwoinkSystem?.SendInputTextUpdated(channel, text.Length > 0);
UIHelper.OnClose += () => { SetAHelpPressed(false); };
UIHelper.OnOpen += () => { SetAHelpPressed(true); };

View File

@@ -0,0 +1,55 @@
using Content.Shared.Actions;
using Content.Shared.Popups;
using Content.Shared.White.Administration;
using Robust.Client.Console;
using Robust.Client.GameObjects;
namespace Content.Client.White.Administration;
public sealed class InvisibilitySystem : SharedInvisibilitySystem
{
[Dependency] private readonly SharedActionsSystem _actions = default!;
[Dependency] private readonly IClientConsoleHost _console = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<InvisibilityComponent, ComponentInit>(OnInvisibilityInit);
SubscribeLocalEvent<InvisibilityComponent, ComponentRemove>(OnInvisibilityRemove);
SubscribeLocalEvent<InvisibilityComponent, ToggleInvisibilityActionEvent>(OnToggleGhosts);
SubscribeNetworkEvent<InvisibilityToggleEvent>(OnInvisibilityToggle);
}
private void OnInvisibilityToggle(InvisibilityToggleEvent ev)
{
if (!EntityManager.TryGetComponent(ev.Uid, out SpriteComponent? sprite))
return;
var newAlpha = Math.Clamp(ev.Invisible ? sprite.Color.A / 3f : sprite.Color.A * 3f, 0f, 1f);
sprite.Color = sprite.Color.WithAlpha(newAlpha);
}
private void OnInvisibilityInit(EntityUid uid, InvisibilityComponent component, ComponentInit args)
{
_actions.AddAction(uid, component.ToggleInvisibilityAction, null);
}
private void OnInvisibilityRemove(EntityUid uid, InvisibilityComponent component, ComponentRemove args)
{
_actions.RemoveAction(uid, component.ToggleInvisibilityAction);
}
private void OnToggleGhosts(EntityUid uid, InvisibilityComponent component, ToggleInvisibilityActionEvent args)
{
if (args.Handled)
return;
_popup.PopupEntity("Невидимость переключена", args.Performer);
_console.RemoteExecuteCommand(null, "invisibility");
args.Handled = true;
}
}