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

Feature/ticket purchase popup #5889

Merged
merged 9 commits into from
Oct 21, 2024
20 changes: 19 additions & 1 deletion nekoyume/Assets/_Scripts/UI/Payment/PaymentPopup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
using Cysharp.Threading.Tasks;
using Libplanet.Types.Assets;
using Nekoyume.Game;
using Nekoyume.Game.Battle;
using Nekoyume.Helper;
using Nekoyume.State;
using Nekoyume.UI.Model;
using Nekoyume.UI.Module;
using TMPro;
using UniRx;
using UnityEngine;
using UnityEngine.UI;

Expand Down Expand Up @@ -59,6 +61,8 @@ private enum PopupType

private System.Action YesCallback { get; set; }

private PopupType _type;

protected override void Awake()
{
base.Awake();
Expand All @@ -72,6 +76,7 @@ protected override void Awake()

private void SetPopupType(PopupType popupType)
{
_type = popupType;
switch (popupType)
{
case PopupType.AttractAction:
Expand Down Expand Up @@ -724,7 +729,20 @@ private System.Action AttractRuneStone(FungibleAssetValue runeStone)
private void Yes()
{
base.Close();
YesCallback?.Invoke();

if (_type == PopupType.AttractAction && BattleRenderer.Instance.IsOnBattle)
{
Lobby.Enter(true);

Game.Game.instance.Lobby.OnLobbyEnterEnd.First().Subscribe(_ =>
{
YesCallback?.Invoke();
});
}
else
{
YesCallback?.Invoke();
}
}

private void Cancel()
Expand Down
4 changes: 0 additions & 4 deletions nekoyume/Assets/_Scripts/UI/Widget/BattlePreparation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,6 @@ private void OnClickBattle()
break;
}

var balance = States.Instance.GoldBalanceState.Gold;
var cost = RxProps.EventScheduleRowForDungeon.Value
.GetDungeonTicketCost(
RxProps.EventDungeonInfo.Value?.NumberOfTicketPurchases ?? 0,
Expand All @@ -465,13 +464,10 @@ private void OnClickBattle()

Find<TicketPurchasePopup>().Show(
CostType.EventDungeonTicket,
CostType.NCG,
balance,
cost,
purchasedCount,
1,
() => StartCoroutine(CoBattleStart(_stageType, CostType.NCG, true)),
() => GoToMarket(TradeType.Sell),
true
);
return;
Expand Down
57 changes: 10 additions & 47 deletions nekoyume/Assets/_Scripts/UI/Widget/Popup/BattleResultPopup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ private IEnumerator OnClickNext()

if (SharedModel.ActionPointNotEnough)
{
var balance = States.Instance.GoldBalanceState.Gold;
var cost = RxProps.EventScheduleRowForDungeon.Value
.GetDungeonTicketCost(
RxProps.EventDungeonInfo.Value?.NumberOfTicketPurchases ?? 0,
Expand All @@ -327,13 +326,10 @@ private IEnumerator OnClickNext()

Find<TicketPurchasePopup>().Show(
CostType.EventDungeonTicket,
CostType.NCG,
balance,
cost,
purchasedCount,
1,
() => StartCoroutine(CoProceedNextStage(true)),
GoToMarket,
true
);
yield break;
Expand Down Expand Up @@ -364,7 +360,6 @@ private IEnumerator OnClickRepeat()

if (SharedModel.ActionPointNotEnough)
{
var balance = States.Instance.GoldBalanceState.Gold;
var cost = RxProps.EventScheduleRowForDungeon.Value
.GetDungeonTicketCost(
RxProps.EventDungeonInfo.Value?.NumberOfTicketPurchases ?? 0,
Expand All @@ -374,13 +369,10 @@ private IEnumerator OnClickRepeat()

Find<TicketPurchasePopup>().Show(
CostType.EventDungeonTicket,
CostType.NCG,
balance,
cost,
purchasedCount,
1,
() => StartCoroutine(CoRepeatStage(true)),
GoToMarket,
true
);
yield break;
Expand Down Expand Up @@ -490,11 +482,6 @@ public void Show(Model model, bool isBoosted, List<TableData.EquipmentItemRecipe
UpdateView(isBoosted);
}

public override void Close(bool ignoreCloseAnimation = false)
{
base.Close(ignoreCloseAnimation);
}

private void UpdateView(bool isBoosted)
{
expText.text = $"EXP + {SharedModel.Exp}";
Expand Down Expand Up @@ -905,6 +892,12 @@ private async UniTask CoGoToNextStageClose(BattleLog log)
Close();
}

private void CloseWithBattle()
{
Lobby.Enter(true);
Close();
}

private void GoToMain(bool worldClear)
{
var props = new Dictionary<string, Value>()
Expand All @@ -919,9 +912,7 @@ private void GoToMain(bool worldClear)
var evt = new AirbridgeEvent(category);
evt.SetValue(Game.Game.instance.Stage.stageId);
AirbridgeUnity.TrackEvent(evt);

Lobby.Enter(true);
Close();
CloseWithBattle();

if (worldClear)
{
Expand All @@ -939,8 +930,7 @@ private void GoToMain(bool worldClear)

private void GoToPreparation()
{
Lobby.Enter(true);
Close();
CloseWithBattle();

var worldMapLoading = Find<LoadingScreen>();
worldMapLoading.Show();
Expand Down Expand Up @@ -999,23 +989,9 @@ private void GoToPreparation()
});
}

private void GoToMarket()
{
Lobby.Enter(true);
Close();

Game.Game.instance.Lobby.OnLobbyEnterEnd.First().Subscribe(_ =>
{
CloseWithOtherWidgets();
Find<HeaderMenuStatic>().UpdateAssets(HeaderMenuStatic.AssetVisibleState.Shop);
Find<ShopSell>().Show();
});
}

private void GoToProduct()
{
Lobby.Enter(true);
Close();
CloseWithBattle();

Game.Game.instance.Lobby.OnLobbyEnterEnd.First().Subscribe(_ =>
{
Expand All @@ -1027,8 +1003,7 @@ private void GoToProduct()

private void GoToCraft()
{
Lobby.Enter(true);
Close();
CloseWithBattle();

Game.Game.instance.Lobby.OnLobbyEnterEnd.First().Subscribe(_ =>
{
Expand All @@ -1037,18 +1012,6 @@ private void GoToCraft()
});
}

private void GoToFood()
{
Lobby.Enter(true);
Close();

Game.Game.instance.Lobby.OnLobbyEnterEnd.First().Subscribe(_ =>
{
CloseWithOtherWidgets();
Find<LobbyMenu>().GoToFood();
});
}

private void StopCoUpdateBottomText()
{
if (_coUpdateBottomText != null)
Expand Down
20 changes: 6 additions & 14 deletions nekoyume/Assets/_Scripts/UI/Widget/Popup/TicketPurchasePopup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Nekoyume.L10n;
using Libplanet.Types.Assets;
using Nekoyume.Game.Controller;
using Nekoyume.State;
using Nekoyume.UI.Module;
using TMPro;
using UnityEngine;
Expand Down Expand Up @@ -49,19 +50,16 @@ protected override void Awake()

public void Show(
CostType ticketType,
CostType costType,
FungibleAssetValue balance,
FungibleAssetValue cost,
int purchasedCount,
int maxPurchaseCount,
System.Action onConfirm,
System.Action goToMarget,
bool isMaxPurchaseInfinite = false)
{
if (purchasedCount < maxPurchaseCount || isMaxPurchaseInfinite)
{
ShowPurchaseTicketPopup(ticketType, costType, balance, cost,
purchasedCount, maxPurchaseCount, onConfirm, goToMarget, isMaxPurchaseInfinite);
ShowPurchaseTicketPopup(ticketType, cost,
purchasedCount, maxPurchaseCount, onConfirm, isMaxPurchaseInfinite);
}
else
{
Expand All @@ -73,18 +71,17 @@ public void Show(

private void ShowPurchaseTicketPopup(
CostType ticketType,
CostType costType,
FungibleAssetValue balance,
FungibleAssetValue cost,
int purchasedCount,
int maxPurchaseCount,
System.Action onConfirm,
System.Action goToMarget,
bool isMaxPurchaseInfinite = false)
{
var costType = CostType.NCG;
ticketIcon.overrideSprite = costIconData.GetIcon(ticketType);
costIcon.overrideSprite = costIconData.GetIcon(costType);

var balance = States.Instance.GoldBalanceState.Gold;
var enoughBalance = balance >= cost;

costContainer.SetActive(true);
Expand Down Expand Up @@ -121,12 +118,7 @@ private void ShowPurchaseTicketPopup(
}
else
{
Find<PaymentPopup>().ShowLackPaymentLegacy(
CostType.NCG,
cost.GetQuantityString(),
L10nManager.Localize("UI_NOT_ENOUGH_NCG_WITH_SUPPLIER_INFO"),
L10nManager.Localize("UI_SHOP"),
goToMarget);
Find<PaymentPopup>().ShowLackPaymentNCG(cost.GetQuantityString());
}

Close(!enoughBalance);
Expand Down
14 changes: 1 addition & 13 deletions nekoyume/Assets/_Scripts/UI/Widget/RaidPreparation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,31 +370,19 @@ private void ShowTicketPurchasePopup(long currentBlockIndex)
var raiderState = WorldBossStates.GetRaiderState(avatarState.address);
var cur = States.Instance.GoldBalanceState.Gold.Currency;
var cost = WorldBossHelper.CalculateTicketPrice(row, raiderState, cur);
var balance = States.Instance.GoldBalanceState;
Find<TicketPurchasePopup>().Show(
CostType.WorldBossTicket,
CostType.NCG,
balance.Gold,
cost,
raiderState.PurchaseCount,
row.MaxPurchaseCount,
() =>
{
coverToBlockClick.SetActive(true);
Raid(true);
},
GoToMarket
}
);
}

private void GoToMarket()
{
Find<WorldBoss>().ForceClose();
Find<RaidPreparation>().Close(true);
Find<ShopBuy>().Show();
Find<HeaderMenuStatic>().UpdateAssets(HeaderMenuStatic.AssetVisibleState.Shop);
}

/// <summary>
/// 마지막으로 Raid 전투를 수행했던 BlockIndex값을 가져옵니다.
/// RaidState가 없는경우 0을 리턴합니다.
Expand Down