Exemplo n.º 1
0
        /// <summary>
        /// Loads settings from <paramref name="config"/>.
        /// </summary>
        /// <param name="config">The settings to use.</param>
        private void SetupFromConfig(ScaleConfig config)
        {
            isFreeScale  = config.isFreeScale;
            defaultScale = config.defaultScale;
            this.Fields["tweakScale"].guiActiveEditor = false;
            this.Fields["tweakName"].guiActiveEditor  = false;
            if (isFreeScale)
            {
                this.Fields["tweakScale"].guiActiveEditor = true;
                var range = (UI_FloatEdit)this.Fields["tweakScale"].uiControlEditor;
                range.minValue       = config.minValue;
                range.maxValue       = config.maxValue;
                range.incrementLarge = (float)Math.Round((range.maxValue - range.minValue) / 10, 2);
                range.incrementSmall = (float)Math.Round(range.incrementLarge / 10, 2);
                this.Fields["tweakScale"].guiUnits = config.suffix;
            }
            else
            {
                this.Fields["tweakName"].guiActiveEditor = config.scaleFactors.Length > 1;
                var options = (UI_ChooseOption)this.Fields["tweakName"].uiControlEditor;

                if (scaleFactors.Length > 0)
                {
                    scaleFactors    = config.scaleFactors;
                    options.options = config.scaleNames;
                }
            }
        }
Exemplo n.º 2
0
 private void ChangeScaleType()
 {
     _oldScaleTypeId = _scaleTypeId;
     _cfg            = ScaleConfig.AllConfigs[_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.scaleFactors);
         _tweakScale       = _cfg.scaleFactors[_tweakName];
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Sets up values from config, creates updaters, and sets up initial values.
        /// </summary>
        protected virtual void Setup()
        {
            if (part.partInfo == null)
            {
                return;
            }

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

            updaters = TweakScaleUpdater.createUpdaters(part).ToArray();

            SetupFromConfig(config = new ScaleConfig(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);
                foreach (var updater in updaters)
                {
                    updater.OnRescale(scalingFactor);
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Loads settings from <paramref name="config"/>.
        /// </summary>
        /// <param name="config">The settings to use.</param>
        private void SetupFromConfig(ScaleConfig config)
        {
            isFreeScale = config.isFreeScale;
            defaultScale = config.defaultScale;
            this.Fields["tweakScale"].guiActiveEditor = false;
            this.Fields["tweakName"].guiActiveEditor = false;
            if (isFreeScale)
            {
                this.Fields["tweakScale"].guiActiveEditor = true;
                var range = (UI_FloatEdit)this.Fields["tweakScale"].uiControlEditor;
                range.minValue = config.minValue;
                range.maxValue = config.maxValue;
                range.incrementLarge = (float)Math.Round((range.maxValue - range.minValue) / 10, 2);
                range.incrementSmall = (float)Math.Round(range.incrementLarge / 10, 2);
                this.Fields["tweakScale"].guiUnits = config.suffix;
            }
            else
            {
                this.Fields["tweakName"].guiActiveEditor = config.scaleFactors.Length > 1;
                var options = (UI_ChooseOption)this.Fields["tweakName"].uiControlEditor;

                if (scaleFactors.Length > 0)
                {
                    scaleFactors = config.scaleFactors;
                    options.options = config.scaleNames;
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Sets up values from config, creates updaters, and sets up initial values.
        /// </summary>
        protected virtual void Setup()
        {
            if (part.partInfo == null)
            {
                return;
            }

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

            updaters = TweakScaleUpdater.createUpdaters(part).ToArray();

            SetupFromConfig(config = new ScaleConfig(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);
                foreach (var updater in updaters)
                {
                    updater.OnRescale(scalingFactor);
                }
            }
        }
Exemplo n.º 6
0
 private void ChangeScaleType()
 {
     _oldScaleTypeId = _scaleTypeId;
     _cfg = ScaleConfig.AllConfigs[_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.scaleFactors);
         _tweakScale = _cfg.scaleFactors[_tweakName];
     }
 }