示例#1
0
        public void onAppTrue()
        {
            string errMsg = InSituation.NetworkEligible(FlightGlobals.ActiveVessel);

            if (!String.IsNullOrEmpty(errMsg))
            {
                Logs.msg(errMsg); //"Must be landed to use logistics"
                return;
            }

            GUIactive = true;
        }
示例#2
0
        internal virtual void onToggle()
        {
            string errMsg = InSituation.NetworkEligible(FlightGlobals.ActiveVessel);

            if (!String.IsNullOrEmpty(errMsg))
            {
                Logs.msg(errMsg);                 //"Must be landed to use logistics"
                return;
            }

            GUIactive = !GUIactive;
            if (!GUIactive)
            {
                refreshGUI = true;
                UnlockControls();
            }
        }
示例#3
0
        public void OnGUI()
        {
            if (gamePaused || GUIglobalHidden || !GUIactive)
            {
                return;
            }

            string IsEligible = InSituation.NetworkEligible(FlightGlobals.ActiveVessel);

            if (!String.IsNullOrEmpty(IsEligible))
            {
                toolbarControl.SetFalse();
                Logs.msg(IsEligible);
            }

            if (refreshGUI)
            {
                windowRect.height = 0;
                refreshGUI        = false;
            }

            if (HighLogic.CurrentGame.Parameters.CustomParams <OptionsA>().useAlternateSkin)
            {
                GUI.skin = HighLogic.Skin;
            }
            GUI.backgroundColor = titleBackColor;
            GUI.contentColor    = titleColor;
            windowRect          = ClickThruBlocker.GUILayoutWindow(
                windowId,
                windowRect,
                DrawGUI,
                Localizer.Format("#SimpleLogistics_WindowTitle", Version.Text), //"Logistics Network v "
                GUILayout.ExpandWidth(true),
                GUILayout.ExpandHeight(true)
                );
            if (windowRect.Contains(Event.current.mousePosition))
            {
                LockControls();
            }
            else
            {
                UnlockControls();
            }
        }
示例#4
0
        private void FixedUpdate()
        {
            // Find all resources in the network
            partResources.Clear();
            foreach (Vessel vessel in FlightGlobals.VesselsLoaded)
            {
                if (!String.IsNullOrEmpty(InSituation.NetworkEligible(vessel)))
                {
                    Logs.dbg("{0} ineligible\n", vessel.GetDisplayName());
                    continue;
                }

                LogisticsModule lm = vessel.FindPartModuleImplementing <LogisticsModule> ();
                if (lm != null && !lm.IsActive)
                {
                    Logs.dbg("{0} not pluged in\n", vessel.GetDisplayName());
                    continue;
                }

                foreach (Part part in vessel.parts)
                {
                    if (part.State == PartStates.DEAD)
                    {
                        Logs.dbg("{0} is dead on {1}\n", part.partName, vessel.GetDisplayName());
                        continue;
                    }

                    foreach (PartResource resource in part.Resources)
                    {
                        if (resource.info.resourceTransferMode == ResourceTransferMode.NONE ||
                            resource._flowMode == PartResource.FlowMode.None ||
                            !resource._flowState)
                        {
                            Logs.dbg("{3}'s {2}'s {1} can't flow", resource.resourceName, part.partName, vessel.vesselName);
                            continue;
                        }

                        partResources.Add(resource);
                    }
                }
            }

            // Create a resource pool
            resourcePool.Clear();
            foreach (var resource in partResources)
            {
                if (!resourcePool.ContainsKey(resource.info.name))
                {
                    resourcePool.Add(resource.info.name, resource.amount);
                }
                else
                {
                    resourcePool [resource.info.name] += resource.amount;
                }
            }

            // Spread resources evenly
            foreach (var resource in resourcePool)
            {
                double value = resource.Value;
                if (requested)
                {
                    if (requestPool.ContainsKey(resource.Key))
                    {
                        value -= requestPool [resource.Key];
                    }
                }

                var resList = partResources.FindAll(r => r.info.name == resource.Key);

                // Don't waste time on single one
//				if (resList.Count == 1)
//					continue;

                ShareResource(resList, value);
            }

            if (requested)
            {
                TransferResources();
                requested = false;
            }
        }