Skip to content

Commit

Permalink
там чутка убавить, там чутка ваучеры добавить
Browse files Browse the repository at this point in the history
  • Loading branch information
Ratyyy committed Dec 24, 2024
1 parent 54a7267 commit ef6d7a9
Show file tree
Hide file tree
Showing 18 changed files with 436 additions and 1 deletion.
27 changes: 27 additions & 0 deletions Content.Client/ADT/Salvage/UI/MiningVoucherBoundUserInterface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Content.Shared.ADT.Salvage;
using Robust.Client.UserInterface;

namespace Content.Client.ADT.Salvage.UI;

public sealed class MiningVoucherBoundUserInterface : BoundUserInterface
{
[ViewVariables]
private MiningVoucherMenu? _menu;

public MiningVoucherBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}

protected override void Open()
{
base.Open();

_menu = this.CreateWindow<MiningVoucherMenu>();
_menu.SetEntity(Owner);
_menu.OnSelected += i =>
{
SendMessage(new MiningVoucherSelectMessage(i));
Close();
};
}
}
10 changes: 10 additions & 0 deletions Content.Client/ADT/Salvage/UI/MiningVoucherMenu.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<ui:RadialMenu xmlns="https://spacestation14.io"
xmlns:ui="clr-namespace:Content.Client.UserInterface.Controls"
BackButtonStyleClass="RadialMenuBackButton"
CloseButtonStyleClass="RadialMenuCloseButton"
VerticalExpand="True"
HorizontalExpand="True"
MinSize="450 450">
<!-- Populated in SetEntity -->
<ui:RadialContainer Name="Main" VerticalExpand="True" HorizontalExpand="True" Radius="64"/>
</ui:RadialMenu>
59 changes: 59 additions & 0 deletions Content.Client/ADT/Salvage/UI/MiningVoucherMenu.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Content.Client.UserInterface.Controls;
using Content.Shared.ADT.Salvage.Components;
using Robust.Client.AutoGenerated;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
using System.Numerics;

namespace Content.Client.ADT.Salvage.UI;

[GenerateTypedNameReferences]
public sealed partial class MiningVoucherMenu : RadialMenu
{
[Dependency] private readonly IEntityManager _entMan = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;

private readonly SpriteSystem _sprite;

public event Action<int>? OnSelected;

public MiningVoucherMenu()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);

_sprite = _entMan.System<SpriteSystem>();
}

public void SetEntity(EntityUid owner)
{
if (!_entMan.TryGetComponent<MiningVoucherComponent>(owner, out var comp))
return;

for (int i = 0; i < comp.Kits.Count; i++)
{
var index = i; // copy so the closure doesn't borrow it
var kit = _proto.Index(comp.Kits[i]);
var button = new RadialMenuTextureButton()
{
StyleClasses = { "RadialMenuButton" },
SetSize = new Vector2(64f, 64f),
ToolTip = Loc.GetString(kit.Description)
};
button.AddChild(new TextureRect()
{
VerticalAlignment = VAlignment.Center,
HorizontalAlignment = HAlignment.Center,
Texture = _sprite.Frame0(kit.Sprite),
TextureScale = new Vector2(2f, 2f)
});

button.OnPressed += _ => OnSelected?.Invoke(index);

Main.AddChild(button);
}
}
}
40 changes: 40 additions & 0 deletions Content.Shared/ADT/Salvage/Components/MiningVoucherComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Content.Shared.ADT.Salvage.Systems;
using Content.Shared.Thief;
using Content.Shared.Whitelist;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;

namespace Content.Shared.ADT.Salvage.Components;

