This commit is contained in:
Evil Factory
2022-07-14 12:25:44 -03:00
86 changed files with 839 additions and 412 deletions
@@ -47,7 +47,9 @@ namespace Barotrauma
CreateUI();
UpdateLocationView(campaignUI.Campaign.Map.CurrentLocation, true);
campaignUI.Campaign.Map.OnLocationChanged += (prevLocation, newLocation) => UpdateLocationView(newLocation, true, prevLocation);
campaignUI.Campaign.Map.OnLocationChanged.RegisterOverwriteExisting(
"CrewManagement.UpdateLocationView".ToIdentifier(),
(locationChangeInfo) => UpdateLocationView(locationChangeInfo.NewLocation, true, locationChangeInfo.PrevLocation));
}
public void RefreshPermissions()
@@ -20,7 +20,7 @@ namespace Barotrauma
private RectTransform currentHighestParent;
private List<RectTransform> parentHierarchy = new List<RectTransform>();
private bool selectMultiple;
private readonly bool selectMultiple;
public bool Dropped { get; set; }
@@ -129,18 +129,20 @@ namespace Barotrauma
}
}
private List<object> selectedDataMultiple = new List<object>();
private readonly List<object> selectedDataMultiple = new List<object>();
public IEnumerable<object> SelectedDataMultiple
{
get { return selectedDataMultiple; }
}
private List<int> selectedIndexMultiple = new List<int>();
private readonly List<int> selectedIndexMultiple = new List<int>();
public IEnumerable<int> SelectedIndexMultiple
{
get { return selectedIndexMultiple; }
}
public bool MustSelectAtLeastOne;
public LocalizedString Text
{
get { return button.Text; }
@@ -269,6 +271,12 @@ namespace Barotrauma
ToolTip = toolTip,
OnSelected = (GUITickBox tb) =>
{
if (MustSelectAtLeastOne && selectedIndexMultiple.Count <= 1 && !tb.Selected)
{
tb.Selected = true;
return false;
}
List<LocalizedString> texts = new List<LocalizedString>();
selectedDataMultiple.Clear();
selectedIndexMultiple.Clear();
@@ -188,21 +188,23 @@ namespace Barotrauma
this.parentComponent = parentComponent;
UpdatePermissions();
CreateUI();
campaignUI.Campaign.Map.OnLocationChanged += UpdateLocation;
if (CurrentLocation?.Reputation != null)
{
CurrentLocation.Reputation.OnReputationValueChanged += () => { needsRefresh = true; };
}
campaignUI.Campaign.CargoManager.OnItemsInBuyCrateChanged += () => { needsBuyingRefresh = true; };
campaignUI.Campaign.CargoManager.OnPurchasedItemsChanged += () => { needsRefresh = true; };
campaignUI.Campaign.CargoManager.OnItemsInSellCrateChanged += () => { needsSellingRefresh = true; };
campaignUI.Campaign.CargoManager.OnSoldItemsChanged += () =>
Identifier refreshStoreId = new Identifier("RefreshStore");
campaignUI.Campaign.Map.OnLocationChanged.RegisterOverwriteExisting(
refreshStoreId,
(locationChangeInfo) => UpdateLocation(locationChangeInfo.PrevLocation, locationChangeInfo.NewLocation));
CurrentLocation?.Reputation?.OnReputationValueChanged.RegisterOverwriteExisting(refreshStoreId, _ => needsRefresh = true);
CargoManager cargoManager = campaignUI.Campaign.CargoManager;
cargoManager.OnItemsInBuyCrateChanged.RegisterOverwriteExisting(refreshStoreId, _ => needsBuyingRefresh = true);
cargoManager.OnPurchasedItemsChanged.RegisterOverwriteExisting(refreshStoreId, _ => needsRefresh = true);
cargoManager.OnItemsInSellCrateChanged.RegisterOverwriteExisting(refreshStoreId, _ => needsSellingRefresh = true);
cargoManager.OnSoldItemsChanged.RegisterOverwriteExisting(refreshStoreId, _ =>
{
needsItemsToSellRefresh = true;
needsItemsToSellFromSubRefresh = true;
needsRefresh = true;
};
campaignUI.Campaign.CargoManager.OnItemsInSellFromSubCrateChanged += () => { needsSellingFromSubRefresh = true; };
});
cargoManager.OnItemsInSellFromSubCrateChanged.RegisterOverwriteExisting(refreshStoreId, _ => needsSellingFromSubRefresh = true);
}
public void SelectStore(Identifier identifier)
@@ -713,7 +715,7 @@ namespace Barotrauma
if (prevLocation == newLocation) { return; }
if (prevLocation?.Reputation != null)
{
prevLocation.Reputation.OnReputationValueChanged -= SetNeedsRefresh;
prevLocation.Reputation.OnReputationValueChanged.Dispose();
}
if (ItemPrefab.Prefabs.Any(p => p.CanBeBoughtFrom(newLocation)))
{
@@ -722,7 +724,7 @@ namespace Barotrauma
ChangeStoreTab(StoreTab.Buy);
if (newLocation?.Reputation != null)
{
newLocation.Reputation.OnReputationValueChanged += SetNeedsRefresh;
CurrentLocation.Reputation.OnReputationValueChanged.RegisterOverwriteExisting("RefreshStore".ToIdentifier(), _ => { SetNeedsRefresh(); });
}
}
@@ -4,7 +4,6 @@ using Microsoft.Xna.Framework;
using System.Linq;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System.Globalization;
using PlayerBalanceElement = Barotrauma.CampaignUI.PlayerBalanceElement;
namespace Barotrauma
@@ -30,12 +29,12 @@ namespace Barotrauma
private int selectionIndicatorThickness;
private GUIImage listBackground;
private GUITickBox transferItemsTickBox;
private GUITextBlock itemTransferReminderBlock;
private GUITextBlock itemTransferInfoBlock;
private readonly List<SubmarineInfo> subsToShow;
private readonly SubmarineDisplayContent[] submarineDisplays = new SubmarineDisplayContent[submarinesPerPage];
private SubmarineInfo selectedSubmarine = null;
private LocalizedString purchaseAndSwitchText, purchaseOnlyText, deliveryText, currentSubText, switchText, missingPreviewText, currencyName;
private LocalizedString purchaseAndSwitchText, purchaseOnlyText, deliveryText, selectedSubText, switchText, missingPreviewText, currencyName;
private readonly RectTransform parent;
private readonly Action closeAction;
private Sprite pageIndicator;
@@ -107,7 +106,7 @@ namespace Barotrauma
private void Initialize()
{
initialized = true;
currentSubText = TextManager.Get("currentsub");
selectedSubText = TextManager.Get("selectedsub");
deliveryText = TextManager.Get("requestdeliverybutton");
switchText = TextManager.Get("switchtosubmarinebutton");
purchaseAndSwitchText = TextManager.Get("purchaseandswitch");
@@ -203,7 +202,7 @@ namespace Barotrauma
OnSelected = (tb) => transferItemsOnSwitch = tb.Selected
};
transferItemsTickBox.RectTransform.Resize(new Point(Math.Min((int)transferItemsTickBox.ContentWidth, transferInfoFrame.Rect.Width), transferItemsTickBox.Rect.Height));
itemTransferReminderBlock = new GUITextBlock(new RectTransform(Vector2.One, transferInfoFrame.RectTransform, Anchor.CenterRight), null)
itemTransferInfoBlock = new GUITextBlock(new RectTransform(Vector2.One, transferInfoFrame.RectTransform, Anchor.CenterRight), null, wrap: true)
{
TextAlignment = Alignment.CenterRight,
Visible = false
@@ -412,7 +411,7 @@ namespace Barotrauma
}
else
{
submarineDisplays[i].submarineFee.Text = currentSubText;
submarineDisplays[i].submarineFee.Text = selectedSubText;
}
}
@@ -474,7 +473,10 @@ namespace Barotrauma
subsToShow.Sort((x, y) => x.SubmarineClass.CompareTo(y.SubmarineClass));
}
if (transferService) SetConfirmButtonState(selectedSubmarine != null && selectedSubmarine.Name != CurrentOrPendingSubmarine().Name);
if (transferService)
{
SetConfirmButtonState(selectedSubmarine != null && selectedSubmarine.Name != CurrentOrPendingSubmarine().Name);
}
subsToShow.Sort((x, y) => x.SubmarineClass.CompareTo(y.SubmarineClass));
pageCount = Math.Max(1, (int)Math.Ceiling(subsToShow.Count / (float)submarinesPerPage));
@@ -607,35 +609,36 @@ namespace Barotrauma
UpdateItemTransferInfoFrame();
}
private bool IsSelectedSubCurrentSub => Submarine.MainSub?.Info?.Name == selectedSubmarine?.Name;
private void UpdateItemTransferInfoFrame()
{
if (selectedSubmarine != null)
{
var pendingSub = GameMain.GameSession?.Campaign?.PendingSubmarineSwitch;
if (Submarine.MainSub?.Info?.Name == selectedSubmarine.Name && pendingSub == null)
if (IsSelectedSubCurrentSub)
{
TransferItemsOnSwitch = false;
transferItemsTickBox.Visible = false;
itemTransferReminderBlock.Visible = false;
itemTransferInfoBlock.Visible = confirmButton.Enabled;
itemTransferInfoBlock.Text = TextManager.Get("switchingbacktocurrentsub");
}
else if (pendingSub?.Name == selectedSubmarine.Name)
else if (GameMain.GameSession?.Campaign?.PendingSubmarineSwitch?.Name == selectedSubmarine.Name)
{
transferItemsTickBox.Visible = false;
itemTransferReminderBlock.Text = GameMain.GameSession.Campaign.TransferItemsOnSubSwitch ?
TextManager.Get("itemtransferenabledreminder") :
TextManager.Get("itemtransferdisabledreminder");
itemTransferReminderBlock.Visible = true;
itemTransferInfoBlock.Visible = true;
itemTransferInfoBlock.Text = GameMain.GameSession.Campaign.TransferItemsOnSubSwitch ? TextManager.Get("itemtransferenabledreminder") : TextManager.Get("itemtransferdisabledreminder");
}
else
{
transferItemsTickBox.Selected = TransferItemsOnSwitch;
transferItemsTickBox.Visible = true;
itemTransferReminderBlock.Visible = false;
itemTransferInfoBlock.Visible = false;
}
}
else
{
transferItemsTickBox.Visible = false;
itemTransferReminderBlock.Visible = false;
itemTransferInfoBlock.Visible = false;
}
}
@@ -710,6 +713,45 @@ namespace Barotrauma
}
msgBox.Buttons[0].OnClicked = (applyButton, obj) =>
{
if (!TransferItemsOnSwitch && !IsSelectedSubCurrentSub)
{
if (selectedSubmarine.NoItems)
{
return ShowConfirmationPopup(TextManager.Get("noitemsheader"), TextManager.Get("noitemswarning"));
}
if (!GameMain.GameSession.IsSubmarineOwned(selectedSubmarine) && !selectedSubmarine.IsManuallyOutfitted)
{
var (header, body) = GetItemTransferWarningText();
return ShowConfirmationPopup(header, body);
}
if (selectedSubmarine.LowFuel)
{
return ShowConfirmationPopup(TextManager.Get("lowfuelheader"), TextManager.Get("lowfuelwarning"));
}
}
return Confirm();
};
msgBox.Buttons[0].OnClicked += msgBox.Close;
msgBox.Buttons[1].OnClicked = msgBox.Close;
bool ShowConfirmationPopup(LocalizedString header, LocalizedString textBody)
{
msgBox.Close();
var extraConfirmationBox = new GUIMessageBox(header, textBody, new LocalizedString[2] { TextManager.Get("ok"), TextManager.Get("cancel") });
extraConfirmationBox.Buttons[0].OnClicked = (b, o) => Confirm();
extraConfirmationBox.Buttons[1].OnClicked = (b, o) =>
{
selectedSubmarine = CurrentOrPendingSubmarine();
RefreshSubmarineDisplay(true);
return true;
};
extraConfirmationBox.Buttons[0].OnClicked += extraConfirmationBox.Close;
extraConfirmationBox.Buttons[1].OnClicked += extraConfirmationBox.Close;
return true;
}
bool Confirm()
{
if (GameMain.Client == null)
{
@@ -721,9 +763,14 @@ namespace Barotrauma
GameMain.Client.InitiateSubmarineChange(selectedSubmarine, TransferItemsOnSwitch, Networking.VoteType.SwitchSub);
}
return true;
};
msgBox.Buttons[0].OnClicked += msgBox.Close;
msgBox.Buttons[1].OnClicked = msgBox.Close;
}
}
private (LocalizedString header, LocalizedString body) GetItemTransferWarningText()
{
var header = TextManager.Get("itemtransferheader").Fallback("lowfuelheader");
var body = TextManager.Get("itemtransferwarning").Fallback("lowfuelwarning");
return (header, body);
}
private void ShowBuyPrompt(bool purchaseOnly)
@@ -737,7 +784,6 @@ namespace Barotrauma
}
GUIMessageBox msgBox;
if (!purchaseOnly)
{
var text = TextManager.GetWithVariables("purchaseandswitchsubmarinetext",
@@ -749,6 +795,39 @@ namespace Barotrauma
msgBox = new GUIMessageBox(TextManager.Get("purchaseandswitchsubmarineheader"), text, messageBoxOptions);
msgBox.Buttons[0].OnClicked = (applyButton, obj) =>
{
if (!TransferItemsOnSwitch && !IsSelectedSubCurrentSub)
{
if (selectedSubmarine.NoItems)
{
ShowConfirmationPopup(TextManager.Get("noitemsheader"), TextManager.Get("noitemswarning"));
return false;
}
if (!GameMain.GameSession.IsSubmarineOwned(selectedSubmarine) && !selectedSubmarine.IsManuallyOutfitted)
{
var (header, body) = GetItemTransferWarningText();
ShowConfirmationPopup(header, body);
return false;
}
if (selectedSubmarine.LowFuel)
{
ShowConfirmationPopup(TextManager.Get("lowfuelheader"), TextManager.Get("lowfuelwarning"));
return false;
}
}
return Confirm();
};
void ShowConfirmationPopup(LocalizedString header, LocalizedString textBody)
{
msgBox.Close();
var extraConfirmationBox = new GUIMessageBox(header, textBody, new LocalizedString[2] { TextManager.Get("ok"), TextManager.Get("cancel") });
extraConfirmationBox.Buttons[0].OnClicked = (b, o) => Confirm();
extraConfirmationBox.Buttons[0].OnClicked += extraConfirmationBox.Close;
extraConfirmationBox.Buttons[1].OnClicked += extraConfirmationBox.Close;
}
bool Confirm()
{
if (GameMain.Client == null)
{
@@ -761,7 +840,7 @@ namespace Barotrauma
GameMain.Client.InitiateSubmarineChange(selectedSubmarine, TransferItemsOnSwitch, Networking.VoteType.PurchaseAndSwitchSub);
}
return true;
};
}
}
else
{
@@ -792,7 +871,13 @@ namespace Barotrauma
private LocalizedString GetItemTransferText()
{
return "\n\n" + TextManager.Get(TransferItemsOnSwitch ? "itemswillbetransferred" : "itemswontbetransferred");
if (Submarine.MainSub?.Info?.Name == selectedSubmarine.Name)
{
return $"\n\n{TextManager.Get("switchingbacktocurrentsub")}";
}
var s = "\n\n" + TextManager.Get(TransferItemsOnSwitch ? "itemswillbetransferred" : "itemswontbetransferred");
s += $" {TextManager.Get("toggleitemtransferprompt")}";
return s;
}
}
}
@@ -1885,6 +1885,7 @@ namespace Barotrauma
{
IgnoreLayoutGroups = true
};
newCharacterBox.TextBlock.AutoScaleHorizontal = true;
newCharacterBox.OnClicked = (button, o) =>
{
@@ -107,10 +107,11 @@ namespace Barotrauma
CreateUI(upgradeFrame);
if (Campaign == null) { return; }
Campaign.UpgradeManager.OnUpgradesChanged += RequestRefresh;
Campaign.CargoManager.OnPurchasedItemsChanged += RequestRefresh;
Campaign.CargoManager.OnSoldItemsChanged += RequestRefresh;
Campaign.OnMoneyChanged.RegisterOverwriteExisting(nameof(UpgradeStore).ToIdentifier(), e => { RequestRefresh(); } );
Identifier eventId = new Identifier(nameof(UpgradeStore));
Campaign.UpgradeManager.OnUpgradesChanged?.RegisterOverwriteExisting(eventId, _ => RequestRefresh());
Campaign.CargoManager.OnPurchasedItemsChanged.RegisterOverwriteExisting(eventId, _ => RequestRefresh());
Campaign.CargoManager.OnSoldItemsChanged.RegisterOverwriteExisting(eventId, _ => RequestRefresh());
Campaign.OnMoneyChanged.RegisterOverwriteExisting(eventId, _ => RequestRefresh());
}
public void RequestRefresh()