using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using DarkTonic.MasterAudio;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

// Token: 0x020000A0 RID: 160
public class CreationSkills : MonoBehaviour
{
	// Token: 0x06000F17 RID: 3863 RVA: 0x00125B5C File Offset: 0x00123D5C
	private void Start()
	{
	}

	// Token: 0x06000F18 RID: 3864 RVA: 0x00125B5E File Offset: 0x00123D5E
	private void OnDisable()
	{
		this.openNum = -1;
		this.currentIndex = -1;
		this.confirming = false;
		this.savingSpell = false;
	}

	// Token: 0x06000F19 RID: 3865 RVA: 0x00125B7C File Offset: 0x00123D7C
	public void OpenMenuFromButton(Creation creationMenu, string clickedSkill, Character currCharacter)
	{
		this.arrayCount = this.textureSize * this.textureSize;
		this.creation = creationMenu;
		this.creation.animator.Play("CreationSpellsOpen");
		this.currentIndex = -1;
		for (int i = 0; i < this.characterOrder.Count; i++)
		{
			if (this.characterOrder[i] == currCharacter && clickedSkill == this.skillOrder[i])
			{
				this.currentIndex = i;
				break;
			}
		}
		this.opened = true;
		this.StartNewChoice();
	}

	// Token: 0x06000F1A RID: 3866 RVA: 0x00125C14 File Offset: 0x00123E14
	public void OpenMenu(Creation creationMenu)
	{
		this.arrayCount = this.textureSize * this.textureSize;
		this.creation = creationMenu;
		this.creation.animator.Play("CreationSpellsOpen");
		this.currentIndex = 0;
		this.opened = true;
		this.StartNewChoice();
	}

	// Token: 0x06000F1B RID: 3867 RVA: 0x00125C64 File Offset: 0x00123E64
	private void Update()
	{
		if (this.spells && this.backButton.interactable)
		{
			if (Time.realtimeSinceStartup > this.fillUpdateTime + 0.25f && this.character)
			{
				this.incompleteFillCount++;
				if (this.incompleteFillCount > 3)
				{
					this.incompleteFillCount = 0;
				}
				for (int i = 0; i < this.scrollCount; i++)
				{
					if (this.fillStatus[i] == 1)
					{
						this.CheckSpellFillStatus(i, true);
						if (this.fillStatus[i] == 1)
						{
							if (this.incompleteFillCount == 0)
							{
								this.scrollFills[i].sprite = this.scrollFillSpellsNotComplete4;
							}
							if (this.incompleteFillCount == 3)
							{
								this.scrollFills[i].sprite = this.scrollFillSpellsNotComplete3;
							}
							if (this.incompleteFillCount == 2)
							{
								this.scrollFills[i].sprite = this.scrollFillSpellsNotComplete2;
							}
							if (this.incompleteFillCount == 1)
							{
								this.scrollFills[i].sprite = this.scrollFillSpellsNotComplete1;
							}
						}
					}
				}
				this.fillUpdateTime = Time.realtimeSinceStartup;
			}
			else
			{
				for (int j = 0; j < this.scrollCount; j++)
				{
					if (this.fillStatus[j] == 1)
					{
						this.CheckSpellFillStatus(j, true);
					}
				}
			}
		}
		if (Time.realtimeSinceStartup > this.updateTime + 0.15f && this.character)
		{
			this.updateTime = Time.realtimeSinceStartup;
			this.currIndex++;
			if (this.currIndex > 4)
			{
				this.currIndex = 0;
			}
			this.portrait.texture = this.character.characterSheetPortrait.GetTextureIdle(this.currIndex);
		}
	}

