예제 #1
0
 private void SelectNote(CreatorNote target)
 {
     if (target.Selected)
     {
         Table.SelectedNote.Remove(target);
     }
     else
     {
         Table.SelectedNote.Add(target);
     }
     target.ChangeSelected();
 }
예제 #2
0
        public void WriteToTWx()
        {
            if (MaxLine.Equals(0))
            {
                MessageBox.Show(LocaleManager.instance.GetLocaleText("creator_notenoughinfo"), LocaleManager.instance.GetLocaleText("creator_error_nolineval"), MessageBoxButton.OK);
                return;
            }
            if (LevelVal < 1)
            {
                MessageBox.Show(LocaleManager.instance.GetLocaleText("creator_notenoughinfo"), LocaleManager.instance.GetLocaleText("creator_error_nolevelval"), MessageBoxButton.OK);
                return;
            }
            if (NameField.text.Equals(""))
            {
                MessageBox.Show(LocaleManager.instance.GetLocaleText("creator_notenoughinfo"), LocaleManager.instance.GetLocaleText("creator_error_nosongname"), MessageBoxButton.OK);
                return;
            }
            if (!OffsetField.text.Equals("") && !int.TryParse(OffsetField.text, out Offset))
            {
                MessageBox.Show(LocaleManager.instance.GetLocaleText("creator_notenoughinfo"), LocaleManager.instance.GetLocaleText("creator_error_wrongoffset"), MessageBoxButton.OK);
                return;
            }

            TWxMetadata metadata = new TWxMetadata();

            metadata.level   = LevelVal;
            metadata.artist  = ArtistField.text;
            metadata.mapper  = MapperField.text;
            metadata.density = DensityVal;
            metadata.offset  = Offset;

            int            noteID     = 1;
            double         absTime    = Offset / 1000f;
            List <TWxNote> NoteBasket = new List <TWxNote>();
            List <int>
            BPMs            = new List <int>(),
                BPMQueues   = new List <int>(),
                Beats       = new List <int>(),
                BeatsQueues = new List <int>();

            for (int i = 0; i < Blocks.Count; i++)
            {
                double blockTime = (60f * Blocks[i].Beats) / Blocks[i].BPM;
                if (i.Equals(0) || (!i.Equals(0) && Blocks[i].BPM != BPMs[BPMs.Count - 1]))
                {
                    BPMs.Add(Blocks[i].BPM);
                    BPMQueues.Add(Blocks[i].Index);
                }
                if (i.Equals(0) || (!i.Equals(0) && Blocks[i].Beats != Beats[Beats.Count - 1]))
                {
                    Beats.Add(Blocks[i].Beats);
                    BeatsQueues.Add(Blocks[i].Index);
                }
                for (int j = 0; j < Blocks[i].GetNoteArray().Length; j++)
                {
                    CreatorNote baseNote = Blocks[i].GetNoteArray()[j];
                    TWxNote     note     = new TWxNote();

                    baseNote.FinalIndex = noteID;
                    List <int> prevDatas = new List <int>();
                    if (baseNote.PreviousNotes.Count > 0)
                    {
                        for (int k = 0; k < baseNote.PreviousNotes.Count; k++)
                        {
                            prevDatas.Add(baseNote.PreviousNotes[k].FinalIndex);
                        }
                    }
                    int[] prevArr;
                    if (prevDatas.Count.Equals(0))
                    {
                        prevArr = new int[] { 0 };
                    }
                    else
                    {
                        prevArr = prevDatas.ToArray();
                    }
                    note.SetValue(baseNote.YPos + 192 * baseNote.ParentBlock.Index, noteID, baseNote.Size, new byte[4] {
                        baseNote.NoteColor.r, baseNote.NoteColor.g, baseNote.NoteColor.b, 255
                    }, baseNote.Type, baseNote.Flick, (float)absTime + ((float)blockTime * (baseNote.YPos / 192f)), baseNote.Speed, baseNote.StartPoint, baseNote.EndPoint, prevArr);
                    NoteBasket.Add(note);
                    noteID++;
                }
                absTime += blockTime;
            }
            metadata.bpm        = BPMs.ToArray();
            metadata.bpmQueue   = BPMQueues.ToArray();
            metadata.beats      = Beats.ToArray();
            metadata.beatsQueue = BeatsQueues.ToArray();

            TWxData data = new TWxData();

            data.metadata = metadata;
            data.notes    = NoteBasket.ToArray();

            string jsonText = JsonMapper.ToJson(data);

            FileStream   stream = new FileStream(GamePath.CreatorPath() + NameField.text + ".tw" + MaxLine.ToString(), FileMode.Create, FileAccess.Write);
            StreamWriter writer = new StreamWriter(stream);

            writer.Write(jsonText);
            writer.Close();
            stream.Close();
            MessageBox.Show(LocaleManager.instance.GetLocaleText("creator_saved"), LocaleManager.instance.GetLocaleText("creator_saveddesc") + NameField.text + ".tw" + MaxLine.ToString(), MessageBoxButton.OK);
        }
