// emulate CrewHatchController, which uses LateUpdate(), not Update() private void LateUpdate() { if (hijack) { considerHijack(); } if (Mouse.CheckButtons(Mouse.GetAllMouseButtonsDown(), Mouse.Buttons.Left) && FlightUIModeController.Instance.Mode != FlightUIMode.ORBITAL) { modclick = modkey.GetKey(); if ((modclick || useCTI) && Physics.Raycast(FlightCamera.fetch.mainCamera.ScreenPointToRay(Input.mousePosition), out hit, RAYCAST_DIST, 1 << LAYER_PARTTRIGGER, QueryTriggerInteraction.Collide)) { if (hit.collider.CompareTag(TAG_AIRLOCK)) { if (InputLockManager.IsAllLocked(ControlTypes.KEYBOARDINPUT)) { Debug.Log("[AirlockPlus] INFO: " + (modclick?"mod+":"") + "click detected on airlock, but input lock is active."); Debug.Log(InputLockManager.PrintLockStack()); } else { Debug.Log("[AirlockPlus] INFO: " + (modclick?"mod+":"") + "click detected on airlock, standing by to hijack CrewHatchDialog."); airlock = hit.collider; hijack = true; chd = null; frame = 0; } } } } }
private void doHijack() { Debug.Log("[AirlockPlus] INFO: hijacking CrewHatchDialog for airlock " + airlock.gameObject.name + " on part " + airlockPart.partInfo.name + " of " + airlockPart.vessel.vesselName); // TextHeader chd.transform.GetChild(0).GetComponent <TextMeshProUGUI>().text = Localizer.Format("#autoLOC_AirlockPlus00000"); // Content transform of Scroll View Transform listContainer = chd.GetComponentInChildren <ContentSizeFitter>().transform; // Wipe the slate clean for (int i = listContainer.childCount - 1; i > 0; i--) { listContainer.GetChild(i).gameObject.SetActive(false); } // EmptyModuleText if (airlockPart.vessel.GetCrewCount() == 0) { listContainer.GetChild(0).gameObject.SetActive(true); chd = null; return; } listContainer.GetChild(0).gameObject.SetActive(false); // Crew in airlock part addCrewToList(listContainer, airlockPart); if (useCLS) { // Crew in other parts ICLSSpace clsSpace = CLSClient.GetCLS().getCLSVessel(airlockPart.vessel).Parts.Find(x => x.Part == airlockPart).Space; foreach (ICLSPart p in clsSpace.Parts) { if (p.Part != airlockPart) { addCrewToList(listContainer.transform, p.Part); } } // TextModuleCrew chd.transform.GetChild(2).GetComponent <TextMeshProUGUI>().text = Localizer.Format("#autoLOC_AirlockPlusAP001", clsSpace.Crew.Count, clsSpace.MaxCrew); } else { // Crew in other parts foreach (Part p in airlockPart.vessel.parts) { if (p != airlockPart) { addCrewToList(listContainer.transform, p); } } // TextModuleCrew chd.transform.GetChild(2).GetComponent <TextMeshProUGUI>().text = Localizer.Format("#autoLOC_AirlockPlusAP001", airlockPart.vessel.GetCrewCount(), airlockPart.vessel.GetCrewCapacity()); } chd = null; }
private void OnCrewTransferPartListCreated(GameEvents.HostedFromToAction <Part, List <Part> > eventData) { if (_allowUnrestrictedTransfers) { return; } // How can I tell if the parts are in the same space?... I need a starting point! What part initiated the event? Part sourcePart = null; // Get the Dialog and find the source part. CrewHatchDialog dialog = Resources.FindObjectsOfTypeAll <CrewHatchDialog>().FirstOrDefault(); if (dialog?.Part == null) { return; } sourcePart = dialog.Part; ICLSPart clsFrom = Instance.Vessel.Parts.Find(x => x.Part == sourcePart); //Let's manhandle the lists List <Part> fullList = new List <Part>(); List <Part> .Enumerator fromList = eventData.from.GetEnumerator(); while (fromList.MoveNext()) { if (fromList.Current == null) { continue; } ICLSPart clsTo = Instance.Vessel.Parts.Find(x => x.Part == fromList.Current); // If in same space, ignore if (clsFrom != null && clsTo != null && clsFrom.Space == clsTo.Space) { continue; } fullList.Add(fromList.Current); } fromList.Dispose(); if (fullList.Count <= 0) { return; } //CrewTransfer.fullMessage = "<color=orange>CLS - This module is either full or internally unreachable.</color>"; List <Part> .Enumerator removeList = fullList.GetEnumerator(); while (removeList.MoveNext()) { eventData.from.Remove(removeList.Current); } removeList.Dispose(); eventData.to.AddRange(fullList); }
private void considerHijack() { frame++; Debug.Log("[AirlockPlus] INFO: considering hijack @ frame +" + frame); // can't do anything if CrewHatchController isn't active yet if (!CrewHatchController.fetch.Active) { // abort if CrewHatchController still isn't active after FRAMEWAIT -- e.g. player may have cancelled by clicking elsewhere if (frame > FRAMEWAIT) { Debug.Log("[AirlockPlus] INFO: CrewHatchController is still inactive, aborting hijack."); hijack = false; chd = null; frame = 0; } return; } // fetch CrewHatchDialog if (chd == null) { chd = CrewHatchController.fetch.CrewDialog; if (chd == null) { Debug.Log("[AirlockPlus] ERROR: failed to obtain CrewHatchDialog."); return; } } // test if TextHeader has been changed from its placeholder value, as proxy indicator for CrewHatchDialog "done populating" if (CHD_NOTREADY_HEADER.Equals(chd.transform.GetChild(0).GetComponent <TextMeshProUGUI>().text)) { return; } // stock KSP done setting up CrewHatchDialog contents, proceed with hijacking airlockPart = airlock.GetComponentInParent <Part>(); if (modclick) { doHijack(); } else { doAugment(); } hijack = false; frame = 0; }
private void doAugment() { Debug.Log("[AirlockPlus] INFO: augmenting CrewHatchDialog for airlock " + airlock.gameObject.name + " on part " + airlockPart.partInfo.name + " of " + airlockPart.vessel.vesselName); // Content transform of Scroll View Transform listContainer = chd.GetComponentInChildren <ContentSizeFitter>().transform; // Add icons for (int i = listContainer.childCount - 1; i > 0; i--) { GameObject icon = CTIWrapper.CTI.getTrait(listContainer.GetChild(i).GetComponent <CrewHatchDialogWidget>().protoCrewMember.experienceTrait.TypeName).makeGameObject(); LayoutElement elem = icon.AddComponent <LayoutElement>(); elem.minWidth = elem.minHeight = elem.preferredWidth = elem.preferredHeight = 20; icon.transform.SetParent(listContainer.GetChild(i).transform, false); icon.transform.SetAsFirstSibling(); icon.SetActive(true); } chd = null; }