Skip to content

Commit 0cf3fa6

Browse files
committed
Sprite editor:
- Added PutChars ASM export data type - Solved several bugs in the sprite editor
1 parent 7fbf5bb commit 0cf3fa6

8 files changed

Lines changed: 387 additions & 61 deletions

File tree

ZXBStudio/DocumentEditors/ZXGraphics/SpriteEditor.axaml.cs

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,8 @@ private void SpriteList_Command(SpritePatternControl sender, string command)
464464
ctrlPreview.Refresh();
465465
ctrlProperties.SpriteData = sender.SpriteData;
466466
ctrlProperties.Refresh();
467+
SpriteProperties_FrameUpdate(ctrlProperties, command);
468+
txtFrame.Text = "0";
467469
break;
468470
}
469471
}
@@ -498,21 +500,7 @@ private void SpriteProperties_Command(SpritePropertiesControl sender, string com
498500
SpriteList_Modified(sender.SpriteData);
499501
break;
500502
case "FRAMEUPDATE":
501-
{
502-
int f = sender.SpriteData.Frames - 1;
503-
if (f < 0)
504-
{
505-
f = 0;
506-
}
507-
else if (f > 255)
508-
{
509-
f = 255;
510-
}
511-
txtFrame.Maximum = f;
512-
txtFrame.Text = f.ToString();
513-
txtFrame.UpdateLayout();
514-
SpriteProperties_Command(sender, "REFRESH");
515-
}
503+
SpriteProperties_FrameUpdate(sender, command);
516504
break;
517505
case "REFRESH":
518506
ctrlEditor.SpriteData = sender.SpriteData;
@@ -549,6 +537,29 @@ private void SpriteProperties_Command(SpritePropertiesControl sender, string com
549537
}
550538

551539

540+
private void SpriteProperties_FrameUpdate(SpritePropertiesControl sender, string command)
541+
{
542+
if (sender.SpriteData == null)
543+
{
544+
return;
545+
}
546+
547+
int f = sender.SpriteData.Frames - 1;
548+
if (f < 0)
549+
{
550+
f = 0;
551+
}
552+
else if (f > 255)
553+
{
554+
f = 255;
555+
}
556+
txtFrame.Maximum = f;
557+
txtFrame.Text = f.ToString();
558+
txtFrame.UpdateLayout();
559+
SpriteProperties_Command(sender, "REFRESH");
560+
}
561+
562+
552563
private void SpriteList_AddSprite()
553564
{
554565
SpritePatternControl selectedSprite = null;

ZXBStudio/DocumentEditors/ZXGraphics/SpriteExportDialog.axaml

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,31 @@
2525
<Grid ColumnDefinitions="180,*,Auto" RowDefinitions="Auto, Auto,Auto,Auto,Auto,Auto,Auto,Auto">
2626
<TextBlock Name="lblBuild" Classes="dialog" VerticalAlignment="Center" HorizontalAlignment="Right">Enable build:</TextBlock>
2727
<CheckBox Classes="dialog" Name="chkAuto" Grid.Column="1"></CheckBox>
28-
29-
<TextBlock Name="lblOutputFile" Grid.Row="1" Classes="dialog" VerticalAlignment="Center" HorizontalAlignment="Right">File path:</TextBlock>
30-
<TextBox Name="txtOutputFile" Grid.Row="1" Classes="dialog" Grid.Column="1" MaxWidth="Infinity"></TextBox>
31-
<Button Name="btnOutputFile" Grid.Row="1" Classes="dialog" Grid.Column="2" VerticalAlignment="Center">...</Button>
3228

33-
<TextBlock Name="lblLabelName" Classes="dialog" Grid.Row="2" VerticalAlignment="Center" HorizontalAlignment="Right">Var prefix:</TextBlock>
34-
<TextBox Name="txtLabelName" Classes="dialog" Grid.Row="2" Grid.Column="1" MaxLength="64" Width="100" HorizontalAlignment="Left"></TextBox>
29+
<TextBlock Name="lblDataType" Classes="dialog" Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Right">Data type:</TextBlock>
30+
<ComboBox Name="cmbDataType" Classes="dialog" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left">
31+
<ComboBoxItem>DIM (data as array)</ComboBoxItem>
32+
<ComboBoxItem>ASM (DEFB inside ASM Block)</ComboBoxItem>
33+
<ComboBoxItem>.BIN file (INCBIN "file.bin")</ComboBoxItem>
34+
<ComboBoxItem>.TAP file (LOAD "" CODE)</ComboBoxItem>
35+
</ComboBox>
36+
37+
<TextBlock Name="lblOutputFile" Grid.Row="2" Classes="dialog" VerticalAlignment="Center" HorizontalAlignment="Right">File path:</TextBlock>
38+
<TextBox Name="txtOutputFile" Grid.Row="2" Classes="dialog" Grid.Column="1" MaxWidth="Infinity"></TextBox>
39+
<Button Name="btnOutputFile" Grid.Row="2" Classes="dialog" Grid.Column="2" VerticalAlignment="Center">...</Button>
40+
41+
<TextBlock Name="lblLabelName" Classes="dialog" Grid.Row="3" VerticalAlignment="Center" HorizontalAlignment="Right">Var prefix:</TextBlock>
42+
<TextBox Name="txtLabelName" Classes="dialog" Grid.Row="3" Grid.Column="1" MaxLength="64" Width="100" HorizontalAlignment="Left"></TextBox>
3543

36-
<TextBlock Name="lblArrayBase" Classes="dialog" Grid.Row="5" VerticalAlignment="Center" HorizontalAlignment="Right">Array base:</TextBlock>
37-
<ComboBox Name="cmbArrayBase" Classes="dialog" Grid.Row="5" Grid.Column="1" HorizontalAlignment="Left">
44+
<TextBlock Name="lblArrayBase" Classes="dialog" Grid.Row="4" VerticalAlignment="Center" HorizontalAlignment="Right">Array base:</TextBlock>
45+
<ComboBox Name="cmbArrayBase" Classes="dialog" Grid.Row="4" Grid.Column="1" HorizontalAlignment="Left">
3846
<ComboBoxItem>0 (default)</ComboBoxItem>
3947
<ComboBoxItem>1</ComboBoxItem>
4048
<ComboBoxItem>From project settings</ComboBoxItem>
4149
</ComboBox>
4250

43-
<TextBlock Name="lblAttr" Grid.Row="6" Classes="dialog" VerticalAlignment="Center" HorizontalAlignment="Right">Export attributes</TextBlock>
44-
<CheckBox Name="chkAttr" Grid.Row="6" Grid.Column="1" Classes="dialog"></CheckBox>
51+
<TextBlock Name="lblAttr" Grid.Row="5" Classes="dialog" VerticalAlignment="Center" HorizontalAlignment="Right">Export attributes</TextBlock>
52+
<CheckBox Name="chkAttr" Grid.Row="5" Grid.Column="1" Classes="dialog"></CheckBox>
4553
</Grid>
4654

4755
<TextBlock Name="txtError" FontSize="14" Foreground="Red" Margin="0,16,0,16" IsVisible="False">

ZXBStudio/DocumentEditors/ZXGraphics/SpriteExportDialog.axaml.cs

Lines changed: 73 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ public SpriteExportDialog()
3939
btnCopy.Tapped += BtnCopy_Tapped;
4040
btnExport.Tapped += BtnExport_Tapped;
4141
btnOutputFile.Tapped += BtnOutputFile_Tapped;
42+
cmbDataType.SelectionChanged += CmbDataType_SelectionChanged;
4243
cmbArrayBase.SelectionChanged += CmbArrayBase_SelectionChanged;
44+
chkAttr.Click += ChkAttr_Click;
4345
btnSave.Tapped += BtnSave_Tapped;
4446
}
4547

@@ -61,6 +63,7 @@ public bool Initialize(string fileName, IEnumerable<Sprite> spritesData)
6163
txtOutputFile.Text = exportConfig.ExportFilePath;
6264
txtLabelName.Text = exportConfig.LabelName;
6365
chkAuto.IsChecked = exportConfig.AutoExport;
66+
cmbDataType.SelectedIndex = (int)exportConfig.ExportDataType;
6467
cmbArrayBase.SelectedIndex = exportConfig.ArrayBase.ToInteger();
6568
chkAttr.IsChecked = exportConfig.IncludeAttr;
6669

@@ -75,7 +78,12 @@ public bool Initialize(string fileName, IEnumerable<Sprite> spritesData)
7578
private void ExportType_Changed(ExportTypes exportType)
7679
{
7780
exportConfig.ExportType = exportType;
81+
Refresh();
82+
}
83+
7884

85+
private void Refresh()
86+
{
7987
grdOptions.IsVisible = true;
8088

8189
chkAuto.IsVisible = true;
@@ -88,6 +96,7 @@ private void ExportType_Changed(ExportTypes exportType)
8896
txtLabelName.IsVisible = true;
8997

9098
lblArrayBase.IsVisible = true;
99+
cmbDataType.IsVisible = true;
91100
cmbArrayBase.IsVisible = true;
92101

93102
bool canExport = false;
@@ -101,7 +110,7 @@ private void ExportType_Changed(ExportTypes exportType)
101110
txtError.IsVisible = false;
102111
}
103112

104-
switch (exportType)
113+
switch (exportConfig.ExportType)
105114
{
106115
case ExportTypes.PutChars:
107116
CreateExportPath(".bas");
@@ -145,6 +154,7 @@ private void GetConfigFromUI()
145154
}
146155
exportConfig.ArrayBase = cmbArrayBase.SelectedIndex.ToInteger();
147156
exportConfig.AutoExport = chkAuto.IsChecked == true;
157+
exportConfig.ExportDataType = (ExportDataTypes)cmbDataType.SelectedIndex.ToInteger();
148158
exportConfig.ExportFilePath = txtOutputFile.Text.ToStringNoNull();
149159
exportConfig.ExportType = cmbSelectExportType.ExportType;
150160
exportConfig.LabelName = txtLabelName.Text.ToStringNoNull();
@@ -160,24 +170,53 @@ private void CreateExample_PutChars()
160170
txtCode.Text = "";
161171
}
162172