예제 #3
0
        public void CreateNote(Vector2 pos)
        {
            Vector2 localPoint;

            RectTransformUtility.ScreenPointToLocalPointInRectangle(Body, pos, Camera.main, out localPoint);
            Debug.Log(localPoint);

            int xpos = Mathf.RoundToInt((localPoint.x / LineGap) + ((MaxLine + 1) / 2f));

            if (xpos < 1 || xpos > MaxLine)
            {
                return;
            }
            int ypos = CalculateNoteYPos(localPoint.y);

            if (ypos < 192)
            {
                CreatorNote sameNote   = null;
                bool        sameExists = false;
                foreach (CreatorNote note in Notes)
                {
                    if (xpos.Equals((int)note.EndPoint) && ypos.Equals(note.YPos))
                    {
                        sameExists = true; sameNote = note;
                    }
                }
                if (sameExists)
                {
                    DeleteNote(sameNote.gameObject); return;
                }

                GameObject newObj = null;
                if (Table.FlickType.Equals(0))
                {
                    if (Table.NoteType.Equals(0))
                    {
                        newObj = Instantiate(NormalNoteTemplate);
                    }
                    else if (Table.NoteType.Equals(1))
                    {
                        newObj = Instantiate(LongNoteTemplate);
                    }
                    else if (Table.NoteType.Equals(2))
                    {
                        newObj = Instantiate(SlideNoteTemplate);
                    }
                    else if (Table.NoteType.Equals(3))
                    {
                        newObj = Instantiate(DamageNoteTemplate);
                    }
                    else if (Table.NoteType.Equals(4))
                    {
                        newObj = Instantiate(HiddenNoteTemplate);
                    }
                }
                else if (Table.FlickType.Equals(1))
                {
                    newObj = Instantiate(FlickLeftTemplate);
                }
                else if (Table.FlickType.Equals(2))
                {
                    newObj = Instantiate(FlickRightTemplate);
                }
                else if (Table.FlickType.Equals(3))
                {
                    newObj = Instantiate(FlickUpTemplate);
                }
                else if (Table.FlickType.Equals(4))
                {
                    newObj = Instantiate(FlickDownTemplate);
                }

                CreatorNote newNote = newObj.GetComponent <CreatorNote>();
                newNote.StartPoint = Table.StartPoint;
                newNote.EndPoint   = xpos;
                if (Table.StartPoint.Equals(0))
                {
                    newNote.StartPoint = newNote.EndPoint;
                }
                newNote.YPos      = ypos;
                newNote.Size      = Table.SizeVal;
                newNote.Type      = Table.NoteType;
                newNote.Flick     = Table.FlickType;
                newNote.Speed     = Table.NoteSpeed;
                newNote.NoteColor = new Color32(Table.NoteColorR, Table.NoteColorG, Table.NoteColorB, 255);
                newNote.ApplyColor();
                newNote.UpdateInfoToUI();
                newNote.SwitchViewMode();
                Notes.Add(newNote);

                newObj.transform.SetParent(NoteBody);
                newObj.transform.localPosition = new Vector3((newNote.EndPoint - ((MaxLine + 1) / 2f)) * LineGap, Body.sizeDelta.y * (newNote.YPos / 192f), newNote.YPos / 192f);
                newObj.transform.localScale    = new Vector3(1, 1, 1);

                newObj.SetActive(true);
                Table.UpdateNoteCount(1);

                if (newNote.Flick != 0)
                {
                    if (Table.NotePlaceMode.Equals(3))
                    {
                        newNote.PreviousNotes.Add(Table.LastFlickNote);
                        Table.LastFlickNote.NextNote = newNote;
                        CreateTail(Table.LastFlickNote.gameObject, newObj, 30);
                        Table.LastFlickNote = newNote;
                    }
                }

                if (newNote.Type.Equals(1))
                {
                    if (Table.NotePlaceMode.Equals(1))
                    {
                        newNote.PreviousNotes.Add(Table.LastLongNote);
                        Table.LastLongNote.NextNote = newNote;
                        CreateTail(Table.LastLongNote.gameObject, newObj, 50);
                        if (newNote.Flick.Equals(0))
                        {
                            Table.NotePlaceMode = 0;
                            Table.PlaceModeChanged(0);
                        }
                    }
                    else
                    {
                        Table.NotePlaceMode = 1;
                        Table.LastLongNote  = newNote;
                        Table.PlaceModeChanged(1);
                    }
                }
                else if (newNote.Type.Equals(2))
                {
                    if (Table.NotePlaceMode.Equals(2))
                    {
                        newNote.PreviousNotes.Add(Table.LastSlideNote);
                        Table.LastSlideNote.NextNote = newNote;
                        CreateTail(Table.LastSlideNote.gameObject, newObj, 50);
                        Table.LastSlideNote = newNote;
                    }
                    else
                    {
                        Table.NotePlaceMode = 2;
                        Table.LastSlideNote = newNote;
                        Table.PlaceModeChanged(2);
                    }
                }

                if (newNote.Flick != 0)
                {
                    if (Table.NotePlaceMode != 3)
                    {
                        Table.NotePlaceMode = 3;
                        Table.LastFlickNote = newNote;
                        Table.PlaceModeChanged(3);
                    }
                }

                SortNotes();
            }
            else
            {
                if (NextBlock != null)
                {
                    NextBlock.CreateNote(pos);
                }
            }
        }
