Skip to content

Commit

Permalink
save blinking "animation": save a
Browse files Browse the repository at this point in the history
selected numer of frame of block on and block off in a selected dir
  • Loading branch information
BlankManifold committed Nov 5, 2022
1 parent 258dc4a commit 4ebe237
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 15 deletions.
29 changes: 28 additions & 1 deletion scenes/PreviewUI.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=4 format=2]
[gd_scene load_steps=5 format=2]

[ext_resource path="res://scripts/PreviewUI.cs" type="Script" id=2]

Expand Down Expand Up @@ -28,6 +28,32 @@ tracks/0/keys = {
} ]
}

[sub_resource type="Animation" id=3]
resource_name = "BlinkingBlockSave"
tracks/0/type = "method"
tracks/0/path = NodePath(".")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.3, 0.7, 1 ),
"transitions": PoolRealArray( 1, 1, 1, 1 ),
"values": [ {
"args": [ true ],
"method": "UpdateOnlyBlock"
}, {
"args": [ "1.png", false ],
"method": "SavePNG"
}, {
"args": [ false ],
"method": "UpdateOnlyBlock"
}, {
"args": [ "2.png", false ],
"method": "SavePNG"
} ]
}

[node name="PreviewUI" type="Control"]
anchor_left = 0.5
anchor_top = 0.5
Expand Down Expand Up @@ -69,3 +95,4 @@ override_selected_font_color = true
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
unique_name_in_owner = true
anims/BlinkingBlock = SubResource( 2 )
anims/BlinkingBlockSave = SubResource( 3 )
40 changes: 32 additions & 8 deletions scenes/ToolsUI.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -440,23 +440,22 @@ anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
margin_left = -132.0
margin_top = -216.0
margin_top = -248.0
margin_right = 133.0
margin_bottom = -16.0
margin_bottom = -18.0
custom_constants/separation = 10
alignment = 1

[node name="BlinkingButton" type="CheckButton" parent="RightPanel/BottomRightBox"]
margin_top = 10.0
margin_right = 265.0
margin_bottom = 50.0
margin_bottom = 40.0
text = "BLINKING"
align = 1

[node name="SaveBox" type="VBoxContainer" parent="RightPanel/BottomRightBox"]
margin_top = 60.0
margin_top = 50.0
margin_right = 265.0
margin_bottom = 150.0
margin_bottom = 194.0
custom_constants/separation = 20

[node name="Shrink2Box" type="CheckButton" parent="RightPanel/BottomRightBox/SaveBox"]
Expand All @@ -476,16 +475,40 @@ size_flags_vertical = 0
shortcut = SubResource( 5 )
text = "SAVE"

[node name="HBoxContainer" type="HBoxContainer" parent="RightPanel/BottomRightBox/SaveBox"]
margin_top = 110.0
margin_right = 265.0
margin_bottom = 144.0

[node name="FramesSpinBox" type="SpinBox" parent="RightPanel/BottomRightBox/SaveBox/HBoxContainer"]
unique_name_in_owner = true
margin_right = 86.0
margin_bottom = 34.0
min_value = 1.0
max_value = 60.0
value = 1.0
rounded = true

[node name="SaveBlink" type="Button" parent="RightPanel/BottomRightBox/SaveBox/HBoxContainer"]
margin_left = 90.0
margin_right = 240.0
margin_bottom = 30.0
rect_min_size = Vector2( 150, 0 )
size_flags_horizontal = 4
size_flags_vertical = 0
text = "SAVE BLINK"

[node name="ZoomButtons" parent="RightPanel/BottomRightBox" instance=ExtResource( 5 )]
margin_top = 160.0
margin_top = 204.0
margin_right = 265.0
margin_bottom = 190.0
margin_bottom = 234.0
alignment = 0

