Skip to content

Commit 6993b90

Browse files
authored
v1.8.0-beta4
- Sprite Editor; - Bug fixed: Keyboard shortcuts now work in the sprite editor - Export to MaskedSprites: - Added a warning when sprites do not meet the requirements for export to MaskedSprites: - 16x16 - Sprites with a mask - Even frames - The ‘Save’ button no longer closes the export window
2 parents 6bccc76 + 4ea3227 commit 6993b90

11 files changed

Lines changed: 505 additions & 8 deletions

File tree

ZXBStudio/DocumentEditors/ZXGraphics/SelectExportTypeControl.axaml.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ public bool InitializeSprite()
5656
Image = "/Svg/Seal.svg",
5757
Name = "PutChars"
5858
});
59+
ExportTypesList.Add(new ExportTypeDescrioptionItem()
60+
{
61+
Description = "Conrado Badenas MaskedSprites library.",
62+
ExportType = ExportTypes.MaskedSprites,
63+
Image = "/Svg/Mask.svg",
64+
Name = "MaskedSprites"
65+
});
5966
/*
6067
ExportTypesList.Add(new ExportTypeDescrioptionItem()
6168
{
@@ -73,7 +80,6 @@ public bool InitializeSprite()
7380
});
7481
*/
7582
lstOptions.ItemsSource = ExportTypesList;
76-
7783
lstOptions.SelectionChanged += LstOptions_SelectionChanged;
7884

7985
return true;

ZXBStudio/DocumentEditors/ZXGraphics/SpriteEditor.axaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ private void _Initialize(string fileName)
342342
btnInk.Tapped += BtnInk_Tapped;
343343
UpdateColorPanel();
344344

345+
InitializeShortcuts();
346+
345347
this.AddHandler(KeyDownEvent, Keyboard_Down, handledEventsToo: true);
346348
this.Focus();
347349
grdProcesando.IsVisible = false;

ZXBStudio/DocumentEditors/ZXGraphics/SpriteExportDialog.axaml.cs

Lines changed: 152 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Avalonia;
22
using Avalonia.Controls;
33
using Avalonia.Platform.Storage;
4+
using MsBox.Avalonia;
45
using System;
56
using System.Collections;
67
using System.Collections.Generic;
@@ -119,6 +120,13 @@ private void Refresh()
119120
CreateExample_PutChars();
120121
}
121122
break;
123+
case ExportTypes.MaskedSprites:
124+
CreateExportPath(".bas");
125+
if (canExport)
126+
{
127+
CreateExample_MaskedSprites();
128+
}
129+
break;
122130
default:
123131
grdOptions.IsVisible = false;
124132
break;
@@ -264,6 +272,149 @@ private void CreateExample_PutChars()
264272
txtCode.Text = sb.ToString();
265273
}
266274