163-
GetConfigFromUI();
164173
var sb = new StringBuilder();
165-
sb.AppendLine("'- Includes -----------------------------------------------");
166-
sb.AppendLine("#INCLUDE <putchars.bas>");
167-
sb.AppendLine("");
168-
sb.AppendLine(ExportManager.Export_Sprite_PutChars(exportConfig, sprites));
169-
sb.AppendLine("");
170-
sb.AppendLine("'- Draw sprite --------------------------------------------");
171-
172-
var sprite = sprites.ElementAt(0);
173-
sb.AppendLine(string.Format(
174-
"putChars(10,5,{0},{1},@{2}{3}({4}))",
175-
sprite.Width / 8,
176-
sprite.Height / 8,
177-
exportConfig.LabelName,
178-
sprite.Name.Replace(" ", "_"),
179-
sprite.Frames == 1 ? "0" : "0,0"));
180-
sb.AppendLine("");
174+
switch (exportConfig.ExportDataType)
175+
{
176+
case ExportDataTypes.DIM:
177+
{
178+
sb.AppendLine("'- Includes -----------------------------------------------");
179+
sb.AppendLine("#INCLUDE <putchars.bas>");
180+
sb.AppendLine("");
181+
sb.AppendLine(string.Format("' Can use: #INCLUDE \"{0}\"",
182+
Path.GetFileName(exportConfig.ExportFilePath)));
183+
sb.AppendLine(ExportManager.Export_Sprite_PutChars(exportConfig, sprites));
184+
sb.AppendLine("");
185+
sb.AppendLine("'- Draw sprite --------------------------------------------");
186+
187+
var sprite = sprites.ElementAt(0);
188+
sb.AppendLine(string.Format(
189+
"putChars(10,5,{0},{1},@{2}{3}({4}))",
190+
sprite.Width / 8,
191+
sprite.Height / 8,
192+
exportConfig.LabelName,
193+
sprite.Name.Replace(" ", "_"),
194+
sprite.Frames == 1 ? "0" : "0,0"));
195+
sb.AppendLine("");
196+
}
197+
break;
198+
199+
case ExportDataTypes.ASM:
200+
{
201+
sb.AppendLine("'- Includes -----------------------------------------------");
202+
sb.AppendLine("#INCLUDE <putchars.bas>");
203+
sb.AppendLine("");
204+
sb.AppendLine("'- Draw sprite --------------------------------------------");
205+
var sprite = sprites.ElementAt(0);
206+
sb.AppendLine(string.Format(
207+
"putChars(10,5,{0},{1},@{2}{3})",
208+
sprite.Width / 8,
209+
sprite.Height / 8,
210+
exportConfig.LabelName,
211+
sprite.Name.Replace(" ", "_")));
212+
sb.AppendLine("");
213+
sb.AppendLine("' This section must not be executed");
214+
sb.AppendLine(string.Format("' Can use: #INCLUDE \"{0}\"",
215+
Path.GetFileName(exportConfig.ExportFilePath)));
216+
sb.AppendLine(ExportManager.Export_Sprite_PutChars(exportConfig, sprites));
217+
}
218+
break;
219+
}
181220

