Example #1
0
        public void Clean()
        {
            MusicSource.clip  = null;
            IsPlaying         = false;
            CurrentBlockIndex = -1;
            CurrentTime       = 0;
            while (Buttons.Count > 0)
            {
                GameObject target = Buttons[0];
                Destroy(target);
                Buttons.Remove(target);
            }

            DirectoryInfo CreatorDir = new DirectoryInfo(GamePath.CreatorPath());

            FileInfo[] CreatorFiles = CreatorDir.GetFiles();

            for (int i = 0; i < CreatorFiles.Length; i++)
            {
                string ext = CreatorFiles[i].Extension;
                if (ext.ToUpper().Equals(".WAV") || ext.ToUpper().Equals(".OGG") || ((Application.platform.Equals(RuntimePlatform.Android) || Application.platform.Equals(RuntimePlatform.IPhonePlayer)) && ext.ToUpper().Equals(".MP3")))
                {
                    GameObject newBtn = Instantiate(BtnTemplate);
                    newBtn.SetActive(true);
                    MusicFileBtn fileBtn = newBtn.GetComponent <MusicFileBtn>();
                    fileBtn.Index = Buttons.Count;
                    fileBtn.SetData(CreatorFiles[i].FullName, CreatorFiles[i].Name);
                    newBtn.GetComponent <RectTransform>().SetParent(BtnParent);
                    newBtn.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1);
                    Buttons.Add(newBtn);
                }
            }
        }
Example #2
0
        public void LoadList()
        {
            CurrentListIndex = 0;
            while (FileButtons.Count > 0)
            {
                FileButton target = FileButtons[0];
                Destroy(target.gameObject);
                FileButtons.Remove(target);
            }

            if (!Directory.Exists(GamePath.CreatorPath()))
            {
                Directory.CreateDirectory(GamePath.CreatorPath());
            }

            DirectoryInfo CreatorDir = new DirectoryInfo(GamePath.CreatorPath());

            FileInfo[] CreatorFiles = CreatorDir.GetFiles();

            for (int i = 0, idx = 0; i < CreatorFiles.Length; i++)
            {
                string ext = CreatorFiles[i].Extension;

                bool checkPassed = false;
                for (int j = 0; j < TWxExtensions.Length; j++)
                {
                    if (ext.Equals(TWxExtensions[j]))
                    {
                        checkPassed = true;
                        break;
                    }
                }
                if (checkPassed && File.Exists(CreatorFiles[i].FullName))
                {
                    GameObject newObj = Instantiate(FileObject);
                    newObj.SetActive(true);
                    FileButton fileBtn = newObj.GetComponent <FileButton>();
                    fileBtn.Index    = idx++;
                    fileBtn.FilePath = CreatorFiles[i].FullName;
                    fileBtn.SetText(CreatorFiles[i].Name);
                    newObj.GetComponent <RectTransform>().SetParent(FileObject.transform.parent);
                    newObj.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1);
                    FileButtons.Add(fileBtn);
                }
            }
        }
Example #3
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);
        }