Make icon kit into a popup
This commit is contained in:
6 files changed
+11290
-11851
No files matched your search
@@ -0,0 +1,216 @@
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using TMPro;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class IconkitPrefab : MonoBehaviour {
|
||||
[SerializeField] private GameObject iconsPanel;
|
||||
[SerializeField] private GameObject overlaysPanel;
|
||||
[SerializeField] private GameObject marketplaceIconsPanel;
|
||||
[SerializeField] private GameObject marketplaceIconsContent;
|
||||
[SerializeField] private GameObject marketplaceIconsSample;
|
||||
[SerializeField] private Sprite defaultIcon;
|
||||
[SerializeField] private Button backButton;
|
||||
[SerializeField] private Button placeholderButton;
|
||||
[SerializeField] private TMP_Text selectionText;
|
||||
[SerializeField] private Image previewBird;
|
||||
[SerializeField] private Image previewOverlay;
|
||||
[SerializeField] private Button[] icons;
|
||||
[SerializeField] private Button[] overlays;
|
||||
[SerializeField] private GameObject previewBirdObject;
|
||||
[SerializeField] private ColorPanel iconColorPanel;
|
||||
[SerializeField] private ColorPanel overlayColorPanel;
|
||||
private readonly Dictionary<string, Button> customIcons = new();
|
||||
|
||||
private void Start() {
|
||||
var customIconData = BazookaManager.Instance.GetCustomBirdIconData();
|
||||
foreach (var icon in customIconData.Purchased) {
|
||||
var iconEntry = Instantiate(marketplaceIconsSample, marketplaceIconsContent.transform);
|
||||
iconEntry.name = "MarketplaceIcon";
|
||||
var button = iconEntry.GetComponent<Button>();
|
||||
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);
|
||||
iconColorPanel.OnColorChanged += color => {
|
||||
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 => {
|
||||
BazookaManager.Instance.SetColorSettingOverlay(color);
|
||||
foreach (var overlay in overlays) {
|
||||
var img = overlay.transform.GetChild(0).TryGetComponent<Image>(out var image) ? image : null;
|
||||
if (img == null) continue;
|
||||
|
||||
img.color = new Color(
|
||||
int.Parse(color[0].ToString()) / 255f,
|
||||
int.Parse(color[1].ToString()) / 255f,
|
||||
int.Parse(color[2].ToString()) / 255f
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
if (customIconData.Selected == null) {
|
||||
defaultIcon = Tools.GetIconForUser(BazookaManager.Instance.GetAccountID() ?? 0);
|
||||
icons[0].transform.GetChild(0).GetComponent<Image>().sprite = defaultIcon;
|
||||
|
||||
SwitchToIcon();
|
||||
SelectOverlay(BazookaManager.Instance.GetBirdOverlay());
|
||||
SelectIcon(BazookaManager.Instance.GetBirdIcon());
|
||||
|
||||
if (BazookaManager.Instance.GetBirdIcon() == 7) {
|
||||
SelectOverlay(0);
|
||||
placeholderButton.interactable = false;
|
||||
}
|
||||
} else SwitchToMarketplaceIcons();
|
||||
placeholderButton.onClick.AddListener(ToggleKit);
|
||||
previewBird.GetComponentInParent<Button>().onClick.AddListener(() => {
|
||||
var scale = previewBird.transform.localScale;
|
||||
scale.x = scale.x == -1 ? 1 : -1;
|
||||
previewBird.transform.localScale = scale;
|
||||
});
|
||||
for (int i = 0; i < icons.Length; i++) {
|
||||
int index = i;
|
||||
icons[i].onClick.AddListener(() => SelectIcon(index + 1));
|
||||
}
|
||||
for (int i = 0; i < overlays.Length; i++) {
|
||||
int index = i;
|
||||
overlays[i].onClick.AddListener(() => SelectOverlay(index));
|
||||
}
|
||||
backButton.onClick.AddListener(() => Destroy(gameObject));
|
||||
}
|
||||
|
||||
private void SwitchToIcon() {
|
||||
iconsPanel.SetActive(true);
|
||||
overlaysPanel.SetActive(false);
|
||||
marketplaceIconsPanel.SetActive(false);
|
||||
selectionText.text = "Icon selection";
|
||||
placeholderButton.GetComponentInChildren<TMP_Text>().text = "Overlays";
|
||||
iconColorPanel.gameObject.SetActive(true);
|
||||
overlayColorPanel.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
private void SwitchToOverlay() {
|
||||
iconsPanel.SetActive(false);
|
||||
overlaysPanel.SetActive(true);
|
||||
marketplaceIconsPanel.SetActive(false);
|
||||
selectionText.text = "Overlay selection";
|
||||
placeholderButton.GetComponentInChildren<TMP_Text>().text = "Marketplace";
|
||||
}
|
||||
|
||||
private void SwitchToMarketplaceIcons() {
|
||||
iconsPanel.SetActive(false);
|
||||
overlaysPanel.SetActive(false);
|
||||
marketplaceIconsPanel.SetActive(true);
|
||||
selectionText.text = "Marketplace Icons selection";
|
||||
placeholderButton.GetComponentInChildren<TMP_Text>().text = "Icons";
|
||||
iconColorPanel.gameObject.SetActive(false);
|
||||
overlayColorPanel.gameObject.SetActive(false);
|
||||
var customIconData = BazookaManager.Instance.GetCustomBirdIconData();
|
||||
foreach (var btn in customIcons.Values) btn.interactable = true;
|
||||
if (customIconData.Selected != null)
|
||||
foreach (var icon in customIconData.Purchased) {
|
||||
if (icon == customIconData.Selected) SelectCustomIcon(icon, false);
|
||||
customIcons[icon].interactable = icon != customIconData.Selected;
|
||||
}
|
||||
|
||||
RenderIcons();
|
||||
}
|
||||
|
||||
private void ToggleKit() {
|
||||
if (GetCurrentKit() == 1) SwitchToOverlay();
|
||||
else if (GetCurrentKit() == 2) SwitchToMarketplaceIcons();
|
||||
else if (GetCurrentKit() == 3) {
|
||||
defaultIcon = Tools.GetIconForUser(BazookaManager.Instance.GetAccountID() ?? 0);
|
||||
icons[0].transform.GetChild(0).GetComponent<Image>().sprite = defaultIcon;
|
||||
|
||||
SwitchToIcon();
|
||||
SelectOverlay(BazookaManager.Instance.GetBirdOverlay());
|
||||
SelectIcon(BazookaManager.Instance.GetBirdIcon());
|
||||
iconColorPanel.SetColor(BazookaManager.Instance.GetColorSettingIcon());
|
||||
overlayColorPanel.SetColor(BazookaManager.Instance.GetColorSettingOverlay());
|
||||
|
||||
if (BazookaManager.Instance.GetBirdIcon() == 7) {
|
||||
SelectOverlay(0);
|
||||
placeholderButton.interactable = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int GetCurrentKit() {
|
||||
if (iconsPanel.activeSelf) return 1;
|
||||
else if (overlaysPanel.activeSelf) return 2;
|
||||
else if (marketplaceIconsPanel.activeSelf) return 3;
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void SelectIcon(int iconID) {
|
||||
var customData = BazookaManager.Instance.GetCustomBirdIconData();
|
||||
customData.Selected = null;
|
||||
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 == 7) {
|
||||
SelectOverlay(0);
|
||||
placeholderButton.interactable = false;
|
||||
} else placeholderButton.interactable = true;
|
||||
}
|
||||
|
||||
private void SelectOverlay(int overlayID) {
|
||||
var customData = BazookaManager.Instance.GetCustomBirdIconData();
|
||||
customData.Selected = null;
|
||||
BazookaManager.Instance.SetCustomBirdIconData(customData);
|
||||
BazookaManager.Instance.SetBirdOverlay(overlayID);
|
||||
for (int i = 0; i < overlays.Length; i++) {
|
||||
overlays[i].interactable = overlayID != i;
|
||||
}
|
||||
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 == 0) {
|
||||
previewOverlay.gameObject.SetActive(false);
|
||||
previewOverlay.sprite = null;
|
||||
} else previewOverlay.sprite = Resources.Load<Sprite>("Icons/Overlays/overlay_" + overlayID);
|
||||
}
|
||||
|
||||
void SelectCustomIcon(string icon, bool renderIcons = true) {
|
||||
var customData = BazookaManager.Instance.GetCustomBirdIconData();
|
||||
customData.Selected = icon;
|
||||
BazookaManager.Instance.SetCustomBirdIconData(customData);
|
||||
previewBird.AddComponent<WaitingForCustomIcon>().ID = icon;
|
||||
if (renderIcons) RenderIcons();
|
||||
previewBird.color = Color.white;
|
||||
previewOverlay.gameObject.SetActive(false);
|
||||
previewOverlay.sprite = null;
|
||||
previewOverlay.color = Color.white;
|
||||
foreach (var loopIcon in customData.Purchased) {
|
||||
customIcons[loopIcon].interactable = loopIcon != icon;
|
||||
}
|
||||
}
|
||||
|
||||
void Update() {
|
||||
if (Keyboard.current.escapeKey.wasPressedThisFrame && backButton.interactable) backButton.onClick.Invoke();
|
||||
}
|
||||
|
||||
void RenderIcons() {
|
||||
var objects = FindObjectsByType<WaitingForCustomIcon>(FindObjectsSortMode.None);
|
||||
if (objects.Length != 0) CustomIconLoader.Init(objects);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 81b945b4d081ffb46aa748002fbc6560
|
||||
Reference in new issue
Block a user