private void HandleAwake() { instance = this; Log.dbg("Platform is {0}", Application.platform); initConfig(); this.state = DisplayState.none; _editorErrorDial = new Rect(Screen.width / 2 - Constants.guiDialogX, Screen.height / 2 - Constants.guiDialogY, Constants.guiDialogW, Constants.guiDialogH); _editorWarningDial = new Rect(Screen.width / 2 - Constants.guiDialogX, Screen.height / 2 - Constants.guiDialogY, Constants.guiDialogW, Constants.guiDialogH); _editorInfoWindow = new Rect(Screen.width / 2 - Constants.guiInfoWindowX, Screen.height / 2 - Constants.guiInfoWindowY, Constants.guiInfoWindowW, Constants.guiInfoWindowH); _editorOverwriteDial = new Rect(Screen.width / 2 - Constants.guiDialogX, Screen.height / 2 - Constants.guiDialogY, Constants.guiDialogW, Constants.guiDialogH); _editorSavedDial = new Rect(Screen.width / 2 - Constants.guiDialogX, Screen.height / 2 - Constants.guiDialogY, Constants.guiDialogW, Constants.guiDialogH); _editorMainWindow = new Rect(_config.MainWindowXPosition, _config.MainWindowYPosition, Constants.guiMainWindowW, Constants.guiMainWindowH); _catNames = WeldingHelpers.initPartCategories(_catNames); _guiStyle = WeldingHelpers.initGuiStyle(_guiStyle); _catDropdown = WeldingHelpers.initDropDown(_catNames, _guiStyle, _catDropdown); DatabaseHandler.initMMAssembly(); }
/* * Called once everything in scene is loaded */ public void Start() { _catNames = new List <GUIContent>(); List <string> catlist = new List <string>(System.Enum.GetNames(typeof(PartCategories))); catlist.Remove(PartCategories.none.ToString()); foreach (string cat in catlist) { _catNames.Add(new GUIContent(cat)); } _catListStyle = new GUIStyle(); _catListStyle.normal.textColor = Color.white; _catListStyle.onHover.background = _catListStyle.hover.background = new Texture2D(2, 2); _catListStyle.padding.left = _catListStyle.padding.right = _catListStyle.padding.top = _catListStyle.padding.bottom = 1; _catDropdown = new GUIDropdown(_catNames[0], _catNames.ToArray(), "button", "box", _catListStyle); }
/* * Called when plug in loaded */ public void Awake() { instance = this; Debug.Log(string.Format("{0}- {1} => Awake", Constants.logPrefix, instance.GetType())); Debug.Log(string.Format("{0} Platform is {1}", Constants.logPrefix, Application.platform)); initConfig(); _state = DisplayState.none; _editorErrorDial = new Rect(Screen.width / 2 - Constants.guiDialogX, Screen.height / 2 - Constants.guiDialogY, Constants.guiDialogW, Constants.guiDialogH); _editorWarningDial = new Rect(Screen.width / 2 - Constants.guiDialogX, Screen.height / 2 - Constants.guiDialogY, Constants.guiDialogW, Constants.guiDialogH); _editorInfoWindow = new Rect(Screen.width / 2 - Constants.guiInfoWindowX, Screen.height / 2 - Constants.guiInfoWindowY, Constants.guiInfoWindowW, Constants.guiInfoWindowH); _editorOverwriteDial = new Rect(Screen.width / 2 - Constants.guiDialogX, Screen.height / 2 - Constants.guiDialogY, Constants.guiDialogW, Constants.guiDialogH); _editorSavedDial = new Rect(Screen.width / 2 - Constants.guiDialogX, Screen.height / 2 - Constants.guiDialogY, Constants.guiDialogW, Constants.guiDialogH); _editorMainWindow = new Rect(_config.MainWindowXPosition, _config.MainWindowYPosition, Constants.guiMainWindowW, Constants.guiMainWindowH); _catNames = WeldingHelpers.initPartCategories(_catNames); _guiStyle = WeldingHelpers.initGuiStyle(_guiStyle); _catDropdown = WeldingHelpers.initDropDown(_catNames, _guiStyle, _catDropdown); DatabaseHandler.initMMAssembly(); }
/// <summary> /// creates a new dropdownmenu list for the techs that are required for the current welding part. /// </summary> /// <param name="techList"></param> /// <param name="guiStyle"></param> /// <param name="dropDown"></param> /// <returns></returns> public static GUIDropdown initTechDropDown(List <string> techList, GUIStyle guiStyle, GUIDropdown dropDown) { List <GUIContent> contentList = new List <GUIContent>(); List <RDTech> rdTechs = AssetBase.RnDTechTree.GetTreeTechs().ToList(); Debug.Log(string.Format("{0} rdTechs.Count = {1}", Constants.logPrefix, rdTechs.Count())); foreach (string techID in techList) { string techTitle = techID; //for case, when techID will not be found - the length of the list of titles always must match the length of the list of techID's. foreach (RDTech rdTech in rdTechs) { if (rdTech.techID == techID) { techTitle = rdTech.title; break; } } contentList.Add(new GUIContent(techTitle)); } dropDown = new GUIDropdown(contentList[0], contentList.ToArray(), "button", "box", guiStyle); return(dropDown); }
/// <summary> /// creates a new dropdownmenu list for the techs that are required for the current welding part. /// </summary> /// <param name="techList"></param> /// <param name="guiStyle"></param> /// <param name="dropDown"></param> /// <returns></returns> public static GUIDropdown initTechDropDown(List <string> techList, GUIStyle guiStyle, GUIDropdown dropDown) { List <GUIContent> contentList = new List <GUIContent>(); List <ProtoTechNode> rdTechs = AssetBase.RnDTechTree.GetTreeTechs().ToList(); Log.dbg("rdTechs.Count = {0}", rdTechs.Count()); foreach (string techID in techList) { string techTitle = techID; //for case, when techID will not be found - the length of the list of titles always must match the length of the list of techID's. foreach (ProtoTechNode rdTech in rdTechs) { if (rdTech.techID == techID) { techTitle = rdTech.techID; break; } } contentList.Add(new GUIContent(techTitle)); } dropDown = new GUIDropdown(contentList[0], contentList.ToArray(), "button", "box", guiStyle, 3); return(dropDown); }
/// <summary> /// creates a new dropdownmenu list for the techs that are required for the current welding part. /// </summary> /// <param name="techList"></param> /// <param name="guiStyle"></param> /// <param name="dropDown"></param> /// <returns></returns> public static GUIDropdown initVesselTypeDropDown(List <string> vesselTypeList, GUIStyle guiStyle, GUIDropdown dropDown) { List <GUIContent> contentList = new List <GUIContent>(); List <string> allVesselTypes = new List <string>(System.Enum.GetNames(typeof(VesselType))); Log.dbg("vessel types Count = {0}", vesselTypeList.Count()); foreach (string vesselTypeID in vesselTypeList) { string vesselTypeTitle = vesselTypeID; //for case, when techID will not be found - the length of the list of titles always must match the length of the list of techID's. foreach (String vesselType in allVesselTypes) { if (vesselType == vesselTypeID) { vesselTypeTitle = vesselType; break; } } contentList.Add(new GUIContent(vesselTypeTitle)); } dropDown = new GUIDropdown(contentList[0], contentList.ToArray(), "button", "box", guiStyle, 3); return(dropDown); }
/// <summary> /// prepares the dropdownlist for a given list of GUIContents /// </summary> /// <param name="categoryList"></param> /// <param name="guiStyle"></param> /// <param name="dropDown"></param> /// <returns></returns> public static GUIDropdown initDropDown(List <GUIContent> categoryList, GUIStyle guiStyle, GUIDropdown dropDown) { dropDown = new GUIDropdown(categoryList[0], categoryList.ToArray(), "button", "box", guiStyle, 3); return(dropDown); }
} //private void OnDraw() private void weldPart(Part partToWeld) { //Lock editor EditorLockManager.lockEditor(Constants.settingWeldingLock); //process the welding #if (DEBUG) Debug.ClearDeveloperConsole(); Log.info("{0}", Constants.logVersion); Log.info("{0}", Constants.logStartWeld); #endif bool warning = false; _welder = new Welder(); _welder.init(); partToWeld.transform.eulerAngles = Vector3.zero; WeldingReturn ret = 0; if (!WeldingHelpers.DoesTextContainRegex(partToWeld.name, "strutConnector")) { ret = _welder.weldThisPart(partToWeld); } if (ret < 0) { Log.dbg("{0}", Constants.logEndWeld); this.state = DisplayState.weldError; return; } else { warning = warning || (0 < ret); } Part[] children = partToWeld.FindChildParts <Part>(true); if (children != null) { foreach (Part child in children) { if (!WeldingHelpers.DoesTextContainRegex(child.name, "strutConnector")) { ret = _welder.weldThisPart(child); } if (ret < 0) { Log.dbg("{0}", Constants.logEndWeld); this.state = DisplayState.weldError; return; } else { warning = warning || (0 < ret); } } } _welder.processNewCoM(); _welder.prepDecals(_welder.moduleList); if (_welder.isMeshSwitchRequired) { _welder.prepareWeldedMeshSwitchModule(_welder.moduleList); } _techDropdown = WeldingHelpers.initTechDropDown(_welder.techList, _guiStyle, _techDropdown); if (_welder.vesselTypeList.Count > 0) { _vesselTypeDropdown = WeldingHelpers.initVesselTypeDropDown(_welder.vesselTypeList, _guiStyle, _vesselTypeDropdown); } _scrollMod = Vector2.zero; _scrollRes = Vector2.zero; Log.dbg("| {0} Parts welded", _welder.NbParts); if (warning) { Log.dbg(Constants.logEndWeld); this.state = DisplayState.weldWarning; } else { Log.dbg("welder.Category: {0}", (int)_welder.Category); _catDropdown.SelectedItemIndex = (int)_welder.Category; this.state = DisplayState.infoWindow; } }
} //private void OnDraw() private void weldPart(Part partToWeld) { //Lock editor EditorLogic.fetch.Lock(true, true, true, Constants.settingWeldingLock); //process the welding #if (DEBUG) Debug.ClearDeveloperConsole(); Debug.Log(string.Format("{0}{1}", Constants.logPrefix, Constants.logVersion)); Debug.Log(string.Format("{0}{1}", Constants.logPrefix, Constants.logStartWeld)); #endif bool warning = false; _welder = new Welder(); partToWeld.transform.eulerAngles = Vector3.up; WeldingReturn ret = _welder.weldThisPart(partToWeld); if (ret < 0) { #if (DEBUG) Debug.Log(string.Format("{0}{1}", Constants.logPrefix, Constants.logEndWeld)); #endif _state = DisplayState.weldError; return; } else { warning = warning || (0 < ret); } Part[] children = partToWeld.FindChildParts <Part>(true); if (children != null) { foreach (Part child in children) { ret = _welder.weldThisPart(child); if (ret < 0) { #if (DEBUG) Debug.Log(string.Format("{0}{1}", Constants.logPrefix, Constants.logEndWeld)); #endif _state = DisplayState.weldError; return; } else { warning = warning || (0 < ret); } } } _welder.processNewCoM(); _techDropdown = WeldingHelpers.initTechDropDown(_welder.techList, _catListStyle, _techDropdown); _scrollMod = Vector2.zero; _scrollRes = Vector2.zero; #if (DEBUG) Debug.Log(string.Format("{0} {1} | {2} Parts welded", Constants.logPrefix, Constants.logEndWeld, _welder.NbParts)); #endif if (warning) { Debug.Log(string.Format("{0} {1} | Warning", Constants.logPrefix, Constants.logEndWeld)); _state = DisplayState.weldWarning; } else { _catDropdown.SelectedItemIndex = (int)_welder.Category; _state = DisplayState.infoWindow; } }