Skip to content

Commit

Permalink
Save work.
Browse files Browse the repository at this point in the history
  • Loading branch information
lunar-crater-ex committed Aug 25, 2023
1 parent f0688c8 commit c774034
Show file tree
Hide file tree
Showing 11 changed files with 152 additions and 13 deletions.
62 changes: 60 additions & 2 deletions Content.Client/_Citadel/Contracts/ContractInfoControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ public ContractInfoControl(ContractUiState state, Guid uuid)
_uuid = uuid;
Update(state);
MainAction.OnPressed += OnMainAction;
SecondaryAction.OnPressed += OnSecondaryAction;
}

private void OnSecondaryAction(BaseButton.ButtonEventArgs obj)
{
if (_state.UserStatus == ContractUiState.ContractUserStatus.Owner && _state.Status == ContractStatus.Initiating)
{
OnCancelContract?.Invoke(_uuid);
}
}

private void OnMainAction(BaseButton.ButtonEventArgs obj)
Expand Down Expand Up @@ -68,6 +77,7 @@ protected override Vector2 ArrangeOverride(Vector2 finalSize)

public void Update(ContractUiState state)
{

_state = state;
// Set OwnerName
var ownerName = new FormattedMessage();
Expand Down Expand Up @@ -137,7 +147,46 @@ public void Update(ContractUiState state)
}
}

var msg = new FormattedMessage();
switch (state.Status)
{
case ContractStatus.Uninitialized:
msg.AddMarkup("[color=green]Available[/color]");
break;
case ContractStatus.Initiating:
msg.AddMarkup("[color=yellow]Initiating[/color]");
break;
case ContractStatus.Active:
msg.AddMarkup("[color=green]Active[/color]");
break;
case ContractStatus.Finalized:
msg.AddMarkup("[color=magenta]Finalized[/color]");
break;
case ContractStatus.Breached:
msg.AddMarkup("[color=red]Breached[/color]");
break;
case ContractStatus.Cancelled:
msg.AddMarkup("[color=red]Cancelled[/color]");
break;
default:
throw new ArgumentOutOfRangeException();
}

ContractState.SetMessage(msg);

Description.SetMessage(descMsg);

if (state.Status is ContractStatus.Breached or ContractStatus.Finalized or ContractStatus.Cancelled)
{
MainAction.Disabled = true;
SecondaryAction.Disabled = true;
}
else
{
MainAction.Disabled = false;
SecondaryAction.Disabled = false;
}

switch (state.UserStatus)
{
case ContractUiState.ContractUserStatus.Owner:
Expand All @@ -164,7 +213,16 @@ public void Update(ContractUiState state)
throw new ArgumentOutOfRangeException();
}

