Example #1
0
 public void OnMouseOver()
 {
     if (HighLogic.LoadedScene == GameScenes.FLIGHT)
     {
         return;
     }
     if (Input.GetKeyUp(KeyCode.P))
     {
         menuOpen          = this;
         currentlyPainting = this;
         didSelect         = true;
         flashTime         = 1f;
     }
 }
Example #2
0
        void doPaintWindow(int id)
        {
            var shouldClear = false;             // Flag for killing the window

            GUILayout.BeginHorizontal();         // First row, Channel to color and X-out button
            GUI.enabled     = !showPatterns;
            selectedChannel = GUILayout.Toolbar(selectedChannel, new[] { "Primary", "Secondary", "Tertiary" });
            GUILayout.FlexibleSpace();
            GUI.enabled = true;
            if (GUILayout.Button("X", GUILayout.ExpandWidth(false)))
            {
                currentlyPainting = null;
                shouldClear       = true;
                menuOpen          = false;
            }
            GUILayout.EndHorizontal();

            var activeSet = new[] { Primary, Secondary, Tertiary }[selectedChannel]; // Grab the data struct

            int trumpWith = -1;                                                      // ID of the preset to trump with

            var rect  = GUILayoutUtility.GetRect(50, 42, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(false));
            var block = rect;

            block.width /= presets.Length;
            for (int i = 0; i < presets.Length; ++i)
            {
                GUI.color = presets [i].Key;
                var tColor = GUI.color;
                tColor.a  = Mathf.Max(0.2f, tColor.a);
                GUI.color = tColor;

                if (showPatterns)                   // Draw the sample patterns instead of the default colorings
                {
                    var sBlock = block;
                    sBlock.height /= 3;
                    GUI.color      = presets [Samples [i].A].Key;
                    GUI.DrawTexture(sBlock, swatch, ScaleMode.StretchToFill, true);
                    sBlock.y += sBlock.height;
                    GUI.color = presets [Samples [i].B].Key;
                    GUI.DrawTexture(sBlock, swatch, ScaleMode.StretchToFill, true);
                    sBlock.y += sBlock.height;
                    GUI.color = presets [Samples [i].C].Key;
                    GUI.DrawTexture(sBlock, swatch, ScaleMode.StretchToFill, true);
                }
                else
                {
                    GUI.DrawTexture(block, swatch, ScaleMode.StretchToFill, true);
                }
                if (GUI.Button(block, GUIContent.none, GUIStyle.none))
                {
                    trumpWith = i;
                }
                block.x += block.width;          // Increment block over
            }
            GUI.color = Color.white;             // Restore full color

            GUILayout.BeginHorizontal();
            GUI.enabled  = !showPatterns;
            showAdvanced = GUILayout.Toggle(showAdvanced, "Show Advanced");
            GUI.enabled  = true;
            GUILayout.FlexibleSpace();
            showPatterns = GUILayout.Button(showPatterns ? "Patterns" : "Solids") ? !showPatterns : showPatterns;
            GUILayout.EndHorizontal();

            if (showAdvanced && !showPatterns)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Opacity", GUILayout.Width(80), GUILayout.ExpandWidth(false));
                activeSet.w = GUILayout.HorizontalSlider(activeSet.w, 0, 1, GUILayout.ExpandWidth(true));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Hue", GUILayout.Width(80), GUILayout.ExpandWidth(false));
                activeSet.x = GUILayout.HorizontalSlider(activeSet.x, 0, 1, GUILayout.ExpandWidth(true));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Saturation", GUILayout.Width(80), GUILayout.ExpandWidth(false));
                activeSet.y = GUILayout.HorizontalSlider(activeSet.y, -1, 1, GUILayout.ExpandWidth(true));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Value", GUILayout.Width(80), GUILayout.ExpandWidth(false));
                activeSet.z = GUILayout.HorizontalSlider(activeSet.z, 0.3f, 1.7f, GUILayout.ExpandWidth(true));
                GUILayout.EndHorizontal();
            }


            if (trumpWith != -1)              // Handle preset overloading
            {
                if (!showPatterns)
                {
                    activeSet = presets [trumpWith].Value;
                }
            }

            GUILayout.BeginHorizontal();              // Copy Paste section

            if (GUILayout.Button("Copy"))
            {
                cGeneral = activeSet;
            }
            if (GUILayout.Button("Paste"))
            {
                activeSet = cGeneral;
            }
            if (GUILayout.Button("Copy Set"))
            {
                cPrimary   = Primary;
                cSecondary = Secondary;
                cTertiary  = Tertiary;
            }
            if (GUILayout.Button("Paste Set"))
            {
                Primary   = cPrimary;
                Secondary = cSecondary;
                Tertiary  = cTertiary;
            }

            GUILayout.EndHorizontal();

            // Apply modified properties
            switch (selectedChannel)
            {
            case 0:
                Primary = activeSet;
                break;

            case 1:
                Secondary = activeSet;
                break;

            case 2:
                Tertiary = activeSet;
                break;
            }

            if (trumpWith != -1)
            {
                if (showPatterns)
                {
                    Primary   = presets [Samples [trumpWith].A].Value;
                    Secondary = presets [Samples [trumpWith].B].Value;
                    Tertiary  = presets [Samples [trumpWith].C].Value;
                }
            }

            // Ideally I should move this out of the window update, but there isn't any otherwise nice solution I can think of
            foreach (Part p in this.part.symmetryCounterparts)               // Based on DYJ's P-dynamics and advice :)
            {
                var clone = p.Modules.OfType <ModulePaintable> ().FirstOrDefault();

                clone.isDirty   = true;               // Constantly dirty symmetrically copied parts!
                clone.Primary   = Primary;
                clone.Secondary = Secondary;
                clone.Tertiary  = Tertiary;
            }

            isDirty = true;             // Dirty the paint so it updates

            if (shouldClear)
            {
                currentlyPainting = null;
            }
            GUI.DragWindow();
        }