2024-01-28 17:32:55 +07:00
|
|
|
|
using Content.Client._White.Sponsors;
|
|
|
|
|
|
using Content.Client.Administration.Managers;
|
2023-04-28 06:07:50 +06:00
|
|
|
|
using Content.Client.UserInterface.Controls;
|
|
|
|
|
|
using Content.Client.UserInterface.Systems.MenuBar.Widgets;
|
|
|
|
|
|
using Content.Shared.Humanoid;
|
2024-01-28 18:37:24 +07:00
|
|
|
|
using Content.Shared._White.MeatyOre;
|
2023-04-28 06:07:50 +06:00
|
|
|
|
using Robust.Client.Player;
|
|
|
|
|
|
using Robust.Client.UserInterface.Controllers;
|
|
|
|
|
|
using Robust.Client.UserInterface.Controls;
|
|
|
|
|
|
using Robust.Shared.Timing;
|
|
|
|
|
|
|
2024-01-28 17:32:55 +07:00
|
|
|
|
namespace Content.Client._White.MeatyOre;
|
2023-04-28 06:07:50 +06:00
|
|
|
|
|
|
|
|
|
|
public sealed class MeatyOreUIController : UIController
|
|
|
|
|
|
{
|
|
|
|
|
|
[Dependency] private readonly IClientAdminManager _clientAdminManager = default!;
|
|
|
|
|
|
[Dependency] private readonly IEntityManager _entityManager = default!;
|
|
|
|
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
|
|
|
|
[Dependency] private readonly IEntityNetworkManager _entityNetworkManager = default!;
|
|
|
|
|
|
[Dependency] private readonly SponsorsManager _sponsorsManager = default!;
|
|
|
|
|
|
|
|
|
|
|
|
private bool _buttonLoaded;
|
|
|
|
|
|
|
|
|
|
|
|
private MenuButton? MeatyOreButton => UIManager.GetActiveUIWidgetOrNull<GameTopMenuBar>()?.MeatyOreButton;
|
|
|
|
|
|
public void LoadButton()
|
|
|
|
|
|
{
|
|
|
|
|
|
MeatyOreButton!.OnPressed += MeatyOreButtonPressed;
|
|
|
|
|
|
_buttonLoaded = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void UnloadButton()
|
|
|
|
|
|
{
|
|
|
|
|
|
MeatyOreButton!.OnPressed -= MeatyOreButtonPressed;
|
|
|
|
|
|
_buttonLoaded = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void MeatyOreButtonPressed(BaseButton.ButtonEventArgs obj)
|
|
|
|
|
|
{
|
|
|
|
|
|
_entityNetworkManager.SendSystemNetworkMessage(new MeatyOreShopRequestEvent());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void FrameUpdate(FrameEventArgs args)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.FrameUpdate(args);
|
|
|
|
|
|
|
2024-08-25 01:37:24 +03:00
|
|
|
|
if (!_buttonLoaded)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2023-04-28 06:07:50 +06:00
|
|
|
|
var shouldBeVisible = CheckButtonVisibility();
|
|
|
|
|
|
MeatyOreButton!.Visible = shouldBeVisible;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private bool CheckButtonVisibility()
|
|
|
|
|
|
{
|
2024-08-25 01:37:24 +03:00
|
|
|
|
if (!_sponsorsManager.TryGetInfo(out var sponsor))
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
if (sponsor.Tier == null || sponsor.MeatyOreCoin == 0)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
var controlledEntity = _playerManager.LocalPlayer!.ControlledEntity;
|
2023-04-28 06:07:50 +06:00
|
|
|
|
|
2024-09-23 21:03:07 +03:00
|
|
|
|
if (!controlledEntity.HasValue)
|
2024-08-25 01:37:24 +03:00
|
|
|
|
return false;
|
2023-04-28 06:07:50 +06:00
|
|
|
|
|
2024-08-25 01:37:24 +03:00
|
|
|
|
if (!_entityManager.HasComponent<HumanoidAppearanceComponent>(controlledEntity))
|
|
|
|
|
|
return false;
|
2023-04-28 06:07:50 +06:00
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|