예제 #4
0
        public void CreateNote(TWxNote note)
        {
            GameObject newObj = null;

            if (note.Flick.Equals(0))
            {
                if (note.Mode.Equals(0))
                {
                    newObj = Instantiate(NormalNoteTemplate);
                }
                else if (note.Mode.Equals(1))
                {
                    newObj = Instantiate(LongNoteTemplate);
                }
                else if (note.Mode.Equals(2))
                {
                    newObj = Instantiate(SlideNoteTemplate);
                }
                else if (note.Mode.Equals(3))
                {
                    newObj = Instantiate(DamageNoteTemplate);
                }
                else if (note.Mode.Equals(4))
                {
                    newObj = Instantiate(HiddenNoteTemplate);
                }
            }
            else if (note.Flick.Equals(1))
            {
                newObj = Instantiate(FlickLeftTemplate);
            }
            else if (note.Flick.Equals(2))
            {
                newObj = Instantiate(FlickRightTemplate);
            }
            else if (note.Flick.Equals(3))
            {
                newObj = Instantiate(FlickUpTemplate);
            }
            else if (note.Flick.Equals(4))
            {
                newObj = Instantiate(FlickDownTemplate);
            }

            CreatorNote newNote = newObj.GetComponent <CreatorNote>();

            newNote.StartPoint = (float)note.StartLine;
            newNote.EndPoint   = (float)note.EndLine;
            newNote.YPos       = note.YPos % 192;
            newNote.Size       = note.Size;
            newNote.Type       = note.Mode;
            newNote.Flick      = note.Flick;
            newNote.Speed      = (float)note.Speed;
            newNote.NoteColor  = new Color32(note.Color[0], note.Color[1], note.Color[2], 255);
            newNote.ApplyColor();
            newNote.UpdateInfoToUI();
            newNote.SwitchViewMode();
            Notes.Add(newNote);
            Table.SelectedNote.Add(newNote);

            newObj.transform.SetParent(NoteBody);
            newObj.transform.localPosition = new Vector3((newNote.EndPoint - ((MaxLine + 1) / 2f)) * LineGap, Body.sizeDelta.y * (newNote.YPos / 192f), newNote.YPos / 192f);
            newObj.transform.localScale    = new Vector3(1, 1, 1);

            newObj.SetActive(true);
            Table.UpdateNoteCount(1);

            if (note.PrevIDs.Length > 0)
            {
                for (int i = 0; i < note.PrevIDs.Length; i++)
                {
                    if (note.PrevIDs[i] > 0)
                    {
                        if (Table.SelectedNote[note.PrevIDs[i] - 1].Type.Equals(1) && newNote.Type.Equals(1))
                        {
                            newNote.PreviousNotes.Add(Table.SelectedNote[note.PrevIDs[i] - 1]);
                            Table.SelectedNote[note.PrevIDs[i] - 1].NextNote = newNote;
                            CreateTail(Table.SelectedNote[note.PrevIDs[i] - 1].gameObject, newObj, 50);
                        }
                        else if (Table.SelectedNote[note.PrevIDs[i] - 1].Type.Equals(2) && newNote.Type.Equals(2))
                        {
                            newNote.PreviousNotes.Add(Table.SelectedNote[note.PrevIDs[i] - 1]);
                            Table.SelectedNote[note.PrevIDs[i] - 1].NextNote = newNote;
                            CreateTail(Table.SelectedNote[note.PrevIDs[i] - 1].gameObject, newObj, 50);
                        }
                        else if (!Table.SelectedNote[note.PrevIDs[i] - 1].Flick.Equals(0) && !newNote.Flick.Equals(0))
                        {
                            newNote.PreviousNotes.Add(Table.SelectedNote[note.PrevIDs[i] - 1]);
                            Table.SelectedNote[note.PrevIDs[i] - 1].NextNote = newNote;
                            CreateTail(Table.SelectedNote[note.PrevIDs[i] - 1].gameObject, newObj, 30);
                        }
                    }
                }
            }

            Table.NoteColorR = newNote.NoteColor.r;
            Table.NoteColorG = newNote.NoteColor.g;
            Table.NoteColorB = newNote.NoteColor.b;
            Table.RText.text = Table.NoteColorR.ToString();
            Table.GText.text = Table.NoteColorG.ToString();
            Table.BText.text = Table.NoteColorB.ToString();
        }
