@@ -7,6 +7,8 @@ import haxe.ui.containers.dialogs.MessageBox.MessageBoxType;
77import sys .FileSystem ;
88import sys .io .File ;
99import haxe .Json ;
10+ import haxe .ui .ToolkitAssets ;
11+ import haxe .ui .containers .dialogs .Dialog .DialogButton ;
1012
1113using StringTools ;
1214
@@ -23,20 +25,29 @@ typedef Data = {
2325}
2426
2527@:build (haxe.ui. ComponentBuilder .build (" assets/ui/mainview.xml" ))
26- class MainUI extends VBox {
27- var bannerBytes : Bytes = null ;
28- var iconBytes : Bytes = null ;
28+ class MainUI extends VBox {
29+ var bannerBytes : Bytes = null ;
30+ var iconBytes : Bytes = null ;
2931
3032 var options : Array <String > = [" yes" , " no" ];
3133
32- public function new (){
33- super ();
34+ public function new () {
35+ super ();
3436 banner .onClick = function (event ) {
3537 Dialogs .openBinaryFile (" Open Banner" , [{label : " Banner File (.png)" , extension : " png" }], function (selectedFile ) {
3638 if (selectedFile != null && selectedFile .bytes != null ) {
3739 trace (" Selected file: " + selectedFile .name );
38- bannerBytes = selectedFile .bytes ;
40+ bannerBytes = selectedFile .bytes ;
3941 banner .text = " Banner Success!" ;
42+
43+ ToolkitAssets .instance .imageFromBytes (bannerBytes , function (imageInfo ) {
44+ if (imageInfo != null ) {
45+ try {
46+ PreviewUI .instance .bannerPreview .resource = imageInfo .data ;
47+ PreviewUI .instance .bannerLabel .show ();
48+ } catch (_ ) {}
49+ }
50+ });
4051 }
4152 });
4253 }
@@ -45,36 +56,51 @@ class MainUI extends VBox{
4556 Dialogs .openBinaryFile (" Open Icon" , [{label : " Icon File (.png)" , extension : " png" }], function (selectedFile ) {
4657 if (selectedFile != null && selectedFile .bytes != null ) {
4758 trace (" Selected file: " + selectedFile .name );
48- iconBytes = selectedFile .bytes ;
59+ iconBytes = selectedFile .bytes ;
4960 iconbtn .text = " Icon Success!" ;
61+
62+ ToolkitAssets .instance .imageFromBytes (iconBytes , function (imageInfo ) {
63+ if (imageInfo != null ) {
64+ try {
65+ PreviewUI .instance .iconPreview .resource = imageInfo .data ;
66+ PreviewUI .instance .iconLabel .show ();
67+ } catch (_ ) {}
68+ }
69+ });
5070 }
5171 });
5272 }
5373
54- finish .onClick = function (event ){
74+ clearbtn .onClick = function (event ){
75+ Dialogs .messageBox (" Are you sure?" , " QUESTION" , MessageBoxType .TYPE_YESNO , function (callback ){
76+ (callback == DialogButton .YES ) ? clearInfo () : return ;
77+ });
78+ }
79+
80+ finish .onClick = function (event ) {
5581 FileSystem .createDirectory (" .solar-engine" );
5682
57- if (bannerBytes == null ){
83+ if (bannerBytes == null ) {
5884 Dialogs .messageBox (" Missing Banner file!" , " ERROR" , MessageBoxType .TYPE_ERROR );
5985 return ;
6086 }
61- if (iconBytes == null ){
87+ if (iconBytes == null ) {
6288 Dialogs .messageBox (" Missing Icon file!" , " ERROR" , MessageBoxType .TYPE_ERROR );
6389 return ;
6490 }
65- if (txtTitle .text == null || txtTitle .text == " " ){
91+ if (txtTitle .text == null || txtTitle .text == " " ) {
6692 Dialogs .messageBox (" No Title!" , " ERROR" , MessageBoxType .TYPE_ERROR );
6793 return ;
6894 }
69- if (txtDescription .text == null || txtDescription .text == " " ){
95+ if (txtDescription .text == null || txtDescription .text == " " ) {
7096 Dialogs .messageBox (" No Description!" , " ERROR" , MessageBoxType .TYPE_ERROR );
7197 return ;
7298 }
73- if (txtMadeBy .text == null || txtMadeBy .text == " " ){
99+ if (txtMadeBy .text == null || txtMadeBy .text == " " ) {
74100 Dialogs .messageBox (" Missing Developer Info!" , " ERROR" , MessageBoxType .TYPE_ERROR );
75101 return ;
76102 }
77- if (downloadUrl .text == null || downloadUrl .text == " " ){
103+ if (downloadUrl .text == null || downloadUrl .text == " " ) {
78104 Dialogs .messageBox (" Missing Download URL!" , " ERROR" , MessageBoxType .TYPE_ERROR );
79105 return ;
80106 }
@@ -89,18 +115,20 @@ class MainUI extends VBox{
89115 data .githubURL = githubUrl .text ;
90116 data .madeByURL = madeUrl .text ;
91117 data .downloadURL = downloadUrl .text ;
92-
118+
93119 File .saveContent (" ./.solar-engine/config.json" , Json .stringify (data ));
94120 File .saveContent (" ./.solar-engine/readme.md" , " Has to be filled in." );
95121
96122 File .saveBytes (" ./.solar-engine/banner.png" , bannerBytes );
97123 File .saveBytes (" ./.solar-engine/icon.png" , iconBytes );
98124
99125 Dialogs .messageBox (" Info Saved!" , " SUCCESS" , MessageBoxType .TYPE_INFO );
100- }
101- }
102126
103- function defaultData (): Data {
127+ clearInfo ();
128+ }
129+ }
130+
131+ function defaultData (): Data {
104132 return {
105133 isOpenSource : " " ,
106134 canMessWithComputer : " " ,
@@ -113,4 +141,29 @@ class MainUI extends VBox{
113141 downloadURL : " "
114142 };
115143 }
116- }
144+
145+ function clearInfo () {
146+ bannerBytes = null ;
147+ iconBytes = null ;
148+
149+ banner .text = " Banner" ;
150+ iconbtn .text = " Icon" ;
151+
152+ txtTitle .text = null ;
153+ txtDescription .text = null ;
154+ txtMadeBy .text = null ;
155+ githubUrl .text = null ;
156+ externalUrl .text = null ;
157+ madeUrl .text = null ;
158+ downloadUrl .text = null ;
159+
160+ isOpenSourceSelect .listView .selectedIndex = 0 ;
161+ messesWithPC .listView .selectedIndex = 0 ;
162+
163+ PreviewUI .instance .bannerPreview .resource = null ;
164+ PreviewUI .instance .iconPreview .resource = null ;
165+
166+ PreviewUI .instance .bannerLabel .hide ();
167+ PreviewUI .instance .iconLabel .hide ();
168+ }
169+ }
0 commit comments