示例#1
0
        private void FixedUpdate()
        {
            // Find all resources in the network
            partResources.Clear();
            foreach (Vessel vessel in FlightGlobals.VesselsLoaded)
            {
                if (vessel.situation != Vessel.Situations.LANDED)
                {
                    continue;
                }

                LogisticsModule lm = vessel.FindPartModuleImplementing <LogisticsModule> ();
                if (lm != null)
                {
                    if (!lm.IsActive)
                    {
                        continue;
                    }
                }

                foreach (Part part in vessel.parts)
                {
                    if (part.State == PartStates.DEAD)
                    {
                        continue;
                    }

                    foreach (PartResource resource in part.Resources)
                    {
                        if (resource.info.resourceTransferMode == ResourceTransferMode.NONE ||
                            resource._flowMode == PartResource.FlowMode.None ||
                            !resource._flowState)
                        {
                            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;
            }
        }
示例#2
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;
            }
        }
示例#3
0
        // It's a mess
        private void DrawGUI(int windowId)
        {
            GUILayout.BeginVertical();
            Layout.LabelAndText(Localizer.Format("#SimpleLogistics_Label1"), Localizer.Format(FlightGlobals.ActiveVessel.RevealName())); //"Current Vessel"

            bool ableToRequest = false;

            LogisticsModule lm = FlightGlobals.ActiveVessel.FindPartModuleImplementing <LogisticsModule> ();

            if (lm != null)
            {
                Layout.Label(
                    lm.IsActive ? Localizer.Format("#SimpleLogistics_Label2") : Localizer.Format("#SimpleLogistics_Label3"), //"Pluged In""Unplugged"
                    lm.IsActive ? Palette.green : Palette.red
                    );

                // "Toggle Plug"
                if (Layout.Button(Localizer.Format("#SimpleLogistics_Label4"), Palette.yellow))
                {
                    lm.Set(!lm.IsActive);
                    refresh = true;
                }
                ableToRequest = !lm.IsActive;
            }

            if (ableToRequest)
            {
                GetVesselSpareSpace();
            }

            Layout.LabelCentered(Localizer.Format("#SimpleLogistics_Label5"), Palette.yellow); //"Resource Pool:"

            foreach (var resource in resourcePool)
            {
                GUILayout.BeginHorizontal();
                Layout.Label(resource.Key, Palette.yellow, GUILayout.Width(170));
                if (ableToRequest && requestPool.ContainsKey(resource.Key))
                {
                    Layout.Label(requestPool[resource.Key].ToString("0.00") + " / " +
                                 resource.Value.ToString("0.00"));
                }
                else
                {
                    Layout.Label(resource.Value.ToString("0.00"));
                }

                GUILayout.EndHorizontal();
                if (ableToRequest && requestPool.ContainsKey(resource.Key))
                {
                    GUILayout.BeginHorizontal();
                    if (Layout.Button("0", GUILayout.Width(20)))
                    {
                        requestPool [resource.Key] = 0;
                    }

                    requestPool [resource.Key] = Layout.HorizontalSlider(
                        requestPool [resource.Key],
                        0,
                        Math.Min(vesselSpareSpace [resource.Key], resource.Value),
                        GUILayout.Width(280)
                        );
                    if (Layout.Button(vesselSpareSpace [resource.Key].ToString("0.00")))
                    {
                        requestPool [resource.Key] = Math.Min(vesselSpareSpace [resource.Key], resource.Value);
                    }

                    GUILayout.EndHorizontal();
                }
            }

            if (ableToRequest)
            {
                // "Request Resources"
                if (Layout.Button(Localizer.Format("#SimpleLogistics_Label6")))
                {
                    requested = true;
                }
            }

            //"Close"
            if (Layout.Button(Localizer.Format("#SimpleLogistics_Label7"), Palette.red))
            {
#if false
                if (appLauncherButton != null)
                {
                    appLauncherButton.SetFalse();
                }
                else
                {
                    onToggle();
                }
#endif
                toolbarControl.SetFalse();
            }

            GUILayout.EndVertical();
            GUI.DragWindow();
        }
示例#4
0
        // It's a mess
        private void DrawGUI(int windowId)
        {
            GUILayout.BeginVertical();
            GUI.contentColor = Color.blue;
            GUILayout.Label(Localizer.Format("#SimpleLogistics_VesselName", FlightGlobals.ActiveVessel.GetDisplayName()));
            GUILayout.Label(Localizer.Format("#SimpleLogistics_Status", FlightGlobals.ActiveVessel.SituationString));

            bool            ableToRequest = false;
            LogisticsModule lm            = FlightGlobals.ActiveVessel.FindPartModuleImplementing <LogisticsModule> ();

            if (lm != null)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(
                    lm.IsActive ? Localizer.Format("#SimpleLogistics_Label2") : Localizer.Format("#SimpleLogistics_Label3")                             //, //"Pluged In""Unplugged"
                    //lm.IsActive ? GUI.contentColor = Color.green : GUI.contentColor = Color.red
                    );
                GUILayout.FlexibleSpace();
                GUI.contentColor = Color.yellow;
                if (GUILayout.Button(Localizer.Format("#SimpleLogistics_Label4"))) // "Toggle Plug"
                {
                    lm.Toggle();                                                   // Set (!lm.IsActive);
                    refreshGUI = true;
                }
                GUILayout.FlexibleSpace();
                GUI.contentColor = Color.white;
                GUILayout.EndHorizontal();
                // if plugged in - not able to request
                ableToRequest = !lm.IsActive;
            }

            //if (ableToRequest)
            GetVesselSpareSpace();

            GUI.contentColor = Color.yellow;
            GUILayout.Label(Localizer.Format("#SimpleLogistics_Label5"));                     //"Resource Pool:"

            foreach (var resource in resourcePool)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(resource.Key, GUILayout.Width(170));
                if (ableToRequest && requestPool.ContainsKey(resource.Key))
                {
                    GUILayout.Label(requestPool[resource.Key].ToString("0.00") + " / " + resource.Value.ToString("0.00"));
                }
                else
                {
                    GUILayout.Label(resource.Value.ToString("0.00"));
                }
                //TODO: *knocking on wood that this woorks.

                /*					if (GUILayout.Button(resourcePool[resource.Key].ToString("0.00")))
                 *                                                      // depositResource(PartResourceLibrary.Instance.GetDefinition(resource.Key.ToString()) );
                 *                                                      depositResource(PartResourceLibrary.Instance.GetDefinition(resource.Key.ToString()) );*//*
                 */
                GUILayout.EndHorizontal();
                if (ableToRequest && requestPool.ContainsKey(resource.Key))
                {
                    GUILayout.BeginHorizontal();
                    if (GUILayout.Button("0", GUILayout.Width(20)))
                    {
                        requestPool[resource.Key] = 0;
                    }

                    requestPool[resource.Key] = GUILayout.HorizontalSlider(
                        (float)requestPool[resource.Key],
                        0,
                        (float)Math.Min(vesselSpareSpace [resource.Key], resource.Value),
                        GUILayout.Width(280)
                        );

                    if (GUILayout.Button(vesselSpareSpace[resource.Key].ToString("0.00")))
                    {
                        requestPool[resource.Key] = Math.Min(vesselSpareSpace [resource.Key], resource.Value);
                    }

                    GUILayout.EndHorizontal();
                }
            }

            if (ableToRequest)
            {
                if (GUILayout.Button(Localizer.Format("#SimpleLogistics_Label6")))                 // "Request Resources"
                {
                    requested = true;
                }
            }
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("<color=red>X</color>", GUILayout.Width(20)))
            {
                toolbarControl.SetFalse();
            }

            GUILayout.EndVertical();

            GUI.DragWindow();
        }