Configuration values for TweakScale.
Exemplo n.º 1
0
        /// <summary>
        /// Loads settings from <paramref name="scaleType"/>.
        /// </summary>
        /// <param name="scaleType">The settings to use.</param>
        private void SetupFromConfig(ScaleType scaleType)
        {
            isFreeScale = scaleType.IsFreeScale;
            defaultScale = scaleType.DefaultScale;
            Fields["tweakScale"].guiActiveEditor = false;
            Fields["tweakName"].guiActiveEditor = false;
            if (isFreeScale)
            {
                Fields["tweakScale"].guiActiveEditor = true;
                var range = (UI_FloatEdit)Fields["tweakScale"].uiControlEditor;
                range.minValue = scaleType.MinValue;
                range.maxValue = scaleType.MaxValue;
                range.incrementLarge = (float)Math.Round((range.maxValue - range.minValue) / 10, 2);
                range.incrementSmall = (float)Math.Round(range.incrementLarge / 10, 2);
                Fields["tweakScale"].guiUnits = scaleType.Suffix;
            }
            else
            {
                Fields["tweakName"].guiActiveEditor = scaleType.ScaleFactors.Length > 1;
                var options = (UI_ChooseOption)Fields["tweakName"].uiControlEditor;

                if (ScaleFactors.Length <= 0)
                    return;
                ScaleFactors = scaleType.ScaleFactors;
                ScaleNodes = scaleType.ScaleNodes;
                options.options = scaleType.ScaleNames;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sets up values from ScaleType, creates updaters, and sets up initial values.
        /// </summary>
        protected virtual void Setup()
        {
            if (part.partInfo == null)
            {
                return;
            }

            if (_setupRun)
            {
                return;
            }

            _prefabPart = PartLoader.getPartInfoByName(part.partInfo.name).partPrefab;

            _updaters = TweakScaleUpdater.CreateUpdaters(part).ToArray();

            SetupFromConfig(ScaleType = new ScaleType(ModuleNode));

            var doUpdate = currentScale < 0f;
            if (doUpdate)
            {
                tweakScale = currentScale = defaultScale;
                DryCost = (float)(part.partInfo.cost - _prefabPart.Resources.Cast<PartResource>().Aggregate(0.0, (a, b) => a + b.maxAmount * b.info.unitCost));
                if (DryCost < 0)
                {
                    DryCost = 0;
                }
            }

            if (!isFreeScale && ScaleFactors.Length != 0)
            {
                tweakName = Tools.ClosestIndex(tweakScale, ScaleFactors);
                tweakScale = ScaleFactors[tweakName];
            }

            if (!doUpdate)
            {
                UpdateByWidth(false, true);
                foreach (var updater in _updaters)
                {
                    updater.OnRescale(ScalingFactor);
                }
            }
            _setupRun = true;
        }
Exemplo n.º 3
0
 protected bool Equals(ScaleType other)
 {
     return string.Equals(Name, other.Name);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Loads settings from <paramref name="scaleType"/>.
        /// </summary>
        /// <param name="scaleType">The settings to use.</param>
        private void SetupFromConfig(ScaleType scaleType)
        {
            isFreeScale = scaleType.IsFreeScale;
            if (defaultScale == -1)
                defaultScale = scaleType.DefaultScale;

            if (currentScale == -1)
                currentScale = defaultScale;
            else if (defaultScale != scaleType.DefaultScale)
            {
                Tools.Logf("defaultScale has changed for part {0}: keeping relative scale.", part.name);
                currentScale *= scaleType.DefaultScale / defaultScale;
                defaultScale = scaleType.DefaultScale;
            }

            if (tweakScale == -1)
                tweakScale = currentScale;
            Fields["tweakScale"].guiActiveEditor = false;
            Fields["tweakName"].guiActiveEditor = false;
            ScaleFactors = scaleType.ScaleFactors;
            if (ScaleFactors.Length <= 0)
                return;

            if (isFreeScale)
            {
                Fields["tweakScale"].guiActiveEditor = true;
                var range = (UI_ScaleEdit)Fields["tweakScale"].uiControlEditor;
                range.intervals = scaleType.ScaleFactors;
                range.incrementSlide = scaleType.IncrementSlide;
                Fields["tweakScale"].guiUnits = scaleType.Suffix;
            }
            else
            {
                Fields["tweakName"].guiActiveEditor = scaleType.ScaleFactors.Length > 1;
                var options = (UI_ChooseOption)Fields["tweakName"].uiControlEditor;
                ScaleNodes = scaleType.ScaleNodes;
                options.options = scaleType.ScaleNames;
            }
        }
Exemplo n.º 5
0
 private void ChangeScaleType()
 {
     _oldScaleTypeId = _scaleTypeId;
     _cfg = ScaleType.AllScaleTypes[_scaleTypeId];
     if (_cfg.IsFreeScale)
     {
         _scaleEdit.minValue = _cfg.MinValue;
         _scaleEdit.maxValue = _cfg.MaxValue;
         _scaleEdit.incrementLarge = (float)Math.Round((_scaleEdit.maxValue - _scaleEdit.minValue) / 10, 2);
         _scaleEdit.incrementSmall = (float)Math.Round(_scaleEdit.incrementLarge / 10, 2);
         _tweakScale = _cfg.DefaultScale;
         _scale.guiUnits = _cfg.Suffix;
     }
     else
     {
         _nameEdit.options = _cfg.ScaleNames;
         _tweakName = Tools.ClosestIndex(_cfg.DefaultScale, _cfg.AllScaleFactors);
         _tweakScale = _cfg.AllScaleFactors[_tweakName];
     }
 }