private void SetEditorMode(EditorMode mode, EditorStatus status) { status.EditorMode = mode; switch (mode) { case EditorMode.Add: { tsbAdd.Checked = true; tsbEdit.Checked = false; tsbDelete.Checked = false; return; } case EditorMode.Edit: { tsbAdd.Checked = false; tsbEdit.Checked = true; tsbDelete.Checked = false; return; } case EditorMode.Delete: { tsbAdd.Checked = false; tsbEdit.Checked = false; tsbDelete.Checked = true; return; } default: Debug.Assert(false); break; } }
private void SetNoteMode(NoteMode mode, EditorStatus status) { status.NoteMode = mode; foreach (var item in toolStrip2.Items) { var tsb = item as ToolStripButton; if (tsb != null) { tsb.Checked = false; } } switch (mode) { case NoteMode.Touch: tsbTouch.Checked = true; return; case NoteMode.Chain: tsbChain.Checked = true; return; case NoteMode.SlideL: tsbSlideL.Checked = true; return; case NoteMode.SlideR: tsbSlideR.Checked = true; return; case NoteMode.SnapU: tsbSnapU.Checked = true; return; case NoteMode.SnapD: tsbSnapD.Checked = true; return; case NoteMode.Hold: tsbHold.Checked = true; return; case NoteMode.HoldRelay: tsbHoldStep.Checked = true; return; case NoteMode.Field: tsbField.Checked = true; return; default: Debug.Assert(false); break; } }
public MainForm() { InitializeComponent(); Text = appName; var display = new MadcaDisplay(new PictureBox() { Location = new Point(), Size = ClientSize }); var fumen = new MadcaFumenData(); var scoreBook = fumen.ScoreBook; var noteBook = fumen.NoteBook; var operationManager = new OperationManager(); var status = new EditorStatus(EditorMode.Add, NoteMode.Touch, 8, new TimingPosition(8, 1)); for (var i = 0; i < 100; ++i) { scoreBook.AddScoreLast(new Score(4, 4)); } // スクロールバーのための初期設定(ちょっと雑実装?) display.VScrollBar.Maximum = (int)(scoreBook.Size.BarRatio * display.EditorLaneEnvironment.TimingUnitHeight); display.VScrollBar.Value = display.VScrollBar.Maximum; SetEditorMode(EditorMode.Add, status); tsbAdd.Click += (s, e) => SetEditorMode(EditorMode.Add, status); tsbEdit.Click += (s, e) => SetEditorMode(EditorMode.Edit, status); tsbDelete.Click += (s, e) => SetEditorMode(EditorMode.Delete, status); tsbUndo.Enabled = tsbRedo.Enabled = false; tsbUndo.Checked = tsbRedo.Checked = false; tsbUndo.Click += (s, e) => { operationManager.Undo(); display.PictureBox.Refresh(); }; tsbRedo.Click += (s, e) => { operationManager.Redo(); display.PictureBox.Refresh(); }; operationManager.UndoStatusChanged += (b) => tsbUndo.Enabled = b; operationManager.RedoStatusChanged += (b) => tsbRedo.Enabled = b; SetNoteMode(NoteMode.Touch, status); tsbTouch.Click += (s, e) => SetNoteMode(NoteMode.Touch, status); tsbChain.Click += (s, e) => SetNoteMode(NoteMode.Chain, status); tsbSlideL.Click += (s, e) => SetNoteMode(NoteMode.SlideL, status); tsbSlideR.Click += (s, e) => SetNoteMode(NoteMode.SlideR, status); tsbSnapU.Click += (s, e) => SetNoteMode(NoteMode.SnapU, status); tsbSnapD.Click += (s, e) => SetNoteMode(NoteMode.SnapD, status); tsbHold.Click += (s, e) => SetNoteMode(NoteMode.Hold, status); tsbHoldStep.Click += (s, e) => SetNoteMode(NoteMode.HoldRelay, status); tsbField.Click += (s, e) => SetNoteMode(NoteMode.Field, status); #region ToolStripMenuItemの設定 tsmiOpen.Click += (s, e) => { using (var dialog = new OpenFileDialog() { Filter = "MADCA譜面ファイル(*.mdc)|*.mdc", Title = "開く" }) { var result = dialog.ShowDialog(); if (result == DialogResult.OK) { string jsonString = default; try { jsonString = File.ReadAllText(dialog.FileName); } catch (Exception) { MessageBox.Show( "譜面ファイルの読み取りに失敗しました。", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { var fumenInput = JsonSerializer.Deserialize <JsonObject>(jsonString, new JsonSerializerOptions()); if (fumenInput == null) { MessageBox.Show( "譜面データのデシリアライズに失敗しました。", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { try { MyUtil.Normalize(fumenInput); fumen.Exchange(fumenInput); } catch (Exception) { MessageBox.Show( "譜面データの読み込みに失敗しました。", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception) { MessageBox.Show( "譜面データのデシリアライズに失敗しました。", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }; tsmiSaveAs.Click += (s, e) => { using (var dialog = new SaveFileDialog() { FileName = "NewScore.mdc", Filter = "MADCA譜面ファイル(*.mdc)|*.mdc", Title = "名前を付けて保存" }) { var result = dialog.ShowDialog(); if (result == DialogResult.OK) { string jsonString = default; try { jsonString = JsonSerializer.Serialize(fumen.Exchange(), new JsonSerializerOptions { WriteIndented = true }); try { File.WriteAllText(dialog.FileName, jsonString); } catch (Exception) { MessageBox.Show( "譜面データの書き込みに失敗しました。", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception) { MessageBox.Show("譜面データのシリアライズに失敗しました。"); } } } }; #endregion #region 分数指定用ComboBoxの設定 var beatStride = new List <uint>() { 4, 8, 12, 16, 24, 32, 48, 64 }; tscbBeat.Items.AddRange(beatStride.Select(x => $"1 / {x}").ToArray()); tscbBeat.Items.Add("カスタム..."); tscbBeat.SelectedIndexChanged += (s, e) => { if (tscbBeat.SelectedIndex == tscbBeat.Items.Count - 1) { using (var dialog = new BeatStrideDialog()) { dialog.BeatStrideConfirmed += (_, t) => { status.BeatStride = t; // 反映されない...(すでに存在するものの場合は反映された) tscbBeat.Text = $"{t.CntValue} / {t.DivValue}"; }; dialog.ShowDialog(); } return; } if (tscbBeat.SelectedIndex < 0 || tscbBeat.SelectedIndex >= beatStride.Count) { return; } status.BeatStride = new TimingPosition(beatStride[tscbBeat.SelectedIndex], 1); }; tscbBeat.SelectedIndex = 0; #endregion #region ノーツサイズ設定用UI関連 var noteSizeUpDown = new NumericUpDown() { Font = new Font("Yu Gothic UI", 9), Minimum = 1, Maximum = MadcaEnv.LaneCount }; noteSizeUpDown.ValueChanged += (s, e) => { status.NoteSize = (int)noteSizeUpDown.Value; tscbFavoriteNoteSize.SelectedIndex = -1; display.PictureBox.Refresh(); }; var idx = toolStrip1.Items.IndexOf(tsbAddFavoriteSize); toolStrip1.Items.Insert(idx, new ToolStripControlHost(noteSizeUpDown)); var favoriteSize = new List <int>(); tsbAddFavoriteSize.Click += (s, e) => { var size = (int)noteSizeUpDown.Value; if (!favoriteSize.Contains(size)) { favoriteSize.Add(size); tscbFavoriteNoteSize.Items.Clear(); tscbFavoriteNoteSize.Items.AddRange(favoriteSize.OrderBy(n => n).Select(x => x.ToString()).ToArray()); } tscbFavoriteNoteSize.SelectedItem = size.ToString(); }; tscbFavoriteNoteSize.SelectedIndexChanged += (s, e) => { if (tscbFavoriteNoteSize.SelectedIndex == -1) { return; } var selectedIndex = tscbFavoriteNoteSize.SelectedIndex; var item = tscbFavoriteNoteSize.SelectedItem.ToString(); noteSizeUpDown.Value = int.Parse(item); tscbFavoriteNoteSize.SelectedIndex = selectedIndex; }; tsbDeleteFavoriteSize.Click += (s, e) => { if (tscbFavoriteNoteSize.SelectedIndex == -1) { return; } var item = tscbFavoriteNoteSize.SelectedItem.ToString(); favoriteSize.Remove(int.Parse(item)); var selectedIndex = tscbFavoriteNoteSize.SelectedIndex; tscbFavoriteNoteSize.Items.RemoveAt(tscbFavoriteNoteSize.SelectedIndex); tscbFavoriteNoteSize.SelectedIndex = selectedIndex < tscbFavoriteNoteSize.Items.Count ? selectedIndex : tscbFavoriteNoteSize.Items.Count - 1; }; noteSizeUpDown.Value = status.NoteSize; #endregion #if DEBUG var time = new Stopwatch(); display.PictureBox.Paint += (s, e) => time.Restart(); #endif display.PictureBox.Paint += (s, e) => { e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; // まずレーンを描画 LaneDrawer.Draw(e.Graphics, display.EditorLaneEnvironment, scoreBook.Scores); PreviewDrawer.Draw(e.Graphics, display.PreviewDisplayEnvironment, scoreBook.Scores); // 次にレーン上にノーツを描画 NoteDrawer.DrawToLane(e.Graphics, display.EditorLaneEnvironment, noteBook); NoteDrawer.DrawToPreview(e.Graphics, display.PreviewDisplayEnvironment, noteBook); }; SizeChanged += (s, e) => { display.PictureBox.Size = ClientSize; }; Controls.Add(display.PictureBox); MinimumSize = new Size((int)display.EditorLaneEnvironment.SideMargin * 2, 10); SetEventToSetCursor(display, noteBook, status); SetEventToPutNote(display, noteBook, scoreBook.Scores, operationManager, status); SetEventToPutHold(display, noteBook, scoreBook.Scores, operationManager, status); SetEventToPutHoldRelay(display, noteBook, scoreBook.Scores, operationManager, status); SetEventToReLocateNote(display, noteBook, scoreBook.Scores, operationManager, status); SetEventToReSizeNote(display, noteBook, scoreBook.Scores, operationManager, status); SetEventToDeleteNote(display, noteBook, operationManager, status); SetEventToDrawPreviewNote(display, scoreBook.Scores, status); SetEventForRefreshRule(display); // 各種SetEvent関数の最後に置く #if DEBUG display.PictureBox.Paint += (s, e) => { time.Stop(); Console.WriteLine($"Time[ms]: {time.ElapsedMilliseconds}"); }; #endif }