diff --git a/Content.Client/_NF/BountyContracts/UI/BountyContractUi.cs b/Content.Client/_NF/BountyContracts/UI/BountyContractUi.cs index 5f2c2d0fc1..5109ab8b45 100644 --- a/Content.Client/_NF/BountyContracts/UI/BountyContractUi.cs +++ b/Content.Client/_NF/BountyContracts/UI/BountyContractUi.cs @@ -1,8 +1,10 @@ +using System.Linq; using Content.Client.UserInterface.Fragments; using Content.Shared._NF.BountyContracts; +using Content.Shared.CartridgeLoader; using JetBrains.Annotations; -using Robust.Client.GameObjects; using Robust.Client.UserInterface; +using Robust.Shared.Prototypes; namespace Content.Client._NF.BountyContracts.UI; @@ -11,6 +13,8 @@ public sealed partial class BountyContractUi : UIFragment { private BountyContractUiFragment? _fragment; private BoundUserInterface? _userInterface; + private ProtoId _lastCollection = "Command"; //FIXME: nasty. + private BoundUserInterfaceState? _lastState = null; public override Control GetUIFragmentRoot() { @@ -21,6 +25,7 @@ public sealed partial class BountyContractUi : UIFragment { _fragment = new BountyContractUiFragment(); _userInterface = userInterface; + _lastState = null; } @@ -30,13 +35,10 @@ public sealed partial class BountyContractUi : UIFragment return; if (state is BountyContractListUiState listState) - { ShowListState(listState); - } else if (state is BountyContractCreateUiState createState) - { ShowCreateState(createState); - } + _lastState = state; } private void UnloadPreviousState() @@ -46,9 +48,13 @@ public sealed partial class BountyContractUi : UIFragment private void ShowCreateState(BountyContractCreateUiState state) { + // If the previous state is already a create state, do not destroy our old state. + if (_lastState is BountyContractCreateUiState) + return; + UnloadPreviousState(); - var create = new BountyContractUiFragmentCreate(); + var create = new BountyContractUiFragmentCreate(state.Collection); create.OnCancelPressed += OnCancelCreatePressed; create.OnCreatePressed += OnTryCreatePressed; @@ -61,40 +67,83 @@ public sealed partial class BountyContractUi : UIFragment private void ShowListState(BountyContractListUiState state) { UnloadPreviousState(); + var tabs = new BountyContractUiFragmentTabSet(); + tabs.OnSelectCollection += OnSelectCollection; + state.Collections.Reverse(); // invert order, show latest first + foreach (var collection in state.Collections) + { + int newTabIndex = tabs.Children.Count(); + if (collection == state.Collection) + { + var list = new BountyContractUiFragmentList(); + list.OnCreateButtonPressed += OnOpenCreateUiPressed; + list.OnRefreshButtonPressed += OnRefreshListPressed; + list.OnRemoveButtonPressed += OnRemovePressed; + list.OnToggleNotificationPressed += OnToggleNotificationPressed; + list.SetContracts(state.Contracts, state.IsAllowedRemoveBounties, state.AuthorUid); + list.SetCanCreate(state.IsAllowedCreateBounties); + list.SetNotificationsEnabled(state.NotificationsEnabled); + tabs.Children.Add(list); - var list = new BountyContractUiFragmentList(); - list.OnCreateButtonPressed += OnOpenCreateUiPressed; - list.OnRefreshButtonPressed += OnRefreshListPressed; - list.OnRemoveButtonPressed += OnRemovePressed; + tabs.CurrentTab = newTabIndex; + tabs.SetTabCollection(newTabIndex, collection); + } + else + { + var placeholder = new BountyContractUiFragmentListPlaceholder(); + tabs.Children.Add(placeholder); + tabs.SetTabCollection(newTabIndex, collection); + } + } - list.SetContracts(state.Contracts, state.IsAllowedRemoveBounties); - list.SetCanCreate(state.IsAllowedCreateBounties); - - _fragment?.AddChild(list); + _fragment?.AddChild(tabs); + _lastCollection = state.Collection; } + // UI event handlers private void OnRemovePressed(BountyContract obj) { - _userInterface?.SendMessage(new BountyContractTryRemoveUiMsg(obj.ContractId)); + SendMessage(new BountyContractTryRemoveMessageEvent(obj.ContractId)); + } + + private void OnSelectCollection(ProtoId collection) + { + SendMessage(MakeCommand(BountyContractCommand.RefreshList, collection)); } private void OnRefreshListPressed() { - _userInterface?.SendMessage(new BountyContractRefreshListUiMsg()); + SendMessage(MakeCommand(BountyContractCommand.RefreshList, _lastCollection)); } private void OnOpenCreateUiPressed() { - _userInterface?.SendMessage(new BountyContractOpenCreateUiMsg()); + SendMessage(MakeCommand(BountyContractCommand.OpenCreateUi, _lastCollection)); } private void OnCancelCreatePressed() { - _userInterface?.SendMessage(new BountyContractCloseCreateUiMsg()); + SendMessage(MakeCommand(BountyContractCommand.CloseCreateUi, _lastCollection)); + } + + private void OnToggleNotificationPressed() + { + SendMessage(MakeCommand(BountyContractCommand.ToggleNotifications, _lastCollection)); } private void OnTryCreatePressed(BountyContractRequest contract) { - _userInterface?.SendMessage(new BountyContractTryCreateMsg(contract)); + SendMessage(new BountyContractTryCreateMessageEvent(contract)); + } + + // Convenience functions for message creation + private BountyContractCommandMessageEvent MakeCommand(BountyContractCommand command, ProtoId collection) + { + return new BountyContractCommandMessageEvent(command, collection); + } + + private void SendMessage(CartridgeMessageEvent msg) + { + _userInterface?.SendMessage(new CartridgeUiMessage(msg)); } } diff --git a/Content.Client/_NF/BountyContracts/UI/BountyContractUiFragmentCreate.xaml b/Content.Client/_NF/BountyContracts/UI/BountyContractUiFragmentCreate.xaml index 9427dd4199..000fb7af40 100644 --- a/Content.Client/_NF/BountyContracts/UI/BountyContractUiFragmentCreate.xaml +++ b/Content.Client/_NF/BountyContracts/UI/BountyContractUiFragmentCreate.xaml @@ -24,18 +24,18 @@