1 module windows.materiallist; 2 3 import PixelPerfectEngine.concrete.window; 4 import PixelPerfectEngine.map.mapformat; 5 6 import app; 7 8 import std.utf : toUTF32; 9 import PixelPerfectEngine.system.etc : intToHex; 10 11 /** 12 * Preliminary, future version will feature material selection with images. 13 */ 14 public class MaterialList : Window { 15 //ListBox listBox_materials; 16 ListView listView_materials; 17 Label palettePos; 18 SmallButton removeMaterial; 19 SmallButton addMaterial; 20 CheckBox horizMirror; 21 CheckBox vertMirror; 22 CheckBox ovrwrtIns; 23 SmallButton paletteUp; 24 SmallButton paletteDown; 25 SmallButton settings; 26 27 protected TileInfo[] tiles; 28 protected ListViewHeader tileListHeader; 29 protected ListViewHeader spriteListHeader; 30 public this(int x, int y, void delegate() onClose) @trusted { 31 super(Coordinate(x, y, x + 129, y + 249), "Materials"d); 32 this.onClose = onClose; 33 StyleSheet ss = getStyleSheet(); 34 /+listBox_materials = new ListBox("listBox0", Coordinate(1, 17, 129, 218), [], new ListBoxHeader(tileListHeaderS.dup, 35 tileListHeaderW.dup));+/ 36 tileListHeader = new ListViewHeader(16, [32, 120], ["ID"d, "Name"d]); 37 spriteListHeader = new ListViewHeader(16, [40, 120, 64], ["ID"d, "Name"d, "Dim"d]); 38 listView_materials = new ListView(tileListHeader, null, "listView_materials", Box(1, 17, 128, 215)); 39 listView_materials.onItemSelect = &onItemSelect; 40 addElement(listView_materials); 41 42 removeMaterial = new SmallButton("removeMaterialB", "removeMaterialA", "rem", Box(113, 233, 129, 248)); 43 removeMaterial.onMouseLClick = &button_trash_onClick; 44 addElement(removeMaterial); 45 46 addMaterial = new SmallButton("addMaterialB", "addMaterialA", "add", Box(113, 217, 129, 232)); 47 addMaterial.onMouseLClick = &button_addMaterial_onClick; 48 addElement(addMaterial); 49 50 horizMirror = new CheckBox("horizMirrorB", "horizMirrorA", "horizMirror", Box(1, 217, 16, 232)); 51 horizMirror.onToggle = &horizMirror_onClick; 52 addElement(horizMirror); 53 54 vertMirror = new CheckBox("vertMirrorB", "vertMirrorA", "vertMirror", Box(17, 217, 32, 232)); 55 vertMirror.onToggle = &vertMirror_onClick; 56 addElement(vertMirror); 57 58 ovrwrtIns = new CheckBox("ovrwrtInsB", "ovrwrtInsA", "ovrwrtIns", Box(33, 217, 48, 232)); 59 ovrwrtIns.onToggle = &ovrwrtIns_onClick; 60 addElement(ovrwrtIns); 61 62 paletteUp = new SmallButton("paletteUpB", "paletteUpA", "palUp", Box(1, 233, 16, 248)); 63 paletteUp.onMouseLClick = &palUp_onClick; 64 addElement(paletteUp); 65 66 paletteDown = new SmallButton("paletteDownB", "paletteDownA", "palDown", Box(17, 233, 32, 248)); 67 paletteDown.onMouseLClick = &palDown_onClick; 68 addElement(paletteDown); 69 70 settings = new SmallButton("settingsButtonB", "settingsButtonA", "editMat", Box(97, 233, 112, 248)); 71 settings.onMouseLClick = &button_editMat_onClick; 72 addElement(settings); 73 74 palettePos = new Label("0x00", "palettePos", Box(34, 234, 96, 248)); 75 addElement(palettePos); 76 } 77 public void updateMaterialList(TileInfo[] list) @trusted { 78 import PixelPerfectEngine.system.etc : intToHex; 79 tiles = list; 80 /+ListViewItem[] output; 81 output.reserve = list.length;+/ 82 listView_materials.clear; 83 foreach (item ; list) { 84 listView_materials ~= new ListViewItem(16, [intToHex!dstring(item.id, 4) ~ "h", toUTF32(item.name)]); 85 } 86 listView_materials.refresh; 87 /+listBox_materials.updateColumns(output, new ListBoxHeader(tileListHeaderS.dup, tileListHeaderW.dup));+/ 88 } 89 private void vertMirror_onClick(Event ev) { 90 CheckBox sender = cast(CheckBox)ev.sender; 91 if (prg.selDoc) { 92 if(sender.isChecked) { 93 prg.selDoc.tileMaterial_FlipVertical(true); 94 } else { 95 prg.selDoc.tileMaterial_FlipVertical(false); 96 } 97 } 98 } 99 private void horizMirror_onClick(Event ev) { 100 CheckBox sender = cast(CheckBox)ev.sender; 101 if (prg.selDoc) { 102 if(sender.isChecked) { 103 prg.selDoc.tileMaterial_FlipHorizontal(true); 104 } else { 105 prg.selDoc.tileMaterial_FlipHorizontal(false); 106 } 107 } 108 } 109 private void button_addMaterial_onClick(Event ev) { 110 prg.initAddMaterials; 111 } 112 private void button_editMat_onClick(Event ev) { 113 114 } 115 private void button_trash_onClick(Event ev) { 116 117 } 118 public void palUp_onClick(Event ev) { 119 palettePos.setText("0x" ~ intToHex!dstring(prg.selDoc.tileMaterial_PaletteUp, 2)); 120 } 121 public void palDown_onClick(Event ev) { 122 palettePos.setText("0x" ~ intToHex!dstring(prg.selDoc.tileMaterial_PaletteDown, 2)); 123 } 124 125 private void ovrwrtIns_onClick(Event ev) { 126 CheckBox sender = cast(CheckBox)ev.sender; 127 if (prg.selDoc) 128 prg.selDoc.voidfill = sender.isChecked; 129 } 130 private void onItemSelect(Event ev) { 131 prg.selDoc.tileMaterial_Select(tiles[listView_materials.value].id); 132 } 133 } 134 /** 135 * Defines a single material. 136 */ 137 public struct Material { 138 dstring id; ///Hexanumeric value of the ID 139 dstring name; ///Name of the object or tile 140 dstring dim; ///Dimensions of the object, null on tiles since they share the same size on one layer 141 }