Пример #1
0
            private void UpdateTimelineTrackTitle(TimelineTrack timelineTrack)
            {
                var newTitle = EditorGUILayout.TextField("title", timelineTrack.title);

                if (newTitle != timelineTrack.title)
                {
                    timelineTrack.BeforeSave();
                    timelineTrack.title = newTitle;
                    timelineTrack.Save();
                }
            }
Пример #2
0
        private void DrawConditionLine(float xOffset, float xScrollIndex, TimelineTrack timeline, float yOffset)
        {
            foreach (var tack in timeline.tackPoints)
            {
                if (!tack.IsExistTack)
                {
                    continue;
                }

                var start = tack.start;
                var span  = tack.span;

                var startPos = xOffset + xScrollIndex + (start * TimeFlowShikiGUISettings.TACK_FRAME_WIDTH);
                var length   = span * TimeFlowShikiGUISettings.TACK_FRAME_WIDTH;
                var tex      = tack.GetColorTex();

                // draw background.
                if (tack.IsActive())
                {
                    var condtionLineBgRect = new Rect(startPos, yOffset - 1, length, TimeFlowShikiGUISettings.CONDITION_INSPECTOR_CONDITIONLINE_HEIGHT + 2);
                    GUI.DrawTexture(condtionLineBgRect, TimeFlowShikiGUISettings.conditionLineBgTex);
                }
                else
                {
                    var condtionLineBgRect = new Rect(startPos, yOffset + 1, length, TimeFlowShikiGUISettings.CONDITION_INSPECTOR_CONDITIONLINE_HEIGHT - 2);
                    GUI.DrawTexture(condtionLineBgRect, TimeFlowShikiGUISettings.conditionLineBgTex);
                }

                // fill color.
                var condtionLineRect = new Rect(startPos + 1, yOffset, length - 2, TimeFlowShikiGUISettings.CONDITION_INSPECTOR_CONDITIONLINE_HEIGHT);
                GUI.DrawTexture(condtionLineRect, tex);
            }

            // draw timelime text
            foreach (var tack in timeline.tackPoints)
            {
                var title = tack.title;
                var start = tack.start;
                var span  = tack.span;

                if (start <= selectedFrame && selectedFrame < start + span)
                {
                    GUI.Label(new Rect(cursorPos + (TimeFlowShikiGUISettings.TACK_FRAME_WIDTH / 2f) + 3f, yOffset - 5f, title.Length * 10f, 20f), title, activeConditionValueLabelStyle);
                }
            }
        }
Пример #3
0
        private Rect DrawConditionInspector(float xScrollIndex, float yIndex, float inspectorWidth)
        {
            var width  = inspectorWidth - TimeFlowShikiGUISettings.TIMELINE_CONDITIONBOX_SPAN;
            var height = yIndex;

            var assumedHeight = height
                                + TimeFlowShikiGUISettings.CONDITION_INSPECTOR_FRAMECOUNT_HEIGHT
                                + TimeFlowShikiGUISettings.CONDITION_INSPECTOR_FRAMELINE_HEIGHT
                                + AssumeConditionLineHeight();

            GUI.BeginGroup(new Rect(TimeFlowShikiGUISettings.TIMELINE_CONDITIONBOX_SPAN, height, width, assumedHeight));
            {
                var internalHeight = 0f;

                // count & frame in header.
                {
                    TimelineTrack.DrawFrameBG(xScrollIndex, internalHeight, width, TimeFlowShikiGUISettings.CONDITION_INSPECTOR_FRAMELINE_HEIGHT, true);
                    internalHeight = internalHeight + TimeFlowShikiGUISettings.CONDITION_INSPECTOR_FRAMECOUNT_HEIGHT + TimeFlowShikiGUISettings.CONDITION_INSPECTOR_FRAMELINE_HEIGHT;
                }
                if (HasValidScore())
                {
                    var currentScore = GetActiveScore();
                    var timelines    = currentScore.timelineTracks;
                    foreach (var timeline in timelines)
                    {
                        if (!timeline.IsExistTimeline)
                        {
                            continue;
                        }
                        internalHeight = internalHeight + TimeFlowShikiGUISettings.CONDITION_INSPECTOR_CONDITIONLINE_SPAN;

                        DrawConditionLine(0, xScrollIndex, timeline, internalHeight);
                        internalHeight = internalHeight + TimeFlowShikiGUISettings.CONDITION_INSPECTOR_CONDITIONLINE_HEIGHT;
                    }

                    if (timelines.Any())
                    {
                        // add footer.
                        internalHeight = internalHeight + TimeFlowShikiGUISettings.CONDITION_INSPECTOR_CONDITIONLINE_SPAN;
                    }
                }
            }
            GUI.EndGroup();

            return(new Rect(0, 0, inspectorWidth, assumedHeight));
        }
