|
|
|
@@ -3,7 +3,6 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Barotrauma.Extensions;
|
|
|
|
|
using Barotrauma.Items.Components;
|
|
|
|
@@ -90,6 +89,16 @@ namespace Barotrauma
|
|
|
|
|
Repairs
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private enum UpgradeStoreUserData
|
|
|
|
|
{
|
|
|
|
|
BuyButton,
|
|
|
|
|
BuyButtonLayout,
|
|
|
|
|
ProgressBarLayout,
|
|
|
|
|
IncreaseLabel,
|
|
|
|
|
PriceLabel,
|
|
|
|
|
MaterialCostList
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public UpgradeStore(CampaignUI campaignUI, GUIComponent parent)
|
|
|
|
|
{
|
|
|
|
|
WaitForServerUpdate = false;
|
|
|
|
@@ -600,7 +609,7 @@ namespace Barotrauma
|
|
|
|
|
GUILayoutGroup textLayout = new GUILayoutGroup(rectT(0.8f - repairIcon.RectTransform.RelativeSize.X, 1, contentLayout)) { Stretch = true };
|
|
|
|
|
new GUITextBlock(rectT(1, 0, textLayout), title, font: GUIStyle.SubHeadingFont) { CanBeFocused = false, AutoScaleHorizontal = true };
|
|
|
|
|
new GUITextBlock(rectT(1, 0, textLayout), TextManager.FormatCurrency(price));
|
|
|
|
|
GUILayoutGroup buyButtonLayout = new GUILayoutGroup(rectT(0.2f, 1, contentLayout), childAnchor: Anchor.Center) { UserData = "buybutton" };
|
|
|
|
|
GUILayoutGroup buyButtonLayout = new GUILayoutGroup(rectT(0.2f, 1, contentLayout), childAnchor: Anchor.Center) { UserData = UpgradeStoreUserData.BuyButtonLayout };
|
|
|
|
|
new GUIButton(rectT(0.7f, 0.5f, buyButtonLayout), string.Empty, style: "RepairBuyButton") { Enabled = PlayerBalance >= price && !isDisabled, OnClicked = onPressed };
|
|
|
|
|
contentLayout.Recalculate();
|
|
|
|
|
buyButtonLayout.Recalculate();
|
|
|
|
@@ -950,7 +959,7 @@ namespace Barotrauma
|
|
|
|
|
frames.Add(CreateUpgradeEntry(rectT(1f, 0.25f, parent.Content), currentOrPending.UpgradePreviewSprite,
|
|
|
|
|
item.PendingItemSwap != null ? TextManager.GetWithVariable("upgrades.pendingitem", "[itemname]", name) : TextManager.GetWithVariable("upgrades.installeditem", "[itemname]", nameWithQuantity),
|
|
|
|
|
currentOrPending.Description,
|
|
|
|
|
0, null, addBuyButton: canUninstall, addProgressBar: false, buttonStyle: "WeaponUninstallButton"));
|
|
|
|
|
0, null, addBuyButton: canUninstall, addProgressBar: false, buttonStyle: "WeaponUninstallButton").Frame);
|
|
|
|
|
|
|
|
|
|
if (canUninstall && frames.Last().FindChild(c => c is GUIButton, recursive: true) is GUIButton refundButton)
|
|
|
|
|
{
|
|
|
|
@@ -987,11 +996,11 @@ namespace Barotrauma
|
|
|
|
|
|
|
|
|
|
int price = isPurchased || replacement == item.Prefab ? 0 : replacement.SwappableItem.GetPrice(Campaign.Map?.CurrentLocation) * linkedItems.Count();
|
|
|
|
|
|
|
|
|
|
frames.Add(CreateUpgradeEntry(rectT(1f, 0.25f, parent.Content), replacement.UpgradePreviewSprite, replacement.Name, replacement.Description,
|
|
|
|
|
price, replacement,
|
|
|
|
|
addBuyButton: true,
|
|
|
|
|
frames.Add(CreateUpgradeEntry(rectT(1f, 0.25f, parent.Content), replacement.UpgradePreviewSprite, replacement.Name, replacement.Description,
|
|
|
|
|
price, replacement,
|
|
|
|
|
addBuyButton: true,
|
|
|
|
|
addProgressBar: false,
|
|
|
|
|
buttonStyle: isPurchased ? "WeaponInstallButton" : "StoreAddToCrateButton"));
|
|
|
|
|
buttonStyle: isPurchased ? "WeaponInstallButton" : "StoreAddToCrateButton").Frame);
|
|
|
|
|
|
|
|
|
|
if (!(frames.Last().FindChild(c => c is GUIButton, recursive: true) is GUIButton buyButton)) { continue; }
|
|
|
|
|
if (PlayerBalance >= price)
|
|
|
|
@@ -1081,13 +1090,23 @@ namespace Barotrauma
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static GUIFrame CreateUpgradeFrame(UpgradePrefab prefab, UpgradeCategory category, CampaignMode campaign, RectTransform rectTransform, bool addBuyButton = true)
|
|
|
|
|
public readonly record struct BuyButtonFrame(GUILayoutGroup Layout, GUIListBox MaterialCostList, GUIButton BuyButton, GUITextBlock PriceText);
|
|
|
|
|
public readonly record struct ProgressBarFrame(GUITextBlock ProgressText, GUIProgressBar ProgressBar);
|
|
|
|
|
|
|
|
|
|
public readonly record struct UpgradeFrame(GUIFrame Frame,
|
|
|
|
|
GUIImage Icon,
|
|
|
|
|
GUITextBlock Name,
|
|
|
|
|
GUITextBlock Description,
|
|
|
|
|
Option<BuyButtonFrame> BuyButton,
|
|
|
|
|
Option<ProgressBarFrame> ProgressBar);
|
|
|
|
|
|
|
|
|
|
public static UpgradeFrame CreateUpgradeFrame(UpgradePrefab prefab, UpgradeCategory category, CampaignMode campaign, RectTransform rectTransform, bool addBuyButton = true)
|
|
|
|
|
{
|
|
|
|
|
int price = prefab.Price.GetBuyPrice(campaign.UpgradeManager.GetUpgradeLevel(prefab, category), campaign.Map?.CurrentLocation);
|
|
|
|
|
return CreateUpgradeEntry(rectTransform, prefab.Sprite, prefab.Name, prefab.Description, price, new CategoryData(category, prefab), addBuyButton, upgradePrefab: prefab, currentLevel: campaign.UpgradeManager.GetUpgradeLevel(prefab, category));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static GUIFrame CreateUpgradeEntry(RectTransform parent, Sprite sprite, LocalizedString title, LocalizedString body, int price, object? userData, bool addBuyButton = true, bool addProgressBar = true, string buttonStyle = "UpgradeBuyButton", UpgradePrefab? upgradePrefab = null, int currentLevel = 0)
|
|
|
|
|
public static UpgradeFrame CreateUpgradeEntry(RectTransform parent, Sprite sprite, LocalizedString title, LocalizedString body, int price, object? userData, bool addBuyButton = true, bool addProgressBar = true, string buttonStyle = "UpgradeBuyButton", UpgradePrefab? upgradePrefab = null, int currentLevel = 0)
|
|
|
|
|
{
|
|
|
|
|
float progressBarHeight = 0.25f;
|
|
|
|
|
|
|
|
|
@@ -1105,21 +1124,26 @@ namespace Barotrauma
|
|
|
|
|
* |------------------------------------------------------------------|
|
|
|
|
|
*/
|
|
|
|
|
GUIFrame prefabFrame = new GUIFrame(parent, style: "ListBoxElement") { SelectedColor = Color.Transparent, UserData = userData };
|
|
|
|
|
GUILayoutGroup prefabLayout = new GUILayoutGroup(rectT(0.98f, 0.95f, prefabFrame, Anchor.Center), isHorizontal: true) { Stretch = true };
|
|
|
|
|
GUILayoutGroup imageLayout = new GUILayoutGroup(rectT(new Point(prefabLayout.Rect.Height, prefabLayout.Rect.Height), prefabLayout), childAnchor: Anchor.Center);
|
|
|
|
|
var icon = new GUIImage(rectT(0.9f, 0.9f, imageLayout, scaleBasis: ScaleBasis.BothHeight), sprite, scaleToFit: true) { CanBeFocused = false };
|
|
|
|
|
GUILayoutGroup textLayout = new GUILayoutGroup(rectT(0.8f - imageLayout.RectTransform.RelativeSize.X, 1, prefabLayout));
|
|
|
|
|
var name = new GUITextBlock(rectT(1, 0.25f, textLayout), RichString.Rich(title), font: GUIStyle.SubHeadingFont) { AutoScaleHorizontal = true, AutoScaleVertical = true, Padding = Vector4.Zero };
|
|
|
|
|
GUILayoutGroup descriptionLayout = new GUILayoutGroup(rectT(1, 0.75f - progressBarHeight, textLayout));
|
|
|
|
|
var description = new GUITextBlock(rectT(1, 1, descriptionLayout), body, font: GUIStyle.SmallFont, wrap: true, textAlignment: Alignment.TopLeft) { Padding = Vector4.Zero };
|
|
|
|
|
GUILayoutGroup? progressLayout = null;
|
|
|
|
|
GUILayoutGroup mainLayout = new GUILayoutGroup(rectT(0.98f, 0.95f, prefabFrame, Anchor.Center), isHorizontal: false);
|
|
|
|
|
GUILayoutGroup prefabLayout = new GUILayoutGroup(rectT(1f, addBuyButton ? 0.65f : 1f, mainLayout, Anchor.Center), isHorizontal: true) { Stretch = true };
|
|
|
|
|
GUILayoutGroup imageLayout = new GUILayoutGroup(rectT(new Point(prefabLayout.Rect.Height, prefabLayout.Rect.Height), prefabLayout), childAnchor: Anchor.Center);
|
|
|
|
|
var icon = new GUIImage(rectT(0.9f, 0.9f, imageLayout, scaleBasis: ScaleBasis.BothHeight), sprite, scaleToFit: true) { CanBeFocused = false };
|
|
|
|
|
GUILayoutGroup textLayout = new GUILayoutGroup(rectT(1f - imageLayout.RectTransform.RelativeSize.X, 1, prefabLayout));
|
|
|
|
|
var name = new GUITextBlock(rectT(1, 0.25f, textLayout), RichString.Rich(title), font: GUIStyle.SubHeadingFont) { AutoScaleHorizontal = true, AutoScaleVertical = true, Padding = Vector4.Zero };
|
|
|
|
|
GUILayoutGroup descriptionLayout = new GUILayoutGroup(rectT(1, 0.75f - progressBarHeight, textLayout));
|
|
|
|
|
var description = new GUITextBlock(rectT(1, 1, descriptionLayout), body, font: GUIStyle.SmallFont, wrap: true, textAlignment: Alignment.TopLeft) { Padding = Vector4.Zero };
|
|
|
|
|
GUILayoutGroup? progressLayout = null;
|
|
|
|
|
GUILayoutGroup? buyButtonLayout = null;
|
|
|
|
|
|
|
|
|
|
Option<BuyButtonFrame> buyButtonOption = Option<BuyButtonFrame>.None();
|
|
|
|
|
Option<ProgressBarFrame> progressBarOption = Option<ProgressBarFrame>.None();
|
|
|
|
|
|
|
|
|
|
if (addProgressBar)
|
|
|
|
|
{
|
|
|
|
|
progressLayout = new GUILayoutGroup(rectT(1, 0.25f, textLayout), isHorizontal: true, childAnchor: Anchor.CenterLeft) { UserData = "progressbar" };
|
|
|
|
|
new GUIProgressBar(rectT(0.8f, 0.75f, progressLayout), 0.0f, GUIStyle.Orange);
|
|
|
|
|
new GUITextBlock(rectT(0.2f, 1, progressLayout), string.Empty, font: GUIStyle.SmallFont, textAlignment: Alignment.Center) { Padding = Vector4.Zero };
|
|
|
|
|
progressLayout = new GUILayoutGroup(rectT(1, 0.25f, textLayout), isHorizontal: true, childAnchor: Anchor.CenterLeft) { UserData = UpgradeStoreUserData.ProgressBarLayout };
|
|
|
|
|
GUITextBlock progressText = new GUITextBlock(rectT(0.15f, 1, progressLayout), string.Empty, font: GUIStyle.SmallFont, textAlignment: Alignment.Center) { Padding = Vector4.Zero };
|
|
|
|
|
GUIProgressBar progressBar = new GUIProgressBar(rectT(0.85f, 0.75f, progressLayout), 0.0f, GUIStyle.Orange);
|
|
|
|
|
progressBarOption = Option.Some(new ProgressBarFrame(progressText, progressBar));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (addBuyButton)
|
|
|
|
@@ -1127,12 +1151,33 @@ namespace Barotrauma
|
|
|
|
|
var formattedPrice = TextManager.FormatCurrency(Math.Abs(price));
|
|
|
|
|
//negative price = refund
|
|
|
|
|
if (price < 0) { formattedPrice = "+" + formattedPrice; }
|
|
|
|
|
buyButtonLayout = new GUILayoutGroup(rectT(0.2f, 1, prefabLayout), childAnchor: Anchor.TopCenter) { UserData = "buybutton" };
|
|
|
|
|
var priceText = new GUITextBlock(rectT(1, 0.2f, buyButtonLayout), formattedPrice, textAlignment: Alignment.Center)
|
|
|
|
|
buyButtonLayout = new GUILayoutGroup(rectT(1f, 0.35f, mainLayout), isHorizontal: true) { UserData = UpgradeStoreUserData.BuyButtonLayout };;
|
|
|
|
|
|
|
|
|
|
GUIListBox materialCostList;
|
|
|
|
|
if (upgradePrefab is not null)
|
|
|
|
|
{
|
|
|
|
|
var increaseText = new GUITextBlock(rectT(imageLayout.RectTransform.RelativeSize.X, 1f, buyButtonLayout), "", textAlignment: Alignment.Center, font: GUIStyle.SubHeadingFont)
|
|
|
|
|
{
|
|
|
|
|
UserData = UpgradeStoreUserData.IncreaseLabel
|
|
|
|
|
};
|
|
|
|
|
UpdateUpgradePercentageText(increaseText, upgradePrefab, currentLevel);
|
|
|
|
|
materialCostList = new GUIListBox(rectT(0.65f - imageLayout.RectTransform.RelativeSize.X, 1f, buyButtonLayout), isHorizontal: true, style: null);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
materialCostList = new GUIListBox(rectT(0.65f, 1f, buyButtonLayout), isHorizontal: true, style: null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
materialCostList.Visible = false;
|
|
|
|
|
materialCostList.UserData = UpgradeStoreUserData.MaterialCostList;
|
|
|
|
|
|
|
|
|
|
var priceText = new GUITextBlock(rectT(0.2f, 1f, buyButtonLayout), formattedPrice, textAlignment: Alignment.Right)
|
|
|
|
|
{
|
|
|
|
|
UserData = UpgradeStoreUserData.PriceLabel,
|
|
|
|
|
//prices on swappable items are always visible, upgrade prices are enabled in UpdateUpgradeEntry for purchasable upgrades
|
|
|
|
|
Visible = userData is ItemPrefab
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (price < 0)
|
|
|
|
|
{
|
|
|
|
|
priceText.TextColor = GUIStyle.Green;
|
|
|
|
@@ -1141,15 +1186,13 @@ namespace Barotrauma
|
|
|
|
|
{
|
|
|
|
|
priceText.Text = string.Empty;
|
|
|
|
|
}
|
|
|
|
|
new GUIButton(rectT(0.7f, 0.5f, buyButtonLayout), string.Empty, style: buttonStyle)
|
|
|
|
|
GUIButton buyButton = new GUIButton(rectT(0.15f, 1f, buyButtonLayout), string.Empty, style: buttonStyle)
|
|
|
|
|
{
|
|
|
|
|
UserData = UpgradeStoreUserData.BuyButton,
|
|
|
|
|
Enabled = false
|
|
|
|
|
};
|
|
|
|
|
if (upgradePrefab != null)
|
|
|
|
|
{
|
|
|
|
|
var increaseText = new GUITextBlock(rectT(1, 0.2f, buyButtonLayout), "", textAlignment: Alignment.Center);
|
|
|
|
|
UpdateUpgradePercentageText(increaseText, upgradePrefab, currentLevel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buyButtonOption = Option.Some(new BuyButtonFrame(buyButtonLayout, materialCostList, buyButton, priceText));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
description.CalculateHeightFromText();
|
|
|
|
@@ -1175,7 +1218,7 @@ namespace Barotrauma
|
|
|
|
|
progressLayout?.Recalculate();
|
|
|
|
|
buyButtonLayout?.Recalculate();
|
|
|
|
|
|
|
|
|
|
return prefabFrame;
|
|
|
|
|
return new UpgradeFrame(prefabFrame, icon, name, description, buyButtonOption, progressBarOption);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void UpdateUpgradePercentageText(GUITextBlock text, UpgradePrefab upgradePrefab, int currentLevel)
|
|
|
|
@@ -1197,31 +1240,21 @@ namespace Barotrauma
|
|
|
|
|
Submarine? sub = GameMain.GameSession?.Submarine ?? Submarine.MainSub;
|
|
|
|
|
if (Campaign is null || sub is null) { return; }
|
|
|
|
|
|
|
|
|
|
GUIFrame prefabFrame = CreateUpgradeFrame(prefab, category, Campaign, rectT(1f, 0.25f, parent));
|
|
|
|
|
var prefabLayout = prefabFrame.GetChild<GUILayoutGroup>();
|
|
|
|
|
GUILayoutGroup[] childLayouts = prefabLayout.GetAllChildren<GUILayoutGroup>().ToArray();
|
|
|
|
|
var imageLayout = childLayouts[0];
|
|
|
|
|
var icon = imageLayout.GetChild<GUIImage>();
|
|
|
|
|
var textLayout = childLayouts[1];
|
|
|
|
|
var name = textLayout.GetChild<GUITextBlock>();
|
|
|
|
|
GUILayoutGroup[] textChildLayouts = textLayout.GetAllChildren<GUILayoutGroup>().ToArray();
|
|
|
|
|
var descriptionLayout = textChildLayouts[0];
|
|
|
|
|
var description = descriptionLayout.GetChild<GUITextBlock>();
|
|
|
|
|
var progressLayout = textChildLayouts[1];
|
|
|
|
|
var buyButtonLayout = childLayouts[2];
|
|
|
|
|
var buyButton = buyButtonLayout.GetChild<GUIButton>();
|
|
|
|
|
UpgradeFrame prefabFrame = CreateUpgradeFrame(prefab, category, Campaign, rectT(1f, 0.4f, parent));
|
|
|
|
|
|
|
|
|
|
if (!prefabFrame.BuyButton.TryUnwrap(out BuyButtonFrame buyButtonFrame)) { return; }
|
|
|
|
|
|
|
|
|
|
if (!HasPermission || !prefab.IsApplicable(submarine.Info) || (itemsOnSubmarine != null && !itemsOnSubmarine.Any(it => category.CanBeApplied(it, prefab))))
|
|
|
|
|
{
|
|
|
|
|
prefabFrame.Enabled = false;
|
|
|
|
|
description.Enabled = false;
|
|
|
|
|
name.Enabled = false;
|
|
|
|
|
icon.Color = Color.Gray;
|
|
|
|
|
buyButton.Enabled = false;
|
|
|
|
|
buyButtonLayout.UserData = null; // prevent UpdateUpgradeEntry() from enabling the button
|
|
|
|
|
prefabFrame.Frame.Enabled = false;
|
|
|
|
|
prefabFrame.Description.Enabled = false;
|
|
|
|
|
prefabFrame.Name.Enabled = false;
|
|
|
|
|
prefabFrame.Icon.Color = Color.Gray;
|
|
|
|
|
buyButtonFrame.BuyButton.Enabled = false;
|
|
|
|
|
buyButtonFrame.Layout.UserData = null; // prevent UpdateUpgradeEntry() from enabling the button
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buyButton.OnClicked += (button, o) =>
|
|
|
|
|
buyButtonFrame.BuyButton.OnClicked += (button, o) =>
|
|
|
|
|
{
|
|
|
|
|
LocalizedString promptBody = TextManager.GetWithVariables("Upgrades.PurchasePromptBody",
|
|
|
|
|
("[upgradename]", prefab.Name),
|
|
|
|
@@ -1240,7 +1273,7 @@ namespace Barotrauma
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
UpdateUpgradeEntry(prefabFrame, prefab, category, Campaign);
|
|
|
|
|
UpdateUpgradeEntry(prefabFrame.Frame, prefab, category, Campaign);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CreateItemTooltip(MapEntity entity)
|
|
|
|
@@ -1623,7 +1656,7 @@ namespace Barotrauma
|
|
|
|
|
|
|
|
|
|
int maxLevel = prefab.GetMaxLevelForCurrentSub();
|
|
|
|
|
LocalizedString progressText = TextManager.GetWithVariables("upgrades.progressformat", ("[level]", currentLevel.ToString()), ("[maxlevel]", maxLevel.ToString()));
|
|
|
|
|
if (prefabFrame.FindChild("progressbar", true) is { } progressParent)
|
|
|
|
|
if (prefabFrame.FindChild(UpgradeStoreUserData.ProgressBarLayout, true) is { } progressParent)
|
|
|
|
|
{
|
|
|
|
|
GUIProgressBar bar = progressParent.GetChild<GUIProgressBar>();
|
|
|
|
|
if (bar != null)
|
|
|
|
@@ -1636,36 +1669,111 @@ namespace Barotrauma
|
|
|
|
|
if (block != null) { block.Text = progressText; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (prefabFrame.FindChild("buybutton", true) is { } buttonParent)
|
|
|
|
|
if (prefabFrame.FindChild(UpgradeStoreUserData.BuyButtonLayout, true) is not { } buttonParent) { return; }
|
|
|
|
|
|
|
|
|
|
GUITextBlock priceLabel = (GUITextBlock)buttonParent.FindChild(UpgradeStoreUserData.PriceLabel, recursive: true);
|
|
|
|
|
priceLabel.Visible = true;
|
|
|
|
|
int price = prefab.Price.GetBuyPrice(campaign.UpgradeManager.GetUpgradeLevel(prefab, category), campaign.Map?.CurrentLocation);
|
|
|
|
|
|
|
|
|
|
if (!WaitForServerUpdate)
|
|
|
|
|
{
|
|
|
|
|
List<GUITextBlock> textBlocks = buttonParent.GetAllChildren<GUITextBlock>().ToList();
|
|
|
|
|
|
|
|
|
|
GUITextBlock priceLabel = textBlocks[0];
|
|
|
|
|
priceLabel.Visible = true;
|
|
|
|
|
int price = prefab.Price.GetBuyPrice(campaign.UpgradeManager.GetUpgradeLevel(prefab, category), campaign.Map?.CurrentLocation);
|
|
|
|
|
|
|
|
|
|
if (priceLabel != null && !WaitForServerUpdate)
|
|
|
|
|
priceLabel.Text = TextManager.FormatCurrency(price);
|
|
|
|
|
if (currentLevel >= maxLevel)
|
|
|
|
|
{
|
|
|
|
|
priceLabel.Text = TextManager.FormatCurrency(price);
|
|
|
|
|
if (currentLevel >= maxLevel)
|
|
|
|
|
{
|
|
|
|
|
priceLabel.Text = TextManager.Get("Upgrade.MaxedUpgrade");
|
|
|
|
|
}
|
|
|
|
|
priceLabel.Text = TextManager.Get("Upgrade.MaxedUpgrade");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GUIButton button = buttonParent.GetChild<GUIButton>();
|
|
|
|
|
if (button != null)
|
|
|
|
|
if (buttonParent.FindChild(UpgradeStoreUserData.IncreaseLabel, recursive: true) is GUITextBlock increaseLabel && !WaitForServerUpdate)
|
|
|
|
|
{
|
|
|
|
|
UpdateUpgradePercentageText(increaseLabel, prefab, currentLevel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool isMax = currentLevel >= maxLevel;
|
|
|
|
|
|
|
|
|
|
if (buttonParent.FindChild(UpgradeStoreUserData.BuyButton, recursive: true) is GUIButton button)
|
|
|
|
|
{
|
|
|
|
|
bool canBuy = !WaitForServerUpdate && !isMax && campaign.GetBalance() >= price && prefab.HasResourcesToUpgrade(Character.Controlled, currentLevel + 1);
|
|
|
|
|
|
|
|
|
|
button.Enabled = canBuy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (prefabFrame.FindChild(UpgradeStoreUserData.MaterialCostList, true) is GUIListBox itemList)
|
|
|
|
|
{
|
|
|
|
|
if (isMax)
|
|
|
|
|
{
|
|
|
|
|
button.Enabled = currentLevel < maxLevel;
|
|
|
|
|
if (WaitForServerUpdate || campaign.GetBalance() < price)
|
|
|
|
|
{
|
|
|
|
|
button.Enabled = false;
|
|
|
|
|
}
|
|
|
|
|
itemList.Visible = false;
|
|
|
|
|
}
|
|
|
|
|
GUITextBlock increaseLabel = textBlocks[1];
|
|
|
|
|
if (increaseLabel != null && !WaitForServerUpdate)
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
UpdateUpgradePercentageText(increaseLabel, prefab, currentLevel);
|
|
|
|
|
CreateMaterialCosts(itemList, prefab, currentLevel + 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void CreateMaterialCosts(GUIListBox list, UpgradePrefab prefab, int targetLevel)
|
|
|
|
|
{
|
|
|
|
|
list.Content.ClearChildren();
|
|
|
|
|
List<Item> allItems = Character.Controlled?.Inventory?.FindAllItems(recursive: true) ?? new List<Item>();
|
|
|
|
|
|
|
|
|
|
var resources = prefab.GetApplicableResources(targetLevel);
|
|
|
|
|
|
|
|
|
|
foreach (ApplicableResourceCollection collection in resources)
|
|
|
|
|
{
|
|
|
|
|
list.Visible = true;
|
|
|
|
|
|
|
|
|
|
int length = collection.MatchingItems.Length;
|
|
|
|
|
|
|
|
|
|
if (length is 0) { continue; }
|
|
|
|
|
|
|
|
|
|
ItemPrefab defaultItemPrefab = collection.MatchingItems.First();
|
|
|
|
|
|
|
|
|
|
GUILayoutGroup wrapperLayout = new GUILayoutGroup(rectT(0.25f, 1f, list.Content));
|
|
|
|
|
|
|
|
|
|
GUIFrame itemFrame = new GUIFrame(rectT(1f, 1f, wrapperLayout), style: null)
|
|
|
|
|
{
|
|
|
|
|
ToolTip = defaultItemPrefab.Name
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bool hasItems = collection.Cost.Amount <= allItems.Count(collection.Cost.MatchesItem);
|
|
|
|
|
|
|
|
|
|
Sprite icon = defaultItemPrefab.InventoryIcon ?? prefab.Sprite;
|
|
|
|
|
Color iconColor = defaultItemPrefab.InventoryIcon is null ? defaultItemPrefab.SpriteColor : defaultItemPrefab.InventoryIconColor;
|
|
|
|
|
|
|
|
|
|
GUIImage itemIcon = new GUIImage(new RectTransform(Vector2.One, itemFrame.RectTransform, scaleBasis: ScaleBasis.Smallest, anchor: Anchor.Center), sprite: icon, scaleToFit: true)
|
|
|
|
|
{
|
|
|
|
|
Color = hasItems ? iconColor : iconColor * 0.9f,
|
|
|
|
|
CanBeFocused = false
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// item count text
|
|
|
|
|
new GUITextBlock(new RectTransform(new Vector2(0.5f, 0.5f), itemIcon.RectTransform, anchor: Anchor.BottomRight), $"{collection.Count}", font: GUIStyle.Font, textAlignment: Alignment.BottomRight)
|
|
|
|
|
{
|
|
|
|
|
Shadow = true,
|
|
|
|
|
CanBeFocused = false,
|
|
|
|
|
Padding = Vector4.Zero,
|
|
|
|
|
TextColor = hasItems ? Color.White : GUIStyle.Red,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (length is 1) { continue; }
|
|
|
|
|
|
|
|
|
|
// we have more than 1 item, show a "slideshow" of the items
|
|
|
|
|
|
|
|
|
|
float index = 0f;
|
|
|
|
|
GUICustomComponent customComponent = new GUICustomComponent(rectT(1f, 1f, itemFrame), null, (deltaTime, component) =>
|
|
|
|
|
{
|
|
|
|
|
index += deltaTime / 3f;
|
|
|
|
|
if (index > length) { index = 0; }
|
|
|
|
|
|
|
|
|
|
ItemPrefab currentPrefab = collection.MatchingItems[(int)MathF.Floor(index)];
|
|
|
|
|
Sprite icon = currentPrefab.InventoryIcon ?? prefab.Sprite;
|
|
|
|
|
Color iconColor = currentPrefab.InventoryIcon is null ? currentPrefab.SpriteColor : currentPrefab.InventoryIconColor;
|
|
|
|
|
itemIcon.Sprite = icon;
|
|
|
|
|
itemIcon.Color = hasItems ? iconColor : iconColor * 0.9f;
|
|
|
|
|
itemFrame.ToolTip = currentPrefab.Name;
|
|
|
|
|
})
|
|
|
|
|
{
|
|
|
|
|
CanBeFocused = false
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|