コード例 #1
0
 void setupdictionary(float value)
 {
     if (NRAPUtils.CheckRange(value, MIN_SIZE - 0.001f, MAX_SIZE))
     {
         Log.Info("Adding : " + value.ToString());
         sizes.Add(sizecnt, value);
         sizecnt++;
     }
 }
コード例 #2
0
 private void LateUpdate()
 {
     if (HighLogic.LoadedSceneIsEditor && (EditorLogic.SortedShipList[0] == this.part || this.part.parent != null))
     {
         if (sizeNeedsUpdating)
         {
             float m;
             if (float.TryParse(this.mass, out m) && NRAPUtils.CheckRange(m, this.minMass, this.maxMass))
             {
                 this.deltaMass   = m - this.part.partInfo.partPrefab.mass;
                 this.currentMass = this.part.TotalMass();
                 //  GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship);
             }
             UpdateSize();
             sizeNeedsUpdating = false;
             GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship);
             EditorLogic.fetch.SetBackup();
         }
         this.currentMass = this.part.TotalMass();
     }
 }
コード例 #3
0
        private void Window(int id)
        {
            GUI.DragWindow(this.drag);
            GUILayout.BeginVertical();
            GUILayout.Space(5);

            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical();
            GUILayout.FlexibleSpace();
            GUILayout.Label("Dry mass (t):", NRAPUtils.CanParse(this.mass) && NRAPUtils.CheckRange(float.Parse(this.mass), this.minMass, this.maxMass) ? GUI.skin.label : NRAPUtils.RedLabel);
            GUILayout.FlexibleSpace();
            GUILayout.EndVertical();
            GUILayout.FlexibleSpace();
            GUILayout.BeginVertical();
            GUILayout.FlexibleSpace();
            this.mass = GUILayout.TextField(this.mass, 10, GUILayout.Width(125));
            GUILayout.FlexibleSpace();
            GUILayout.EndVertical();

            if (GUILayout.Button("Apply", GUILayout.Width(60)))
            {
                float m;
                sizeNeedsUpdating = true;
                if (float.TryParse(this.mass, out m) && NRAPUtils.CheckRange(m, this.minMass, this.maxMass))
                {
                    this.deltaMass   = m - this.part.partInfo.partPrefab.mass;
                    this.currentMass = this.part.TotalMass();
                    //  GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship);
                }
            }
            GUILayout.EndHorizontal();

            StringBuilder builder = new StringBuilder().AppendFormat("\nCurrent total mass: {0}t ({1}t dry - {2}t resources)\n", this.part.TotalMass(), this.part.mass, this.part.GetResourceMass());

            builder.AppendFormat("Test weight cost: {0}f (total: {1}f)", GetModuleCost(0, 0), this.part.TotalCost());
            GUILayout.Label(builder.ToString());
            GUILayout.Space(10);


            //   oldSize = this.size;
            oldHeight   = this.height;
            oldDiameter = this.baseDiameter;

            //this.baseDiameter = GetSize(this.size);
            snapDiameter = GUILayout.Toggle(snapDiameter, "Snap diameter to predefined sizes");
            GUILayout.Label($"Diameter (m):  {this.baseDiameter}");
            if (snapDiameter)
            {
                this.size         = (int)GUILayout.HorizontalSlider(this.size, 0, sizes.Count() - 1);
                this.baseDiameter = GetSize(this.size);
            }
            //this.size = (int)GUILayout.HorizontalSlider(this.size, 0, 4);
            //this.width = GetSize(this.size) / 2.5f; // this.baseDiameter;
            else
            {
                this.baseDiameter = GUILayout.HorizontalSlider(this.baseDiameter, MIN_SIZE, MAX_SIZE);
            }
            this.width = this.baseDiameter / 2.5f;

            GUILayout.Label($"Height multiplier: {this.height.ToString("0.000")}");
            this.height = GUILayout.HorizontalSlider(this.height, this.minHeight, this.maxHeight);
            GUILayout.Space(10);
            //if (oldSize != this.size || oldHeight != this.height)
            if (oldDiameter != this.baseDiameter || oldHeight != this.height)
            {
                sizeNeedsUpdating = true;
            }
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Reset to defaults", GUILayout.Width(150)))
            {
                sizeNeedsUpdating = true;
                this.deltaMass    = 0;
                this.mass         = this.part.partInfo.partPrefab.mass.ToString();
                this.currentMass  = this.part.TotalMass();
                //  this.size = GetID(this.baseDiameter);
                this.width  = 1;
                this.height = 1;
            }

            if (GUILayout.Button("Close", GUILayout.Width(150)))
            {
                this.visible = false;
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            GUI.DragWindow();
        }