diff options
Diffstat (limited to 'Client/Assembly-CSharp/PetsTab.cs')
-rw-r--r-- | Client/Assembly-CSharp/PetsTab.cs | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/Client/Assembly-CSharp/PetsTab.cs b/Client/Assembly-CSharp/PetsTab.cs new file mode 100644 index 0000000..2c362c3 --- /dev/null +++ b/Client/Assembly-CSharp/PetsTab.cs @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +public class PetsTab : MonoBehaviour +{ + public ColorChip ColorTabPrefab; + + public SpriteRenderer DemoImage; + + public SpriteRenderer HatImage; + + public SpriteRenderer SkinImage; + + public SpriteRenderer PetImage; + + public FloatRange XRange = new FloatRange(1.5f, 3f); + + public float YStart = 0.8f; + + public float YOffset = 0.8f; + + public int NumPerRow = 4; + + public Scroller scroller; + + private List<ColorChip> ColorChips = new List<ColorChip>(); + + public void OnEnable() + { + PlayerControl.SetPlayerMaterialColors((int)PlayerControl.LocalPlayer.Data.ColorId, this.DemoImage); + PlayerControl.SetHatImage(SaveManager.LastHat, this.HatImage); + PlayerControl.SetSkinImage(SaveManager.LastSkin, this.SkinImage); + PlayerControl.SetPetImage(SaveManager.LastPet, (int)PlayerControl.LocalPlayer.Data.ColorId, this.PetImage); + PetBehaviour[] unlockedPets = DestroyableSingleton<HatManager>.Instance.GetUnlockedPets(); + for (int i = 0; i < unlockedPets.Length; i++) + { + PetBehaviour pet = unlockedPets[i]; + float x = this.XRange.Lerp((float)(i % this.NumPerRow) / ((float)this.NumPerRow - 1f)); + float y = this.YStart - (float)(i / this.NumPerRow) * this.YOffset; + ColorChip chip = UnityEngine.Object.Instantiate<ColorChip>(this.ColorTabPrefab, this.scroller.Inner); + chip.transform.localPosition = new Vector3(x, y, -1f); + chip.InUseForeground.SetActive(DestroyableSingleton<HatManager>.Instance.GetIdFromPet(pet) == SaveManager.LastPet); + chip.Button.OnClick.AddListener(delegate() + { + this.SelectPet(chip, pet); + }); + PlayerControl.SetPetImage(pet, (int)PlayerControl.LocalPlayer.Data.ColorId, chip.Inner); + this.ColorChips.Add(chip); + } + this.scroller.YBounds.max = -(this.YStart - (float)(unlockedPets.Length / this.NumPerRow) * this.YOffset) - 3f; + } + + public void OnDisable() + { + for (int i = 0; i < this.ColorChips.Count; i++) + { + UnityEngine.Object.Destroy(this.ColorChips[i].gameObject); + } + this.ColorChips.Clear(); + } + + private void SelectPet(ColorChip sender, PetBehaviour pet) + { + uint idFromPet = DestroyableSingleton<HatManager>.Instance.GetIdFromPet(pet); + SaveManager.LastPet = idFromPet; + PlayerControl.SetPetImage(pet, (int)PlayerControl.LocalPlayer.Data.ColorId, this.PetImage); + if (PlayerControl.LocalPlayer) + { + PlayerControl.LocalPlayer.RpcSetPet(idFromPet); + } + for (int i = 0; i < this.ColorChips.Count; i++) + { + ColorChip colorChip = this.ColorChips[i]; + colorChip.InUseForeground.SetActive(colorChip == sender); + } + } +} |