Ejemplo n.º 1
0
        private void ScalingFactorChanged()
        {
            var format = "0.";

            for (int i = 0; i < Math.Max(1, ScalingFactor.ToString().Count(c => c == '0') + 1); i++)
            {
                format += "0";
            }

            _graphContext.DisplayFormat = format;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Build a string representation of this unit of measure
        /// </summary>
        /// <returns>String value</returns>
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            // type
            sb.Append(MeasurementSystem.UnitsManager.GetString("unit.type.text")).Append(' ').Append(UOMType.ToString()).Append(", ");

            // unit enumeration
            if (Enumeration.HasValue)
            {
                sb.Append(MeasurementSystem.UnitsManager.GetString("enum.text")).Append(' ').Append(Enumeration.ToString()).Append(", ");
            }

            // symbol
            sb.Append(MeasurementSystem.UnitsManager.GetString("symbol.text")).Append(' ').Append(Symbol);
            sb.Append(", ").Append(MeasurementSystem.UnitsManager.GetString("conversion.text")).Append(' ');

            // scaling factor
            if (ScalingFactor.CompareTo(1) != 0)
            {
                sb.Append(ScalingFactor.ToString()).Append(MULT);
            }

            // abscissa unit
            if (AbscissaUnit != null)
            {
                sb.Append(AbscissaUnit.Symbol);
            }

            // offset
            if (Offset.CompareTo(0d) != 0)
            {
                sb.Append(" + ").Append(Offset.ToString());
            }

            sb.Append(", ").Append(MeasurementSystem.UnitsManager.GetString("base.text")).Append(' ');

            // base symbol
            sb.Append(GetBaseSymbol());

            return(sb.ToString());
        }
        internal void OnRescale(ScalingFactor factor)
        {
            Log.dbg("OnRescale {0}:{1:X} to {2}", this.name, this.part.GetInstanceID(), factor.ToString());

            // Needed because I can't intialize this on OnAwake as this module can be awaken before FSbuoyancy,
            // and OnRescale can be fired before OnLoad.
            if (null == this.targetPartModule)
            {
                this.InitInternalData();
            }

            this.RescaleMaxBuoyancy();
            this.UpdateTarget();
            this.RefreshUI();
        }
        internal void OnRescale(ScalingFactor factor)
        {
            Log.dbg("OnRescale {0}:{1:X} to {2}", this.name, this.part.GetInstanceID(), factor.ToString());

            KISP.ModuleKISInventory prefab = this.part.partInfo.partPrefab.Modules.GetModule <KISP.ModuleKISInventory>();
            KISP.ModuleKISInventory part   = this.part.Modules.GetModule <KISP.ModuleKISInventory>();

            TweakScale.TweakScale ts_prefab = this.part.partInfo.partPrefab.Modules.GetModule <TweakScale.TweakScale>();
            TweakScale.TweakScale ts_part   = this.part.Modules.GetModule <TweakScale.TweakScale>();

            part.maxVolume  = prefab.maxVolume * factor.absolute.cubic;
            ts_part.DryCost = (float)(ts_prefab.DryCost * factor.absolute.cubic);
            if (this.increaseSlotsNumber)
            {
                //part.slotSize = prefab.slotSize;
                part.slotsX = (int)Math.Floor(prefab.slotsX * factor.absolute.linear);
                part.slotsY = (int)Math.Floor(prefab.slotsY * factor.absolute.linear);

                int slotsCount = part.slotsX * part.slotsY;
                if (slotsCount > prefab.slotsX * prefab.slotsY)
                {
                    Log.dbg("before {0} {1}", part.maxVolume, ts_part.DryCost);
                    part.maxVolume  -= (float)(slotsCount * (0.0005 * part.maxVolume));                                 // Reduce volume by 0.05% per slot
                    ts_part.DryCost += (float)(slotsCount * (0.001 * ts_part.DryCost));                                 // Add 0.1% of cost penalty per slot
                    Log.dbg("after {0} {1}", part.maxVolume, ts_part.DryCost);
                }
            }
            else
            {
                //part.slotSize = (int)Math.Floor(prefab.slotSize * factor.absolute.linear);
                part.slotsX = prefab.slotsX;
                part.slotsY = prefab.slotsY;
            }

            // FIXME: Resize the Inventory Window size!

            Log.dbg("Current size : {0} maxVolume, {1} slotsX, {2} slotsX, {3} dry cost; {4} currentScale; {5} defaultScale", part.maxVolume, part.slotsX, part.slotsY, ts_part.DryCost, ts_part.currentScale, ts_part.defaultScale);
        }