UI update 02
This commit is contained in:
+20623
-15749
File diff suppressed because it is too large
Load Diff
@@ -10,6 +10,22 @@ using UnityEditor;
|
||||
|
||||
public class uBag : MonoBehaviour
|
||||
{
|
||||
private enum BagFilterMode
|
||||
{
|
||||
All,
|
||||
Cultivation,
|
||||
Precious,
|
||||
Other
|
||||
}
|
||||
|
||||
private enum BagSortMode
|
||||
{
|
||||
Default,
|
||||
Name,
|
||||
Rarity,
|
||||
Count
|
||||
}
|
||||
|
||||
private enum BagCategory
|
||||
{
|
||||
All,
|
||||
@@ -80,6 +96,10 @@ public class uBag : MonoBehaviour
|
||||
public Sprite fallbackBackgroundSprite;
|
||||
public ItemRarityColorConfigSO rarityColorConfig;
|
||||
|
||||
[Header("filters")]
|
||||
public Dropdown bag_filterDropdown;
|
||||
public Dropdown bag_sortDropdown;
|
||||
|
||||
[Header("paths")]
|
||||
[SerializeField] private string notebookEditorPath = "Assets/Resources/so/notebook";
|
||||
[SerializeField] private string notebookRuntimePath = "so/notebook";
|
||||
@@ -92,15 +112,21 @@ public class uBag : MonoBehaviour
|
||||
private readonly List<GameObject> spawnedItems = new List<GameObject>();
|
||||
private readonly List<BagEntry> allEntries = new List<BagEntry>();
|
||||
private readonly Dictionary<uBagItemPrefab, BagEntry> viewEntries = new Dictionary<uBagItemPrefab, BagEntry>();
|
||||
private readonly List<Dropdown.OptionData> filterOptions = new List<Dropdown.OptionData>();
|
||||
private readonly List<Dropdown.OptionData> sortOptions = new List<Dropdown.OptionData>();
|
||||
private Coroutine rebuildRoutine;
|
||||
private BagCategory currentCategory = BagCategory.All;
|
||||
private BagFilterMode currentFilterMode = BagFilterMode.All;
|
||||
private BagSortMode currentSortMode = BagSortMode.Default;
|
||||
private GameObject spawnedIntroduction;
|
||||
private uBagItemPrefab activePreviewSource;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
InitializeToggleGroup();
|
||||
InitializeFilterDropdowns();
|
||||
BindToggles();
|
||||
BindFilterDropdowns();
|
||||
BindLedgerEvents();
|
||||
InitializeViewMode();
|
||||
SelectDefaultCategory();
|
||||
@@ -109,7 +135,9 @@ public class uBag : MonoBehaviour
|
||||
private void OnEnable()
|
||||
{
|
||||
InitializeToggleGroup();
|
||||
InitializeFilterDropdowns();
|
||||
BindToggles();
|
||||
BindFilterDropdowns();
|
||||
BindLedgerEvents();
|
||||
InitializeViewMode();
|
||||
Rebuild();
|
||||
@@ -122,6 +150,8 @@ public class uBag : MonoBehaviour
|
||||
UnbindToggle(preciousToggle, HandlePreciousChanged);
|
||||
UnbindToggle(otherToggle, HandleOtherChanged);
|
||||
UnbindToggle(equipSystemToggle, HandleEquipSystemChanged);
|
||||
UnbindDropdown(bag_filterDropdown, HandleFilterDropdownChanged);
|
||||
UnbindDropdown(bag_sortDropdown, HandleSortDropdownChanged);
|
||||
UnbindLedgerEvents();
|
||||
HideCurrentPreview();
|
||||
}
|
||||
@@ -164,6 +194,89 @@ public class uBag : MonoBehaviour
|
||||
RebindToggle(equipSystemToggle, HandleEquipSystemChanged);
|
||||
}
|
||||
|
||||
private void InitializeFilterDropdowns()
|
||||
{
|
||||
InitializeFilterDropdown(bag_filterDropdown, filterOptions, new[]
|
||||
{
|
||||
"全部",
|
||||
"培养",
|
||||
"珍贵",
|
||||
"其他"
|
||||
});
|
||||
|
||||
InitializeFilterDropdown(bag_sortDropdown, sortOptions, new[]
|
||||
{
|
||||
"默认",
|
||||
"名称",
|
||||
"稀有度",
|
||||
"数量"
|
||||
});
|
||||
}
|
||||
|
||||
private void InitializeFilterDropdown(Dropdown dropdown, List<Dropdown.OptionData> cache, string[] labels)
|
||||
{
|
||||
if (dropdown == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool wasActive = dropdown.gameObject.activeInHierarchy;
|
||||
cache.Clear();
|
||||
for (int i = 0; i < labels.Length; i++)
|
||||
{
|
||||
cache.Add(new Dropdown.OptionData(labels[i]));
|
||||
}
|
||||
|
||||
dropdown.ClearOptions();
|
||||
dropdown.AddOptions(cache);
|
||||
if (dropdown.value < 0 || dropdown.value >= labels.Length)
|
||||
{
|
||||
dropdown.value = 0;
|
||||
}
|
||||
dropdown.RefreshShownValue();
|
||||
dropdown.gameObject.SetActive(wasActive);
|
||||
}
|
||||
|
||||
private void BindFilterDropdowns()
|
||||
{
|
||||
RebindDropdown(bag_filterDropdown, HandleFilterDropdownChanged);
|
||||
RebindDropdown(bag_sortDropdown, HandleSortDropdownChanged);
|
||||
}
|
||||
|
||||
private void RebindDropdown(Dropdown dropdown, UnityAction<int> action)
|
||||
{
|
||||
if (dropdown == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
dropdown.onValueChanged.RemoveListener(action);
|
||||
dropdown.onValueChanged.AddListener(action);
|
||||
}
|
||||
|
||||
private void UnbindDropdown(Dropdown dropdown, UnityAction<int> action)
|
||||
{
|
||||
if (dropdown == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
dropdown.onValueChanged.RemoveListener(action);
|
||||
}
|
||||
|
||||
private void HandleFilterDropdownChanged(int value)
|
||||
{
|
||||
currentFilterMode = (BagFilterMode)Mathf.Clamp(value, 0, 3);
|
||||
currentCategory = (BagCategory)currentFilterMode;
|
||||
Rebuild();
|
||||
}
|
||||
|
||||
private void HandleSortDropdownChanged(int value)
|
||||
{
|
||||
currentSortMode = (BagSortMode)Mathf.Clamp(value, 0, 3);
|
||||
Rebuild();
|
||||
}
|
||||
|
||||
private void RebindToggle(Toggle toggle, UnityAction<bool> action)
|
||||
{
|
||||
if (toggle == null)
|
||||
@@ -260,6 +373,12 @@ public class uBag : MonoBehaviour
|
||||
private void ApplyCategory(BagCategory category)
|
||||
{
|
||||
currentCategory = category;
|
||||
currentFilterMode = (BagFilterMode)category;
|
||||
if (bag_filterDropdown != null)
|
||||
{
|
||||
bag_filterDropdown.SetValueWithoutNotify((int)currentFilterMode);
|
||||
bag_filterDropdown.RefreshShownValue();
|
||||
}
|
||||
SetToggleInteractable(allToggle, category != BagCategory.All);
|
||||
SetToggleInteractable(cultivateToggle, category != BagCategory.Cultivation);
|
||||
SetToggleInteractable(preciousToggle, category != BagCategory.Precious);
|
||||
@@ -416,6 +535,7 @@ public class uBag : MonoBehaviour
|
||||
AddNotebookPreciousEntries();
|
||||
AddOwnedStorePreciousEntries(storeItems);
|
||||
allEntries.Sort(CompareEntries);
|
||||
ApplySortMode(allEntries);
|
||||
}
|
||||
|
||||
private void AddExpBottleEntries(List<storeItemSO> storeItems)
|
||||
@@ -662,9 +782,50 @@ public class uBag : MonoBehaviour
|
||||
result.Add(entry);
|
||||
}
|
||||
|
||||
ApplySortMode(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void ApplySortMode(List<BagEntry> entries)
|
||||
{
|
||||
if (entries == null || entries.Count <= 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (currentSortMode)
|
||||
{
|
||||
case BagSortMode.Name:
|
||||
entries.Sort((left, right) => string.CompareOrdinal(
|
||||
left != null ? left.displayName : string.Empty,
|
||||
right != null ? right.displayName : string.Empty));
|
||||
break;
|
||||
case BagSortMode.Rarity:
|
||||
entries.Sort((left, right) =>
|
||||
{
|
||||
int rarityResult = (left != null ? left.rarity : ItemRarity.None).CompareTo(right != null ? right.rarity : ItemRarity.None);
|
||||
if (rarityResult != 0) return rarityResult;
|
||||
return CompareEntries(left, right);
|
||||
});
|
||||
break;
|
||||
case BagSortMode.Count:
|
||||
entries.Sort((left, right) =>
|
||||
{
|
||||
int leftCount = ParseSafeInt(left != null ? left.amountText : null);
|
||||
int rightCount = ParseSafeInt(right != null ? right.amountText : null);
|
||||
int countResult = rightCount.CompareTo(leftCount);
|
||||
if (countResult != 0) return countResult;
|
||||
return CompareEntries(left, right);
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static int ParseSafeInt(string value)
|
||||
{
|
||||
return int.TryParse(value, out int parsed) ? parsed : 0;
|
||||
}
|
||||
|
||||
private uBagItemPrefab SpawnEntry(BagEntry entry)
|
||||
{
|
||||
if (entry == null || itemPrefab == null || itemParent == null)
|
||||
|
||||
Reference in New Issue
Block a user