/// <summary>
/// Thief toolbox except it uses a radial menu and has to be redeemed at the salvage vendor.
/// </summary>
[RegisterComponent, NetworkedComponent, Access(typeof(MiningVoucherSystem))]
[AutoGenerateComponentState]
public sealed partial class MiningVoucherComponent : Component
{
/// <summary>
/// Vendor must match this whitelist to be redeemed.
/// </summary>
[DataField(required: true)]
public EntityWhitelist VendorWhitelist;

/// <summary>
/// The kits that can be selected.
/// </summary>
[DataField(required: true)]
public List<ProtoId<ThiefBackpackSetPrototype>> Kits = new();

/// <summary>
/// The index of the selected kit.
/// </summary>
[DataField, AutoNetworkedField]
public int? Selected;

/// <summary>
/// Sound to play when redeeming the voucher.
/// </summary>
[DataField]
public SoundSpecifier? RedeemSound = new SoundPathSpecifier("/Audio/Machines/twobeep.ogg");
}
18 changes: 18 additions & 0 deletions Content.Shared/ADT/Salvage/MiningVoucherUI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Robust.Shared.Serialization;

namespace Content.Shared.ADT.Salvage;

/// <summary>
/// Message for a mining voucher kit to be selected.
/// </summary>
[Serializable, NetSerializable]
public sealed class MiningVoucherSelectMessage(int index) : BoundUserInterfaceMessage
{
public readonly int Index = index;
}

[Serializable, NetSerializable]
public enum MiningVoucherUiKey : byte
{
Key
}
93 changes: 93 additions & 0 deletions Content.Shared/ADT/Salvage/Systems/MiningVoucherSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using Content.Shared.ADT.Salvage.Components;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using Content.Shared.Power.EntitySystems;
using Content.Shared.Whitelist;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Network;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;

namespace Content.Shared.ADT.Salvage.Systems;

public sealed class MiningVoucherSystem : EntitySystem
{
[Dependency] private readonly EntityWhitelistSystem _whitelist = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly INetManager _net = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly SharedPowerReceiverSystem _power = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<MiningVoucherComponent, AfterInteractEvent>(OnAfterInteract);
Subs.BuiEvents<MiningVoucherComponent>(MiningVoucherUiKey.Key, subs =>
{
subs.Event<MiningVoucherSelectMessage>(OnSelect);
});
}

private void OnAfterInteract(Entity<MiningVoucherComponent> ent, ref AfterInteractEvent args)
{
if (args.Target is not {} target)
return;

if (_whitelist.IsWhitelistFail(ent.Comp.VendorWhitelist, target))
return;

var user = args.User;
args.Handled = true;

if (ent.Comp.Selected is not {} index)
{
_popup.PopupClient(Loc.GetString("mining-voucher-select-first"), target, user);
return;
}

if (!_power.IsPowered(target))
{
_popup.PopupClient(Loc.GetString("mining-voucher-vendor-unpowered", ("vendor", target)), target, user);
return;
}

if (!_timing.IsFirstTimePredicted)
return;

_audio.PlayPredicted(ent.Comp.RedeemSound, target, user);
Redeem(ent, index, user);
}

private void OnSelect(Entity<MiningVoucherComponent> ent, ref MiningVoucherSelectMessage args)
{
var index = args.Index;
if (index < 0 || index >= ent.Comp.Kits.Count)
return;

var user = args.Actor;
var kit = _proto.Index(ent.Comp.Kits[index]);
var name = Loc.GetString(kit.Name);
_popup.PopupEntity(Loc.GetString("mining-voucher-selected", ("kit", name)), user, user);

ent.Comp.Selected = index;
Dirty(ent);
}