	// Token: 0x06000F1C RID: 3868 RVA: 0x00125E30 File Offset: 0x00124030
	public void StartNewChoice()
	{
		if (this.currentIndex < this.skillOrder.Count)
		{
			this.newSelection = false;
			this.openNum = -1;
			this.character = this.characterOrder[this.currentIndex];
			this.currentSkill = this.skillOrder[this.currentIndex];
			this.spells = false;
			this.words = false;
			this.songs = false;
			this.maxSelections = this.GetMaxSelections(this.currentSkill, this.skillType[this.currentIndex]);
			if (this.currentSkill == "Vines" || this.currentSkill == "Fauna" || this.currentSkill == "Spores")
			{
				this.spells = true;
				if (this.currentSkill == "Vines")
				{
					this.drawImage.material = this.vines;
				}
				if (this.currentSkill == "Fauna")
				{
					this.drawImage.material = this.fauna;
				}
				if (this.currentSkill == "Spores")
				{
					this.drawImage.material = this.spores;
				}
			}
			if (this.currentSkill == "Melee" || this.currentSkill == "Range" || this.currentSkill == "Defense")
			{
				this.words = true;
			}
			if (this.currentSkill == "Horn" || this.currentSkill == "Flute" || this.currentSkill == "Drum")
			{
				this.songs = true;
			}
			for (int i = 0; i < 6; i++)
			{
				if (i < this.scrollCount)
				{
					this.scrollMainImages[i].gameObject.transform.parent.SetParent(this.usedScrolls, true);
				}
				else
				{
					this.scrollMainImages[i].gameObject.transform.parent.SetParent(this.unusedScrolls, true);
				}
				this.SetScrollStateAll(true, i);
			}
			this.str.Clear();
			if (this.character.stats.displayName != "")
			{
				this.str.Append(this.character.stats.displayName);
				this.str.Append("'s ");
			}
			this.str.Append(Links.x.manual.DisplayName(this.currentSkill));
			this.title.text = this.str.ToString();
			this.str.Clear();
			this.str.Append("Select ");
			if (this.maxSelections == 3)
			{
				this.str.Append("three");
			}
			else if (this.maxSelections == 2)
			{
				this.str.Append("two");
			}
			else
			{
				this.str.Append("one");
			}
			if (this.songs)
			{
				this.str.Append(" song");
			}
			if (this.words)
			{
				this.str.Append(" word");
			}
			if (this.spells)
			{
				this.str.Append(" spell");
			}
			if (this.maxSelections > 1)
			{
				this.str.Append("s");
			}
			this.message.text = this.str.ToString();
			foreach (Image image in this.scrollFills)
			{
				if (this.songs)
				{
					image.sprite = this.scrollFillSongs;
				}
				if (this.words)
				{
					image.sprite = this.scrollFillWords;
				}
				if (this.spells)
				{
					image.sprite = this.scrollFillSpells;
				}
				image.enabled = false;
			}
			if (this.spells)
			{
				this.ResetDrawings();
			}
			for (int j = 0; j < this.scrollCount; j++)
			{
				this.fillStatus[j] = 0;
				if (this.spells)
				{
					bool flag = false;
					if (this.characterLearned1[this.currentIndex] == j)
					{
						flag = true;
					}
					if (this.characterLearned2[this.currentIndex] == j)
					{
						flag = true;
					}
					if (this.characterLearned3[this.currentIndex] == j)
					{
						flag = true;
					}
					if (flag)
					{
						this.fillStatus[j] = 1;
						this.CheckSpellFillStatus(j, false);
						if (this.fillStatus[j] == 1)
						{
							if (this.incompleteFillCount == 0)
							{
								this.scrollFills[j].sprite = this.scrollFillSpellsNotComplete4;
							}
							if (this.incompleteFillCount == 3)
							{
								this.scrollFills[j].sprite = this.scrollFillSpellsNotComplete3;
							}
							if (this.incompleteFillCount == 2)
							{
								this.scrollFills[j].sprite = this.scrollFillSpellsNotComplete2;
							}
							if (this.incompleteFillCount == 1)
							{
								this.scrollFills[j].sprite = this.scrollFillSpellsNotComplete1;
							}
						}
					}
				}
				else
				{
					bool flag2 = false;
					if (this.characterLearned1[this.currentIndex] == j)
					{
						flag2 = true;
					}
					if (this.characterLearned2[this.currentIndex] == j)
					{
						flag2 = true;
					}
					if (this.characterLearned3[this.currentIndex] == j)
					{
						flag2 = true;
					}
					if (flag2)
					{
						this.fillStatus[j] = 2;
					}
				}
			}
			int num = 0;
			if (this.characterLearned1[this.currentIndex] > -1)
			{
				num++;
			}
			if (this.characterLearned2[this.currentIndex] > -1)
			{
				num++;
			}
			if (this.characterLearned3[this.currentIndex] > -1)
			{
				num++;
			}
			int num2 = 0;
			for (int k = 0; k < this.scrollCount; k++)
			{
				if (this.fillStatus[k] == 2)
				{
					num2++;
				}
			}
			Debug.Log(string.Concat(new string[]
			{
				num2.ToString(),
				" ",
				num.ToString(),
				" ",
				this.maxSelections.ToString()
			}));
			for (int l = 0; l < this.scrollCount; l++)
			{
				if (num < this.maxSelections || num2 < this.maxSelections)
				{
					this.SetScrollState(true, l);
					if (this.characterLearned1[this.currentIndex] == l || this.characterLearned2[this.currentIndex] == l || this.characterLearned3[this.currentIndex] == l)
					{
						this.scrollFills[l].enabled = true;
					}
				}
				else if (this.characterLearned1[this.currentIndex] == l || this.characterLearned2[this.currentIndex] == l || this.characterLearned3[this.currentIndex] == l)
				{
					this.SetScrollState(true, l);
					this.scrollFills[l].enabled = true;
				}
				else
				{
					this.SetScrollState(false, l);
				}
			}
			this.skillNames.Clear();
			this.skillAbilities.Clear();
			for (int m = 0; m < this.scrollCount; m++)
			{
				string abilityName = this.GetAbilityName(this.currentSkill, m);
				this.skillNames.Add(abilityName);
				this.skillAbilities.Add(Links.x.library.GetAbilityRow(abilityName));
			}
			for (int n = 0; n < this.scrollCount; n++)
			{
				this.scrollTitles[n].text = this.skillAbilities[n]._DisplayName;
			}
			for (int num3 = 0; num3 < this.scrollCount; num3++)
			{
				this.scrollTitles[num3].color = this.selectedText;
			}
			this.nextButton.interactable = false;
			this.backButton.interactable = true;
			this.GetButtonText(false);
		}
	}

	// Token: 0x06000F1D RID: 3869 RVA: 0x0012667C File Offset: 0x0012487C
	public void SaveAll()
	{
		this.runesSaved.Clear();
		for (int i = 0; i < this.characterOrder.Count; i++)
		{
			this.spells = false;
			this.songs = false;
			this.words = false;
			this.currentSkill = this.skillOrder[i];
			if (this.currentSkill == "Vines" || this.currentSkill == "Fauna" || this.currentSkill == "Spores")
			{
				this.spells = true;
			}
			if (this.currentSkill == "Melee" || this.currentSkill == "Range" || this.currentSkill == "Defense")
			{
				this.words = true;
			}
			if (this.currentSkill == "Horn" || this.currentSkill == "Flute" || this.currentSkill == "Drum")
			{
				this.songs = true;
			}
			bool flag = false;
			string text = this.skillOrder[i];
			if (this.skillType[i] == "Major" && this.characterOrder[i].stats.HasTokenInSkill(text, true, false))
			{
				flag = true;
			}
			if (this.skillType[i] == "Minor" && this.characterOrder[i].stats.HasTokenInSkill(text, false, true))
			{
				flag = true;
			}
			if (flag)
			{
				for (int j = 0; j < this.scrollCount; j++)
				{
					if (this.characterLearned1[i] == j || this.characterLearned2[i] == j || this.characterLearned3[i] == j)
					{
						string abilityName = this.GetAbilityName(this.currentSkill, j);
						string text2 = "Saving ";
						string text3 = abilityName;
						string text4 = " for ";
						Character character = this.characterOrder[i];
						Debug.Log(text2 + text3 + text4 + ((character != null) ? character.ToString() : null));
						if (this.spells)
						{
							Library.Abilities abilityRow = Links.x.library.GetAbilityRow(abilityName);
							string spellName = this.GetSpellName(abilityRow);
							string text5 = string.Concat(new string[]
							{
								Application.persistentDataPath,
								"/AutoSave/",
								spellName,
								"_",
								this.characterOrder[i].stats.partyID.ToString(),
								".png"
							});
							this.runesSaved.Add(text5);
							this.selectedPagan = Links.x.library.GetPaganRow(abilityName);
							Links.x.spellcrafting.selectedPagan = this.selectedPagan;
							Links.x.spellcrafting.SelectLearningButton(-1);
							this.characterOrder[i].stats.SaveSpell(this.selectedPagan._ID, spellName, (int)Links.x.spellcrafting.slider1.value, (int)Links.x.spellcrafting.slider2.value, (int)Links.x.spellcrafting.slider3.value, (int)Links.x.spellcrafting.tetherSlider.value, new Vector2(1f, 0f));
						}
						if (this.songs)
						{
							this.characterOrder[i].stats.AddSong(abilityName, abilityName, new Vector3(1f, 1f, 1f));
						}
						if (this.words)
						{
							this.characterOrder[i].stats.AddWord(abilityName, abilityName, new Vector3(1f, 1f, 1f));
						}
					}
				}
			}
			this.characterOrder[i].stats.AddSong("SummonFriend", "SummonFriend", new Vector3(1f, 1f, 1f));
		}
		string[] files = Directory.GetFiles(Application.persistentDataPath + "/AutoSave");
		for (int k = 0; k < this.runesCreated.Count; k++)
		{
			if (!this.runesSaved.Contains(this.runesCreated[k]))
			{
				foreach (string text6 in files)
				{
					if (text6 == this.runesCreated[k])
					{
						File.Delete(text6);
					}
				}
			}
		}
	}

