New custom icon system (not fully done yet)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using TMPro;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.SceneManagement;
|
||||
@@ -20,25 +21,22 @@ public class Iconsmenu : MonoBehaviour
|
||||
[SerializeField] private Image previewOverlay;
|
||||
[SerializeField] private Button[] icons;
|
||||
[SerializeField] private Button[] overlays;
|
||||
private Dictionary<string, Button> customIcons = new();
|
||||
[SerializeField] private GameObject previewBirdObject;
|
||||
[SerializeField] private ColorPanel iconColorPanel;
|
||||
[SerializeField] private ColorPanel overlayColorPanel;
|
||||
private Dictionary<string, Button> customIcons = new();
|
||||
|
||||
private void Start()
|
||||
{
|
||||
var customIconData = BazookaManager.Instance.GetCustomBirdIconData();
|
||||
foreach (var icon in customIconData.Data)
|
||||
foreach (var icon in customIconData.Purchased)
|
||||
{
|
||||
var iconEntry = Instantiate(marketplaceIconsSample, marketplaceIconsContent.transform);
|
||||
iconEntry.name = "MarketplaceIcon";
|
||||
var button = iconEntry.GetComponent<Button>();
|
||||
customIcons[icon.UUID] = button;
|
||||
button.onClick.AddListener(() =>
|
||||
{
|
||||
SelectCustomIcon(icon);
|
||||
});
|
||||
Tools.RenderFromBase64(icon.Data, iconEntry.transform.GetChild(0).GetComponent<Image>());
|
||||
customIcons[icon] = button;
|
||||
button.onClick.AddListener(() => SelectCustomIcon(icon));
|
||||
iconEntry.transform.GetChild(0).AddComponent<WaitingForCustomIcon>().ID = icon;
|
||||
iconEntry.SetActive(true);
|
||||
}
|
||||
iconColorPanel.Init(customIconData.Selected == null ? BazookaManager.Instance.GetColorSettingIcon() : JArray.Parse("[255,255,255]"), Color.white);
|
||||
@@ -46,13 +44,11 @@ public class Iconsmenu : MonoBehaviour
|
||||
{
|
||||
BazookaManager.Instance.SetColorSettingIcon(color);
|
||||
foreach (var icon in icons)
|
||||
{
|
||||
icon.transform.GetChild(0).GetComponent<Image>().color = new Color(
|
||||
int.Parse(color[0].ToString()) / 255f,
|
||||
int.Parse(color[1].ToString()) / 255f,
|
||||
int.Parse(color[2].ToString()) / 255f
|
||||
);
|
||||
}
|
||||
};
|
||||
overlayColorPanel.Init(customIconData.Selected == null ? BazookaManager.Instance.GetColorSettingOverlay() : JArray.Parse("[255,255,255]"), Color.white);
|
||||
overlayColorPanel.OnColorChanged += color =>
|
||||
@@ -86,22 +82,12 @@ public class Iconsmenu : MonoBehaviour
|
||||
placeholderButton.interactable = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SwitchToMarketplaceIcons();
|
||||
}
|
||||
else SwitchToMarketplaceIcons();
|
||||
placeholderButton.onClick.AddListener(ToggleKit);
|
||||
previewBird.GetComponentInParent<Button>().onClick.AddListener(() =>
|
||||
{
|
||||
var scale = previewBird.transform.localScale;
|
||||
if (scale.x == -1)
|
||||
{
|
||||
scale.x = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
scale.x = -1;
|
||||
}
|
||||
scale.x = scale.x == -1 ? 1 : -1;
|
||||
previewBird.transform.localScale = scale;
|
||||
});
|
||||
for (int i = 0; i < icons.Length; i++)
|
||||
@@ -148,28 +134,20 @@ public class Iconsmenu : MonoBehaviour
|
||||
var customIconData = BazookaManager.Instance.GetCustomBirdIconData();
|
||||
foreach (var btn in customIcons.Values) btn.interactable = true;
|
||||
if (customIconData.Selected != null)
|
||||
{
|
||||
foreach (var icon in customIconData.Data)
|
||||
foreach (var icon in customIconData.Purchased)
|
||||
{
|
||||
if (icon.UUID == customIconData.Selected)
|
||||
{
|
||||
SelectCustomIcon(icon);
|
||||
}
|
||||
customIcons[icon.UUID].interactable = icon.UUID != customIconData.Selected;
|
||||
if (icon == customIconData.Selected) SelectCustomIcon(icon);
|
||||
customIcons[icon].interactable = icon != customIconData.Selected;
|
||||
}
|
||||
}
|
||||
|
||||
var objects = FindObjectsByType<WaitingForCustomIcon>(FindObjectsSortMode.None);
|
||||
if (objects.Length != 0) CustomIconLoader.Init(objects);
|
||||
}
|
||||
|
||||
private void ToggleKit()
|
||||
{
|
||||
if (GetCurrentKit() == 1)
|
||||
{
|
||||
SwitchToOverlay();
|
||||
}
|
||||
else if (GetCurrentKit() == 2)
|
||||
{
|
||||
SwitchToMarketplaceIcons();
|
||||
}
|
||||
if (GetCurrentKit() == 1) SwitchToOverlay();
|
||||
else if (GetCurrentKit() == 2) SwitchToMarketplaceIcons();
|
||||
else if (GetCurrentKit() == 3)
|
||||
{
|
||||
defaultIcon = Tools.GetIconForUser(BazookaManager.Instance.GetAccountID() ?? 0);
|
||||
@@ -191,18 +169,9 @@ public class Iconsmenu : MonoBehaviour
|
||||
|
||||
private int GetCurrentKit()
|
||||
{
|
||||
if (iconsPanel.activeSelf)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (overlaysPanel.activeSelf)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
if (marketplaceIconsPanel.activeSelf)
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
if (iconsPanel.activeSelf) return 1;
|
||||
else if (overlaysPanel.activeSelf) return 2;
|
||||
else if (marketplaceIconsPanel.activeSelf) return 3;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -213,23 +182,15 @@ public class Iconsmenu : MonoBehaviour
|
||||
BazookaManager.Instance.SetCustomBirdIconData(customData);
|
||||
BazookaManager.Instance.SetBirdIcon(iconID);
|
||||
for (int i = 0; i < icons.Length; i++)
|
||||
{
|
||||
icons[i].interactable = iconID != i + 1;
|
||||
}
|
||||
previewBird.sprite = Resources.Load<Sprite>("Icons/Icons/bird_" + iconID);
|
||||
if (iconID == 1)
|
||||
{
|
||||
previewBird.sprite = defaultIcon;
|
||||
}
|
||||
if (iconID == 1) previewBird.sprite = defaultIcon;
|
||||
if (iconID == 7)
|
||||
{
|
||||
SelectOverlay(0);
|
||||
placeholderButton.interactable = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
placeholderButton.interactable = true;
|
||||
}
|
||||
else placeholderButton.interactable = true;
|
||||
}
|
||||
|
||||
private void SelectOverlay(int overlayID)
|
||||
@@ -244,43 +205,33 @@ public class Iconsmenu : MonoBehaviour
|
||||
}
|
||||
previewOverlay.rectTransform.localPosition = new Vector3(-32f, 44.50001f, 0f);
|
||||
previewOverlay.gameObject.SetActive(true);
|
||||
if (overlayID == 8)
|
||||
{
|
||||
previewOverlay.rectTransform.localPosition = new Vector3(-35.36f, 31.6f, 0f);
|
||||
}
|
||||
else if (overlayID == 11)
|
||||
{
|
||||
previewOverlay.rectTransform.localPosition = new Vector3(-31.44f, 43.50004f, 0f);
|
||||
}
|
||||
else if (overlayID == 13)
|
||||
{
|
||||
previewOverlay.rectTransform.localPosition = new Vector3(-35.28575f, 31.3667f, 0f);
|
||||
}
|
||||
if (overlayID == 8) previewOverlay.rectTransform.localPosition = new Vector3(-35.36f, 31.6f, 0f);
|
||||
else if (overlayID == 11) previewOverlay.rectTransform.localPosition = new Vector3(-31.44f, 43.50004f, 0f);
|
||||
else if (overlayID == 13) previewOverlay.rectTransform.localPosition = new Vector3(-35.28575f, 31.3667f, 0f);
|
||||
|
||||
if (overlayID == 0)
|
||||
{
|
||||
previewOverlay.gameObject.SetActive(false);
|
||||
previewOverlay.sprite = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
previewOverlay.sprite = Resources.Load<Sprite>("Icons/Overlays/overlay_" + overlayID);
|
||||
}
|
||||
else previewOverlay.sprite = Resources.Load<Sprite>("Icons/Overlays/overlay_" + overlayID);
|
||||
}
|
||||
|
||||
void SelectCustomIcon(MarketplaceIconType icon)
|
||||
void SelectCustomIcon(string icon)
|
||||
{
|
||||
var customData = BazookaManager.Instance.GetCustomBirdIconData();
|
||||
customData.Selected = icon.UUID;
|
||||
customData.Selected = icon;
|
||||
BazookaManager.Instance.SetCustomBirdIconData(customData);
|
||||
Tools.RenderFromBase64(icon.Data, previewBird);
|
||||
var waitingForCustomIcon = previewBird.AddComponent<WaitingForCustomIcon>();
|
||||
waitingForCustomIcon.ID = icon;
|
||||
CustomIconLoader.Init(new[] { waitingForCustomIcon });
|
||||
previewBird.color = Color.white;
|
||||
previewOverlay.gameObject.SetActive(false);
|
||||
previewOverlay.sprite = null;
|
||||
previewOverlay.color = Color.white;
|
||||
foreach (var loopIcon in customData.Data)
|
||||
foreach (var loopIcon in customData.Purchased)
|
||||
{
|
||||
customIcons[loopIcon.UUID].interactable = loopIcon.UUID != icon.UUID;
|
||||
customIcons[loopIcon].interactable = loopIcon != icon;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user