123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735 |
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.Events;
- using UnityEngine.EventSystems;
- using System;
- using System.Xml;
- using System.Linq;
- using System.Collections;
- using System.Collections.Generic;
- using Random = UnityEngine.Random;
- public class GardenLabel
- {
- public static string GardenBK2 = "GardenBK2";
- public static string GardenBK3 = "GardenBK3";
- public static string GardenBK4 = "GardenBK4";
- public static string BK2RightPos = "BK2RightPos";
- public static string BK2LeftPos = "BK2LeftPos";
- public static string BK3RightPos = "BK3RightPos";
- public static string BK3LeftPos = "BK3LeftPos";
- public static string BK4RightPos = "BK4RightPos";
- public static string BK4LeftPos = "BK4LeftPos";
- public static string MinigameLeftPos = "MinigameLeftPos";
- public static string GardenCloud1 = "GardenCloud1";
- public static string GardenCloud2 = "GardenCloud2";
- public static string GardenCloud3 = "GardenCloud3";
- public static string BirdPivot = "BirdPivot";
- public static string GardenLeftTree = "GardenLeftTree";
- public static string GardenRightTree = "GardenRightTree";
- public static string GardenRainbow = "GardenRainbow";
- public static string Minigame = "Minigame";
- public static string SlotPage = "SlotPage";
- public static string GardenPivot = "GardenPivot";
- public static string GardenPlayerPos = "GardenPlayerPos";
- public static string Minigame_DropAward_LeftBorder = "Minigame_DropAward_LeftBorder";
- public static string FindMinigame_DropAward_RightBorder = "FindMinigame_DropAward_RightBorder";
- public static string MemoryMinigame_DropAward_RightBorder = "MemoryMinigame_DropAward_RightBorder";
- public static string MinigameSlot1 = "MinigameSlot1";
- public static string MinigameSlot2 = "MinigameSlot2";
- public static string MinigameSlot3 = "MinigameSlot3";
- public static string MinigameSlot4 = "MinigameSlot4";
- public static string MinigameSlot5 = "MinigameSlot5";
- public static string MinigameSlot6 = "MinigameSlot6";
- public static string MinigameSlot7 = "MinigameSlot7";
- public static string MinigameSlot8 = "MinigameSlot8";
- public static string MinigameSlot9 = "MinigameSlot9";
- }
- public enum ElfType
- {
- Bee_Red,
- Bee_Blue,
- Bee_White,
- Bee_Purple,
- Bee_Yellow,
- Beetle_Red,
- Beetle_Blue,
- Beetle_White,
- Beetle_Purple,
- Beetle_Yellow,
- Butterfly_Red,
- Butterfly_Blue,
- Butterfly_White,
- Butterfly_Purple,
- Butterfly_Yellow,
- Dragonfly_Red,
- Dragonfly_Blue,
- Dragonfly_White,
- Dragonfly_Purple,
- Dragonfly_Yellow,
- }
- public class GardenManager : Regist
- {
- #region Config
- public static int TotalSlot
- {
- get { return totalSlot; }
- set
- {
- totalSlot = value;
- ResourceManager.SetText(CanvasLabel.G_CollectLab2, string.Format("{0}/{1}", totalSlot, TotalSlotPage * TotalSlotInOnePage));
- }
- }
- public static int totalSlot;
- public static int TotalSlotPage
- {
- get { return SlotPageList.Count; }
- }
- public static int TotalUnlockFlower
- {
- get { return totalUnlockFlower; }
- set
- {
- totalUnlockFlower = value;
- AchieveManager.UpdateStatus(AchieveType.UnlockFlowerAmt, totalUnlockFlower);
- ResourceManager.SetText(CanvasLabel.F_FlowerLab, string.Format("{0}", TotalUnlockFlower));
- ResourceManager.SetText(CanvasLabel.G_CollectLab1, string.Format("{0}/{1}", TotalUnlockFlower, TotalFlower));
- if (totalUnlockFlower >= TutorialManager.MinFlowerForFindGame && Manager.GardenLevel >= TutorialManager.FindMinigameTutorialLevel)
- {
- if (TutorialManager.findMinigameTutorial)
- {
- TutorialManager.PlayFindGame();
- }
- }
- }
- }
- private static int totalUnlockFlower;
- public static int TotalUnlockSpecialFlower
- {
- get { return totalUnlockSpecialFlower; }
- set
- {
- totalUnlockSpecialFlower = value;
- TotalUnlockFlower = totalUnlockSpecialFlower + totalUnlockNormalFlower;
- }
- }
- private static int totalUnlockSpecialFlower;
- public static int TotalUnlockNormalFlower
- {
- get { return totalUnlockNormalFlower; }
- set
- {
- totalUnlockNormalFlower = value;
- TotalUnlockFlower = totalUnlockSpecialFlower + totalUnlockNormalFlower;
- }
- }
- private static int totalUnlockNormalFlower;
- public static int TotalFlower;
- public static int TotalSpecialFlower
- {
- get { return totalSpecialFlower; }
- set
- {
- totalSpecialFlower = value;
- TotalFlower = totalSpecialFlower + totalNormalFlower;
- }
- }
- private static int totalSpecialFlower;
- public static int TotalNormalFlower
- {
- get { return totalNormalFlower; }
- set
- {
- totalNormalFlower = value;
- TotalFlower = totalSpecialFlower + totalNormalFlower;
- }
- }
- private static int totalNormalFlower;
- public static int FirstUnlockFlowerID
- {
- get
- {
- foreach (var kv in FlowerInfoDictionary)
- {
- if (!kv.Value.Unlock)
- {
- return kv.Key;
- }
- }
- return -1;
- }
- }
- public static List<int> UnlockedFlowerIDList
- {
- get
- {
- List<int> unlockedFlowerIDList = new List<int>();
- foreach (var kv in FlowerInfoDictionary)
- {
- if (kv.Value.Unlock)
- {
- unlockedFlowerIDList.Add(kv.Key);
- }
- }
- return unlockedFlowerIDList;
- }
- }
- public static int DefaultUnlockSlot = 1;
- public static bool InMinigameFlag = true;
- public static float MinCreateElfTime = 5;
- public static float MaxCreateElfTime = 30;
- public static float CreateElfTimer;
- public static float MinCreateStarTime;
- public static float MaxCreateStarTime;
- public static float CreateStarTimer;
- public static float MinCreateAwardTime = 5;
- public static float MaxCreateAwardTime = 15;
- public static float CreateAwardTimer;
- public static Text BuyFlowerButtonText;
- public static Text RetrieveFlowerButtonText;
- public static Button BuyFlowerButton;
- public static Button RetrieveFlowerButton;
- public static FlowerInfo SelectFlowerInfo;
- public static TweenMatFloat FlowerCardMaterialTween;
- public static GardenManager Instance;
- public static List<Slot> SlotList = new List<Slot>();
- public static List<Slot> PlantSlotList = new List<Slot>();
- public static List<Star> StarList = new List<Star>();
- public static List<ElfType> ElfList = new List<ElfType>();
- public static List<Transform> SlotPageList = new List<Transform>();
- public static Dictionary<int, FlowerInfo> FlowerInfoDictionary = new Dictionary<int, FlowerInfo>();
- public static int DefaultSlotPage = 2;
- public static int CriticalSlotIndex = 7;
- public static int TotalSlotInOnePage = 9;
- public static int LeftTopSlotIndex = 0;
- public static int RightTopSlotIndex = 3;
- public static int RightDownSlotIndex = 8;
- public static int LeftDownSlotIndex = 4;
- #endregion
- public void Update()
- {
- if (TutorialManager.NewplayerTutorial || Player.InDressRoom || SFSManager.GardenSmartFox.PlazaRoomController.JoinedPlazaRoom)
- {
- return;
- }
- CreateElfThread();
- CreateStarThread();
- CreateAwardThread();
- }
- public void CreateElfThread()
- {
- if (!InMinigameFlag)
- {
- return;
- }
- CreateElfTimer -= Time.deltaTime;
- if (CreateElfTimer < 0)
- {
- CreateElfTimer = Random.Range(MinCreateElfTime, MaxCreateElfTime);
- if (ElfList.Count > 0 && PlantSlotList.Count > 0)
- {
- PlantSlotList.Random()[0].PlantFlower.GetElf(ElfList.Random()[0]);
- }
- }
- }
- public void CreateStarThread()
- {
- if (InMinigameFlag && !Manager.MinigameFlag && !VisitManager.InVisit)
- {
- CreateStarTimer -= Time.deltaTime;
- if (CreateStarTimer < 0)
- {
- CreateStarTimer = Mathf.Lerp(MinCreateStarTime, MaxCreateStarTime, Random.Range(0f, 1f));
- StarList.Add(ResourceManager.GetStar());
- }
- }
- }
- public void CreateAwardThread()
- {
- if (InMinigameFlag)
- {
- CreateAwardTimer -= Time.deltaTime;
- if (CreateAwardTimer <= 0)
- {
- CreateAwardTimer = Random.Range(MinCreateAwardTime, MaxCreateAwardTime);
- List<Flower> spareList = new List<Flower>();
- for (int i = 0; i < PlantSlotList.Count; i++)
- {
- if (PlantSlotList[i].PlantFlower.HaveAward == false)
- {
- spareList.Add(PlantSlotList[i].PlantFlower);
- }
- }
- if (spareList.Count > 0)
- {
- spareList.Random()[0].HaveAward = true;
- }
- }
- }
- }
- public override void InstantiatePrefabs()
- {
- ResourceManager.Get(ResourceLabel.Garden, Folder.Scene, true, transform, true, ObjType.Garden).AddScript<Garden>();
- for (int i = 0; i < DefaultSlotPage; i++)
- {
- CreatePage();
- }
- #region 生成FlowerItem
- List<XmlAttributeCollection> attributeList = ConfigManager.GetFlowerConfig();
- for (int i = 0; i < attributeList.Count; i++)
- {
- FlowerInfo flowerInfo = new FlowerInfo(attributeList[i]);
- if (flowerInfo.IsSpecial)
- {
- TotalSpecialFlower++;
- }
- else
- {
- TotalNormalFlower++;
- }
- FlowerInfoDictionary.Add(flowerInfo.ID, flowerInfo);
- }
- #endregion
- }
- public override void FirstInit()
- {
- Instance = this;
- CreateElfTimer = Random.Range(MinCreateElfTime, MaxCreateElfTime);
- CreateAwardTimer = Random.Range(MinCreateAwardTime, MaxCreateAwardTime);
- UnlockSlot();
- for (int i = 0; i < ConfigManager.GetIntFormConfig(PlayerConfigLabel.ExtraSlot); i++)
- {
- UnlockSlot();
- }
- #region 读花朵存档
- List<int> flowerIDList = ConfigManager.GetFlowerList();
- for (int i = 0; i < flowerIDList.Count; i++)
- {
- FlowerInfoDictionary[flowerIDList[i]].Unlock = true;
- }
- List<int> flowerAmountList = ConfigManager.GetIntList(' ', PlayerConfigLabel.FlowerAmtList, null);
- for (int i = 0; i < flowerAmountList.Count; i++)
- {
- FlowerInfoDictionary[flowerIDList[i]].Amount = flowerAmountList[i];
- }
- List<KV<int, int>> plantList = ConfigManager.GetPlantList();
- for (int i = 0; i < plantList.Count; i++)
- {
- PlantFlower(plantList[i].Key, plantList[i].Value);
- }
- #endregion
- }
- public override void RegistReference()
- {
- RetrieveFlowerButton = ResourceManager.Get<Button>(CanvasLabel.H_Btn);
- RetrieveFlowerButtonText = ResourceManager.Get<Text>(CanvasLabel.H_BtnLab);
- BuyFlowerButton = ResourceManager.Get<Button>(CanvasLabel.H_Btn1);
- BuyFlowerButtonText = ResourceManager.Get<Text>(CanvasLabel.H_BtnLab1);
- }
- private static float PageXOffset = 18.9f;
- public static void CreatePage()
- {
- Transform tra = ResourceManager.Get(ResourceLabel.Page, Folder.Scene, false, ResourceManager.Get(GardenLabel.SlotPage), false, ObjType.SlotPage);
- float offset = TotalSlotPage * PageXOffset;
- tra.SetLX(offset);
- Vector3 pos = ResourceManager.Get(GardenLabel.SlotPage).position;
- pos.x = -offset;
- Garden.PagePos.Add(pos);
- for (int i = 0; i < TotalSlotInOnePage; i++)
- {
- Slot slot = tra.GetChild(i).GetComponent<Slot>();
- if (slot == null)
- {
- slot = tra.GetChild(i).AddScript<Slot>();
- }
- slot.Index = SlotList.Count;
- SlotList.Add(slot);
- }
- SlotPageList.Add(tra);
- }
- public static void UnlockSlot()
- {
- for (int i = 0; i < SlotList.Count; i++)
- {
- if (SlotList[i].Lock == false)
- {
- TotalSlot++;
-
- SlotList[i].Lock = true;
- SlotList[i].Available = true;
-
- if (TotalSlot% TotalSlotInOnePage == CriticalSlotIndex)
- {
- if (TotalSlot/ TotalSlotInOnePage + DefaultSlotPage >= TotalSlotPage)
- {
- CreatePage();
- }
- }
- return;
- }
- }
- }
- public static void ShowPlantCard(FlowerInfo flowerInfo, Slot seleSlot = null)
- {
- ShowFlowerCard(flowerInfo, null, seleSlot);
- RetrieveFlowerButton.SetActive(false);
- BuyFlowerButton.SetActive(true);
- }
- public static void PlantFlower(int id, int index)
- {
- Slot slot = SlotList[index];
- FlowerInfo flowerInfo = FlowerInfoDictionary[id];
- slot.Plant(flowerInfo, false);
- }
- public static void PlantFlower(FlowerInfo flowerInfo)
- {
- Slot slot = null;
- for (int i = 0; i < SlotList.Count; i++)
- {
- if (SlotList[i].Available)
- {
- slot = SlotList[i];
- break;
- }
- }
- if (slot == null)
- {
- Bubble.Show(null, Language.GetStr(LanguageLabel.Common__NoValidSlot));
- }
- else
- {
- slot.Plant(flowerInfo, true);
- UpdatePlantCardStatus(flowerInfo);
- UpdateRetrieveCardStatus(flowerInfo, RetrieveFlowerButton);
- AudioManager.PlayClip(AudioLabel.PlantFlower);
- }
- }
- private static void UpdatePlantCardStatus(FlowerInfo flowerInfo)
- {
- if (flowerInfo.RemainAmount == 0)
- {
- ResourceManager.Get<Button>(CanvasLabel.H_Icon2).interactable = false;
- ResourceManager.SetActive(CanvasLabel.H_AmtLab, false);
- ResourceManager.SetActive(CanvasLabel.H_Rotate, false);
- ResourceManager.SetText(CanvasLabel.H_Desc, Language.GetStr(LanguageLabel.UI__H_AllPlanted));
- }
- else
- {
- ResourceManager.Get<Button>(CanvasLabel.H_Icon2).interactable = true;
- ResourceManager.SetActive(CanvasLabel.H_AmtLab, true);
- ResourceManager.SetText(CanvasLabel.H_AmtLab, FlowerInfo.AmountTextPrefix + flowerInfo.RemainAmount);
- ResourceManager.SetActive(CanvasLabel.H_Rotate, true);
- ResourceManager.SetText(CanvasLabel.H_Desc, Language.GetStr(LanguageLabel.UI__H_PlantTip));
- }
- }
- private static void SetBuyFlowerButton(FlowerInfo flowerInfo, Button button, Text buttonLab)
- {
- if (flowerInfo.UnlockCur == Current.Free)
- {
- buttonLab.text = Language.GetStr(LanguageLabel.UI__H_BtnLab2);
- button.image.material = Lib.GrayMat;
- button.onClick.RemoveAllListeners();
- button.onClick.AddListener
- (
- () =>
- {
- Bubble.Show(null, Language.GetStr(LanguageLabel.UI__H_BtnLab3));
- }
- );
- }
- else
- {
- buttonLab.text = Auxiliary.ImageParse(flowerInfo.UnlockCur) + flowerInfo.UnlockCost;
- button.image.material = null;
- button.onClick.RemoveAllListeners();
- button.onClick.AddListener
- (
- () =>
- {
- Manager.Pay
- (
- "",
- flowerInfo.UnlockCost,
- flowerInfo.UnlockCur,
- () =>
- {
- flowerInfo.Add();
- UpdatePlantCardStatus(flowerInfo);
- HttpManager.UploadConfig();
- PlayFlowerCardMaterialTween();
- AudioManager.PlayClip(AudioLabel.GetCurrent);
- ResourceManager.Get(CanvasLabel.H_Icon1).FindChild($"{CanvasLabel.H_UIFlashLight}/{CanvasLabel.H_UIParticleSystem}").GetComponent<UIPartical>().Begin();
- },
- StaticsManager.ItemID.解锁花朵,
- StaticsManager.ConsumeModule.Shop,
- true,
- false,
- () =>
- {
- ResourceManager.Get(CanvasLabel.H_FlowerCard).TweenBacCG();
- TweenCG tweenCg = ResourceManager.Get(CanvasLabel.G_Flower).TweenBacCG();
- tweenCg.AddEventOnetime
- (
- EventType.BackwardFinish,
- () =>
- {
- ResourceManager.Get(CanvasLabel.F_Manage0).TweenForVec();
- }
- );
- }
- );
- }
- );
- }
- }
- private static void PlayFlowerCardMaterialTween()
- {
- if (ResourceManager.Get<Image>(CanvasLabel.H_Icon2).material != Lib.GrayMat)
- {
- return;
- }
- Material material = new Material(ResourceManager.Get<Image>(CanvasLabel.H_Icon2).material);
- MaterialUnit materialUnit = new MaterialUnit
- (
- material,
- ResourceManager.Get(CanvasLabel.H_Icon2),
- new List<string>()
- {
- MaterialLabel.GrayMatGrayLerp,
- }
- );
- FlowerCardMaterialTween = materialUnit.CreateTweenMatFloat(1, 0, 1, true, true, Curve.EaseOutQuad, false);
- FlowerCardMaterialTween.OnForwardStart = () =>
- {
- materialUnit.Transform.GetComponent<Image>().material = materialUnit.Material;
- };
- FlowerCardMaterialTween.OnForwardFinish = () =>
- {
- ResourceManager.Get<Image>(CanvasLabel.H_Icon2).material = null;
- };
- materialUnit.TweenForMatFloat();
- }
- public static void ShowRetrieveCard(FlowerInfo flowerInfo, Slot seleSlot = null)
- {
- ShowFlowerCard(flowerInfo, null, seleSlot);
- RetrieveFlowerButton.SetActive(true);
- BuyFlowerButton.SetActive(true);
- }
- public static void RetriveFlower(Slot seleSlot = null)
- {
- if (seleSlot != null && seleSlot.PlantFlower == null)
- seleSlot = null;
- if (seleSlot == null)
- {
- foreach (var slot in PlantSlotList)
- {
- if (slot.PlantFlower.FlowerInfo == SelectFlowerInfo)
- {
- seleSlot = slot;
- break;
- }
- }
- }
- seleSlot.Retrieve();
- UpdatePlantCardStatus(seleSlot.PlantFlowerInfo);
- UpdateRetrieveCardStatus(seleSlot.PlantFlowerInfo, RetrieveFlowerButton);
- }
- public static void RetriveAllFlower()
- {
- for (int i = 0; i < PlantSlotList.Count; i++)
- {
- PlantSlotList[i--].Retrieve();
- }
- }
- private static void UpdateRetrieveCardStatus(FlowerInfo flowerInfo, Button button)
- {
- if (flowerInfo.PlantAmt == 0)
- button.SetActive(false);
- else
- button.SetActive(true);
- }
- private static void SetRetrieveFlowerButton(Button button, Text buttonLab, Slot seleSlot = null)
- {
- RetrieveFlowerButton = button;
- buttonLab.text = Language.GetStr(LanguageLabel.UI__H_BtnLab1);
- button.image.material = null;
- button.onClick.RemoveAllListeners();
- button.onClick.AddListener
- (
- () =>
- {
- AudioManager.PlayClip(AudioLabel.ClickButton);
- RetriveFlower(seleSlot);
- }
- );
- }
- public static void ShowUnlockCard(FlowerInfo flowerInfo, Slot seleSlot = null)
- {
- ShowFlowerCard(flowerInfo, Lib.GrayMat, seleSlot);
- RetrieveFlowerButton.SetActive(false);
- BuyFlowerButton.SetActive(true);
- }
- private static void ShowFlowerCard(FlowerInfo flowerInfo, Material material, Slot seleSlot)
- {
- SetRetrieveFlowerButton(RetrieveFlowerButton, RetrieveFlowerButtonText, seleSlot);
- SetBuyFlowerButton(flowerInfo, BuyFlowerButton, BuyFlowerButtonText);
- SelectFlowerInfo = flowerInfo;
- ResourceManager.Get(CanvasLabel.H_FlowerCard).TweenForCG();
- ResourceManager.SetText(CanvasLabel.H_Lab, flowerInfo.Name);
- UpdatePlantCardStatus(flowerInfo);
- Image image = ResourceManager.Get<Image>(CanvasLabel.H_Icon2);
- image.material = material;
- image.sprite = flowerInfo.Icon;
- image.Resize(true, DeltaSize.FlowerCardSpriteX, DeltaSize.FlowerCardSpriteY);
- }
- public static void RetrieveAllElf()
- {
- for (int i = 0; i < PlantSlotList.Count; i++)
- {
- PlantSlotList[i].PlantFlower.RetrieveElf();
- }
- }
- public static void RetrieveAllStar()
- {
- for (int i = 0; i < StarList.Count; i++)
- {
- ResourceManager.Save(StarList[i]);
- }
- }
- }
|