Works aside from buy button being missing

This commit is contained in:
gamer147
2025-11-24 22:41:12 -05:00
parent 7263b88baa
commit 6caccf553e
2 changed files with 46 additions and 8 deletions

View File

@@ -126,15 +126,16 @@ public class ShopQuestion extends Question {
form.endHorizontalFlow();
}
// Items table
form.beginTable(items.size(), new String[] { "Item", "Description", "Price", "Buy" });
// Items tree (hover shows description)
int height = 16 + 16 * items.size();
String header = "height=\"" + height + "\"col{text=\"Price\";width=\"80\"};col{text=\"Buy\";width=\"50\"};";
form.beginTree("shopItems", 2, header);
for (ShopItem item : items) {
form.addLabel(escape(item.getName()));
form.addLabel(escape(item.getDescription()));
form.addLabel(escape(item.getPriceDisplay()));
form.addButton("+1", "buy_" + item.getId());
String priceCell = "text=\"" + escape(item.getPriceDisplay()) + "\"";
String buyCell = "button{id=\"buy_" + item.getId() + "\";text=\"+1\"}";
form.addTreeRow("i" + item.getId(), item.getName(), item.getDescription(), priceCell, buyCell);
}
form.endTable();
form.endTree();
form.beginHorizontalFlow();
form.addButton("Close", "close");

View File

@@ -16,7 +16,7 @@ public class BmlForm {
private int openColumns = 0;
private int openTables = 0;
private int indentNum = 0;
private boolean beautify = false;
private boolean beautify = true;
private boolean closeDefault = false;
public BmlForm() {
@@ -210,6 +210,43 @@ public class BmlForm {
this.buf.append(this.indent("button{text=' " + name + " ';id='" + id + "'}"));
}
private String escape(String val) {
if (val == null) {
return "";
}
return val.replace("\"", "''");
}
public void beginTree(String id, int cols, String headers) {
this.buf.append(this.indent("tree{id=\"" + id + "\";cols=\"" + cols + "\";showheader=\"true\";" + headers));
++this.indentNum;
++this.openTrees;
}
public void endTree() {
--this.indentNum;
this.buf.append(this.indent("}"));
--this.openTrees;
}
public void addTreeRow(String id, String name, String hover, String... cells) {
StringBuilder row = new StringBuilder();
row.append("row{id=\"").append(id).append("\";");
if (hover != null && !hover.isEmpty()) {
row.append("hover=\"").append(escape(hover)).append("\";");
}
row.append("name=\"").append(name).append("\";rarity=\"0\";children=\"0\";");
for(int i=0;i<cells.length;i++) {
String c = cells[i];
row.append("col{").append(c).append("}");
if(i != cells.length-1) {
row.append(";");
}
}
row.append("}");
this.buf.append(this.indent(row.toString()));
}
public String toString() {
if (this.closeDefault) {
this.endVerticalFlow();