예제 #1
0
		private static SmarterButton AttachBehaviour(InternalProp thatProp, InternalModel thatModel, string buttonName)
		{

			if (thatModel == null) {
				string[] tokens = buttonName.Split('|');
				if (tokens.Length == 2) {
					// First token is the button name, second is the prop ID.
					int propID;
					if (int.TryParse(tokens[1], out propID)) {
						if (propID < thatProp.internalModel.props.Count) {
							if (propID < 0)
								thatModel = thatProp.internalModel;
							else
								thatProp = thatProp.internalModel.props[propID];

							buttonName = tokens[0].Trim();
						} else
							Debug.LogError(string.Format("Could not find a prop with ID {0}", propID));
					}
				} else
					buttonName = buttonName.Trim();
			}
			try {
				GameObject buttonObject;
				buttonObject = thatModel == null ? thatProp.FindModelTransform(buttonName).gameObject : thatModel.FindModelTransform(buttonName).gameObject;
				SmarterButton thatComponent = buttonObject.GetComponent<SmarterButton>() ?? buttonObject.AddComponent<SmarterButton>();
				return thatComponent;
			} catch {
				Debug.LogError(string.Format(
					"Could not register a button on transform named '{0}' in {2} named '{1}'. Check your configuration.",
					buttonName, thatModel == null ? thatProp.propName : thatModel.name, thatModel == null ? "prop" : "internal model"));
			}
			return null;
		}
예제 #2
0
 public static void CreateButton(InternalProp thatProp, string buttonName, Action handlerFunction, Action releaseHandlerFunction = null, InternalModel thatModel = null)
 {
     SmarterButton buttonBehaviour;
     if ((buttonBehaviour = AttachBehaviour(thatProp, thatModel, buttonName)) == null)
     {
         return;
     }
     buttonBehaviour.clickHandlers.Add(handlerFunction);
     if (releaseHandlerFunction != null)
     {
         buttonBehaviour.releaseHandlers.Add(releaseHandlerFunction);
     }
     buttonBehaviour.part = (thatModel == null) ? thatProp.part : thatModel.part;
 }
예제 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NodeHierarchyMapping"/> class.
        /// </summary>
        /// <param name="internalModel">The inetrnal model</param>
        /// <param name="rootEntity">The root entity</param>
        public NodeHierarchyMapping(InternalModel internalModel, Entity rootEntity)
        {
            if (internalModel == null)
            {
                throw new ArgumentNullException("internalModel");
            }

            if (rootEntity == null)
            {
                throw new ArgumentNullException("rootEntity");
            }

            this.internalModel = internalModel;
            this.rootEntity    = rootEntity;

            this.ResolveHierarchy();
        }
        private void refreshVesselRooms()
        {
            Vessel      vessel    = FlightGlobals.ActiveVessel;
            List <Part> rooms     = new List <Part> ();
            List <Part> stockIVAs = new List <Part> ();

            if (vessel != null)
            {
                ProbeControlRoomUtils.Logger.message("[ProbeControlRoom] refreshVesselRooms() - scanning vessel: " + vessel.ToString());
                foreach (Part p in vessel.parts)
                {
                    ProbeControlRoomPart room = p.GetComponent <ProbeControlRoomPart> ();
                    if (room != null)
                    {
                        ProbeControlRoomUtils.Logger.debug("[ProbeControlRoom] refreshVesselRooms() - found ProbeControlRoomPart in: " + p.ToString());
                        InternalModel model = p.internalModel;
                        if (model != null)
                        {
                            ProbeControlRoomUtils.Logger.debug("[ProbeControlRoom] refreshVesselRooms() - found internalModel in: " + p.ToString());
                            rooms.Add(p);
                        }
                    }

                    InternalModel imodel = p.internalModel;
                    if (imodel != null)
                    {
                        ProbeControlRoomUtils.Logger.debug("[ProbeControlRoom] refreshVesselRooms() - found internalModel in: " + p.ToString());
                        if (p.protoModuleCrew.Count >= 1)
                        {
                            ProbeControlRoomUtils.Logger.debug("[ProbeControlRoom] refreshVesselRooms() - found internalModel in: " + p.ToString() + " - and it has crew!");
                            stockIVAs.Add(p);
                        }
                    }
                }
                ProbeControlRoomUtils.Logger.message("[ProbeControlRoom] refreshVesselRooms() - scanned vessel: " + vessel.ToString() + " - rooms: " + rooms.Count.ToString() + " - stockIVAs: " + stockIVAs.Count.ToString());
                vesselRooms     = rooms;
                vesselStockIVAs = stockIVAs;
            }
            else
            {
                ProbeControlRoomUtils.Logger.debug("[ProbeControlRoom] refreshVesselRooms() - no valid vessel");
                vesselRooms     = new List <Part> ();
                vesselStockIVAs = new List <Part> ();
            }
        }
