Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Нёрфы шахтёров #936

Merged
merged 4 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 56 additions & 55 deletions Content.Client/ADT/MiningShop/MiningShopBui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public sealed class MiningShopBui : BoundUserInterface
[Dependency] private readonly IResourceCache _resource = default!;
private readonly MiningPointsSystem _miningPoints;
private MiningShopWindow? _window;
private List<SharedMiningShopSectionPrototype> _sections = new();
public MiningShopBui(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
_miningPoints = EntMan.System<MiningPointsSystem>();
Expand All @@ -34,63 +35,61 @@ protected override void Open()
_window.OnClose += Close;
_window.Title = EntMan.GetComponentOrNull<MetaDataComponent>(Owner)?.EntityName ?? "MiningShop";

if (EntMan.TryGetComponent(Owner, out MiningShopComponent? vendor))
if (!EntMan.TryGetComponent(Owner, out MiningShopComponent? vendor))
return;
var sections = _prototype.EnumeratePrototypes<SharedMiningShopSectionPrototype>().ToList();
sections.Sort((x, y) => x.Name[0].CompareTo(x.Name[0]));

foreach (var section in sections)
{
for (var sectionIndex = 0; sectionIndex < vendor.Sections.Count; sectionIndex++)
var uiSection = new MiningShopSection();
uiSection.Label.SetMessage(GetSectionName(section));
_sections.Add(section);

foreach (var entry in section.Entries)
{
var section = vendor.Sections[sectionIndex];
var uiEntry = new MiningShopEntry();

if (_prototype.TryIndex(entry.Id, out var entity))
{
uiEntry.Texture.Textures = SpriteComponent.GetPrototypeTextures(entity, _resource)
.Select(o => o.Default)
.ToList();
uiEntry.Panel.Button.Label.Text = entry.Name?.Replace("\\n", "\n") ?? entity.Name;

var uiSection = new MiningShopSection();
uiSection.Label.SetMessage(GetSectionName(section));
var name = entity.Name;
var color = MiningShopPanel.DefaultColor;
var borderColor = MiningShopPanel.DefaultBorderColor;
var hoverColor = MiningShopPanel.DefaultBorderColor;

uiEntry.Panel.Color = color;
uiEntry.Panel.BorderColor = borderColor;
uiEntry.Panel.HoveredColor = hoverColor;

for (var entryIndex = 0; entryIndex < section.Entries.Count; entryIndex++)
{
var entry = section.Entries[entryIndex];
var uiEntry = new MiningShopEntry();

if (_prototype.TryIndex(entry.Id, out var entity))
{
uiEntry.Texture.Textures = SpriteComponent.GetPrototypeTextures(entity, _resource)
.Select(o => o.Default)
.ToList();
uiEntry.Panel.Button.Label.Text = entry.Name?.Replace("\\n", "\n") ?? entity.Name;

var name = entity.Name;
var color = MiningShopPanel.DefaultColor;
var borderColor = MiningShopPanel.DefaultBorderColor;
var hoverColor = MiningShopPanel.DefaultBorderColor;

uiEntry.Panel.Color = color;
uiEntry.Panel.BorderColor = borderColor;
uiEntry.Panel.HoveredColor = hoverColor;

var msg = new FormattedMessage();
msg.AddText(name);
msg.PushNewline();

if (!string.IsNullOrWhiteSpace(entity.Description))
msg.AddText(entity.Description);

var tooltip = new Tooltip();
tooltip.SetMessage(msg);
tooltip.MaxWidth = 250f;

uiEntry.TooltipLabel.ToolTip = entity.Description;
uiEntry.TooltipLabel.TooltipDelay = 0;
uiEntry.TooltipLabel.TooltipSupplier = _ => tooltip;

var sectionI = sectionIndex;
var entryI = entryIndex;
uiEntry.Panel.Button.OnPressed += _ => OnButtonPressed(sectionI, entryI);
}

uiSection.Entries.AddChild(uiEntry);
var msg = new FormattedMessage();
msg.AddText(name);
msg.PushNewline();

if (!string.IsNullOrWhiteSpace(entity.Description))
msg.AddText(entity.Description);

var tooltip = new Tooltip();
tooltip.SetMessage(msg);
tooltip.MaxWidth = 250f;

uiEntry.TooltipLabel.ToolTip = entity.Description;
uiEntry.TooltipLabel.TooltipDelay = 0;
uiEntry.TooltipLabel.TooltipSupplier = _ => tooltip;

uiEntry.Panel.Button.OnPressed += _ => OnButtonPressed(entry);
}

_window.Sections.AddChild(uiSection);
uiSection.Entries.AddChild(uiEntry);
}

_window.Sections.AddChild(uiSection);
}

_window.Express.OnPressed += _ => OnExpressDeliveryButtonPressed();
_window.Search.OnTextChanged += OnSearchChanged;

Expand All @@ -99,9 +98,9 @@ protected override void Open()
_window.OpenCentered();
}

private void OnButtonPressed(int sectionIndex, int entryIndex)
private void OnButtonPressed(Content.Shared.ADT.MiningShop.MiningShopEntry entry)
{
var msg = new MiningShopBuiMsg(sectionIndex, entryIndex);
var msg = new MiningShopBuiMsg(entry);
SendMessage(msg);
Refresh();
}
Expand Down Expand Up @@ -168,18 +167,20 @@ public void Refresh()

_window.PointsLabel.Text = $"Осталось очков: {userpoints}";

for (var sectionIndex = 0; sectionIndex < vendor.Sections.Count; sectionIndex++)
var sections = _prototype.EnumeratePrototypes<SharedMiningShopSectionPrototype>();

for (var sectionIndex = 0; sectionIndex < _sections.Count; sectionIndex++)
{
var section = vendor.Sections[sectionIndex];
var uiSection = (MiningShopSection) _window.Sections.GetChild(sectionIndex);
var section = _sections[sectionIndex];
var uiSection = (MiningShopSection)_window.Sections.GetChild(sectionIndex);
uiSection.Label.SetMessage(GetSectionName(section));

var sectionDisabled = false;

for (var entryIndex = 0; entryIndex < section.Entries.Count; entryIndex++)
{
var entry = section.Entries[entryIndex];
var uiEntry = (MiningShopEntry) uiSection.Entries.GetChild(entryIndex);
var uiEntry = (MiningShopEntry)uiSection.Entries.GetChild(entryIndex);
var disabled = sectionDisabled;

if (userpoints < entry.Price)
Expand Down Expand Up @@ -210,7 +211,7 @@ protected override void ReceiveMessage(BoundUserInterfaceMessage message)
}
}

private FormattedMessage GetSectionName(SharedMiningShopSection section)
private FormattedMessage GetSectionName(SharedMiningShopSectionPrototype section)
{
var name = new FormattedMessage();
name.PushTag(new MarkupNode("bold", new MarkupParameter(section.Name.ToUpperInvariant()), null));
Expand Down
3 changes: 0 additions & 3 deletions Content.Shared/ADT/MiningShop/MiningShopComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ namespace Content.Shared.ADT.MiningShop;
[Access(typeof(SharedMiningShopSystem))]
public sealed partial class MiningShopComponent : Component
{

[DataField, AutoNetworkedField]
public List<SharedMiningShopSection> Sections = new();
[DataField, AutoNetworkedField]
public List<MiningShopEntry> OrderList = new();

Expand Down
15 changes: 5 additions & 10 deletions Content.Shared/ADT/MiningShop/MiningShopSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,17 @@

namespace Content.Shared.ADT.MiningShop;

[DataDefinition]
[Serializable, NetSerializable]
public sealed partial class SharedMiningShopSection
[Prototype("miningShopSection")]
public sealed partial class SharedMiningShopSectionPrototype : IPrototype
{
[IdDataField]
public string ID { get; private set; } = default!;

[DataField(required: true)]
public string Name = string.Empty;

[DataField(required: true)]
public List<MiningShopEntry> Entries = new();

// Only used by Spec Vendors to mark the kit section for RMCVendorSpecialistComponent logic.
[DataField]
public int? SharedSpecLimit;

[DataField]
public List<ProtoId<JobPrototype>> Jobs = new();
}

[DataDefinition]
Expand Down
5 changes: 2 additions & 3 deletions Content.Shared/ADT/MiningShop/MiningShopVendorUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ public enum MiningShopUI : byte
}

[Serializable, NetSerializable]
public sealed class MiningShopBuiMsg(int section, int entry) : BoundUserInterfaceMessage
public sealed class MiningShopBuiMsg(MiningShopEntry entry) : BoundUserInterfaceMessage
{
public readonly int Section = section;
public readonly int Entry = entry;
public readonly MiningShopEntry Entry = entry;
}

[Serializable, NetSerializable]
Expand Down
22 changes: 3 additions & 19 deletions Content.Shared/ADT/MiningShop/SharedMiningShopSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,11 @@ public override void Initialize()
protected virtual void OnVendBui(Entity<MiningShopComponent> vendor, ref MiningShopBuiMsg args)
{
var comp = vendor.Comp;
var sections = comp.Sections.Count;
var actor = args.Actor;
if (args.Section < 0 || args.Section >= sections)
{
Log.Error($"{ToPrettyString(actor)} sent an invalid vend section: {args.Section}. Max: {sections}");
return;
}

var section = comp.Sections[args.Section];
var entries = section.Entries.Count;
if (args.Entry < 0 || args.Entry >= entries)
{
Log.Error($"{ToPrettyString(actor)} sent an invalid vend entry: {args.Entry}. Max: {entries}");
return;
}

var entry = section.Entries[args.Entry];

if (entry.Price != null)
if (args.Entry.Price != null)
{
if (_miningPoints.TryFindIdCard(actor) is {} idCard && _miningPoints.RemovePoints(idCard, entry.Price.Value))
if (_miningPoints.TryFindIdCard(actor) is {} idCard && _miningPoints.RemovePoints(idCard, args.Entry.Price.Value))
{
Dirty(vendor);
}
Expand All @@ -52,7 +36,7 @@ protected virtual void OnVendBui(Entity<MiningShopComponent> vendor, ref MiningS
if (_net.IsClient)
return;

vendor.Comp.OrderList.Add(entry);
vendor.Comp.OrderList.Add(args.Entry);
}


Expand Down
82 changes: 0 additions & 82 deletions Resources/Maps/ADTMaps/Nonstation/lavaland_outpost.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1462,88 +1462,6 @@ entities:
pos: 22.5,5.5
parent: 1
- type: MiningShop
sections:
- jobs: []
sharedSpecLimit: null
entries:
- price: 750
name: null
id: WeaponCrusher
- price: 1050
name: null
id: WeaponKineticSpear
- price: 1050
name: null
id: WeaponKineticHammer
- price: 1050
name: null
id: WeaponKineticClaws
- price: 1050
name: null
id: WeaponKineticMachete
name: Крашеры
- jobs: []
sharedSpecLimit: null
entries:
- price: 550
name: null
id: WeaponProtoKineticAccelerator
name: ПКА
- jobs: []
sharedSpecLimit: null
entries:
- price: 600
name: null
id: FultonBeacon
- price: 1150
name: null
id: Fulton
name: фултоны
- jobs: []
sharedSpecLimit: null
entries:
- price: 700
name: null
id: MedkitBruteFilled
- price: 600
name: null
id: MedkitBurnFilled
name: медицина
- jobs: []
sharedSpecLimit: null
entries:
- price: 500
name: null
id: ClothingBeltSalvageWebbing
- price: 3000
name: null
id: ClothingOuterHardsuitSalvage
- price: 1000
name: null
id: ADTClothingOuterArmorMiner
- price: 3600
name: null
id: ADTClothingOuterArmorMinerHeavy
- price: 4000
name: null
id: ClothingOuterArmorMinerLight
name: снаряжение
- jobs: []
sharedSpecLimit: null
entries:
- price: 500
name: null
id: PKAUpgradeDamage
- price: 500
name: null
id: PKAUpgradeRange
- price: 500
name: null
id: PKAUpgradeFireRate
- price: 500
name: null
id: PKAUpgradeLight
name: улучшения
- uid: 1835
components:
- type: Transform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
wideAnimationRotation: -135
damage:
types:
Slash: 20
Slash: 15
soundHit:
collection: MetalThud
angle: 0
Expand All @@ -154,7 +154,7 @@
- type: BackstabDamageMultipilier
bonusDamage:
types:
Slash: 40
Slash: 20
- type: GunRequiresWield
- type: Wieldable
- type: Item
Expand All @@ -176,7 +176,7 @@
attackRate: 1.5
damage:
types:
Slash: 25
Slash: 20
soundHit:
collection: MetalThud
angle: 0
Expand All @@ -188,4 +188,4 @@
- type: BackstabDamageMultipilier
bonusDamage:
types:
Slash: 15
Slash: 10
Loading
Loading