	// Token: 0x06000F1E RID: 3870 RVA: 0x00126B03 File Offset: 0x00124D03
	public void Back()
	{
		this.confirming = true;
		this.nextButton.interactable = false;
		this.backButton.interactable = false;
		base.StartCoroutine(this.ConfirmBack());
	}

	// Token: 0x06000F1F RID: 3871 RVA: 0x00126B31 File Offset: 0x00124D31
	private IEnumerator ConfirmBack()
	{
		if (this.spells && this.openNum > -1)
		{
			this.savingSpell = true;
			base.StartCoroutine(this.SaveSpellOpenInfo());
			while (this.savingSpell)
			{
				yield return null;
			}
		}
		this.creation.SetCharacterInfo();
		this.creation.animator.Play("CreationSpellsBackToAll");
		this.creation.SetAbilityButtons(false, false);
		base.gameObject.SetActive(false);
		yield break;
	}

	// Token: 0x06000F20 RID: 3872 RVA: 0x00126B40 File Offset: 0x00124D40
	public void SelectScroll(int num)
	{
		if (!this.backButton.interactable)
		{
			return;
		}
		this.backButton.interactable = false;
		this.nextButton.interactable = false;
		base.StartCoroutine(this.OpenScrollCoroutine(num));
	}

	// Token: 0x06000F21 RID: 3873 RVA: 0x00126B76 File Offset: 0x00124D76
	private IEnumerator OpenScrollCoroutine(int num)
	{
		bool closing = false;
		if (this.spells && this.openNum > -1)
		{
			this.savingSpell = true;
			base.StartCoroutine(this.SaveSpellOpenInfo());
			while (this.savingSpell)
			{
				yield return null;
			}
		}
		if (this.creation.animator.GetCurrentAnimatorStateInfo(0).IsName("CreationSpellInfoOpen") || this.creation.animator.GetCurrentAnimatorStateInfo(0).IsName("CreationSkillInfoOpen"))
		{
			if (num == this.openNum)
			{
				closing = true;
			}
			if (closing)
			{
				if (this.spells)
				{
					this.creation.animator.Play("CreationSpellInfoClose");
				}
				else
				{
					this.creation.animator.Play("CreationSkillInfoClose");
				}
				for (int i = 0; i < this.scrollCount; i++)
				{
					this.scrollTitles[i].color = this.selectedText;
				}
				this.openNum = -1;
			}
		}
		if (!closing)
		{
			if (this.words)
			{
				this.OpenWord(num);
			}
			if (this.songs)
			{
				this.OpenSong(num);
			}
			if (this.spells)
			{
				this.OpenSpell(num);
			}
			if (!this.creation.animator.GetCurrentAnimatorStateInfo(0).IsName("CreationSpellInfoOpen") && !this.creation.animator.GetCurrentAnimatorStateInfo(0).IsName("CreationSkillInfoOpen"))
			{
				if (this.spells)
				{
					this.creation.animator.Play("CreationSpellInfoOpen");
				}
				else
				{
					this.creation.animator.Play("CreationSkillInfoOpen");
				}
			}
			for (int j = 0; j < this.scrollCount; j++)
			{
				if (j == num)
				{
					this.scrollTitles[j].color = this.selectedText;
				}
				else
				{
					this.scrollTitles[j].color = this.unselectedText;
				}
			}
		}
		if (Links.x.mk)
		{
			EventSystem.current.SetSelectedGameObject(null);
		}
		this.backButton.interactable = true;
		yield break;
	}

