Develop and Download Open Source Software

Browse Subversion Repository

Contents of /SchoolIdolFestivalSimulator.Main/EditSongForm.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 20 - (show annotations) (download)
Wed Jun 4 13:09:42 2014 UTC (9 years, 11 months ago) by kayochin_3141
File size: 7982 byte(s)


1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using SchoolIdolFestivalSimulator.Components;
10 namespace SchoolIdolFestivalSimulator.Main {
11 public partial class EditSongForm:Form {
12 private SongCollection _songs = null;
13 private EditSongForm() {
14 InitializeComponent();
15 }
16 public EditSongForm(SongCollection songs):this() {
17 _songs = songs;
18 }
19 private void EditSongForm_Load(object sender,EventArgs e) {
20 foreach(Song song in _songs) {
21 ListViewItem li = new ListViewItem();
22 li.Text = song.Name;
23 li.SubItems.Add(song.DifficultyText);
24 li.Tag = song;
25 lv.Items.Add(li);
26 }
27 }
28 /// <summary>
29 /// OKクリック
30 /// </summary>
31 /// <param name="sender"></param>
32 /// <param name="e"></param>
33 private void button1_Click(object sender, EventArgs e) {
34
35 this.DialogResult = System.Windows.Forms.DialogResult.OK;
36 }
37 /// <summary>
38 /// キャンセルクリック
39 /// </summary>
40 /// <param name="sender"></param>
41 /// <param name="e"></param>
42 private void button2_Click(object sender, EventArgs e) {
43 this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
44 }
45
46 private void cmdAdd_Click(object sender,EventArgs e) {
47 Song song = new Song();
48 if(lv.SelectedItems.Count > 0) {
49 _songs.Insert(lv.SelectedItems[0].Index,song);
50 } else {
51 _songs.Add(song);
52 }
53 _songs.Add(song);
54 RemoveEventHandlers();
55 ListViewItem li = new ListViewItem();
56 li.Text = song.Name;
57 li.SubItems.Add(song.DifficultyText);
58 li.Tag = song;
59 lv.Items.Add(li);
60 AddEventHandlers();
61 lv.SelectedItems.Clear();
62 li.EnsureVisible();
63 li.Selected = true;
64 }
65
66 private void cmdDelete_Click(object sender,EventArgs e) {
67 if(lv.SelectedItems.Count <= 0) {
68 return;
69 }
70 _songs.RemoveAt(lv.SelectedItems[0].Index);
71 lv.SelectedItems[0].Remove();
72
73 }
74 private void InitEditPart() {
75 txtSongName.Clear();
76 cboSongType.SelectedIndex = 0;
77 cboDifficulty.SelectedIndex = 0;
78 txtTotalIconCount.Clear();
79 txtLongIconCount.Clear();
80 txtSeconds.Clear();
81 }
82 private void RemoveEventHandlers() {
83 txtLongIconCount.TextChanged -= txtChanged;
84 txtSongName.TextChanged -= txtChanged;
85 txtSeconds.TextChanged -= txtChanged;
86 txtTotalIconCount.TextChanged -= txtChanged;
87 cboSongType.SelectedIndexChanged -= cboSelectedIndexChanged;
88 cboDifficulty.SelectedIndexChanged -= cboSelectedIndexChanged;
89 }
90 private void AddEventHandlers() {
91 cboSongType.SelectedIndexChanged += cboSelectedIndexChanged;
92 cboDifficulty.SelectedIndexChanged += cboSelectedIndexChanged;
93 txtLongIconCount.TextChanged += txtChanged;
94 txtSongName.TextChanged += txtChanged;
95 txtSeconds.TextChanged += txtChanged;
96 txtTotalIconCount.TextChanged += txtChanged;
97 }
98 private void ShowSong(Song song) {
99 RemoveEventHandlers();
100 txtSongName.Text = song.Name;
101 txtTotalIconCount.Text = song.TotalIconCount.ToString();
102 txtLongIconCount.Text = song.LongIconCount.ToString();
103 txtSeconds.Text = song.Seconds.ToString();
104 switch(song.SongType){
105 case StatusType.Smile:
106 cboSongType.SelectedIndex = 0;
107 break;
108 case StatusType.Pure:
109 cboSongType.SelectedIndex = 1;
110 break;
111 case StatusType.Cool:
112 cboSongType.SelectedIndex = 2;
113 break;
114 default:
115 cboSongType.SelectedIndex = 0;
116 break;
117 }
118 switch(song.Difficulty) {
119 case SongDifficulty.Easy:
120 cboDifficulty.SelectedIndex = 0;
121 break;
122 case SongDifficulty.Normal:
123 cboDifficulty.SelectedIndex = 1;
124 break;
125 case SongDifficulty.Hard:
126 cboDifficulty.SelectedIndex = 2;
127 break;
128 case SongDifficulty.Ex:
129 cboDifficulty.SelectedIndex = 3;
130 break;
131 case SongDifficulty.SuperEx:
132 cboDifficulty.SelectedIndex = 4;
133 break;
134 default:
135 cboDifficulty.SelectedIndex = 0;
136 break;
137 }
138 AddEventHandlers();
139 }
140 private void lv_ItemSelectionChanged(object sender,ListViewItemSelectionChangedEventArgs e) {
141 cmdDelete.Enabled = e.IsSelected;
142 InitEditPart();
143 if(!e.IsSelected) {
144 return;
145 }
146 ShowSong((Song)e.Item.Tag);
147 }
148 private Song SelectedSong {
149 get {
150 if(lv.SelectedItems.Count <= 0) {
151 return null;
152 }
153 return (Song)lv.SelectedItems[0].Tag;
154 }
155 }
156 private void txtChanged(object sender,EventArgs e) {
157 if(this.SelectedSong == null) {
158 return;
159 }
160 this.SelectedSong.LongIconCount = txtLongIconCount.Value;
161 this.SelectedSong.TotalIconCount = txtTotalIconCount.Value;
162 this.SelectedSong.Name = txtSongName.Text;
163 this.SelectedSong.Seconds = txtSeconds.Value;
164 lv.SelectedItems[0].Text = txtSongName.Text;
165 }
166
167 private void cboSelectedIndexChanged(object sender,EventArgs e) {
168 if(this.SelectedSong == null) {
169 return;
170 }
171 switch(cboSongType.SelectedIndex) {
172 case 0:
173 this.SelectedSong.SongType = StatusType.Smile;
174 break;
175 case 1:
176 this.SelectedSong.SongType = StatusType.Pure;
177 break;
178 case 2:
179 this.SelectedSong.SongType = StatusType.Cool;
180 break;
181 default:
182 this.SelectedSong.SongType = StatusType.None;
183 break;
184 }
185 switch(cboDifficulty.SelectedIndex) {
186 case 0:
187 this.SelectedSong.Difficulty = SongDifficulty.Easy;
188 break;
189 case 1:
190 this.SelectedSong.Difficulty = SongDifficulty.Normal;
191 break;
192 case 2:
193 this.SelectedSong.Difficulty = SongDifficulty.Hard;
194 break;
195 case 3:
196 this.SelectedSong.Difficulty = SongDifficulty.Ex;
197 break;
198 case 4:
199 this.SelectedSong.Difficulty = SongDifficulty.SuperEx;
200 break;
201 default:
202 this.SelectedSong.Difficulty = SongDifficulty.Easy;
203 break;
204 }
205 lv.SelectedItems[0].SubItems[1].Text = this.SelectedSong.DifficultyText;
206 }
207
208 }
209 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26