예제 #5
0
    protected override void onPartStart()
    {
        GameObject iS = GameObject.Find("internalSpace");
        if ((defSeat != null) && (iS != null))
        {
            internalModel = new InternalModel();
            internalModel.seats = new Transform[crewCapacity];
            for (int i = 0; i < crewCapacity; i++)
            {
                internalModel.seats[i] = defSeat[i % 3];
            }

            InternalModel m = iS.transform.FindChild("mk1pod_internal").GetComponent<InternalModel>();
            m.seats = defSeat;
        }

        base.onPartStart();
    }
예제 #6
0
        public static void CreateButton(InternalProp thatProp, string buttonName, MonitorPage thatPage, Action<MonitorPage> handlerFunction, InternalModel thatModel = null)
        {
            SmarterButton buttonBehaviour;
            if ((buttonBehaviour = AttachBehaviour(thatProp, thatModel, buttonName)) == null)
            {
                return;
            }
            foreach (PageTriggerSet pageset in buttonBehaviour.pageTriggers)
            {
                if (pageset.Add(handlerFunction, thatPage))
                {
                    return;
                }
            }

            buttonBehaviour.pageTriggers.Add(new PageTriggerSet(handlerFunction, thatPage));
            buttonBehaviour.part = (thatModel == null) ? thatProp.part : thatModel.part;
        }
        public void Unload(bool force = false, bool cache = true)
        {
            if (loaded || force)
            {
                string partUrl = this.part.partInfo.partUrl;
                Loader.Log("Unloading: " + partUrl);

                if (!texCache.ContainsKey(partUrl))
                {
                    List <TexRefCnt> list = new List <TexRefCnt>();
                    foreach (Renderer mr in part.FindModelComponents <Renderer>())
                    {
                        //Loader.Log("Renderer: " + mr.name);
                        TexRefCnt.UnLoadFromRenderer(mr, force, list);
                    }

                    if (part.partInfo.internalConfig.HasData && HighLogic.LoadedSceneIsGame)
                    {
                        Loader.Log("unloading IVA: ");
                        Part iPart = fetchInternalPart();
                        if (iPart != null)
                        {
                            InternalModel internalModel = iPart.internalModel;
                            foreach (Renderer mr in internalModel.FindModelComponents <Renderer>())
                            {
                                TexRefCnt.UnLoadFromRenderer(mr, force, list);
                            }
                            GameObject.DestroyImmediate(iPart);
                        }
                    }
                    if (cache)
                    {
                        texCache[partUrl] = list;
                    }
                }
                else
                {
                    Loader.Log("Unloading from cache...");
                    List <TexRefCnt> list = texCache[partUrl];
                    TexRefCnt.UnLoadFromList(list, force);
                }
                loaded = false;
            }
        }
예제 #8
0
        public static void CreateButton(InternalProp thatProp, string buttonName, int numericID, Action<int> clickHandlerFunction, Action<int> releaseHandlerFunction, InternalModel thatModel = null)
        {
            SmarterButton buttonBehaviour;
            if ((buttonBehaviour = AttachBehaviour(thatProp, thatModel, buttonName)) == null)
            {
                return;
            }

            buttonBehaviour.clickHandlersID.Add(new HandlerID
            {
                function = clickHandlerFunction,
                idValue = numericID
            });
            buttonBehaviour.releaseHandlersID.Add(new HandlerID
            {
                function = releaseHandlerFunction,
                idValue = numericID
            });
            buttonBehaviour.part = (thatModel == null) ? thatProp.part : thatModel.part;
        }
