diff --git a/src/main/java/com/wurmonline/server/questions/ShopQuestion.java b/src/main/java/com/wurmonline/server/questions/ShopQuestion.java index c74ef17..a7680f0 100644 --- a/src/main/java/com/wurmonline/server/questions/ShopQuestion.java +++ b/src/main/java/com/wurmonline/server/questions/ShopQuestion.java @@ -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"); diff --git a/src/main/java/mod/treestar/shopmod/util/BmlForm.java b/src/main/java/mod/treestar/shopmod/util/BmlForm.java index 5477b45..5afa110 100644 --- a/src/main/java/mod/treestar/shopmod/util/BmlForm.java +++ b/src/main/java/mod/treestar/shopmod/util/BmlForm.java @@ -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