Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ public bool InitializeSprite()
Image = "/Svg/Seal.svg",
Name = "PutChars"
});
ExportTypesList.Add(new ExportTypeDescrioptionItem()
{
Description = "Conrado Badenas MaskedSprites library.",
ExportType = ExportTypes.MaskedSprites,
Image = "/Svg/Mask.svg",
Name = "MaskedSprites"
});
/*
ExportTypesList.Add(new ExportTypeDescrioptionItem()
{
Expand All @@ -73,7 +80,6 @@ public bool InitializeSprite()
});
*/
lstOptions.ItemsSource = ExportTypesList;

lstOptions.SelectionChanged += LstOptions_SelectionChanged;

return true;
Expand Down
2 changes: 2 additions & 0 deletions ZXBStudio/DocumentEditors/ZXGraphics/SpriteEditor.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ private void _Initialize(string fileName)
btnInk.Tapped += BtnInk_Tapped;
UpdateColorPanel();

InitializeShortcuts();

this.AddHandler(KeyDownEvent, Keyboard_Down, handledEventsToo: true);
this.Focus();
grdProcesando.IsVisible = false;
Expand Down
153 changes: 152 additions & 1 deletion ZXBStudio/DocumentEditors/ZXGraphics/SpriteExportDialog.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Platform.Storage;
using MsBox.Avalonia;
using System;
using System.Collections;
using System.Collections.Generic;
Expand Down Expand Up @@ -119,6 +120,13 @@ private void Refresh()
CreateExample_PutChars();
}
break;
case ExportTypes.MaskedSprites:
CreateExportPath(".bas");
if (canExport)
{
CreateExample_MaskedSprites();
}
break;
default:
grdOptions.IsVisible = false;
break;
Expand Down Expand Up @@ -264,6 +272,149 @@ private void CreateExample_PutChars()
txtCode.Text = sb.ToString();
}


