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.
204 lines
5.5 KiB
204 lines
5.5 KiB
using Container;
|
|
using EnhancedUI;
|
|
using System;
|
|
using UnityEngine;
|
|
|
|
public partial class FantasyWorldSettingView : View
|
|
{
|
|
[SerializeField] GameObject leftPanel;
|
|
[SerializeField] GameObject rightPanel;
|
|
|
|
[SerializeField] SelectedWorld selectedWorld;
|
|
|
|
[SerializeField] EScrController worldListScrollCtrl;
|
|
|
|
HorizontalDataMatrix<GameModData> worldDataMatrix;
|
|
|
|
GameModData selectedMod;
|
|
GameModEscrListRowSlot selectedListSlot;
|
|
|
|
private void Start()
|
|
{
|
|
leftPanel.SetActive(false);
|
|
rightPanel.SetActive(false);
|
|
viewState = ViewState.Hidden;
|
|
}
|
|
|
|
private void LateUpdate()
|
|
{
|
|
selectedWorld.Update();
|
|
}
|
|
|
|
public override void Show()
|
|
{
|
|
GameUIMgr.SSetMainUiOn(false);
|
|
GameUIMgr.SOpenLeftPanel(fatansyWorldRing : true, memoryPiece : true);
|
|
|
|
ResetPosition();
|
|
leftPanel.SetActive(true);
|
|
rightPanel.SetActive(true);
|
|
viewState = ViewState.Shown;
|
|
|
|
RefreshWorldListScroll();
|
|
}
|
|
|
|
public override void Hide()
|
|
{
|
|
selectedWorld.Dispose();
|
|
|
|
selectedMod = null;
|
|
selectedListSlot = null;
|
|
|
|
leftPanel.SetActive(false);
|
|
rightPanel.SetActive(false);
|
|
viewState = ViewState.Hidden;
|
|
|
|
GameUIMgr.SCloseLeftPanel();
|
|
GameUIMgr.SSetMainUiOn(true);
|
|
}
|
|
|
|
private void RefreshWorldListScroll()
|
|
{
|
|
if(worldListScrollCtrl is null) return;
|
|
|
|
if(worldDataMatrix is null)
|
|
{
|
|
const int columnCount = 1;
|
|
worldDataMatrix = new HorizontalDataMatrix<GameModData>(columnCount);
|
|
|
|
string[] modCodeNames = new string[]
|
|
{
|
|
DreamWorldProp.CodeName
|
|
};
|
|
|
|
for (int i = 0; i < modCodeNames.Length; i++)
|
|
{
|
|
if (GameModDataGroup.Instance.TryGetModData(modCodeNames[i], out GameModData modData))
|
|
{
|
|
worldDataMatrix.PushBack(modData);
|
|
}
|
|
}
|
|
}
|
|
|
|
var worldRowIndices = new SmallList<int>();
|
|
for (int i = 0; i < worldDataMatrix.RowCount; i++)
|
|
{
|
|
worldRowIndices.Add(i);
|
|
}
|
|
|
|
worldListScrollCtrl.LoadDatas(worldRowIndices, new ListRowDelegate
|
|
{
|
|
OnSetData = OnSetWorldListRow
|
|
});
|
|
}
|
|
|
|
private void OnSetWorldListRow(EscrListRowSlot slot)
|
|
{
|
|
var worldSlot = slot as GameModEscrListRowSlot;
|
|
if (worldSlot is null) return;
|
|
|
|
if(worldDataMatrix.TryGetValue(worldSlot.RowIndex, worldSlot.ColumnIndex, out var worldData))
|
|
{
|
|
// if there is no selected slot, then select this slot
|
|
if (selectedMod is null)
|
|
{
|
|
selectedMod = worldData;
|
|
selectedListSlot = worldSlot;
|
|
selectedWorld.SetData(worldData);
|
|
}
|
|
|
|
worldSlot.SetData(worldData);
|
|
worldSlot.SetActiveSelectedIndicator(selectedMod == worldData);
|
|
|
|
worldSlot.OnClick -= OnClickWorldSlot;
|
|
worldSlot.OnClick += OnClickWorldSlot;
|
|
}
|
|
}
|
|
|
|
private void OnClickWorldSlot(GameModEscrListRowSlot slot)
|
|
{
|
|
selectedListSlot?.SetActiveSelectedIndicator(false);
|
|
|
|
var selectedMod = slot.GetData() as GameModData;
|
|
this.selectedMod = selectedMod;
|
|
selectedListSlot = slot;
|
|
selectedListSlot.SetActiveSelectedIndicator(true);
|
|
|
|
if (selectedMod != null)
|
|
{
|
|
selectedWorld.SetData(selectedMod);
|
|
}
|
|
}
|
|
|
|
public void EnterSelectedWorld()
|
|
{
|
|
if(selectedWorld.worldData is null) return;
|
|
DungeonMgr.Instance.OpenPopupPreset(selectedWorld.worldData, Hide);
|
|
}
|
|
}
|
|
|
|
public partial class FantasyWorldSettingView : View
|
|
{
|
|
[Serializable]
|
|
class SelectedWorld
|
|
{
|
|
[SerializeField] ExtendImage worldImage;
|
|
[SerializeField] ExtendText levelText;
|
|
[SerializeField] ButtonIV enterButton;
|
|
[SerializeField] ObjectIndicator[] rewards;
|
|
public GameModData worldData { get; private set; }
|
|
|
|
public void SetData(GameModData worldData)
|
|
{
|
|
this.worldData = worldData;
|
|
|
|
if(worldData is null) return;
|
|
|
|
SetImage();
|
|
SetLevelText();
|
|
SetRewards();
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
if(worldData is null) return;
|
|
|
|
if(enterButton != null)
|
|
enterButton.interactable = worldData.IsUnlocked && DataHandler.Goods.fantasyWorldRing >= 1;
|
|
}
|
|
|
|
private void SetImage()
|
|
{
|
|
var hasThumbnail = worldData as IHasThumbnail;
|
|
if(hasThumbnail is null) return;
|
|
|
|
worldImage?.SetImageInAtlasAsync(hasThumbnail.ThumbnailAtlasName, hasThumbnail.ThumbnailSpriteName);
|
|
}
|
|
|
|
private void SetLevelText()
|
|
{
|
|
levelText?.SetText(FormatString.StringFormat(LocalizationText.GetText("dg_diff"), worldData.Level));
|
|
}
|
|
|
|
private void SetRewards()
|
|
{
|
|
var hasRewards = worldData as IHasRewards;
|
|
if(hasRewards is null) return;
|
|
|
|
var rewardList = hasRewards.GetRewardList(worldData.Level);
|
|
for (int i = 0; i < rewards.Length; i++)
|
|
{
|
|
bool isActive = i < rewardList.Count;
|
|
|
|
rewards[i].gameObject.SetActive(isActive);
|
|
if(isActive)
|
|
ObjectIndicatorSetter.SetWith(rewards[i], rewardList[i]);
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
worldData = null;
|
|
}
|
|
}
|
|
}
|