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

bluespace harvester #957

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Content.Shared.ADT.BluespaceHarvester;
using JetBrains.Annotations;

namespace Content.Client.ADT.BluespaceHarvester;

[UsedImplicitly]
public sealed class BluespaceHarvesterBoundUserInterface : BoundUserInterface
{
private BluespaceHarvesterMenu? _window;

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

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

_window = new BluespaceHarvesterMenu(this);
_window.OnClose += Close;
_window?.OpenCentered();
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;

_window?.Dispose();
_window = null;
}

protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);

if (state is not BluespaceHarvesterBoundUserInterfaceState current)
return;

_window?.UpdateState(current);
}

public void SendTargetLevel(int level)
{
SendMessage(new BluespaceHarvesterTargetLevelMessage(level));
}

public void SendBuy(Shared.ADT.BluespaceHarvester.BluespaceHarvesterCategory category)
{
SendMessage(new BluespaceHarvesterBuyMessage(category));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Control xmlns="https://spacestation14.io">
<GridContainer Margin = "2 0 0 0" Columns="2">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем использовать GridContainer, когда есть BoxContainer с Orientation="Horizontal"? Лучше изменить, удобней будет в будущем редактировать

<Label Name="CategoryLabel" Text="Category" StyleClasses="StatusFieldTitle"></Label>
<Button Name="CategoryButton" Text="10000" StyleClasses="OpenRight" Access="Public"/>
</GridContainer>
</Control>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.XAML;
using Content.Shared.ADT.BluespaceHarvester;

namespace Content.Client.ADT.BluespaceHarvester;

[GenerateTypedNameReferences]
public sealed partial class BluespaceHarvesterCategory : Control
{
public BluespaceHarvesterCategory(BluespaceHarvesterCategoryInfo category, bool canBuy)
{
RobustXamlLoader.Load(this);

CategoryLabel.Text = Loc.GetString($"bluespace-harvester-category-{Enum.GetName(typeof(Shared.ADT.BluespaceHarvester.BluespaceHarvesterCategory), category.Type)}");

CategoryButton.Text = $"{category.Cost}";
CategoryButton.Disabled = !canBuy;
}
}
44 changes: 44 additions & 0 deletions Content.Client/ADT/BluespaceHarvester/BluespaceHarvesterMenu.xaml
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Лучше сделать UI меньше по горизонтали. Он выглядит растянуто и пусто сейчас
  2. Где Margin, Лебовски? Добавь отступы от краёв окна, а то выглядит плохо
  3. Прогресс бар уходит в пустоту, надо как-либо ограничить его
  4. Может стоит добавить кнопки для повышения/понижения уровня?

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<controls:FancyWindow xmlns="https://spacestation14.io"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
Title="{Loc 'bluespace-harvester-window-title'}"
MinSize="480 360">
<BoxContainer Orientation="Vertical">
<Label Text="{Loc 'bluespace-harvester-window-lable-input'}"/>
<controls:HLine Color="#404040" Thickness="2" Margin="0 5"/>
<GridContainer Margin="2 0 0 0" Columns="2">
<Label Text="{Loc 'bluespace-harvester-window-level-input'}" StyleClasses="StatusFieldTitle"/>
<LineEdit Name="InputLevelBar" PlaceHolder="0" HorizontalExpand="True" Margin ="0 4"/>
<Label Text="{Loc 'bluespace-harvester-window-level-target'}" StyleClasses="StatusFieldTitle"/>
<Label Name="TargetLevel" Text="0"/>
<Label Text="{Loc 'bluespace-harvester-window-level-current'}" StyleClasses="StatusFieldTitle"/>
<Label Name="CurrentLevel" Text="0"/>
<Label Text="{Loc 'bluespace-harvester-window-level-desired'}" StyleClasses="StatusFieldTitle"/>
<ProgressBar Name="DesiredBar"
HorizontalExpand="True"
MinValue="0"
MaxValue="1"
SetHeight="25"/>
<Label Text="{Loc 'bluespace-harvester-window-power-usage'}" StyleClasses="StatusFieldTitle"/>
<Label Name="PowerUsageLabel" Text="0w"/>
<Label Text="{Loc 'bluespace-harvester-window-power-next'}" StyleClasses="StatusFieldTitle"/>
<Label Name="PowerUsageNextLabel" Text="0w"/>
</GridContainer>
<Control/>
<Label Text="{Loc 'bluespace-harvester-window-lable-output'}"/>
<controls:HLine Color="#404040" Thickness="2" Margin="0 5"/>
<GridContainer Margin="2 0 10 0" Columns="2">
<BoxContainer Orientation="Vertical">
<GridContainer Margin="2 0 0 0" Columns="2">
<Label Text="{Loc 'bluespace-harvester-window-points-available'}" StyleClasses="StatusFieldTitle"/>
<Label Name="AvailablePointsLabel" Text="0"/>
<Label Text="{Loc 'bluespace-harvester-window-points-generation'}" StyleClasses="StatusFieldTitle"/>
<Label Name="GenerationPointsLabel" Text="0"/>
<Label Text="{Loc 'bluespace-harvester-window-points-total'}" StyleClasses="StatusFieldTitle"/>
<Label Name="TotalPontsLabel" Text="0"/>
</GridContainer>
</BoxContainer>
<BoxContainer Name="Categories" Orientation="Vertical">
</BoxContainer>
</GridContainer>
</BoxContainer>
</controls:FancyWindow>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using Content.Client.UserInterface.Controls;
using Content.Shared.ADT.BluespaceHarvester;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.XAML;

namespace Content.Client.ADT.BluespaceHarvester;

[GenerateTypedNameReferences]
public sealed partial class BluespaceHarvesterMenu : FancyWindow
{
private readonly BluespaceHarvesterBoundUserInterface _owner;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вместо макарон использования классов друг другом, используй экшны.
Например:
В меню - public Action<int>? SetLevelAction; для создания и SetLevelAction?.Invoke(level); для его использования.
В функции Open в BUI добавляешь _window.SetLevelAction += args => Blabla, и теперь каждый раз, когда используется SetLevelAction, будет вызываться Blabla (функция, которая имеет аргумент соответствующего типа, что и экшн)


public BluespaceHarvesterMenu(BluespaceHarvesterBoundUserInterface owner)
{
RobustXamlLoader.Load(this);

_owner = owner;

InputLevelBar.OnTextEntered += (args) =>
{
if (!int.TryParse(args.Text, out var level) || level < 0 || level > 20)
{
InputLevelBar.Text = "0";
return;
}
_owner.SendTargetLevel(level);
};

// EntityView.SetEntity(_owner.Owner);
}

public void UpdateState(BluespaceHarvesterBoundUserInterfaceState state)
{
TargetLevel.Text = $"{state.TargetLevel}";
CurrentLevel.Text = $"{state.CurrentLevel}";
DesiredBar.Value = ((float)state.CurrentLevel) / ((float)state.MaxLevel);

PowerUsageLabel.Text = Loc.GetString("power-monitoring-window-value", ("value", state.PowerUsage));
PowerUsageNextLabel.Text = Loc.GetString("power-monitoring-window-value", ("value", state.PowerUsageNext));

AvailablePointsLabel.Text = $"{state.Points}";
TotalPontsLabel.Text = $"{state.TotalPoints}";
GenerationPointsLabel.Text = $"{state.PointsGen}";

Categories.RemoveAllChildren();
foreach (var category in state.Categories)
{
var child = new BluespaceHarvesterCategory(category, state.Points >= category.Cost);

child.CategoryButton.OnButtonDown += _ =>
{
_owner.SendBuy(category.Type);
};

Categories.AddChild(child);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Content.Shared.Storage;

namespace Content.Server.ADT.BluespaceHarvester;

// TODO: Make it not tied to the harvester for mappers and loot in debris and dungeons.
[RegisterComponent]
public sealed partial class BluespaceHarvesterBundleComponent : Component
{
[DataField]
public List<EntitySpawnEntry> Contents = new();

[DataField]
public bool Spawned;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Content.Shared.Destructible;
using Content.Shared.Storage.Components;
using Robust.Shared.Random;

namespace Content.Server.ADT.BluespaceHarvester;

public sealed class BluespaceHarvesterBundleSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;

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

SubscribeLocalEvent<BluespaceHarvesterBundleComponent, StorageBeforeOpenEvent>(OnOpen);
SubscribeLocalEvent<BluespaceHarvesterBundleComponent, DestructionEventArgs>(OnDestruction);
}

private void OnOpen(Entity<BluespaceHarvesterBundleComponent> bundle, ref StorageBeforeOpenEvent args)
{
CreateLoot(bundle);
}

private void OnDestruction(Entity<BluespaceHarvesterBundleComponent> bundle, ref DestructionEventArgs args)
{
CreateLoot(bundle);
}

private void CreateLoot(Entity<BluespaceHarvesterBundleComponent> bundle)
{
if (bundle.Comp.Spawned)
return;

var content = _random.Pick(bundle.Comp.Contents);
var position = Transform(bundle.Owner).Coordinates;

for (var i = 0; i < content.Amount; i++)
{
Spawn(content.PrototypeId, position);
}

bundle.Comp.Spawned = true;
}
}
Loading
Loading