Пример #4
0
        private List <ScoreComponent> LoadScores(Dictionary <string, object> deserialized)
        {
            var newScores = new List <ScoreComponent>();

            var scoresList = deserialized[TimeFlowShikiSettings.TIMEFLOWSHIKI_DATA_SCORES] as List <object>;

            foreach (var score in scoresList)
            {
                var scoreDict      = score as Dictionary <string, object>;
                var scoreId        = scoreDict[TimeFlowShikiSettings.TIMEFLOWSHIKI_DATA_SCORE_ID] as string;
                var scoreTitle     = scoreDict[TimeFlowShikiSettings.TIMEFLOWSHIKI_DATA_SCORE_TITLE] as string;
                var scoreTimelines = scoreDict[TimeFlowShikiSettings.TIMEFLOWSHIKI_DATA_SCORE_TIMELINES] as List <object>;

                var currentTimelines = new List <TimelineTrack>();
                foreach (var scoreTimeline in scoreTimelines)
                {
                    var scoreTimelineDict = scoreTimeline as Dictionary <string, object>;

                    var timelineTitle = scoreTimelineDict[TimeFlowShikiSettings.TIMEFLOWSHIKI_DATA_TIMELINE_TITLE] as string;
                    var timelineTacks = scoreTimelineDict[TimeFlowShikiSettings.TIMEFLOWSHIKI_DATA_TIMELINE_TACKS] as List <object>;

                    var currentTacks = new List <TackPoint>();
                    foreach (var timelineTack in timelineTacks)
                    {
                        var timelineTacksDict = timelineTack as Dictionary <string, object>;

                        var tackTitle = timelineTacksDict[TimeFlowShikiSettings.TIMEFLOWSHIKI_DATA_TACK_TITLE] as string;
                        var tackStart = Convert.ToInt32(timelineTacksDict[TimeFlowShikiSettings.TIMEFLOWSHIKI_DATA_TACK_START]);
                        var tackSpan  = Convert.ToInt32(timelineTacksDict[TimeFlowShikiSettings.TIMEFLOWSHIKI_DATA_TACK_SPAN]);

                        var newTack = new TackPoint(currentTacks.Count, tackTitle, tackStart, tackSpan);

                        currentTacks.Add(newTack);
                    }

                    var newTimeline = new TimelineTrack(currentTimelines.Count, timelineTitle, currentTacks);
                    currentTimelines.Add(newTimeline);
                }
                var newScore = new ScoreComponent(scoreId, scoreTitle, currentTimelines);
                newScores.Add(newScore);
            }
            return(newScores);
        }
Пример #5
0
 public void UpdateTimelineTrack(TimelineTrack timelineTrack)
 {
     this.timelineTrack = timelineTrack;
 }