private void CreateExample_MaskedSprites()
{
if (sprites == null || sprites.Count() == 0)
{
txtCode.Text = "";
}

var sprite = sprites.ElementAt(0);
var exportData = ExportManager.Export_Sprite_MaskedSprites(exportConfig, sprites);
if (exportData.StartsWith("ERROR:"))
{
txtError.Text = exportData;
txtError.IsVisible = true;
return;
}
txtError.IsVisible = false;

var sb = new StringBuilder();
switch (exportConfig.ExportDataType)
{
case ExportDataTypes.DIM:
{
sb.AppendLine("'- Includes -----------------------------------------------");
sb.AppendLine("#INCLUDE <retrace.bas>");
sb.AppendLine("#INCLUDE \"maskedsprites.bas\"");
sb.AppendLine("");
sb.AppendLine("'- Sprites definition -------------------------------------");
sb.AppendLine(string.Format("' Can use: #INCLUDE \"{0}\"",
Path.GetFileName(exportConfig.ExportFilePath)));
sb.AppendLine(exportData);
sb.AppendLine("' - Init vars ---------------------------------------------");
sb.AppendLine("#define NumberofMaskedSprites 1");
sb.AppendLine("DIM sprDir, sprBackDir AS UInteger");
sb.AppendLine("");
sb.AppendLine("'- Initialise the sprite engine ---------------------------");
sb.AppendLine("InitMaskedSpritesFileSystem()");
sb.AppendLine("' Create sprite");
sb.AppendLine($"sprDir = RegisterSpriteImageInMSFS(@{exportConfig.LabelName}{sprite.Name.Replace(" ", "_")}(0))");
sb.AppendLine("' Save background for first time");
sb.AppendLine("sprBackDir = MaskedSpritesBackground(0)");
sb.AppendLine("");
sb.AppendLine("'- Draw sprite --------------------------------------------");
sb.AppendLine("DIM n AS UByte");
sb.AppendLine("DO");
sb.AppendLine(" ' Sync with raytrace");
sb.AppendLine(" waitretrace");
sb.AppendLine(" ' Restore background");
sb.AppendLine(" RestoreBackground(100,52,sprBackDir)");
sb.AppendLine(" ");
sb.AppendLine(" ' Print a number");
sb.AppendLine(" PRINT AT 7,12;n;");
sb.AppendLine(" n = n + 1");
sb.AppendLine(" ' Draw sprite");
sb.AppendLine(" SaveBackgroundAndDrawSpriteRegisteredInMSFS(100,52,sprBackDir,sprDir) ");
sb.AppendLine("LOOP");
sb.AppendLine("");
}
break;

case ExportDataTypes.ASM:
{
sb.AppendLine("'- Includes -----------------------------------------------");
sb.AppendLine("#INCLUDE <retrace.bas>");
sb.AppendLine("#INCLUDE \"maskedsprites.bas\"");
sb.AppendLine("");
sb.AppendLine("' - Init vars ---------------------------------------------");
sb.AppendLine("#define NumberofMaskedSprites 1");
sb.AppendLine("DIM sprDir, sprBackDir AS UInteger");
sb.AppendLine("");
sb.AppendLine("'- Initialise the sprite engine ---------------------------");
sb.AppendLine("InitMaskedSpritesFileSystem()");
sb.AppendLine("' Create sprite");
sb.AppendLine($"sprDir = RegisterSpriteImageInMSFS(@{exportConfig.LabelName}_{sprite.Name.Replace(" ", "_")})");
sb.AppendLine("' Save background for first time");
sb.AppendLine("sprBackDir = MaskedSpritesBackground(0)");
sb.AppendLine("");
sb.AppendLine("'- Draw sprite --------------------------------------------");
sb.AppendLine("DIM n AS UByte");
sb.AppendLine("DO");
sb.AppendLine(" ' Sync with raytrace");
sb.AppendLine(" waitretrace");
sb.AppendLine(" ' Restore background");
sb.AppendLine(" RestoreBackground(100,52,sprBackDir)");
sb.AppendLine(" ");
sb.AppendLine(" ' Print a number");
sb.AppendLine(" PRINT AT 7,12;n;");
sb.AppendLine(" n = n + 1");
sb.AppendLine(" ' Draw sprite");
sb.AppendLine(" SaveBackgroundAndDrawSpriteRegisteredInMSFS(100,52,sprBackDir,sprDir) ");
sb.AppendLine("LOOP");
sb.AppendLine("");
sb.AppendLine("' - This section must not be executed --------------------");
sb.AppendLine(string.Format("' Can use: #INCLUDE \"{0}\"",
Path.GetFileName(exportConfig.ExportFilePath)));
sb.AppendLine(exportData);
}
break;

case ExportDataTypes.BIN:
{
sb.AppendLine("'- Includes -----------------------------------------------");
sb.AppendLine("#INCLUDE <putchars.bas>");
sb.AppendLine("");
sb.AppendLine("'- Draw sprite --------------------------------------------");
sb.AppendLine(string.Format(
"putChars(10,5,{0},{1},@{2})",
sprite.Width / 8,
sprite.Height / 8,
exportConfig.LabelName));
sb.AppendLine("");
sb.AppendLine("' This section must not be executed");
sb.AppendLine(string.Format(
"{0}:",
exportConfig.LabelName));
sb.AppendLine("ASM");
sb.AppendLine(string.Format("\tINCBIN \"{0}\"",
Path.GetFileName(exportConfig.ExportFilePath)));
sb.AppendLine("END ASM");
}
break;

case ExportDataTypes.TAP:
{
sb.AppendLine("'- Includes -----------------------------------------------");
sb.AppendLine("#INCLUDE <putchars.bas>");
sb.AppendLine("");
sb.AppendLine("' Load .tap data ------------------------------------------");
sb.AppendLine("LOAD \"\" CODE");
sb.AppendLine("");
sb.AppendLine("'- Draw sprite --------------------------------------------");
sb.AppendLine(string.Format(
"putChars(10,5,{0},{1},@{2})",
sprite.Width / 8,
sprite.Height / 8,
exportConfig.LabelName));
sb.AppendLine("");
}
break;
}

txtCode.Text = sb.ToString();
}
#endregion


Expand All @@ -287,7 +438,7 @@ private void BtnSave_Tapped(object? sender, Avalonia.Input.TappedEventArgs e)
GetConfigFromUI();
ServiceLayer.Export_SetConfigFile(fileName + ".zbs", exportConfig);
Export();
this.Close();
//this.Close();
}

private async void BtnOutputFile_Tapped(object? sender, Avalonia.Input.TappedEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,10 @@ private void SetAttribute(Pattern pattern, int x, int y)

private AttributeColor GetAttribute(Pattern pattern, int x, int y)
{
if(pattern.Attributes == null)
{
pattern.Attributes = new AttributeColor[(SpriteData.Width / 8) * (SpriteData.Height / 8)];
}
int cW = SpriteData.Width / 8;
int cX = x / 8;
int cY = y / 8;
Expand Down Expand Up @@ -1163,6 +1167,10 @@ private void GrdEditor_InvertColorsCell(double mx, double my)
var inkBak = PrimaryColorIndex;
var paperBak = SecondaryColorIndex;
var attr=GetAttribute(SpriteData.Patterns[SpriteData.CurrentFrame], x, y);
if (attr == null)
{
return;
}
PrimaryColorIndex = attr.Paper;
SecondaryColorIndex = attr.Ink;
SetAttribute(SpriteData.Patterns[SpriteData.CurrentFrame], x, y);
Expand Down
Loading
Loading