	// Token: 0x06000F22 RID: 3874 RVA: 0x00126B8C File Offset: 0x00124D8C
	private IEnumerator SaveSpellOpenInfo()
	{
		int num = this.arrayCount;
		if (this.characterLearned1[this.currentIndex] == this.openNum)
		{
			Color32[] pixels = this.drawingTextures[this.openNum].GetPixels32();
			Color32[] array = this.runeColors1[this.currentIndex];
			for (int i = 0; i < num; i++)
			{
				array[i] = pixels[i];
			}
		}
		if (this.characterLearned2[this.currentIndex] == this.openNum)
		{
			Color32[] pixels2 = this.drawingTextures[this.openNum].GetPixels32();
			Color32[] array2 = this.runeColors2[this.currentIndex];
			for (int j = 0; j < num; j++)
			{
				array2[j] = pixels2[j];
			}
		}
		if (this.characterLearned3[this.currentIndex] == this.openNum)
		{
			Color32[] pixels3 = this.drawingTextures[this.openNum].GetPixels32();
			Color32[] array3 = this.runeColors3[this.currentIndex];
			for (int k = 0; k < num; k++)
			{
				array3[k] = pixels3[k];
			}
		}
		string spellName = this.GetSpellName(this.openNum);
		string fileName = string.Concat(new string[]
		{
			Application.persistentDataPath,
			"/AutoSave/",
			spellName,
			"_",
			this.character.stats.partyID.ToString(),
			".png"
		});
		yield return new WaitForEndOfFrame();
		Vector3[] array4 = new Vector3[4];
		this.targetRect.GetWorldCorners(array4);
		Vector2 vector = RectTransformUtility.WorldToScreenPoint(Links.x.menuCamera, array4[0]);
		Vector2 vector2 = RectTransformUtility.WorldToScreenPoint(Links.x.menuCamera, array4[1]);
		ref Vector2 ptr = RectTransformUtility.WorldToScreenPoint(Links.x.menuCamera, array4[2]);
		int num2 = Mathf.RoundToInt(vector2.y - vector.y);
		int num3 = Mathf.RoundToInt(ptr.x - vector.x);
		Texture2D texture2D = new Texture2D(num3, num2, TextureFormat.RGB24, false);
		Rect rect = new Rect(Mathf.Round(vector.x), Mathf.Round(vector.y), (float)num3, (float)num2);
		texture2D.ReadPixels(rect, 0, 0);
		texture2D.Apply();
		if (num3 > 256)
		{
			Texture2D texture2D2 = this.ScaleTexture(texture2D, 256, 256);
			byte[] array5 = texture2D2.EncodeToPNG();
			Object.Destroy(texture2D);
			Object.Destroy(texture2D2);
			File.WriteAllBytes(fileName, array5);
		}
		else
		{
			byte[] array6 = texture2D.EncodeToPNG();
			Object.Destroy(texture2D);
			File.WriteAllBytes(fileName, array6);
		}
		if (!this.runesCreated.Contains(fileName))
		{
			this.runesCreated.Add(fileName);
		}
		this.savingSpell = false;
		yield break;
	}

	// Token: 0x06000F23 RID: 3875 RVA: 0x00126B9C File Offset: 0x00124D9C
	private Texture2D ScaleTexture(Texture2D source, int targetWidth, int targetHeight)
	{
		Texture2D texture2D = new Texture2D(targetWidth, targetHeight, source.format, true);
		Color[] pixels = texture2D.GetPixels(0);
		float num = 1f / (float)source.width * ((float)source.width / (float)targetWidth);
		float num2 = 1f / (float)source.height * ((float)source.height / (float)targetHeight);
		for (int i = 0; i < pixels.Length; i++)
		{
			pixels[i] = source.GetPixelBilinear(num * ((float)i % (float)targetWidth), num2 * Mathf.Floor((float)(i / targetWidth)));
		}
		texture2D.SetPixels(pixels, 0);
		texture2D.Apply();
		return texture2D;
	}

	// Token: 0x06000F24 RID: 3876 RVA: 0x00126C38 File Offset: 0x00124E38
	public void CheckScrollBox(int num)
	{
		if (this.backButton.interactable)
		{
			this.newSelection = true;
			if (this.scrollFills[num].enabled)
			{
				this.scrollFills[num].enabled = false;
				if (this.characterLearned1[this.currentIndex] == num)
				{
					this.characterLearned1[this.currentIndex] = -1;
				}
				if (this.characterLearned2[this.currentIndex] == num)
				{
					this.characterLearned2[this.currentIndex] = -1;
				}
				if (this.characterLearned3[this.currentIndex] == num)
				{
					this.characterLearned3[this.currentIndex] = -1;
				}
				this.fillStatus[num] = 0;
			}
			else
			{
				this.scrollFills[num].enabled = true;
				bool flag = false;
				if (this.characterLearned1[this.currentIndex] == -1)
				{
					this.characterLearned1[this.currentIndex] = num;
					flag = true;
				}
				if (this.characterLearned2[this.currentIndex] == -1 && !flag)
				{
					this.characterLearned2[this.currentIndex] = num;
					flag = true;
				}
				if (this.characterLearned3[this.currentIndex] == -1 && !flag)
				{
					this.characterLearned3[this.currentIndex] = num;
					flag = true;
				}
				if (this.spells && flag)
				{
					this.GetSpellName(num);
					int num2 = this.arrayCount;
					Color32[] pixels = this.drawingTextures[num].GetPixels32();
					if (this.characterLearned1[this.currentIndex] == num)
					{
						Color32[] array = this.runeColors1[this.currentIndex];
						for (int i = 0; i < num2; i++)
						{
							array[i] = pixels[i];
						}
					}
					if (this.characterLearned2[this.currentIndex] == num)
					{
						Color32[] array2 = this.runeColors2[this.currentIndex];
						for (int j = 0; j < num2; j++)
						{
							array2[j] = pixels[j];
						}
					}
					if (this.characterLearned3[this.currentIndex] == num)
					{
						Color32[] array3 = this.runeColors3[this.currentIndex];
						for (int k = 0; k < num2; k++)
						{
							array3[k] = pixels[k];
						}
					}
					this.fillStatus[num] = 1;
					this.CheckSpellFillStatus(num, true);
					if (this.fillStatus[num] == 1)
					{
						if (this.incompleteFillCount == 0)
						{
							this.scrollFills[num].sprite = this.scrollFillSpellsNotComplete4;
						}
						if (this.incompleteFillCount == 3)
						{
							this.scrollFills[num].sprite = this.scrollFillSpellsNotComplete3;
						}
						if (this.incompleteFillCount == 2)
						{
							this.scrollFills[num].sprite = this.scrollFillSpellsNotComplete2;
						}
						if (this.incompleteFillCount == 1)
						{
							this.scrollFills[num].sprite = this.scrollFillSpellsNotComplete1;
						}
					}
					else
					{
						this.scrollFills[num].sprite = this.scrollFillSpells;
					}
				}
				else if (!this.spells)
				{
					this.fillStatus[num] = 2;
				}
			}
			this.GetButtonText(true);
		}
		if (Links.x.mk)
		{
			EventSystem.current.SetSelectedGameObject(null);
		}
	}

