using UnityEngine; using UnityEngine.UI; using System.Collections.Generic; using System.Linq; using System.Collections; public class UIT_CABINET : MonoBehaviour { public GameObject BoxSelections; public GameObject CABMODEL; public GameObject CABMODELContainer; public GameObject FILTERSContainer; public GameObject SUB_FILTERSContainer; public GameObject LibraryItemTemplate; public GameObject CatItemTemplate; public GameObject CabinetPln; static string model = "NA"; public void Setting(string name) { //print("name===========================================================eee=========="+name); DOIT.CloseALLPNL(); CabinetPln.SetActive(true); _G.PON = "CABINETpnl"; _G.PNL = "Cabinet"; Get.o1("Title").GetComponent().text = name; //Clear library selection pnl ///DOIT.DELETEAllChild(FILTERSContainer.transform); //DOIT.DELETEAllChild(SUB_FILTERSContainer.transform); Get.o2("CABINETpnl","SHOWSELECTION").GetComponent().alpha = 0; StaticCoroutine.Start(SetFILTERS(name)); //Set Box Selection SetBoxSelection(); ShowCabWithBoxSelection(); Get.o2("CABINETpnl","SaveToServer").SetActive(false); if(_G.User=="Admin" ){Get.o2("CABINETpnl","SaveToServer").SetActive(true);} //Resize Door Pattern Get.o2("CABINETpnl/SHOWSELECTION","RowHeightBtn").SetActive(_P.ListSwitch["ALLOW_DOORPATTERN_RESIZE"]); //BMR KENT bool isbmrKentHH=false; if(_G.PATH=="bmr" || _G.PATH=="kent" || _G.PATH=="homehardware" ){isbmrKentHH=true;} Get.o2("CABINETpnl/SHOWSELECTION","M_INSERT").SetActive(isbmrKentHH); Get.o2("CABINETpnl","M_COLOR").SetActive(isbmrKentHH); Get.o2("CABINETpnl","T_DoorSelection").SetActive(false); } //Box Selection----------------------------------------------------------------------------------------------- public void SetBoxSelection(){ List BoxList=new(); DOIT.AllChildOff(BoxSelections); string CodeRecipe=""; foreach (string line in _G.UIT_LibraryBoxTextures){ if(!string.IsNullOrEmpty(line) && line!=_G.UIT_LibraryBoxTextures[0]){ BoxList.Add(line.Split(",")[0]); } } if(BoxList.Count>1){ foreach (string ID in BoxList){//COUN.1?F6F6F6?F6F6F6?F6F6F6?1?0?0.5?0.3?1 string Texture=UIT.Value(Library.BoxTexture,ID,Header.Texture); string c1=UIT.Value(Library.BoxTexture,ID,Header.C1); string c2=UIT.Value(Library.BoxTexture,ID,Header.C2); string c3=UIT.Value(Library.BoxTexture,ID,Header.C3); string R=UIT.Value(Library.BoxTexture,ID,Header.Rotation); CodeRecipe+=Texture+"?"+c1+"?"+c2+"?"+c3+"?1?"+R+"?0.5?0.3?1"; Transform Box=BoxSelections.transform.Find("Box"+ID); Box.gameObject.SetActive(true); //print("CodeRecipe===="+CodeRecipe); BoxSelections.transform.Find("Box"+ID+"/Background").GetComponent().sprite = UIT_MATERIAL.GetTexturebyRecipe(CodeRecipe); CodeRecipe=""; } } else {Get.o2("CABINETpnl","T_BoxSelection").SetActive(false);} //Set Globals // Set.GlobalColorBtn(Get.o2("CABINETpnl","GlobalNumber"),"CONSTRUCT","Cabinet"); //Set.GlobalSelections.SetActive(false); Get.o2("CABINETpnl", "AvailableDoors").SetActive(false); bool isTextGlobal=false; if(_P.Listfloat["GLOBAL_QTY"]!=1){ isTextGlobal=true;} Get.o2("CABINETpnl","T_DoorSelection").SetActive(isTextGlobal); } public void ShowCabWithBoxSelection(){ List CainetOnPanel = new(); foreach(Transform CabOn in CABMODELContainer.transform){ if(!CabOn.gameObject.activeSelf) continue; // ✅ ignorer les inactifs if(string.IsNullOrEmpty(CabOn.name)) continue; if(CabOn.name.Contains("(Clone)")) continue; CainetOnPanel.Add(CabOn.name); } //DOIT.AllChildOff(CABMODELContainer); string BoxSelection = Get.TogOn(BoxSelections).name; foreach (string CabName in CainetOnPanel) { try { string Box_finish = UIT.Value(Library.Cabinet, CabName, Header.Box_finish); if (Box_finish == BoxSelection[3..] || Box_finish == "All") { CABMODELContainer.transform.Find(CabName)?.gameObject.SetActive(true); } } catch { Debug.LogWarning($"'{CabName}' introuvable dans Library.Cabinet"); } } Get.o2("CABINETpnl","SHOWSELECTION").GetComponent().alpha = 0; Get.o2("CABINETpnl","Description").GetComponent().text = ""; } //----------------------------------------------------------------------------------------------- //-------------------Setup----------------------------------------------------------------------- //----------------------------------------------------------------------------------------------- public IEnumerator SetFILTERS(string Name) { if (LibraryItemTemplate == null) { Transform t = CabinetPln.transform.Find("BASEBTN/UIT_SELECTION"); if (t != null) LibraryItemTemplate = t.gameObject; } GameObject pnl = FILTERSContainer; List L = _G.UIT_LibraryCabinets; List list = new(); int CatIndex = UIT.Ind(Library.Cabinet, Header.Category); int LibraryIndex = UIT.Ind(Library.Cabinet, Header.Library_Name); DOIT.AllChildOff(pnl); int index = 0; for(int i=1; i IsReady(_G.UIT_LibraryCabinets)); GameObject KitchenFilter = Get.o2("CABINETpnl/FILTERS/Viewport/Content","Kitchen"); if(KitchenFilter != null){ KitchenFilter.transform.SetSiblingIndex(0); } GameObject Models = FILTERSContainer; if(Models.transform.childCount > 0){ Models.transform.GetChild(0).gameObject.GetComponent().isOn = true; SetCategory(Get.o1("Title").GetComponent().text); } else{ _M.PH(25,0,"ffffff",1,1); Get.o2("PNL","CABINETpnl").SetActive(false); } Get.o2("Canvas/Panel_SCENE/PNL/CABINETpnl", "ADDINPUTS").SetActive(false); } private static bool IsReady(List L) { if (L == null || L.Count == 0) { Debug.Log("LibraryCabTextures is not ready"); return false; } return true; } public void SetCategory(string name) { if (CatItemTemplate == null) { Transform t = CabinetPln.transform.Find("BASEBTN/UIT_SELECTION"); if (t != null) CatItemTemplate = t.gameObject; } GameObject pnl = SUB_FILTERSContainer; DOIT.AllChildOff(pnl); Allfalse.SetCabPnlOpen(); Get.o2("CABINETpnl","SHOWSELECTION").GetComponent().alpha = 0; string LibraryName = UIT.TogOn("FILTERS"); List L = _G.UIT_LibraryCabinets; List list = new(); int SubCatIndex = UIT.Ind("Cabinet","Sub_Category"); int Library_NameIndex = UIT.Ind("Cabinet","Library_Name"); int CatIndex = UIT.Ind("Cabinet","Category"); int index = 0; for(int i=1; i().isOn = true; ShowSelections(); } //----------------------------------------------------------------------------------------------- //-------------------Add to list----------------------------------------------------------------------- //----------------------------------------------------------------------------------------------- public static void AddCat(string SubCategory,GameObject pnl,GameObject btn,string Category) { //("SubCategory===="+SubCategory+" Category===="+Category);//SubCategory====Drawer | Door Category====TALL GameObject Cat = Instantiate(btn); Cat.transform.SetParent(pnl.transform, false); string SubCategoryName = TRANS.CabinetSubCategory(Category,SubCategory); Cat.transform.Find("Background").transform.Find("text").gameObject.GetComponent().text = TRANS.Retext(SubCategoryName); Cat.name = SubCategory; Cat.SetActive(true); } public static void AddLibrary(string Name,GameObject pnl,GameObject btn) { GameObject L = Instantiate(btn); L.transform.SetParent(pnl.transform, false); string nameLibrary = TRANS.This("T_" + Name); if (nameLibrary == "ERROR TXT") nameLibrary = Name; // print("Name=====AL==="+nameLibrary); L.transform.Find("Background").transform.Find("text").gameObject.GetComponent().text = TRANS.Retext(nameLibrary); L.name = Name; L.SetActive(true); } //----------------------------------------------------------------------------------------------- //-------------------Show Selections---------------------------------------------------------------------- //----------------------------------------------------------------------------------------------- // used by Canvas/Panel_SCENE/PNL/CABINETpnl/BTNCABSORT // public void ShowSelections() // { // Showselections(name); // } public void ShowSelections()//SHOWSELECTION { string name = Get.TogOn(SUB_FILTERSContainer).name; Allfalse.SetCabPnlOpen(); Get.o2("CABINETpnl","SHOWSELECTION").GetComponent().alpha = 0; Get.o2("CABINETpnl","Description").GetComponent().text = ""; Get.o2("CABINETpnl","Flip").GetComponent().text = ""; model = Get.o1("CABINETpnl/Title").GetComponent().text; //GameObject btn=Get.o2("CABINETpnl/BASEBTN","UIT_SELECTION"); //GameObject pnl=Get.o2("CABINETpnl/CABMODEL/Viewport","Content"); //DOIT.DELETEAllObjectChild(CABMODELContainer); DOIT.AllChildOff(CABMODELContainer); List cablist = new(); List paternlist25 = new(); List paternlist26 = new(); List L=_G.UIT_LibraryCabinets; string LibraryName = UIT.TogOn("FILTERS"); string LN="Cabinet"; UIT.SortLibrary(_G.UIT_LibraryCabinets); int UNind=UIT.Ind(LN,"Unique_Name"); int SubCatIndex=UIT.Ind(LN,"Sub_Category"); int Library_NameIndex=UIT.Ind(LN,"Library_Name"); int CategoryIndex=UIT.Ind(LN,"Category"); int Door1=Get.IndexCSV(L,"Pattern_Door_1"); int Door2=Get.IndexCSV(L,"Pattern_Door_2"); for(int i=1; i= CABMODELContainer.transform.childCount) { Instantiate(CABMODELContainer.transform.GetChild(0).gameObject, CABMODELContainer.transform).SetActive(false); } print("cablist[i]"+cablist[i]); GameObject M = CABMODELContainer.transform.GetChild(i).gameObject; M.name = cablist[i]; Text label = M.GetComponentInChildren(true); if (label != null) label.text = cablist[i]; //string ncat = cablist[i]; M.SetActive(true); M.transform.GetComponent().localScale = new Vector3(1.0f, 1.0f, 1.0f); AddPaternCab(M, paternlist25[i], paternlist26[i], 0f, 10f); } } // Aucune sélection à l'ouverture — passer par le groupe du toggle lui-même Toggle firstTog = CABMODELContainer.GetComponentInChildren(); if (firstTog != null && firstTog.group != null) firstTog.group.SetAllTogglesOff(false); } //----------------------------------------------------------------------------------------------- //-------------------Action---------------------------------------------------------------------- //----------------------------------------------------------------------------------------------- public static void AddPaternCab(GameObject Cab, string patern25, string patern26, float x, float y) { // ✅ Supprimer seulement le pattern existant Transform oldPattern = Cab.transform.Find("PaternCab"); if(oldPattern != null) DestroyImmediate(oldPattern.gameObject); string catcab; if(UIT.TogOn("FILTERS")=="Ukitchenit"){catcab = UIT.Value("CabinetUkitchenit",Cab.name,"Cab_Model");} else{ catcab = UIT.Value("Cabinet",Cab.name,"Cab_Model");} string[] code25 = patern25.Split('_'); string[] code26 = patern26.Split('_'); GameObject CabImage = new("PaternCab"); // ✅ nom fixe au lieu de catcab PaternDraw.Paterns(CabImage, code25, code26, Cab.name); CabImage.transform.SetParent(Cab.transform); CabImage.transform.localPosition = new Vector3(x, y, 1.0f); CabImage.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); } // used by // Canvas/Panel_SCENE/PNL/EMPTYpnl/MODIFYER/BASECAB/TopOff // Canvas/Panel_SCENE/PNL/EMPTYpnl/MODIFYER/BASECAB/TopOn public void TopOnOff() { _G.SC[1] =name; } // used by Canvas/Panel_SCENE/PNL/CABINETpnl/BTNLIBRARY public void LibrarySelect() { string name = Get.o1("Title").GetComponent().text; SetCategory(name); if (SUB_FILTERSContainer.transform.childCount == 0) return; GameObject CAT = SUB_FILTERSContainer.transform.GetChild(0).gameObject; ShowSelections(); CAT.GetComponent().isOn = true; } public static void AddLibraryPool(string Name, GameObject pnl, int index, GameObject itemTemplate) { if (pnl.transform.childCount == 0) { if (itemTemplate == null) { Debug.LogError($"AddLibraryPool: pool '{pnl.name}' is empty and LibraryItemTemplate is not assigned in the Inspector."); return; } Instantiate(itemTemplate, pnl.transform).SetActive(false); } while (index >= pnl.transform.childCount) { GameObject clone = Instantiate(pnl.transform.GetChild(0).gameObject, pnl.transform); clone.SetActive(false); } GameObject L = pnl.transform.GetChild(index).gameObject; string nameLibrary = TRANS.This("T_" + Name); if(nameLibrary == "ERROR TXT") nameLibrary = Name; Text lbl = L.GetComponentInChildren(true); if (lbl != null) lbl.text = TRANS.Retext(nameLibrary); L.name = Name; L.SetActive(true); } public static void AddCatPool(string SubCategory, GameObject pnl, int index, string Category, GameObject itemTemplate) { if (pnl.transform.childCount == 0) { if (itemTemplate == null) { Debug.LogError($"AddCatPool: pool '{pnl.name}' is empty and CatItemTemplate is not assigned in the Inspector."); return; } Instantiate(itemTemplate, pnl.transform).SetActive(false); } while (index >= pnl.transform.childCount) { GameObject clone = Instantiate(pnl.transform.GetChild(0).gameObject, pnl.transform); clone.SetActive(false); } GameObject Cat = pnl.transform.GetChild(index).gameObject; string SubCategoryName = TRANS.CabinetSubCategory(Category, SubCategory); Text lbl = Cat.GetComponentInChildren(true); if (lbl != null) lbl.text = TRANS.Retext(SubCategoryName); Cat.name = SubCategory; Cat.SetActive(true); } }