SecondaryAction.Text = "Hail";
SecondaryAction.ToolTip = "Hails the owner of the contract in an effort to grab their attention.";
if (state.UserStatus == ContractUiState.ContractUserStatus.Owner && state.Status == ContractStatus.Initiating)
{
SecondaryAction.Text = "Cancel";
SecondaryAction.Disabled = false;
}
else
{
SecondaryAction.Text = "Hail";
SecondaryAction.ToolTip = "Hails the owner of the contract in an effort to grab their attention.";
SecondaryAction.Disabled = true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@
VerticalExpand="True"
HorizontalExpand="True">
<contracts:ContractListControl Name="MainContractList" VerticalExpand="True" Margin="0 4"/>
<BoxContainer Orientation="Vertical" HorizontalExpand="True" VerticalExpand="True">
<BoxContainer Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
<Label Text="Thalers"/>
<Label Name="BankAmount"/>
</BoxContainer>
</BoxContainer>
</contracts:ContractsCartridgeControl>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using Content.Shared._Citadel.Contracts;
using Content.Shared._Citadel.Contracts.BUI;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
Expand All @@ -21,6 +22,8 @@ public ContractsCartridgeControl()
{
RobustXamlLoader.Load(this);
SetTabTitle(0, "Contracts");
SetTabTitle(1, "Bank Account");

MainContractList.OnStartContract += guid => OnStartContract?.Invoke(guid);
MainContractList.OnCancelContract += guid => OnCancelContract?.Invoke(guid);
MainContractList.OnJoinContract += guid => OnJoinContract?.Invoke(guid);
Expand All @@ -32,6 +35,12 @@ public ContractsCartridgeControl()

public void Update(ContractCartridgeUiState uiState)
{
MainContractList.Update(uiState.Contracts.Contracts.OrderBy(x => x.Value.UserStatus));
MainContractList.Update(uiState.Contracts.Contracts
.OrderBy(x => x.Value.Status)
.ThenBy(x => x.Value.UserStatus)
.Where(x => x.Value.Status is not ContractStatus.Breached and not ContractStatus.Finalized and not ContractStatus.Cancelled
|| x.Value.UserStatus is ContractUiState.ContractUserStatus.Subcontractor or ContractUiState.ContractUserStatus.Owner)
);
BankAmount.Text = uiState.Contracts.BankAccount.ToString();
}
}
1 change: 1 addition & 0 deletions Content.Server/CartridgeLoader/CartridgeLoaderSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ private void OnUiMessage(EntityUid uid, CartridgeLoaderComponent component, Cart
{
var cartridgeEvent = args.MessageEvent;
cartridgeEvent.LoaderUid = uid;
cartridgeEvent.Session = args.Session;

RelayEvent(component, cartridgeEvent, true);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Server._Citadel.Contracts.Components;
using Content.Server._Citadel.Contracts.Prototypes;
using Content.Server.Administration;
Expand Down Expand Up @@ -92,6 +93,20 @@ public EntityUid CreateBoundContract(string contractProto, Mind.Mind owner)
return contractEnt;
}

public bool CouldChangeStatusTo(EntityUid contractUid, ContractStatus newStatus, out FormattedMessage? failMsg, ContractComponent? contractComponent = null)
{
failMsg = null;
if (!Resolve(contractUid, ref contractComponent))
return false;
var ev = new ContractTryStatusChange(contractComponent.Status, newStatus);
RaiseLocalEvent(contractUid, ref ev);

if (ev.Cancelled)
failMsg = ev.FailMessage;

return !ev.Cancelled;
}

private bool TryChangeContractState(EntityUid contractUid, ContractComponent contractComponent,
ContractStatus newStatus)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public override void Update(float frameTime)
{
var vessel = vesselContractQuery.GetComponent(cc.OwningContract);

if (criteria.Ticking is false || criteria.Satisfied is true || vessel.Vessel is null)
if (criteria.Ticking is false || criteria.Satisfied || vessel.Vessel is null)
continue;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Content.Shared._Citadel.Contracts;
using Content.Shared._Citadel.Contracts.BUI;
using Content.Shared.CartridgeLoader;
using Content.Shared.FixedPoint;
using Robust.Server.Player;
using Robust.Shared.Utility;

Expand All @@ -18,12 +19,50 @@ namespace Content.Server._Citadel.PDAContracts.Systems;
public sealed class ContractsCartridgeSystem : EntitySystem
{
[Dependency] private readonly CartridgeLoaderSystem? _cartridgeLoaderSystem = default!;
[Dependency] private readonly ContractManagementSystem _contracts = default!;
[Dependency] private readonly ContractCriteriaSystem _criteria = default!;

/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<ContractsCartridgeComponent, CartridgeUiReadyEvent>(OnUiReady);
SubscribeLocalEvent<ContractsCartridgeComponent, CartridgeMessageEvent>(OnMessage);
}

private void OnMessage(EntityUid uid, ContractsCartridgeComponent component, CartridgeMessageEvent args)
{
if (args is not ContractsUiMessageEvent { } ev)
return;

var player = (IPlayerSession) args.Session!;
var contract = EntityQuery<ContractComponent>().First(x => x.Uuid == ev.Contract);
switch (ev.Action)
{
case ContractsUiMessageEvent.ContractAction.Sign:
if (contract.OwningContractor is not null)
return;
_contracts.BindContract(contract.Owner, player.GetMind()!);
break;
case ContractsUiMessageEvent.ContractAction.Join:
_contracts.BindContract(contract.Owner, player.GetMind()!);
break;
case ContractsUiMessageEvent.ContractAction.Cancel:
if (contract.OwningContractor != player.GetMind()!)
return;
_contracts.TryCancelContract(contract.Owner);
break;
case ContractsUiMessageEvent.ContractAction.Leave:
break;
case ContractsUiMessageEvent.ContractAction.Start:
if (contract.OwningContractor != player.GetMind()!)
return;
_contracts.TryActivateContract(contract.Owner);
break;
case ContractsUiMessageEvent.ContractAction.Hail:
break;
default:
throw new ArgumentOutOfRangeException();
}
}

private void OnUiReady(EntityUid uid, ContractsCartridgeComponent component, CartridgeUiReadyEvent args)
Expand Down Expand Up @@ -63,6 +102,12 @@ public ContractListUiState GenerateState(EntityUid cart, IPlayerSession user)
var state = new ContractUiState(status, Name(contract), ownerName, subContractorNames,
new ContractDisplayData(FormattedMessage.FromUnformatted(Description(contract))), contractComp.Status);

if (!_contracts.CouldChangeStatusTo(contract, ContractStatus.Active, out var failMsg))
{
state.Startable = false;
state.NoStartReason = failMsg;
}

foreach (var (group, criteria) in criteriaComp.Criteria)
{
state.Criteria[group] = new();
Expand All @@ -89,7 +134,7 @@ public ContractListUiState GenerateState(EntityUid cart, IPlayerSession user)
contractStates.Add(contractComp.Uuid, state);
}

return new ContractListUiState(contractStates);
return new ContractListUiState(contractStates, mind.BankAccount?.Thalers ?? FixedPoint2.Zero);
}

private void UpdateUiState(EntityUid uid, EntityUid loaderUid, IPlayerSession session, ContractsCartridgeComponent? component)
Expand Down
4 changes: 2 additions & 2 deletions Content.Server/_Citadel/Thalers/PersonalBankSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private void OnContractTryStatusChange(EntityUid uid, ContractStartFeeComponent

args.Cancelled = true;

args.FailMessage.AddText(Loc.GetString("citadel-failed-contract-start-not-enough-money", ("userBalance", contract.OwningContractor.BankAccount!.Thalers), ("cost", component.Cost)));
args.FailMessage.AddText($"Not enough money to start the contract, you have {contract.OwningContractor.BankAccount!.Thalers} but need {component.Cost}.");
}

private void OnAwardCash(CriteriaGroupAwardCash ev)
Expand Down Expand Up @@ -123,6 +123,6 @@ public sealed partial record CriteriaGroupAwardCash() : CriteriaGroupEffectEvent
public FixedPoint2 Amount;
public override string? Describe()
{
return Loc.GetString("criteria-group-award-cash-effect-description", ("amount", Amount));
return Loc.GetString("criteria-group-award-cash-effect-description", ("amount", Amount.Float()));
}
}
4 changes: 3 additions & 1 deletion Content.Shared/CartridgeLoader/CartridgeUiMessage.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Robust.Shared.Serialization;
using Robust.Shared.Players;
using Robust.Shared.Serialization;

namespace Content.Shared.CartridgeLoader;

Expand All @@ -17,4 +18,5 @@ public CartridgeUiMessage(CartridgeMessageEvent messageEvent)
public abstract class CartridgeMessageEvent : EntityEventArgs
{
public EntityUid LoaderUid;
public ICommonSession? Session;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Shared.CartridgeLoader;
using Content.Shared.FixedPoint;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;

Expand All @@ -11,10 +12,12 @@ namespace Content.Shared._Citadel.Contracts.BUI;
public sealed class ContractListUiState
{
public Dictionary<Guid, ContractUiState> Contracts;
public FixedPoint2 BankAccount;

public ContractListUiState(Dictionary<Guid, ContractUiState> contracts)
public ContractListUiState(Dictionary<Guid, ContractUiState> contracts, FixedPoint2 bankAccount)
{
Contracts = contracts;
BankAccount = bankAccount;
}
}

Expand All @@ -28,8 +31,8 @@ public sealed record ContractUiState(ContractUiState.ContractUserStatus UserStat
public List<string> Subcontractors = Subcontractors;
public Dictionary<string, List<CriteriaDisplayData>> Criteria = new();
public Dictionary<string, List<FormattedMessage>> Effects = new();
public bool Joinable = true;

public bool Startable = true;
public FormattedMessage? NoStartReason = null;

public ContractDisplayData Data = Data;

Expand Down
2 changes: 1 addition & 1 deletion Resources/Locale/en-US/_citadel/bank/contracts.ftl
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
criteria-group-award-cash-effect-description = Payout of {$amount} {MANY($amount, -bank-currency-name)}.
criteria-group-award-cash-effect-description = Payout of {$amount} {-bank-currency-name}.
criteria-material-storage-has-materials-component-display-description =
Collect {$amount} {$material} units within your vessel's material storage.

0 comments on commit c774034

Please sign in to comment.