[connection signal="UpdatePalette" from="." to="RightPanel/TopRightBox/ColorBox/BackgroundColorSelection" method="_on_ToolsUI_UpdatePalette"]
[connection signal="UpdatePalette" from="." to="RightPanel/TopRightBox/ColorBox/FontColorSelection" method="_on_ToolsUI_UpdatePalette"]
[connection signal="UpdatePalette" from="." to="RightPanel/TopRightBox/ColorBox/SymbolColorSelection" method="_on_ToolsUI_UpdatePalette"]
[connection signal="confirmed" from="FileDialog" to="." method="_on_FileDialog_confirmed"]
[connection signal="dir_selected" from="FileDialog" to="." method="_on_FileDialog_dir_selected"]
[connection signal="file_selected" from="FileDialog" to="." method="_on_FileDialog_file_selected"]
[connection signal="files_selected" from="FileDialog" to="." method="_on_FileDialog_files_selected"]
[connection signal="text_entered" from="TemplateNamePanel/VBoxContainer/TemeplateName" to="." method="_on_TemeplateName_text_entered"]
Expand All @@ -511,4 +534,5 @@ alignment = 0
[connection signal="toggled" from="RightPanel/BottomRightBox/BlinkingButton" to="." method="_on_BlinkingButton_toggled"]
[connection signal="toggled" from="RightPanel/BottomRightBox/SaveBox/Shrink2Box" to="." method="_on_Shrink2Box_toggled"]
[connection signal="button_down" from="RightPanel/BottomRightBox/SaveBox/Save" to="." method="_on_Save_button_down"]
[connection signal="button_down" from="RightPanel/BottomRightBox/SaveBox/HBoxContainer/SaveBlink" to="." method="_on_SaveBlink_button_down"]
[connection signal="Changed" from="RightPanel/BottomRightBox/ZoomButtons" to="." method="_on_ZoomButtons_Changed"]
2 changes: 1 addition & 1 deletion scripts/Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public enum Tool
FONT, FONTCOLOR, SYMCOLOR, SPACING, BOLDFONT,
INCIPIT, CLOSING, TEXT,
TEMPLATE,
SAVE,
SAVE, SAVEBLINKING,
BLINKING
}
public enum Text
Expand Down
13 changes: 9 additions & 4 deletions scripts/MainControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public override void _Ready()
_toolsUI.ConnectTool(this, Globals.Tool.ZOOM, nameof(on_ToolsUI_Zoom));
_toolsUI.ConnectTool(this, Globals.Tool.SAVE, nameof(on_ToolsUI_Save));
_toolsUI.ConnectTool(this, Globals.Tool.BLINKING, nameof(on_ToolsUI_BlinkingPressed));
_toolsUI.ConnectTool(this, Globals.Tool.SAVEBLINKING, nameof(on_ToolsUI_SaveBlinking));
}

public void on_ToolsUI_SizeChanged(Vector2 ratioVec)
Expand Down Expand Up @@ -65,20 +66,24 @@ public void on_ToolsUI_Zoom(bool zoomIn, bool maxime)
{
if (maxime)
return;

Vector2 zoom = _camera.Zoom;
if (zoomIn)
zoom /= 1.1f;
zoom /= 1.1f;
else
zoom *= 1.1f;
zoom *= 1.1f;

if (zoom[0] >= _maxZoom[0] && zoom[1] <= _maxZoom[1])
_camera.Zoom = zoom;
}
public void on_ToolsUI_Save(string path, bool shrink2)
{
_previewUI.SavePNG(path, shrink2);
}
public void on_ToolsUI_SaveBlinking(string dirpath, bool shrink2, int numberOfFrame)
{
_previewUI.SaveBlinking(dirpath, shrink2, numberOfFrame);
}
public void on_ToolsUI_BlinkingPressed(bool blinkingOn)
{
_previewUI.BlinkAnimation(blinkingOn);
Expand Down
28 changes: 28 additions & 0 deletions scripts/PreviewUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,34 @@ public void SavePNG(string path, bool shrink2)
}
frame.SavePng(path);
}

