DennyTX / DockingCam

Other
8 stars 19 forks source link

Installing DockingCam overwrites the default text style #1

Closed hvacengi closed 8 years ago

hvacengi commented 8 years ago

When installing this mod, the default text style gets overwritten with the font color of red. Looking through the code, this is because of the following lines:

        public DockingCamera(Part part, bool noiseActive, string windowLabel = "Docking Camera")
            : base(part, windowLabel)
        {
            this.noiseActive = noiseActive;
            target = new TargetHelper(part);
            guiStyleRedLabel = HighLogic.Skin.label;
            guiStyleRedLabel.normal.textColor = Color.red;
            if (textureWhiteNoise != null || !noiseActive) return;
            textureWhiteNoise = new List<Texture2D>[3];
            for (int j = 0; j < 3; j++)
            {
                textureWhiteNoise[j] = new List<Texture2D>();
                for (int i = 0; i < 4; i++)
                    textureWhiteNoise[j].Add(Util.WhiteNoiseTexture((int)texturePosition.width, (int)texturePosition.height));

            }
        }

https://github.com/DennyTX/DockingCam/blob/master/KSPCamera/Camera/DockingCamera.cs#L35

The guiStyleRedLabel is a reference type, and doesn't create a local copy by default. In kOS, we implemented a "deep copy" of the skin. I didn't implement it myself, but it looks like you probably want to change line 3 to guiStyleRedLabel = new GUIStyle(HighLogic.Skin.label); https://github.com/KSP-KOS/KOS/blob/develop/src/kOS/Utilities/Utils.cs#L134

DennyTX commented 8 years ago

got it. will be fixed in next build