	// Token: 0x06000F25 RID: 3877 RVA: 0x00126F94 File Offset: 0x00125194
	public void CheckSpellFillStatus(int num, bool canPlayFX)
	{
		bool flag = this.HasRune(num);
		if (!flag && this.openNum > -1 && num == this.openNum && base.gameObject.activeSelf)
		{
			int num2 = this.arrayCount;
			Color32[] pixels = this.drawingTextures[this.openNum].GetPixels32();
			bool flag2 = false;
			for (int i = 0; i < num2; i++)
			{
				if (pixels[i] != this.resetColor)
				{
					flag2 = true;
					break;
				}
			}
			if (flag2)
			{
				if (this.characterLearned1[this.currentIndex] == num)
				{
					Color32[] array = this.runeColors1[this.currentIndex];
					for (int j = 0; j < num2; j++)
					{
						array[j] = pixels[j];
					}
				}
				if (this.characterLearned2[this.currentIndex] == num)
				{
					Color32[] array2 = this.runeColors2[this.currentIndex];
					for (int k = 0; k < num2; k++)
					{
						array2[k] = pixels[k];
					}
				}
				if (this.characterLearned3[this.currentIndex] == num)
				{
					Color32[] array3 = this.runeColors3[this.currentIndex];
					for (int l = 0; l < num2; l++)
					{
						array3[l] = pixels[l];
					}
				}
				flag = true;
			}
		}
		if (flag)
		{
			this.fillStatus[num] = 2;
			this.GetButtonText(canPlayFX);
			this.scrollFills[num].sprite = this.scrollFillSpells;
			return;
		}
		this.fillStatus[num] = 1;
	}

	// Token: 0x06000F26 RID: 3878 RVA: 0x00127144 File Offset: 0x00125344
	public void GetButtonText(bool canPlayFX)
	{
		int num = 0;
		if (this.characterLearned1[this.currentIndex] > -1)
		{
			num++;
		}
		if (this.characterLearned2[this.currentIndex] > -1)
		{
			num++;
		}
		if (this.characterLearned3[this.currentIndex] > -1)
		{
			num++;
		}
		int num2 = 0;
		for (int i = 0; i < this.scrollCount; i++)
		{
			if (this.fillStatus[i] == 2)
			{
				num2++;
			}
		}
		if (num < this.maxSelections || num2 < this.maxSelections)
		{
			if (!this.spells || (this.spells && num < this.maxSelections))
			{
				for (int j = 0; j < this.scrollCount; j++)
				{
					this.SetScrollState(true, j);
				}
			}
			else
			{
				for (int k = 0; k < this.scrollCount; k++)
				{
					if (this.characterLearned1[this.currentIndex] != k && this.characterLearned2[this.currentIndex] != k && this.characterLearned3[this.currentIndex] != k)
					{
						this.SetScrollState(false, k);
					}
				}
			}
			this.nextButton.interactable = false;
			this.buttonText.text = string.Concat(new string[]
			{
				"(",
				num2.ToString(),
				"/",
				this.maxSelections.ToString(),
				")"
			});
			return;
		}
		for (int l = 0; l < this.scrollCount; l++)
		{
			if (this.characterLearned1[this.currentIndex] != l && this.characterLearned2[this.currentIndex] != l && this.characterLearned3[this.currentIndex] != l)
			{
				this.SetScrollState(false, l);
			}
		}
		if (!this.nextButton.interactable && canPlayFX)
		{
			for (int m = 0; m < this.scrollCount; m++)
			{
				if (this.characterLearned1[this.currentIndex] == m || this.characterLearned2[this.currentIndex] == m || this.characterLearned3[this.currentIndex] == m)
				{
					this.scrollMainImages[m].gameObject.transform.parent.GetChild(4).gameObject.GetComponent<HannahAnimator>().Play("Idle");
				}
			}
			MasterAudio.PlaySoundAndForget("Feedback", 0.4f, new float?(1f), 0f, "Level Up", null);
		}
		this.nextButton.interactable = true;
		if (this.currentIndex < this.skillOrder.Count - 2)
		{
			this.buttonText.text = "Next";
			return;
		}
		this.buttonText.text = "Finish";
	}

	// Token: 0x06000F27 RID: 3879 RVA: 0x0012742C File Offset: 0x0012562C
	public void OpenWord(int num)
	{
		this.str.Clear();
		this.str.Append("<font=Bold><size=1.6em>");
		this.str.Append(this.skillAbilities[num]._DisplayName);
		this.str.Append("</font></size>\n");
		this.str.Append(this.skillAbilities[num]._Description);
		this.skillDescription.text = this.str.ToString();
		this.infoBorderRT.sizeDelta = new Vector2(this.infoBorderRT.sizeDelta.x, this.skillDescription.preferredHeight + 60f);
		this.openNum = num;
	}

	// Token: 0x06000F28 RID: 3880 RVA: 0x001274F0 File Offset: 0x001256F0
	public void OpenSong(int num)
	{
		this.openNum = num;
		this.str.Clear();
		this.str.Append("<font=Bold><size=1.6em>");
		this.str.Append(this.skillAbilities[num]._DisplayName);
		this.str.Append("</font></size>\n");
		this.str.Append(this.skillAbilities[num]._Description);
		Library.Effects effectRow = Links.x.library.GetEffectRow(this.skillNames[num]);
		this.str.Append("\n\nSong length: ");
		int overallTime = this.skillAbilities[num]._OverallTime;
		float num2 = Records.x.ShowSeconds(overallTime);
		this.str.Append(num2);
		if (num2 == 1f)
		{
			this.str.Append(" second");
		}
		else
		{
			this.str.Append(" seconds");
		}
		if (effectRow != null)
		{
			this.str.Append("\nSong effects: ");
			this.str.Append(Links.x.manual.GetEffectDescription(effectRow, 0f, 0));
		}
		this.skillDescription.text = this.str.ToString();
		this.infoBorderRT.sizeDelta = new Vector2(this.infoBorderRT.sizeDelta.x, this.skillDescription.preferredHeight + 60f);
	}

