Пример #1
0
 public void Awake()
 {
     ExEditorButton             = ToolbarManager.Instance.add("ExtraplanetaryLaunchpads", "ExEditorButton");
     ExEditorButton.TexturePath = "ExtraplanetaryLaunchpads/Textures/icon_button";
     ExEditorButton.ToolTip     = "EL Build Window";
     ExEditorButton.OnClick    += (e) => ExBuildWindow.ToggleGUI();
 }
 void OnDestroy()
 {
     instance = null;
     GameEvents.onVesselChange.Remove(onVesselChange);
     GameEvents.onVesselWasModified.Remove(onVesselWasModified);
     GameEvents.onHideUI.Remove(onHideUI);
     GameEvents.onShowUI.Remove(onShowUI);
 }
 void Awake()
 {
     instance = this;
     GameEvents.onVesselChange.Add(onVesselChange);
     GameEvents.onVesselWasModified.Add(onVesselWasModified);
     GameEvents.onHideUI.Add(onHideUI);
     GameEvents.onShowUI.Add(onShowUI);
     enabled = false;
 }
        public override void OnLoad(ConfigNode config)
        {
            //Debug.Log (String.Format ("[EL] Settings load"));
            var settings = config.GetNode("Settings");

            if (settings == null)
            {
                settings = new ConfigNode("Settings");
                if (HighLogic.LoadedScene == GameScenes.SPACECENTER)
                {
                    enabled = true;
                }
            }
            if (!settings.HasValue("ForceResourceUse"))
            {
                var val = ExLaunchPad.force_resource_use;
                settings.AddValue("ForceResourceUse", val);
            }
            if (!settings.HasValue("TimedBuilds"))
            {
                var val = ExLaunchPad.timed_builds;
                settings.AddValue("TimedBuilds", val);
            }

            ExLaunchPad.force_resource_use = false;
            var fru = settings.GetValue("ForceResourceUse");

            bool.TryParse(fru, out ExLaunchPad.force_resource_use);

            ExLaunchPad.timed_builds = true;
            var tb = settings.GetValue("TimedBuilds");

            bool.TryParse(tb, out ExLaunchPad.timed_builds);

            if (settings.HasNode("ShipInfo"))
            {
                var node = settings.GetNode("ShipInfo");
                ExShipInfo.LoadSettings(node);
            }

            if (settings.HasNode("BuildWindow"))
            {
                var node = settings.GetNode("BuildWindow");
                ExBuildWindow.LoadSettings(node);
            }
        }
Пример #5
0
        void SetPadMass()
        {
            double mass = 0;

            if (builtStuff != null && buildCost != null)
            {
                var built = builtStuff.required;
                var cost  = buildCost.required;

                foreach (var bres in built)
                {
                    var cres = ExBuildWindow.FindResource(cost, bres.name);
                    mass += (cres.amount - bres.amount) * bres.density;
                }
            }
            part.mass = base_mass + (float)mass;
        }
        public override void OnSave(ConfigNode config)
        {
            //Debug.Log (String.Format ("[EL] Settings save: {0}", config));
            var settings = new ConfigNode("Settings");

            bool fru = ExLaunchPad.force_resource_use;

            settings.AddValue("ForceResourceUse", fru);

            bool tb = ExLaunchPad.timed_builds;

            settings.AddValue("TimedBuilds", tb);

            config.AddNode(settings);

            ExShipInfo.SaveSettings(settings.AddNode("ShipInfo"));
            ExBuildWindow.SaveSettings(settings.AddNode("BuildWindow"));
        }
 void OnDestroy()
 {
     instance = null;
     GameEvents.onVesselChange.Remove (onVesselChange);
     GameEvents.onVesselWasModified.Remove (onVesselWasModified);
     GameEvents.onHideUI.Remove (onHideUI);
     GameEvents.onShowUI.Remove (onShowUI);
 }
 void Awake()
 {
     instance = this;
     GameEvents.onVesselChange.Add (onVesselChange);
     GameEvents.onVesselWasModified.Add (onVesselWasModified);
     GameEvents.onHideUI.Add (onHideUI);
     GameEvents.onShowUI.Add (onShowUI);
     enabled = false;
 }
Пример #9
0
 public void ShowUI()
 {
     ExBuildWindow.ShowGUI();
     ExBuildWindow.SelectPad(this);
 }
Пример #10
0
 public void HideUI()
 {
     ExBuildWindow.HideGUI();
 }
        private void DoWork_Cancel(double kerbalHours)
        {
            var built = builtStuff.required;
            var cost  = buildCost.required;

            bool did_work;
            int  count;

            do
            {
                count = 0;
                foreach (var bres in built)
                {
                    var cres = ExBuildWindow.FindResource(cost, bres.name);
                    if (cres.amount - bres.amount > 0)
                    {
                        count++;
                    }
                }
                if (count == 0)
                {
                    break;
                }

                double work = kerbalHours / count;
                did_work = false;
                count    = 0;
                foreach (var bres in built)
                {
                    var    cres      = ExBuildWindow.FindResource(cost, bres.name);
                    double remaining = cres.amount - bres.amount;
                    if (remaining < 0)
                    {
                        continue;
                    }
                    double mass        = work / 5;              //FIXME not hard-coded (5Kh/t)
                    double amount      = mass / bres.density;
                    double base_amount = amount;

                    if (amount > remaining)
                    {
                        amount = remaining;
                    }
                    double capacity = padResources.ResourceCapacity(bres.name)
                                      - padResources.ResourceAmount(bres.name);
                    if (amount > capacity)
                    {
                        amount = capacity;
                    }
                    if (amount <= 0)
                    {
                        break;
                    }
                    count++;
                    did_work = true;
                    // do only the work required to process the actual amount
                    // of returned resource
                    kerbalHours -= work * amount / base_amount;
                    bres.amount += amount;
                    padResources.TransferResource(bres.name, amount);
                }
            } while (did_work && kerbalHours > 0);

            SetPadMass();

            if (count == 0)
            {
                state = State.Planning;
            }
        }