Ejemplo n.º 1
0
        /// <summary>
        /// Initialize the UI controls, including default values, and specifying delegates for their 'onClick' methods.<para/>
        /// All UI based interaction code will be defined/run through these delegates.
        /// </summary>
        public void InitializeUI()
        {
            //set up the core variant UI control
            string[] variantNames = ROLUtils.getNames(variantSets.Values, m => m.variantName);
            this.ROLupdateUIChooseOptionControl(nameof(currentVariant), variantNames, variantNames, true, currentVariant);
            Fields[nameof(currentVariant)].guiActiveEditor = variantSets.Count > 1;

            Fields[nameof(currentVariant)].uiControlEditor.onFieldChanged = (a, b) =>
            {
                //TODO find variant set for the currently enabled core model
                //query the index from that variant set
                ModelDefinitionVariantSet prevMdvs = GetVariantSet(coreModule.definition.name);
                //this is the index of the currently selected model within its variant set
                int previousIndex = prevMdvs.IndexOf(coreModule.layoutOptions);
                //grab ref to the current/new variant set
                ModelDefinitionVariantSet mdvs = GetVariantSet(currentVariant);
                //and a reference to the model from same index out of the new set ([] call does validation internally for IAOOBE)
                ModelDefinitionLayoutOptions newCoreDef = mdvs[previousIndex];
                //now, call model-selected on the core model to update for the changes, including symmetry counterpart updating.
                this.ROLactionWithSymmetry(m =>
                {
                    if (lengthWidth)
                    {
                        m.SetModelFromDimensions();
                    }
                    else
                    {
                        m.coreModule.modelSelected(newCoreDef.definition.name);
                    }
                });
                ModelChangedHandlerWithSymmetry(true, true);
            };

            Fields[nameof(currentDiameter)].uiControlEditor.onFieldChanged             =
                Fields[nameof(currentDiameter)].uiControlEditor.onSymmetryFieldChanged = OnDiameterChanged;

            Fields[nameof(currentLength)].uiControlEditor.onFieldChanged             =
                Fields[nameof(currentLength)].uiControlEditor.onSymmetryFieldChanged = OnLengthChanged;

            Fields[nameof(currentVScale)].uiControlEditor.onFieldChanged = (a, b) =>
            {
                ModelChangedHandlerWithSymmetry(true, true);
            };

            Fields[nameof(currentNose)].uiControlEditor.onFieldChanged = (a, b) =>
            {
                noseModule.modelSelected(a, b);
                ModelChangedHandlerWithSymmetry(true, true);
            };

            Fields[nameof(currentCore)].uiControlEditor.onFieldChanged = (a, b) =>
            {
                coreModule.modelSelected(a, b);
                ModelChangedHandlerWithSymmetry(true, true);
            };

            Fields[nameof(currentMount)].uiControlEditor.onFieldChanged = (a, b) =>
            {
                mountModule.modelSelected(a, b);
                ModelChangedHandlerWithSymmetry(true, true);
            };

            //------------------MODEL DIAMETER / LENGTH SWITCH UI INIT---------------------//
            if (maxDiameter == minDiameter)
            {
                Fields[nameof(currentDiameter)].guiActiveEditor = false;
            }
            else
            {
                this.ROLupdateUIFloatEditControl(nameof(currentDiameter), minDiameter, maxDiameter, diameterLargeStep, diameterSmallStep, diameterSlideStep, true, currentDiameter);
            }

            if (maxLength == minLength || !lengthWidth)
            {
                Fields[nameof(currentLength)].guiActiveEditor = false;
            }
            else
            {
                this.ROLupdateUIFloatEditControl(nameof(currentLength), minLength, maxLength, diameterLargeStep, diameterSmallStep, diameterSlideStep, true, currentLength);
            }

            Fields[nameof(currentVScale)].guiActiveEditor = enableVScale && !lengthWidth;
            Events[nameof(ResetModel)].guiActiveEditor    = !lengthWidth;

            //------------------MODULE TEXTURE SWITCH UI INIT---------------------//
            Fields[nameof(currentNoseTexture)].uiControlEditor.onFieldChanged  = noseModule.textureSetSelected;
            Fields[nameof(currentCoreTexture)].uiControlEditor.onFieldChanged  = coreModule.textureSetSelected;
            Fields[nameof(currentMountTexture)].uiControlEditor.onFieldChanged = mountModule.textureSetSelected;

            if (HighLogic.LoadedSceneIsEditor)
            {
                GameEvents.onEditorShipModified.Add(new EventData <ShipConstruct> .OnEvent(OnEditorVesselModified));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initialize the UI controls, including default values, and specifying delegates for their 'onClick' methods.<para/>
        /// All UI based interaction code will be defined/run through these delegates.
        /// </summary>
        public void InitializeUI()
        {
            // Set up the core variant UI control
            string[] variantNames = ROLUtils.getNames(variantSets.Values, m => m.variantName);
            this.ROLupdateUIChooseOptionControl(nameof(currentVariant), variantNames, variantNames, true, currentVariant);
            Fields[nameof(currentVariant)].guiActiveEditor = variantSets.Count > 1;
            Fields[nameof(currentVariant)].uiControlEditor.onFieldChanged = (a, b) =>
            {
                // Query the index from that variant set
                ModelDefinitionVariantSet prevMdvs = GetVariantSet(coreModule.definition.name);
                // This is the index of the currently selected model within its variant set
                int previousIndex = prevMdvs.IndexOf(coreModule.layoutOptions);
                // Grab ref to the current/new variant set
                ModelDefinitionVariantSet mdvs = GetVariantSet(currentVariant);
                // And a reference to the model from same index out of the new set ([] call does validation internally for IAOOBE)
                ModelDefinitionLayoutOptions newCoreDef = mdvs[previousIndex];
                // Now, call model-selected on the core model to update for the changes, including symmetry counterpart updating.
                this.ROLactionWithSymmetry(m =>
                {
                    m.coreModule.modelSelected(newCoreDef.definition.name);
                    lengthWidth = coreModule.definition.lengthWidth;
                    Fields[nameof(panelLength)].guiActiveEditor = lengthWidth;
                    Fields[nameof(panelWidth)].guiActiveEditor  = lengthWidth;
                    Fields[nameof(panelScale)].guiActiveEditor  = !lengthWidth;
                    m.ResetModel();
                });
                ModelChangedHandlerWithSymmetry(true, true);
            };

            Fields[nameof(currentCore)].uiControlEditor.onFieldChanged = (a, b) =>
            {
                coreModule.modelSelected(a, b);
                lengthWidth = coreModule.definition.lengthWidth;
                Fields[nameof(panelLength)].guiActiveEditor = lengthWidth;
                Fields[nameof(panelWidth)].guiActiveEditor  = lengthWidth;
                Fields[nameof(panelScale)].guiActiveEditor  = !lengthWidth;
                if (!lengthWidth)
                {
                    this.ROLupdateUIFloatEditControl(nameof(panelScale), 0.1f, 100f, largeStep, smallStep, slideStep, true, panelScale);
                }
                else
                {
                    this.ROLupdateUIFloatEditControl(nameof(panelLength), minLength, maxLength, largeStep, smallStep, slideStep, true, panelLength);
                    this.ROLupdateUIFloatEditControl(nameof(panelWidth), minWidth, maxWidth, largeStep, smallStep, slideStep, true, panelWidth);
                }
                ModelChangedHandlerWithSymmetry(true, true);
            };

            Fields[nameof(panelLength)].uiControlEditor.onFieldChanged             =
                Fields[nameof(panelLength)].uiControlEditor.onSymmetryFieldChanged = (a, b) =>
            {
                if ((float)a.GetValue(this) != prevLength)
                {
                    ModelChangedHandler(true);
                    prevLength = panelLength;
                }
            };

            Fields[nameof(panelWidth)].uiControlEditor.onFieldChanged             =
                Fields[nameof(panelWidth)].uiControlEditor.onSymmetryFieldChanged = (a, b) =>
            {
                if ((float)a.GetValue(this) != prevWidth)
                {
                    ModelChangedHandler(true);
                    prevWidth = panelWidth;
                }
            };

            Fields[nameof(panelScale)].uiControlEditor.onFieldChanged             =
                Fields[nameof(panelScale)].uiControlEditor.onSymmetryFieldChanged = (a, b) =>
            {
                if ((float)a.GetValue(this) != prevScale)
                {
                    ModelChangedHandler(true);
                    prevScale = panelScale;
                }
            };

            Fields[nameof(panelScale)].guiActiveEditor = !lengthWidth;
            if (!lengthWidth)
            {
                this.ROLupdateUIFloatEditControl(nameof(panelScale), 0.1f, 100f, largeStep, smallStep, slideStep, true, panelScale);
            }

            Fields[nameof(TechLevel)].uiControlEditor.onFieldChanged = (a, b) =>
            {
                ModelChangedHandlerWithSymmetry(true, true);
            };

            if (maxLength == minLength || !lengthWidth)
            {
                Fields[nameof(panelLength)].guiActiveEditor = false;
            }
            else
            {
                this.ROLupdateUIFloatEditControl(nameof(panelLength), minLength, maxLength, largeStep, smallStep, slideStep, true, panelLength);
            }

            if (maxWidth == minWidth || !lengthWidth)
            {
                Fields[nameof(panelWidth)].guiActiveEditor = false;
            }
            else
            {
                this.ROLupdateUIFloatEditControl(nameof(panelWidth), minWidth, maxWidth, largeStep, smallStep, slideStep, true, panelWidth);
            }

            if (HighLogic.LoadedSceneIsEditor)
            {
                GameEvents.onEditorShipModified.Add(OnEditorVesselModified);
            }
        }