Пример #6
0
        private void Emit(OnTrackEvent onTrackEvent)
        {
            var type = onTrackEvent.eventType;

            // tack events.
            switch (type)
            {
            case OnTrackEvent.EventType.EVENT_UNSELECTED: {
                manipulateTargets = new ManipulateTargets(new List <string>());

                Undo.RecordObject(this, "Unselect");

                var activeAuto = GetActiveScore();
                activeAuto.DeactivateAllObjects();
                Repaint();
                return;
            }

            case OnTrackEvent.EventType.EVENT_OBJECT_SELECTED: {
                manipulateTargets = new ManipulateTargets(new List <string> {
                        onTrackEvent.activeObjectId
                    });

                var activeAuto = GetActiveScore();

                Undo.RecordObject(this, "Select");
                activeAuto.ActivateObjectsAndDeactivateOthers(manipulateTargets.activeObjectIds);
                Repaint();
                return;
            }

            /*
             *      auto events.
             */
            case OnTrackEvent.EventType.EVENT_SCORE_ADDTIMELINE: {
                var activeAuto  = GetActiveScore();
                var tackPoints  = new List <TackPoint>();
                var newTimeline = new TimelineTrack(activeAuto.timelineTracks.Count, "New Timeline", tackPoints);

                Undo.RecordObject(this, "Add Timeline");

                activeAuto.timelineTracks.Add(newTimeline);
                return;
            }


            /*
             *      timeline events.
             */
            case OnTrackEvent.EventType.EVENT_TIMELINE_ADDTACK: {
                eventStacks.Add(onTrackEvent.Copy());
                return;
            }

            case OnTrackEvent.EventType.EVENT_TIMELINE_DELETE: {
                var targetTimelineId = onTrackEvent.activeObjectId;
                var activeAuto       = GetActiveScore();

                Undo.RecordObject(this, "Delete Timeline");

                activeAuto.DeleteObjectById(targetTimelineId);
                Repaint();
                SaveData();
                return;
            }

            case OnTrackEvent.EventType.EVENT_TIMELINE_BEFORESAVE: {
                Undo.RecordObject(this, "Update Timeline Title");
                return;
            }

            case OnTrackEvent.EventType.EVENT_TIMELINE_SAVE: {
                SaveData();
                return;
            }


            /*
             *      tack events.
             */
            case OnTrackEvent.EventType.EVENT_TACK_MOVING: {
                var movingTackId = onTrackEvent.activeObjectId;

                var activeAuto = GetActiveScore();

                activeAuto.SetMovingTackToTimelimes(movingTackId);
                break;
            }

            case OnTrackEvent.EventType.EVENT_TACK_MOVED: {
                Undo.RecordObject(this, "Move Tack");

                return;
            }

            case OnTrackEvent.EventType.EVENT_TACK_MOVED_AFTER: {
                var targetTackId = onTrackEvent.activeObjectId;

                var activeAuto          = GetActiveScore();
                var activeTimelineIndex = activeAuto.GetTackContainedTimelineIndex(targetTackId);
                if (0 <= activeTimelineIndex)
                {
                    activeAuto.timelineTracks[activeTimelineIndex].UpdateByTackMoved(targetTackId);

                    Repaint();
                    SaveData();
                }
                return;
            }

            case OnTrackEvent.EventType.EVENT_TACK_DELETED: {
                var targetTackId = onTrackEvent.activeObjectId;
                var activeAuto   = GetActiveScore();

                Undo.RecordObject(this, "Delete Tack");

                activeAuto.DeleteObjectById(targetTackId);
                Repaint();
                SaveData();
                return;
            }

            case OnTrackEvent.EventType.EVENT_TACK_BEFORESAVE: {
                Undo.RecordObject(this, "Update Tack Title");
                return;
            }

            case OnTrackEvent.EventType.EVENT_TACK_SAVE: {
                SaveData();
                return;
            }

            default: {
                Debug.LogError("no match type:" + type);
                break;
            }
            }
        }
