Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions mage/Compiling/ScriptExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,12 @@ public async Task<ScriptResult> ExecuteAsync(string tempRomPath, CancellationTok

private static string? ParseOutputRomPath(List<string> lines)
{
for (int i = lines.Count - 1; i >= 0; i--)
for (int i = lines.Count - 1; i >= lines.Count - 40; i--)
{
var trimmed = lines[i].Trim();
if (trimmed.Length == 0) continue;
if (AbsolutePathPattern.IsMatch(trimmed))
return trimmed;
// Stop searching after the first non-empty, non-path line from the bottom.
break;
}
return null;
}
Expand Down
6 changes: 6 additions & 0 deletions mage/Controls/ExtendedPanel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -26,4 +27,9 @@ protected override void OnMouseWheel(MouseEventArgs e)
}
base.OnMouseWheel(e);
}

protected override Point ScrollToControl(Control activeControl)
{
return this.AutoScrollPosition;
}
}
9 changes: 5 additions & 4 deletions mage/Controls/TileTableTooltip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ public class TileTableTooltip : ToolTip
public Image TileGFX { get; set; } = null;
public Point PositionOnImage = new Point(-1, -1);
public ushort TileVal = 0;
public int TileID => TileVal & 0x3FF;
public int TileID => TileVal - Shift & 0x3FF;
public int TilePal => TileVal >> 12;
public bool FlipH => (TileVal & 0x400) != 0;
public bool FlipV => (TileVal & 0x800) != 0;
public int Shift = 0;

public TileTableTooltip()
{
Expand Down Expand Up @@ -67,7 +68,7 @@ private void TileTableTooltip_Draw(object? sender, DrawToolTipEventArgs e)
// Title text
g.DrawString(caption, captionFont, textBrush, drawLocation);
drawLocation.Y += (int)captionSize.Height + margin;

// Tile ID
g.DrawString($"ID:\t {Hex.ToString(TileID)}", regularFont, textBrush, drawLocation);
drawLocation.Y += regularHeight + margin;
Expand All @@ -90,8 +91,8 @@ private void TileTableTooltip_Draw(object? sender, DrawToolTipEventArgs e)
// Draw actual Tile
g.InterpolationMode = InterpolationMode.NearestNeighbor;
g.DrawImage(
TileGFX,
new Rectangle(drawLocation.X + vArrow.Width + 1, drawLocation.Y + hArrow.Height + 1, previewSize, previewSize),
TileGFX,
new Rectangle(drawLocation.X + vArrow.Width + 1, drawLocation.Y + hArrow.Height + 1, previewSize, previewSize),
new Rectangle(PositionOnImage.X, PositionOnImage.Y, 7, 7), GraphicsUnit.Pixel
);
}
Expand Down
56 changes: 54 additions & 2 deletions mage/Dialogs/AreaImageExportDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ public partial class AreaImageExportDialog : Form
private string areaName => Version.AreaNames[area];
private bool requireDoors => checkBox_roomRequireDoors.Checked;
private List<int> excludedRooms => listbox_excludedRooms.SelectedIndices.Cast<int>().ToList();
private bool pixelMode;
PixelImageColors pixelColors;

public AreaImageExportDialog(FormMain main, byte[] roomsPerArea, int area)
public AreaImageExportDialog(FormMain main, byte[] roomsPerArea, int area, bool pixelMode = false)
{
InitializeComponent();

Expand All @@ -39,6 +41,20 @@ public AreaImageExportDialog(FormMain main, byte[] roomsPerArea, int area)
string item = $"{areaName} - {Hex.ToString(i)}";
listbox_excludedRooms.Items.Add(item);
}

Text = pixelMode ? "Export Area Pixel Image" : "Export Area Image";
this.pixelMode = pixelMode;

if (pixelMode)
{
RoomPixelImageExportDialog dialog = new RoomPixelImageExportDialog();
if (dialog.ShowDialog() != DialogResult.OK)
{
DialogResult = DialogResult.Cancel;
Close();
}
pixelColors = dialog.Colors;
}
}

private void button_save_Click(object sender, EventArgs e)
Expand All @@ -49,7 +65,7 @@ private void button_save_Click(object sender, EventArgs e)

filePath = dialog.FileName;

// Export image
// List of all relevant rooms
List<Room> rooms = new List<Room>();
(Point, Point) bounds = new(new Point(16, 16), new Point(0, 0));

Expand All @@ -73,6 +89,13 @@ private void button_save_Click(object sender, EventArgs e)
if (r.header.mapX + r.WidthInScreens > bounds.Item2.X) bounds.Item2.X = r.header.mapX + r.WidthInScreens;
if (r.header.mapY + r.HeightInScreens > bounds.Item2.Y) bounds.Item2.Y = r.header.mapY + r.HeightInScreens;
}

if (!pixelMode) exportAreaImage(rooms, bounds);
else exportPixelImage(rooms, bounds);
}

private void exportAreaImage(List<Room> rooms, (Point, Point) bounds)
{
//Rectangle with maximum area size
Rectangle areaSize = new Rectangle(
bounds.Item1.X * 15 * 16,
Expand Down Expand Up @@ -103,4 +126,33 @@ private void button_save_Click(object sender, EventArgs e)
areaImage.Dispose();
Close();
}

private void exportPixelImage(List<Room> rooms, (Point, Point) bounds)
{

//Rectangle with maximum area size
Rectangle areaSize = new(
bounds.Item1.X * 15,
bounds.Item1.Y * 10,
(bounds.Item2.X - bounds.Item1.X) * 15,
(bounds.Item2.Y - bounds.Item1.Y) * 10
);

//Creating bitmap
using Bitmap areaImage = new Bitmap(areaSize.Width, areaSize.Height);
using Graphics g = Graphics.FromImage(areaImage);

foreach (Room r in rooms)
{
using Bitmap roomImage = new(r.Width - 4, r.Height - 4);
r.backgrounds.clipTypes.DrawCollisionPixel(roomImage, pixelColors, true);

int areaCoordinateX = r.header.mapX * 15 - areaSize.X;
int areaCoordinateY = r.header.mapY * 10 - areaSize.Y;
g.DrawImage(roomImage, areaCoordinateX, areaCoordinateY, roomImage.Width, roomImage.Height);
}

areaImage.Save(filePath);
Close();
}
}
Loading
Loading