Esempio n. 1
0
        internal OpenDialog(bool reference)
        {
            editor = Editor.Instance;

            InitializeComponent();
            this.reference = reference;
            if (reference)
            {
                checkBoxAutosave.Visible = false;
            }

            TopLevel = true;

            sortedItems = new List <OpenDialogItem>();
            List <String> files = new List <string>(BeatmapManager.Current.InOszContainer ?
                                                    BeatmapManager.Current.Package.MapFiles :
                                                    Directory.GetFiles(BeatmapManager.Current.ContainingFolderAbsolute, @"*.osu"));

            if (BeatmapManager.Current.ExtractionFolder != null)
            {
                string[] fileOverrides = Directory.GetFiles(BeatmapManager.Current.ExtractionFolder, @"*.osu");
                foreach (string file in fileOverrides)
                {
                    if (!files.Exists((f) => f.EndsWith(Path.GetFileName(file))))
                    {
                        files.Add(file);
                    }
                }
            }

            if (BeatmapManager.Current.ExtractionFolder != null)
            {
                BeatmapManager.ProcessFolder(BeatmapManager.Current.ExtractionFolder);
            }

            foreach (string f in files)
            {
                OpenDialogItem di = new OpenDialogItem();
                Beatmap        b  = BeatmapManager.GetBeatmapByFilename(Path.GetFileName(f));
                if (b == null)
                {
                    di.displayString = "?NEW? " + Path.GetFileName(f);
                    di.filename      = Path.GetFileName(f);
                    di.sort          = 10;
                }
                else
                {
                    di.beatmap       = b;
                    di.filename      = b.Filename;
                    di.displayString = string.Format("{0}", b.Version);
                    di.sort          = b.StarDisplayEyup;
                }

                sortedItems.AddInPlace(di);
            }

            foreach (OpenDialogItem i in sortedItems)
            {
                listBox1.Items.Add(i);
            }

            if (reference)
            {
                OpenDialogItem di = new OpenDialogItem();
                di.displayString = @"None";
                sortedItems.Insert(0, di);
                listBox1.Items.Insert(0, di);

                if (editor.Compose.ReferenceHitObjectManager == null)
                {
                    listBox1.SelectedIndex = 0;
                }
                else
                {
                    SetTo(editor.Compose.ReferenceHitObjectManager.Beatmap);
                }
            }
            else
            {
                SetTo(BeatmapManager.Current);
            }
        }
Esempio n. 2
0
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string oldFilename = BeatmapManager.Current.Filename;
            string newFilename = Path.GetFileName(SelectedFilename);

            if (oldFilename == newFilename)
            {
                return;
            }

            if (reference)
            {
                if (newFilename == null)
                {
                    editor.LoadReferenceFile(null);
                    return;
                }

                Beatmap newMap = BeatmapManager.GetBeatmapByFilename(newFilename);
                if (newMap == null || newMap == BeatmapManager.Current || newMap.PlayMode != PlayModes.OsuMania)
                {
                    return;
                }
                if (!editor.LoadReferenceFile(newMap))
                {
                    MessageBox.Show("Cannot load this file!");
                }
                return;
            }

            if (checkBoxAutosave.Checked)
            {
                editor.SaveIfDirty(false);
            }
            else if (!editor.SaveIfDirty(true))
            {
                SetTo(BeatmapManager.Current);
                return;
            }

            if (!BeatmapManager.SetCurrentFromFilename(newFilename))
            {
                BeatmapManager.ProcessBeatmaps();
                BeatmapManager.SetCurrentFromFilename(newFilename);
            }

            Beatmap b = BeatmapManager.Current;

            if (b != null)
            {
                if (b.Filename != oldFilename)
                {
                    editor.LoadFile(b, false, false);
                    editor.changeManager.HistoryClear();
                }
            }
            else
            {
                BeatmapManager.SetCurrentFromFilename(oldFilename);
                MessageBox.Show("Cannot load this file!");
            }
        }