275+
276+
private void CreateExample_MaskedSprites()
277+
{
278+
if (sprites == null || sprites.Count() == 0)
279+
{
280+
txtCode.Text = "";
281+
}
282+
283+
var sprite = sprites.ElementAt(0);
284+
var exportData = ExportManager.Export_Sprite_MaskedSprites(exportConfig, sprites);
285+
if (exportData.StartsWith("ERROR:"))
286+
{
287+
txtError.Text = exportData;
288+
txtError.IsVisible = true;
289+
return;
290+
}
291+
txtError.IsVisible = false;
292+
293+
var sb = new StringBuilder();
294+
switch (exportConfig.ExportDataType)
295+
{
296+
case ExportDataTypes.DIM:
297+
{
298+
sb.AppendLine("'- Includes -----------------------------------------------");
299+
sb.AppendLine("#INCLUDE <retrace.bas>");
300+
sb.AppendLine("#INCLUDE \"maskedsprites.bas\"");
301+
sb.AppendLine("");
302+
sb.AppendLine("'- Sprites definition -------------------------------------");
303+
sb.AppendLine(string.Format("' Can use: #INCLUDE \"{0}\"",
304+
Path.GetFileName(exportConfig.ExportFilePath)));
305+
sb.AppendLine(exportData);
306+
sb.AppendLine("' - Init vars ---------------------------------------------");
307+
sb.AppendLine("#define NumberofMaskedSprites 1");
308+
sb.AppendLine("DIM sprDir, sprBackDir AS UInteger");
309+
sb.AppendLine("");
310+
sb.AppendLine("'- Initialise the sprite engine ---------------------------");
311+
sb.AppendLine("InitMaskedSpritesFileSystem()");
312+
sb.AppendLine("' Create sprite");
313+
sb.AppendLine($"sprDir = RegisterSpriteImageInMSFS(@{exportConfig.LabelName}{sprite.Name.Replace(" ", "_")}(0))");
314+
sb.AppendLine("' Save background for first time");
315+
sb.AppendLine("sprBackDir = MaskedSpritesBackground(0)");
316+
sb.AppendLine("");
317+
sb.AppendLine("'- Draw sprite --------------------------------------------");
318+
sb.AppendLine("DIM n AS UByte");
319+
sb.AppendLine("DO");
320+
sb.AppendLine(" ' Sync with raytrace");
321+
sb.AppendLine(" waitretrace");
322+
sb.AppendLine(" ' Restore background");
323+
sb.AppendLine(" RestoreBackground(100,52,sprBackDir)");
324+
sb.AppendLine(" ");
325+
sb.AppendLine(" ' Print a number");
326+
sb.AppendLine(" PRINT AT 7,12;n;");
327+
sb.AppendLine(" n = n + 1");
328+
sb.AppendLine(" ' Draw sprite");
329+
sb.AppendLine(" SaveBackgroundAndDrawSpriteRegisteredInMSFS(100,52,sprBackDir,sprDir) ");
330+
sb.AppendLine("LOOP");
331+
sb.AppendLine("");
332+
}
333+
break;
334+
335+
case ExportDataTypes.ASM:
336+
{
337+
sb.AppendLine("'- Includes -----------------------------------------------");
338+
sb.AppendLine("#INCLUDE <retrace.bas>");
339+
sb.AppendLine("#INCLUDE \"maskedsprites.bas\"");
340+
sb.AppendLine("");
341+
sb.AppendLine("' - Init vars ---------------------------------------------");
342+
sb.AppendLine("#define NumberofMaskedSprites 1");
343+
sb.AppendLine("DIM sprDir, sprBackDir AS UInteger");
344+
sb.AppendLine("");
345+
sb.AppendLine("'- Initialise the sprite engine ---------------------------");
346+
sb.AppendLine("InitMaskedSpritesFileSystem()");
347+
sb.AppendLine("' Create sprite");
348+
sb.AppendLine($"sprDir = RegisterSpriteImageInMSFS(@{exportConfig.LabelName}_{sprite.Name.Replace(" ", "_")})");
349+
sb.AppendLine("' Save background for first time");
350+
sb.AppendLine("sprBackDir = MaskedSpritesBackground(0)");
351+
sb.AppendLine("");
352+
sb.AppendLine("'- Draw sprite --------------------------------------------");
353+
sb.AppendLine("DIM n AS UByte");
354+
sb.AppendLine("DO");
355+
sb.AppendLine(" ' Sync with raytrace");
356+
sb.AppendLine(" waitretrace");
357+
sb.AppendLine(" ' Restore background");
358+
sb.AppendLine(" RestoreBackground(100,52,sprBackDir)");
359+
sb.AppendLine(" ");
360+
sb.AppendLine(" ' Print a number");
361+
sb.AppendLine(" PRINT AT 7,12;n;");
362+
sb.AppendLine(" n = n + 1");
363+
sb.AppendLine(" ' Draw sprite");
364+
sb.AppendLine(" SaveBackgroundAndDrawSpriteRegisteredInMSFS(100,52,sprBackDir,sprDir) ");
365+
sb.AppendLine("LOOP");
366+
sb.AppendLine("");
367+
sb.AppendLine("' - This section must not be executed --------------------");
368+
sb.AppendLine(string.Format("' Can use: #INCLUDE \"{0}\"",
369+
Path.GetFileName(exportConfig.ExportFilePath)));
370+
sb.AppendLine(exportData);
371+
}
372+
break;
373+
374+
case ExportDataTypes.BIN:
375+
{
376+
sb.AppendLine("'- Includes -----------------------------------------------");
377+
sb.AppendLine("#INCLUDE <putchars.bas>");
378+
sb.AppendLine("");
379+
sb.AppendLine("'- Draw sprite --------------------------------------------");
380+
sb.AppendLine(string.Format(
381+
"putChars(10,5,{0},{1},@{2})",
382+
sprite.Width / 8,
383+
sprite.Height / 8,
384+
exportConfig.LabelName));
385+
sb.AppendLine("");
386+
sb.AppendLine("' This section must not be executed");
387+
sb.AppendLine(string.Format(
388+
"{0}:",
389+
exportConfig.LabelName));
390+
sb.AppendLine("ASM");
391+
sb.AppendLine(string.Format("\tINCBIN \"{0}\"",
392+
Path.GetFileName(exportConfig.ExportFilePath)));
393+
sb.AppendLine("END ASM");
394+
}
395+
break;
396+
397+
case ExportDataTypes.TAP:
398+
{
399+
sb.AppendLine("'- Includes -----------------------------------------------");
400+
sb.AppendLine("#INCLUDE <putchars.bas>");
401+
sb.AppendLine("");
402+
sb.AppendLine("' Load .tap data ------------------------------------------");
403+
sb.AppendLine("LOAD \"\" CODE");
404+
sb.AppendLine("");
405+
sb.AppendLine("'- Draw sprite --------------------------------------------");
406+
sb.AppendLine(string.Format(
407+
"putChars(10,5,{0},{1},@{2})",
408+
sprite.Width / 8,
409+
sprite.Height / 8,
410+
exportConfig.LabelName));
411+
sb.AppendLine("");
412+
}
413+
break;
414+
}
415+
416+
txtCode.Text = sb.ToString();
417+
}
267418
#endregion
268419

