Dictionaryが追加順序を保持するという前提を仕様
@@ -40,6 +40,11 @@ | ||
40 | 40 | private set; |
41 | 41 | } |
42 | 42 | |
43 | + public IEnumerable< LayerData > Layers { | |
44 | + get { | |
45 | + return this.LayerTable.Values; | |
46 | + } | |
47 | + } | |
43 | 48 | /// <summary> |
44 | 49 | /// レイヤを取得します。 |
45 | 50 | /// </summary> |
@@ -46,7 +51,7 @@ | ||
46 | 51 | /// <param name="name">レイヤ名</param> |
47 | 52 | /// <returns>レイヤ</returns> |
48 | 53 | public LayerData GetLayer( string name ) { |
49 | - return this.Layers.Single( layer => layer.Name == name ); | |
54 | + return this.LayerTable[ name ]; | |
50 | 55 | } |
51 | 56 | |
52 | 57 | /// <summary> |
@@ -71,8 +76,8 @@ | ||
71 | 76 | public int ChipCount { |
72 | 77 | get { |
73 | 78 | int value = 0; |
74 | - foreach( LayerData layer in this.Layers ) { | |
75 | - value += layer.Chips.Length; | |
79 | + foreach( LayerData layer in this.LayerTable.Values ) { | |
80 | + value += layer.ChipTable.Count; | |
76 | 81 | } |
77 | 82 | return value; |
78 | 83 | } |
@@ -81,7 +86,7 @@ | ||
81 | 86 | /// <summary> |
82 | 87 | /// レイヤセットを取得します。 |
83 | 88 | /// </summary> |
84 | - public LayerData[] Layers { | |
89 | + public Dictionary< string , LayerData > LayerTable { | |
85 | 90 | get; |
86 | 91 | set; |
87 | 92 | } |
@@ -106,8 +111,8 @@ | ||
106 | 111 | /// </summary> |
107 | 112 | /// <param name="name">レイヤ名</param> |
108 | 113 | /// <returns>チップセット</returns> |
109 | - public LayerChipData[] GetChips( string name ) { | |
110 | - return GetLayer( name ).Chips; | |
114 | + public IEnumerable< LayerChipData > GetChips( string name ) { | |
115 | + return LayerTable[ name ].Chips; | |
111 | 116 | } |
112 | 117 | |
113 | 118 | #region マップの取得 |
@@ -115,7 +120,7 @@ | ||
115 | 120 | /// 指定のレイヤーのチップを参照します。 |
116 | 121 | /// </summary> |
117 | 122 | public LayerChipData[,] GetMap( string name ) { |
118 | - return GetLayer( name ).Map; | |
123 | + return LayerTable[ name ].Map; | |
119 | 124 | } |
120 | 125 | |
121 | 126 | /// <summary> |
@@ -26,18 +26,18 @@ | ||
26 | 26 | StageData stageData = new StageData( stageElement.GetAttribute( "Index" ).ToInt32() ); |
27 | 27 | int mapRowCount = stageElement.GetChildElement( "MapRowCount" ).GetText().ToInt32(); |
28 | 28 | int mapColumnCount = stageElement.GetChildElement( "MapColumnCount" ).GetText().ToInt32(); |
29 | - List< LayerData > layerDataList = new List< LayerData >(); | |
29 | + stageData.LayerTable = new Dictionary< string , LayerData >(); | |
30 | 30 | XmlElement layersElement = stageElement.GetChildElement( "Layers" ); |
31 | 31 | foreach( XmlElement layerElement in layersElement.GetChildElements( "Layer" ) ) { |
32 | 32 | LayerData layerData = new LayerData( layerElement.GetAttribute( "Name" ) ); |
33 | 33 | string chipsetPath = Path.Combine( Path.GetDirectoryName( path ) , layerElement.GetChildElement( "ChipsetPath" ).GetText() ); |
34 | 34 | string chipsetImagePath; |
35 | - LayerChipData[] chipDatas; | |
36 | - LoadLayerChipsetFromFile( out chipsetImagePath , out chipDatas , chipsetPath ); | |
35 | + SortedDictionary< int , LayerChipData > chipTableData; | |
36 | + LoadLayerChipsetFromFile( out chipsetImagePath , out chipTableData , chipsetPath ); | |
37 | 37 | layerData.ChipsetImagePath = chipsetImagePath; |
38 | - layerData.Chips = chipDatas; | |
38 | + layerData.ChipTable = chipTableData; | |
39 | 39 | layerData.Map = new LayerChipData[ mapRowCount , mapColumnCount ]; |
40 | - LayerChipData noneChipData = layerData.Chips[ 0 ]; | |
40 | + LayerChipData noneChipData = layerData.ChipTable[ 0 ]; | |
41 | 41 | for( int i = 0; i < layerData.Map.GetLength( 0 ); ++i ) { |
42 | 42 | for( int j = 0; j < layerData.Map.GetLength( 1 ); ++j ) { |
43 | 43 | layerData.Map[ i , j ] = noneChipData; |
@@ -47,20 +47,19 @@ | ||
47 | 47 | int rowIndex = rowElement.GetAttribute( "Index" ).ToInt32(); |
48 | 48 | foreach( XmlElement columnElement in rowElement.GetChildElements( "Column" ) ) { |
49 | 49 | int columnIndex = columnElement.GetAttribute( "Index" ).ToInt32(); |
50 | - layerData.Map[ rowIndex , columnIndex ] = layerData.Chips[ columnElement.GetText().ToInt32() ]; | |
50 | + layerData.Map[ rowIndex , columnIndex ] = layerData.ChipTable[ columnElement.GetText().ToInt32() ]; | |
51 | 51 | } |
52 | 52 | } |
53 | - layerDataList.Add( layerData ); | |
53 | + stageData.LayerTable.Add( layerData.Name , layerData ); | |
54 | 54 | }; |
55 | - stageData.Layers = layerDataList.ToArray(); | |
56 | 55 | return stageData; |
57 | 56 | } |
58 | 57 | |
59 | - private static void LoadLayerChipsetFromFile( out string imagePath , out LayerChipData[] chipDatas , string path ) { | |
58 | + private static void LoadLayerChipsetFromFile( out string imagePath , out SortedDictionary< int , LayerChipData > chipTableData , string path ) { | |
60 | 59 | XmlDocument document = LoadDocumentFromFile( path ); |
61 | 60 | XmlElement chipsetElement = document.GetChildElement( "LayerChipset" ); |
62 | 61 | imagePath = Path.Combine( Path.GetDirectoryName( path ) , chipsetElement.GetChildElement( "ImagePath" ).GetText() ); |
63 | - Dictionary< int , LayerChipData > chipDataTable = new Dictionary< int , LayerChipData >(); | |
62 | + chipTableData = new SortedDictionary< int , LayerChipData >(); | |
64 | 63 | XmlElement chipsElement = chipsetElement.GetChildElement( "Chips" ); |
65 | 64 | foreach( XmlElement chipElement in chipsElement.GetChildElements( "Chip" ) ) { |
66 | 65 | LayerChipData chipData = new LayerChipData( chipElement.GetAttribute( "Index" ).ToInt32() ); |
@@ -68,9 +67,8 @@ | ||
68 | 67 | chipData.Summary = chipElement.GetChildElement( "Summary" ).GetText(); |
69 | 68 | chipData.Type = chipElement.GetChildElement( "Type" ).GetText().ToEnum< LayerChipType >(); |
70 | 69 | chipData.Friction = chipElement.GetChildElement( "Friction" ).GetText().ToDouble(); |
71 | - chipDataTable.Add( chipData.Index , chipData ); | |
70 | + chipTableData.Add( chipData.Index , chipData ); | |
72 | 71 | } |
73 | - chipDatas = chipDataTable.ToSequence(); | |
74 | 72 | } |
75 | 73 | |
76 | 74 | private static XmlDocument LoadDocumentFromFile( string path ) { |
@@ -97,13 +95,12 @@ | ||
97 | 95 | } |
98 | 96 | |
99 | 97 | var layerNames = Enum.GetNames( typeof( LayerType ) ); |
100 | - List< LayerData > layerList = new List< LayerData >(); | |
98 | + stage.LayerTable = new Dictionary< string , LayerData >(); | |
101 | 99 | for( int i = 0 ; i < layerNames.Length ; i++ ) { |
102 | 100 | var name = layerNames[i]; |
103 | 101 | var layer = LoadLayer( document , Path.GetDirectoryName( path ) , name ); |
104 | - layerList.Add( layer ); | |
102 | + stage.LayerTable[ name ] = layer; | |
105 | 103 | } |
106 | - stage.Layers = layerList.ToArray(); | |
107 | 104 | |
108 | 105 | return stage; |
109 | 106 | } |
@@ -122,9 +119,9 @@ | ||
122 | 119 | var chipsetPath = Path.Combine( currentPath , chipsetFile.Replace( currentPath , string.Empty ).Trim( '\\' ).Replace( "..\\" , string.Empty ) ); |
123 | 120 | var chipsetImagePath = LoadLayerChipsetImagePath( chipsetPath ); |
124 | 121 | |
125 | - var chips = LoadLayerChipTable( chipsetPath ); | |
126 | - var map = LoadMap( document , mapXmlPath , chips ); | |
127 | - return new LayerData( name , chipsetPath , chipsetImagePath , chips , map ); | |
122 | + var chipTable = LoadLayerChipTable( chipsetPath ); | |
123 | + var map = LoadMap( document , mapXmlPath , chipTable.Values ); | |
124 | + return new LayerData( name , chipsetPath , chipsetImagePath , chipTable , map ); | |
128 | 125 | } |
129 | 126 | |
130 | 127 | /// <summary> |
@@ -154,7 +151,7 @@ | ||
154 | 151 | /// </summary> |
155 | 152 | /// <param name="path">チップセットへのパス</param> |
156 | 153 | /// <returns>チップの配列</returns> |
157 | - private static LayerChipData[] LoadLayerChipTable( string path ) { | |
154 | + private static SortedDictionary< int , LayerChipData > LoadLayerChipTable( string path ) { | |
158 | 155 | if( string.IsNullOrEmpty( path ) ) |
159 | 156 | return null; |
160 | 157 | if( File.Exists( path ) == false ) |
@@ -184,7 +181,7 @@ | ||
184 | 181 | chipTable.Add( chip.Index , chip ); |
185 | 182 | } |
186 | 183 | |
187 | - return chipTable.ToSequence(); | |
184 | + return chipTable; | |
188 | 185 | } |
189 | 186 | |
190 | 187 | /// <summary> |
@@ -215,9 +212,9 @@ | ||
215 | 212 | /// </summary> |
216 | 213 | /// <param name="document">XMLドキュメント</param> |
217 | 214 | /// <param name="xmlPath">マップのXMLパス</param> |
218 | - /// <param name="chipDatas">チップの配列</param> | |
215 | + /// <param name="chips">チップの配列</param> | |
219 | 216 | /// <returns>マップ</returns> |
220 | - private static LayerChipData[,] LoadMap( XmlDocument document , string xmlPath , LayerChipData[] chips ) { | |
217 | + private static LayerChipData[,] LoadMap( XmlDocument document , string xmlPath , IEnumerable< LayerChipData > chips ) { | |
221 | 218 | var data = document.TryXmlPath( xmlPath ); |
222 | 219 | if( string.IsNullOrEmpty( data ) ) |
223 | 220 | return null; |
@@ -263,7 +263,7 @@ | ||
263 | 263 | } |
264 | 264 | |
265 | 265 | public static T[] ToSequence< T >( this IDictionary< int , T > source ) { |
266 | - T[] target = new T[ source.Max( item => item.Key ) + 1 ]; | |
266 | + T[] target = new T[ source.Max( item => item.Key ) ]; | |
267 | 267 | foreach( var item in source ) { |
268 | 268 | target[ item.Key ] = item.Value; |
269 | 269 | } |
@@ -20,13 +20,13 @@ | ||
20 | 20 | /// <param name="name">レイヤ名</param> |
21 | 21 | /// <param name="chipsetPath">チップセットへのパス</param> |
22 | 22 | /// <param name="chipsetImagePath">イメージへのパス</param> |
23 | - /// <param name="chipDatas">すべてのチップ</param> | |
23 | + /// <param name="chips">すべてのチップ</param> | |
24 | 24 | /// <param name="map">マップ</param> |
25 | - public LayerData( string name , string chipsetPath , string chipsetImagePath , LayerChipData[] chips , LayerChipData[,] map ) { | |
25 | + public LayerData( string name , string chipsetPath , string chipsetImagePath , SortedDictionary< int , LayerChipData > chipTable , LayerChipData[,] map ) { | |
26 | 26 | this.Name = name; |
27 | 27 | this.ChipsetPath = chipsetPath; |
28 | 28 | this.ChipsetImagePath = chipsetImagePath; |
29 | - this.Chips = chips; | |
29 | + this.ChipTable = chipTable; | |
30 | 30 | this.Map = map; |
31 | 31 | } |
32 | 32 |
@@ -54,10 +54,15 @@ | ||
54 | 54 | /// <summary> |
55 | 55 | /// すべてのチップ |
56 | 56 | /// </summary> |
57 | - public LayerChipData[] Chips { | |
57 | + public SortedDictionary< int , LayerChipData > ChipTable { | |
58 | 58 | get; |
59 | 59 | set; |
60 | 60 | } |
61 | + public IEnumerable< LayerChipData > Chips { | |
62 | + get { | |
63 | + return this.ChipTable.Values; | |
64 | + } | |
65 | + } | |
61 | 66 | /// <summary> |
62 | 67 | /// マップ |
63 | 68 | /// </summary> |
@@ -51,12 +51,12 @@ | ||
51 | 51 | document.Save( path ); |
52 | 52 | } |
53 | 53 | |
54 | - private static void SaveLayerChipsetToFile( string path , string imagePath , LayerChipData[] chipDatas ) { | |
54 | + private static void SaveLayerChipsetToFile( string path , string imagePath , IEnumerable< LayerChipData > chipsData ) { | |
55 | 55 | XmlDocument document = CreateDocument(); |
56 | 56 | XmlElement chipsetElement = document.AddChildElement( "LayerChipset" ); |
57 | 57 | chipsetElement.AddChildElement( "ImagePath" ).SetText( Utility.GetRelativePath( imagePath , Path.GetDirectoryName( path ) ) ); |
58 | 58 | XmlElement chipsNode = chipsetElement.AddChildElement( "Chips" ); |
59 | - foreach( LayerChipData chipData in chipDatas ) { | |
59 | + foreach( LayerChipData chipData in chipsData ) { | |
60 | 60 | XmlElement chipElement = chipsNode.AddChildElement( "Chip" ); |
61 | 61 | chipElement.SetAttribute( "Index" , chipData.Index.ToString() ); |
62 | 62 | chipElement.AddChildElement( "Name" ).SetText( chipData.Name ); |
@@ -23,15 +23,13 @@ | ||
23 | 23 | |
24 | 24 | foreach( var layerData in stageData.Layers ) { |
25 | 25 | var layerNotify = LayerInstance.Add( layerData.Name ); |
26 | - Dictionary< int , LayerChipNotify > chipNotifyTable = new Dictionary< int , LayerChipNotify >(); | |
27 | 26 | foreach( var chipData in layerData.Chips ) { |
28 | - var chipNotify = ChipsetInstance.Add( layerNotify , chipData.Index ); | |
29 | 27 | var chipProperty = new LayerChipProperty(); |
30 | 28 | chipProperty.Name = chipData.Name; |
31 | 29 | chipProperty.Friction = chipData.Friction; |
32 | 30 | chipProperty.Type = chipData.Type.ToString(); |
33 | 31 | chipProperty.Summary = chipData.Summary; |
34 | - chipNotify.SetProperty( chipProperty ); | |
32 | + ChipsetInstance.Add( layerNotify , new LayerChipNotify( chipData.Index , chipProperty ) ); | |
35 | 33 | } |
36 | 34 | layerNotify.ChipsetPath = layerData.ChipsetPath; |
37 | 35 | LayerInstance.LoadImage( layerNotify , layerData.ChipsetImagePath ); |
@@ -39,12 +37,12 @@ | ||
39 | 37 | var mapNotify = new LayerChipNotify[ mapData.GetLength( 0 ) , mapData.GetLength( 1 ) ]; |
40 | 38 | for( int y = 0 ; y < mapNotify.GetLength( 0 ) ; y++ ) { |
41 | 39 | for( int x = 0 ; x < mapNotify.GetLength( 1 ) ; x++ ) { |
42 | - mapNotify[ y , x ] = layerNotify.ChipList[ mapData[ y , x ].Index ]; | |
40 | + mapNotify[ y , x ] = layerNotify.ChipTable[ mapData[ y , x ].Index ]; | |
43 | 41 | } |
44 | 42 | } |
45 | 43 | LayerInstance.SetMap( layerNotify , mapNotify ); |
46 | 44 | |
47 | - editor.SetCurrentChip( layerNotify , layerNotify.ChipList[ 0 ] ); | |
45 | + editor.SetCurrentChip( layerNotify , layerNotify.ChipTable[ 0 ] ); | |
48 | 46 | } |
49 | 47 | |
50 | 48 | LayerInstance.SetCurrentLayer( 0 ); |
@@ -5,7 +5,6 @@ | ||
5 | 5 | using System.ComponentModel; |
6 | 6 | using System.Drawing; |
7 | 7 | using Nlgp1.StageEditor.Notifies.LayerChipProperties; |
8 | -using Nlgp1.Common; | |
9 | 8 | |
10 | 9 | namespace Nlgp1.StageEditor.Notifies { |
11 | 10 | public class LayerNotify : INotifyPropertyChanged { |
@@ -24,11 +23,17 @@ | ||
24 | 23 | get; |
25 | 24 | private set; |
26 | 25 | } |
27 | - public List< LayerChipNotify > ChipList { | |
26 | + public IEnumerable< LayerChipNotify > Chips { | |
27 | + get { | |
28 | + return this.ChipTable.Values; | |
29 | + } | |
30 | + } | |
31 | + public LayerChipNotify[,] Map { | |
28 | 32 | get; |
29 | 33 | private set; |
30 | 34 | } |
31 | - public LayerChipNotify[,] Map { | |
35 | + | |
36 | + public SortedDictionary< int , LayerChipNotify > ChipTable { | |
32 | 37 | get; |
33 | 38 | private set; |
34 | 39 | } |
@@ -36,7 +41,7 @@ | ||
36 | 41 | public LayerNotify( int row , int column ) { |
37 | 42 | if( row > 0 && column > 0 ) { |
38 | 43 | this.ChipsetImage = new ChipsetImage(); |
39 | - this.ChipList = new List< LayerChipNotify >(); | |
44 | + this.ChipTable = new SortedDictionary< int , LayerChipNotify >(); | |
40 | 45 | |
41 | 46 | this.Map = new LayerChipNotify[ row , column ]; |
42 | 47 | for( int i = 0; i < this.Map.GetLength( 0 ); ++i ) { |
@@ -49,7 +54,7 @@ | ||
49 | 54 | this.Name = "None"; |
50 | 55 | this.Map = new LayerChipNotify[ row , column ]; |
51 | 56 | this.ChipsetImage = ChipsetImage.None; |
52 | - this.ChipList = new List< LayerChipNotify >(); | |
57 | + this.ChipTable = new SortedDictionary< int , LayerChipNotify >(); | |
53 | 58 | } |
54 | 59 | } |
55 | 60 |
@@ -64,28 +69,32 @@ | ||
64 | 69 | } |
65 | 70 | |
66 | 71 | #region チップ操作 |
67 | - public LayerChipNotify AddChip( int chipIndex ) { | |
68 | - var createdChip = new LayerChipNotify( chipIndex ); | |
69 | - this.ChipList.Add( createdChip ); | |
70 | - var chipSequence = ChipList.ToDictionary( chip => chip.Index ).ToSequence(); | |
71 | - this.ChipList.Clear(); | |
72 | - this.ChipList.AddRange( chipSequence ); | |
72 | + public LayerChipNotify CreateChip() { | |
73 | + return new LayerChipNotify( ChipTable.Keys.Max() + 1 ); | |
74 | + } | |
75 | + | |
76 | + public void AddChip( LayerChipNotify chip ) { | |
77 | + this.ChipTable.Add( chip.Index , chip ); | |
73 | 78 | OnPropertyChanged( "AddChipData" ); |
74 | - return createdChip; | |
75 | 79 | } |
76 | 80 | |
77 | - public void RemoveChip() { | |
78 | - if( this.ChipList.Count <= 1 ) | |
81 | + public void RemoveChip( LayerChipNotify removedChip ) { | |
82 | + if( ChipTable.Count <= 1 ) | |
79 | 83 | return; |
80 | 84 | |
85 | + if( removedChip == LayerChipNotify.None ) { | |
86 | + ChipTable.Remove( removedChip.Index ); | |
87 | + OnPropertyChanged( "RemoveChipData" ); | |
88 | + return; | |
89 | + } | |
81 | 90 | |
82 | - LayerChipNotify removedChip = this.ChipList[ this.ChipList.Count - 1 ]; | |
83 | - this.ChipList.RemoveAt( this.ChipList.Count - 1 ); | |
84 | 91 | |
92 | + ChipTable.Remove( removedChip.Index ); | |
93 | + | |
85 | 94 | for( int i = 0; i < this.Map.GetLength( 0 ); ++i ) { |
86 | 95 | for( int j = 0; j < this.Map.GetLength( 1 ); ++j ) { |
87 | 96 | if( this.Map[ i , j ] == removedChip ) { |
88 | - this.Map[ i , j ] = this.ChipList[ 0 ]; | |
97 | + this.Map[ i , j ] = this.ChipTable[ 0 ]; | |
89 | 98 | } |
90 | 99 | } |
91 | 100 | } |
@@ -94,15 +103,21 @@ | ||
94 | 103 | } |
95 | 104 | |
96 | 105 | public LayerChipNotify GetPreviousChip( LayerChipNotify chip ) { |
106 | + if( Chips.Contains( chip ) == false ) | |
107 | + return Chips.First(); | |
108 | + | |
97 | 109 | var index = chip.Index; |
98 | 110 | index = Math.Max( index - 1 , 0 ); |
99 | - return ChipList[index]; | |
111 | + return ChipTable[index]; | |
100 | 112 | } |
101 | 113 | |
102 | 114 | public LayerChipNotify GetNextChip( LayerChipNotify chip ) { |
115 | + if( Chips.Contains( chip ) == false ) | |
116 | + return Chips.Last(); | |
117 | + | |
103 | 118 | var index = chip.Index; |
104 | - index = Math.Min( index + 1 , ChipList.Count - 1 ); | |
105 | - return ChipList[index]; | |
119 | + index = Math.Min( index + 1 , ChipTable.Count - 1 ); | |
120 | + return ChipTable[index]; | |
106 | 121 | } |
107 | 122 | #endregion |
108 | 123 |
@@ -120,7 +135,7 @@ | ||
120 | 135 | } |
121 | 136 | public void SetChip(int chipIndex, int row, int column) |
122 | 137 | { |
123 | - this.SetChip( this.ChipList[ chipIndex ] , row , column ); | |
138 | + this.SetChip( this.ChipTable[ chipIndex ] , row , column ); | |
124 | 139 | } |
125 | 140 | //ID返す |
126 | 141 | public int GetChipIndex(int row, int column) |
@@ -43,6 +43,11 @@ | ||
43 | 43 | this.Property = chipProperty; |
44 | 44 | } |
45 | 45 | |
46 | + public LayerChipNotify( int index , LayerChipProperty chipProperty ) { | |
47 | + this.Index = index; | |
48 | + this.Property = chipProperty; | |
49 | + } | |
50 | + | |
46 | 51 | public void SetIndex( int index ) { |
47 | 52 | this.Index = index; |
48 | 53 |
@@ -18,31 +18,29 @@ | ||
18 | 18 | |
19 | 19 | var stageData = new StageData( 0 ); |
20 | 20 | |
21 | - List< LayerData > layerDataList = new List< LayerData >(); | |
21 | + stageData.LayerTable = new Dictionary< string , LayerData >(); | |
22 | 22 | foreach( var layerNotify in stageNotify.LayerList ) { |
23 | 23 | var layerData = new LayerData( layerNotify.Name ); |
24 | 24 | layerData.ChipsetPath = layerNotify.ChipsetPath; |
25 | 25 | layerData.ChipsetImagePath = layerNotify.ChipsetImage.Path; |
26 | - Dictionary< int , LayerChipData > chipDataTable = new Dictionary< int ,LayerChipData >(); | |
27 | - foreach( var chipNotify in layerNotify.ChipList ) { | |
26 | + layerData.ChipTable = new SortedDictionary< int ,LayerChipData >(); | |
27 | + foreach( var chipNotify in layerNotify.Chips ) { | |
28 | 28 | var chipData = new LayerChipData( chipNotify.Index ); |
29 | 29 | chipData.Name = chipNotify.Property.Name; |
30 | 30 | chipData.Summary = chipNotify.Property.Summary; |
31 | 31 | chipData.Type = chipNotify.Property.Type.ToEnum< LayerChipType >(); |
32 | 32 | chipData.Friction = chipNotify.Property.Friction; |
33 | - chipDataTable.Add( chipData.Index , chipData ); | |
33 | + layerData.ChipTable.Add( chipData.Index , chipData ); | |
34 | 34 | } |
35 | - layerData.Chips = chipDataTable.ToSequence(); | |
36 | 35 | var mapNotify = layerNotify.Map; |
37 | 36 | layerData.Map = new LayerChipData[ mapNotify.GetLength( 0 ) , mapNotify.GetLength( 1 ) ]; |
38 | 37 | for( int y = 0 ; y < mapNotify.GetLength( 0 ) ; y++ ) { |
39 | 38 | for( int x = 0 ; x < mapNotify.GetLength( 1 ) ; x++ ) { |
40 | - layerData.Map[ y , x ] = layerData.Chips[ mapNotify[ y , x ].Index ]; | |
39 | + layerData.Map[ y , x ] = layerData.ChipTable[ mapNotify[ y , x ].Index ]; | |
41 | 40 | } |
42 | 41 | } |
43 | - layerDataList.Add( layerData ); | |
42 | + stageData.LayerTable.Add( layerData.Name , layerData ); | |
44 | 43 | } |
45 | - stageData.Layers = layerDataList.ToArray(); | |
46 | 44 | |
47 | 45 | stageData.Save( path ); |
48 | 46 | stageNotify.SetPath( path ); |
@@ -65,8 +63,8 @@ | ||
65 | 63 | |
66 | 64 | var sameChipFunc = new Action( () => { |
67 | 65 | foreach( var layer in layerList ) |
68 | - foreach( var chip1 in layer.ChipList ) | |
69 | - foreach( var chip2 in layer.ChipList ) { | |
66 | + foreach( var chip1 in layer.Chips ) | |
67 | + foreach( var chip2 in layer.Chips ) { | |
70 | 68 | if( chip1 == chip2 ) |
71 | 69 | continue; |
72 | 70 | if( chip1.Property.Name != chip2.Property.Name ) |
@@ -12,6 +12,8 @@ | ||
12 | 12 | { |
13 | 13 | public partial class LayerAdderControl : UserControl |
14 | 14 | { |
15 | + private IEnumerable< int > validIndexList; | |
16 | + | |
15 | 17 | public LayerAdderControl() |
16 | 18 | { |
17 | 19 | InitializeComponent(); |
@@ -43,6 +45,7 @@ | ||
43 | 45 | |
44 | 46 | private void UpdateValidList(LayerNotify layer) |
45 | 47 | { |
48 | + this.validIndexList = layer.ChipTable.Keys; | |
46 | 49 | } |
47 | 50 | |
48 | 51 | private void AddButton_Click(object sender, EventArgs e) |
@@ -81,6 +81,7 @@ | ||
81 | 81 | this.DeleteButton.TabIndex = 2; |
82 | 82 | this.DeleteButton.Text = "削除"; |
83 | 83 | this.DeleteButton.UseVisualStyleBackColor = true; |
84 | + | |
84 | 85 | // |
85 | 86 | // ImageLoadButton |
86 | 87 | // |
@@ -110,7 +111,7 @@ | ||
110 | 111 | // CommandPanel |
111 | 112 | // |
112 | 113 | this.CommandPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) |
113 | - | System.Windows.Forms.AnchorStyles.Right))); | |
114 | + | System.Windows.Forms.AnchorStyles.Right))); | |
114 | 115 | this.CommandPanel.Controls.Add(this.SettingButton); |
115 | 116 | this.CommandPanel.Controls.Add(this.DeleteButton); |
116 | 117 | this.CommandPanel.Controls.Add(this.ImageLoadButton); |
@@ -263,7 +263,7 @@ | ||
263 | 263 | // chipSetSave |
264 | 264 | // |
265 | 265 | this.chipSetSave.DefaultExt = "png"; |
266 | - this.chipSetSave.FileName = "chipDatas.png"; | |
266 | + this.chipSetSave.FileName = "chips.png"; | |
267 | 267 | this.chipSetSave.Filter = "PNGファイル|*.png"; |
268 | 268 | this.chipSetSave.RestoreDirectory = true; |
269 | 269 | this.chipSetSave.Title = "チップセットの保存"; |
@@ -12,7 +12,7 @@ | ||
12 | 12 | public partial class LayerChipsetControl : UserControl { |
13 | 13 | private int chipSize = 1; |
14 | 14 | private ChipsetImage chipsetImage = ChipsetImage.None; |
15 | - private List< LayerChipNotify > chipList = new List< LayerChipNotify >(); | |
15 | + private SortedDictionary< int , LayerChipNotify > chipTable = new SortedDictionary< int , LayerChipNotify >(); | |
16 | 16 | private LayerNotify currentLayer = LayerNotify.None; |
17 | 17 | private LayerChipNotify currentChip = LayerChipNotify.None; |
18 | 18 |
@@ -75,7 +75,7 @@ | ||
75 | 75 | this.currentLayer = editor.CurrentLayer; |
76 | 76 | this.currentChip = editor.CurrentChip; |
77 | 77 | this.chipsetImage = currentLayer.ChipsetImage; |
78 | - this.chipList = currentLayer.ChipList; | |
78 | + this.chipTable = currentLayer.ChipTable; | |
79 | 79 | |
80 | 80 | this.CommandPanel.Visible = ( currentLayer != LayerNotify.None ); |
81 | 81 |
@@ -85,13 +85,13 @@ | ||
85 | 85 | #endregion |
86 | 86 | |
87 | 87 | private void UpdateSize( object sender , EventArgs e ) { |
88 | - if( chipList.Count == 0 ) | |
88 | + if( chipTable.Count == 0 ) | |
89 | 89 | return; |
90 | 90 | |
91 | 91 | var clientWidth = ThumbnailClientWidth; |
92 | 92 | var clientHeight = ChipThumbnailBase.Height; |
93 | 93 | |
94 | - var chipNum = chipList.Count; | |
94 | + var chipNum = chipTable.Count; | |
95 | 95 | |
96 | 96 | var width = ( clientWidth / chipSize ) * chipSize; |
97 | 97 | var column = width / chipSize; |
@@ -124,10 +124,10 @@ | ||
124 | 124 | var y = e.Y / chipSize; |
125 | 125 | var gridNumber = x + y * column; |
126 | 126 | |
127 | - if( gridNumber >= chipList.Count ) | |
127 | + if( gridNumber >= chipTable.Count ) | |
128 | 128 | return; |
129 | 129 | |
130 | - var chip = chipList[gridNumber]; | |
130 | + var chip = chipTable[gridNumber]; | |
131 | 131 | |
132 | 132 | OnChipClicked( chip ); |
133 | 133 | } |
@@ -139,7 +139,7 @@ | ||
139 | 139 | |
140 | 140 | var gridPen = Pens.Black; |
141 | 141 | var i = 0; |
142 | - foreach( var chip in chipList ) { | |
142 | + foreach( var chip in chipTable.Values ) { | |
143 | 143 | var x = ( i % column ) * chipSize; |
144 | 144 | var y = ( i / column ) * chipSize; |
145 | 145 | var imageNumber = chip.Index; |
@@ -615,7 +615,7 @@ | ||
615 | 615 | { |
616 | 616 | for (int j = 0; j < layer.Map.GetLength( 1 ); j++) |
617 | 617 | { |
618 | - layer.Map[ i , j ] = layer.ChipList[ 0 ]; | |
618 | + layer.Map[ i , j ] = layer.ChipTable[ 0 ]; | |
619 | 619 | } |
620 | 620 | } |
621 | 621 | } |
@@ -643,7 +643,7 @@ | ||
643 | 643 | targetMap[i, j] = sourceMap[i, j]; |
644 | 644 | } |
645 | 645 | else { |
646 | - targetMap[i, j] = layer.ChipList[0]; | |
646 | + targetMap[i, j] = layer.ChipTable[0]; | |
647 | 647 | } |
648 | 648 | } |
649 | 649 | } |
@@ -6,7 +6,6 @@ | ||
6 | 6 | using Nlgp1.StageEditor.Controls; |
7 | 7 | using System.Windows.Forms; |
8 | 8 | using Nlgp1.StageEditor.Instances; |
9 | -using Nlgp1.StageEditor.Notifies.LayerChipProperties; | |
10 | 9 | |
11 | 10 | namespace Nlgp1.StageEditor.Controls.Events |
12 | 11 | { |
@@ -18,7 +17,7 @@ | ||
18 | 17 | { |
19 | 18 | var layer = LayerInstance.Add(e.Name); |
20 | 19 | //LayerController.Add(e.Name, e.DefaultChipID); |
21 | - ChipsetInstance.Add(layer); | |
20 | + ChipsetInstance.Add(layer, layer.CreateChip()); | |
22 | 21 | }; |
23 | 22 | |
24 | 23 | layersetControl.LayerTabSelected += (sender, e) => |
@@ -6,7 +6,6 @@ | ||
6 | 6 | using Nlgp1.StageEditor.Controls; |
7 | 7 | using System.Windows.Forms; |
8 | 8 | using Nlgp1.StageEditor.Instances; |
9 | -using Nlgp1.StageEditor.Notifies.LayerChipProperties; | |
10 | 9 | |
11 | 10 | namespace Nlgp1.StageEditor.Controls.Events |
12 | 11 | { |
@@ -15,7 +14,7 @@ | ||
15 | 14 | public static void Initialize(LayerChipsetControl chipsetControl, EditorNotify editor, StageNotify stage) |
16 | 15 | { |
17 | 16 | var commandTable = new Dictionary<string, Action>(); |
18 | - commandTable["Add"] = () => ChipsetInstance.Add(editor.CurrentLayer); | |
17 | + commandTable["Add"] = () => ChipsetInstance.Add(editor.CurrentLayer, editor.CurrentLayer.CreateChip()); | |
19 | 18 | commandTable["Delete"] = () => |
20 | 19 | { |
21 | 20 | var response = MessageBox.Show("本当に削除しますか?ステージは保存されてないかもしれませんよ?", "確認", MessageBoxButtons.YesNoCancel); |
@@ -26,7 +25,7 @@ | ||
26 | 25 | } |
27 | 26 | else if (response == DialogResult.Yes) |
28 | 27 | { |
29 | - ChipsetInstance.Remove(editor.CurrentLayer); | |
28 | + ChipsetInstance.Remove(editor.CurrentLayer, editor.CurrentChip); | |
30 | 29 | } |
31 | 30 | |
32 | 31 | }; |
@@ -26,7 +26,7 @@ | ||
26 | 26 | CommanTable["Clear"] = () => { |
27 | 27 | for( int i = 0 ; i < layer.Map.GetLength( 0 ) ; i++ ) { |
28 | 28 | for( int j = 0 ; j < layer.Map.GetLength( 1 ) ; j++ ) { |
29 | - layer.Map[ i , j ] = layer.ChipList[ 0 ]; | |
29 | + layer.Map[ i , j ] = layer.ChipTable[ 0 ]; | |
30 | 30 | } |
31 | 31 | } |
32 | 32 | layer.OnPropertyChanged( "SetGridData" ); |
@@ -21,37 +21,28 @@ | ||
21 | 21 | ChipsetInstance.editor = editor; |
22 | 22 | } |
23 | 23 | |
24 | - public static LayerChipNotify Add(LayerNotify layer) | |
24 | + public static void Add(LayerNotify layer, LayerChipNotify chip ) | |
25 | 25 | { |
26 | - return ChipsetInstance.Add(layer, layer.ChipList.Count); | |
27 | - } | |
28 | - | |
29 | - public static LayerChipNotify Add(LayerNotify layer, int chipIndex) | |
30 | - { | |
31 | - var chip = layer.AddChip(chipIndex); | |
32 | 26 | chip.PropertyChanged += stageEditor.MapControl.ChipData_PropertyChanged; |
33 | 27 | chip.PropertyChanged += stageEditor.LayerChipControl.ChipData_PropertyChanged; |
34 | 28 | chip.PropertyChanged += stageEditor.LayerChipsetControl.ChipData_PropertyChanged; |
35 | 29 | |
30 | + layer.AddChip(chip); | |
36 | 31 | editor.SetCurrentChip(layer, chip); |
37 | 32 | if (editor.CurrentLayer == layer) |
38 | 33 | { |
39 | 34 | editor.CurrentChip = chip; |
40 | 35 | } |
41 | - return chip; | |
42 | 36 | } |
43 | 37 | |
44 | - private static void InitializeChip(LayerChipNotify chip) { | |
45 | - } | |
46 | - | |
47 | - public static void Remove(LayerNotify layer) | |
38 | + public static void Remove(LayerNotify layer, LayerChipNotify chip) | |
48 | 39 | { |
49 | - var previousChip = layer.GetPreviousChip(editor.CurrentChip); | |
50 | - layer.RemoveChip(); | |
51 | - editor.SetCurrentChip(layer, previousChip); | |
40 | + var prevChip = layer.GetPreviousChip(editor.CurrentChip); | |
41 | + layer.RemoveChip(chip); | |
42 | + editor.SetCurrentChip(layer, prevChip); | |
52 | 43 | if (editor.CurrentLayer == layer) |
53 | 44 | { |
54 | - editor.CurrentChip = previousChip; | |
45 | + editor.CurrentChip = prevChip; | |
55 | 46 | } |
56 | 47 | } |
57 | 48 |
@@ -11,10 +11,10 @@ | ||
11 | 11 | { |
12 | 12 | public static class LayerInstance |
13 | 13 | { |
14 | - private class Data | |
14 | + private class LayerData | |
15 | 15 | { |
16 | 16 | public LayerNotify layer; |
17 | - public LayerSettingNotify layerSetting; | |
17 | + public LayerSettingNotify viewerSetting; | |
18 | 18 | public LayerTabPage layerTabPage; |
19 | 19 | } |
20 | 20 |
@@ -21,7 +21,7 @@ | ||
21 | 21 | private static StageEditorForm stageEditor; |
22 | 22 | private static StageNotify stage; |
23 | 23 | private static EditorNotify editor; |
24 | - private static Dictionary<LayerNotify, Data> layerDataTable; | |
24 | + private static Dictionary<LayerNotify, LayerData> layerDataTable; | |
25 | 25 | |
26 | 26 | public static void Initialize(StageEditorForm stageEditor, EditorNotify editor, StageNotify stage) |
27 | 27 | { |
@@ -28,7 +28,7 @@ | ||
28 | 28 | LayerInstance.stageEditor = stageEditor; |
29 | 29 | LayerInstance.stage = stage; |
30 | 30 | LayerInstance.editor = editor; |
31 | - LayerInstance.layerDataTable = new Dictionary<LayerNotify, Data>(); | |
31 | + LayerInstance.layerDataTable = new Dictionary<LayerNotify, LayerData>(); | |
32 | 32 | } |
33 | 33 | |
34 | 34 | public static void LoadImage(LayerNotify layer, string path) |
@@ -39,23 +39,23 @@ | ||
39 | 39 | public static LayerNotify Add(string name) |
40 | 40 | { |
41 | 41 | var layer = stage.CreateLayer(name); |
42 | - var layerSetting = editor.CreateLayerSetting(); | |
42 | + var viewerSetting = editor.CreateLayerSetting(); | |
43 | 43 | var layerTabPage = stageEditor.LayersetControl.CreateLayer(name); |
44 | - LayerControlEvent.Initialize(layerTabPage, layer, layerSetting); | |
44 | + LayerControlEvent.Initialize(layerTabPage, layer, viewerSetting); | |
45 | 45 | |
46 | 46 | stageEditor.LayersetControl.AddLayer(layerTabPage); |
47 | 47 | stage.AddLayer(layer); |
48 | - editor.AddLayer(layer, layerSetting); | |
48 | + editor.AddLayer(layer, viewerSetting); | |
49 | 49 | |
50 | 50 | layer.PropertyChanged += stageEditor.MapControl.ChipGridData_PropertyChanged; |
51 | 51 | layer.PropertyChanged += stageEditor.LayerChipControl.ChipGridData_PropertyChanged; |
52 | 52 | layer.PropertyChanged += stageEditor.LayerChipsetControl.ChipGridData_PropertyChanged; |
53 | 53 | layer.PropertyChanged += stageEditor.LayersetControl.ChipGridData_PropertyChanged; |
54 | - layerSetting.PropertyChanged += stageEditor.MapControl.ViewSettingData_PropertyChanged; | |
54 | + viewerSetting.PropertyChanged += stageEditor.MapControl.ViewSettingData_PropertyChanged; | |
55 | 55 | |
56 | - var data = new Data(); | |
56 | + var data = new LayerData(); | |
57 | 57 | data.layer = layer; |
58 | - data.layerSetting = layerSetting; | |
58 | + data.viewerSetting = viewerSetting; | |
59 | 59 | data.layerTabPage = layerTabPage; |
60 | 60 | layerDataTable[layer] = data; |
61 | 61 |