예제 #9
0
        private bool PartHasSeats(string partName)
        {
            AvailablePart partInfoByName = PartLoader.getPartInfoByName(partName);
            InternalModel internalModel  = null;

            if (partInfoByName != null)
            {
                string name = string.Empty;
                if (partInfoByName.internalConfig.HasValue("name"))
                {
                    name = partInfoByName.internalConfig.GetValue("name");
                }
                foreach (InternalModel current in PartLoader.Instance.internalParts)
                {
                    if (current.internalName == name)
                    {
                        internalModel = current;
                        break;
                    }
                }
            }
            return(internalModel != null && internalModel.seats != null && internalModel.seats.Count > 0);
        }
예제 #10
0
        protected Model_Should()
        {
            ModelType = InternalModel.TypeFor(InterfaceType);
            var tmp = InterfaceType
                      .GetProperties(BindingFlags.Public | BindingFlags.Instance)
                      .OrderBy(x => x.Name)
                      .Select(x => new PropInfo()
            {
                Property = x
            })
                      .ToArray();

            foreach (var p in tmp)
            {
                var sib  = ModelType.GetProperty(p.Property.Name);
                var attr = sib?.GetCustomAttribute <JsonPropertyAttribute>();
                p.Name        = attr?.PropertyName ?? p.Property.Name;
                p.Deserialize = p.Property.CanRead && (sib.GetCustomAttribute <JsonIgnoreAttribute>() is null);
                p.Serialize   = p.Deserialize && p.Property.CanWrite;
            }

            Properties = tmp.Cast <IPropInfo>().ToArray();
        }
예제 #11
0
        // Can be safely called multiple times for the same part.
        public static void AddPropHatches(InternalModel internalModel)
        {
            Debug.Log("# Adding prop hatch for " + internalModel.part);

            if (internalModel == null)
            {
                Debug.LogWarning("Unable to create prop hatches: internal model was null");
                return;
            }

            int propCount = internalModel.props.Count; // This list will be added to in the loop below.

            for (int i = 0; i < propCount; i++)
            {
                InternalProp prop = internalModel.props[i];
                if (prop.name == "Hatch_Plane" && !HatchInitialised(prop)) // TODO: Generalise this.
                {
                    Debug.Log("# Found Hatch_Plane");
                    InternalProp openHatch = PartLoader.GetInternalProp("Hatch_Plane_Frame");
                    openHatch.propID        = FreeIva.CurrentPart.internalModel.props.Count;
                    openHatch.internalModel = FreeIva.CurrentPart.internalModel;
                    //openHatch.get_transform().set_parent(base.get_transform()); TODO: Set parent
                    openHatch.hasModel = true;
                    internalModel.props.Add(openHatch);
                    openHatch.transform.rotation = prop.transform.rotation;
                    openHatch.transform.position = prop.transform.position;

                    MeshRenderer mr = openHatch.GetComponentInChildren <MeshRenderer>();
                    mr.enabled = false;

                    PropHatch propHatch = new PropHatch();
                    propHatch.ClosedProp = prop;
                    propHatch.OpenProp   = openHatch;
                    PropHatches.Add(propHatch);
                }
            }
        }
