1 module windows.newtilelayer; 2 3 import pixelperfectengine.concrete.window; 4 5 import editor; 6 7 import std.conv : to; 8 import std.utf : toUTF8, toUTF32; 9 import pixelperfectengine.concrete.dialogs.filedialog; 10 11 /+import dimage.base; 12 import dimage.tga; 13 import dimage.png;+/ 14 15 public class NewTileLayerDialog : Window { 16 //Label label0; 17 //TextBox textBox_TS; 18 //Button button_TSBrowse; 19 Label label1; 20 Label label2; 21 TextBox textBox_TX; 22 TextBox textBox_TY; 23 Label label3; 24 Button button_MSBrowse; 25 TextBox textBox_MS; 26 CheckBox checkBox_embed; 27 Label label4; 28 Label label5; 29 Label label6; 30 TextBox textBox_Name; 31 TextBox textBox_MX; 32 TextBox textBox_MY; 33 Button button_Create; 34 Editor editor; 35 public this(Editor editor){ 36 this.editor = editor; 37 super(Box(0, 0, 165, 203 ), "Create New Tile Layer"d); 38 //label0 = new Label("Tile source:"d, "label0", Box(5, 22, 71, 40)); 39 //addElement(label0); 40 //textBox_TS = new TextBox("none"d, "textBox_TS", Box(5, 41, 160, 59)); 41 //addElement(textBox_TS); 42 //button_TSBrowse = new Button("Browse"d, "button_TSBrowse", Box(70, 21, 160, 39)); 43 //button_TSBrowse.onMouseLClickRel = &button_TSBrowse_onClick; 44 //addElement(button_TSBrowse); 45 label1 = new Label("Tile Width:"d, "label1", Box(5, 22, 70, 39)); 46 addElement(label1); 47 label2 = new Label("Tile Height:"d, "label2", Box(5, 42, 70, 59)); 48 addElement(label2); 49 textBox_TX = new TextBox("8"d, "textBox_TX", Box(80, 21, 160, 39)); 50 addElement(textBox_TX); 51 textBox_TY = new TextBox("8"d, "textBox_TY", Box(80, 41, 160, 59)); 52 addElement(textBox_TY); 53 label3 = new Label("Map source:"d, "label3", Box(5, 62, 70, 79)); 54 addElement(label3); 55 button_MSBrowse = new Button("Browse"d, "button_MSBrowse", Box(70, 61, 160, 79)); 56 button_MSBrowse.onMouseLClick = &button_MSBrowse_onClick; 57 addElement(button_MSBrowse); 58 textBox_MS = new TextBox("none"d, "textBox_MS", Box(5, 81, 160, 99)); 59 addElement(textBox_MS); 60 checkBox_embed = new CheckBox("Embed as BASE64"d, "checkBox_embed", Box(5, 102, 160, 118)); 61 addElement(checkBox_embed); 62 label4 = new Label("Map Width:"d, "label4", Box(5, 122, 70, 138)); 63 addElement(label4); 64 label5 = new Label("Map Height:"d, "label5", Box(5, 142, 70, 158)); 65 addElement(label5); 66 textBox_MX = new TextBox("64"d, "textBox_MX", Box(70, 121, 160, 139)); 67 addElement(textBox_MX); 68 textBox_MY = new TextBox("64"d, "textBox_MY", Box(70, 141, 160, 159)); 69 addElement(textBox_MY); 70 label6 = new Label("Layer Name:", "label6", Box(5, 162, 70, 178)); 71 addElement(label5); 72 textBox_Name = new TextBox("64"d, "textBox_Name", Box(70, 161, 160, 179)); 73 addElement(textBox_Name); 74 button_Create = new Button("Create"d, "button_Create", Box(70, 181, 160, 199)); 75 addElement(button_Create); 76 button_Create.onMouseLClick = &button_Create_onClick; 77 textBox_MX.setFilter(TextInputFieldType.IntegerP); 78 textBox_MY.setFilter(TextInputFieldType.IntegerP); 79 textBox_TX.setFilter(TextInputFieldType.IntegerP); 80 textBox_TY.setFilter(TextInputFieldType.IntegerP); 81 } 82 /+private void button_TSBrowse_onClick(Event ev){ 83 parent.addWindow(new FileDialog("Import Tile Source"d, "fileDialog_TSBrowse", &fileDialog_TSBrowse_event, 84 [FileDialog.FileAssociationDescriptor("All supported formats", ["*.pmp", "*.tga", "*.png"]), 85 FileDialog.FileAssociationDescriptor("PPE Map file", ["*.pmp"]), 86 FileDialog.FileAssociationDescriptor("TGA File", ["*.tga"]), 87 FileDialog.FileAssociationDescriptor("PNG file", ["*.png"])], "./")); 88 }+/ 89 /+private void fileDialog_TSBrowse_event(Event ev){ 90 textBox_TS.setText(toUTF32(ev.getFullPath)); 91 //Get tile data from source 92 }+/ 93 private void button_MSBrowse_onClick(Event ev){ 94 handler.addWindow(new FileDialog("Import Map Source"d, "fileDialog_MSBrowse", &fileDialog_MSBrowse_event, 95 [FileDialog.FileAssociationDescriptor("Extendible Map file", ["*.xmp"]), 96 FileDialog.FileAssociationDescriptor("PPE Binary Map file", ["*.map"])], "./")); 97 } 98 private void fileDialog_MSBrowse_event(Event ev){ 99 FileEvent fev = cast(FileEvent)ev; 100 textBox_MS.setText(toUTF32(fev.getFullPath)); 101 } 102 private void button_Create_onClick(Event ev){ 103 try{ 104 const int mX = to!int(textBox_MX.getText.text); 105 const int mY = to!int(textBox_MY.getText.text); 106 const int tX = to!int(textBox_TX.getText.text); 107 const int tY = to!int(textBox_TY.getText.text); 108 string mS; 109 if(textBox_MS.getText.text != "" && textBox_MS.getText.text != "none") 110 mS = toUTF8(textBox_MS.getText.text); 111 //string tS; 112 /+if(textBox_TS.getText.text != "" && textBox_TS.getText.text != "none") 113 tS = toUTF8(textBox_TS.getText.text);+/ 114 dstring name = textBox_Name.getText.text; 115 editor.newTileLayer(tX, tY, mX, mY, name, mS, checkBox_embed.isChecked); 116 }catch(Exception e){ 117 handler.message("Error!", "Cannot parse data!"); 118 } 119 close(); 120 } 121 }