Ejemplo n.º 1
0
        protected override void DrawWindowContents(int windowId)
        {
            Func <TransferCostPaymentModes> getSelectedMode = () =>
            {
                return((this._costPayModes.First(kv => kv.Value)).Key);
            };

            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("<<", MKSGui.buttonStyle, GUILayout.Width(40)))
            {
                previousBodyVesselList(ref vesselFrom);
                _model.VesselFrom = _central.bodyVesselList[vesselFrom];
                fromVesselComboBox.SelectedItemIndex = vesselFrom;
                _model.calcResources();
            }
            GUILayout.Label("From:", MKSGui.labelStyle, GUILayout.Width(60));
            fromVesselComboBox.Show();
            //GUILayout.Label(_model.VesselFrom.vesselName, MKSGui.labelStyle, GUILayout.Width(160));
            if (GUIButton.LayoutButton(new GUIContent(">>"), MKSGui.buttonStyle, GUILayout.Width(40)))
            {
                nextBodyVesselList(ref vesselFrom);
                _model.VesselFrom = _central.bodyVesselList[vesselFrom];
                fromVesselComboBox.SelectedItemIndex = vesselFrom;
                _model.calcResources();
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("<<", MKSGui.buttonStyle, GUILayout.Width(40)))
            {
                previousBodyVesselList(ref vesselTo);
                _model.VesselTo = _central.bodyVesselList[vesselTo];
                toVesselComboBox.SelectedItemIndex = vesselTo;
                _model.calcResources();
            }
            GUILayout.Label("To:", MKSGui.labelStyle, GUILayout.Width(60));
            toVesselComboBox.Show();
            //GUILayout.Label(_model.VesselTo.vesselName, MKSGui.labelStyle, GUILayout.Width(160));
            if (GUIButton.LayoutButton(new GUIContent(">>"), MKSGui.buttonStyle, GUILayout.Width(40)))
            {
                nextBodyVesselList(ref vesselTo);
                _model.VesselTo = _central.bodyVesselList[vesselTo];
                toVesselComboBox.SelectedItemIndex = vesselTo;
                _model.calcResources();
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();

            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical();
            scrollPositionEditGUIResources = GUILayout.BeginScrollView(scrollPositionEditGUIResources, GUILayout.Width(300), GUILayout.Height(150));
            foreach (MKSLresource res in _model.transferList)
            {
                GUILayout.BeginHorizontal();
                if (GUIButton.LayoutButton(new GUIContent(res.resourceName + ": " + Math.Round(res.amount, 2) + " of " +
                                                          Math.Round(_model.resourceAmount.Find(x => x.resourceName == res.resourceName).amount))))
                {
                    editGUIResource      = res;
                    StrAmount            = Math.Round(res.amount, 2).ToString();
                    currentAvailable     = readResource(_model.VesselFrom, editGUIResource.resourceName)[0];
                    currentTargetAmounts = this.readResource(_model.VesselTo, editGUIResource.resourceName);
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndScrollView();
            GUILayout.EndVertical();

            GUILayout.BeginVertical();

            if (editGUIResource != null)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Resource:", MKSGui.labelStyle, GUILayout.Width(80));
                GUILayout.Label(editGUIResource.resourceName, MKSGui.labelStyle, GUILayout.Width(100));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Amount:", MKSGui.labelStyle, GUILayout.Width(80));
                StrAmount = GUILayout.TextField(StrAmount, 10, MKSGui.textFieldStyle, GUILayout.Width(60));
                Action <double> setAmount = (a) =>
                {
                    if (a < currentAvailable)
                    {
                        editGUIResource.amount = a;
                    }
                    else
                    {
                        editGUIResource.amount = currentAvailable;
                        StrAmount = editGUIResource.amount.ToString("F2");
                    }
                };
                if (GUILayout.Button("Set", MKSGui.buttonStyle, GUILayout.Width(30)))
                {
                    double number;
                    if (Double.TryParse(StrAmount, out number))
                    {
                        setAmount(number);
                    }
                    else
                    {
                        StrAmount = "0";
                        editGUIResource.amount = 0;
                    }
                    updateCostList(_model);
                    validateTransfer(_model, getSelectedMode(), ref StrValidationMessage);
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Mass:", MKSGui.labelStyle, GUILayout.Width(80));
                GUILayout.Label(Math.Round(editGUIResource.mass(), 2).ToString(), MKSGui.labelStyle, GUILayout.Width(100));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Available:", MKSGui.labelStyle, GUILayout.Width(80));
                GUILayout.Label(Math.Round(currentAvailable, 2).ToString(), MKSGui.labelStyle, GUILayout.Width(100));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Target:", MKSGui.labelStyle, GUILayout.Width(80));
                GUILayout.Label(string.Format("{0:F2}/{1:F2}", currentTargetAmounts[0], currentTargetAmounts[1]), MKSGui.labelStyle, GUILayout.Width(100));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Fill Up", MKSGui.buttonStyle, GUILayout.Width(100)))
                {
                    var diff = Math.Round(currentTargetAmounts[1] - currentTargetAmounts[0], 2);
                    if (diff >= 0)
                    {
                        setAmount(diff);
                        StrAmount = diff.ToString("F2");
                    }
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
            GUILayout.BeginVertical();
            GUILayout.Label("Tranfer Mass: " + Math.Round(_model.totalMass(), 2) + " (maximum: " + _central.maxTransferMass + ")", MKSGui.labelStyle, GUILayout.Width(300));


            GUILayout.BeginHorizontal();
            GUILayout.Label("");
            if (_central.Mix1CostName != "")
            {
                if (GUILayout.Button(_central.Mix1CostName, MKSGui.buttonStyle, GUILayout.Width(170)))
                {
                    _model.initCostList(_central.Mix1CostResources);
                    updateCostList(_model);
                }
            }
            if (_central.Mix2CostName != "")
            {
                if (GUILayout.Button(_central.Mix2CostName, MKSGui.buttonStyle, GUILayout.Width(170)))
                {
                    _model.initCostList(_central.Mix2CostResources);
                    updateCostList(_model);
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (_central.Mix3CostName != "")
            {
                if (GUILayout.Button(_central.Mix3CostName, MKSGui.buttonStyle, GUILayout.Width(170)))
                {
                    _model.initCostList(_central.Mix3CostResources);
                    updateCostList(_model);
                }
            }
            if (_central.Mix4CostName != "")
            {
                if (GUILayout.Button(_central.Mix4CostName, MKSGui.buttonStyle, GUILayout.Width(170)))
                {
                    _model.initCostList(_central.Mix4CostResources);
                    updateCostList(_model);
                }
            }
            GUILayout.EndHorizontal();

            foreach (MKSLresource resCost in _model.costList)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(resCost.resourceName + ":", MKSGui.labelStyle, GUILayout.Width(100));
                GUILayout.Label(Math.Round(resCost.amount, 2).ToString(), MKSGui.labelStyle, GUILayout.Width(200));
                GUILayout.EndHorizontal();
            }

            GUILayout.BeginHorizontal();
            GUILayout.Label("Transfer cost paid by: ", MKSGui.labelStyle, GUILayout.Width(170));
            if (this._checkTransferAmounts(this._model, TransferCostPaymentModes.Both).EnoughRes)
            {
                var oldVal = this._costPayModes[TransferCostPaymentModes.Both];
                this._costPayModes[TransferCostPaymentModes.Both] = GUILayout.Toggle(this._costPayModes[TransferCostPaymentModes.Both], "Both", MKSGui.buttonStyle);
                if (oldVal != this._costPayModes[TransferCostPaymentModes.Both])
                {
                    this._costPayModes[TransferCostPaymentModes.Source] = this._costPayModes[TransferCostPaymentModes.Target] = false;
                }
            }
            if (this._checkTransferAmounts(this._model, TransferCostPaymentModes.Source).EnoughRes)
            {
                var oldVal = this._costPayModes[TransferCostPaymentModes.Source];
                this._costPayModes[TransferCostPaymentModes.Source] = GUILayout.Toggle(this._costPayModes[TransferCostPaymentModes.Source], "Source", MKSGui.buttonStyle);
                if (oldVal != this._costPayModes[TransferCostPaymentModes.Source])
                {
                    this._costPayModes[TransferCostPaymentModes.Both] = this._costPayModes[TransferCostPaymentModes.Target] = false;
                }
            }
            if (this._checkTransferAmounts(this._model, TransferCostPaymentModes.Target).EnoughRes)
            {
                var oldVal = this._costPayModes[TransferCostPaymentModes.Target];
                this._costPayModes[TransferCostPaymentModes.Target] = GUILayout.Toggle(this._costPayModes[TransferCostPaymentModes.Target], "Target", MKSGui.buttonStyle);
                if (oldVal != this._costPayModes[TransferCostPaymentModes.Target])
                {
                    this._costPayModes[TransferCostPaymentModes.Both] = this._costPayModes[TransferCostPaymentModes.Source] = false;
                }
            }
            if (!(this._costPayModes[TransferCostPaymentModes.Both] || this._costPayModes[TransferCostPaymentModes.Source] || this._costPayModes[TransferCostPaymentModes.Target]))
            {
                this._costPayModes[TransferCostPaymentModes.Both] = true;
            }
            GUILayout.EndHorizontal();

            updateArrivalTime(_model);
            GUILayout.Label("Transfer time: " + Utilities.DeliveryTimeString(_model.arrivaltime, Planetarium.GetUniversalTime()));

            GUILayout.Label(StrValidationMessage, MKSGui.redlabelStyle);

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Initiate Transfer", MKSGui.buttonStyle, GUILayout.Width(200)))
            {
                updateCostList(_model);
                var selMode = getSelectedMode();
                if (validateTransfer(_model, selMode, ref StrValidationMessage))
                {
                    createTransfer(_model, selMode);
                }
            }
            if (GUILayout.Button("Cancel", MKSGui.buttonStyle, GUILayout.Width(100)))
            {
                SetVisible(false);
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            fromVesselComboBox.ShowRest();
            toVesselComboBox.ShowRest();
        }
Ejemplo n.º 2
0
        protected override void DrawWindowContents(int windowId)
        {
            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("<<", MKSGui.buttonStyle, GUILayout.Width(40)))
            {
                previousBodyVesselList(ref vesselFrom);
                _model.VesselFrom = _central.bodyVesselList[vesselFrom];
                fromVesselComboBox.SelectedItemIndex = vesselFrom;
                _model.calcResources();
            }
            GUILayout.Label("From:", MKSGui.labelStyle, GUILayout.Width(60));
            fromVesselComboBox.Show();
            //GUILayout.Label(_model.VesselFrom.vesselName, MKSGui.labelStyle, GUILayout.Width(160));
            if (GUIButton.LayoutButton(new GUIContent(">>"), MKSGui.buttonStyle, GUILayout.Width(40)))
            {
                nextBodyVesselList(ref vesselFrom);
                _model.VesselFrom = _central.bodyVesselList[vesselFrom];
                fromVesselComboBox.SelectedItemIndex = vesselFrom;
                _model.calcResources();
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("<<", MKSGui.buttonStyle, GUILayout.Width(40)))
            {
                previousBodyVesselList(ref vesselTo);
                _model.VesselTo = _central.bodyVesselList[vesselTo];
                toVesselComboBox.SelectedItemIndex = vesselTo;
                _model.calcResources();
            }
            GUILayout.Label("To:", MKSGui.labelStyle, GUILayout.Width(60));
            toVesselComboBox.Show();
            //GUILayout.Label(_model.VesselTo.vesselName, MKSGui.labelStyle, GUILayout.Width(160));
            if (GUIButton.LayoutButton(new GUIContent(">>"), MKSGui.buttonStyle, GUILayout.Width(40)))
            {
                nextBodyVesselList(ref vesselTo);
                _model.VesselTo = _central.bodyVesselList[vesselTo];
                toVesselComboBox.SelectedItemIndex = vesselTo;
                _model.calcResources();
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();

            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical();
            scrollPositionEditGUIResources = GUILayout.BeginScrollView(scrollPositionEditGUIResources, GUILayout.Width(300), GUILayout.Height(150));
            foreach (MKSLresource res in _model.transferList)
            {
                GUILayout.BeginHorizontal();
                if (GUIButton.LayoutButton(new GUIContent(res.resourceName + ": " + Math.Round(res.amount, 2) + " of " +
                                                          Math.Round(_model.resourceAmount.Find(x => x.resourceName == res.resourceName).amount))))
                {
                    editGUIResource  = res;
                    StrAmount        = Math.Round(res.amount, 2).ToString();
                    currentAvailable = readResource(_model.VesselFrom, editGUIResource.resourceName);
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndScrollView();
            GUILayout.EndVertical();

            GUILayout.BeginVertical();

            if (editGUIResource != null)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Resource:", MKSGui.labelStyle, GUILayout.Width(80));
                GUILayout.Label(editGUIResource.resourceName, MKSGui.labelStyle, GUILayout.Width(100));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Amount:", MKSGui.labelStyle, GUILayout.Width(80));
                StrAmount = GUILayout.TextField(StrAmount, 10, MKSGui.textFieldStyle, GUILayout.Width(60));
                if (GUILayout.Button("Set", MKSGui.buttonStyle, GUILayout.Width(30)))
                {
                    double number;
                    if (Double.TryParse(StrAmount, out number))
                    {
                        if (number < currentAvailable)
                        {
                            editGUIResource.amount = number;
                        }
                        else
                        {
                            editGUIResource.amount = currentAvailable;
                        }
                        StrAmount = Math.Round(editGUIResource.amount, 2).ToString();
                    }
                    else
                    {
                        StrAmount = "0";
                        editGUIResource.amount = 0;
                    }
                    updateCostList(_model);
                    validateTransfer(_model, ref StrValidationMessage);
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Mass:", MKSGui.labelStyle, GUILayout.Width(80));
                GUILayout.Label(Math.Round(editGUIResource.mass(), 2).ToString(), MKSGui.labelStyle, GUILayout.Width(100));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Available:", MKSGui.labelStyle, GUILayout.Width(80));
                GUILayout.Label(Math.Round(currentAvailable, 2).ToString(), MKSGui.labelStyle, GUILayout.Width(100));
                GUILayout.EndHorizontal();
            }
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
            GUILayout.BeginVertical();
            GUILayout.Label("Tranfer Mass: " + Math.Round(_model.totalMass(), 2) + " (maximum: " + _central.maxTransferMass + ")", MKSGui.labelStyle, GUILayout.Width(300));


            GUILayout.BeginHorizontal();
            GUILayout.Label("");
            if (_central.Mix1CostName != "")
            {
                if (GUILayout.Button(_central.Mix1CostName, MKSGui.buttonStyle, GUILayout.Width(170)))
                {
                    _model.initCostList(_central.Mix1CostResources);
                    updateCostList(_model);
                }
            }
            if (_central.Mix2CostName != "")
            {
                if (GUILayout.Button(_central.Mix2CostName, MKSGui.buttonStyle, GUILayout.Width(170)))
                {
                    _model.initCostList(_central.Mix2CostResources);
                    updateCostList(_model);
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (_central.Mix3CostName != "")
            {
                if (GUILayout.Button(_central.Mix3CostName, MKSGui.buttonStyle, GUILayout.Width(170)))
                {
                    _model.initCostList(_central.Mix3CostResources);
                    updateCostList(_model);
                }
            }
            if (_central.Mix4CostName != "")
            {
                if (GUILayout.Button(_central.Mix4CostName, MKSGui.buttonStyle, GUILayout.Width(170)))
                {
                    _model.initCostList(_central.Mix4CostResources);
                    updateCostList(_model);
                }
            }
            GUILayout.EndHorizontal();

            foreach (MKSLresource resCost in _model.costList)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(resCost.resourceName + ":", MKSGui.labelStyle, GUILayout.Width(100));
                GUILayout.Label(Math.Round(resCost.amount, 2).ToString(), MKSGui.labelStyle, GUILayout.Width(200));
                GUILayout.EndHorizontal();
            }


            GUILayout.Label(StrValidationMessage, MKSGui.redlabelStyle);

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Initiate Transfer", MKSGui.buttonStyle, GUILayout.Width(200)))
            {
                updateCostList(_model);
                if (validateTransfer(_model, ref StrValidationMessage))
                {
                    createTransfer(_model);
                }
            }
            if (GUILayout.Button("Cancel", MKSGui.buttonStyle, GUILayout.Width(100)))
            {
                SetVisible(false);
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            fromVesselComboBox.ShowRest();
            toVesselComboBox.ShowRest();
        }