	// Token: 0x06000F29 RID: 3881 RVA: 0x00127670 File Offset: 0x00125870
	public void OpenSpell(int num)
	{
		this.openNum = num;
		string text = this.skillNames[num];
		this.selectedPagan = Links.x.library.GetPaganRow(text);
		this.hasDrawn = false;
		Links.x.spellcrafting.selectedPagan = this.selectedPagan;
		Links.x.spellcrafting.SelectLearningButton(-1);
		this.str.Clear();
		this.str.Append("<font=Bold><size=1.6em>");
		this.str.Append(this.selectedPagan._DisplayName);
		this.str.Append("</font></size>\n");
		this.str.Append(Links.x.spellcrafting.SetDescription());
		this.str.Append("\n\n<color=#5B5452><size=.9em>Draw rune to save as learned spell.</size></color>");
		this.spellDescription.text = this.str.ToString();
		this.drawImage.enabled = true;
		this.drawImage.sprite = this.drawingSprites[num];
		this.drawing.Initialize();
	}

	// Token: 0x06000F2A RID: 3882 RVA: 0x00127788 File Offset: 0x00125988
	public void ResetTexture()
	{
		this.resetColor = new Color(0f, 0f, 0f, 0f);
		this.resetColorsArray = new Color[(int)this.drawingSprites[0].rect.width * (int)this.drawingSprites[0].rect.height];
		int num = this.resetColorsArray.Length;
		for (int i = 0; i < num; i++)
		{
			this.resetColorsArray[i] = this.resetColor;
		}
		this.drawingTextures[this.openNum].SetPixels(this.resetColorsArray);
		this.drawingTextures[this.openNum].Apply();
		if (this.characterLearned1[this.currentIndex] == this.openNum)
		{
			Color32[] array = this.runeColors1[this.currentIndex];
			for (int j = 0; j < num; j++)
			{
				array[j] = this.resetColor;
			}
		}
		if (this.characterLearned2[this.currentIndex] == this.openNum)
		{
			Color32[] array2 = this.runeColors2[this.currentIndex];
			for (int k = 0; k < num; k++)
			{
				array2[k] = this.resetColor;
			}
		}
		if (this.characterLearned3[this.currentIndex] == this.openNum)
		{
			Color32[] array3 = this.runeColors3[this.currentIndex];
			for (int l = 0; l < num; l++)
			{
				array3[l] = this.resetColor;
			}
		}
	}

	// Token: 0x06000F2B RID: 3883 RVA: 0x0012793C File Offset: 0x00125B3C
	public void ResetDrawings()
	{
		this.resetColor = new Color(0f, 0f, 0f, 0f);
		this.resetColorsArray = new Color[(int)this.drawingSprites[0].rect.width * (int)this.drawingSprites[0].rect.height];
		for (int i = 0; i < this.scrollCount; i++)
		{
			int num = this.resetColorsArray.Length;
			for (int j = 0; j < num; j++)
			{
				this.resetColorsArray[j] = this.resetColor;
			}
			if (this.characterLearned1[this.currentIndex] == i)
			{
				Color32[] array = this.runeColors1[this.currentIndex];
				for (int k = 0; k < num; k++)
				{
					this.resetColorsArray[k] = array[k];
				}
			}
			if (this.characterLearned2[this.currentIndex] == i)
			{
				Color32[] array2 = this.runeColors2[this.currentIndex];
				for (int l = 0; l < num; l++)
				{
					this.resetColorsArray[l] = array2[l];
				}
			}
			if (this.characterLearned3[this.currentIndex] == i)
			{
				Color32[] array3 = this.runeColors3[this.currentIndex];
				for (int m = 0; m < num; m++)
				{
					this.resetColorsArray[m] = array3[m];
				}
			}
			Texture2D texture2D = this.drawingTextures[i];
			texture2D.SetPixels(this.resetColorsArray);
			texture2D.Apply();
		}
	}

	// Token: 0x06000F2C RID: 3884 RVA: 0x00127AF9 File Offset: 0x00125CF9
	public void SetScrollState(bool state, int i)
	{
		this.scrollButtons[i].interactable = true;
		this.scrollMainImages[i].raycastTarget = true;
		this.scrollCheckBoxButtons[i].interactable = state;
	}

	// Token: 0x06000F2D RID: 3885 RVA: 0x00127B31 File Offset: 0x00125D31
	public void SetScrollStateAll(bool state, int i)
	{
		this.scrollButtons[i].interactable = state;
		this.scrollMainImages[i].raycastTarget = state;
		this.scrollCheckBoxButtons[i].interactable = state;
	}

	// Token: 0x06000F2E RID: 3886 RVA: 0x00127B6C File Offset: 0x00125D6C
	public bool HasSavedRune(int checkIndex, int listNumber)
	{
		int num = this.arrayCount;
		Color color = new Color(0f, 0f, 0f, 0f);
		if (listNumber == 1)
		{
			this.currentRuneColorsToCheck = this.runeColors1[checkIndex];
		}
		if (listNumber == 2)
		{
			this.currentRuneColorsToCheck = this.runeColors2[checkIndex];
		}
		if (listNumber == 3)
		{
			this.currentRuneColorsToCheck = this.runeColors3[checkIndex];
		}
		for (int i = 0; i < num; i++)
		{
			if (this.currentRuneColorsToCheck[i] != color)
			{
				return true;
			}
		}
		return false;
	}

	// Token: 0x06000F2F RID: 3887 RVA: 0x00127C08 File Offset: 0x00125E08
	private bool HasRune(int num)
	{
		Color color = new Color(0f, 0f, 0f, 0f);
		if (this.characterLearned1[this.currentIndex] == num)
		{
			int num2 = this.arrayCount;
			Color32[] array = this.runeColors1[this.currentIndex];
			for (int i = 0; i < num2; i++)
			{
				if (array[i] != color)
				{
					return true;
				}
			}
		}
		if (this.characterLearned2[this.currentIndex] == num)
		{
			int num3 = this.arrayCount;
			Color32[] array2 = this.runeColors2[this.currentIndex];
			for (int j = 0; j < num3; j++)
			{
				if (array2[j] != color)
				{
					return true;
				}
			}
		}
		if (this.characterLearned3[this.currentIndex] == num)
		{
			int num4 = this.arrayCount;
			Color32[] array3 = this.runeColors3[this.currentIndex];
			for (int k = 0; k < num4; k++)
			{
				if (array3[k] != color)
				{
					return true;
				}
			}
		}
		return false;
	}

