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 } 78 /+private void button_TSBrowse_onClick(Event ev){ 79 parent.addWindow(new FileDialog("Import Tile Source"d, "fileDialog_TSBrowse", &fileDialog_TSBrowse_event, 80 [FileDialog.FileAssociationDescriptor("All supported formats", ["*.pmp", "*.tga", "*.png"]), 81 FileDialog.FileAssociationDescriptor("PPE Map file", ["*.pmp"]), 82 FileDialog.FileAssociationDescriptor("TGA File", ["*.tga"]), 83 FileDialog.FileAssociationDescriptor("PNG file", ["*.png"])], "./")); 84 }+/ 85 /+private void fileDialog_TSBrowse_event(Event ev){ 86 textBox_TS.setText(toUTF32(ev.getFullPath)); 87 //Get tile data from source 88 }+/ 89 private void button_MSBrowse_onClick(Event ev){ 90 handler.addWindow(new FileDialog("Import Map Source"d, "fileDialog_MSBrowse", &fileDialog_MSBrowse_event, 91 [FileDialog.FileAssociationDescriptor("Extendible Map file", ["*.xmp"]), 92 FileDialog.FileAssociationDescriptor("PPE Binary Map file", ["*.map"])], "./")); 93 } 94 private void fileDialog_MSBrowse_event(Event ev){ 95 FileEvent fev = cast(FileEvent)ev; 96 textBox_MS.setText(toUTF32(fev.getFullPath)); 97 } 98 private void checkTextBoxInput(Event ev){ 99 import PixelPerfectEngine.system.etc : isInteger; 100 WindowElement we = cast(WindowElement)ev.sender; 101 if(!isInteger(we.getText.text)){ 102 handler.message("Input error!", "Not a numeric value!"); 103 we.setText("0"); 104 } 105 } 106 private void button_Create_onClick(Event ev){ 107 try{ 108 const int mX = to!int(textBox_MX.getText.text); 109 const int mY = to!int(textBox_MY.getText.text); 110 const int tX = to!int(textBox_TX.getText.text); 111 const int tY = to!int(textBox_TY.getText.text); 112 string mS; 113 if(textBox_MS.getText.text != "" && textBox_MS.getText.text != "none") 114 mS = toUTF8(textBox_MS.getText.text); 115 //string tS; 116 /+if(textBox_TS.getText.text != "" && textBox_TS.getText.text != "none") 117 tS = toUTF8(textBox_TS.getText.text);+/ 118 dstring name = textBox_Name.getText.text; 119 editor.newTileLayer(tX, tY, mX, mY, name, mS, checkBox_embed.isChecked); 120 }catch(Exception e){ 121 handler.message("Error!", "Cannot parse data!"); 122 } 123 close(); 124 } 125 }