SetTextureColor() public static method

public static SetTextureColor ( Texture2D texture, int width, int height, Color color ) : void
texture UnityEngine.Texture2D
width int
height int
color Color
return void
 public void updateColorTextures()
 {
     for (int i = 0; i < TrackManager.Instance.allTracks.Count; ++i)
     {
         Utilities.SetTextureColor(trackColorTextures[i], 20, 20, TrackManager.Instance.allTracks[i].LineColor);
     }
 }
Esempio n. 2
0
        protected override void DrawWindowContents(int windowID)
        {
            GUILayout.BeginVertical(); // BEGIN outer container

            GUILayout.BeginHorizontal();
            GUILayout.Label("Track Name:");
            newName = GUILayout.TextField(newName);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Description:");
            newDescription = GUILayout.TextField(newDescription);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Color");

            GUILayout.BeginVertical();
            float h, s, v;

            Utilities.ColorToHSV(newColor, out h, out s, out v);
            GUILayout.BeginHorizontal();
            GUILayout.Label("Hue");
            h = GUILayout.HorizontalSlider(h, 0, 360);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("Sat.");
            s = GUILayout.HorizontalSlider(s, 0, 1);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("Val.");
            v        = GUILayout.HorizontalSlider(v, 0, 1);
            newColor = Utilities.ColorFromHSV(h, s, v);
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();

            Utilities.SetTextureColor(colorTex, 32, 32, this.newColor);
            //this.colorStyle = new GUIStyle();
            //colorStyle.normal.textColor = this.newColor;
            //GUIStyle generic_style = new GUIStyle();
            //GUI.skin.box = generic_style;
            //GUI.Box(new Rect(x, y, w, h), rgb_texture);

            if (GUILayout.Button(colorTex))
            {
                // Show the color dialog.
                ExplorerTrackBehaviour.Instance.colorDlg = new ColorPicker(this);
                ExplorerTrackBehaviour.Instance.colorDlg.Awake();
                ExplorerTrackBehaviour.Instance.colorDlg.SetVisible(true);
            }

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Draw Sampling:");
            sampling = GUILayout.HorizontalSlider(sampling, 1, 10);
            GUILayout.Label("" + (int)sampling + "x");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Line Width (m):");
            float sliderPos = lineWidthToSliderPos(lineWidth);

            sliderPos = GUILayout.HorizontalSlider(sliderPos, 1, 12);
            lineWidth = sliderPosToLineWidth(sliderPos);
            GUILayout.Label("" + lineWidth + "m");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Direction marker radius:");
            markerRadiusFactor = GUILayout.HorizontalSlider(markerRadiusFactor, 2, 50);
            GUILayout.Label("" + lineWidth * markerRadiusFactor + "m");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Number of direction markers:");
            numMarkers = GUILayout.HorizontalSlider(numMarkers, 0, 20);
            GUILayout.Label("" + (int)numMarkers);
            GUILayout.EndHorizontal();

            colliders = GUILayout.Toggle(colliders, "Activate Replay Colliders");

            GUILayout.BeginHorizontal();
            GUILayout.Label("Replay End Action:");
            selectedActionIndex = GUILayout.SelectionGrid(selectedActionIndex, new string[] { "Stop", "Loop", "OffRails", "Delete" }, 4);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Loop closure time:");
            loopTime = GUILayout.HorizontalSlider(loopTime, 0, 100);
            GUILayout.Label("" + (int)loopTime + "s");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();

            if (GUILayout.Button("OK"))
            {
                string newUniqueName = Utilities.makeUniqueTrackName(newName, ref trackList, true);
                if (File.Exists(Utilities.TrackPath + track.TrackName + ".trk"))
                {
                    File.Move(Utilities.TrackPath + track.TrackName + ".trk", Utilities.TrackPath + newUniqueName + ".trk");
                }

                track.TrackName      = newUniqueName;
                track.Description    = newDescription;
                track.LineColor      = newColor;
                track.SamplingFactor = (int)sampling;
                track.LineWidth      = lineWidth;
                track.ConeRadiusToLineWidthFactor = markerRadiusFactor;
                track.NumDirectionMarkers         = (int)numMarkers;
                track.LoopClosureTime             = (int)loopTime;
                track.ReplayColliders             = colliders;
                track.EndAction = (Track.EndActions)selectedActionIndex;

                track.Modified = true;

                track.setupRenderer();
                mainWindow.updateColorTextures();
                SetVisible(false);
                Save(new ConfigNode(GetConfigNodeName()));//Does nothing...
            }

            if (GUILayout.Button("Cancel"))
            {
                SetVisible(false);
            }

            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
        }
        private void createTrackList()
        {
            //Debug.Log("creating track list object");
            //var noExpandWidth = GUILayout.ExpandWidth(false);

            //But the basic way of showing a tooltip would be, in effect, to just do GUILayout.Box(new Rect(mouseX,mouseY, someWidth, someHeight),GUI.tooltip) to have a hovertip.
            trackListScroll = GUILayout.BeginScrollView(trackListScroll, false, true);
            for (int i = 0; i < TrackManager.Instance.allTracks.Count; ++i)
            {
                Track track = TrackManager.Instance.allTracks.ElementAt(i);

                GUILayout.BeginHorizontal(/*noExpandWidth*/); // BEGIN path widgets
                //Name //ShowToggle Delete Continue
                //GUIStyle trackColorFontStyle = new GUIStyle();
                //trackColorFontStyle.normal.textColor = track.LineColor;

                GUILayout.Label(TrackManager.Instance.allTracks.ElementAt(i).TrackName, GUIResources.LabelStyle, GUILayout.ExpandWidth(true), GUILayout.Height(26));

                //track length is only calculated when we are on the same planet to prevent floating point issues
                string lengthString;
                if (FlightGlobals.currentMainBody == TrackManager.Instance.allTracks.ElementAt(i).ReferenceBody)
                {
                    lengthString = Utilities.distanceString(TrackManager.Instance.allTracks.ElementAt(i).length());
                }
                else
                {
                    lengthString = "on " + TrackManager.Instance.allTracks.ElementAt(i).ReferenceBody.bodyName;
                }

                GUILayout.Label(lengthString, GUIResources.LabelStyle, GUILayout.Width(75), GUILayout.Height(26));

                if (trackColorTextures.Count < i + 1)
                {
                    //create new texture
                    Texture2D colorTex = new Texture2D(20, 20);
                    Utilities.SetTextureColor(colorTex, 20, 20, track.LineColor);
                    trackColorTextures.Add(colorTex);
                }


                GUILayout.Label(trackColorTextures[i], GUILayout.Width(26), GUILayout.Height(26));

                Texture2D showIconTex;
                if (track.Visible)
                {
                    showIconTex = visibleTex;
                }
                else
                {
                    showIconTex = invisibleTex;
                }

                if (GUILayout.Button(new GUIContent(showIconTex, "toggle visibility"), GUIResources.ButtonStyle, GUILayout.Width(26), GUILayout.Height(26)))
                {
                    track.toggleVisibility();
                }


                if (GUILayout.Button(new GUIContent(deleteTex, "delete track"), GUIResources.ButtonStyle, GUILayout.Width(26), GUILayout.Height(26)))
                {
                    TrackManager.Instance.deleteTrack(ref track);
                    trackColorTextures.RemoveAt(i);
                    if (i >= TrackManager.Instance.allTracks.Count)
                    {
                        break;
                    }
                }

                GUI.enabled = TrackManager.Instance.isRecordingAllowed();
                if (GUILayout.Button(new GUIContent(continueTex, "resume track with current vessel"), GUIResources.ButtonStyle, GUILayout.Width(26), GUILayout.Height(26)))
                {
                    TrackManager.Instance.continueTrack(track);
                }
                GUI.enabled = true;

                if (GUILayout.Button(new GUIContent(editTex, "edit track properties"), GUIResources.ButtonStyle, GUILayout.Width(26), GUILayout.Height(26)))
                {
                    if (ExplorerTrackBehaviour.Instance.currentlyOpenTrackEditWindow != null)
                    {
                        ExplorerTrackBehaviour.Instance.currentlyOpenTrackEditWindow.SetVisible(false);
                    }

                    ExplorerTrackBehaviour.Instance.currentlyOpenTrackEditWindow = new TrackEditWindow(track, this);
                    ExplorerTrackBehaviour.Instance.currentlyOpenTrackEditWindow.SetVisible(true);
                }

                if (GUILayout.Button(new GUIContent(playbackTex, "playback track"), GUIResources.ButtonStyle, GUILayout.Width(26), GUILayout.Height(26)))
                {
                    ExplorerTrackBehaviour.Instance.replaywindow = new ReplayWindow(track);
                    ExplorerTrackBehaviour.Instance.replaywindow.Awake();
                    ExplorerTrackBehaviour.Instance.replaywindow.SetVisible(true);
                }

                GUILayout.EndHorizontal(); // END path widgets
            }
            GUILayout.EndScrollView();
        }