182221
txtCode.Text = sb.ToString();
183222
}
@@ -253,6 +292,22 @@ private void CmbArrayBase_SelectionChanged(object? sender, SelectionChangedEvent
253292
{
254293
var idx = cmbArrayBase.SelectedIndex;
255294
exportConfig.ArrayBase = idx;
295+
Refresh();
296+
}
297+
298+
299+
private void CmbDataType_SelectionChanged(object? sender, SelectionChangedEventArgs e)
300+
{
301+
var idx = cmbDataType.SelectedIndex;
302+
exportConfig.ExportDataType = (ExportDataTypes)idx;
303+
Refresh();
304+
}
305+
306+
307+
private void ChkAttr_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
308+
{
309+
exportConfig.IncludeAttr = chkAttr.IsChecked.ToBoolean();
310+
Refresh();
256311
}
257312

258313
#endregion

ZXBStudio/DocumentEditors/ZXGraphics/ZXSpriteImage.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,26 @@ private AttributeColor GetAttribute(Sprite Sprite, Pattern Pattern, int X, int Y
129129
int cW = Sprite.Width / 8;
130130
int cX = X / 8;
131131
int cY = Y / 8;
132-
return Pattern.Attributes[(cY * cW) + cX];
132+
int dir = (cY * cW) + cX;
133+
if (Pattern.Attributes == null)
134+
{
135+
Pattern.Attributes = new AttributeColor[(Sprite.Width + Sprite.Height) / 8];
136+
for (int n = 0; n < Pattern.Attributes.Length; n++)
137+
{
138+
Pattern.Attributes[n] = new AttributeColor()
139+
{
140+
Attribute = 56 // Paper 7, ink 0
141+
};
142+
}
143+
}
144+
if (dir > Pattern.Attributes.Length)
145+
{
146+
return new AttributeColor()
147+
{
148+
Attribute = 56 // Paper 7, ink 0
149+
};
150+
}
151+
return Pattern.Attributes[dir];
133152
}
134153
#endregion
135154

0 commit comments

Comments
 (0)