Skip to content

Commit 575c178

Browse files
committed
Fix bugs
1 parent df169ea commit 575c178

10 files changed

+48
-31
lines changed

MapEditor/CObject.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ class CObject
1212
public Rectangle region;
1313
public Color color;
1414
public int type;
15-
public int name;
15+
public int idName;
1616

1717
public int ID { get => id; }
1818

19-
public CObject(int id, Rectangle region, Color color, int name, int type)
19+
public CObject(int id, Rectangle region, Color color, int idName, int type)
2020
{
2121
this.id = id;
2222
this.region = region;
2323
this.color = color;
24-
this.name = name;
24+
this.idName = idName;
2525
this.type = type;
2626
}
2727
}

MapEditor/MapEditorForm.cs

+45-28
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ private void bunifuThinButton23_Click_2(object sender, EventArgs e)
588588
MessageBox.Show("You must load map before you export quadtree", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
589589
return;
590590
}
591+
saveQuadtree.FileName = Path.GetFileName(openImage.FileName);
591592
if (saveQuadtree.ShowDialog() == DialogResult.OK)
592593
{
593594
string path = Path.GetDirectoryName(saveQuadtree.FileName);
@@ -599,79 +600,95 @@ private void bunifuThinButton23_Click_2(object sender, EventArgs e)
599600
SaveAll(path, name);
600601
break;
601602
case 1:
602-
SaveStatic(path, name, false);
603+
SaveStatic(path, name, true);
603604
break;
604605
case 2:
605-
SaveDynamic(path, name, false);
606+
SaveDynamic(path, name, true);
606607
break;
607608
default:
608609
SaveAll(path, name);
609610
break;
610611
}
612+
611613
}
612614
}
613615

614-
private void SaveDynamic(string path, string name, bool twoFiles)
616+
private void SaveDynamic(string path, string name, bool saveObject)
615617
{
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);
621623

622-
Save(root, file);
624+
SaveQuadTree(root, file);
623625
}
624626

625-
private void SaveStatic(string path, string name, bool twoFiles)
627+
private void SaveStatic(string path, string name, bool saveObject)
626628
{
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);
634634
}
635635

636636
private void SaveAll(string path, string name)
637637
{
638-
if(!checkBoxOnly.Checked)
638+
639+
string fileObject = Path.Combine(path, name + ".txt");
640+
if (!checkBoxOnly.Checked)
639641
{
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);
642645
return;
643646
}
644647

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);
649652
}
650653

651-
private QuadNode AutoBuild(int type)
654+
private QuadNode AutoBuild(int type, out List<CObject> objs)
652655
{
653656
QuadNode root = new QuadNode(0, 0, new Rectangle(0, 0, image.Width, image.Height));
657+
objs = new List<CObject>();
654658
if (type != (int)Type.All)
655659
{
656660
foreach (var item in objects)
657-
{
658661
if (item.Value.type == type)
662+
{
659663
root.Build(item.Value);
660-
}
664+
objs.Add(item.Value);
665+
}
661666
}else
662667
foreach (var item in objects)
663668
{
664669
root.Build(item.Value);
670+
objs.Add(item.Value);
665671
}
666672
return root;
667673
}
668674

669-
private void Save(QuadNode root,string path)
675+
private void SaveQuadTree(QuadNode root,string path)
670676
{
671677
StreamWriter stream = new StreamWriter(path);
672678
root.Save(stream);
673679
stream.Close();
674680
}
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+
}
675692

676693
private void cbbExport_SelectedIndexChanged(object sender, EventArgs e)
677694
{
143 KB
Loading
186 KB
Loading

MapEditor/Resources/Image/Object.JPG

152 KB
Loading
87.1 KB
Loading

MapEditor/Resources/Image/Tile.JPG

30.3 KB
Loading

MapEditor/Resources/Image/TileTxt.JPG

53 KB
Loading

MapEditor/Resources/Image/leve2.png

134 KB
Loading

MapEditor/Resources/Image/level.png

277 KB
Loading

0 commit comments

Comments
 (0)