예제 #12
0
        public void FocusIVAWindow()
        {
            switch (CameraManager.Instance.currentCameraMode)
            {
            case CameraManager.CameraMode.IVA:
            {
                Kerbal kerbal = GetActiveIVAKerbal();

                if (kerbal != null && kerbal.InPart != null && kerbal.InPart.internalModel != null)
                {
                    //Debug.Log("Kerbal: " + kerbal.crewMemberName + " inside "+ kerbal.InPart.internalModel.internalName);
                    InternalModel intModel     = kerbal.InPart.internalModel;
                    Transform     camTransform = InternalCamera.Instance.transform;
                    Ray           ray          = new Ray(camTransform.position, camTransform.forward);
                    RaycastHit    hit;
                    if (Physics.Raycast(ray, out hit, 5f))
                    {
                        //Debug.Log("RaycastHit: " + hit.collider.name + " (dist: " + hit.distance + ")");
                        foreach (InternalCameraSwitch intCam in intModel.FindModelComponents <InternalCameraSwitch>())
                        {
                            if (hit.collider.name.Equals(intCam.colliderTransformName))
                            {
                                intCam.Button_OnDoubleTap();
                            }
                        }
                    }
                }
                break;
            }

            case CameraManager.CameraMode.Internal:
            {
                CameraManager.Instance.SetCameraIVA();
                break;
            }
            }
        }
예제 #13
0
        private void Load()
        {
            if (!loaded)
            {
                string partUrl = this.part.partInfo.partUrl;

                Loader.Log("Loading: " + partUrl);

                foreach (Renderer mr in part.FindModelComponents <Renderer>())
                {
                    Loader.Log("Renderer: " + mr.name);
                    TexRefCnt.LoadFromRenderer(mr);
                }

                if (!internalCache.ContainsKey(partUrl))
                {
                    if (part.partInfo.internalConfig.HasData && HighLogic.LoadedSceneIsGame)
                    {
                        Part             iPart         = fetchInternalPart();
                        InternalModel    internalModel = iPart.internalModel;
                        List <TexRefCnt> list          = new List <TexRefCnt>();
                        foreach (Renderer mr in internalModel.FindModelComponents <Renderer>())
                        {
                            TexRefCnt.LoadFromRenderer(mr, list);
                        }
                        internalCache[partUrl] = list;
                        GameObject.DestroyImmediate(iPart);
                    }
                }
                else
                {
                    List <TexRefCnt> list = internalCache[partUrl];
                    TexRefCnt.LoadFromList(list);
                }
                loaded = true;
            }
        }
예제 #14
0
        public static void CreateButton(InternalProp thatProp, string buttonName, Action handlerFunction, Action releaseHandlerFunction = null, InternalModel thatModel = null)
        {
            SmarterButton buttonBehaviour;

            if ((buttonBehaviour = AttachBehaviour(thatProp, thatModel, buttonName)) == null)
            {
                return;
            }
            buttonBehaviour.clickHandlers.Add(handlerFunction);
            if (releaseHandlerFunction != null)
            {
                buttonBehaviour.releaseHandlers.Add(releaseHandlerFunction);
            }
        }
예제 #15
0
        public static void CreateButton(InternalProp thatProp, string buttonName, int numericID, Action <int> clickHandlerFunction, Action <int> releaseHandlerFunction, InternalModel thatModel = null)
        {
            SmarterButton buttonBehaviour;

            if ((buttonBehaviour = AttachBehaviour(thatProp, thatModel, buttonName)) == null)
            {
                return;
            }

            buttonBehaviour.clickHandlersID.Add(new HandlerID {
                function = clickHandlerFunction,
                idValue  = numericID
            });
            buttonBehaviour.releaseHandlersID.Add(new HandlerID {
                function = releaseHandlerFunction,
                idValue  = numericID
            });
        }
예제 #16
0
        public static void CreateButton(InternalProp thatProp, string buttonName, MonitorPage thatPage, Action <MonitorPage> handlerFunction, InternalModel thatModel = null)
        {
            SmarterButton buttonBehaviour;

            if ((buttonBehaviour = AttachBehaviour(thatProp, thatModel, buttonName)) == null)
            {
                return;
            }
            foreach (PageTriggerSet pageset in buttonBehaviour.pageTriggers)
            {
                if (pageset.Add(handlerFunction, thatPage))
                {
                    return;
                }
            }

            buttonBehaviour.pageTriggers.Add(new PageTriggerSet(handlerFunction, thatPage));
        }
