@@ -588,6 +588,7 @@ private void bunifuThinButton23_Click_2(object sender, EventArgs e)
588
588
MessageBox . Show ( "You must load map before you export quadtree" , "Error" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
589
589
return ;
590
590
}
591
+ saveQuadtree . FileName = Path . GetFileName ( openImage . FileName ) ;
591
592
if ( saveQuadtree . ShowDialog ( ) == DialogResult . OK )
592
593
{
593
594
string path = Path . GetDirectoryName ( saveQuadtree . FileName ) ;
@@ -599,79 +600,95 @@ private void bunifuThinButton23_Click_2(object sender, EventArgs e)
599
600
SaveAll ( path , name ) ;
600
601
break ;
601
602
case 1 :
602
- SaveStatic ( path , name , false ) ;
603
+ SaveStatic ( path , name , true ) ;
603
604
break ;
604
605
case 2 :
605
- SaveDynamic ( path , name , false ) ;
606
+ SaveDynamic ( path , name , true ) ;
606
607
break ;
607
608
default :
608
609
SaveAll ( path , name ) ;
609
610
break ;
610
611
}
612
+
611
613
}
612
614
}
613
615
614
- private void SaveDynamic ( string path , string name , bool twoFiles )
616
+ private void SaveDynamic ( string path , string name , bool saveObject )
615
617
{
616
- QuadNode root = AutoBuild ( ( int ) Type . Dynamic ) ;
617
- string file ;
618
- if ( twoFiles )
619
- file = Path . Combine ( path , name + "_dynamic .txt" ) ;
620
- else file = Path . Combine ( path , name + ".txt" ) ;
618
+
619
+ QuadNode root = AutoBuild ( ( int ) Type . Dynamic , out List < CObject > objs ) ;
620
+ string file = Path . Combine ( path , name + "_dynamic.txt" ) ;
621
+ string fileObject = Path . Combine ( path , name + ".txt" ) ;
622
+ if ( saveObject ) SaveObject ( objs , fileObject ) ;
621
623
622
- Save ( root , file ) ;
624
+ SaveQuadTree ( root , file ) ;
623
625
}
624
626
625
- private void SaveStatic ( string path , string name , bool twoFiles )
627
+ private void SaveStatic ( string path , string name , bool saveObject )
626
628
{
627
- QuadNode root = AutoBuild ( ( int ) Type . Static ) ;
628
- string file ;
629
- if ( twoFiles )
630
- file = Path . Combine ( path , name + "_static.txt" ) ;
631
- else file = Path . Combine ( path , name + ".txt" ) ;
632
-
633
- Save ( root , file ) ;
629
+ QuadNode root = AutoBuild ( ( int ) Type . Static , out List < CObject > objs ) ;
630
+ string file = Path . Combine ( path , name + "_static.txt" ) ;
631
+ string fileObject = Path . Combine ( path , name + ".txt" ) ;
632
+ if ( saveObject ) SaveObject ( objs , fileObject ) ;
633
+ SaveQuadTree ( root , file ) ;
634
634
}
635
635
636
636
private void SaveAll ( string path , string name )
637
637
{
638
- if ( ! checkBoxOnly . Checked )
638
+
639
+ string fileObject = Path . Combine ( path , name + ".txt" ) ;
640
+ if ( ! checkBoxOnly . Checked )
639
641
{
640
- SaveDynamic ( path , name , true ) ;
641
- SaveStatic ( path , name , true ) ;
642
+ SaveObject ( objects . Values . ToList ( ) , fileObject ) ;
643
+ SaveDynamic ( path , name , false ) ;
644
+ SaveStatic ( path , name , false ) ;
642
645
return ;
643
646
}
644
647
645
- QuadNode root = AutoBuild ( ( int ) Type . All ) ;
646
- string file = Path . Combine ( path , name + ".txt" ) ;
647
-
648
- Save ( root , file ) ;
648
+ QuadNode root = AutoBuild ( ( int ) Type . All , out List < CObject > objs ) ;
649
+ string file = Path . Combine ( path , name + "_all .txt" ) ;
650
+ SaveObject ( objs , fileObject ) ;
651
+ SaveQuadTree ( root , file ) ;
649
652
}
650
653
651
- private QuadNode AutoBuild ( int type )
654
+ private QuadNode AutoBuild ( int type , out List < CObject > objs )
652
655
{
653
656
QuadNode root = new QuadNode ( 0 , 0 , new Rectangle ( 0 , 0 , image . Width , image . Height ) ) ;
657
+ objs = new List < CObject > ( ) ;
654
658
if ( type != ( int ) Type . All )
655
659
{
656
660
foreach ( var item in objects )
657
- {
658
661
if ( item . Value . type == type )
662
+ {
659
663
root . Build ( item . Value ) ;
660
- }
664
+ objs . Add ( item . Value ) ;
665
+ }
661
666
} else
662
667
foreach ( var item in objects )
663
668
{
664
669
root . Build ( item . Value ) ;
670
+ objs . Add ( item . Value ) ;
665
671
}
666
672
return root ;
667
673
}
668
674
669
- private void Save ( QuadNode root , string path )
675
+ private void SaveQuadTree ( QuadNode root , string path )
670
676
{
671
677
StreamWriter stream = new StreamWriter ( path ) ;
672
678
root . Save ( stream ) ;
673
679
stream . Close ( ) ;
674
680
}
681
+ private void SaveObject ( List < CObject > objs , string path )
682
+ {
683
+ StreamWriter stream = new StreamWriter ( path ) ;
684
+ foreach ( var item in objs )
685
+ {
686
+ stream . Write ( item . ID + " " + item . idName + " " + item . type + " " + item . region . X + " " + item . region . Y + " " + item . region . Right + " " + item . region . Bottom ) ;
687
+ stream . WriteLine ( ) ;
688
+ stream . Flush ( ) ;
689
+ }
690
+ stream . Close ( ) ;
691
+ }
675
692
676
693
private void cbbExport_SelectedIndexChanged ( object sender , EventArgs e )
677
694
{
0 commit comments