	// Token: 0x06000F30 RID: 3888 RVA: 0x00127D30 File Offset: 0x00125F30
	private string GetAbilityName(string skill, int num)
	{
		string text = "";
		if (skill == "Vines")
		{
			if (num == 0)
			{
				text = "Entangle";
			}
			if (num == 1)
			{
				text = "EntangleSpikes";
			}
			if (num == 2)
			{
				text = "SilentMoss";
			}
			if (num == 3)
			{
				text = "Bushes";
			}
			if (num == 4)
			{
				text = "VineWall";
			}
			if (num == 5)
			{
				text = "TrapRoot";
			}
		}
		if (skill == "Fauna")
		{
			if (num == 0)
			{
				text = "ScoutFrog";
			}
			if (num == 1)
			{
				text = "AcornMen";
			}
			if (num == 2)
			{
				text = "FetishCorpse";
			}
			if (num == 3)
			{
				text = "BeeShield";
			}
			if (num == 4)
			{
				text = "Decoy";
			}
			if (num == 5)
			{
				text = "LootFrog";
			}
		}
		if (skill == "Spores")
		{
			if (num == 0)
			{
				text = "PukeSpores";
			}
			if (num == 1)
			{
				text = "SlipperyGround";
			}
			if (num == 2)
			{
				text = "HealingSpores";
			}
			if (num == 3)
			{
				text = "TurnIntoMushrooms";
			}
			if (num == 4)
			{
				text = "VolPrison";
			}
			if (num == 5)
			{
				text = "ChaosSpores";
			}
		}
		if (skill == "Melee")
		{
			if (num == 0)
			{
				text = "ShoulderRam";
			}
			if (num == 1)
			{
				text = "CrushingBlow";
			}
			if (num == 2)
			{
				text = "DmgUpDurDown";
			}
			if (num == 3)
			{
				text = "Parry";
			}
			if (num == 4)
			{
				text = "BreakArmor";
			}
			if (num == 5)
			{
				text = "StealthAttack";
			}
		}
		if (skill == "Range")
		{
			if (num == 0)
			{
				text = "Arc";
			}
			if (num == 1)
			{
				text = "DmgUpHealthDown";
			}
			if (num == 2)
			{
				text = "Strafe";
			}
			if (num == 3)
			{
				text = "CombatStartDmg";
			}
			if (num == 4)
			{
				text = "RangeStun";
			}
			if (num == 5)
			{
				text = "Repetition";
			}
		}
		if (skill == "Defense")
		{
			if (num == 0)
			{
				text = "DefenseStance";
			}
			if (num == 1)
			{
				text = "Illuminate";
			}
			if (num == 2)
			{
				text = "KillFlee";
			}
			if (num == 3)
			{
				text = "WeaponBlock";
			}
			if (num == 4)
			{
				text = "FatigueRegen";
			}
			if (num == 5)
			{
				text = "DefUpDmgDown";
			}
		}
		if (skill == "Horn")
		{
			if (num == 0)
			{
				text = "SlowSong";
			}
			if (num == 1)
			{
				text = "DodgeChanceDown";
			}
			if (num == 2)
			{
				text = "HitChanceDown";
			}
			if (num == 3)
			{
				text = "DmgDown";
			}
			if (num == 4)
			{
				text = "PaganDown";
			}
			if (num == 5)
			{
				text = "AmplifyAilments";
			}
		}
		if (skill == "Flute")
		{
			if (num == 0)
			{
				text = "HealingSong";
			}
			if (num == 1)
			{
				text = "AmplifyDmg";
			}
			if (num == 2)
			{
				text = "SpiritReleaseUp";
			}
			if (num == 3)
			{
				text = "SpeedUp";
			}
			if (num == 4)
			{
				text = "HitChanceUp";
			}
			if (num == 5)
			{
				text = "SkillsUp";
			}
		}
		if (skill == "Drum")
		{
			if (num == 0)
			{
				text = "StruckDumb";
			}
			if (num == 1)
			{
				text = "Rally";
			}
			if (num == 2)
			{
				text = "Fear";
			}
			if (num == 3)
			{
				text = "Taunt";
			}
			if (num == 4)
			{
				text = "DimVision";
			}
			if (num == 5)
			{
				text = "Confuse";
			}
		}
		return text;
	}

	// Token: 0x06000F31 RID: 3889 RVA: 0x00127FCC File Offset: 0x001261CC
	public int GetMaxSelections(string skill, string type)
	{
		int num = 0;
		if (skill == "Vines" || skill == "Fauna" || skill == "Spores")
		{
			num = 3;
			if (type == "Minor")
			{
				num = 2;
			}
			this.scrollCount = 5;
		}
		if (skill == "Melee" || skill == "Range" || skill == "Defense")
		{
			this.words = true;
			num = 2;
			if (type == "Minor")
			{
				num = 1;
			}
			this.scrollCount = 4;
		}
		if (skill == "Horn" || skill == "Flute" || skill == "Drum")
		{
			this.songs = true;
			num = 2;
			if (type == "Minor")
			{
				num = 1;
			}
			this.scrollCount = 4;
		}
		return num;
	}

	// Token: 0x06000F32 RID: 3890 RVA: 0x001280A7 File Offset: 0x001262A7
	private string GetSpellName(Library.Abilities row)
	{
		return "Initiate " + row._DisplayName;
	}

	// Token: 0x06000F33 RID: 3891 RVA: 0x001280B9 File Offset: 0x001262B9
	private string GetSpellName(int num)
	{
		return "Initiate " + this.skillAbilities[num]._DisplayName;
	}

	// Token: 0x040018B0 RID: 6320
	[Header("Info")]
	public bool spells;

	// Token: 0x040018B1 RID: 6321
	public bool songs;

	// Token: 0x040018B2 RID: 6322
	public bool words;

	// Token: 0x040018B3 RID: 6323
	public bool newSelection;

	// Token: 0x040018B4 RID: 6324
	public bool confirming;

	// Token: 0x040018B5 RID: 6325
	public int scrollCount = 5;

	// Token: 0x040018B6 RID: 6326
	public int textureSize = 512;

	// Token: 0x040018B7 RID: 6327
	private int incompleteFillCount;

	// Token: 0x040018B8 RID: 6328
	private int arrayCount;

	// Token: 0x040018B9 RID: 6329
	public int maxSelections;