private async void TweenSavingBlink(string dirpath, bool shrink2, int numberOfFrame)
{
SceneTreeTween tween = CreateTween();
tween.TweenCallback(this, "UpdateOnlyBlock", new Godot.Collections.Array() { true }).SetDelay(0f);
tween.TweenCallback(this, "SavePNG", new Godot.Collections.Array() { dirpath + "/f0_On.png", shrink2 }).SetDelay(0.3f);
tween.TweenCallback(this, "UpdateOnlyBlock", new Godot.Collections.Array() { false }).SetDelay(0.5f);
tween.TweenCallback(this, "SavePNG", new Godot.Collections.Array() { dirpath + "/f0_Off.png", shrink2 }).SetDelay(0.8f);

await ToSignal(tween, "finished");

Directory dir = new Directory();

for (int i = 1; i < numberOfFrame; i++)
{
dir.Copy(dirpath + "/f0_On.png", dirpath + $"/f{i}_On.png");
dir.Copy(dirpath + "/f0_Off.png", dirpath + $"/f{i}_Off.png");
}

}
public void SaveBlinking(string dirpath, bool shrink2, int numberOfFrame)
{
TweenSavingBlink(dirpath, shrink2, numberOfFrame);



}

public void BlinkAnimation(bool blinkingOn)
{
if (blinkingOn)
Expand Down
26 changes: 25 additions & 1 deletion scripts/ToolsUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class ToolsUI : Control
{
public enum FileDialogMode
{
TXT, PALETTE, SAVE_PNG, TXTS, FONT, BOLDFONT
TXT, PALETTE, SAVE_PNG, TXTS, FONT, BOLDFONT, SAVE_BLINKING
}

[Export]
Expand Down Expand Up @@ -86,6 +86,8 @@ public enum FileDialogMode
[Signal]
delegate void Save(string path, bool shrink2);
[Signal]
delegate void SaveBlinking(string dirpath, bool shrink2, int numberOfFrame);
[Signal]
delegate void BlinkingPressed(bool blinkingOn);


Expand Down Expand Up @@ -178,6 +180,9 @@ public void ConnectTool(Node nodeToConnect, Globals.Tool tool, string targetMeth
case Globals.Tool.SAVE:
Connect(nameof(Save), nodeToConnect, targetMethod);
break;
case Globals.Tool.SAVEBLINKING:
Connect(nameof(SaveBlinking), nodeToConnect, targetMethod);
break;
case Globals.Tool.BLINKING:
Connect(nameof(BlinkingPressed), nodeToConnect, targetMethod);
break;
Expand Down Expand Up @@ -252,6 +257,12 @@ private void UpdateFileDialogFilters(FileDialogMode mode)
_fileDialog.WindowTitle = "Save the comunque as a PNG";
_fileDialog.Filters = new string[] { Globals.RESOURCE_EXT.PNG };
break;
case FileDialogMode.SAVE_BLINKING:
_fileDialog.Mode = FileDialog.ModeEnum.OpenDir;
_fileDialog.CurrentDir = "";
_fileDialog.WindowTitle = "Select a dir destination";
_fileDialog.Filters = new string[] {};
break;
case FileDialogMode.FONT:
case FileDialogMode.BOLDFONT:
_fileDialog.CurrentFile = "";
Expand Down Expand Up @@ -493,6 +504,14 @@ public void _on_FileDialog_confirmed()
EmitSignal(nameof(Save), _fileDialog.CurrentPath, _shrink2);
}
}
public void _on_FileDialog_dir_selected(string dirpath)
{
if (_fileDialogMode == FileDialogMode.SAVE_BLINKING)
{
int numberOfFrame = (int)GetNode<SpinBox>("%FramesSpinBox").Value;
EmitSignal(nameof(SaveBlinking), dirpath, _shrink2, numberOfFrame);
}
}

///////////////////////////////////////////////////////////
// TEXT /////////////////////////////////////////////////
Expand Down Expand Up @@ -569,5 +588,10 @@ public void _on_BlinkingButton_toggled(bool blinkingOn)
{
EmitSignal(nameof(BlinkingPressed), blinkingOn);
}
public void _on_SaveBlink_button_down()
{
UpdateFileDialogFilters(FileDialogMode.SAVE_BLINKING);
_fileDialog.Popup_();
}
}

0 comments on commit 4ebe237

Please sign in to comment.