You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
422 lines
12 KiB
422 lines
12 KiB
using Container;
|
|
using EnhancedUI;
|
|
using System;
|
|
using System.Numerics;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public partial class MateSettingView : View
|
|
{
|
|
[SerializeField] GameObject leftPanel;
|
|
[SerializeField] GameObject rightPanel;
|
|
|
|
[SerializeField] SelectedMateUI selectedMateUI;
|
|
|
|
[SerializeField] SettedSlotUI[] settedSlots;
|
|
[SerializeField] EScrController mateListScrollCtrl;
|
|
|
|
[SerializeField] ExtendText curListViewModeText;
|
|
|
|
HorizontalDataMatrix<MateData> mateDataMatrix;
|
|
MateEscrListRowSlot selectedListSlot;
|
|
MateEscrListRowSlot.ViewMode curViewMode;
|
|
|
|
private void Start()
|
|
{
|
|
selectedMateUI.HideFull2D();
|
|
|
|
leftPanel.SetActive(false);
|
|
rightPanel.SetActive(false);
|
|
viewState = ViewState.Hidden;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
selectedMateUI.Update();
|
|
}
|
|
|
|
public override void Show()
|
|
{
|
|
GameUIMgr.SSetMainUiOn(false);
|
|
GameUIMgr.SOpenLeftPanel(gold: true);
|
|
selectedMateUI.HideFull2D();
|
|
|
|
ResetPosition();
|
|
leftPanel.SetActive(true);
|
|
rightPanel.SetActive(true);
|
|
viewState = ViewState.Shown;
|
|
|
|
RefreshSettedMateSlots();
|
|
RefreshMateListScroll();
|
|
}
|
|
|
|
public override void Hide()
|
|
{
|
|
selectedListSlot = null;
|
|
mateDataMatrix = null;
|
|
selectedMateUI.Dispose();
|
|
|
|
leftPanel.SetActive(false);
|
|
rightPanel.SetActive(false);
|
|
viewState = ViewState.Hidden;
|
|
|
|
selectedMateUI.HideFull2D();
|
|
GameUIMgr.SCloseLeftPanel();
|
|
GameUIMgr.SSetMainUiOn(true);
|
|
}
|
|
|
|
private void RefreshMateListScroll()
|
|
{
|
|
if (mateListScrollCtrl is null) return;
|
|
|
|
if(mateDataMatrix is null)
|
|
{
|
|
const int columnCount = 4;
|
|
mateDataMatrix = MateDataGroup.Instance.GetMateDataMatrix(MateData.CompareByID, columnCount);
|
|
}
|
|
|
|
var mateRowIndices = new SmallList<int>();
|
|
for (int i = 0; i < mateDataMatrix.RowCount; i++)
|
|
{
|
|
mateRowIndices.Add(i);
|
|
}
|
|
|
|
mateListScrollCtrl.LoadDatas(mateRowIndices, new ListRowDelegate
|
|
{
|
|
OnSetData = OnSetMateListRow
|
|
});
|
|
}
|
|
|
|
private void OnSetMateListRow(EscrListRowSlot slot)
|
|
{
|
|
MateEscrListRowSlot mateSlot = slot as MateEscrListRowSlot;
|
|
if (mateSlot is null) return;
|
|
|
|
if (mateDataMatrix.TryGetValue(slot.RowIndex, slot.ColumnIndex, out var mateData))
|
|
{
|
|
bool isSetted = false;
|
|
MateMgr.Instance.SettedMates.LoopValidSlot((settedMate) =>
|
|
{
|
|
if (settedMate.Data.ID == mateData.ID)
|
|
{
|
|
isSetted = true;
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
});
|
|
|
|
// there is no selected slot then select this slot
|
|
if (selectedListSlot is null)
|
|
{
|
|
selectedListSlot = mateSlot;
|
|
selectedMateUI.SetMateData(mateData);
|
|
}
|
|
|
|
mateSlot.viewMode = curViewMode;
|
|
mateSlot.SetData(mateData);
|
|
mateSlot.SetActiveSettedIndicator(isSetted);
|
|
mateSlot.SetActiveSelectedIndicator(selectedListSlot == mateSlot);
|
|
mateSlot.OnClick -= OnClickMateListSlot;
|
|
mateSlot.OnClick += OnClickMateListSlot;
|
|
|
|
slot.gameObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
slot.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
private void OnClickMateListSlot(MateEscrListRowSlot slot)
|
|
{
|
|
if (slot == selectedListSlot) return;
|
|
|
|
if (selectedListSlot != null)
|
|
{
|
|
selectedListSlot.SetActiveSelectedIndicator(false);
|
|
}
|
|
|
|
selectedListSlot = slot;
|
|
selectedListSlot.SetActiveSelectedIndicator(true);
|
|
|
|
var selectedMateData = slot.GetData() as MateData;
|
|
|
|
if (selectedMateData != null)
|
|
{
|
|
if (selectedMateData.IsUnlocked)
|
|
{
|
|
var mateMgr = MateMgr.Instance;
|
|
|
|
mateMgr.SettedMates.GetEmptySlots(out var emptyList);
|
|
if (emptyList.Count != 0)
|
|
{
|
|
var emptySlot = emptyList[0];
|
|
mateMgr.SetMateAt(selectedMateData.ID, emptySlot.slotIndex);
|
|
mateListScrollCtrl?.scroller.RefreshActiveCellViews();
|
|
RefreshSettedMateSlots();
|
|
}
|
|
}
|
|
|
|
selectedMateUI.SetMateData(selectedMateData);
|
|
}
|
|
}
|
|
|
|
public void OnClickedSettedSlot(int slotIdx)
|
|
{
|
|
if(slotIdx < 0 || slotIdx >= settedSlots.Length) return;
|
|
|
|
var targetSlot = settedSlots[slotIdx];
|
|
|
|
var mateMgr = MateMgr.Instance;
|
|
if (mateMgr.ActiveMate.Data.ID == targetSlot.slot.item.Data.ID && !mateMgr.IsSafeToChangeCurrentMate())
|
|
{
|
|
GameUIMgr.SOpenToast(LocalizationText.GetText("try_and_failed_0"));
|
|
}
|
|
else
|
|
{
|
|
mateMgr.RemoveMateAt(targetSlot.slot.slotIndex);
|
|
mateListScrollCtrl?.scroller.RefreshActiveCellViews();
|
|
RefreshSettedMateSlots();
|
|
}
|
|
}
|
|
|
|
private void RefreshSettedMateSlots()
|
|
{
|
|
int i = 0;
|
|
foreach (var slot in MateMgr.Instance.SettedMates)
|
|
{
|
|
if(i >= settedSlots.Length) break;
|
|
settedSlots[i].SetSlot(slot);
|
|
i++;
|
|
}
|
|
}
|
|
|
|
public void SwitchViewMode()
|
|
{
|
|
string viewModeKey;
|
|
if (curViewMode == MateEscrListRowSlot.ViewMode.Character)
|
|
{
|
|
curViewMode = MateEscrListRowSlot.ViewMode.Nationality;
|
|
viewModeKey = "show_nationality";
|
|
}
|
|
else
|
|
{
|
|
curViewMode = MateEscrListRowSlot.ViewMode.Character;
|
|
viewModeKey = "show_character";
|
|
}
|
|
|
|
curListViewModeText?.SetText(LocalizationInjector.MakeToLocalizationKey(viewModeKey));
|
|
mateListScrollCtrl?.scroller.RefreshActiveCellViews();
|
|
}
|
|
|
|
public void ShowCurrentSelectedFull2D() => selectedMateUI.ShowFull2D();
|
|
public void HideFull2D() => selectedMateUI.HideFull2D();
|
|
}
|
|
|
|
public partial class MateSettingView : View
|
|
{
|
|
[Serializable]
|
|
class SelectedMateUI
|
|
{
|
|
public ObjectIndicator indicator;
|
|
public ExtendText nameText;
|
|
public GraphicsColorSetter nameTextColorSetter;
|
|
public TextMeshProUGUI levelText;
|
|
public ExtendButton levelUpButton;
|
|
public TextMeshProUGUI levelUpCostText;
|
|
public GraphicsColorSetter levelUpCostTextColorSetter;
|
|
|
|
public ButtonGroup tabButtonGroup;
|
|
|
|
public GameObject privateSkillPage;
|
|
public ObjectIndicator privateSkillIndicator;
|
|
public ExtendText privateSkillNameText;
|
|
public ExtendText privateSkillDescText;
|
|
|
|
public GameObject full2DImgRoot;
|
|
public ExtendImage full2DImg;
|
|
|
|
uint prevLevel;
|
|
BigInteger currentRequireGold;
|
|
BigInteger appendedLvUpCost;
|
|
|
|
public MateData mateData { get; private set; }
|
|
|
|
public void SetMateData(MateData mateData)
|
|
{
|
|
this.mateData = mateData;
|
|
prevLevel = 0;
|
|
|
|
ObjectIndicatorSetter.SetWith(indicator, mateData);
|
|
indicator?.gameObject.SetActive(true);
|
|
|
|
nameText?.SetText(LocalizationInjector.MakeToLocalizationKey(mateData.NameKey));
|
|
nameTextColorSetter?.SetColor(mateData.Grade.ToString());
|
|
|
|
if (levelUpButton != null)
|
|
{
|
|
levelUpButton.OnPressedShortly -= OnClickLvUpButton;
|
|
levelUpButton.OnLongPressed -= OnPressedLvUpButton;
|
|
levelUpButton.OnLongPressedReleased -= OnReleasedLvUpButton;
|
|
|
|
levelUpButton.OnPressedShortly += OnClickLvUpButton;
|
|
levelUpButton.OnLongPressed += OnPressedLvUpButton;
|
|
levelUpButton.OnLongPressedReleased += OnReleasedLvUpButton;
|
|
}
|
|
|
|
if (tabButtonGroup != null)
|
|
{
|
|
tabButtonGroup.OnChangedButtonState -= OnClickedTabButton;
|
|
tabButtonGroup.OnChangedButtonState += OnClickedTabButton;
|
|
|
|
tabButtonGroup.SelectButton(0);
|
|
}
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
if(mateData is null) return;
|
|
|
|
if(prevLevel != mateData.Level)
|
|
{
|
|
currentRequireGold = mateData.GetRequireExpToNextLv();
|
|
|
|
levelText?.SetText(FormatString.StringFormat("Lv.{0}/{1}", mateData.Level, MateData.MaxLevel));
|
|
levelUpCostText?.SetText(FormatString.BigIntString1(currentRequireGold));
|
|
}
|
|
|
|
bool canLevelUp = mateData.Level < MateData.MaxLevel;
|
|
bool isEnoughGold = DataHandler.Goods.gold >= currentRequireGold;
|
|
|
|
if(levelUpButton != null)
|
|
{
|
|
levelUpButton.ButtonComponent.interactable = canLevelUp && isEnoughGold;
|
|
levelUpButton.gameObject.SetActive(canLevelUp);
|
|
}
|
|
|
|
levelUpCostTextColorSetter?.SetColor(isEnoughGold ? "white" : "red");
|
|
|
|
prevLevel = mateData.Level;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
if (tabButtonGroup != null)
|
|
tabButtonGroup.OnChangedButtonState -= OnClickedTabButton;
|
|
|
|
if (levelUpButton != null)
|
|
{
|
|
levelUpButton.OnPressedShortly -= OnClickLvUpButton;
|
|
levelUpButton.OnLongPressed -= OnPressedLvUpButton;
|
|
levelUpButton.OnLongPressedReleased -= OnReleasedLvUpButton;
|
|
}
|
|
|
|
nameText?.SetText(string.Empty);
|
|
levelText?.SetText(string.Empty);
|
|
|
|
indicator?.gameObject.SetActive(false);
|
|
|
|
mateData = null;
|
|
}
|
|
|
|
private void OnClickLvUpButton()
|
|
{
|
|
if (mateData is null) return;
|
|
|
|
var cost = mateData.GetRequireExpToNextLv();
|
|
if (DataHandler.Goods.gold >= cost)
|
|
{
|
|
mateData.AddLevelExp(cost);
|
|
//TODO : request server to set level and subtract gold
|
|
}
|
|
}
|
|
|
|
private void OnPressedLvUpButton()
|
|
{
|
|
if (mateData is null) return;
|
|
|
|
var cost = mateData.GetRequireExpToNextLv();
|
|
if (DataHandler.Goods.gold >= cost)
|
|
{
|
|
mateData.AddLevelExp(cost);
|
|
appendedLvUpCost += cost;
|
|
}
|
|
}
|
|
|
|
private void OnReleasedLvUpButton()
|
|
{
|
|
if(appendedLvUpCost > 0)
|
|
{
|
|
//TODO : request server to set level and subtract gold
|
|
Logger.Log("Appended LvUpCost : " + appendedLvUpCost);
|
|
|
|
appendedLvUpCost = 0;
|
|
}
|
|
}
|
|
|
|
private void OnClickedTabButton(int idx, Button button, bool activate)
|
|
{
|
|
if (idx == 0) SetActivePrivateSkillPage(activate);
|
|
else if (idx == 1) SetActiveEffectPage(activate);
|
|
}
|
|
|
|
public void SetActivePrivateSkillPage(bool activate)
|
|
{
|
|
privateSkillPage?.SetActive(activate);
|
|
|
|
if (activate && mateData != null && mateData.Skill != null)
|
|
{
|
|
ObjectIndicatorSetter.SetWith(privateSkillIndicator, mateData.Skill);
|
|
privateSkillNameText?.SetText(LocalizationInjector.MakeToLocalizationKey(mateData.Skill.NameKey));
|
|
privateSkillDescText?.SetText(mateData.Skill.GetSkillDesc());
|
|
}
|
|
}
|
|
|
|
public void SetActiveEffectPage(bool activate)
|
|
{
|
|
//TODO : ShowExtraEffectPage
|
|
}
|
|
|
|
public void ShowFull2D()
|
|
{
|
|
if (mateData is null) return;
|
|
|
|
full2DImg?.SetImageAsync(mateData.ImgFull2DPath);
|
|
full2DImgRoot?.SetActive(true);
|
|
}
|
|
|
|
public void HideFull2D()
|
|
{
|
|
full2DImgRoot?.SetActive(false);
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
struct SettedSlotUI
|
|
{
|
|
public ObjectIndicator indicator;
|
|
public GameObject removeIndicator;
|
|
public GameObject emptyIndicator;
|
|
public SlotGroup<IVMate>.Slot slot { get; private set; }
|
|
|
|
public void SetSlot(SlotGroup<IVMate>.Slot slot)
|
|
{
|
|
this.slot = slot;
|
|
|
|
if(slot.IsEmpty)
|
|
{
|
|
removeIndicator?.SetActive(false);
|
|
emptyIndicator?.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
ObjectIndicatorSetter.SetWith(indicator, slot.item.Data);
|
|
indicator.gameObject.SetActive(true);
|
|
removeIndicator.SetActive(true);
|
|
emptyIndicator.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
}
|