Пример #7
0
        private void DrawAutoConponent(float viewWidth)
        {
            var changedInDraw = false;

            var xScrollIndex = -scrollPos;
            var yOffsetPos   = 0f;


            // draw header.
            var inspectorRect = DrawConditionInspector(xScrollIndex, 0, viewWidth);

            yOffsetPos += inspectorRect.y + inspectorRect.height;

            if (HasValidScore())
            {
                var activeAuto = GetActiveScore();
                // draw timelines
                DrawTimelines(activeAuto, yOffsetPos, xScrollIndex, viewWidth);

                yOffsetPos += activeAuto.TimelinesTotalHeight();

                // draw tick
                DrawTick();
            }

            var useEvent = false;


            switch (Event.current.type)
            {
            // mouse event handling.
            case EventType.MouseDown: {
                var touchedFrameCount = TimelineTrack.GetFrameOnTimelineFromAbsolutePosX(scrollPos + (Event.current.mousePosition.x - TimeFlowShikiGUISettings.TIMELINE_CONDITIONBOX_SPAN));
                if (touchedFrameCount < 0)
                {
                    touchedFrameCount = 0;
                }
                selectedPos   = touchedFrameCount * TimeFlowShikiGUISettings.TACK_FRAME_WIDTH;
                selectedFrame = touchedFrameCount;
                repaint       = true;

                Emit(new OnTrackEvent(OnTrackEvent.EventType.EVENT_UNSELECTED, null));

                useEvent = true;
                break;
            }

            case EventType.ContextClick: {
                ShowContextMenu();
                useEvent = true;
                break;
            }

            case EventType.MouseUp: {
                // right click.
                if (Event.current.button == 1)
                {
                    ShowContextMenu();
                    useEvent = true;
                    break;
                }

                var touchedFrameCount = TimelineTrack.GetFrameOnTimelineFromAbsolutePosX(scrollPos + (Event.current.mousePosition.x - TimeFlowShikiGUISettings.TIMELINE_CONDITIONBOX_SPAN));
                if (touchedFrameCount < 0)
                {
                    touchedFrameCount = 0;
                }
                selectedPos   = touchedFrameCount * TimeFlowShikiGUISettings.TACK_FRAME_WIDTH;
                selectedFrame = touchedFrameCount;
                repaint       = true;
                useEvent      = true;
                break;
            }

            case EventType.MouseDrag: {
                var pos = scrollPos + (Event.current.mousePosition.x - TimeFlowShikiGUISettings.TIMELINE_CONDITIONBOX_SPAN);
                if (pos < 0)
                {
                    pos = 0;
                }
                selectedPos   = pos - ((TimeFlowShikiGUISettings.TACK_FRAME_WIDTH / 2f) - 1f);
                selectedFrame = TimelineTrack.GetFrameOnTimelineFromAbsolutePosX(pos);

                FocusToFrame(selectedFrame);

                repaint  = true;
                useEvent = true;
                break;
            }

            // scroll event handling.
            case EventType.ScrollWheel: {
                if (0 != Event.current.delta.x)
                {
                    scrollPos = scrollPos + (Event.current.delta.x * 2);
                    if (scrollPos < 0)
                    {
                        scrollPos = 0;
                    }

                    repaint = true;
                }
                useEvent = true;
                break;
            }

            // key event handling.
            case EventType.KeyDown: {
                switch (Event.current.keyCode)
                {
                case KeyCode.LeftArrow: {
                    if (manipulateTargets.activeObjectIds.Count == 0)
                    {
                        selectedFrame = selectedFrame - 1;
                        if (selectedFrame < 0)
                        {
                            selectedFrame = 0;
                        }
                        selectedPos = selectedFrame * TimeFlowShikiGUISettings.TACK_FRAME_WIDTH;
                        repaint     = true;

                        FocusToFrame(selectedFrame);
                    }
                    manipulateEvents.keyLeft = true;
                    useEvent = true;
                    break;
                }

                case KeyCode.RightArrow: {
                    if (manipulateTargets.activeObjectIds.Count == 0)
                    {
                        selectedFrame = selectedFrame + 1;
                        selectedPos   = selectedFrame * TimeFlowShikiGUISettings.TACK_FRAME_WIDTH;
                        repaint       = true;

                        FocusToFrame(selectedFrame);
                    }
                    manipulateEvents.keyRight = true;
                    useEvent = true;
                    break;
                }

                case KeyCode.UpArrow: {
                    manipulateEvents.keyUp = true;
                    useEvent = true;
                    break;
                }

                case KeyCode.DownArrow: {
                    manipulateEvents.keyDown = true;
                    useEvent = true;
                    break;
                }
                }
                break;
            }
            }

            // update cursor pos
            cursorPos = selectedPos - scrollPos;



            if (repaint)
            {
                HandleUtility.Repaint();
            }

            if (eventStacks.Any())
            {
                foreach (var onTrackEvent in eventStacks)
                {
                    EmitAfterDraw(onTrackEvent);
                }
                eventStacks.Clear();
                SaveData();
            }

            if (useEvent)
            {
                Event.current.Use();
            }
        }