Пример #1
0
        public override void OnStart(StartState state)
        {
            isInitialized = true;
            InitializeObjects();
            InitializeShapes();

            if (HighLogic.LoadedSceneIsEditor)
            {
                Debug.Log($"{ModTag} TechLimits: {part.name} diameter=({diameterMin:G3}, {diameterMax:G3}) length=({lengthMin:G3}, {lengthMax:G3}) volume=({volumeMin:G3}, {volumeMax:G3})");
                legacyTextureHandler.ValidateSelectedTexture();
                texturePickerGUI = new TUTexturePickerGUI(this);
                Fields[nameof(showTUPickerGUI)].guiActiveEditor = installedTU && !forceLegacyTextures;
            }

            if (shape is ProceduralAbstractShape)
            {
                shape.UpdateShape();
            }
            if (part.variants is ModulePartVariants)
            {
                part.variants.useMultipleDragCubes = false;
            }

            if (HighLogic.LoadedSceneIsEditor)
            {
                if (!TUEnabled)
                {
                    forceLegacyTextures = true;
                }
                SetTextureFieldVisibility();

                Fields[nameof(forceLegacyTextures)].uiControlEditor.onFieldChanged = OnForceLegacyTextureChanged;

                BaseField       field = Fields[nameof(textureSet)];
                UI_ChooseOption opt   = field.uiControlEditor as UI_ChooseOption;
                opt.options = LegacyTextureHandler.textureSets.Keys.ToArray();
                opt.onSymmetryFieldChanged = opt.onFieldChanged = OnTextureChanged;

                BaseField capTextureField = Fields[nameof(capTextureIndex)];
                opt         = capTextureField.uiControlEditor as UI_ChooseOption;
                opt.options = Enum.GetNames(typeof(LegacyTextureHandler.CapTextureMode));
                opt.onSymmetryFieldChanged = opt.onFieldChanged = OnTextureChanged;

                Fields[nameof(shapeName)].guiActiveEditor = availableShapes.Count > 1;
                opt         = Fields[nameof(shapeName)].uiControlEditor as UI_ChooseOption;
                opt.options = availableShapes.Keys.ToArray();
                // The onSymmetryFieldChanged callbacks do not have the correct previous object assigned.
                // Since this matters, we need to handle it ourselves.
                opt.onFieldChanged = OnShapeSelectionChanged;

                Fields[nameof(costDisplay)].guiActiveEditor = displayCost;

                GameEvents.onVariantApplied.Add(OnVariantApplied);
                GameEvents.onGameSceneSwitchRequested.Add(OnEditorExit);
            }
        }
Пример #2
0
        public override void OnStart(StartState state)
        {
            Debug.Log($"{ModTag} OnStart({state}) for {this}");
            isInitialized = true;
            InitializeObjects();
            InitializeShapes();

            if (HighLogic.LoadedSceneIsEditor)
            {
                InitializeTechLimits();
                legacyTextureHandler.ValidateSelectedTexture();
                texturePickerGUI = new TUTexturePickerGUI(this);
                Fields[nameof(showTUPickerGUI)].guiActiveEditor = installedTU && !forceLegacyTextures;
            }

            if (shape is ProceduralAbstractShape)
            {
                shape.UpdateShape();
            }
            if (part.variants is ModulePartVariants)
            {
                part.variants.useMultipleDragCubes = false;
            }

            if (HighLogic.LoadedSceneIsFlight && vessel is Vessel && vessel.rootPart == part)
            {
                GameEvents.onFlightReady.Add(DragCubeFixer);
            }

            if (HighLogic.LoadedSceneIsEditor)
            {
                if (!(part.GetComponent("KSPTextureSwitch") is Component))  // TU not enabled/installed for this part
                {
                    forceLegacyTextures = true;
                    Fields[nameof(forceLegacyTextures)].guiActiveEditor = false;
                }
                Fields[nameof(forceLegacyTextures)].uiControlEditor.onFieldChanged = OnForceLegacyTextureChanged;

                BaseField       field = Fields[nameof(textureSet)];
                UI_ChooseOption opt   = field.uiControlEditor as UI_ChooseOption;
                opt.options = LegacyTextureHandler.textureSets.Keys.ToArray();
                opt.onSymmetryFieldChanged = opt.onFieldChanged = OnTextureChanged;

                BaseField capTextureField = Fields[nameof(capTextureIndex)];
                opt         = capTextureField.uiControlEditor as UI_ChooseOption;
                opt.options = Enum.GetNames(typeof(LegacyTextureHandler.CapTextureMode));
                opt.onSymmetryFieldChanged = opt.onFieldChanged = OnTextureChanged;

                Fields[nameof(shapeName)].guiActiveEditor = availableShapes.Count > 1;
                opt         = Fields[nameof(shapeName)].uiControlEditor as UI_ChooseOption;
                opt.options = availableShapes.Keys.ToArray();
                // The onSymmetryFieldChanged callbacks do not have the correct previous object assigned.
                // Since this matters, we need to handle it ourselves.
                opt.onFieldChanged = OnShapeSelectionChanged;

                Fields[nameof(costDisplay)].guiActiveEditor = displayCost;

                GameEvents.onVariantApplied.Add(OnVariantApplied);
                GameEvents.onGameSceneSwitchRequested.Add(OnEditorExit);
            }

            if (tempCollider != null)
            {
                // delete the temporary collider, if there is one, probably too soon to do this
                Component.Destroy(tempCollider);
                tempCollider = null;
            }
        }