269420

@@ -287,7 +438,7 @@ private void BtnSave_Tapped(object? sender, Avalonia.Input.TappedEventArgs e)
287438
GetConfigFromUI();
288439
ServiceLayer.Export_SetConfigFile(fileName + ".zbs", exportConfig);
289440
Export();
290-
this.Close();
441+
//this.Close();
291442
}
292443

293444
private async void BtnOutputFile_Tapped(object? sender, Avalonia.Input.TappedEventArgs e)

ZXBStudio/DocumentEditors/ZXGraphics/SpritePatternEditor.axaml.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,10 @@ private void SetAttribute(Pattern pattern, int x, int y)
475475

476476
private AttributeColor GetAttribute(Pattern pattern, int x, int y)
477477
{
478+
if(pattern.Attributes == null)
479+
{
480+
pattern.Attributes = new AttributeColor[(SpriteData.Width / 8) * (SpriteData.Height / 8)];
481+
}
478482
int cW = SpriteData.Width / 8;
479483
int cX = x / 8;
480484
int cY = y / 8;
@@ -1163,6 +1167,10 @@ private void GrdEditor_InvertColorsCell(double mx, double my)
11631167
var inkBak = PrimaryColorIndex;
11641168
var paperBak = SecondaryColorIndex;
11651169
var attr=GetAttribute(SpriteData.Patterns[SpriteData.CurrentFrame], x, y);
1170+
if (attr == null)
1171+
{
1172+
return;
1173+
}
11661174
PrimaryColorIndex = attr.Paper;
11671175
SecondaryColorIndex = attr.Ink;
11681176
SetAttribute(SpriteData.Patterns[SpriteData.CurrentFrame], x, y);

0 commit comments

Comments
 (0)