商品管理View追加
This commit is contained in:
parent
55d4f541f5
commit
3099d51483
|
|
@ -0,0 +1,104 @@
|
||||||
|
using System;
|
||||||
|
using UniRx;
|
||||||
|
using UniRx.Triggers;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
public enum TankState
|
||||||
|
{
|
||||||
|
Unavailable,
|
||||||
|
Lock,
|
||||||
|
Unlock,
|
||||||
|
Selected,
|
||||||
|
}
|
||||||
|
public class ProductManagementTankView : MonoBehaviour
|
||||||
|
{
|
||||||
|
[SerializeField] private GameObject selectedIndicateObject;
|
||||||
|
[SerializeField] private GameObject tankObject;
|
||||||
|
[SerializeField] private Image popcornImage;
|
||||||
|
[SerializeField] private Image packageImage;
|
||||||
|
[SerializeField] private Text tankNumber;
|
||||||
|
[SerializeField] private Text tankStock;
|
||||||
|
private string tankStockFormat = "{0}/{1} 個";
|
||||||
|
private string tankEmptyText = "空っぽ";
|
||||||
|
[SerializeField] private TankRarityView rarityView;
|
||||||
|
[SerializeField] private Button detailButton;
|
||||||
|
[SerializeField] private GameObject arrow;
|
||||||
|
// 未購入
|
||||||
|
[SerializeField] private GameObject lockedTankObject;
|
||||||
|
[SerializeField] private Text lockedTankNumber;
|
||||||
|
[SerializeField] private Text price;
|
||||||
|
[SerializeField] private Button purchaseButton;
|
||||||
|
private int tankNumberInt;
|
||||||
|
private readonly BoolReactiveProperty isEmply = new BoolReactiveProperty();
|
||||||
|
private readonly BoolReactiveProperty detailButtonActive = new BoolReactiveProperty();
|
||||||
|
public int TankNumber => tankNumberInt;
|
||||||
|
|
||||||
|
private readonly ReactiveProperty<TankState> state = new ReactiveProperty<TankState>();
|
||||||
|
public IReadOnlyReactiveProperty<TankState> State => state;
|
||||||
|
public IObservable<Unit> DetailButtonObservable => detailButton.OnClickAsObservable().TakeUntilDestroy(this);
|
||||||
|
public IObservable<Unit> PurchaseButtonObservable => purchaseButton.OnClickAsObservable().TakeUntilDestroy(this);
|
||||||
|
public IObservable<Unit> TankClickObservable { get; private set; }
|
||||||
|
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
var eventTrigger = gameObject.AddComponent<ObservableEventTrigger>();
|
||||||
|
TankClickObservable = eventTrigger.OnPointerClickAsObservable().TakeUntilDestroy(this).AsUnitObservable();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
isEmply.AddTo(this);
|
||||||
|
detailButtonActive.AddTo(this);
|
||||||
|
state.Subscribe(x =>
|
||||||
|
{
|
||||||
|
tankObject.SetActive(x != TankState.Lock && x != TankState.Unavailable);
|
||||||
|
lockedTankObject.SetActive(x == TankState.Lock || x == TankState.Unavailable);
|
||||||
|
purchaseButton.gameObject.SetActive(x == TankState.Lock);
|
||||||
|
selectedIndicateObject.SetActive(x == TankState.Selected);
|
||||||
|
}).AddTo(this);
|
||||||
|
isEmply.Subscribe(active =>
|
||||||
|
{
|
||||||
|
packageImage.gameObject.SetActive(!active);
|
||||||
|
popcornImage.gameObject.SetActive(!active);
|
||||||
|
rarityView.gameObject.SetActive(!active);
|
||||||
|
}).AddTo(this);
|
||||||
|
isEmply.CombineLatest(detailButtonActive, (b, b1) => !b && b1)
|
||||||
|
.Subscribe(active =>
|
||||||
|
{
|
||||||
|
detailButton.gameObject.SetActive(active);
|
||||||
|
}).AddTo(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Initialize(int number, int tankPrice)
|
||||||
|
{
|
||||||
|
state.Value = TankState.Unavailable;
|
||||||
|
tankNumberInt = number;
|
||||||
|
tankNumber.text = $"{number}";
|
||||||
|
lockedTankNumber.text = $"{number}";
|
||||||
|
price.text = $"{tankPrice}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetData(StorageTank tank)
|
||||||
|
{
|
||||||
|
isEmply.Value = tank.Stock == 0;
|
||||||
|
tankStock.text = isEmply.Value ? tankEmptyText : String.Format(tankStockFormat, tank.Stock, tank.Capacity);
|
||||||
|
rarityView.SetHasRarity(tank.Stocks);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetState(TankState tankState)
|
||||||
|
{
|
||||||
|
state.Value = tankState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetArrow(bool active)
|
||||||
|
{
|
||||||
|
arrow.SetActive(active);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetDetailButtonActive(bool active)
|
||||||
|
{
|
||||||
|
detailButtonActive.Value = active;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: cb86ab823f03425b97e7c977c5e65267
|
||||||
|
timeCreated: 1631500410
|
||||||
|
|
@ -0,0 +1,55 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UniRx;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
public enum ProductRefillMode
|
||||||
|
{
|
||||||
|
OneByOne,
|
||||||
|
TankByTank,
|
||||||
|
}
|
||||||
|
public class ProductManagementView : MonoBehaviour
|
||||||
|
{
|
||||||
|
[SerializeField] private List<ProductManagementTankView> tankList = new List<ProductManagementTankView>();
|
||||||
|
[SerializeField] private GameObject oneByOneOn;
|
||||||
|
[SerializeField] private GameObject tankByTankOn;
|
||||||
|
[SerializeField] private Button oneByOneOff;
|
||||||
|
[SerializeField] private Button tankByTankOff;
|
||||||
|
|
||||||
|
public ReactiveProperty<ProductRefillMode> RefillType => refillType;
|
||||||
|
private readonly ReactiveProperty<ProductRefillMode> refillType = new ReactiveProperty<ProductRefillMode>();
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
refillType.AddTo(this);
|
||||||
|
oneByOneOff.OnClickAsObservable().Select(_ => ProductRefillMode.OneByOne)
|
||||||
|
.Merge(tankByTankOff.OnClickAsObservable().Select(_ => ProductRefillMode.TankByTank))
|
||||||
|
.Subscribe(type =>
|
||||||
|
{
|
||||||
|
refillType.Value = type;
|
||||||
|
}).AddTo(this);
|
||||||
|
refillType.Subscribe(type =>
|
||||||
|
{
|
||||||
|
oneByOneOn.SetActive(type == ProductRefillMode.OneByOne);
|
||||||
|
oneByOneOff.gameObject.SetActive(type != ProductRefillMode.OneByOne);
|
||||||
|
tankByTankOn.SetActive(type == ProductRefillMode.TankByTank);
|
||||||
|
tankByTankOff.gameObject.SetActive(type != ProductRefillMode.TankByTank);
|
||||||
|
}).AddTo(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ProductManagementTankView> SetTanks(List<int> priceList)
|
||||||
|
{
|
||||||
|
var i = 1;
|
||||||
|
foreach (var tankView in tankList)
|
||||||
|
{
|
||||||
|
tankView.Initialize(i, priceList[i - 1]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return tankList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetRefillType(ProductRefillMode mode)
|
||||||
|
{
|
||||||
|
refillType.Value = mode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6fb8a3338e924cbe9255939ad1ab6017
|
||||||
|
timeCreated: 1631500384
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
public class RarityStockView : MonoBehaviour
|
||||||
|
{
|
||||||
|
private static readonly string textFormat = "{0}×{1}個";
|
||||||
|
[SerializeField] private Text normalText;
|
||||||
|
[SerializeField] private ProductRarity rarity;
|
||||||
|
public ProductRarity Rarity => rarity;
|
||||||
|
|
||||||
|
public void SetText(int price, int stock)
|
||||||
|
{
|
||||||
|
normalText.text = string.Format(textFormat, price, stock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b0dc9cb18f7548c6a51cf39c843c54ef
|
||||||
|
timeCreated: 1631684472
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
public class RaritySummaryView : MonoBehaviour
|
||||||
|
{
|
||||||
|
[SerializeField] private List<RarityStockView> rarityStockViews;
|
||||||
|
|
||||||
|
public void SetHasRarity(List<(ProductRarity rarity, int price, int stock)> dataList)
|
||||||
|
{
|
||||||
|
foreach (var data in dataList)
|
||||||
|
{
|
||||||
|
rarityStockViews.First(x => x.Rarity == data.rarity)?.SetText(data.price, data.stock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 756a75c73f084205b9473c046ff47a94
|
||||||
|
timeCreated: 1631632399
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UniRx;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
public class TankDetailView : MonoBehaviour
|
||||||
|
{
|
||||||
|
public static readonly string TankDetailDataTag = "TankDetailData";
|
||||||
|
private static readonly int OpenTrigger = Animator.StringToHash("OpenTrigger");
|
||||||
|
private static readonly int CloseTrigger = Animator.StringToHash("CloseTrigger");
|
||||||
|
private static readonly string totalStockFormat = "所持数:{0}";
|
||||||
|
private static readonly string tankStockFormat = "タンク{0}:{1}";
|
||||||
|
|
||||||
|
[SerializeField] private Animator backgroundAnimator;
|
||||||
|
[SerializeField] private Text tankNumber;
|
||||||
|
[SerializeField] private Text totalStock;
|
||||||
|
[SerializeField] private Text tankStock;
|
||||||
|
[SerializeField] private Text price;
|
||||||
|
[SerializeField] private Text name;
|
||||||
|
[SerializeField] private Text text;
|
||||||
|
[SerializeField] private Image popcornImage;
|
||||||
|
[SerializeField] private RaritySummaryView raritySummaryView;
|
||||||
|
[SerializeField] private Button closeButton;
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
var data = LocalCacheManager.Load<(int tankNum, int totalStock, StorageTank tankData, RecipeData recipeData, List<(ProductRarity rarity, int price, int stock)> raritySummaryData)>(TankDetailDataTag);
|
||||||
|
closeButton.OnClickAsObservable().Subscribe(_ =>
|
||||||
|
{
|
||||||
|
transform.SetLocalScale(0);
|
||||||
|
backgroundAnimator.SetTrigger(CloseTrigger);
|
||||||
|
this.CallWaitForSeconds(.25f, () =>
|
||||||
|
{
|
||||||
|
TransitionManager.Instance.UnloadScene(GameScenes.PopcornDescription);
|
||||||
|
});
|
||||||
|
}).AddTo(this);
|
||||||
|
|
||||||
|
tankNumber.text = $"{data.tankNum}";
|
||||||
|
totalStock.text = string.Format(totalStockFormat, data.totalStock);
|
||||||
|
tankStock.text = string.Format(tankStockFormat, data.tankNum, data.tankData.Stock);
|
||||||
|
price.text = $"{data.recipeData.Price}";
|
||||||
|
name.text = $"{data.recipeData.Name}";
|
||||||
|
text.text = $"";
|
||||||
|
raritySummaryView.SetHasRarity(data.raritySummaryData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 503f73b9937449a58919451f7b823757
|
||||||
|
timeCreated: 1631631272
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class TankRarityView : MonoBehaviour
|
||||||
|
{
|
||||||
|
[SerializeField] private GameObject normalOn;
|
||||||
|
[SerializeField] private GameObject normalOff;
|
||||||
|
[SerializeField] private GameObject yellowOn;
|
||||||
|
[SerializeField] private GameObject yellowOff;
|
||||||
|
[SerializeField] private GameObject copperOn;
|
||||||
|
[SerializeField] private GameObject copperOff;
|
||||||
|
[SerializeField] private GameObject silverOn;
|
||||||
|
[SerializeField] private GameObject silverOff;
|
||||||
|
[SerializeField] private GameObject goldOn;
|
||||||
|
[SerializeField] private GameObject goldOff;
|
||||||
|
[SerializeField] private GameObject rainbowOn;
|
||||||
|
[SerializeField] private GameObject rainbowOff;
|
||||||
|
|
||||||
|
public void SetHasRarity(List<ProductStockData> stocks)
|
||||||
|
{
|
||||||
|
var rarities = stocks.Where(x => x.Stock > 0).Select(x => x.Rarity).ToList();
|
||||||
|
normalOn.SetActive(rarities.Contains(ProductRarity.Normal));
|
||||||
|
normalOff.SetActive(!rarities.Contains(ProductRarity.Normal));
|
||||||
|
yellowOn.SetActive(rarities.Contains(ProductRarity.Yellow));
|
||||||
|
yellowOff.SetActive(!rarities.Contains(ProductRarity.Yellow));
|
||||||
|
copperOn.SetActive(rarities.Contains(ProductRarity.Copper));
|
||||||
|
copperOff.SetActive(!rarities.Contains(ProductRarity.Copper));
|
||||||
|
silverOn.SetActive(rarities.Contains(ProductRarity.Silver));
|
||||||
|
silverOff.SetActive(!rarities.Contains(ProductRarity.Silver));
|
||||||
|
goldOn.SetActive(rarities.Contains(ProductRarity.Gold));
|
||||||
|
goldOff.SetActive(!rarities.Contains(ProductRarity.Gold));
|
||||||
|
rainbowOn.SetActive(rarities.Contains(ProductRarity.Rainbow));
|
||||||
|
rainbowOff.SetActive(!rarities.Contains(ProductRarity.Rainbow));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: bb57f12f265d434da0a003594c0d20d1
|
||||||
|
timeCreated: 1631509426
|
||||||
Loading…
Reference in New Issue