	// Token: 0x040018BA RID: 6330
	public string currentSkill;

	// Token: 0x040018BB RID: 6331
	public List<Texture2D> drawingTextures = new List<Texture2D>();

	// Token: 0x040018BC RID: 6332
	public List<Sprite> drawingSprites = new List<Sprite>();

	// Token: 0x040018BD RID: 6333
	public List<Character> characterOrder = new List<Character>();

	// Token: 0x040018BE RID: 6334
	public List<string> skillOrder = new List<string>();

	// Token: 0x040018BF RID: 6335
	public List<string> skillType = new List<string>();

	// Token: 0x040018C0 RID: 6336
	public List<int> characterLearned1 = new List<int>();

	// Token: 0x040018C1 RID: 6337
	public List<int> characterLearned2 = new List<int>();

	// Token: 0x040018C2 RID: 6338
	public List<int> characterLearned3 = new List<int>();

	// Token: 0x040018C3 RID: 6339
	public List<Color32[]> runeColors1 = new List<Color32[]>();

	// Token: 0x040018C4 RID: 6340
	public List<Color32[]> runeColors2 = new List<Color32[]>();

	// Token: 0x040018C5 RID: 6341
	public List<Color32[]> runeColors3 = new List<Color32[]>();

	// Token: 0x040018C6 RID: 6342
	public List<string> skillNames = new List<string>();

	// Token: 0x040018C7 RID: 6343
	public List<Library.Abilities> skillAbilities = new List<Library.Abilities>();

	// Token: 0x040018C8 RID: 6344
	public Library.Pagan selectedPagan;

	// Token: 0x040018C9 RID: 6345
	public Character character;

	// Token: 0x040018CA RID: 6346
	public int currentIndex;

	// Token: 0x040018CB RID: 6347
	public Creation creation;

	// Token: 0x040018CC RID: 6348
	public bool opened;

	// Token: 0x040018CD RID: 6349
	private int openNum;

	// Token: 0x040018CE RID: 6350
	private Color32[] currentRuneColors;

	// Token: 0x040018CF RID: 6351
	private Color32[] currentRuneColorsToCheck;

	// Token: 0x040018D0 RID: 6352
	public List<string> runesCreated = new List<string>();

	// Token: 0x040018D1 RID: 6353
	public List<string> runesSaved = new List<string>();

	// Token: 0x040018D2 RID: 6354
	[Header("Objects")]
	public TextMeshProUGUI title;

	// Token: 0x040018D3 RID: 6355
	public TextMeshProUGUI message;

	// Token: 0x040018D4 RID: 6356
	public TextMeshProUGUI skillDescription;

	// Token: 0x040018D5 RID: 6357
	public TextMeshProUGUI spellDescription;

	// Token: 0x040018D6 RID: 6358
	public TextMeshProUGUI buttonText;

	// Token: 0x040018D7 RID: 6359
	public List<TextMeshProUGUI> scrollTitles = new List<TextMeshProUGUI>();

	// Token: 0x040018D8 RID: 6360
	public List<Image> scrollFills = new List<Image>();

	// Token: 0x040018D9 RID: 6361
	public List<ButtonMultiTargets> scrollButtons = new List<ButtonMultiTargets>();

	// Token: 0x040018DA RID: 6362
	public List<ButtonMultiTargets> scrollCheckBoxButtons = new List<ButtonMultiTargets>();

	// Token: 0x040018DB RID: 6363
	public List<int> fillStatus = new List<int>();

	// Token: 0x040018DC RID: 6364
	public List<Image> scrollMainImages = new List<Image>();

	// Token: 0x040018DD RID: 6365
	public RawImage portrait;

	// Token: 0x040018DE RID: 6366
	public DrawViewController drawing;

	// Token: 0x040018DF RID: 6367
	public Image drawImage;

	// Token: 0x040018E0 RID: 6368
	public ButtonMultiTargets nextButton;

	// Token: 0x040018E1 RID: 6369
	public ButtonMultiTargets backButton;

	// Token: 0x040018E2 RID: 6370
	public bool hasDrawn;

	// Token: 0x040018E3 RID: 6371
	public TMP_InputField nameInput;

	// Token: 0x040018E4 RID: 6372
	private StringFast str = new StringFast(64);

	// Token: 0x040018E5 RID: 6373
	public RectTransform infoBorderRT;

	// Token: 0x040018E6 RID: 6374
	public Transform unusedScrolls;

	// Token: 0x040018E7 RID: 6375
	public Transform usedScrolls;

	// Token: 0x040018E8 RID: 6376
	public RectTransform targetRect;

	// Token: 0x040018E9 RID: 6377
	public Material vines;

	// Token: 0x040018EA RID: 6378
	public Material spores;

	// Token: 0x040018EB RID: 6379
	public Material fauna;

	// Token: 0x040018EC RID: 6380
	public Color selectedText;

	// Token: 0x040018ED RID: 6381
	public Color unselectedText;

	// Token: 0x040018EE RID: 6382
	[Header("Graphics")]
	public Sprite scrollFillSpells;

	// Token: 0x040018EF RID: 6383
	public Sprite scrollFillSongs;

	// Token: 0x040018F0 RID: 6384
	public Sprite scrollFillWords;

	// Token: 0x040018F1 RID: 6385
	public Sprite scrollFillSpellsNotComplete;

	// Token: 0x040018F2 RID: 6386
	public Sprite scrollFillSpellsNotComplete1;

	// Token: 0x040018F3 RID: 6387
	public Sprite scrollFillSpellsNotComplete2;

	// Token: 0x040018F4 RID: 6388
	public Sprite scrollFillSpellsNotComplete3;

	// Token: 0x040018F5 RID: 6389
	public Sprite scrollFillSpellsNotComplete4;

	// Token: 0x040018F6 RID: 6390
	private Color[] resetColorsArray;

	// Token: 0x040018F7 RID: 6391
	private Color resetColor;

	// Token: 0x040018F8 RID: 6392
	private float updateTime;

	// Token: 0x040018F9 RID: 6393
	private float fillUpdateTime;

	// Token: 0x040018FA RID: 6394
	private int currIndex;

	// Token: 0x040018FB RID: 6395
	private bool savingSpell;
}