예제 #17
0
    protected override void onPartStart()
    {
        stackIcon.SetIcon(DefaultIcons.ADV_SAS);

        GameObject iS = GameObject.Find("internalSpace");
        if (iS != null)
        {
            InternalModel m = iS.transform.FindChild("mk1pod_internal").GetComponent<InternalModel>();
            if (m.seats.Length == 0)
            {
                m.seats = defSeat;
            }

            internalModel = new InternalModel();
        }

        core.part = this;
        core.onPartStart();

        base.onPartStart();

        if (transform.Find("model/base/eye") == null)
        {
            return;
        }

        brain[0] = (GameObject)GameObject.Instantiate(Resources.Load("Effects/fx_exhaustFlame_blue"));
        brain[0].name = "brain_FX";
        brain[0].transform.parent = transform.Find("model");
        brain[0].transform.localPosition = new Vector3(0, -0.2F, 0);
        brain[0].transform.localRotation = Quaternion.AngleAxis(45, Vector3.up);

        brain[0].particleEmitter.emit = false;
        brain[0].particleEmitter.maxEmission = brain[0].particleEmitter.minEmission = 0;
        brain[0].particleEmitter.maxEnergy = 0.75F;
        brain[0].particleEmitter.minEnergy = 0.25F;
        brain[0].particleEmitter.maxSize = brain[0].particleEmitter.minSize = 0.1F;
        brain[0].particleEmitter.localVelocity = Vector3.zero;
        brain[0].particleEmitter.rndVelocity = new Vector3(0.3F, 0.3F, 3.0F);
        brain[0].particleEmitter.useWorldSpace = false;

        brain[1] = (GameObject)GameObject.Instantiate(brain[0]);
        brain[1].transform.parent = transform.Find("model");
        brain[1].transform.localPosition = new Vector3(0, -0.2F, 0);
        brain[1].transform.localRotation = Quaternion.AngleAxis(-45, Vector3.up);
    }
예제 #18
0
            internal JSIIntLight(ConfigNode node, RPMVesselComputer comp, InternalModel internalModel)
                : base(node)
            {
                if (!node.HasValue("internalLightName"))
                {
                    throw new Exception("Unable to configure IJSIAction intlight without 'internalLightName'");
                }

                string internalLightName = node.GetValue("internalLightName");

                if (node.HasValue("persistentVarName"))
                {
                    persistentVarName = node.GetValue("persistentVarName");
                    if (string.IsNullOrEmpty(persistentVarName))
                    {
                        throw new Exception("Invalid persistentVarName supplied for internal light " + internalLightName);
                    }
                }
                else
                {
                    persistentVarName = internalLightName;
                }

                Light[] availableLights = internalModel.FindModelComponents <Light>();
                if (availableLights != null && availableLights.Length > 0)
                {
                    List <Light> lights = new List <Light>(availableLights);
                    for (int i = lights.Count - 1; i >= 0; --i)
                    {
                        if (lights[i].name != internalLightName)
                        {
                            lights.RemoveAt(i);
                        }
                    }
                    if (lights.Count > 0)
                    {
                        lightObjects = lights.ToArray();
                    }
                }

                if (lightObjects == null)
                {
                    throw new Exception("No lights with name " + internalLightName + " were found for JSISwitch intlight");
                }

                if (node.HasValue("needsElectricCharge"))
                {
                    bool.TryParse(node.GetValue("needsElectricCharge"), out needsElectricCharge);
                }

                bool initialState = false;

                if (node.HasValue("initialState"))
                {
                    bool.TryParse(node.GetValue("initialState"), out initialState);
                }

                comp.GetPersistentVariable(persistentVarName, initialState);
                currentState = initialState;
                comp.SetPersistentVariable(persistentVarName, currentState);

                SetInternalLights(currentState);
            }
예제 #19
0
 public VslFrzrCams(Transform frzrcamTransform, InternalModel frzrcamModel, int frzrcamSeatIndex, string frzrcamPartName, DeepFreezer frzrcamPart)
 {
     FrzrCamTransform = frzrcamTransform;
     FrzrCamModel = frzrcamModel;
     FrzrCamSeatIndex = frzrcamSeatIndex;
     FrzrCamPartName = frzrcamPartName;
     FrzrCamPart = frzrcamPart;
 }