예제 #5
0
 private void Update()
 {
     if (Input.touchSupported && Input.touchCount > 0)
     {
         for (int i = 0; i < Input.touchCount; i++)
         {
             if (Input.GetTouch(i).phase.Equals(TouchPhase.Began))
             {
                 TouchTime.Add(Input.GetTouch(i).fingerId, 0);
                 if (ExtendedInputModule.GetPointerEventData(Input.GetTouch(i).fingerId).pointerEnter != null && ExtendedInputModule.GetPointerEventData(Input.GetTouch(i).fingerId).pointerEnter.tag.Equals("CreatorNote") && ExtendedInputModule.GetPointerEventData(Input.GetTouch(i).fingerId).pointerEnter.GetComponent <CreatorNote>().ParentBlock.Equals(this))
                 {
                     CreatorNote note = ExtendedInputModule.GetPointerEventData(Input.GetTouch(i).fingerId).pointerEnter.GetComponent <CreatorNote>();
                     if (Table.NotePlaceMode.Equals(3) && !note.Flick.Equals(0) && (Table.LastFlickNote.ParentBlock.Index < Index || (Table.LastFlickNote.ParentBlock.Index.Equals(Index) && Table.LastFlickNote.YPos < note.YPos)))
                     {
                         CreateTail(Table.LastFlickNote.gameObject, note.gameObject, 30);
                         Table.LastFlickNote.NextNote = note;
                         note.PreviousNotes.Add(Table.LastFlickNote);
                         Table.PlaceModeChanged(0);
                     }
                     else
                     {
                         SelectNote(ExtendedInputModule.GetPointerEventData(Input.GetTouch(i).fingerId).pointerEnter.GetComponent <CreatorNote>());
                     }
                     TouchTime[Input.GetTouch(i).fingerId] += Time.deltaTime;
                 }
                 else if (ExtendedInputModule.GetPointerEventData(Input.GetTouch(i).fingerId).pointerEnter.Equals(gameObject))
                 {
                     if (Table.SelectedNote.Count.Equals(0))
                     {
                         CreateNote(Input.GetTouch(i).position);
                     }
                     else
                     {
                         while (Table.SelectedNote.Count > 0)
                         {
                             CreatorNote target = Table.SelectedNote[0];
                             target.ChangeSelected();
                             Table.SelectedNote.Remove(target);
                         }
                     }
                 }
             }
             else if (Input.GetTouch(i).phase.Equals(TouchPhase.Stationary))
             {
                 if (ExtendedInputModule.GetPointerEventData(Input.GetTouch(i).fingerId).pointerEnter != null && ExtendedInputModule.GetPointerEventData(Input.GetTouch(i).fingerId).pointerEnter.tag.Equals("CreatorNote") && ExtendedInputModule.GetPointerEventData(Input.GetTouch(i).fingerId).pointerEnter.GetComponent <CreatorNote>().ParentBlock.Equals(this))
                 {
                     if (TouchTime[Input.GetTouch(i).fingerId] >= 0.4f)
                     {
                         DeleteNote(ExtendedInputModule.GetPointerEventData(Input.GetTouch(i).fingerId).pointerEnter);
                     }
                     else
                     {
                         TouchTime[Input.GetTouch(i).fingerId] += Time.deltaTime;
                     }
                 }
             }
             else if (Input.GetTouch(i).phase.Equals(TouchPhase.Ended))
             {
                 TouchTime.Remove(Input.GetTouch(i).fingerId);
             }
         }
     }
     else if (Input.GetMouseButtonDown(0))
     {
         if (ExtendedInputModule.GetPointerEventData().pointerEnter != null && ExtendedInputModule.GetPointerEventData().pointerEnter.tag.Equals("CreatorNote") && ExtendedInputModule.GetPointerEventData().pointerEnter.GetComponent <CreatorNote>().ParentBlock.Equals(this))
         {
             if (inputCount.Equals(0))
             {
                 DeleteNote(ExtendedInputModule.GetPointerEventData().pointerEnter);
             }
         }
         else if (ExtendedInputModule.GetPointerEventData().pointerEnter.Equals(gameObject))
         {
             if (inputCount.Equals(0))
             {
                 CreateNote(Input.mousePosition); justAdded = true;
             }
         }
         inputCount += Time.deltaTime;
     }
     else if (Input.GetMouseButtonDown(1))
     {
         if (ExtendedInputModule.GetPointerEventData().pointerEnter != null && ExtendedInputModule.GetPointerEventData().pointerEnter.tag.Equals("CreatorNote") && ExtendedInputModule.GetPointerEventData().pointerEnter.GetComponent <CreatorNote>().ParentBlock.Equals(this))
         {
             CreatorNote note = ExtendedInputModule.GetPointerEventData().pointerEnter.GetComponent <CreatorNote>();
             if (Table.NotePlaceMode.Equals(3) && !note.Flick.Equals(0) && (Table.LastFlickNote.ParentBlock.Index < Index || (Table.LastFlickNote.ParentBlock.Index.Equals(Index) && Table.LastFlickNote.YPos < note.YPos)))
             {
                 CreateTail(Table.LastFlickNote.gameObject, note.gameObject, 30);
                 Table.LastFlickNote.NextNote = note;
                 note.PreviousNotes.Add(Table.LastFlickNote);
                 Table.PlaceModeChanged(0);
             }
             else
             {
                 SelectNote(ExtendedInputModule.GetPointerEventData().pointerEnter.GetComponent <CreatorNote>());
             }
         }
         else if (ExtendedInputModule.GetPointerEventData().pointerEnter.Equals(gameObject))
         {
             while (Table.SelectedNote.Count > 0)
             {
                 CreatorNote target = Table.SelectedNote[0];
                 target.ChangeSelected();
                 Table.SelectedNote.Remove(target);
             }
         }
     }
     else if (Input.GetMouseButtonUp(0))
     {
         if (justAdded)
         {
             justAdded = false;
         }
         inputCount = 0;
     }
 }