public void Redeem(Entity<MiningVoucherComponent> ent, int index, EntityUid user)
{
if (_net.IsClient)
return;

var kit = _proto.Index(ent.Comp.Kits[index]);
var xform = Transform(ent);
foreach (var id in kit.Content)
{
SpawnNextToOrDrop(id, ent, xform);
}

QueueDel(ent);
}
}
31 changes: 31 additions & 0 deletions Resources/Locale/ru-RU/ADT/salvage/mining-voucher.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
mining-voucher-select-first = Выберите набор в начале!
mining-voucher-unpowered = {CAPITALIZE(THE($vendor))} не запитан!
mining-voucher-selected = Выбран {$kit}!
mining-voucher-crusher-name = Набор крушителя
mining-voucher-crusher-description =
Содержит кинетический крушитель
Крушитель - это универсальное оружие, способное добывать ископаемые и помогать при убийстве фауны.
Однако его трудно использовать эффективно для всех, кроме самых опытных и/или склонных к суициду шахтеров.
mining-voucher-extraction-name = Доставка и спасение
mining-voucher-extraction-description =
Содержит фултон-маяк и 20 фултонов, которые позволяют отправлять минералы,
предметы и трупы домой, не прибегая к помощи шахтерского шаттла.
mining-voucher-resonator-name = Набор резонатора
mining-voucher-resonator-description =
Содержит резонатор и карманный огнетушитель.
Резонатор - это портативное устройство, создающее небольшие поля
энергии, которые резонируют, пока не взорвутся, разрушая камень.
Он наносит повышенный урон при низком давлении.
mining-voucher-survival-name = РПС
mining-voucher-survival-description =
Содержит РПС утилизатора, что позволяет переносить ещё больше вещей.
mining-voucher-minebot-name = Набор роботизированных раскопок
mining-voucher-minebot-description =
Содержит маленького компаньона-копатьбота, который помогает вам хранить руду и охотиться на диких животных.
mining-voucher-spatio-name = Лёгкий скафандр утилизатора
mining-voucher-spatio-description =
Легковесный скафандр, предназначенный для сложных технических работ в космосе.
mining-voucher-mining-armor-name = Костюм исследователя
mining-voucher-mining-armor-description =
Не спасёт от давления, но хорошо защищает от фауны.
82 changes: 82 additions & 0 deletions Resources/Prototypes/ADT/Catalog/mining_voucher.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
- type: thiefBackpackSet
id: MiningCrusher
name: mining-voucher-crusher-name
description: mining-voucher-crusher-description
sprite:
sprite: Objects/Weapons/Melee/crusher.rsi
state: icon
content:
- WeaponCrusher
- FireExtinguisherMini

- type: thiefBackpackSet
id: MiningExtraction
name: mining-voucher-extraction-name
description: mining-voucher-extraction-description
sprite:
sprite: Objects/Tools/fulton.rsi
state: extraction_pack
content:
- Fulton
- Fulton
- FultonBeacon
# TODO: 30 marker beacons

# TODO: resonator
#- type: thiefBackpackSet
# id: MiningResonator
# name: mining-voucher-resonator-name
# description: mining-voucher-resonator-description
# sprite:
# sprite: DeltaV/Objects/Weapons/Ranged/resonator.rsi
# state: icon
# content:
# - Resonator
# - FireExtinguisherMini

# TODO: bluespace shelter capsule so this isnt a scam
#- type: thiefBackpackSet
# id: MiningSurvival
# name: mining-voucher-survival-name
# description: mining-voucher-survival-description
# sprite:
# sprite: Clothing/Belt/salvagewebbing.rsi
# state: icon
# content:
# - ClothingBeltSalvageWebbing

# TODO: mining drone
#- type: thiefBackpackSet
# id: MiningDrone
# name: mining-voucher-minebot-name
# description: mining-voucher-minebot-description
# sprite:
# sprite: ...
# state: icon
# content:
# - mining drone...
# - WelderIndustrial
# - ClothingHeadHatWelding
# - drone passthrough ka modkit

- type: thiefBackpackSet
id: MiningArmor
name: mining-voucher-mining-armor-name
description: mining-voucher-mining-armor-description
sprite:
sprite: ADT/Clothing/OuterClothing/Armor/mining.rsi
state: icon
content:
- ADTClothingOuterArmorMiner
- ClothingMaskGasExplorer

- type: thiefBackpackSet
id: MiningSpatio
name: mining-voucher-spatio-name
description: mining-voucher-spatio-description
sprite:
sprite: Clothing/OuterClothing/Hardsuits/spatio.rsi
state: icon
content:
- ClothingOuterHardsuitSpatio
- ClothingMaskGasExplorer
Loading

0 comments on commit ef6d7a9

Please sign in to comment.