public void RefreshObjList() { ObjectList.Items.Clear(); //We want a full refresh, so clear out all previous objects switch (loadedRSDKver) { case 3: Object_Definitions.Retro_SonicObjects RSObj = new Object_Definitions.Retro_SonicObjects(); for (int i = 0; i < objectsV1.Count; i++) { string Obj; string t = RSObj.GetObjectByType(objectsV1[i].type, objectsV1[i].subtype).Name; //Get the object name if (t != null) { Obj = t + ", " + objectsV1[i].xPos + ", " + objectsV1[i].yPos; } //If the object's definition is found, we use it's name in the list else { Obj = "Unnamed Object" + ", " + objectsV1[i].xPos + ", " + objectsV1[i].yPos; } //If not, call it "Unnamed Object" ObjectList.Items.Add(Obj); } break; case 2: Object_Definitions.SonicNexusObjects RSDK2Obj = new Object_Definitions.SonicNexusObjects(); for (int i = 0; i < objectsV2.Count; i++) { string Obj; string t = RSDK2Obj.GetObjectByType(objectsV2[i].type, objectsV2[i].subtype).Name; if (t != null) { Obj = t + ", " + objectsV2[i].xPos + ", " + objectsV2[i].yPos; } else { Obj = "Unnamed Object" + ", " + objectsV2[i].xPos + ", " + objectsV2[i].yPos; } ObjectList.Items.Add(Obj); } break; case 1: Object_Definitions.SonicCDObjects RSDK3Obj = new Object_Definitions.SonicCDObjects(); for (int i = 0; i < objectsV3.Count; i++) { string Obj; string t = RSDK3Obj.GetObjectByType(objectsV3[i].type, objectsV3[i].subtype).Name; if (t != null) { Obj = t + ", " + objectsV3[i].xPos + ", " + objectsV3[i].yPos; } else { Obj = "Unnamed Object" + ", " + objectsV3[i].xPos + ", " + objectsV3[i].yPos; } ObjectList.Items.Add(Obj); } break; case 0: Object_Definitions.Sonic1Objects RSDKBObj = new Object_Definitions.Sonic1Objects(); for (int i = 0; i < objectsV4.Count; i++) { string Obj; string t = RSDKBObj.GetObjectByType(objectsV4[i].type, objectsV4[i].subtype).Name; if (t != null) { Obj = t + ", " + objectsV4[i].xPos + ", " + objectsV4[i].yPos; } else { Obj = "Unnamed Object" + ", " + objectsV4[i].xPos + ", " + objectsV4[i].yPos; } ObjectList.Items.Add(Obj); } break; } }
void pnlMap_Paint(object sender, PaintEventArgs e) { Size gridCellSize = new Size(128, 128); Pen p = new Pen(System.Drawing.Color.Yellow); switch (loadedRSDKver) { case 0: if (_RSDK4Level == null) { return; } e.Graphics.Clear(Color.FromArgb(255, 255, 0, 255)); Rectangle viewport4 = new Rectangle(-pnlMap.AutoScrollPosition.X, -pnlMap.AutoScrollPosition.Y, pnlMap.Width, pnlMap.Height); int startX4 = (viewport4.X / 128) - 1; if (startX4 < 0) { startX4 = 0; } int startY4 = (viewport4.Y / 128) - 1; if (startY4 < 0) { startY4 = 0; } int endX4 = startX4 + (pnlMap.Width / 128) + 1; int endY4 = startY4 + (pnlMap.Height / 128) + 1; for (int y = startY4; y < endY4; y++) { for (int x = startX4; x < endX4; x++) { if (y < _RSDK4Level.MapLayout.Length && x < _RSDK4Level.MapLayout[y].Length && _RSDK4Level.MapLayout[y][x] < _RSDK4Chunks.BlockList.Count) { if (e.ClipRectangle.IntersectsWith(new Rectangle(x * 128, y * 128, 128, 128))) { if (ShowMap) { if (_RSDK4Level.MapLayout[y][x] > 0) { e.Graphics.DrawImageUnscaled(Chunks[_RSDK4Level.MapLayout[y][x]], x * 128, y * 128); } else { } } if (ShowCollision) { } if (ShowObjects) { } } } } } if (ShowObjects) //Heh, It works now :) { for (int o = 0; o < _RSDK4Level.objects.Count; o++) { if (e.ClipRectangle.IntersectsWith(new Rectangle(_RSDK4Level.objects[o].xPos, _RSDK4Level.objects[o].yPos, viewport4.Width, viewport4.Height))) { Object_Definitions.MapObject mapobj = RSObjects.GetObjectByType(_RSDK4Level.objects[o].type, _RSDK4Level.objects[o].subtype); if (mapobj != null && mapobj.ID > 0) { e.Graphics.DrawImageUnscaled(mapobj.RenderObject(loadedRSDKver, datapath), _RSDK4Level.objects[o].xPos, _RSDK4Level.objects[o].yPos); } else { e.Graphics.DrawImage(RetroED.Properties.Resources.OBJ, _RSDK4Level.objects[o].xPos, _RSDK4Level.objects[o].yPos); } } } } if (ShowGrid) { Pen pen = new Pen(Color.DarkGray); if (gridCellSize.Width >= 8 && gridCellSize.Height >= 8) { int lft = 0 % gridCellSize.Width; int top = 0 % gridCellSize.Height; for (int i = 0; i <= _RSDK4Level.width * 128; ++i) { e.Graphics.DrawLine(pen, lft + i * gridCellSize.Width, 0, lft + i * gridCellSize.Width, _RSDK4Level.height * 128); } for (int j = 0; j <= _RSDK4Level.height * 128; ++j) { e.Graphics.DrawLine(pen, 0, top + j * gridCellSize.Height, _RSDK4Level.width * 128, top + j * gridCellSize.Height); } } } e.Graphics.DrawRectangle(p, new Rectangle(tilePoint.X * 128, tilePoint.Y * 128, 128, 128)); break; case 1: if (_RSDK3Level == null) { return; } e.Graphics.Clear(Color.FromArgb(255, 255, 0, 255)); Rectangle viewport3 = new Rectangle(-pnlMap.AutoScrollPosition.X, -pnlMap.AutoScrollPosition.Y, pnlMap.Width, pnlMap.Height); int startX3 = (viewport3.X / 128) - 1; if (startX3 < 0) { startX3 = 0; } int startY3 = (viewport3.Y / 128) - 1; if (startY3 < 0) { startY3 = 0; } int endX3 = startX3 + (pnlMap.Width / 128) + 1; int endY3 = startY3 + (pnlMap.Height / 128) + 1; for (int y = startY3; y < endY3; y++) { for (int x = startX3; x < endX3; x++) { if (y < _RSDK3Level.MapLayout.Length && x < _RSDK3Level.MapLayout[y].Length && _RSDK3Level.MapLayout[y][x] < _RSDK3Chunks.BlockList.Count) { if (e.ClipRectangle.IntersectsWith(new Rectangle(x * 128, y * 128, 128, 128))) { if (ShowMap) { if (_RSDK3Level.MapLayout[y][x] > 0) { e.Graphics.DrawImageUnscaled(Chunks[_RSDK3Level.MapLayout[y][x]], x * 128, y * 128); } else { } } if (ShowCollision) { } } } } } if (ShowObjects) //Heh, It works now :) { for (int o = 0; o < _RSDK3Level.objects.Count; o++) { if (e.ClipRectangle.IntersectsWith(new Rectangle(_RSDK3Level.objects[o].xPos, _RSDK3Level.objects[o].yPos, viewport3.Width, viewport3.Height))) { Object_Definitions.MapObject mapobj = RSObjects.GetObjectByType(_RSDK3Level.objects[o].type, _RSDK3Level.objects[o].subtype); if (mapobj != null && mapobj.ID > 0) { e.Graphics.DrawImageUnscaled(mapobj.RenderObject(loadedRSDKver, datapath), _RSDK3Level.objects[o].xPos, _RSDK3Level.objects[o].yPos); } else { e.Graphics.DrawImage(RetroED.Properties.Resources.OBJ, _RSDK3Level.objects[o].xPos, _RSDK3Level.objects[o].yPos); } } } } if (ShowGrid) { Pen pen = new Pen(Color.DarkGray); if (gridCellSize.Width >= 8 && gridCellSize.Height >= 8) { int lft = 0 % gridCellSize.Width; int top = 0 % gridCellSize.Height; for (int i = 0; i <= _RSDK3Level.width * 128; ++i) { e.Graphics.DrawLine(pen, lft + i * gridCellSize.Width, 0, lft + i * gridCellSize.Width, _RSDK3Level.height * 128); } for (int j = 0; j <= _RSDK3Level.height * 128; ++j) { e.Graphics.DrawLine(pen, 0, top + j * gridCellSize.Height, _RSDK3Level.width * 128, top + j * gridCellSize.Height); } } } e.Graphics.DrawRectangle(p, new Rectangle(tilePoint.X * 128, tilePoint.Y * 128, 128, 128)); break; case 2: if (_RSDK2Level == null) { return; } e.Graphics.Clear(Color.FromArgb(255, 255, 0, 255)); Rectangle viewport2 = new Rectangle(-pnlMap.AutoScrollPosition.X, -pnlMap.AutoScrollPosition.Y, pnlMap.Width, pnlMap.Height); int startX2 = (viewport2.X / 128) - 1; if (startX2 < 0) { startX2 = 0; } int startY2 = (viewport2.Y / 128) - 1; if (startY2 < 0) { startY2 = 0; } int endX2 = startX2 + (pnlMap.Width / 128) + 1; int endY2 = startY2 + (pnlMap.Height / 128) + 1; for (int y = startY2; y < endY2; y++) { for (int x = startX2; x < endX2; x++) { if (y < _RSDK2Level.MapLayout.Length && x < _RSDK2Level.MapLayout[y].Length && _RSDK2Level.MapLayout[y][x] < _RSDK2Chunks.BlockList.Count) { if (e.ClipRectangle.IntersectsWith(new Rectangle(x * 128, y * 128, 128, 128))) { if (ShowMap) { if (_RSDK2Level.MapLayout[y][x] > 0) { e.Graphics.DrawImageUnscaled(Chunks[_RSDK2Level.MapLayout[y][x]], x * 128, y * 128); } else { } } if (ShowCollision) { } } } } } if (ShowObjects) //Heh, It works now :) { for (int o = 0; o < _RSDK2Level.objects.Count; o++) { if (e.ClipRectangle.IntersectsWith(new Rectangle(_RSDK2Level.objects[o].xPos, _RSDK2Level.objects[o].yPos, viewport2.Width, viewport2.Height))) { Object_Definitions.MapObject mapobj = RSObjects.GetObjectByType(_RSDK2Level.objects[o].type, _RSDK2Level.objects[o].subtype); if (mapobj != null && mapobj.ID > 0) { e.Graphics.DrawImageUnscaled(mapobj.RenderObject(loadedRSDKver, datapath), _RSDK2Level.objects[o].xPos, _RSDK2Level.objects[o].yPos); } else { e.Graphics.DrawImage(RetroED.Properties.Resources.OBJ, _RSDK2Level.objects[o].xPos, _RSDK2Level.objects[o].yPos); } //Console.WriteLine(o); } } } if (ShowGrid) { Pen pen = new Pen(Color.DarkGray); if (gridCellSize.Width >= 8 && gridCellSize.Height >= 8) { int lft = 0 % gridCellSize.Width; int top = 0 % gridCellSize.Height; for (int i = 0; i <= _RSDK2Level.width * 128; ++i) { e.Graphics.DrawLine(pen, lft + i * gridCellSize.Width, 0, lft + i * gridCellSize.Width, _RSDK2Level.height * 128); } for (int j = 0; j <= _RSDK2Level.height * 128; ++j) { e.Graphics.DrawLine(pen, 0, top + j * gridCellSize.Height, _RSDK2Level.width * 128, top + j * gridCellSize.Height); } } } e.Graphics.DrawRectangle(p, new Rectangle(tilePoint.X * 128, tilePoint.Y * 128, 128, 128)); break; case 3: if (_RSDK1Level == null) { return; //We're not going to draw a level if we don't have one lol! } if (PanelMap != null) { PanelMap.Dispose(); } //Delet this, We don't need it anymore e.Graphics.Clear(Color.FromArgb(255, 255, 0, 255)); //Fill the "Canvas" with the colour FF00FF //Setup the viewport, this defines where on the map we are (I think) Rectangle viewport1 = new Rectangle(-pnlMap.AutoScrollPosition.X, -pnlMap.AutoScrollPosition.Y, pnlMap.Width, pnlMap.Height); int startX1 = (viewport1.X / 128) - 1; //Where to start drawing (Xpos) if (startX1 < 0) { startX1 = 0; } int startY1 = (viewport1.Y / 128) - 1; //Where to start drawing (Ypos) if (startY1 < 0) { startY1 = 0; } int endX1 = startX1 + (pnlMap.Width / 128) + 1; //Where to Stop drawing (Xpos) int endY1 = startY1 + (pnlMap.Height / 128) + 1; //Where to Stop drawing (Ypos) for (int y = startY1; y < endY1; y++) { for (int x = startX1; x < endX1; x++) { if (y < _RSDK1Level.MapLayout.Length && x < _RSDK1Level.MapLayout[y].Length && _RSDK1Level.MapLayout[y][x] < _RSDK1Chunks.BlockList.Count) { // Draw the map, line by line! //if (e.ClipRectangle.IntersectsWith(new Rectangle(0, 0, viewport1.Width, viewport1.Height))) if (e.ClipRectangle.IntersectsWith(new Rectangle(x * 128, y * 128, 128, 128))) { if (ShowMap) //Check if the user wants to show the map { if (_RSDK1Level.MapLayout[y][x] > 0) //Don't draw Chunk Zero, It's always transparent! { e.Graphics.DrawImageUnscaled(Chunks[_RSDK1Level.MapLayout[y][x]], x * 128, y * 128); //Draw the chunk to the map! } else { } } if (ShowCollision) { //in future this will show the collision masks of the tiles } } } } } if (ShowObjects) //Heh, It works now :) { for (int o = 0; o < _RSDK1Level.objects.Count; o++) { if (e.ClipRectangle.IntersectsWith(new Rectangle(_RSDK1Level.objects[o].xPos, _RSDK1Level.objects[o].yPos, viewport1.Width, viewport1.Height))) { Object_Definitions.MapObject mapobj = RSObjects.GetObjectByType(_RSDK1Level.objects[o].type, _RSDK1Level.objects[o].subtype); if (mapobj != null && mapobj.ID > 0) { e.Graphics.DrawImageUnscaled(mapobj.RenderObject(loadedRSDKver, datapath), _RSDK1Level.objects[o].xPos, _RSDK1Level.objects[o].yPos); } else { e.Graphics.DrawImage(RetroED.Properties.Resources.OBJ, _RSDK1Level.objects[o].xPos, _RSDK1Level.objects[o].yPos); } //Console.WriteLine(o); } } } if (ShowGrid) //If we want a grid, then draw it over the map { Pen pen = new Pen(Color.DarkGray); if (gridCellSize.Width >= 8 && gridCellSize.Height >= 8) { int lft = 0 % gridCellSize.Width; int top = 0 % gridCellSize.Height; for (int i = 0; i <= _RSDK1Level.width * 128; ++i) { e.Graphics.DrawLine(pen, lft + i * gridCellSize.Width, 0, lft + i * gridCellSize.Width, _RSDK1Level.height * 128); } for (int j = 0; j <= _RSDK1Level.height * 128; ++j) { e.Graphics.DrawLine(pen, 0, top + j * gridCellSize.Height, _RSDK1Level.width * 128, top + j * gridCellSize.Height); } } } Pen PSpen = new Pen(Color.White); //We want the player spawn circle to be white! e.Graphics.DrawRectangle(p, new Rectangle(tilePoint.X * 128, tilePoint.Y * 128, 128, 128)); //Draw the selected tile! e.Graphics.DrawEllipse(PSpen, _RSDK1Level.PlayerXpos, _RSDK1Level.PlayerYPos, 32, 32); //Draw Spawn Circle break; default: break; } }